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"> |
| 11 | <b-table |
| 12 | sort-icon-left |
| 13 | no-sort-reset |
| 14 | sticky-header="75vh" |
| 15 | sort-by="status" |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 16 | :items="filteredSensors" |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 17 | :fields="fields" |
| 18 | :sort-desc="true" |
| 19 | :sort-compare="sortCompare" |
| 20 | > |
| 21 | <template v-slot:cell(status)="{ value }"> |
| 22 | <status-icon :status="statusIcon(value)" /> |
| 23 | {{ value }} |
| 24 | </template> |
| 25 | <template v-slot:cell(currentValue)="data"> |
| 26 | {{ data.value }} {{ data.item.units }} |
| 27 | </template> |
| 28 | <template v-slot:cell(lowerCaution)="data"> |
| 29 | {{ data.value }} {{ data.item.units }} |
| 30 | </template> |
| 31 | <template v-slot:cell(upperCaution)="data"> |
| 32 | {{ data.value }} {{ data.item.units }} |
| 33 | </template> |
| 34 | <template v-slot:cell(lowerCritical)="data"> |
| 35 | {{ data.value }} {{ data.item.units }} |
| 36 | </template> |
| 37 | <template v-slot:cell(upperCritical)="data"> |
| 38 | {{ data.value }} {{ data.item.units }} |
| 39 | </template> |
| 40 | </b-table> |
| 41 | </b-col> |
| 42 | </b-row> |
| 43 | </b-container> |
| 44 | </template> |
| 45 | |
| 46 | <script> |
| 47 | import PageTitle from '../../../components/Global/PageTitle'; |
| 48 | import StatusIcon from '../../../components/Global/StatusIcon'; |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 49 | import TableFilter from '../../../components/Global/TableFilter'; |
| 50 | import TableFilterMixin from '../../../components/Mixins/TableFilterMixin'; |
| 51 | |
| 52 | const SENSOR_STATUS = ['OK', 'Warning', 'Critical']; |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 53 | |
| 54 | const valueFormatter = value => { |
| 55 | if (value === null || value === undefined) { |
| 56 | return '--'; |
| 57 | } |
| 58 | return parseFloat(value.toFixed(3)); |
| 59 | }; |
| 60 | |
| 61 | export default { |
| 62 | name: 'Sensors', |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 63 | components: { PageTitle, StatusIcon, TableFilter }, |
| 64 | mixins: [TableFilterMixin], |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 65 | data() { |
| 66 | return { |
| 67 | fields: [ |
| 68 | { |
| 69 | key: 'name', |
| 70 | sortable: true, |
| 71 | label: this.$t('pageSensors.table.name') |
| 72 | }, |
| 73 | { |
| 74 | key: 'status', |
| 75 | sortable: true, |
| 76 | label: this.$t('pageSensors.table.status') |
| 77 | }, |
| 78 | { |
| 79 | key: 'lowerCritical', |
| 80 | formatter: valueFormatter, |
| 81 | label: this.$t('pageSensors.table.lowerCritical') |
| 82 | }, |
| 83 | { |
| 84 | key: 'lowerCaution', |
| 85 | formatter: valueFormatter, |
| 86 | label: this.$t('pageSensors.table.lowerWarning') |
| 87 | }, |
| 88 | |
| 89 | { |
| 90 | key: 'currentValue', |
| 91 | formatter: valueFormatter, |
| 92 | label: this.$t('pageSensors.table.currentValue') |
| 93 | }, |
| 94 | { |
| 95 | key: 'upperCaution', |
| 96 | formatter: valueFormatter, |
| 97 | label: this.$t('pageSensors.table.upperWarning') |
| 98 | }, |
| 99 | { |
| 100 | key: 'upperCritical', |
| 101 | formatter: valueFormatter, |
| 102 | label: this.$t('pageSensors.table.upperCritical') |
| 103 | } |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 104 | ], |
| 105 | tableFilters: [ |
| 106 | { |
| 107 | label: this.$t('pageSensors.table.status'), |
| 108 | values: SENSOR_STATUS |
| 109 | } |
| 110 | ], |
| 111 | activeFilters: [] |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 112 | }; |
| 113 | }, |
| 114 | computed: { |
| 115 | allSensors() { |
| 116 | return this.$store.getters['sensors/sensors']; |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 117 | }, |
| 118 | filteredSensors: { |
| 119 | get: function() { |
| 120 | return this.getFilteredTableData(this.allSensors, this.activeFilters); |
| 121 | }, |
| 122 | set: function(newVal) { |
| 123 | return newVal; |
| 124 | } |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 125 | } |
| 126 | }, |
| 127 | created() { |
| 128 | this.$store.dispatch('sensors/getAllSensors'); |
| 129 | }, |
| 130 | methods: { |
| 131 | statusIcon(status) { |
| 132 | switch (status) { |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 133 | case SENSOR_STATUS[0]: |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 134 | return 'success'; |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 135 | case SENSOR_STATUS[1]: |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 136 | return 'warning'; |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 137 | case SENSOR_STATUS[2]: |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 138 | return 'danger'; |
| 139 | default: |
| 140 | return ''; |
| 141 | } |
| 142 | }, |
| 143 | sortCompare(a, b, key) { |
| 144 | if (key === 'status') { |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 145 | return ( |
| 146 | SENSOR_STATUS.indexOf(a.status) - SENSOR_STATUS.indexOf(b.status) |
| 147 | ); |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 148 | } |
Yoshie Muranaka | 82cca54 | 2020-04-07 10:20:37 -0700 | [diff] [blame] | 149 | }, |
| 150 | onFilterChange({ activeFilters }) { |
| 151 | this.activeFilters = activeFilters; |
| 152 | this.filteredSensors = this.getFilteredTableData( |
| 153 | this.allSensors, |
| 154 | activeFilters |
| 155 | ); |
Yoshie Muranaka | 30abccb | 2020-03-11 12:44:24 -0700 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | }; |
| 159 | </script> |