Skip to content

Commit db2940a

Browse files
committed
Add status state info to inventory tables
Add status state information to the inventory tables for fans and power supplies. Also updates sortCompare to be able to sort by the state. Change-Id: Ic830dd0867daee0bf6052a5d1cff5592b98fc009 Signed-off-by: Farah Rasheed <[email protected]>
1 parent 09a3b9e commit db2940a

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

src/views/HardwareStatus/Inventory/InventoryTableFans.vue

+41
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
{{ value }}
5252
</template>
5353

54+
<!-- StatusState -->
55+
<template #cell(statusState)="{ value }">
56+
<status-icon :status="statusStateIcon(value)" />
57+
{{ value }}
58+
</template>
59+
5460
<template #row-details="{ item }">
5561
<b-container fluid>
5662
<b-row>
@@ -145,6 +151,12 @@ export default {
145151
sortable: true,
146152
tdClass: 'text-nowrap',
147153
},
154+
{
155+
key: 'statusState',
156+
label: this.$t('pageInventory.table.state'),
157+
formatter: this.dataFormatter,
158+
tdClass: 'text-nowrap',
159+
},
148160
{
149161
key: 'partNumber',
150162
label: this.$t('pageInventory.table.partNumber'),
@@ -183,11 +195,40 @@ export default {
183195
sortCompare(a, b, key) {
184196
if (key === 'health') {
185197
return this.sortStatus(a, b, key);
198+
} else if (key === 'statusState') {
199+
return this.sortStatusState(a, b, key);
186200
}
187201
},
188202
onFiltered(filteredItems) {
189203
this.searchTotalFilteredRows = filteredItems.length;
190204
},
205+
/**
206+
* Returns the appropriate icon based on the given status.
207+
*
208+
* @param {string} status - The status to determine the icon for.
209+
* @return {string} The icon corresponding to the given status.
210+
*/
211+
statusStateIcon(status) {
212+
switch (status) {
213+
case 'Enabled':
214+
return 'success';
215+
case 'Absent':
216+
return 'warning';
217+
default:
218+
return '';
219+
}
220+
},
221+
/**
222+
* Sorts the status state of two objects based on the provided key.
223+
*
224+
* @param {Object} a - The first object to compare.
225+
* @param {Object} b - The second object to compare.
226+
* @param {string} key - The key to use for comparison.
227+
*/
228+
sortStatusState(a, b, key) {
229+
const statusState = ['Enabled', 'Absent'];
230+
return statusState.indexOf(a[key]) - statusState.indexOf(b[key]);
231+
},
191232
},
192233
};
193234
</script>

src/views/HardwareStatus/Inventory/InventoryTablePowerSupplies.vue

+39
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
{{ value }}
5252
</template>
5353

54+
<!-- StatusState -->
55+
<template #cell(statusState)="{ value }">
56+
<status-icon :status="statusStateIcon(value)" />
57+
{{ value }}
58+
</template>
59+
5460
<template #row-details="{ item }">
5561
<b-container fluid>
5662
<b-row>
@@ -166,6 +172,12 @@ export default {
166172
sortable: true,
167173
tdClass: 'text-nowrap',
168174
},
175+
{
176+
key: 'statusState',
177+
label: this.$t('pageInventory.table.state'),
178+
formatter: this.dataFormatter,
179+
tdClass: 'text-nowrap',
180+
},
169181
{
170182
key: 'locationNumber',
171183
label: this.$t('pageInventory.table.locationNumber'),
@@ -204,11 +216,38 @@ export default {
204216
sortCompare(a, b, key) {
205217
if (key === 'health') {
206218
return this.sortStatus(a, b, key);
219+
} else if (key === 'statusState') {
220+
return this.sortStatusState(a, b, key);
207221
}
208222
},
209223
onFiltered(filteredItems) {
210224
this.searchTotalFilteredRows = filteredItems.length;
211225
},
226+
/**
227+
* Returns the icon to use for status state based on the given status.
228+
* @param {string} status The status to determine the icon for.
229+
* @return {string} The icon for the given status.
230+
*/
231+
statusStateIcon(status) {
232+
switch (status) {
233+
case 'Enabled':
234+
return 'success';
235+
case 'Absent':
236+
return 'warning';
237+
default:
238+
return '';
239+
}
240+
},
241+
/**
242+
* Sorts the status state of two objects based on the provided key.
243+
* @param {Object} a The first object to compare.
244+
* @param {Object} b The second object to compare.
245+
* @param {string} key The key to use for comparison.
246+
*/
247+
sortStatusState(a, b, key) {
248+
const statusState = ['Enabled', 'Absent'];
249+
return statusState.indexOf(a[key]) - statusState.indexOf(b[key]);
250+
},
212251
},
213252
};
214253
</script>

0 commit comments

Comments
 (0)