blob: fe9d3972b4acb8fc815573cff4ff77770d5671a5 [file] [log] [blame]
Yoshie Muranaka30abccb2020-03-11 12:44:24 -07001<template>
Yoshie Muranaka3111b6f2020-04-21 19:48:38 -07002 <b-container fluid="xl">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -07003 <page-title />
4 <b-row>
Yoshie Muranaka82cca542020-04-07 10:20:37 -07005 <b-col xl="12" class="text-right">
6 <table-filter :filters="tableFilters" @filterChange="onFilterChange" />
7 </b-col>
8 </b-row>
9 <b-row>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070010 <b-col xl="12">
11 <b-table
12 sort-icon-left
13 no-sort-reset
14 sticky-header="75vh"
15 sort-by="status"
Yoshie Muranaka82cca542020-04-07 10:20:37 -070016 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070017 :fields="fields"
18 :sort-desc="true"
19 :sort-compare="sortCompare"
20 >
21 <template v-slot:cell(status)="{ value }">
22 <status-icon :status="statusIcon(value)" />
23 {{ value }}
24 </template>
25 <template v-slot:cell(currentValue)="data">
26 {{ data.value }} {{ data.item.units }}
27 </template>
28 <template v-slot:cell(lowerCaution)="data">
29 {{ data.value }} {{ data.item.units }}
30 </template>
31 <template v-slot:cell(upperCaution)="data">
32 {{ data.value }} {{ data.item.units }}
33 </template>
34 <template v-slot:cell(lowerCritical)="data">
35 {{ data.value }} {{ data.item.units }}
36 </template>
37 <template v-slot:cell(upperCritical)="data">
38 {{ data.value }} {{ data.item.units }}
39 </template>
40 </b-table>
41 </b-col>
42 </b-row>
43 </b-container>
44</template>
45
46<script>
47import PageTitle from '../../../components/Global/PageTitle';
48import StatusIcon from '../../../components/Global/StatusIcon';
Yoshie Muranaka82cca542020-04-07 10:20:37 -070049import TableFilter from '../../../components/Global/TableFilter';
50import TableFilterMixin from '../../../components/Mixins/TableFilterMixin';
51
52const SENSOR_STATUS = ['OK', 'Warning', 'Critical'];
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070053
54const valueFormatter = value => {
55 if (value === null || value === undefined) {
56 return '--';
57 }
58 return parseFloat(value.toFixed(3));
59};
60
61export default {
62 name: 'Sensors',
Yoshie Muranaka82cca542020-04-07 10:20:37 -070063 components: { PageTitle, StatusIcon, TableFilter },
64 mixins: [TableFilterMixin],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070065 data() {
66 return {
67 fields: [
68 {
69 key: 'name',
70 sortable: true,
71 label: this.$t('pageSensors.table.name')
72 },
73 {
74 key: 'status',
75 sortable: true,
76 label: this.$t('pageSensors.table.status')
77 },
78 {
79 key: 'lowerCritical',
80 formatter: valueFormatter,
81 label: this.$t('pageSensors.table.lowerCritical')
82 },
83 {
84 key: 'lowerCaution',
85 formatter: valueFormatter,
86 label: this.$t('pageSensors.table.lowerWarning')
87 },
88
89 {
90 key: 'currentValue',
91 formatter: valueFormatter,
92 label: this.$t('pageSensors.table.currentValue')
93 },
94 {
95 key: 'upperCaution',
96 formatter: valueFormatter,
97 label: this.$t('pageSensors.table.upperWarning')
98 },
99 {
100 key: 'upperCritical',
101 formatter: valueFormatter,
102 label: this.$t('pageSensors.table.upperCritical')
103 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700104 ],
105 tableFilters: [
106 {
107 label: this.$t('pageSensors.table.status'),
108 values: SENSOR_STATUS
109 }
110 ],
111 activeFilters: []
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700112 };
113 },
114 computed: {
115 allSensors() {
116 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700117 },
118 filteredSensors: {
119 get: function() {
120 return this.getFilteredTableData(this.allSensors, this.activeFilters);
121 },
122 set: function(newVal) {
123 return newVal;
124 }
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700125 }
126 },
127 created() {
128 this.$store.dispatch('sensors/getAllSensors');
129 },
130 methods: {
131 statusIcon(status) {
132 switch (status) {
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700133 case SENSOR_STATUS[0]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700134 return 'success';
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700135 case SENSOR_STATUS[1]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700136 return 'warning';
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700137 case SENSOR_STATUS[2]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700138 return 'danger';
139 default:
140 return '';
141 }
142 },
143 sortCompare(a, b, key) {
144 if (key === 'status') {
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700145 return (
146 SENSOR_STATUS.indexOf(a.status) - SENSOR_STATUS.indexOf(b.status)
147 );
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700148 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700149 },
150 onFilterChange({ activeFilters }) {
151 this.activeFilters = activeFilters;
152 this.filteredSensors = this.getFilteredTableData(
153 this.allSensors,
154 activeFilters
155 );
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700156 }
157 }
158};
159</script>