blob: e1cea8223bebecda36f4dbf251981b0993c704db [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>
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')"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +05308 @change-search="onChangeSearchInput"
9 @clear-search="onClearSearchInput"
SurenNeware71724be2020-06-01 15:31:00 +053010 />
11 </b-col>
Sukanya Pandey99010962020-07-27 21:44:47 +053012 <b-col sm="3" md="3" xl="2">
13 <table-cell-count
14 :filtered-items-count="filteredRows"
15 :total-number-of-cells="allSensors.length"
16 ></table-cell-count>
17 </b-col>
18 <b-col sm="3" md="4" xl="6" class="text-right">
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053019 <table-filter :filters="tableFilters" @filter-change="onFilterChange" />
Yoshie Muranaka82cca542020-04-07 10:20:37 -070020 </b-col>
21 </b-row>
22 <b-row>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070023 <b-col xl="12">
Yoshie Muranakab1a71912020-04-29 10:52:39 -070024 <table-toolbar
25 ref="toolbar"
26 :selected-items-count="selectedRows.length"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053027 @clear-selected="clearSelectedRows($refs.table)"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070028 >
Derick Montague602e98a2020-10-21 16:20:00 -050029 <template #export>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070030 <table-toolbar-export
31 :data="selectedRows"
SurenNeware1471f8f2020-09-18 18:41:22 +053032 :file-name="exportFileNameByDate()"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070033 />
34 </template>
35 </table-toolbar>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070036 <b-table
Yoshie Muranakab1a71912020-04-29 10:52:39 -070037 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053038 responsive="md"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070039 selectable
40 no-select-on-click
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070041 sort-icon-left
Sukanya Pandeyfde429e2020-09-14 20:48:39 +053042 hover
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070043 no-sort-reset
44 sticky-header="75vh"
45 sort-by="status"
SurenNeware307382e2020-07-27 20:45:14 +053046 show-empty
Mateusz Gapski1d2da292020-09-10 12:07:45 +020047 :no-border-collapse="true"
Yoshie Muranaka82cca542020-04-07 10:20:37 -070048 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070049 :fields="fields"
50 :sort-desc="true"
51 :sort-compare="sortCompare"
SurenNeware71724be2020-06-01 15:31:00 +053052 :filter="searchFilter"
SurenNeware307382e2020-07-27 20:45:14 +053053 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053054 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Sukanya Pandey99010962020-07-27 21:44:47 +053055 @filtered="onFiltered"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070056 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070057 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070058 <!-- Checkbox column -->
Derick Montague602e98a2020-10-21 16:20:00 -050059 <template #head(checkbox)>
Yoshie Muranakab1a71912020-04-29 10:52:39 -070060 <b-form-checkbox
61 v-model="tableHeaderCheckboxModel"
62 :indeterminate="tableHeaderCheckboxIndeterminate"
63 @change="onChangeHeaderCheckbox($refs.table)"
64 />
65 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050066 <template #cell(checkbox)="row">
Yoshie Muranakab1a71912020-04-29 10:52:39 -070067 <b-form-checkbox
68 v-model="row.rowSelected"
69 @change="toggleSelectRow($refs.table, row.index)"
70 />
71 </template>
72
Derick Montague602e98a2020-10-21 16:20:00 -050073 <template #cell(status)="{ value }">
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -050074 <status-icon :status="statusIcon(value)" /> {{ value }}
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070075 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050076 <template #cell(currentValue)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070077 {{ data.value }} {{ data.item.units }}
78 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050079 <template #cell(lowerCaution)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070080 {{ data.value }} {{ data.item.units }}
81 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050082 <template #cell(upperCaution)="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(lowerCritical)="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(upperCritical)="data">
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070089 {{ data.value }} {{ data.item.units }}
90 </template>
91 </b-table>
92 </b-col>
93 </b-row>
94 </b-container>
95</template>
96
97<script>
SurenNeware5e25e282020-07-08 15:57:23 +053098import PageTitle from '@/components/Global/PageTitle';
99import Search from '@/components/Global/Search';
100import StatusIcon from '@/components/Global/StatusIcon';
101import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700102import TableToolbar from '@/components/Global/TableToolbar';
103import TableToolbarExport from '@/components/Global/TableToolbarExport';
Sukanya Pandey99010962020-07-27 21:44:47 +0530104import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700105
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700106import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700107import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
SurenNeware5e25e282020-07-08 15:57:23 +0530108import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700109import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
110import TableSortMixin from '@/components/Mixins/TableSortMixin';
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500111import SearchFilterMixin from '@/components/Mixins/SearchFilterMixin';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700112
113export default {
114 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700115 components: {
116 PageTitle,
SurenNeware71724be2020-06-01 15:31:00 +0530117 Search,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700118 StatusIcon,
Sukanya Pandey99010962020-07-27 21:44:47 +0530119 TableCellCount,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700120 TableFilter,
121 TableToolbar,
Derick Montague602e98a2020-10-21 16:20:00 -0500122 TableToolbarExport,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700123 },
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700124 mixins: [
125 TableFilterMixin,
126 BVTableSelectableMixin,
127 LoadingBarMixin,
128 TableDataFormatterMixin,
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500129 TableSortMixin,
Derick Montague602e98a2020-10-21 16:20:00 -0500130 SearchFilterMixin,
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700131 ],
Derick Montague602e98a2020-10-21 16:20:00 -0500132 beforeRouteLeave(to, from, next) {
133 this.hideLoader();
134 next();
135 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700136 data() {
137 return {
138 fields: [
139 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700140 key: 'checkbox',
141 sortable: false,
Derick Montague602e98a2020-10-21 16:20:00 -0500142 label: '',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700143 },
144 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700145 key: 'name',
146 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500147 label: this.$t('pageSensors.table.name'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700148 },
149 {
150 key: 'status',
151 sortable: true,
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -0500152 label: this.$t('pageSensors.table.status'),
Derick Montague602e98a2020-10-21 16:20:00 -0500153 tdClass: 'text-nowrap',
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700154 },
155 {
156 key: 'lowerCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700157 formatter: this.tableFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500158 label: this.$t('pageSensors.table.lowerCritical'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700159 },
160 {
161 key: 'lowerCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700162 formatter: this.tableFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500163 label: this.$t('pageSensors.table.lowerWarning'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700164 },
165
166 {
167 key: 'currentValue',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700168 formatter: this.tableFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500169 label: this.$t('pageSensors.table.currentValue'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700170 },
171 {
172 key: 'upperCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700173 formatter: this.tableFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500174 label: this.$t('pageSensors.table.upperWarning'),
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700175 },
176 {
177 key: 'upperCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700178 formatter: this.tableFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500179 label: this.$t('pageSensors.table.upperCritical'),
180 },
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700181 ],
182 tableFilters: [
183 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700184 key: 'status',
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700185 label: this.$t('pageSensors.table.status'),
Derick Montague602e98a2020-10-21 16:20:00 -0500186 values: ['OK', 'Warning', 'Critical'],
187 },
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700188 ],
SurenNeware71724be2020-06-01 15:31:00 +0530189 activeFilters: [],
Derick Montague602e98a2020-10-21 16:20:00 -0500190 searchTotalFilteredRows: 0,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700191 };
192 },
193 computed: {
194 allSensors() {
195 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700196 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530197 filteredRows() {
198 return this.searchFilter
199 ? this.searchTotalFilteredRows
200 : this.filteredSensors.length;
201 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700202 filteredSensors() {
203 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Derick Montague602e98a2020-10-21 16:20:00 -0500204 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700205 },
206 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700207 this.startLoader();
208 this.$store
209 .dispatch('sensors/getAllSensors')
210 .finally(() => this.endLoader());
211 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700212 methods: {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700213 sortCompare(a, b, key) {
214 if (key === 'status') {
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700215 return this.sortStatus(a, b, key);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700216 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700217 },
218 onFilterChange({ activeFilters }) {
219 this.activeFilters = activeFilters;
SurenNeware71724be2020-06-01 15:31:00 +0530220 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530221 onFiltered(filteredItems) {
222 this.searchTotalFilteredRows = filteredItems.length;
SurenNeware1471f8f2020-09-18 18:41:22 +0530223 },
224 onChangeSearchInput(event) {
225 this.searchFilter = event;
226 },
227 exportFileNameByDate() {
228 // Create export file name based on date
229 let date = new Date();
230 date =
231 date.toISOString().slice(0, 10) +
232 '_' +
Derick Montague602e98a2020-10-21 16:20:00 -0500233 date.toString().split(':').join('-').split(' ')[4];
SurenNeware1471f8f2020-09-18 18:41:22 +0530234 return this.$t('pageSensors.exportFilePrefix') + date;
Derick Montague602e98a2020-10-21 16:20:00 -0500235 },
236 },
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700237};
238</script>