From 65237e34ee6efb0b9e2c49d2eeac19a7a8659474 Mon Sep 17 00:00:00 2001
From: roly <Rolyli.Li@luxshare-ict.com>
Date: Wed, 6 Nov 2024 10:56:49 +0800
Subject: [PATCH] Webui Firmware page support cpld verison

---
 src/locales/en-US.json                        |  1 +
 src/store/modules/Operations/FirmwareStore.js | 13 ++++++
 src/views/Operations/Firmware/Firmware.vue    |  8 ++++
 .../Operations/Firmware/FirmwareCardsCPLD.vue | 40 +++++++++++++++++++
 4 files changed, 62 insertions(+)
 create mode 100755 src/views/Operations/Firmware/FirmwareCardsCPLD.vue

diff --git a/src/locales/en-US.json b/src/locales/en-US.json
index 18bb7c6..dd944aa 100644
--- a/src/locales/en-US.json
+++ b/src/locales/en-US.json
@@ -333,6 +333,7 @@
         "sectionTitleBmcCardsCombined": "BMC and server",
         "sectionTitleHostCards": "Host",
         "sectionTitleUpdateFirmware": "Update firmware",
+        "sectionTitleCPLDCards": "CPLD",
         "alert": {
             "operationInProgress": "Server power operation in progress.",
             "serverMustBePoweredOffTo": "Server must be powered off to:",
diff --git a/src/store/modules/Operations/FirmwareStore.js b/src/store/modules/Operations/FirmwareStore.js
index afc12e9..a90e1a5 100644
--- a/src/store/modules/Operations/FirmwareStore.js
+++ b/src/store/modules/Operations/FirmwareStore.js
@@ -6,6 +6,7 @@ const FirmwareStore = {
   state: {
     bmcFirmware: [],
     hostFirmware: [],
+    cpldFirmware: [],
     bmcActiveFirmwareId: null,
     hostActiveFirmwareId: null,
     applyTime: null,
@@ -35,12 +36,18 @@ const FirmwareStore = {
         (firmware) => firmware.id !== state.hostActiveFirmwareId
       );
     },
+    cpldFirmware: (state) => {
+      return state.cpldFirmware.find(
+        (firmware) => firmware.id === 'cpld_active'
+      );
+    },
   },
   mutations: {
     setActiveBmcFirmwareId: (state, id) => (state.bmcActiveFirmwareId = id),
     setActiveHostFirmwareId: (state, id) => (state.hostActiveFirmwareId = id),
     setBmcFirmware: (state, firmware) => (state.bmcFirmware = firmware),
     setHostFirmware: (state, firmware) => (state.hostFirmware = firmware),
+    setCPLDFirmware: (state, firmware) => (state.cpldFirmware = firmware),
     setApplyTime: (state, applyTime) => (state.applyTime = applyTime),
     setHttpPushUri: (state, httpPushUri) => (state.httpPushUri = httpPushUri),
     setTftpUploadAvailable: (state, tftpAvailable) =>
@@ -82,6 +89,7 @@ const FirmwareStore = {
         .then((response) => {
           const bmcFirmware = [];
           const hostFirmware = [];
+          const cpldFirmware = [];
           response.forEach(({ data }) => {
             const firmwareType = data?.RelatedItem?.[0]?.['@odata.id']
               .split('/')
@@ -97,9 +105,14 @@ const FirmwareStore = {
             } else if (firmwareType === 'Bios') {
               hostFirmware.push(item);
             }
+
+            if (item.id === 'cpld_active') {
+              cpldFirmware.push(item);
+            }
           });
           commit('setBmcFirmware', bmcFirmware);
           commit('setHostFirmware', hostFirmware);
+          commit('setCPLDFirmware', cpldFirmware);
         })
         .catch((error) => {
           console.log(error);
diff --git a/src/views/Operations/Firmware/Firmware.vue b/src/views/Operations/Firmware/Firmware.vue
index a2acb9b..25fe0bb 100644
--- a/src/views/Operations/Firmware/Firmware.vue
+++ b/src/views/Operations/Firmware/Firmware.vue
@@ -14,6 +14,9 @@
 
         <!-- Host Firmware -->
         <host-cards v-if="!isSingleFileUploadEnabled" />
+
+        <!-- CPLD Firmware -->
+        <cpld-cards v-if="cpld" />
       </b-col>
     </b-row>
 
@@ -41,6 +44,7 @@ import FormUpdate from './FirmwareFormUpdate';
 import HostCards from './FirmwareCardsHost';
 import PageSection from '@/components/Global/PageSection';
 import PageTitle from '@/components/Global/PageTitle';
+import CpldCards from './FirmwareCardsCPLD';
 
 import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
 
@@ -53,6 +57,7 @@ export default {
     HostCards,
     PageSection,
     PageTitle,
+    CpldCards,
   },
   mixins: [LoadingBarMixin],
   beforeRouteLeave(to, from, next) {
@@ -82,6 +87,9 @@ export default {
       }
       return this.loading || this.isOperationInProgress;
     },
+    cpld() {
+      return this.$store.getters['firmware/cpldFirmware'];
+    },
   },
   created() {
     this.startLoader();
diff --git a/src/views/Operations/Firmware/FirmwareCardsCPLD.vue b/src/views/Operations/Firmware/FirmwareCardsCPLD.vue
new file mode 100755
index 0000000..baaec3e
--- /dev/null
+++ b/src/views/Operations/Firmware/FirmwareCardsCPLD.vue
@@ -0,0 +1,40 @@
+<template>
+  <page-section :section-title="$t('pageFirmware.sectionTitleCPLDCards')">
+    <b-card-group deck>
+      <!-- Running image -->
+      <b-card>
+        <template #header>
+          <p class="font-weight-bold m-0">
+            {{ $t('pageFirmware.cardTitleRunning') }}
+          </p>
+        </template>
+        <dl class="mb-0">
+          <dt>{{ $t('pageFirmware.cardBodyVersion') }}</dt>
+          <dd class="mb-0">{{ runningVersion }}</dd>
+        </dl>
+      </b-card>
+    </b-card-group>
+  </page-section>
+</template>
+
+<script>
+import PageSection from '@/components/Global/PageSection';
+
+export default {
+  components: { PageSection },
+  computed: {
+    running() {
+      return this.$store.getters['firmware/cpldFirmware'];
+    },
+    runningVersion() {
+      return this.running?.version || '--';
+    },
+  },
+};
+</script>
+
+<style lang="scss" scoped>
+.page-section {
+  margin-top: -$spacer * 1.5;
+}
+</style>
-- 
2.25.1

