Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 1 | <template> |
Sandeepa Singh | 7affc52 | 2021-07-06 16:29:10 +0530 | [diff] [blame] | 2 | <page-section :section-title="$t('pageInventory.fans')"> |
SurenNeware | 787635a | 2020-11-24 22:42:42 +0530 | [diff] [blame] | 3 | <b-row class="align-items-end"> |
Yoshie Muranaka | c069c67 | 2020-06-18 14:21:50 -0700 | [diff] [blame] | 4 | <b-col sm="6" md="5" xl="4"> |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 5 | <search |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 6 | @change-search="onChangeSearchInput" |
| 7 | @clear-search="onClearSearchInput" |
Dixsie Wolmers | 9b22b49 | 2020-09-07 21:26:06 -0500 | [diff] [blame] | 8 | /> |
Yoshie Muranaka | c069c67 | 2020-06-18 14:21:50 -0700 | [diff] [blame] | 9 | </b-col> |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 10 | <b-col sm="6" md="3" xl="2"> |
| 11 | <table-cell-count |
| 12 | :filtered-items-count="filteredRows" |
| 13 | :total-number-of-cells="fans.length" |
| 14 | ></table-cell-count> |
| 15 | </b-col> |
Yoshie Muranaka | c069c67 | 2020-06-18 14:21:50 -0700 | [diff] [blame] | 16 | </b-row> |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 17 | <b-table |
| 18 | sort-icon-left |
| 19 | no-sort-reset |
Sukanya Pandey | fde429e | 2020-09-14 20:48:39 +0530 | [diff] [blame] | 20 | hover |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 21 | responsive="md" |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 22 | sort-by="health" |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 23 | show-empty |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 24 | :items="fans" |
| 25 | :fields="fields" |
| 26 | :sort-desc="true" |
| 27 | :sort-compare="sortCompare" |
Yoshie Muranaka | c069c67 | 2020-06-18 14:21:50 -0700 | [diff] [blame] | 28 | :filter="searchFilter" |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 29 | :empty-text="$t('global.table.emptyMessage')" |
SurenNeware | 156a0e6 | 2020-08-28 19:20:03 +0530 | [diff] [blame] | 30 | :empty-filtered-text="$t('global.table.emptySearchMessage')" |
Kenneth Fullbright | 4105785 | 2021-12-27 16:19:37 -0600 | [diff] [blame] | 31 | :busy="isBusy" |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 32 | @filtered="onFiltered" |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 33 | > |
| 34 | <!-- Expand chevron icon --> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 35 | <template #cell(expandRow)="row"> |
Dixsie Wolmers | 8313376 | 2020-07-15 08:45:19 -0500 | [diff] [blame] | 36 | <b-button |
| 37 | variant="link" |
| 38 | data-test-id="hardwareStatus-button-expandFans" |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 39 | :title="expandRowLabel" |
| 40 | class="btn-icon-only" |
Dixsie Wolmers | b53e086 | 2020-09-08 14:13:38 -0500 | [diff] [blame] | 41 | @click="toggleRowDetails(row)" |
Dixsie Wolmers | 8313376 | 2020-07-15 08:45:19 -0500 | [diff] [blame] | 42 | > |
Dixsie Wolmers | 30f11f8 | 2020-11-10 16:07:56 -0600 | [diff] [blame] | 43 | <icon-chevron /> |
SurenNeware | 6e2cb97 | 2020-12-24 20:58:16 +0530 | [diff] [blame] | 44 | <span class="sr-only">{{ expandRowLabel }}</span> |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 45 | </b-button> |
| 46 | </template> |
| 47 | |
| 48 | <!-- Health --> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 49 | <template #cell(health)="{ value }"> |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 50 | <status-icon :status="statusIcon(value)" /> |
| 51 | {{ value }} |
| 52 | </template> |
| 53 | |
Farah Rasheed | db2940a | 2024-07-25 14:04:18 -0500 | [diff] [blame] | 54 | <!-- StatusState --> |
| 55 | <template #cell(statusState)="{ value }"> |
| 56 | <status-icon :status="statusStateIcon(value)" /> |
| 57 | {{ value }} |
| 58 | </template> |
| 59 | |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 60 | <template #row-details="{ item }"> |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 61 | <b-container fluid> |
| 62 | <b-row> |
| 63 | <b-col sm="6" xl="4"> |
| 64 | <dl> |
Glukhov Mikhail | 73d255b | 2024-01-16 11:17:46 +0300 | [diff] [blame] | 65 | <!-- ID --> |
| 66 | <dt>{{ $t('pageInventory.table.id') }}:</dt> |
| 67 | <dd>{{ dataFormatter(item.id) }}</dd> |
Dixsie Wolmers | dd652d7 | 2021-05-13 09:08:53 -0500 | [diff] [blame] | 68 | </dl> |
| 69 | <dl> |
| 70 | <!-- Serial number --> |
Sandeepa Singh | 7affc52 | 2021-07-06 16:29:10 +0530 | [diff] [blame] | 71 | <dt>{{ $t('pageInventory.table.serialNumber') }}:</dt> |
Dixsie Wolmers | 9726f9a | 2021-09-07 15:33:16 -0500 | [diff] [blame] | 72 | <dd>{{ dataFormatter(item.serialNumber) }}</dd> |
Dixsie Wolmers | dd652d7 | 2021-05-13 09:08:53 -0500 | [diff] [blame] | 73 | </dl> |
| 74 | <dl> |
| 75 | <!-- Part number --> |
Sandeepa Singh | 7affc52 | 2021-07-06 16:29:10 +0530 | [diff] [blame] | 76 | <dt>{{ $t('pageInventory.table.partNumber') }}:</dt> |
Dixsie Wolmers | 9726f9a | 2021-09-07 15:33:16 -0500 | [diff] [blame] | 77 | <dd>{{ dataFormatter(item.partNumber) }}</dd> |
Dixsie Wolmers | dd652d7 | 2021-05-13 09:08:53 -0500 | [diff] [blame] | 78 | </dl> |
| 79 | <dl> |
| 80 | <!-- Fan speed --> |
Sandeepa Singh | 7affc52 | 2021-07-06 16:29:10 +0530 | [diff] [blame] | 81 | <dt>{{ $t('pageInventory.table.fanSpeed') }}:</dt> |
Glukhov Mikhail | d0b078f | 2022-12-24 12:16:53 +0300 | [diff] [blame] | 82 | <dd> |
| 83 | {{ dataFormatter(item.speed) }} |
| 84 | {{ $t('unit.RPM') }} |
| 85 | </dd> |
Dixsie Wolmers | dd652d7 | 2021-05-13 09:08:53 -0500 | [diff] [blame] | 86 | </dl> |
| 87 | </b-col> |
| 88 | <b-col sm="6" xl="4"> |
| 89 | <dl> |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 90 | <!-- Status state --> |
Sandeepa Singh | 7affc52 | 2021-07-06 16:29:10 +0530 | [diff] [blame] | 91 | <dt>{{ $t('pageInventory.table.statusState') }}:</dt> |
Dixsie Wolmers | 9726f9a | 2021-09-07 15:33:16 -0500 | [diff] [blame] | 92 | <dd>{{ dataFormatter(item.statusState) }}</dd> |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 93 | </dl> |
Dixsie Wolmers | dd652d7 | 2021-05-13 09:08:53 -0500 | [diff] [blame] | 94 | <dl> |
| 95 | <!-- Health Rollup state --> |
Sandeepa Singh | 7affc52 | 2021-07-06 16:29:10 +0530 | [diff] [blame] | 96 | <dt>{{ $t('pageInventory.table.statusHealthRollup') }}:</dt> |
Dixsie Wolmers | 9726f9a | 2021-09-07 15:33:16 -0500 | [diff] [blame] | 97 | <dd>{{ dataFormatter(item.healthRollup) }}</dd> |
Dixsie Wolmers | dd652d7 | 2021-05-13 09:08:53 -0500 | [diff] [blame] | 98 | </dl> |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 99 | </b-col> |
| 100 | </b-row> |
| 101 | </b-container> |
| 102 | </template> |
| 103 | </b-table> |
| 104 | </page-section> |
| 105 | </template> |
| 106 | |
| 107 | <script> |
| 108 | import PageSection from '@/components/Global/PageSection'; |
| 109 | import IconChevron from '@carbon/icons-vue/es/chevron--down/20'; |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 110 | import TableCellCount from '@/components/Global/TableCellCount'; |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 111 | |
| 112 | import StatusIcon from '@/components/Global/StatusIcon'; |
Dixsie Wolmers | 9726f9a | 2021-09-07 15:33:16 -0500 | [diff] [blame] | 113 | import DataFormatterMixin from '@/components/Mixins/DataFormatterMixin'; |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 114 | import TableSortMixin from '@/components/Mixins/TableSortMixin'; |
Yoshie Muranaka | c069c67 | 2020-06-18 14:21:50 -0700 | [diff] [blame] | 115 | import Search from '@/components/Global/Search'; |
SurenNeware | ba91c49 | 2020-10-27 14:18:54 +0530 | [diff] [blame] | 116 | import SearchFilterMixin, { |
| 117 | searchFilter, |
| 118 | } from '@/components/Mixins/SearchFilterMixin'; |
| 119 | import TableRowExpandMixin, { |
| 120 | expandRowLabel, |
| 121 | } from '@/components/Mixins/TableRowExpandMixin'; |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 122 | import { useI18n } from 'vue-i18n'; |
| 123 | import i18n from '@/i18n'; |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 124 | |
| 125 | export default { |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 126 | components: { IconChevron, PageSection, StatusIcon, Search, TableCellCount }, |
Dixsie Wolmers | b53e086 | 2020-09-08 14:13:38 -0500 | [diff] [blame] | 127 | mixins: [ |
| 128 | TableRowExpandMixin, |
Dixsie Wolmers | 9726f9a | 2021-09-07 15:33:16 -0500 | [diff] [blame] | 129 | DataFormatterMixin, |
Dixsie Wolmers | b53e086 | 2020-09-08 14:13:38 -0500 | [diff] [blame] | 130 | TableSortMixin, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 131 | SearchFilterMixin, |
Dixsie Wolmers | b53e086 | 2020-09-08 14:13:38 -0500 | [diff] [blame] | 132 | ], |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 133 | data() { |
| 134 | return { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 135 | $t: useI18n().t, |
Kenneth Fullbright | 4105785 | 2021-12-27 16:19:37 -0600 | [diff] [blame] | 136 | isBusy: true, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 137 | fields: [ |
| 138 | { |
| 139 | key: 'expandRow', |
| 140 | label: '', |
| 141 | tdClass: 'table-row-expand', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 142 | sortable: false, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 143 | }, |
| 144 | { |
Glukhov Mikhail | 73d255b | 2024-01-16 11:17:46 +0300 | [diff] [blame] | 145 | key: 'name', |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 146 | label: i18n.global.t('pageInventory.table.name'), |
Dixsie Wolmers | 9726f9a | 2021-09-07 15:33:16 -0500 | [diff] [blame] | 147 | formatter: this.dataFormatter, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 148 | sortable: true, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 149 | }, |
| 150 | { |
| 151 | key: 'health', |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 152 | label: i18n.global.t('pageInventory.table.health'), |
Dixsie Wolmers | 9726f9a | 2021-09-07 15:33:16 -0500 | [diff] [blame] | 153 | formatter: this.dataFormatter, |
Dixsie Wolmers | a04d46f | 2020-10-22 06:34:56 -0500 | [diff] [blame] | 154 | sortable: true, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 155 | tdClass: 'text-nowrap', |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 156 | }, |
| 157 | { |
Farah Rasheed | db2940a | 2024-07-25 14:04:18 -0500 | [diff] [blame] | 158 | key: 'statusState', |
| 159 | label: this.$t('pageInventory.table.state'), |
| 160 | formatter: this.dataFormatter, |
| 161 | tdClass: 'text-nowrap', |
| 162 | }, |
| 163 | { |
Sandeepa Singh | 7affc52 | 2021-07-06 16:29:10 +0530 | [diff] [blame] | 164 | key: 'partNumber', |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 165 | label: i18n.global.t('pageInventory.table.partNumber'), |
Dixsie Wolmers | 9726f9a | 2021-09-07 15:33:16 -0500 | [diff] [blame] | 166 | formatter: this.dataFormatter, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 167 | sortable: true, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 168 | }, |
| 169 | { |
Sandeepa Singh | 7affc52 | 2021-07-06 16:29:10 +0530 | [diff] [blame] | 170 | key: 'serialNumber', |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 171 | label: i18n.global.t('pageInventory.table.serialNumber'), |
Dixsie Wolmers | 9726f9a | 2021-09-07 15:33:16 -0500 | [diff] [blame] | 172 | formatter: this.dataFormatter, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 173 | }, |
Yoshie Muranaka | c069c67 | 2020-06-18 14:21:50 -0700 | [diff] [blame] | 174 | ], |
SurenNeware | ba91c49 | 2020-10-27 14:18:54 +0530 | [diff] [blame] | 175 | searchFilter: searchFilter, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 176 | searchTotalFilteredRows: 0, |
SurenNeware | ba91c49 | 2020-10-27 14:18:54 +0530 | [diff] [blame] | 177 | expandRowLabel: expandRowLabel, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 178 | }; |
| 179 | }, |
| 180 | computed: { |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 181 | filteredRows() { |
| 182 | return this.searchFilter |
| 183 | ? this.searchTotalFilteredRows |
| 184 | : this.fans.length; |
| 185 | }, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 186 | fans() { |
| 187 | return this.$store.getters['fan/fans']; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 188 | }, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 189 | }, |
| 190 | created() { |
| 191 | this.$store.dispatch('fan/getFanInfo').finally(() => { |
Gunnar Mills | defc9e2 | 2020-07-07 20:29:03 -0500 | [diff] [blame] | 192 | // Emit initial data fetch complete to parent component |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 193 | this.$root.$emit('hardware-status-fans-complete'); |
Kenneth Fullbright | 4105785 | 2021-12-27 16:19:37 -0600 | [diff] [blame] | 194 | this.isBusy = false; |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 195 | }); |
| 196 | }, |
| 197 | methods: { |
| 198 | sortCompare(a, b, key) { |
| 199 | if (key === 'health') { |
| 200 | return this.sortStatus(a, b, key); |
Farah Rasheed | db2940a | 2024-07-25 14:04:18 -0500 | [diff] [blame] | 201 | } else if (key === 'statusState') { |
| 202 | return this.sortStatusState(a, b, key); |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 203 | } |
Yoshie Muranaka | c069c67 | 2020-06-18 14:21:50 -0700 | [diff] [blame] | 204 | }, |
Sukanya Pandey | 9901096 | 2020-07-27 21:44:47 +0530 | [diff] [blame] | 205 | onFiltered(filteredItems) { |
| 206 | this.searchTotalFilteredRows = filteredItems.length; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 207 | }, |
Farah Rasheed | db2940a | 2024-07-25 14:04:18 -0500 | [diff] [blame] | 208 | /** |
| 209 | * Returns the appropriate icon based on the given status. |
| 210 | * |
| 211 | * @param {string} status - The status to determine the icon for. |
| 212 | * @return {string} The icon corresponding to the given status. |
| 213 | */ |
| 214 | statusStateIcon(status) { |
| 215 | switch (status) { |
| 216 | case 'Enabled': |
| 217 | return 'success'; |
| 218 | case 'Absent': |
| 219 | return 'warning'; |
| 220 | default: |
| 221 | return ''; |
| 222 | } |
| 223 | }, |
| 224 | /** |
| 225 | * Sorts the status state of two objects based on the provided key. |
| 226 | * |
| 227 | * @param {Object} a - The first object to compare. |
| 228 | * @param {Object} b - The second object to compare. |
| 229 | * @param {string} key - The key to use for comparison. |
| 230 | */ |
| 231 | sortStatusState(a, b, key) { |
| 232 | const statusState = ['Enabled', 'Absent']; |
| 233 | return statusState.indexOf(a[key]) - statusState.indexOf(b[key]); |
| 234 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 235 | }, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 236 | }; |
| 237 | </script> |