blob: 8bc4e22e0fe1a6456c75b8885830532aebd43ca6 [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 >
Derick Montague602e98a2020-10-21 16:20:00 -050030 <template #export>
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')"
Sukanya Pandey99010962020-07-27 21:44:47 +053056 @filtered="onFiltered"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070057 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070058 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070059 <!-- Checkbox column -->
Derick Montague602e98a2020-10-21 16:20:00 -050060 <template #head(checkbox)>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070061 <b-form-checkbox
62 v-model="tableHeaderCheckboxModel"
63 :indeterminate="tableHeaderCheckboxIndeterminate"
64 @change="onChangeHeaderCheckbox($refs.table)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060065 >
66 <span class="sr-only">{{ $t('global.table.selectAll') }}</span>
67 </b-form-checkbox>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070068 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050069 <template #cell(checkbox)="row">
Yoshie Muranakab1a71912020-04-29 10:52:39 -070070 <b-form-checkbox
71 v-model="row.rowSelected"
72 @change="toggleSelectRow($refs.table, row.index)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060073 >
74 <span class="sr-only">{{ $t('global.table.selectItem') }}</span>
75 </b-form-checkbox>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070076 </template>
77
Derick Montague602e98a2020-10-21 16:20:00 -050078 <template #cell(status)="{ value }">
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -050079 <status-icon :status="statusIcon(value)" /> {{ value }}
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070080 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050081 <template #cell(currentValue)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070082 {{ data.value }} {{ data.item.units }}
83 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050084 <template #cell(lowerCaution)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070085 {{ data.value }} {{ data.item.units }}
86 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050087 <template #cell(upperCaution)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070088 {{ data.value }} {{ data.item.units }}
89 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050090 <template #cell(lowerCritical)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070091 {{ data.value }} {{ data.item.units }}
92 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050093 <template #cell(upperCritical)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070094 {{ data.value }} {{ data.item.units }}
95 </template>
96 </b-table>
97 </b-col>
98 </b-row>
99 </b-container>
100</template>
101
102<script>
SurenNeware5e25e282020-07-08 15:57:23 +0530103import PageTitle from '@/components/Global/PageTitle';
104import Search from '@/components/Global/Search';
105import StatusIcon from '@/components/Global/StatusIcon';
106import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700107import TableToolbar from '@/components/Global/TableToolbar';
108import TableToolbarExport from '@/components/Global/TableToolbarExport';
Sukanya Pandey99010962020-07-27 21:44:47 +0530109import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700110
SurenNewareba91c492020-10-27 14:18:54 +0530111import BVTableSelectableMixin, {
112 selectedRows,
113 tableHeaderCheckboxModel,
114 tableHeaderCheckboxIndeterminate,
115} from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700116import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
SurenNeware5e25e282020-07-08 15:57:23 +0530117import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700118import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
119import TableSortMixin from '@/components/Mixins/TableSortMixin';
SurenNewareba91c492020-10-27 14:18:54 +0530120import SearchFilterMixin, {
121 searchFilter,
122} from '@/components/Mixins/SearchFilterMixin';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700123
124export default {
125 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700126 components: {
127 PageTitle,
SurenNeware71724be2020-06-01 15:31:00 +0530128 Search,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700129 StatusIcon,
Sukanya Pandey99010962020-07-27 21:44:47 +0530130 TableCellCount,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700131 TableFilter,
132 TableToolbar,
Derick Montague602e98a2020-10-21 16:20:00 -0500133 TableToolbarExport,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700134 },
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700135 mixins: [
136 TableFilterMixin,
137 BVTableSelectableMixin,
138 LoadingBarMixin,
139 TableDataFormatterMixin,
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500140 TableSortMixin,
Derick Montague602e98a2020-10-21 16:20:00 -0500141 SearchFilterMixin,
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700142 ],
Derick Montague602e98a2020-10-21 16:20:00 -0500143 beforeRouteLeave(to, from, next) {
144 this.hideLoader();
145 next();
146 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700147 data() {
148 return {
149 fields: [
150 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700151 key: 'checkbox',
152 sortable: false,
Derick Montague602e98a2020-10-21 16:20:00 -0500153 label: '',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700154 },
155 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700156 key: 'name',
157 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500158 label: this.$t('pageSensors.table.name'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700159 },
160 {
161 key: 'status',
162 sortable: true,
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -0500163 label: this.$t('pageSensors.table.status'),
Derick Montague602e98a2020-10-21 16:20:00 -0500164 tdClass: 'text-nowrap',
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700165 },
166 {
167 key: 'lowerCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700168 formatter: this.tableFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500169 label: this.$t('pageSensors.table.lowerCritical'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700170 },
171 {
172 key: 'lowerCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700173 formatter: this.tableFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500174 label: this.$t('pageSensors.table.lowerWarning'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700175 },
176
177 {
178 key: 'currentValue',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700179 formatter: this.tableFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500180 label: this.$t('pageSensors.table.currentValue'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700181 },
182 {
183 key: 'upperCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700184 formatter: this.tableFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500185 label: this.$t('pageSensors.table.upperWarning'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700186 },
187 {
188 key: 'upperCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700189 formatter: this.tableFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500190 label: this.$t('pageSensors.table.upperCritical'),
191 },
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700192 ],
193 tableFilters: [
194 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700195 key: 'status',
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700196 label: this.$t('pageSensors.table.status'),
Derick Montague602e98a2020-10-21 16:20:00 -0500197 values: ['OK', 'Warning', 'Critical'],
198 },
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700199 ],
SurenNeware71724be2020-06-01 15:31:00 +0530200 activeFilters: [],
SurenNewareba91c492020-10-27 14:18:54 +0530201 searchFilter: searchFilter,
Derick Montague602e98a2020-10-21 16:20:00 -0500202 searchTotalFilteredRows: 0,
SurenNewareba91c492020-10-27 14:18:54 +0530203 selectedRows: selectedRows,
204 tableHeaderCheckboxModel: tableHeaderCheckboxModel,
205 tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700206 };
207 },
208 computed: {
209 allSensors() {
210 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700211 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530212 filteredRows() {
213 return this.searchFilter
214 ? this.searchTotalFilteredRows
215 : this.filteredSensors.length;
216 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700217 filteredSensors() {
218 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Derick Montague602e98a2020-10-21 16:20:00 -0500219 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700220 },
221 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700222 this.startLoader();
223 this.$store
224 .dispatch('sensors/getAllSensors')
225 .finally(() => this.endLoader());
226 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700227 methods: {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700228 sortCompare(a, b, key) {
229 if (key === 'status') {
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700230 return this.sortStatus(a, b, key);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700231 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700232 },
233 onFilterChange({ activeFilters }) {
234 this.activeFilters = activeFilters;
SurenNeware71724be2020-06-01 15:31:00 +0530235 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530236 onFiltered(filteredItems) {
237 this.searchTotalFilteredRows = filteredItems.length;
SurenNeware1471f8f2020-09-18 18:41:22 +0530238 },
239 onChangeSearchInput(event) {
240 this.searchFilter = event;
241 },
242 exportFileNameByDate() {
243 // Create export file name based on date
244 let date = new Date();
245 date =
246 date.toISOString().slice(0, 10) +
247 '_' +
Derick Montague602e98a2020-10-21 16:20:00 -0500248 date.toString().split(':').join('-').split(' ')[4];
SurenNeware1471f8f2020-09-18 18:41:22 +0530249 return this.$t('pageSensors.exportFilePrefix') + date;
Derick Montague602e98a2020-10-21 16:20:00 -0500250 },
251 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700252};
253</script>