blob: 6cd70be8b7c935b14705e5cd66065fe9561f9d32 [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 Muranaka50ff1832020-05-01 11:00:17 -070086import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranaka82cca542020-04-07 10:20:37 -070087
88const SENSOR_STATUS = ['OK', 'Warning', 'Critical'];
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070089
90const valueFormatter = value => {
91 if (value === null || value === undefined) {
92 return '--';
93 }
94 return parseFloat(value.toFixed(3));
95};
96
97export default {
98 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -070099 components: {
100 PageTitle,
101 StatusIcon,
102 TableFilter,
103 TableToolbar,
104 TableToolbarExport
105 },
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700106 mixins: [TableFilterMixin, BVTableSelectableMixin, LoadingBarMixin],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700107 data() {
108 return {
109 fields: [
110 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700111 key: 'checkbox',
112 sortable: false,
113 label: ''
114 },
115 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700116 key: 'name',
117 sortable: true,
118 label: this.$t('pageSensors.table.name')
119 },
120 {
121 key: 'status',
122 sortable: true,
123 label: this.$t('pageSensors.table.status')
124 },
125 {
126 key: 'lowerCritical',
127 formatter: valueFormatter,
128 label: this.$t('pageSensors.table.lowerCritical')
129 },
130 {
131 key: 'lowerCaution',
132 formatter: valueFormatter,
133 label: this.$t('pageSensors.table.lowerWarning')
134 },
135
136 {
137 key: 'currentValue',
138 formatter: valueFormatter,
139 label: this.$t('pageSensors.table.currentValue')
140 },
141 {
142 key: 'upperCaution',
143 formatter: valueFormatter,
144 label: this.$t('pageSensors.table.upperWarning')
145 },
146 {
147 key: 'upperCritical',
148 formatter: valueFormatter,
149 label: this.$t('pageSensors.table.upperCritical')
150 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700151 ],
152 tableFilters: [
153 {
154 label: this.$t('pageSensors.table.status'),
155 values: SENSOR_STATUS
156 }
157 ],
158 activeFilters: []
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700159 };
160 },
161 computed: {
162 allSensors() {
163 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700164 },
165 filteredSensors: {
166 get: function() {
167 return this.getFilteredTableData(this.allSensors, this.activeFilters);
168 },
169 set: function(newVal) {
170 return newVal;
171 }
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700172 }
173 },
174 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700175 this.startLoader();
176 this.$store
177 .dispatch('sensors/getAllSensors')
178 .finally(() => this.endLoader());
179 },
180 beforeRouteLeave(to, from, next) {
181 this.hideLoader();
182 next();
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700183 },
184 methods: {
185 statusIcon(status) {
186 switch (status) {
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700187 case SENSOR_STATUS[0]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700188 return 'success';
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700189 case SENSOR_STATUS[1]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700190 return 'warning';
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700191 case SENSOR_STATUS[2]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700192 return 'danger';
193 default:
194 return '';
195 }
196 },
197 sortCompare(a, b, key) {
198 if (key === 'status') {
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700199 return (
200 SENSOR_STATUS.indexOf(a.status) - SENSOR_STATUS.indexOf(b.status)
201 );
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700202 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700203 },
204 onFilterChange({ activeFilters }) {
205 this.activeFilters = activeFilters;
206 this.filteredSensors = this.getFilteredTableData(
207 this.allSensors,
208 activeFilters
209 );
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700210 }
211 }
212};
213</script>