blob: c2343591bdc046a7704fc15ed069d0b51b6760cc [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')"
8 @changeSearch="onChangeSearchInput"
Dixsie Wolmers9b22b492020-09-07 21:26:06 -05009 @clearSearch="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">
Yoshie Muranaka82cca542020-04-07 10:20:37 -070019 <table-filter :filters="tableFilters" @filterChange="onFilterChange" />
20 </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"
27 @clearSelected="clearSelectedRows($refs.table)"
28 >
29 <template v-slot:export>
30 <table-toolbar-export
31 :data="selectedRows"
32 :file-name="$t('appPageTitle.sensors')"
33 />
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
42 no-sort-reset
43 sticky-header="75vh"
44 sort-by="status"
SurenNeware307382e2020-07-27 20:45:14 +053045 show-empty
Mateusz Gapski1d2da292020-09-10 12:07:45 +020046 :no-border-collapse="true"
Yoshie Muranaka82cca542020-04-07 10:20:37 -070047 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070048 :fields="fields"
49 :sort-desc="true"
50 :sort-compare="sortCompare"
SurenNeware71724be2020-06-01 15:31:00 +053051 :filter="searchFilter"
SurenNeware307382e2020-07-27 20:45:14 +053052 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053053 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Sukanya Pandey99010962020-07-27 21:44:47 +053054 @filtered="onFiltered"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070055 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070056 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070057 <!-- Checkbox column -->
58 <template v-slot:head(checkbox)>
59 <b-form-checkbox
60 v-model="tableHeaderCheckboxModel"
61 :indeterminate="tableHeaderCheckboxIndeterminate"
62 @change="onChangeHeaderCheckbox($refs.table)"
63 />
64 </template>
65 <template v-slot:cell(checkbox)="row">
66 <b-form-checkbox
67 v-model="row.rowSelected"
68 @change="toggleSelectRow($refs.table, row.index)"
69 />
70 </template>
71
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070072 <template v-slot:cell(status)="{ value }">
73 <status-icon :status="statusIcon(value)" />
74 {{ value }}
75 </template>
76 <template v-slot:cell(currentValue)="data">
77 {{ data.value }} {{ data.item.units }}
78 </template>
79 <template v-slot:cell(lowerCaution)="data">
80 {{ data.value }} {{ data.item.units }}
81 </template>
82 <template v-slot:cell(upperCaution)="data">
83 {{ data.value }} {{ data.item.units }}
84 </template>
85 <template v-slot:cell(lowerCritical)="data">
86 {{ data.value }} {{ data.item.units }}
87 </template>
88 <template v-slot:cell(upperCritical)="data">
89 {{ 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,
122 TableToolbarExport
123 },
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,
130 SearchFilterMixin
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700131 ],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700132 data() {
133 return {
134 fields: [
135 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700136 key: 'checkbox',
137 sortable: false,
138 label: ''
139 },
140 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700141 key: 'name',
142 sortable: true,
143 label: this.$t('pageSensors.table.name')
144 },
145 {
146 key: 'status',
147 sortable: true,
148 label: this.$t('pageSensors.table.status')
149 },
150 {
151 key: 'lowerCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700152 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700153 label: this.$t('pageSensors.table.lowerCritical')
154 },
155 {
156 key: 'lowerCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700157 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700158 label: this.$t('pageSensors.table.lowerWarning')
159 },
160
161 {
162 key: 'currentValue',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700163 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700164 label: this.$t('pageSensors.table.currentValue')
165 },
166 {
167 key: 'upperCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700168 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700169 label: this.$t('pageSensors.table.upperWarning')
170 },
171 {
172 key: 'upperCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700173 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700174 label: this.$t('pageSensors.table.upperCritical')
175 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700176 ],
177 tableFilters: [
178 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700179 key: 'status',
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700180 label: this.$t('pageSensors.table.status'),
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700181 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700182 }
183 ],
SurenNeware71724be2020-06-01 15:31:00 +0530184 activeFilters: [],
Sukanya Pandey99010962020-07-27 21:44:47 +0530185 searchFilter: null,
186 searchTotalFilteredRows: 0
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700187 };
188 },
189 computed: {
190 allSensors() {
191 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700192 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530193 filteredRows() {
194 return this.searchFilter
195 ? this.searchTotalFilteredRows
196 : this.filteredSensors.length;
197 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700198 filteredSensors() {
199 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700200 }
201 },
202 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700203 this.startLoader();
204 this.$store
205 .dispatch('sensors/getAllSensors')
206 .finally(() => this.endLoader());
207 },
208 beforeRouteLeave(to, from, next) {
209 this.hideLoader();
210 next();
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700211 },
212 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;
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700223 }
224 }
225};
226</script>