blob: 6de5c9e71de3648f64cdd838acc4c28cc1255e9f [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">
Yoshie Muranakab1a71912020-04-29 10:52:39 -070011 <table-toolbar
12 ref="toolbar"
13 :selected-items-count="selectedRows.length"
14 @clearSelected="clearSelectedRows($refs.table)"
15 >
16 <template v-slot:export>
17 <table-toolbar-export
18 :data="selectedRows"
19 :file-name="$t('appPageTitle.sensors')"
20 />
21 </template>
22 </table-toolbar>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070023 <b-table
Yoshie Muranakab1a71912020-04-29 10:52:39 -070024 ref="table"
25 selectable
26 no-select-on-click
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070027 sort-icon-left
28 no-sort-reset
29 sticky-header="75vh"
30 sort-by="status"
Yoshie Muranaka82cca542020-04-07 10:20:37 -070031 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070032 :fields="fields"
33 :sort-desc="true"
34 :sort-compare="sortCompare"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070035 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070036 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070037 <!-- Checkbox column -->
38 <template v-slot:head(checkbox)>
39 <b-form-checkbox
40 v-model="tableHeaderCheckboxModel"
41 :indeterminate="tableHeaderCheckboxIndeterminate"
42 @change="onChangeHeaderCheckbox($refs.table)"
43 />
44 </template>
45 <template v-slot:cell(checkbox)="row">
46 <b-form-checkbox
47 v-model="row.rowSelected"
48 @change="toggleSelectRow($refs.table, row.index)"
49 />
50 </template>
51
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070052 <template v-slot:cell(status)="{ value }">
53 <status-icon :status="statusIcon(value)" />
54 {{ value }}
55 </template>
56 <template v-slot:cell(currentValue)="data">
57 {{ data.value }} {{ data.item.units }}
58 </template>
59 <template v-slot:cell(lowerCaution)="data">
60 {{ data.value }} {{ data.item.units }}
61 </template>
62 <template v-slot:cell(upperCaution)="data">
63 {{ data.value }} {{ data.item.units }}
64 </template>
65 <template v-slot:cell(lowerCritical)="data">
66 {{ data.value }} {{ data.item.units }}
67 </template>
68 <template v-slot:cell(upperCritical)="data">
69 {{ data.value }} {{ data.item.units }}
70 </template>
71 </b-table>
72 </b-col>
73 </b-row>
74 </b-container>
75</template>
76
77<script>
78import PageTitle from '../../../components/Global/PageTitle';
79import StatusIcon from '../../../components/Global/StatusIcon';
Yoshie Muranaka82cca542020-04-07 10:20:37 -070080import TableFilter from '../../../components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -070081import TableToolbar from '@/components/Global/TableToolbar';
82import TableToolbarExport from '@/components/Global/TableToolbarExport';
83
Yoshie Muranaka82cca542020-04-07 10:20:37 -070084import TableFilterMixin from '../../../components/Mixins/TableFilterMixin';
Yoshie Muranakab1a71912020-04-29 10:52:39 -070085import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka82cca542020-04-07 10:20:37 -070086
87const SENSOR_STATUS = ['OK', 'Warning', 'Critical'];
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070088
89const valueFormatter = value => {
90 if (value === null || value === undefined) {
91 return '--';
92 }
93 return parseFloat(value.toFixed(3));
94};
95
96export default {
97 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -070098 components: {
99 PageTitle,
100 StatusIcon,
101 TableFilter,
102 TableToolbar,
103 TableToolbarExport
104 },
105 mixins: [TableFilterMixin, BVTableSelectableMixin],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700106 data() {
107 return {
108 fields: [
109 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700110 key: 'checkbox',
111 sortable: false,
112 label: ''
113 },
114 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700115 key: 'name',
116 sortable: true,
117 label: this.$t('pageSensors.table.name')
118 },
119 {
120 key: 'status',
121 sortable: true,
122 label: this.$t('pageSensors.table.status')
123 },
124 {
125 key: 'lowerCritical',
126 formatter: valueFormatter,
127 label: this.$t('pageSensors.table.lowerCritical')
128 },
129 {
130 key: 'lowerCaution',
131 formatter: valueFormatter,
132 label: this.$t('pageSensors.table.lowerWarning')
133 },
134
135 {
136 key: 'currentValue',
137 formatter: valueFormatter,
138 label: this.$t('pageSensors.table.currentValue')
139 },
140 {
141 key: 'upperCaution',
142 formatter: valueFormatter,
143 label: this.$t('pageSensors.table.upperWarning')
144 },
145 {
146 key: 'upperCritical',
147 formatter: valueFormatter,
148 label: this.$t('pageSensors.table.upperCritical')
149 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700150 ],
151 tableFilters: [
152 {
153 label: this.$t('pageSensors.table.status'),
154 values: SENSOR_STATUS
155 }
156 ],
157 activeFilters: []
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700158 };
159 },
160 computed: {
161 allSensors() {
162 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700163 },
164 filteredSensors: {
165 get: function() {
166 return this.getFilteredTableData(this.allSensors, this.activeFilters);
167 },
168 set: function(newVal) {
169 return newVal;
170 }
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700171 }
172 },
173 created() {
174 this.$store.dispatch('sensors/getAllSensors');
175 },
176 methods: {
177 statusIcon(status) {
178 switch (status) {
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700179 case SENSOR_STATUS[0]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700180 return 'success';
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700181 case SENSOR_STATUS[1]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700182 return 'warning';
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700183 case SENSOR_STATUS[2]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700184 return 'danger';
185 default:
186 return '';
187 }
188 },
189 sortCompare(a, b, key) {
190 if (key === 'status') {
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700191 return (
192 SENSOR_STATUS.indexOf(a.status) - SENSOR_STATUS.indexOf(b.status)
193 );
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700194 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700195 },
196 onFilterChange({ activeFilters }) {
197 this.activeFilters = activeFilters;
198 this.filteredSensors = this.getFilteredTableData(
199 this.allSensors,
200 activeFilters
201 );
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700202 }
203 }
204};
205</script>