blob: f09665401e679301feac680270797e96fe6728f5 [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')"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070045 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070046 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070047 <!-- Checkbox column -->
48 <template v-slot:head(checkbox)>
49 <b-form-checkbox
50 v-model="tableHeaderCheckboxModel"
51 :indeterminate="tableHeaderCheckboxIndeterminate"
52 @change="onChangeHeaderCheckbox($refs.table)"
53 />
54 </template>
55 <template v-slot:cell(checkbox)="row">
56 <b-form-checkbox
57 v-model="row.rowSelected"
58 @change="toggleSelectRow($refs.table, row.index)"
59 />
60 </template>
61
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070062 <template v-slot:cell(status)="{ value }">
63 <status-icon :status="statusIcon(value)" />
64 {{ value }}
65 </template>
66 <template v-slot:cell(currentValue)="data">
67 {{ data.value }} {{ data.item.units }}
68 </template>
69 <template v-slot:cell(lowerCaution)="data">
70 {{ data.value }} {{ data.item.units }}
71 </template>
72 <template v-slot:cell(upperCaution)="data">
73 {{ data.value }} {{ data.item.units }}
74 </template>
75 <template v-slot:cell(lowerCritical)="data">
76 {{ data.value }} {{ data.item.units }}
77 </template>
78 <template v-slot:cell(upperCritical)="data">
79 {{ data.value }} {{ data.item.units }}
80 </template>
81 </b-table>
82 </b-col>
83 </b-row>
84 </b-container>
85</template>
86
87<script>
SurenNeware5e25e282020-07-08 15:57:23 +053088import PageTitle from '@/components/Global/PageTitle';
89import Search from '@/components/Global/Search';
90import StatusIcon from '@/components/Global/StatusIcon';
91import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -070092import TableToolbar from '@/components/Global/TableToolbar';
93import TableToolbarExport from '@/components/Global/TableToolbarExport';
94
Yoshie Muranakab1a71912020-04-29 10:52:39 -070095import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka50ff1832020-05-01 11:00:17 -070096import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
SurenNeware5e25e282020-07-08 15:57:23 +053097import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranaka202c5992020-06-18 12:02:57 -070098import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
99import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700100
101export default {
102 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700103 components: {
104 PageTitle,
SurenNeware71724be2020-06-01 15:31:00 +0530105 Search,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700106 StatusIcon,
107 TableFilter,
108 TableToolbar,
109 TableToolbarExport
110 },
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700111 mixins: [
112 TableFilterMixin,
113 BVTableSelectableMixin,
114 LoadingBarMixin,
115 TableDataFormatterMixin,
116 TableSortMixin
117 ],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700118 data() {
119 return {
120 fields: [
121 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700122 key: 'checkbox',
123 sortable: false,
124 label: ''
125 },
126 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700127 key: 'name',
128 sortable: true,
129 label: this.$t('pageSensors.table.name')
130 },
131 {
132 key: 'status',
133 sortable: true,
134 label: this.$t('pageSensors.table.status')
135 },
136 {
137 key: 'lowerCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700138 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700139 label: this.$t('pageSensors.table.lowerCritical')
140 },
141 {
142 key: 'lowerCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700143 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700144 label: this.$t('pageSensors.table.lowerWarning')
145 },
146
147 {
148 key: 'currentValue',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700149 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700150 label: this.$t('pageSensors.table.currentValue')
151 },
152 {
153 key: 'upperCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700154 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700155 label: this.$t('pageSensors.table.upperWarning')
156 },
157 {
158 key: 'upperCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700159 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700160 label: this.$t('pageSensors.table.upperCritical')
161 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700162 ],
163 tableFilters: [
164 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700165 key: 'status',
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700166 label: this.$t('pageSensors.table.status'),
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700167 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700168 }
169 ],
SurenNeware71724be2020-06-01 15:31:00 +0530170 activeFilters: [],
171 searchFilter: null
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700172 };
173 },
174 computed: {
175 allSensors() {
176 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700177 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700178 filteredSensors() {
179 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700180 }
181 },
182 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700183 this.startLoader();
184 this.$store
185 .dispatch('sensors/getAllSensors')
186 .finally(() => this.endLoader());
187 },
188 beforeRouteLeave(to, from, next) {
189 this.hideLoader();
190 next();
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700191 },
192 methods: {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700193 sortCompare(a, b, key) {
194 if (key === 'status') {
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700195 return this.sortStatus(a, b, key);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700196 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700197 },
198 onFilterChange({ activeFilters }) {
199 this.activeFilters = activeFilters;
SurenNeware71724be2020-06-01 15:31:00 +0530200 },
201 onChangeSearchInput(event) {
202 this.searchFilter = event;
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700203 }
204 }
205};
206</script>