blob: 6acabd98b8c4eca240bfa46741ce075ce5a2fe57 [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>
SurenNeware71724be2020-06-01 15:31:00 +05305 <b-col md="5" xl="4">
6 <search
7 :placeholder="$t('pageSensors.searchForSensors')"
8 @changeSearch="onChangeSearchInput"
9 />
10 </b-col>
11 <b-col md="7" xl="8" class="text-right">
Yoshie Muranaka82cca542020-04-07 10:20:37 -070012 <table-filter :filters="tableFilters" @filterChange="onFilterChange" />
13 </b-col>
14 </b-row>
15 <b-row>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070016 <b-col xl="12">
Yoshie Muranakab1a71912020-04-29 10:52:39 -070017 <table-toolbar
18 ref="toolbar"
19 :selected-items-count="selectedRows.length"
20 @clearSelected="clearSelectedRows($refs.table)"
21 >
22 <template v-slot:export>
23 <table-toolbar-export
24 :data="selectedRows"
25 :file-name="$t('appPageTitle.sensors')"
26 />
27 </template>
28 </table-toolbar>
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070029 <b-table
Yoshie Muranakab1a71912020-04-29 10:52:39 -070030 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053031 responsive="md"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070032 selectable
33 no-select-on-click
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070034 sort-icon-left
35 no-sort-reset
36 sticky-header="75vh"
37 sort-by="status"
SurenNeware307382e2020-07-27 20:45:14 +053038 show-empty
Mateusz Gapski1d2da292020-09-10 12:07:45 +020039 :no-border-collapse="true"
Yoshie Muranaka82cca542020-04-07 10:20:37 -070040 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070041 :fields="fields"
42 :sort-desc="true"
43 :sort-compare="sortCompare"
SurenNeware71724be2020-06-01 15:31:00 +053044 :filter="searchFilter"
SurenNeware307382e2020-07-27 20:45:14 +053045 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053046 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070047 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070048 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070049 <!-- Checkbox column -->
50 <template v-slot:head(checkbox)>
51 <b-form-checkbox
52 v-model="tableHeaderCheckboxModel"
53 :indeterminate="tableHeaderCheckboxIndeterminate"
54 @change="onChangeHeaderCheckbox($refs.table)"
55 />
56 </template>
57 <template v-slot:cell(checkbox)="row">
58 <b-form-checkbox
59 v-model="row.rowSelected"
60 @change="toggleSelectRow($refs.table, row.index)"
61 />
62 </template>
63
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070064 <template v-slot:cell(status)="{ value }">
65 <status-icon :status="statusIcon(value)" />
66 {{ value }}
67 </template>
68 <template v-slot:cell(currentValue)="data">
69 {{ data.value }} {{ data.item.units }}
70 </template>
71 <template v-slot:cell(lowerCaution)="data">
72 {{ data.value }} {{ data.item.units }}
73 </template>
74 <template v-slot:cell(upperCaution)="data">
75 {{ data.value }} {{ data.item.units }}
76 </template>
77 <template v-slot:cell(lowerCritical)="data">
78 {{ data.value }} {{ data.item.units }}
79 </template>
80 <template v-slot:cell(upperCritical)="data">
81 {{ data.value }} {{ data.item.units }}
82 </template>
83 </b-table>
84 </b-col>
85 </b-row>
86 </b-container>
87</template>
88
89<script>
SurenNeware5e25e282020-07-08 15:57:23 +053090import PageTitle from '@/components/Global/PageTitle';
91import Search from '@/components/Global/Search';
92import StatusIcon from '@/components/Global/StatusIcon';
93import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -070094import TableToolbar from '@/components/Global/TableToolbar';
95import TableToolbarExport from '@/components/Global/TableToolbarExport';
96
Yoshie Muranakab1a71912020-04-29 10:52:39 -070097import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka50ff1832020-05-01 11:00:17 -070098import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
SurenNeware5e25e282020-07-08 15:57:23 +053099import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700100import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
101import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700102
103export default {
104 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700105 components: {
106 PageTitle,
SurenNeware71724be2020-06-01 15:31:00 +0530107 Search,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700108 StatusIcon,
109 TableFilter,
110 TableToolbar,
111 TableToolbarExport
112 },
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700113 mixins: [
114 TableFilterMixin,
115 BVTableSelectableMixin,
116 LoadingBarMixin,
117 TableDataFormatterMixin,
118 TableSortMixin
119 ],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700120 data() {
121 return {
122 fields: [
123 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700124 key: 'checkbox',
125 sortable: false,
126 label: ''
127 },
128 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700129 key: 'name',
130 sortable: true,
131 label: this.$t('pageSensors.table.name')
132 },
133 {
134 key: 'status',
135 sortable: true,
136 label: this.$t('pageSensors.table.status')
137 },
138 {
139 key: 'lowerCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700140 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700141 label: this.$t('pageSensors.table.lowerCritical')
142 },
143 {
144 key: 'lowerCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700145 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700146 label: this.$t('pageSensors.table.lowerWarning')
147 },
148
149 {
150 key: 'currentValue',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700151 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700152 label: this.$t('pageSensors.table.currentValue')
153 },
154 {
155 key: 'upperCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700156 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700157 label: this.$t('pageSensors.table.upperWarning')
158 },
159 {
160 key: 'upperCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700161 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700162 label: this.$t('pageSensors.table.upperCritical')
163 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700164 ],
165 tableFilters: [
166 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700167 key: 'status',
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700168 label: this.$t('pageSensors.table.status'),
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700169 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700170 }
171 ],
SurenNeware71724be2020-06-01 15:31:00 +0530172 activeFilters: [],
173 searchFilter: null
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700174 };
175 },
176 computed: {
177 allSensors() {
178 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700179 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700180 filteredSensors() {
181 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700182 }
183 },
184 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700185 this.startLoader();
186 this.$store
187 .dispatch('sensors/getAllSensors')
188 .finally(() => this.endLoader());
189 },
190 beforeRouteLeave(to, from, next) {
191 this.hideLoader();
192 next();
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700193 },
194 methods: {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700195 sortCompare(a, b, key) {
196 if (key === 'status') {
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700197 return this.sortStatus(a, b, key);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700198 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700199 },
200 onFilterChange({ activeFilters }) {
201 this.activeFilters = activeFilters;
SurenNeware71724be2020-06-01 15:31:00 +0530202 },
203 onChangeSearchInput(event) {
204 this.searchFilter = event;
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700205 }
206 }
207};
208</script>