blob: 0b6e1a351157f2f3ec4c26a966fb564d1a8ec47f [file] [log] [blame]
Yoshie Muranakab89a53c2020-06-15 13:25:46 -07001<template>
2 <page-section :section-title="$t('pageHardwareStatus.fans')">
Yoshie Muranakac069c672020-06-18 14:21:50 -07003 <b-row>
4 <b-col sm="6" md="5" xl="4">
5 <search @changeSearch="onChangeSearchInput" />
6 </b-col>
Sukanya Pandey99010962020-07-27 21:44:47 +05307 <b-col sm="6" md="3" xl="2">
8 <table-cell-count
9 :filtered-items-count="filteredRows"
10 :total-number-of-cells="fans.length"
11 ></table-cell-count>
12 </b-col>
Yoshie Muranakac069c672020-06-18 14:21:50 -070013 </b-row>
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070014 <b-table
15 sort-icon-left
16 no-sort-reset
SurenNeware5e25e282020-07-08 15:57:23 +053017 responsive="md"
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070018 sort-by="health"
SurenNeware307382e2020-07-27 20:45:14 +053019 show-empty
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070020 :items="fans"
21 :fields="fields"
22 :sort-desc="true"
23 :sort-compare="sortCompare"
Yoshie Muranakac069c672020-06-18 14:21:50 -070024 :filter="searchFilter"
SurenNeware307382e2020-07-27 20:45:14 +053025 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053026 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Sukanya Pandey99010962020-07-27 21:44:47 +053027 @filtered="onFiltered"
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070028 >
29 <!-- Expand chevron icon -->
30 <template v-slot:cell(expandRow)="row">
Dixsie Wolmers83133762020-07-15 08:45:19 -050031 <b-button
32 variant="link"
33 data-test-id="hardwareStatus-button-expandFans"
34 @click="row.toggleDetails"
35 >
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070036 <icon-chevron />
37 </b-button>
38 </template>
39
40 <!-- Health -->
41 <template v-slot:cell(health)="{ value }">
42 <status-icon :status="statusIcon(value)" />
43 {{ value }}
44 </template>
45
46 <template v-slot:row-details="{ item }">
47 <b-container fluid>
48 <b-row>
49 <b-col sm="6" xl="4">
50 <dl>
51 <!-- Status state -->
52 <dt>{{ $t('pageHardwareStatus.table.statusState') }}:</dt>
53 <dd>{{ tableFormatter(item.statusState) }}</dd>
54 </dl>
55 </b-col>
56 </b-row>
57 </b-container>
58 </template>
59 </b-table>
60 </page-section>
61</template>
62
63<script>
64import PageSection from '@/components/Global/PageSection';
65import IconChevron from '@carbon/icons-vue/es/chevron--down/20';
Sukanya Pandey99010962020-07-27 21:44:47 +053066import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070067
68import StatusIcon from '@/components/Global/StatusIcon';
Yoshie Muranaka386df452020-06-18 12:45:13 -070069import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070070import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranakac069c672020-06-18 14:21:50 -070071import Search from '@/components/Global/Search';
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070072
73export default {
Sukanya Pandey99010962020-07-27 21:44:47 +053074 components: { IconChevron, PageSection, StatusIcon, Search, TableCellCount },
Yoshie Muranaka386df452020-06-18 12:45:13 -070075 mixins: [TableDataFormatterMixin, TableSortMixin],
Yoshie Muranakab89a53c2020-06-15 13:25:46 -070076 data() {
77 return {
78 fields: [
79 {
80 key: 'expandRow',
81 label: '',
82 tdClass: 'table-row-expand',
83 sortable: false
84 },
85 {
86 key: 'id',
87 label: this.$t('pageHardwareStatus.table.id'),
88 formatter: this.tableFormatter,
89 sortable: true
90 },
91 {
92 key: 'health',
93 label: this.$t('pageHardwareStatus.table.health'),
94 formatter: this.tableFormatter,
95 sortable: true
96 },
97 {
98 key: 'partNumber',
99 label: this.$t('pageHardwareStatus.table.partNumber'),
100 formatter: this.tableFormatter,
101 sortable: true
102 },
103 {
104 key: 'serialNumber',
105 label: this.$t('pageHardwareStatus.table.serialNumber'),
106 formatter: this.tableFormatter,
107 sortable: true
108 }
Yoshie Muranakac069c672020-06-18 14:21:50 -0700109 ],
Sukanya Pandey99010962020-07-27 21:44:47 +0530110 searchFilter: null,
111 searchTotalFilteredRows: 0
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700112 };
113 },
114 computed: {
Sukanya Pandey99010962020-07-27 21:44:47 +0530115 filteredRows() {
116 return this.searchFilter
117 ? this.searchTotalFilteredRows
118 : this.fans.length;
119 },
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700120 fans() {
121 return this.$store.getters['fan/fans'];
122 }
123 },
124 created() {
125 this.$store.dispatch('fan/getFanInfo').finally(() => {
Gunnar Millsdefc9e22020-07-07 20:29:03 -0500126 // Emit initial data fetch complete to parent component
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700127 this.$root.$emit('hardwareStatus::fans::complete');
128 });
129 },
130 methods: {
131 sortCompare(a, b, key) {
132 if (key === 'health') {
133 return this.sortStatus(a, b, key);
134 }
Yoshie Muranakac069c672020-06-18 14:21:50 -0700135 },
136 onChangeSearchInput(searchValue) {
137 this.searchFilter = searchValue;
Sukanya Pandey99010962020-07-27 21:44:47 +0530138 },
139 onFiltered(filteredItems) {
140 this.searchTotalFilteredRows = filteredItems.length;
Yoshie Muranakab89a53c2020-06-15 13:25:46 -0700141 }
142 }
143};
144</script>