Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 3111b6f | 2020-04-21 19:48:38 -0700 | [diff] [blame] | 2 | <b-container fluid="xl"> |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 3 | <page-title /> |
| 4 | <b-row> |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 5 | <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 Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 12 | <table-filter :filters="tableFilters" @filterChange="onFilterChange" /> |
| 13 | </b-col> |
| 14 | </b-row> |
| 15 | <b-row> |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 16 | <b-col xl="12"> |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 17 | <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 Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 29 | <b-table |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 30 | ref="table" |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 31 | responsive="md" |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 32 | selectable |
| 33 | no-select-on-click |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 34 | sort-icon-left |
| 35 | no-sort-reset |
| 36 | sticky-header="75vh" |
| 37 | sort-by="status" |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 38 | show-empty |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 39 | :items="filteredSensors" |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 40 | :fields="fields" |
| 41 | :sort-desc="true" |
| 42 | :sort-compare="sortCompare" |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 43 | :filter="searchFilter" |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 44 | :empty-text="$t('global.table.emptyMessage')" |
SurenNeware | 156a0e6 | 2020-08-28 19:20:03 +0530 | [diff] [blame] | 45 | :empty-filtered-text="$t('global.table.emptySearchMessage')" |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 46 | @row-selected="onRowSelected($event, filteredSensors.length)" |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 47 | > |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 48 | <!-- 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 Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 63 | <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> |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 89 | import PageTitle from '@/components/Global/PageTitle'; |
| 90 | import Search from '@/components/Global/Search'; |
| 91 | import StatusIcon from '@/components/Global/StatusIcon'; |
| 92 | import TableFilter from '@/components/Global/TableFilter'; |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 93 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 94 | import TableToolbarExport from '@/components/Global/TableToolbarExport'; |
| 95 | |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 96 | import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin'; |
Yoshie Muranaka | 50ff183 | 2020-05-01 11:00:17 -0700 | [diff] [blame] | 97 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 98 | import TableFilterMixin from '@/components/Mixins/TableFilterMixin'; |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 99 | import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin'; |
| 100 | import TableSortMixin from '@/components/Mixins/TableSortMixin'; |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 101 | |
| 102 | export default { |
| 103 | name: 'Sensors', |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 104 | components: { |
| 105 | PageTitle, |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 106 | Search, |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 107 | StatusIcon, |
| 108 | TableFilter, |
| 109 | TableToolbar, |
| 110 | TableToolbarExport |
| 111 | }, |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 112 | mixins: [ |
| 113 | TableFilterMixin, |
| 114 | BVTableSelectableMixin, |
| 115 | LoadingBarMixin, |
| 116 | TableDataFormatterMixin, |
| 117 | TableSortMixin |
| 118 | ], |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 119 | data() { |
| 120 | return { |
| 121 | fields: [ |
| 122 | { |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 123 | key: 'checkbox', |
| 124 | sortable: false, |
| 125 | label: '' |
| 126 | }, |
| 127 | { |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 128 | 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 Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 139 | formatter: this.tableFormatter, |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 140 | label: this.$t('pageSensors.table.lowerCritical') |
| 141 | }, |
| 142 | { |
| 143 | key: 'lowerCaution', |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 144 | formatter: this.tableFormatter, |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 145 | label: this.$t('pageSensors.table.lowerWarning') |
| 146 | }, |
| 147 | |
| 148 | { |
| 149 | key: 'currentValue', |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 150 | formatter: this.tableFormatter, |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 151 | label: this.$t('pageSensors.table.currentValue') |
| 152 | }, |
| 153 | { |
| 154 | key: 'upperCaution', |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 155 | formatter: this.tableFormatter, |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 156 | label: this.$t('pageSensors.table.upperWarning') |
| 157 | }, |
| 158 | { |
| 159 | key: 'upperCritical', |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 160 | formatter: this.tableFormatter, |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 161 | label: this.$t('pageSensors.table.upperCritical') |
| 162 | } |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 163 | ], |
| 164 | tableFilters: [ |
| 165 | { |
Yoshie Muranaka | 0045400 | 2020-06-22 09:14:05 -0700 | [diff] [blame] | 166 | key: 'status', |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 167 | label: this.$t('pageSensors.table.status'), |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 168 | values: ['OK', 'Warning', 'Critical'] |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 169 | } |
| 170 | ], |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 171 | activeFilters: [], |
| 172 | searchFilter: null |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 173 | }; |
| 174 | }, |
| 175 | computed: { |
| 176 | allSensors() { |
| 177 | return this.$store.getters['sensors/sensors']; |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 178 | }, |
Yoshie Muranaka | 396aaab | 2020-05-20 10:11:06 -0700 | [diff] [blame] | 179 | filteredSensors() { |
| 180 | return this.getFilteredTableData(this.allSensors, this.activeFilters); |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 181 | } |
| 182 | }, |
| 183 | created() { |
Yoshie Muranaka | 50ff183 | 2020-05-01 11:00:17 -0700 | [diff] [blame] | 184 | 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 Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 192 | }, |
| 193 | methods: { |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 194 | sortCompare(a, b, key) { |
| 195 | if (key === 'status') { |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 196 | return this.sortStatus(a, b, key); |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 197 | } |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 198 | }, |
| 199 | onFilterChange({ activeFilters }) { |
| 200 | this.activeFilters = activeFilters; |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 201 | }, |
| 202 | onChangeSearchInput(event) { |
| 203 | this.searchFilter = event; |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | }; |
| 207 | </script> |