Get the alert information from the view for the Sensors plugin in the WebUI

pull/2745/head
nicolargo 2024-04-29 10:52:25 +02:00
parent a56063b8d0
commit 263db4f263
3 changed files with 24 additions and 16 deletions

View File

@ -5,9 +5,9 @@
</div>
<div class="table-row" v-for="(sensor, sensorId) in sensors" :key="sensorId">
<div class="table-cell text-left">{{ sensor.label }}</div>
<div class="table-cell">{{ sensor.unit }}</div>
<div class="table-cell" :class="getAlert(sensor)">
{{ sensor.value }}
<div class="table-cell"></div>
<div class="table-cell" :class="getDecoration(sensor.label)">
{{ sensor.value }}{{ sensor.unit }}
</div>
</div>
</section>
@ -35,13 +35,16 @@ export default {
stats() {
return this.data.stats['sensors'];
},
view() {
return this.data.views['sensors'];
},
sensors() {
return this.stats
.filter((sensor) => {
// prettier-ignore
const isEmpty = (Array.isArray(sensor.value) && sensor.value.length === 0) || sensor.value === 0;
return !isEmpty;
})
// .filter((sensor) => {
// // prettier-ignore
// const isEmpty = (Array.isArray(sensor.value) && sensor.value.length === 0) || sensor.value === 0;
// return !isEmpty;
// })
.map((sensor) => {
if (
this.args.fahrenheit &&
@ -57,9 +60,11 @@ export default {
}
},
methods: {
getAlert(sensor) {
const current = sensor.type == 'battery' ? 100 - sensor.value : sensor.value;
return GlancesHelper.getAlert('sensors', 'sensors_' + sensor.type + '_', current);
getDecoration(key) {
if (this.view[key].value.decoration === undefined) {
return;
}
return this.view[key].value.decoration.toLowerCase();
}
}
};

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
#
# This file is part of Glances.
#
# SPDX-FileCopyrightText: 2022 Nicolas Hennion <nicolas@nicolargo.com>
# SPDX-FileCopyrightText: 2024 Nicolas Hennion <nicolas@nicolargo.com>
#
# SPDX-License-Identifier: LGPL-3.0-only
#
@ -154,15 +154,18 @@ class PluginModel(GlancesPluginModel):
pass
# Global change on stats
self.stats = self.get_init_value()
stats_transformed = []
for stat in stats:
# Hide sensors configured in the hide ou show configuration key
if not self.is_display(stat["label"].lower()):
continue
# Set alias for sensors
stat["label"] = self.__get_alias(stat)
# Update the stats
self.stats.append(stat)
# Add the stat to the stats_transformed list
stats_transformed.append(stat)
# Update the stats
self.stats = stats_transformed
return self.stats