blob: 373ecc8d76dbceb146210bc70fad0ba96949faf0 [file] [log] [blame]
Yoshie Muranakab89a53c2020-06-15 13:25:46 -07001<template>
Sandeepa Singh7affc522021-07-06 16:29:10 +05302 <page-section :section-title="$t('pageInventory.fans')">
SurenNeware787635a2020-11-24 22:42:42 +05303 <b-row class="align-items-end">
Yoshie Muranakac069c672020-06-18 14:21:50 -07004 <b-col sm="6" md="5" xl="4">
Dixsie Wolmers9b22b492020-09-07 21:26:06 -05005 <search
Sukanya Pandeyedb8a772020-10-29 11:33:42 +05306 @change-search="onChangeSearchInput"
7 @clear-search="onClearSearchInput"
Dixsie Wolmers9b22b492020-09-07 21:26:06 -05008 />
Yoshie Muranakac069c672020-06-18 14:21:50 -07009 </b-col>
Sukanya Pandey99010962020-07-27 21:44:47 +053010 <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 Muranakac069c672020-06-18 14:21:50 -070016 </b-row>
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070017 <b-table
18 sort-icon-left
19 no-sort-reset
Sukanya Pandeyfde429e2020-09-14 20:48:39 +053020 hover
SurenNeware5e25e282020-07-08 15:57:23 +053021 responsive="md"
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070022 sort-by="health"
SurenNeware307382e2020-07-27 20:45:14 +053023 show-empty
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070024 :items="fans"
25 :fields="fields"
26 :sort-desc="true"
27 :sort-compare="sortCompare"
Yoshie Muranakac069c672020-06-18 14:21:50 -070028 :filter="searchFilter"
SurenNeware307382e2020-07-27 20:45:14 +053029 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053030 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Kenneth Fullbright41057852021-12-27 16:19:37 -060031 :busy="isBusy"
Sukanya Pandey99010962020-07-27 21:44:47 +053032 @filtered="onFiltered"
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070033 >
34 <!-- Expand chevron icon -->
Derick Montague602e98a2020-10-21 16:20:00 -050035 <template #cell(expandRow)="row">
Dixsie Wolmers83133762020-07-15 08:45:19 -050036 <b-button
37 variant="link"
38 data-test-id="hardwareStatus-button-expandFans"
Dixsie Wolmers30f11f82020-11-10 16:07:56 -060039 :title="expandRowLabel"
40 class="btn-icon-only"
Dixsie Wolmersb53e0862020-09-08 14:13:38 -050041 @click="toggleRowDetails(row)"
Dixsie Wolmers83133762020-07-15 08:45:19 -050042 >
Dixsie Wolmers30f11f82020-11-10 16:07:56 -060043 <icon-chevron />
SurenNeware6e2cb972020-12-24 20:58:16 +053044 <span class="sr-only">{{ expandRowLabel }}</span>
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070045 </b-button>
46 </template>
47
48 <!-- Health -->
Derick Montague602e98a2020-10-21 16:20:00 -050049 <template #cell(health)="{ value }">
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070050 <status-icon :status="statusIcon(value)" />
51 {{ value }}
52 </template>
53
Farah Rasheeddb2940a2024-07-25 14:04:18 -050054 <!-- StatusState -->
55 <template #cell(statusState)="{ value }">
56 <status-icon :status="statusStateIcon(value)" />
57 {{ value }}
58 </template>
59
Derick Montague602e98a2020-10-21 16:20:00 -050060 <template #row-details="{ item }">
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070061 <b-container fluid>
62 <b-row>
63 <b-col sm="6" xl="4">
64 <dl>
Glukhov Mikhail73d255b2024-01-16 11:17:46 +030065 <!-- ID -->
66 <dt>{{ $t('pageInventory.table.id') }}:</dt>
67 <dd>{{ dataFormatter(item.id) }}</dd>
Dixsie Wolmersdd652d72021-05-13 09:08:53 -050068 </dl>
69 <dl>
70 <!-- Serial number -->
Sandeepa Singh7affc522021-07-06 16:29:10 +053071 <dt>{{ $t('pageInventory.table.serialNumber') }}:</dt>
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -050072 <dd>{{ dataFormatter(item.serialNumber) }}</dd>
Dixsie Wolmersdd652d72021-05-13 09:08:53 -050073 </dl>
74 <dl>
75 <!-- Part number -->
Sandeepa Singh7affc522021-07-06 16:29:10 +053076 <dt>{{ $t('pageInventory.table.partNumber') }}:</dt>
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -050077 <dd>{{ dataFormatter(item.partNumber) }}</dd>
Dixsie Wolmersdd652d72021-05-13 09:08:53 -050078 </dl>
79 <dl>
80 <!-- Fan speed -->
Sandeepa Singh7affc522021-07-06 16:29:10 +053081 <dt>{{ $t('pageInventory.table.fanSpeed') }}:</dt>
Glukhov Mikhaild0b078f2022-12-24 12:16:53 +030082 <dd>
83 {{ dataFormatter(item.speed) }}
84 {{ $t('unit.RPM') }}
85 </dd>
Dixsie Wolmersdd652d72021-05-13 09:08:53 -050086 </dl>
87 </b-col>
88 <b-col sm="6" xl="4">
89 <dl>
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070090 <!-- Status state -->
Sandeepa Singh7affc522021-07-06 16:29:10 +053091 <dt>{{ $t('pageInventory.table.statusState') }}:</dt>
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -050092 <dd>{{ dataFormatter(item.statusState) }}</dd>
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070093 </dl>
Dixsie Wolmersdd652d72021-05-13 09:08:53 -050094 <dl>
95 <!-- Health Rollup state -->
Sandeepa Singh7affc522021-07-06 16:29:10 +053096 <dt>{{ $t('pageInventory.table.statusHealthRollup') }}:</dt>
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -050097 <dd>{{ dataFormatter(item.healthRollup) }}</dd>
Dixsie Wolmersdd652d72021-05-13 09:08:53 -050098 </dl>
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070099 </b-col>
100 </b-row>
101 </b-container>
102 </template>
103 </b-table>
104 </page-section>
105</template>
106
107<script>
108import PageSection from '@/components/Global/PageSection';
109import IconChevron from '@carbon/icons-vue/es/chevron--down/20';
Sukanya Pandey99010962020-07-27 21:44:47 +0530110import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700111
112import StatusIcon from '@/components/Global/StatusIcon';
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500113import DataFormatterMixin from '@/components/Mixins/DataFormatterMixin';
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700114import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranakac069c672020-06-18 14:21:50 -0700115import Search from '@/components/Global/Search';
SurenNewareba91c492020-10-27 14:18:54 +0530116import SearchFilterMixin, {
117 searchFilter,
118} from '@/components/Mixins/SearchFilterMixin';
119import TableRowExpandMixin, {
120 expandRowLabel,
121} from '@/components/Mixins/TableRowExpandMixin';
Surya Vde23ea22024-07-11 15:19:46 +0530122import { useI18n } from 'vue-i18n';
123import i18n from '@/i18n';
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700124
125export default {
Sukanya Pandey99010962020-07-27 21:44:47 +0530126 components: { IconChevron, PageSection, StatusIcon, Search, TableCellCount },
Dixsie Wolmersb53e0862020-09-08 14:13:38 -0500127 mixins: [
128 TableRowExpandMixin,
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500129 DataFormatterMixin,
Dixsie Wolmersb53e0862020-09-08 14:13:38 -0500130 TableSortMixin,
Derick Montague602e98a2020-10-21 16:20:00 -0500131 SearchFilterMixin,
Dixsie Wolmersb53e0862020-09-08 14:13:38 -0500132 ],
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700133 data() {
134 return {
Surya Vde23ea22024-07-11 15:19:46 +0530135 $t: useI18n().t,
Kenneth Fullbright41057852021-12-27 16:19:37 -0600136 isBusy: true,
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700137 fields: [
138 {
139 key: 'expandRow',
140 label: '',
141 tdClass: 'table-row-expand',
Derick Montague602e98a2020-10-21 16:20:00 -0500142 sortable: false,
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700143 },
144 {
Glukhov Mikhail73d255b2024-01-16 11:17:46 +0300145 key: 'name',
Surya Vde23ea22024-07-11 15:19:46 +0530146 label: i18n.global.t('pageInventory.table.name'),
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500147 formatter: this.dataFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500148 sortable: true,
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700149 },
150 {
151 key: 'health',
Surya Vde23ea22024-07-11 15:19:46 +0530152 label: i18n.global.t('pageInventory.table.health'),
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500153 formatter: this.dataFormatter,
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -0500154 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500155 tdClass: 'text-nowrap',
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700156 },
157 {
Farah Rasheeddb2940a2024-07-25 14:04:18 -0500158 key: 'statusState',
159 label: this.$t('pageInventory.table.state'),
160 formatter: this.dataFormatter,
161 tdClass: 'text-nowrap',
162 },
163 {
Sandeepa Singh7affc522021-07-06 16:29:10 +0530164 key: 'partNumber',
Surya Vde23ea22024-07-11 15:19:46 +0530165 label: i18n.global.t('pageInventory.table.partNumber'),
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500166 formatter: this.dataFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500167 sortable: true,
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700168 },
169 {
Sandeepa Singh7affc522021-07-06 16:29:10 +0530170 key: 'serialNumber',
Surya Vde23ea22024-07-11 15:19:46 +0530171 label: i18n.global.t('pageInventory.table.serialNumber'),
Dixsie Wolmers9726f9a2021-09-07 15:33:16 -0500172 formatter: this.dataFormatter,
Derick Montague602e98a2020-10-21 16:20:00 -0500173 },
Yoshie Muranakac069c672020-06-18 14:21:50 -0700174 ],
SurenNewareba91c492020-10-27 14:18:54 +0530175 searchFilter: searchFilter,
Derick Montague602e98a2020-10-21 16:20:00 -0500176 searchTotalFilteredRows: 0,
SurenNewareba91c492020-10-27 14:18:54 +0530177 expandRowLabel: expandRowLabel,
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700178 };
179 },
180 computed: {
Sukanya Pandey99010962020-07-27 21:44:47 +0530181 filteredRows() {
182 return this.searchFilter
183 ? this.searchTotalFilteredRows
184 : this.fans.length;
185 },
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700186 fans() {
187 return this.$store.getters['fan/fans'];
Derick Montague602e98a2020-10-21 16:20:00 -0500188 },
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700189 },
190 created() {
191 this.$store.dispatch('fan/getFanInfo').finally(() => {
Gunnar Millsdefc9e22020-07-07 20:29:03 -0500192 // Emit initial data fetch complete to parent component
Sukanya Pandeyedb8a772020-10-29 11:33:42 +0530193 this.$root.$emit('hardware-status-fans-complete');
Kenneth Fullbright41057852021-12-27 16:19:37 -0600194 this.isBusy = false;
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700195 });
196 },
197 methods: {
198 sortCompare(a, b, key) {
199 if (key === 'health') {
200 return this.sortStatus(a, b, key);
Farah Rasheeddb2940a2024-07-25 14:04:18 -0500201 } else if (key === 'statusState') {
202 return this.sortStatusState(a, b, key);
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700203 }
Yoshie Muranakac069c672020-06-18 14:21:50 -0700204 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530205 onFiltered(filteredItems) {
206 this.searchTotalFilteredRows = filteredItems.length;
Derick Montague602e98a2020-10-21 16:20:00 -0500207 },
Farah Rasheeddb2940a2024-07-25 14:04:18 -0500208 /**
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 Montague602e98a2020-10-21 16:20:00 -0500235 },
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700236};
237</script>