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