blob: 3915ff203ff56783380679af03b591cc0fd229d3 [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"
9 />
10 </b-col>
Sukanya Pandey99010962020-07-27 21:44:47 +053011 <b-col sm="3" md="3" xl="2">
12 <table-cell-count
13 :filtered-items-count="filteredRows"
14 :total-number-of-cells="allSensors.length"
15 ></table-cell-count>
16 </b-col>
17 <b-col sm="3" md="4" xl="6" class="text-right">
Yoshie Muranaka82cca542020-04-07 10:20:37 -070018 <table-filter :filters="tableFilters" @filterChange="onFilterChange" />
19 </b-col>
20 </b-row>
21 <b-row>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070022 <b-col xl="12">
Yoshie Muranakab1a71912020-04-29 10:52:39 -070023 <table-toolbar
24 ref="toolbar"
25 :selected-items-count="selectedRows.length"
26 @clearSelected="clearSelectedRows($refs.table)"
27 >
28 <template v-slot:export>
29 <table-toolbar-export
30 :data="selectedRows"
31 :file-name="$t('appPageTitle.sensors')"
32 />
33 </template>
34 </table-toolbar>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070035 <b-table
Yoshie Muranakab1a71912020-04-29 10:52:39 -070036 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053037 responsive="md"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070038 selectable
39 no-select-on-click
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070040 sort-icon-left
41 no-sort-reset
42 sticky-header="75vh"
43 sort-by="status"
SurenNeware307382e2020-07-27 20:45:14 +053044 show-empty
Mateusz Gapski1d2da292020-09-10 12:07:45 +020045 :no-border-collapse="true"
Yoshie Muranaka82cca542020-04-07 10:20:37 -070046 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070047 :fields="fields"
48 :sort-desc="true"
49 :sort-compare="sortCompare"
SurenNeware71724be2020-06-01 15:31:00 +053050 :filter="searchFilter"
SurenNeware307382e2020-07-27 20:45:14 +053051 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053052 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Sukanya Pandey99010962020-07-27 21:44:47 +053053 @filtered="onFiltered"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070054 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070055 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070056 <!-- Checkbox column -->
57 <template v-slot:head(checkbox)>
58 <b-form-checkbox
59 v-model="tableHeaderCheckboxModel"
60 :indeterminate="tableHeaderCheckboxIndeterminate"
61 @change="onChangeHeaderCheckbox($refs.table)"
62 />
63 </template>
64 <template v-slot:cell(checkbox)="row">
65 <b-form-checkbox
66 v-model="row.rowSelected"
67 @change="toggleSelectRow($refs.table, row.index)"
68 />
69 </template>
70
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070071 <template v-slot:cell(status)="{ value }">
72 <status-icon :status="statusIcon(value)" />
73 {{ value }}
74 </template>
75 <template v-slot:cell(currentValue)="data">
76 {{ data.value }} {{ data.item.units }}
77 </template>
78 <template v-slot:cell(lowerCaution)="data">
79 {{ data.value }} {{ data.item.units }}
80 </template>
81 <template v-slot:cell(upperCaution)="data">
82 {{ data.value }} {{ data.item.units }}
83 </template>
84 <template v-slot:cell(lowerCritical)="data">
85 {{ data.value }} {{ data.item.units }}
86 </template>
87 <template v-slot:cell(upperCritical)="data">
88 {{ data.value }} {{ data.item.units }}
89 </template>
90 </b-table>
91 </b-col>
92 </b-row>
93 </b-container>
94</template>
95
96<script>
SurenNeware5e25e282020-07-08 15:57:23 +053097import PageTitle from '@/components/Global/PageTitle';
98import Search from '@/components/Global/Search';
99import StatusIcon from '@/components/Global/StatusIcon';
100import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700101import TableToolbar from '@/components/Global/TableToolbar';
102import TableToolbarExport from '@/components/Global/TableToolbarExport';
Sukanya Pandey99010962020-07-27 21:44:47 +0530103import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700104
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700105import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700106import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
SurenNeware5e25e282020-07-08 15:57:23 +0530107import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700108import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
109import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700110
111export default {
112 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700113 components: {
114 PageTitle,
SurenNeware71724be2020-06-01 15:31:00 +0530115 Search,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700116 StatusIcon,
Sukanya Pandey99010962020-07-27 21:44:47 +0530117 TableCellCount,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700118 TableFilter,
119 TableToolbar,
120 TableToolbarExport
121 },
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700122 mixins: [
123 TableFilterMixin,
124 BVTableSelectableMixin,
125 LoadingBarMixin,
126 TableDataFormatterMixin,
127 TableSortMixin
128 ],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700129 data() {
130 return {
131 fields: [
132 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700133 key: 'checkbox',
134 sortable: false,
135 label: ''
136 },
137 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700138 key: 'name',
139 sortable: true,
140 label: this.$t('pageSensors.table.name')
141 },
142 {
143 key: 'status',
144 sortable: true,
145 label: this.$t('pageSensors.table.status')
146 },
147 {
148 key: 'lowerCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700149 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700150 label: this.$t('pageSensors.table.lowerCritical')
151 },
152 {
153 key: 'lowerCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700154 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700155 label: this.$t('pageSensors.table.lowerWarning')
156 },
157
158 {
159 key: 'currentValue',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700160 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700161 label: this.$t('pageSensors.table.currentValue')
162 },
163 {
164 key: 'upperCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700165 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700166 label: this.$t('pageSensors.table.upperWarning')
167 },
168 {
169 key: 'upperCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700170 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700171 label: this.$t('pageSensors.table.upperCritical')
172 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700173 ],
174 tableFilters: [
175 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700176 key: 'status',
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700177 label: this.$t('pageSensors.table.status'),
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700178 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700179 }
180 ],
SurenNeware71724be2020-06-01 15:31:00 +0530181 activeFilters: [],
Sukanya Pandey99010962020-07-27 21:44:47 +0530182 searchFilter: null,
183 searchTotalFilteredRows: 0
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700184 };
185 },
186 computed: {
187 allSensors() {
188 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700189 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530190 filteredRows() {
191 return this.searchFilter
192 ? this.searchTotalFilteredRows
193 : this.filteredSensors.length;
194 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700195 filteredSensors() {
196 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700197 }
198 },
199 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700200 this.startLoader();
201 this.$store
202 .dispatch('sensors/getAllSensors')
203 .finally(() => this.endLoader());
204 },
205 beforeRouteLeave(to, from, next) {
206 this.hideLoader();
207 next();
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700208 },
209 methods: {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700210 sortCompare(a, b, key) {
211 if (key === 'status') {
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700212 return this.sortStatus(a, b, key);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700213 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700214 },
215 onFilterChange({ activeFilters }) {
216 this.activeFilters = activeFilters;
SurenNeware71724be2020-06-01 15:31:00 +0530217 },
218 onChangeSearchInput(event) {
219 this.searchFilter = event;
Sukanya Pandey99010962020-07-27 21:44:47 +0530220 },
221 onFiltered(filteredItems) {
222 this.searchTotalFilteredRows = filteredItems.length;
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700223 }
224 }
225};
226</script>