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