blob: f8564d869e3420277579038109a3f42f800baff8 [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"
Yoshie Muranaka82cca542020-04-07 10:20:37 -070038 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070039 :fields="fields"
40 :sort-desc="true"
41 :sort-compare="sortCompare"
SurenNeware71724be2020-06-01 15:31:00 +053042 :filter="searchFilter"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070043 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070044 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070045 <!-- Checkbox column -->
46 <template v-slot:head(checkbox)>
47 <b-form-checkbox
48 v-model="tableHeaderCheckboxModel"
49 :indeterminate="tableHeaderCheckboxIndeterminate"
50 @change="onChangeHeaderCheckbox($refs.table)"
51 />
52 </template>
53 <template v-slot:cell(checkbox)="row">
54 <b-form-checkbox
55 v-model="row.rowSelected"
56 @change="toggleSelectRow($refs.table, row.index)"
57 />
58 </template>
59
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070060 <template v-slot:cell(status)="{ value }">
61 <status-icon :status="statusIcon(value)" />
62 {{ value }}
63 </template>
64 <template v-slot:cell(currentValue)="data">
65 {{ data.value }} {{ data.item.units }}
66 </template>
67 <template v-slot:cell(lowerCaution)="data">
68 {{ data.value }} {{ data.item.units }}
69 </template>
70 <template v-slot:cell(upperCaution)="data">
71 {{ data.value }} {{ data.item.units }}
72 </template>
73 <template v-slot:cell(lowerCritical)="data">
74 {{ data.value }} {{ data.item.units }}
75 </template>
76 <template v-slot:cell(upperCritical)="data">
77 {{ data.value }} {{ data.item.units }}
78 </template>
79 </b-table>
80 </b-col>
81 </b-row>
82 </b-container>
83</template>
84
85<script>
SurenNeware5e25e282020-07-08 15:57:23 +053086import PageTitle from '@/components/Global/PageTitle';
87import Search from '@/components/Global/Search';
88import StatusIcon from '@/components/Global/StatusIcon';
89import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -070090import TableToolbar from '@/components/Global/TableToolbar';
91import TableToolbarExport from '@/components/Global/TableToolbarExport';
92
Yoshie Muranakab1a71912020-04-29 10:52:39 -070093import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranaka50ff1832020-05-01 11:00:17 -070094import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
SurenNeware5e25e282020-07-08 15:57:23 +053095import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranaka202c5992020-06-18 12:02:57 -070096import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
97import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070098
99export default {
100 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700101 components: {
102 PageTitle,
SurenNeware71724be2020-06-01 15:31:00 +0530103 Search,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700104 StatusIcon,
105 TableFilter,
106 TableToolbar,
107 TableToolbarExport
108 },
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700109 mixins: [
110 TableFilterMixin,
111 BVTableSelectableMixin,
112 LoadingBarMixin,
113 TableDataFormatterMixin,
114 TableSortMixin
115 ],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700116 data() {
117 return {
118 fields: [
119 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700120 key: 'checkbox',
121 sortable: false,
122 label: ''
123 },
124 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700125 key: 'name',
126 sortable: true,
127 label: this.$t('pageSensors.table.name')
128 },
129 {
130 key: 'status',
131 sortable: true,
132 label: this.$t('pageSensors.table.status')
133 },
134 {
135 key: 'lowerCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700136 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700137 label: this.$t('pageSensors.table.lowerCritical')
138 },
139 {
140 key: 'lowerCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700141 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700142 label: this.$t('pageSensors.table.lowerWarning')
143 },
144
145 {
146 key: 'currentValue',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700147 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700148 label: this.$t('pageSensors.table.currentValue')
149 },
150 {
151 key: 'upperCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700152 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700153 label: this.$t('pageSensors.table.upperWarning')
154 },
155 {
156 key: 'upperCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700157 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700158 label: this.$t('pageSensors.table.upperCritical')
159 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700160 ],
161 tableFilters: [
162 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700163 key: 'status',
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700164 label: this.$t('pageSensors.table.status'),
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700165 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700166 }
167 ],
SurenNeware71724be2020-06-01 15:31:00 +0530168 activeFilters: [],
169 searchFilter: null
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700170 };
171 },
172 computed: {
173 allSensors() {
174 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700175 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700176 filteredSensors() {
177 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700178 }
179 },
180 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700181 this.startLoader();
182 this.$store
183 .dispatch('sensors/getAllSensors')
184 .finally(() => this.endLoader());
185 },
186 beforeRouteLeave(to, from, next) {
187 this.hideLoader();
188 next();
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700189 },
190 methods: {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700191 sortCompare(a, b, key) {
192 if (key === 'status') {
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700193 return this.sortStatus(a, b, key);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700194 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700195 },
196 onFilterChange({ activeFilters }) {
197 this.activeFilters = activeFilters;
SurenNeware71724be2020-06-01 15:31:00 +0530198 },
199 onChangeSearchInput(event) {
200 this.searchFilter = event;
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700201 }
202 }
203};
204</script>