summaryrefslogtreecommitdiffstats
path: root/glances/outputs/static/js/components/plugin-sensors.vue
blob: bce35429a52a53ca34cd8e428713fa27bdd4c1d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<template>
    <section>
        <div class="table-row" v-if="sensors.length > 0">
            <div class="table-cell text-left title">SENSORS</div>
        </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>
        </div>
    </section>
</template>

<script>
import { GlancesHelper } from '../services.js';
import { store } from '../store.js';

export default {
    props: {
        data: {
            type: Object
        }
    },
    data() {
        return {
            store
        };
    },
    computed: {
        args() {
            return this.store.args || {};
        },
        stats() {
            return this.data.stats['sensors'];
        },
        sensors() {
            return this.stats
                .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 &&
                        sensor.type != 'battery' &&
                        sensor.type != 'fan_speed'
                    ) {
                        // prettier-ignore
                        sensor.value = parseFloat(sensor.value * 1.8 + 32).toFixed(1);
                        sensor.unit = 'F';
                    }
                    return sensor;
                });
        }
    },
    methods: {
        getAlert(sensor) {
            const current = sensor.type == 'battery' ? 100 - sensor.value : sensor.value;
            return GlancesHelper.getAlert('sensors', 'sensors_' + sensor.type + '_', current);
        }
    }
};
</script>