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> |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 5 | <b-col sm="6" md="5" xl="4"> |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 6 | <search |
| 7 | :placeholder="$t('pageSensors.searchForSensors')" |
| 8 | @changeSearch="onChangeSearchInput" |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 9 | @clearSearch="onClearSearchInput" |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 10 | /> |
| 11 | </b-col> |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 12 | <b-col sm="3" md="3" xl="2"> |
| 13 | <table-cell-count |
| 14 | :filtered-items-count="filteredRows" |
| 15 | :total-number-of-cells="allSensors.length" |
| 16 | ></table-cell-count> |
| 17 | </b-col> |
| 18 | <b-col sm="3" md="4" xl="6" class="text-right"> |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 19 | <table-filter :filters="tableFilters" @filterChange="onFilterChange" /> |
| 20 | </b-col> |
| 21 | </b-row> |
| 22 | <b-row> |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 23 | <b-col xl="12"> |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 24 | <table-toolbar |
| 25 | ref="toolbar" |
| 26 | :selected-items-count="selectedRows.length" |
| 27 | @clearSelected="clearSelectedRows($refs.table)" |
| 28 | > |
| 29 | <template v-slot:export> |
| 30 | <table-toolbar-export |
| 31 | :data="selectedRows" |
SurenNeware | 1471f8f | 2020-09-18 18:41:22 +0530 | [diff] [blame] | 32 | :file-name="exportFileNameByDate()" |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 33 | /> |
| 34 | </template> |
| 35 | </table-toolbar> |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 36 | <b-table |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 37 | ref="table" |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 38 | responsive="md" |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 39 | selectable |
| 40 | no-select-on-click |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 41 | sort-icon-left |
Sukanya Pandey | fde429e | 2020-09-14 20:48:39 +0530 | [diff] [blame] | 42 | hover |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 43 | no-sort-reset |
| 44 | sticky-header="75vh" |
| 45 | sort-by="status" |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 46 | show-empty |
Mateusz Gapski | 1d2da29 | 2020-09-10 12:07:45 +0200 | [diff] [blame] | 47 | :no-border-collapse="true" |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 48 | :items="filteredSensors" |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 49 | :fields="fields" |
| 50 | :sort-desc="true" |
| 51 | :sort-compare="sortCompare" |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 52 | :filter="searchFilter" |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 53 | :empty-text="$t('global.table.emptyMessage')" |
SurenNeware | 156a0e6 | 2020-08-28 19:20:03 +0530 | [diff] [blame] | 54 | :empty-filtered-text="$t('global.table.emptySearchMessage')" |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 55 | @filtered="onFiltered" |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 56 | @row-selected="onRowSelected($event, filteredSensors.length)" |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 57 | > |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 58 | <!-- Checkbox column --> |
| 59 | <template v-slot:head(checkbox)> |
| 60 | <b-form-checkbox |
| 61 | v-model="tableHeaderCheckboxModel" |
| 62 | :indeterminate="tableHeaderCheckboxIndeterminate" |
| 63 | @change="onChangeHeaderCheckbox($refs.table)" |
| 64 | /> |
| 65 | </template> |
| 66 | <template v-slot:cell(checkbox)="row"> |
| 67 | <b-form-checkbox |
| 68 | v-model="row.rowSelected" |
| 69 | @change="toggleSelectRow($refs.table, row.index)" |
| 70 | /> |
| 71 | </template> |
| 72 | |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 73 | <template v-slot:cell(status)="{ value }"> |
Dixsie Wolmers | a04d46f | 2020-10-22 06:34:56 -0500 | [diff] [blame^] | 74 | <status-icon :status="statusIcon(value)" /> {{ value }} |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 75 | </template> |
| 76 | <template v-slot:cell(currentValue)="data"> |
| 77 | {{ data.value }} {{ data.item.units }} |
| 78 | </template> |
| 79 | <template v-slot:cell(lowerCaution)="data"> |
| 80 | {{ data.value }} {{ data.item.units }} |
| 81 | </template> |
| 82 | <template v-slot:cell(upperCaution)="data"> |
| 83 | {{ data.value }} {{ data.item.units }} |
| 84 | </template> |
| 85 | <template v-slot:cell(lowerCritical)="data"> |
| 86 | {{ data.value }} {{ data.item.units }} |
| 87 | </template> |
| 88 | <template v-slot:cell(upperCritical)="data"> |
| 89 | {{ data.value }} {{ data.item.units }} |
| 90 | </template> |
| 91 | </b-table> |
| 92 | </b-col> |
| 93 | </b-row> |
| 94 | </b-container> |
| 95 | </template> |
| 96 | |
| 97 | <script> |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 98 | import PageTitle from '@/components/Global/PageTitle'; |
| 99 | import Search from '@/components/Global/Search'; |
| 100 | import StatusIcon from '@/components/Global/StatusIcon'; |
| 101 | import TableFilter from '@/components/Global/TableFilter'; |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 102 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 103 | import TableToolbarExport from '@/components/Global/TableToolbarExport'; |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 104 | import TableCellCount from '@/components/Global/TableCellCount'; |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 105 | |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 106 | import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin'; |
Yoshie Muranaka | 50ff183 | 2020-05-01 11:00:17 -0700 | [diff] [blame] | 107 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 108 | import TableFilterMixin from '@/components/Mixins/TableFilterMixin'; |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 109 | import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin'; |
| 110 | import TableSortMixin from '@/components/Mixins/TableSortMixin'; |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 111 | import SearchFilterMixin from '@/components/Mixins/SearchFilterMixin'; |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 112 | |
| 113 | export default { |
| 114 | name: 'Sensors', |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 115 | components: { |
| 116 | PageTitle, |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 117 | Search, |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 118 | StatusIcon, |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 119 | TableCellCount, |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 120 | TableFilter, |
| 121 | TableToolbar, |
| 122 | TableToolbarExport |
| 123 | }, |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 124 | mixins: [ |
| 125 | TableFilterMixin, |
| 126 | BVTableSelectableMixin, |
| 127 | LoadingBarMixin, |
| 128 | TableDataFormatterMixin, |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 129 | TableSortMixin, |
| 130 | SearchFilterMixin |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 131 | ], |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 132 | data() { |
| 133 | return { |
| 134 | fields: [ |
| 135 | { |
Yoshie Muranaka | b1a7191 | 2020-04-29 10:52:39 -0700 | [diff] [blame] | 136 | key: 'checkbox', |
| 137 | sortable: false, |
| 138 | label: '' |
| 139 | }, |
| 140 | { |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 141 | key: 'name', |
| 142 | sortable: true, |
| 143 | label: this.$t('pageSensors.table.name') |
| 144 | }, |
| 145 | { |
| 146 | key: 'status', |
| 147 | sortable: true, |
Dixsie Wolmers | a04d46f | 2020-10-22 06:34:56 -0500 | [diff] [blame^] | 148 | label: this.$t('pageSensors.table.status'), |
| 149 | tdClass: 'text-nowrap' |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 150 | }, |
| 151 | { |
| 152 | key: 'lowerCritical', |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 153 | formatter: this.tableFormatter, |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 154 | label: this.$t('pageSensors.table.lowerCritical') |
| 155 | }, |
| 156 | { |
| 157 | key: 'lowerCaution', |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 158 | formatter: this.tableFormatter, |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 159 | label: this.$t('pageSensors.table.lowerWarning') |
| 160 | }, |
| 161 | |
| 162 | { |
| 163 | key: 'currentValue', |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 164 | formatter: this.tableFormatter, |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 165 | label: this.$t('pageSensors.table.currentValue') |
| 166 | }, |
| 167 | { |
| 168 | key: 'upperCaution', |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 169 | formatter: this.tableFormatter, |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 170 | label: this.$t('pageSensors.table.upperWarning') |
| 171 | }, |
| 172 | { |
| 173 | key: 'upperCritical', |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 174 | formatter: this.tableFormatter, |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 175 | label: this.$t('pageSensors.table.upperCritical') |
| 176 | } |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 177 | ], |
| 178 | tableFilters: [ |
| 179 | { |
Yoshie Muranaka | 0045400 | 2020-06-22 09:14:05 -0700 | [diff] [blame] | 180 | key: 'status', |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 181 | label: this.$t('pageSensors.table.status'), |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 182 | values: ['OK', 'Warning', 'Critical'] |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 183 | } |
| 184 | ], |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 185 | activeFilters: [], |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 186 | searchTotalFilteredRows: 0 |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 187 | }; |
| 188 | }, |
| 189 | computed: { |
| 190 | allSensors() { |
| 191 | return this.$store.getters['sensors/sensors']; |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 192 | }, |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 193 | filteredRows() { |
| 194 | return this.searchFilter |
| 195 | ? this.searchTotalFilteredRows |
| 196 | : this.filteredSensors.length; |
| 197 | }, |
Yoshie Muranaka | 396aaab | 2020-05-20 10:11:06 -0700 | [diff] [blame] | 198 | filteredSensors() { |
| 199 | return this.getFilteredTableData(this.allSensors, this.activeFilters); |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 200 | } |
| 201 | }, |
| 202 | created() { |
Yoshie Muranaka | 50ff183 | 2020-05-01 11:00:17 -0700 | [diff] [blame] | 203 | this.startLoader(); |
| 204 | this.$store |
| 205 | .dispatch('sensors/getAllSensors') |
| 206 | .finally(() => this.endLoader()); |
| 207 | }, |
| 208 | beforeRouteLeave(to, from, next) { |
| 209 | this.hideLoader(); |
| 210 | next(); |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 211 | }, |
| 212 | methods: { |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 213 | sortCompare(a, b, key) { |
| 214 | if (key === 'status') { |
Yoshie Muranaka | 202c599 | 2020-06-18 12:02:57 -0700 | [diff] [blame] | 215 | return this.sortStatus(a, b, key); |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 216 | } |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 217 | }, |
| 218 | onFilterChange({ activeFilters }) { |
| 219 | this.activeFilters = activeFilters; |
SurenNeware | 71724be | 2020-06-01 15:31:00 +0530 | [diff] [blame] | 220 | }, |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 221 | onFiltered(filteredItems) { |
| 222 | this.searchTotalFilteredRows = filteredItems.length; |
SurenNeware | 1471f8f | 2020-09-18 18:41:22 +0530 | [diff] [blame] | 223 | }, |
| 224 | onChangeSearchInput(event) { |
| 225 | this.searchFilter = event; |
| 226 | }, |
| 227 | exportFileNameByDate() { |
| 228 | // Create export file name based on date |
| 229 | let date = new Date(); |
| 230 | date = |
| 231 | date.toISOString().slice(0, 10) + |
| 232 | '_' + |
| 233 | date |
| 234 | .toString() |
| 235 | .split(':') |
| 236 | .join('-') |
| 237 | .split(' ')[4]; |
| 238 | return this.$t('pageSensors.exportFilePrefix') + date; |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | }; |
| 242 | </script> |