blob: c4663a94c40f91b060b8323b930bd733e5351174 [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 />
SurenNeware787635a2020-11-24 22:42:42 +05304 <b-row class="align-items-end">
Sukanya Pandey99010962020-07-27 21:44:47 +05305 <b-col sm="6" md="5" xl="4">
SurenNeware71724be2020-06-01 15:31:00 +05306 <search
7 :placeholder="$t('pageSensors.searchForSensors')"
Sandeepa Singhb28e2432021-02-10 19:26:21 +05308 data-test-id="sensors-input-searchForSensors"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +05309 @change-search="onChangeSearchInput"
10 @clear-search="onClearSearchInput"
SurenNeware71724be2020-06-01 15:31:00 +053011 />
12 </b-col>
Sukanya Pandey99010962020-07-27 21:44:47 +053013 <b-col sm="3" md="3" xl="2">
14 <table-cell-count
15 :filtered-items-count="filteredRows"
16 :total-number-of-cells="allSensors.length"
17 ></table-cell-count>
18 </b-col>
19 <b-col sm="3" md="4" xl="6" class="text-right">
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053020 <table-filter :filters="tableFilters" @filter-change="onFilterChange" />
Yoshie Muranaka82cca542020-04-07 10:20:37 -070021 </b-col>
22 </b-row>
23 <b-row>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070024 <b-col xl="12">
Yoshie Muranakab1a71912020-04-29 10:52:39 -070025 <table-toolbar
26 ref="toolbar"
27 :selected-items-count="selectedRows.length"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053028 @clear-selected="clearSelectedRows($refs.table)"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070029 >
Dixsie Wolmers27d68af2021-05-02 18:20:27 -050030 <template #toolbar-buttons>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070031 <table-toolbar-export
32 :data="selectedRows"
SurenNeware1471f8f2020-09-18 18:41:22 +053033 :file-name="exportFileNameByDate()"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070034 />
35 </template>
36 </table-toolbar>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070037 <b-table
Yoshie Muranakab1a71912020-04-29 10:52:39 -070038 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053039 responsive="md"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070040 selectable
41 no-select-on-click
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070042 sort-icon-left
Sukanya Pandeyfde429e2020-09-14 20:48:39 +053043 hover
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070044 no-sort-reset
45 sticky-header="75vh"
46 sort-by="status"
SurenNeware307382e2020-07-27 20:45:14 +053047 show-empty
Mateusz Gapski1d2da292020-09-10 12:07:45 +020048 :no-border-collapse="true"
Yoshie Muranaka82cca542020-04-07 10:20:37 -070049 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070050 :fields="fields"
51 :sort-desc="true"
52 :sort-compare="sortCompare"
SurenNeware71724be2020-06-01 15:31:00 +053053 :filter="searchFilter"
SurenNeware307382e2020-07-27 20:45:14 +053054 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053055 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Kenneth Fullbright41057852021-12-27 16:19:37 -060056 :busy="isBusy"
Sukanya Pandey99010962020-07-27 21:44:47 +053057 @filtered="onFiltered"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070058 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070059 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070060 <!-- Checkbox column -->
Derick Montague602e98a2020-10-21 16:20:00 -050061 <template #head(checkbox)>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070062 <b-form-checkbox
63 v-model="tableHeaderCheckboxModel"
64 :indeterminate="tableHeaderCheckboxIndeterminate"
65 @change="onChangeHeaderCheckbox($refs.table)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060066 >
67 <span class="sr-only">{{ $t('global.table.selectAll') }}</span>
68 </b-form-checkbox>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070069 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050070 <template #cell(checkbox)="row">
Yoshie Muranakab1a71912020-04-29 10:52:39 -070071 <b-form-checkbox
72 v-model="row.rowSelected"
73 @change="toggleSelectRow($refs.table, row.index)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060074 >
75 <span class="sr-only">{{ $t('global.table.selectItem') }}</span>
76 </b-form-checkbox>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070077 </template>
78
Derick Montague602e98a2020-10-21 16:20:00 -050079 <template #cell(status)="{ value }">
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -050080 <status-icon :status="statusIcon(value)" /> {{ value }}
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070081 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050082 <template #cell(currentValue)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070083 {{ data.value }} {{ data.item.units }}
84 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050085 <template #cell(lowerCaution)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070086 {{ data.value }} {{ data.item.units }}
87 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050088 <template #cell(upperCaution)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070089 {{ data.value }} {{ data.item.units }}
90 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050091 <template #cell(lowerCritical)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070092 {{ data.value }} {{ data.item.units }}
93 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050094 <template #cell(upperCritical)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070095 {{ data.value }} {{ data.item.units }}
96 </template>
97 </b-table>
98 </b-col>
99 </b-row>
100 </b-container>
101</template>
102
103<script>
SurenNeware5e25e282020-07-08 15:57:23 +0530104import PageTitle from '@/components/Global/PageTitle';
105import Search from '@/components/Global/Search';
106import StatusIcon from '@/components/Global/StatusIcon';
107import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700108import TableToolbar from '@/components/Global/TableToolbar';
109import TableToolbarExport from '@/components/Global/TableToolbarExport';
Sukanya Pandey99010962020-07-27 21:44:47 +0530110import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700111
SurenNewareba91c492020-10-27 14:18:54 +0530112import BVTableSelectableMixin, {
113 selectedRows,
114 tableHeaderCheckboxModel,
115 tableHeaderCheckboxIndeterminate,
116} from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700117import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
SurenNeware5e25e282020-07-08 15:57:23 +0530118import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500119import DataFormatterMixin from '@/components/Mixins/DataFormatterMixin';
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700120import TableSortMixin from '@/components/Mixins/TableSortMixin';
SurenNewareba91c492020-10-27 14:18:54 +0530121import SearchFilterMixin, {
122 searchFilter,
123} from '@/components/Mixins/SearchFilterMixin';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700124
125export default {
126 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700127 components: {
128 PageTitle,
SurenNeware71724be2020-06-01 15:31:00 +0530129 Search,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700130 StatusIcon,
Sukanya Pandey99010962020-07-27 21:44:47 +0530131 TableCellCount,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700132 TableFilter,
133 TableToolbar,
Derick Montague602e98a2020-10-21 16:20:00 -0500134 TableToolbarExport,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700135 },
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700136 mixins: [
137 TableFilterMixin,
138 BVTableSelectableMixin,
139 LoadingBarMixin,
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500140 DataFormatterMixin,
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500141 TableSortMixin,
Derick Montague602e98a2020-10-21 16:20:00 -0500142 SearchFilterMixin,
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700143 ],
Derick Montague602e98a2020-10-21 16:20:00 -0500144 beforeRouteLeave(to, from, next) {
145 this.hideLoader();
146 next();
147 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700148 data() {
149 return {
Kenneth Fullbright41057852021-12-27 16:19:37 -0600150 isBusy: true,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700151 fields: [
152 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700153 key: 'checkbox',
154 sortable: false,
Derick Montague602e98a2020-10-21 16:20:00 -0500155 label: '',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700156 },
157 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700158 key: 'name',
159 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500160 label: this.$t('pageSensors.table.name'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700161 },
162 {
163 key: 'status',
164 sortable: true,
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -0500165 label: this.$t('pageSensors.table.status'),
Derick Montague602e98a2020-10-21 16:20:00 -0500166 tdClass: 'text-nowrap',
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700167 },
168 {
169 key: 'lowerCritical',
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500170 formatter: this.dataFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500171 label: this.$t('pageSensors.table.lowerCritical'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700172 },
173 {
174 key: 'lowerCaution',
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500175 formatter: this.dataFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500176 label: this.$t('pageSensors.table.lowerWarning'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700177 },
178
179 {
180 key: 'currentValue',
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500181 formatter: this.dataFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500182 label: this.$t('pageSensors.table.currentValue'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700183 },
184 {
185 key: 'upperCaution',
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500186 formatter: this.dataFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500187 label: this.$t('pageSensors.table.upperWarning'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700188 },
189 {
190 key: 'upperCritical',
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500191 formatter: this.dataFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500192 label: this.$t('pageSensors.table.upperCritical'),
193 },
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700194 ],
195 tableFilters: [
196 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700197 key: 'status',
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700198 label: this.$t('pageSensors.table.status'),
kirankumarb073bf966a2023-02-07 19:12:33 +0530199 values: [
200 this.$t('global.action.ok'),
201 this.$t('global.action.warning'),
202 this.$t('global.action.critical'),
203 ],
Derick Montague602e98a2020-10-21 16:20:00 -0500204 },
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700205 ],
SurenNeware71724be2020-06-01 15:31:00 +0530206 activeFilters: [],
SurenNewareba91c492020-10-27 14:18:54 +0530207 searchFilter: searchFilter,
Derick Montague602e98a2020-10-21 16:20:00 -0500208 searchTotalFilteredRows: 0,
SurenNewareba91c492020-10-27 14:18:54 +0530209 selectedRows: selectedRows,
210 tableHeaderCheckboxModel: tableHeaderCheckboxModel,
211 tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700212 };
213 },
214 computed: {
215 allSensors() {
216 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700217 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530218 filteredRows() {
219 return this.searchFilter
220 ? this.searchTotalFilteredRows
221 : this.filteredSensors.length;
222 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700223 filteredSensors() {
224 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Derick Montague602e98a2020-10-21 16:20:00 -0500225 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700226 },
227 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700228 this.startLoader();
Kenneth Fullbright41057852021-12-27 16:19:37 -0600229 this.$store.dispatch('sensors/getAllSensors').finally(() => {
230 this.endLoader();
231 this.isBusy = false;
232 });
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700233 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700234 methods: {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700235 sortCompare(a, b, key) {
236 if (key === 'status') {
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700237 return this.sortStatus(a, b, key);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700238 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700239 },
240 onFilterChange({ activeFilters }) {
241 this.activeFilters = activeFilters;
SurenNeware71724be2020-06-01 15:31:00 +0530242 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530243 onFiltered(filteredItems) {
244 this.searchTotalFilteredRows = filteredItems.length;
SurenNeware1471f8f2020-09-18 18:41:22 +0530245 },
246 onChangeSearchInput(event) {
247 this.searchFilter = event;
248 },
249 exportFileNameByDate() {
250 // Create export file name based on date
251 let date = new Date();
252 date =
253 date.toISOString().slice(0, 10) +
254 '_' +
Derick Montague602e98a2020-10-21 16:20:00 -0500255 date.toString().split(':').join('-').split(' ')[4];
SurenNeware1471f8f2020-09-18 18:41:22 +0530256 return this.$t('pageSensors.exportFilePrefix') + date;
Derick Montague602e98a2020-10-21 16:20:00 -0500257 },
258 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700259};
260</script>