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