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