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