blob: b0c6c1389d6d8c41eacde04fc872b556617123be [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
Yoshie Muranaka82cca542020-04-07 10:20:37 -070039 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070040 :fields="fields"
41 :sort-desc="true"
42 :sort-compare="sortCompare"
SurenNeware71724be2020-06-01 15:31:00 +053043 :filter="searchFilter"
SurenNeware307382e2020-07-27 20:45:14 +053044 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053045 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070046 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070047 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070048 <!-- Checkbox column -->
49 <template v-slot:head(checkbox)>
50 <b-form-checkbox
51 v-model="tableHeaderCheckboxModel"
52 :indeterminate="tableHeaderCheckboxIndeterminate"
53 @change="onChangeHeaderCheckbox($refs.table)"
54 />
55 </template>
56 <template v-slot:cell(checkbox)="row">
57 <b-form-checkbox
58 v-model="row.rowSelected"
59 @change="toggleSelectRow($refs.table, row.index)"
60 />
61 </template>
62
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070063 <template v-slot:cell(status)="{ value }">
64 <status-icon :status="statusIcon(value)" />
65 {{ value }}
66 </template>
67 <template v-slot:cell(currentValue)="data">
68 {{ data.value }} {{ data.item.units }}
69 </template>
70 <template v-slot:cell(lowerCaution)="data">
71 {{ data.value }} {{ data.item.units }}
72 </template>
73 <template v-slot:cell(upperCaution)="data">
74 {{ data.value }} {{ data.item.units }}
75 </template>
76 <template v-slot:cell(lowerCritical)="data">
77 {{ data.value }} {{ data.item.units }}
78 </template>
79 <template v-slot:cell(upperCritical)="data">
80 {{ data.value }} {{ data.item.units }}
81 </template>
82 </b-table>
83 </b-col>
84 </b-row>
85 </b-container>
86</template>
87
88<script>
SurenNeware5e25e282020-07-08 15:57:23 +053089import PageTitle from '@/components/Global/PageTitle';
90import Search from '@/components/Global/Search';
91import StatusIcon from '@/components/Global/StatusIcon';
92import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -070093import TableToolbar from '@/components/Global/TableToolbar';
94import TableToolbarExport from '@/components/Global/TableToolbarExport';
95
Yoshie Muranakab1a71912020-04-29 10:52:39 -070096import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka50ff1832020-05-01 11:00:17 -070097import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
SurenNeware5e25e282020-07-08 15:57:23 +053098import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranaka202c5992020-06-18 12:02:57 -070099import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
100import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700101
102export default {
103 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700104 components: {
105 PageTitle,
SurenNeware71724be2020-06-01 15:31:00 +0530106 Search,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700107 StatusIcon,
108 TableFilter,
109 TableToolbar,
110 TableToolbarExport
111 },
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700112 mixins: [
113 TableFilterMixin,
114 BVTableSelectableMixin,
115 LoadingBarMixin,
116 TableDataFormatterMixin,
117 TableSortMixin
118 ],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700119 data() {
120 return {
121 fields: [
122 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700123 key: 'checkbox',
124 sortable: false,
125 label: ''
126 },
127 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700128 key: 'name',
129 sortable: true,
130 label: this.$t('pageSensors.table.name')
131 },
132 {
133 key: 'status',
134 sortable: true,
135 label: this.$t('pageSensors.table.status')
136 },
137 {
138 key: 'lowerCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700139 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700140 label: this.$t('pageSensors.table.lowerCritical')
141 },
142 {
143 key: 'lowerCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700144 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700145 label: this.$t('pageSensors.table.lowerWarning')
146 },
147
148 {
149 key: 'currentValue',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700150 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700151 label: this.$t('pageSensors.table.currentValue')
152 },
153 {
154 key: 'upperCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700155 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700156 label: this.$t('pageSensors.table.upperWarning')
157 },
158 {
159 key: 'upperCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700160 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700161 label: this.$t('pageSensors.table.upperCritical')
162 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700163 ],
164 tableFilters: [
165 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700166 key: 'status',
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700167 label: this.$t('pageSensors.table.status'),
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700168 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700169 }
170 ],
SurenNeware71724be2020-06-01 15:31:00 +0530171 activeFilters: [],
172 searchFilter: null
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700173 };
174 },
175 computed: {
176 allSensors() {
177 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700178 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700179 filteredSensors() {
180 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700181 }
182 },
183 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700184 this.startLoader();
185 this.$store
186 .dispatch('sensors/getAllSensors')
187 .finally(() => this.endLoader());
188 },
189 beforeRouteLeave(to, from, next) {
190 this.hideLoader();
191 next();
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700192 },
193 methods: {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700194 sortCompare(a, b, key) {
195 if (key === 'status') {
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700196 return this.sortStatus(a, b, key);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700197 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700198 },
199 onFilterChange({ activeFilters }) {
200 this.activeFilters = activeFilters;
SurenNeware71724be2020-06-01 15:31:00 +0530201 },
202 onChangeSearchInput(event) {
203 this.searchFilter = event;
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700204 }
205 }
206};
207</script>