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