blob: 3b368976e35a9b0cf06fc9912b049f1baaff64c5 [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>
SurenNeware71724be2020-06-01 15:31:00 +05305 <b-col md="5" xl="4">
6 <search
7 :placeholder="$t('pageSensors.searchForSensors')"
8 @changeSearch="onChangeSearchInput"
9 />
10 </b-col>
11 <b-col md="7" xl="8" class="text-right">
Yoshie Muranaka82cca542020-04-07 10:20:37 -070012 <table-filter :filters="tableFilters" @filterChange="onFilterChange" />
13 </b-col>
14 </b-row>
15 <b-row>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070016 <b-col xl="12">
Yoshie Muranakab1a71912020-04-29 10:52:39 -070017 <table-toolbar
18 ref="toolbar"
19 :selected-items-count="selectedRows.length"
20 @clearSelected="clearSelectedRows($refs.table)"
21 >
22 <template v-slot:export>
23 <table-toolbar-export
24 :data="selectedRows"
25 :file-name="$t('appPageTitle.sensors')"
26 />
27 </template>
28 </table-toolbar>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070029 <b-table
Yoshie Muranakab1a71912020-04-29 10:52:39 -070030 ref="table"
31 selectable
32 no-select-on-click
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070033 sort-icon-left
34 no-sort-reset
35 sticky-header="75vh"
36 sort-by="status"
Yoshie Muranaka82cca542020-04-07 10:20:37 -070037 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070038 :fields="fields"
39 :sort-desc="true"
40 :sort-compare="sortCompare"
SurenNeware71724be2020-06-01 15:31:00 +053041 :filter="searchFilter"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070042 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070043 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070044 <!-- Checkbox column -->
45 <template v-slot:head(checkbox)>
46 <b-form-checkbox
47 v-model="tableHeaderCheckboxModel"
48 :indeterminate="tableHeaderCheckboxIndeterminate"
49 @change="onChangeHeaderCheckbox($refs.table)"
50 />
51 </template>
52 <template v-slot:cell(checkbox)="row">
53 <b-form-checkbox
54 v-model="row.rowSelected"
55 @change="toggleSelectRow($refs.table, row.index)"
56 />
57 </template>
58
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070059 <template v-slot:cell(status)="{ value }">
60 <status-icon :status="statusIcon(value)" />
61 {{ value }}
62 </template>
63 <template v-slot:cell(currentValue)="data">
64 {{ data.value }} {{ data.item.units }}
65 </template>
66 <template v-slot:cell(lowerCaution)="data">
67 {{ data.value }} {{ data.item.units }}
68 </template>
69 <template v-slot:cell(upperCaution)="data">
70 {{ data.value }} {{ data.item.units }}
71 </template>
72 <template v-slot:cell(lowerCritical)="data">
73 {{ data.value }} {{ data.item.units }}
74 </template>
75 <template v-slot:cell(upperCritical)="data">
76 {{ data.value }} {{ data.item.units }}
77 </template>
78 </b-table>
79 </b-col>
80 </b-row>
81 </b-container>
82</template>
83
84<script>
85import PageTitle from '../../../components/Global/PageTitle';
SurenNeware71724be2020-06-01 15:31:00 +053086import Search from '../../../components/Global/Search';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070087import StatusIcon from '../../../components/Global/StatusIcon';
Yoshie Muranaka82cca542020-04-07 10:20:37 -070088import TableFilter from '../../../components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -070089import TableToolbar from '@/components/Global/TableToolbar';
90import TableToolbarExport from '@/components/Global/TableToolbarExport';
91
Yoshie Muranaka82cca542020-04-07 10:20:37 -070092import TableFilterMixin from '../../../components/Mixins/TableFilterMixin';
Yoshie Muranakab1a71912020-04-29 10:52:39 -070093import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka50ff1832020-05-01 11:00:17 -070094import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranaka82cca542020-04-07 10:20:37 -070095
96const SENSOR_STATUS = ['OK', 'Warning', 'Critical'];
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070097
98const valueFormatter = value => {
99 if (value === null || value === undefined) {
100 return '--';
101 }
102 return parseFloat(value.toFixed(3));
103};
104
105export default {
106 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700107 components: {
108 PageTitle,
SurenNeware71724be2020-06-01 15:31:00 +0530109 Search,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700110 StatusIcon,
111 TableFilter,
112 TableToolbar,
113 TableToolbarExport
114 },
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700115 mixins: [TableFilterMixin, BVTableSelectableMixin, LoadingBarMixin],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700116 data() {
117 return {
118 fields: [
119 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700120 key: 'checkbox',
121 sortable: false,
122 label: ''
123 },
124 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700125 key: 'name',
126 sortable: true,
127 label: this.$t('pageSensors.table.name')
128 },
129 {
130 key: 'status',
131 sortable: true,
132 label: this.$t('pageSensors.table.status')
133 },
134 {
135 key: 'lowerCritical',
136 formatter: valueFormatter,
137 label: this.$t('pageSensors.table.lowerCritical')
138 },
139 {
140 key: 'lowerCaution',
141 formatter: valueFormatter,
142 label: this.$t('pageSensors.table.lowerWarning')
143 },
144
145 {
146 key: 'currentValue',
147 formatter: valueFormatter,
148 label: this.$t('pageSensors.table.currentValue')
149 },
150 {
151 key: 'upperCaution',
152 formatter: valueFormatter,
153 label: this.$t('pageSensors.table.upperWarning')
154 },
155 {
156 key: 'upperCritical',
157 formatter: valueFormatter,
158 label: this.$t('pageSensors.table.upperCritical')
159 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700160 ],
161 tableFilters: [
162 {
163 label: this.$t('pageSensors.table.status'),
164 values: SENSOR_STATUS
165 }
166 ],
SurenNeware71724be2020-06-01 15:31:00 +0530167 activeFilters: [],
168 searchFilter: null
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700169 };
170 },
171 computed: {
172 allSensors() {
173 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700174 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700175 filteredSensors() {
176 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700177 }
178 },
179 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700180 this.startLoader();
181 this.$store
182 .dispatch('sensors/getAllSensors')
183 .finally(() => this.endLoader());
184 },
185 beforeRouteLeave(to, from, next) {
186 this.hideLoader();
187 next();
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700188 },
189 methods: {
190 statusIcon(status) {
191 switch (status) {
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700192 case SENSOR_STATUS[0]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700193 return 'success';
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700194 case SENSOR_STATUS[1]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700195 return 'warning';
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700196 case SENSOR_STATUS[2]:
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700197 return 'danger';
198 default:
199 return '';
200 }
201 },
202 sortCompare(a, b, key) {
203 if (key === 'status') {
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700204 return (
205 SENSOR_STATUS.indexOf(a.status) - SENSOR_STATUS.indexOf(b.status)
206 );
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700207 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700208 },
209 onFilterChange({ activeFilters }) {
210 this.activeFilters = activeFilters;
SurenNeware71724be2020-06-01 15:31:00 +0530211 },
212 onChangeSearchInput(event) {
213 this.searchFilter = event;
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700214 }
215 }
216};
217</script>