blob: 70d4f90d55056243582fb5296f0d73622b66ecc2 [file] [log] [blame]
Yoshie Muranaka30abccb2020-03-11 12:44:24 -07001<template>
2 <b-container fluid>
3 <page-title />
4 <b-row>
5 <b-col xl="12">
6 <b-table
7 sort-icon-left
8 no-sort-reset
9 sticky-header="75vh"
10 sort-by="status"
11 :items="allSensors"
12 :fields="fields"
13 :sort-desc="true"
14 :sort-compare="sortCompare"
15 >
16 <template v-slot:cell(status)="{ value }">
17 <status-icon :status="statusIcon(value)" />
18 {{ value }}
19 </template>
20 <template v-slot:cell(currentValue)="data">
21 {{ data.value }} {{ data.item.units }}
22 </template>
23 <template v-slot:cell(lowerCaution)="data">
24 {{ data.value }} {{ data.item.units }}
25 </template>
26 <template v-slot:cell(upperCaution)="data">
27 {{ data.value }} {{ data.item.units }}
28 </template>
29 <template v-slot:cell(lowerCritical)="data">
30 {{ data.value }} {{ data.item.units }}
31 </template>
32 <template v-slot:cell(upperCritical)="data">
33 {{ data.value }} {{ data.item.units }}
34 </template>
35 </b-table>
36 </b-col>
37 </b-row>
38 </b-container>
39</template>
40
41<script>
42import PageTitle from '../../../components/Global/PageTitle';
43import StatusIcon from '../../../components/Global/StatusIcon';
44
45const valueFormatter = value => {
46 if (value === null || value === undefined) {
47 return '--';
48 }
49 return parseFloat(value.toFixed(3));
50};
51
52export default {
53 name: 'Sensors',
54 components: { PageTitle, StatusIcon },
55 data() {
56 return {
57 fields: [
58 {
59 key: 'name',
60 sortable: true,
61 label: this.$t('pageSensors.table.name')
62 },
63 {
64 key: 'status',
65 sortable: true,
66 label: this.$t('pageSensors.table.status')
67 },
68 {
69 key: 'lowerCritical',
70 formatter: valueFormatter,
71 label: this.$t('pageSensors.table.lowerCritical')
72 },
73 {
74 key: 'lowerCaution',
75 formatter: valueFormatter,
76 label: this.$t('pageSensors.table.lowerWarning')
77 },
78
79 {
80 key: 'currentValue',
81 formatter: valueFormatter,
82 label: this.$t('pageSensors.table.currentValue')
83 },
84 {
85 key: 'upperCaution',
86 formatter: valueFormatter,
87 label: this.$t('pageSensors.table.upperWarning')
88 },
89 {
90 key: 'upperCritical',
91 formatter: valueFormatter,
92 label: this.$t('pageSensors.table.upperCritical')
93 }
94 ]
95 };
96 },
97 computed: {
98 allSensors() {
99 return this.$store.getters['sensors/sensors'];
100 }
101 },
102 created() {
103 this.$store.dispatch('sensors/getAllSensors');
104 },
105 methods: {
106 statusIcon(status) {
107 switch (status) {
108 case 'OK':
109 return 'success';
110 case 'Warning':
111 return 'warning';
112 case 'Critical':
113 return 'danger';
114 default:
115 return '';
116 }
117 },
118 sortCompare(a, b, key) {
119 if (key === 'status') {
120 const status = ['OK', 'Warning', 'Critical'];
121 return status.indexOf(a.status) - status.indexOf(b.status);
122 }
123 }
124 }
125};
126</script>