blob: 879e2363d0ce20512afc82a4c9e3911381680b06 [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"
31 selectable
32 no-select-on-click
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070033 sort-icon-left
34 no-sort-reset
35 sticky-header="75vh"
36 sort-by="status"
Yoshie Muranaka82cca542020-04-07 10:20:37 -070037 :items="filteredSensors"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070038 :fields="fields"
39 :sort-desc="true"
40 :sort-compare="sortCompare"
SurenNeware71724be2020-06-01 15:31:00 +053041 :filter="searchFilter"
Yoshie Muranakab1a71912020-04-29 10:52:39 -070042 @row-selected="onRowSelected($event, filteredSensors.length)"
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070043 >
Yoshie Muranakab1a71912020-04-29 10:52:39 -070044 <!-- Checkbox column -->
45 <template v-slot:head(checkbox)>
46 <b-form-checkbox
47 v-model="tableHeaderCheckboxModel"
48 :indeterminate="tableHeaderCheckboxIndeterminate"
49 @change="onChangeHeaderCheckbox($refs.table)"
50 />
51 </template>
52 <template v-slot:cell(checkbox)="row">
53 <b-form-checkbox
54 v-model="row.rowSelected"
55 @change="toggleSelectRow($refs.table, row.index)"
56 />
57 </template>
58
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070059 <template v-slot:cell(status)="{ value }">
60 <status-icon :status="statusIcon(value)" />
61 {{ value }}
62 </template>
63 <template v-slot:cell(currentValue)="data">
64 {{ data.value }} {{ data.item.units }}
65 </template>
66 <template v-slot:cell(lowerCaution)="data">
67 {{ data.value }} {{ data.item.units }}
68 </template>
69 <template v-slot:cell(upperCaution)="data">
70 {{ data.value }} {{ data.item.units }}
71 </template>
72 <template v-slot:cell(lowerCritical)="data">
73 {{ data.value }} {{ data.item.units }}
74 </template>
75 <template v-slot:cell(upperCritical)="data">
76 {{ data.value }} {{ data.item.units }}
77 </template>
78 </b-table>
79 </b-col>
80 </b-row>
81 </b-container>
82</template>
83
84<script>
85import PageTitle from '../../../components/Global/PageTitle';
SurenNeware71724be2020-06-01 15:31:00 +053086import Search from '../../../components/Global/Search';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070087import StatusIcon from '../../../components/Global/StatusIcon';
Yoshie Muranaka82cca542020-04-07 10:20:37 -070088import TableFilter from '../../../components/Global/TableFilter';
Yoshie Muranakab1a71912020-04-29 10:52:39 -070089import TableToolbar from '@/components/Global/TableToolbar';
90import TableToolbarExport from '@/components/Global/TableToolbarExport';
91
Yoshie Muranaka82cca542020-04-07 10:20:37 -070092import TableFilterMixin from '../../../components/Mixins/TableFilterMixin';
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';
Yoshie Muranaka202c5992020-06-18 12:02:57 -070095import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
96import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070097
98export default {
99 name: 'Sensors',
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700100 components: {
101 PageTitle,
SurenNeware71724be2020-06-01 15:31:00 +0530102 Search,
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700103 StatusIcon,
104 TableFilter,
105 TableToolbar,
106 TableToolbarExport
107 },
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700108 mixins: [
109 TableFilterMixin,
110 BVTableSelectableMixin,
111 LoadingBarMixin,
112 TableDataFormatterMixin,
113 TableSortMixin
114 ],
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700115 data() {
116 return {
117 fields: [
118 {
Yoshie Muranakab1a71912020-04-29 10:52:39 -0700119 key: 'checkbox',
120 sortable: false,
121 label: ''
122 },
123 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700124 key: 'name',
125 sortable: true,
126 label: this.$t('pageSensors.table.name')
127 },
128 {
129 key: 'status',
130 sortable: true,
131 label: this.$t('pageSensors.table.status')
132 },
133 {
134 key: 'lowerCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700135 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700136 label: this.$t('pageSensors.table.lowerCritical')
137 },
138 {
139 key: 'lowerCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700140 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700141 label: this.$t('pageSensors.table.lowerWarning')
142 },
143
144 {
145 key: 'currentValue',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700146 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700147 label: this.$t('pageSensors.table.currentValue')
148 },
149 {
150 key: 'upperCaution',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700151 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700152 label: this.$t('pageSensors.table.upperWarning')
153 },
154 {
155 key: 'upperCritical',
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700156 formatter: this.tableFormatter,
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700157 label: this.$t('pageSensors.table.upperCritical')
158 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700159 ],
160 tableFilters: [
161 {
162 label: this.$t('pageSensors.table.status'),
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700163 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700164 }
165 ],
SurenNeware71724be2020-06-01 15:31:00 +0530166 activeFilters: [],
167 searchFilter: null
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700168 };
169 },
170 computed: {
171 allSensors() {
172 return this.$store.getters['sensors/sensors'];
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700173 },
Yoshie Muranaka396aaab2020-05-20 10:11:06 -0700174 filteredSensors() {
175 return this.getFilteredTableData(this.allSensors, this.activeFilters);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700176 }
177 },
178 created() {
Yoshie Muranaka50ff1832020-05-01 11:00:17 -0700179 this.startLoader();
180 this.$store
181 .dispatch('sensors/getAllSensors')
182 .finally(() => this.endLoader());
183 },
184 beforeRouteLeave(to, from, next) {
185 this.hideLoader();
186 next();
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700187 },
188 methods: {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700189 sortCompare(a, b, key) {
190 if (key === 'status') {
Yoshie Muranaka202c5992020-06-18 12:02:57 -0700191 return this.sortStatus(a, b, key);
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700192 }
Yoshie Muranaka82cca542020-04-07 10:20:37 -0700193 },
194 onFilterChange({ activeFilters }) {
195 this.activeFilters = activeFilters;
SurenNeware71724be2020-06-01 15:31:00 +0530196 },
197 onChangeSearchInput(event) {
198 this.searchFilter = event;
Yoshie Muranaka30abccb2020-03-11 12:44:24 -0700199 }
200 }
201};
202</script>