1<template>
2  <page-section :section-title="$t('pageInventory.dimmSlot')">
3    <b-row class="align-items-end">
4      <b-col sm="6" md="5" xl="4">
5        <search
6          @change-search="onChangeSearchInput"
7          @clear-search="onClearSearchInput"
8        />
9      </b-col>
10      <b-col sm="6" md="3" xl="2">
11        <table-cell-count
12          :filtered-items-count="filteredRows"
13          :total-number-of-cells="dimms.length"
14        ></table-cell-count>
15      </b-col>
16    </b-row>
17    <b-table
18      sort-icon-left
19      no-sort-reset
20      hover
21      sort-by="health"
22      responsive="md"
23      show-empty
24      :items="dimms"
25      :fields="fields"
26      :sort-desc="true"
27      :sort-compare="sortCompare"
28      :filter="searchFilter"
29      :empty-text="$t('global.table.emptyMessage')"
30      :empty-filtered-text="$t('global.table.emptySearchMessage')"
31      :busy="isBusy"
32      @filtered="onFiltered"
33    >
34      <!-- Expand chevron icon -->
35      <template #cell(expandRow)="row">
36        <b-button
37          variant="link"
38          data-test-id="hardwareStatus-button-expandDimms"
39          :title="expandRowLabel"
40          class="btn-icon-only"
41          @click="toggleRowDetails(row)"
42        >
43          <icon-chevron />
44          <span class="sr-only">{{ expandRowLabel }}</span>
45        </b-button>
46      </template>
47
48      <!-- Health -->
49      <template #cell(health)="{ value }">
50        <status-icon :status="statusIcon(value)" />
51        {{ value }}
52      </template>
53      <!-- Toggle identify LED -->
54      <template #cell(identifyLed)="row">
55        <b-form-checkbox
56          v-if="hasIdentifyLed(row.item.identifyLed)"
57          v-model="row.item.identifyLed"
58          name="switch"
59          switch
60          @change="toggleIdentifyLedValue(row.item)"
61        >
62          <span v-if="row.item.identifyLed">
63            {{ $t('global.status.on') }}
64          </span>
65          <span v-else> {{ $t('global.status.off') }} </span>
66        </b-form-checkbox>
67        <div v-else>--</div>
68      </template>
69      <template #row-details="{ item }">
70        <b-container fluid>
71          <b-row>
72            <b-col sm="6" xl="6">
73              <dl>
74                <!-- Part Number -->
75                <dt>{{ $t('pageInventory.table.partNumber') }}:</dt>
76                <dd>{{ dataFormatter(item.partNumber) }}</dd>
77              </dl>
78              <dl>
79                <!-- Serial Number -->
80                <dt>{{ $t('pageInventory.table.serialNumber') }}:</dt>
81                <dd>{{ dataFormatter(item.serialNumber) }}</dd>
82              </dl>
83              <dl>
84                <!-- Spare Part Number -->
85                <dt>{{ $t('pageInventory.table.sparePartNumber') }}:</dt>
86                <dd>{{ dataFormatter(item.sparePartNumber) }}</dd>
87              </dl>
88              <dl>
89                <!-- Model -->
90                <dt>{{ $t('pageInventory.table.model') }}:</dt>
91                <dd>{{ dataFormatter(item.model) }}</dd>
92              </dl>
93            </b-col>
94            <b-col sm="6" xl="6">
95              <dl>
96                <!-- Capacity MiB -->
97                <dt>{{ $t('pageInventory.table.capacityMiB') }}:</dt>
98                <dd>
99                  {{ dataFormatter(item.capacityMiB) }}
100                  {{ $t('unit.MiB') }}
101                </dd>
102              </dl>
103              <dl>
104                <!-- Status-->
105                <dt>{{ $t('pageInventory.table.statusState') }}:</dt>
106                <dd>{{ dataFormatter(item.statusState) }}</dd>
107              </dl>
108              <dl>
109                <!-- Enabled-->
110                <dt>{{ $t('pageInventory.table.enabled') }}:</dt>
111                <dd>{{ dataFormatter(item.enabled) }}</dd>
112              </dl>
113            </b-col>
114          </b-row>
115          <div class="section-divider mb-3 mt-3"></div>
116          <b-row>
117            <b-col sm="6" xl="6">
118              <dl>
119                <!-- Description -->
120                <dt>{{ $t('pageInventory.table.description') }}:</dt>
121                <dd>{{ dataFormatter(item.description) }}</dd>
122              </dl>
123              <dl>
124                <!-- Memory Type -->
125                <dt>{{ $t('pageInventory.table.memoryType') }}:</dt>
126                <dd>{{ dataFormatter(item.memoryType) }}</dd>
127              </dl>
128              <dl>
129                <!-- Base Module Type -->
130                <dt>{{ $t('pageInventory.table.baseModuleType') }}:</dt>
131                <dd>{{ dataFormatter(item.baseModuleType) }}</dd>
132              </dl>
133            </b-col>
134            <b-col sm="6" xl="6">
135              <dl>
136                <!-- Bus Width Bits -->
137                <dt>{{ $t('pageInventory.table.busWidthBits') }}:</dt>
138                <dd>
139                  {{ dataFormatter(item.busWidthBits) }}
140                  {{ $t('unit.bit') }}
141                </dd>
142              </dl>
143              <dl>
144                <!-- Data Width Bits -->
145                <dt>{{ $t('pageInventory.table.dataWidthBits') }}:</dt>
146                <dd>
147                  {{ dataFormatter(item.dataWidthBits) }}
148                  {{ $t('unit.bit') }}
149                </dd>
150              </dl>
151              <dl>
152                <!-- Operating Speed Mhz -->
153                <dt>{{ $t('pageInventory.table.operatingSpeedMhz') }}:</dt>
154                <dd>
155                  {{ dataFormatter(item.operatingSpeedMhz) }}
156                  {{ $t('unit.MHz') }}
157                </dd>
158              </dl>
159            </b-col>
160          </b-row>
161        </b-container>
162      </template>
163    </b-table>
164  </page-section>
165</template>
166
167<script>
168import PageSection from '@/components/Global/PageSection';
169import IconChevron from '@carbon/icons-vue/es/chevron--down/20';
170
171import StatusIcon from '@/components/Global/StatusIcon';
172import TableCellCount from '@/components/Global/TableCellCount';
173
174import DataFormatterMixin from '@/components/Mixins/DataFormatterMixin';
175import TableSortMixin from '@/components/Mixins/TableSortMixin';
176import Search from '@/components/Global/Search';
177import SearchFilterMixin, {
178  searchFilter,
179} from '@/components/Mixins/SearchFilterMixin';
180import TableRowExpandMixin, {
181  expandRowLabel,
182} from '@/components/Mixins/TableRowExpandMixin';
183
184export default {
185  components: { IconChevron, PageSection, StatusIcon, Search, TableCellCount },
186  mixins: [
187    TableRowExpandMixin,
188    DataFormatterMixin,
189    TableSortMixin,
190    SearchFilterMixin,
191  ],
192  data() {
193    return {
194      isBusy: true,
195      fields: [
196        {
197          key: 'expandRow',
198          label: '',
199          tdClass: 'table-row-expand',
200        },
201        {
202          key: 'id',
203          label: this.$t('pageInventory.table.id'),
204          formatter: this.dataFormatter,
205        },
206        {
207          key: 'health',
208          label: this.$t('pageInventory.table.health'),
209          formatter: this.dataFormatter,
210          tdClass: 'text-nowrap',
211        },
212        {
213          key: 'locationNumber',
214          label: this.$t('pageInventory.table.locationNumber'),
215          formatter: this.dataFormatter,
216        },
217        {
218          key: 'identifyLed',
219          label: this.$t('pageInventory.table.identifyLed'),
220          formatter: this.dataFormatter,
221        },
222      ],
223      searchFilter: searchFilter,
224      searchTotalFilteredRows: 0,
225      expandRowLabel: expandRowLabel,
226    };
227  },
228  computed: {
229    filteredRows() {
230      return this.searchFilter
231        ? this.searchTotalFilteredRows
232        : this.dimms.length;
233    },
234    dimms() {
235      return this.$store.getters['memory/dimms'];
236    },
237  },
238  created() {
239    this.$store.dispatch('memory/getDimms').finally(() => {
240      // Emit initial data fetch complete to parent component
241      this.$root.$emit('hardware-status-dimm-slot-complete');
242      this.isBusy = false;
243    });
244  },
245  methods: {
246    sortCompare(a, b, key) {
247      if (key === 'health') {
248        return this.sortStatus(a, b, key);
249      }
250    },
251    onFiltered(filteredItems) {
252      this.searchTotalFilteredRows = filteredItems.length;
253    },
254    toggleIdentifyLedValue(row) {
255      this.$store
256        .dispatch('memory/updateIdentifyLedValue', {
257          uri: row.uri,
258          identifyLed: row.identifyLed,
259        })
260        .catch(({ message }) => this.errorToast(message));
261    },
262    hasIdentifyLed(identifyLed) {
263      return typeof identifyLed === 'boolean';
264    },
265  },
266};
267</script>
268