Repository: ibm-openbmc/webui-vue
Pull request #393: Added DHCP NTP Servers list
Author: login: vedangimittal
Labels: name: 1110
name: 1060
Created: 2025-03-20T08:03:03Z | Merged: 2025-03-28T21:29:34Z

- Added DHCP NTP Servers list on GUI
- JIRA story- https://jsw.ibm.com/browse/PFEBMC-2786
- Defect- https://jazz07.rchland.ibm.com:13443/jazz/web/projects/CSSD#action=com.ibm.team.workitem.viewWorkItem&id=621402


Diff:
diff --git a/src/locales/en-US.json b/src/locales/en-US.json
index 3f4f23c94b..a0ab29191a 100644
--- a/src/locales/en-US.json
+++ b/src/locales/en-US.json
@@ -409,6 +409,9 @@
       "mfaMessage": "Changing date and time will affect MFA users."
     },
     "configureSettings": "Configure settings",
+    "viewDynamicNtp": "View Dynamic NTP servers",
+    "dhcpNtpInfoTooltip": "This section captures the DHCP supplied NTP server details",
+    "staticNtp":"Static NTP servers",
     "form": {
       "date": "Date",
       "manual": "Manual",
diff --git a/src/store/modules/Settings/DateTimeStore.js b/src/store/modules/Settings/DateTimeStore.js
index 3033f2d7ba..08add3fe44 100644
--- a/src/store/modules/Settings/DateTimeStore.js
+++ b/src/store/modules/Settings/DateTimeStore.js
@@ -6,15 +6,19 @@ const DateTimeStore = {
   state: {
     ntpServers: [],
     isNtpProtocolEnabled: null,
+    networkSuppliedServers: [],
   },
   getters: {
     ntpServers: (state) => state.ntpServers,
     isNtpProtocolEnabled: (state) => state.isNtpProtocolEnabled,
+    networkSuppliedServers: (state) => state.networkSuppliedServers,
   },
   mutations: {
     setNtpServers: (state, ntpServers) => (state.ntpServers = ntpServers),
     setIsNtpProtocolEnabled: (state, isNtpProtocolEnabled) =>
       (state.isNtpProtocolEnabled = isNtpProtocolEnabled),
+    setNetworkSuppliedServers: (state, networkSuppliedServers) =>
+      (state.networkSuppliedServers = networkSuppliedServers),
   },
   actions: {
     async getNtpData({ commit }) {
@@ -23,8 +27,11 @@ const DateTimeStore = {
         .then((response) => {
           const ntpServers = response.data.NTP.NTPServers;
           const isNtpProtocolEnabled = response.data.NTP.ProtocolEnabled;
+          const networkSuppliedServers =
+            response?.data?.NTP?.NetworkSuppliedServers;
           commit('setNtpServers', ntpServers);
           commit('setIsNtpProtocolEnabled', isNtpProtocolEnabled);
+          commit('setNetworkSuppliedServers', networkSuppliedServers);
         })
         .catch((error) => {
           console.log(error);
diff --git a/src/views/Settings/DateTime/DateTime.vue b/src/views/Settings/DateTime/DateTime.vue
index 5698e51977..f4c703e7f7 100644
--- a/src/views/Settings/DateTime/DateTime.vue
+++ b/src/views/Settings/DateTime/DateTime.vue
@@ -31,6 +31,41 @@
         </b-col>
       </b-row>
     </page-section>
+    <page-section v-show="showDhcpNtpServers">
+      <b-button v-b-toggle.collapse-dhcp-ntp variant="link" class="mt-3">
+        <icon-chevron />
+        {{ $t('pageDateTime.viewDynamicNtp') }}
+        <info-tooltip :title="$t('pageDateTime.dhcpNtpInfoTooltip')" />
+      </b-button>
+
+      <b-collapse id="collapse-dhcp-ntp">
+        <b-row
+          v-for="(group, rowIndex) in chunkedDhcpNtp"
+          :key="rowIndex"
+          class="mt-3 ml-3"
+        >
+          <b-col
+            v-for="(item, colIndex) in group"
+            :key="colIndex"
+            sm="6"
+            lg="4"
+            xl="3"
+          >
+            <b-form-group
+              :label="`Server ${rowIndex * 3 + colIndex + 1}`"
+              :label-for="`${colIndex + 1}`"
+            >
+              <b-form-input
+                :id="`${colIndex + 1}`"
+                class="custom-form-group"
+                :disabled="true"
+                :placeholder="item"
+              />
+            </b-form-group>
+          </b-col>
+        </b-row>
+      </b-collapse>
+    </page-section>
     <page-section :section-title="$t('pageDateTime.configureSettings')">
       <b-row>
         <b-col md="8" xl="6">
@@ -148,7 +183,7 @@
             value="ntp"
             data-test-id="dateTime-radio-configureNTP"
           >
-            NTP
+            {{ $t('pageDateTime.staticNtp') }}
           </b-form-radio>
           <b-row class="mt-3 ml-3">
             <b-col sm="6" lg="4" xl="3">
@@ -237,9 +272,10 @@
 <script>
 import Alert from '@/components/Global/Alert';
 import IconCalendar from '@carbon/icons-vue/es/calendar/20';
+import IconChevron from '@carbon/icons-vue/es/chevron--up/20';
 import PageTitle from '@/components/Global/PageTitle';
 import PageSection from '@/components/Global/PageSection';
-
+import InfoTooltip from '@/components/Global/InfoTooltip';
 import BVToastMixin from '@/components/Mixins/BVToastMixin';
 import LoadingBarMixin, { loading } from '@/components/Mixins/LoadingBarMixin';
 import LocalTimezoneLabelMixin from '@/components/Mixins/LocalTimezoneLabelMixin';
@@ -253,7 +289,14 @@ const isoTimeRegex = /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/;
 
 export default {
   name: 'DateTime',
-  components: { Alert, IconCalendar, PageTitle, PageSection },
+  components: {
+    Alert,
+    IconCalendar,
+    IconChevron,
+    PageTitle,
+    PageSection,
+    InfoTooltip,
+  },
   mixins: [
     BVToastMixin,
     LoadingBarMixin,
@@ -276,6 +319,8 @@ export default {
         ntp: { firstAddress: '', secondAddress: '', thirdAddress: '' },
       },
       loading,
+      showDhcpNtpServers: false,
+      dhcpNtp: [],
     };
   },
   validations() {
@@ -313,7 +358,11 @@ export default {
     };
   },
   computed: {
-    ...mapState('dateTime', ['ntpServers', 'isNtpProtocolEnabled']),
+    ...mapState('dateTime', [
+      'ntpServers',
+      'isNtpProtocolEnabled',
+      'networkSuppliedServers',
+    ]),
     bmcTime() {
       return this.$store.getters['global/bmcTime'];
     },
@@ -343,6 +392,20 @@ export default {
     serverStatus() {
       return this.$store.getters['global/serverStatus'];
     },
+    networkSuppliedServers() {
+      this.$store.getters['dateTime/networkSuppliedServers'].map((server) =>
+        this.dhcpNtp.push(server)
+      );
+      return this.dhcpNtp;
+    },
+    chunkedDhcpNtp() {
+      const chunkSize = 3;
+      const result = [];
+      for (let i = 0; i < this.dhcpNtp.length; i += chunkSize) {
+        result.push(this.dhcpNtp.slice(i, i + chunkSize));
+      }
+      return result;
+    },
   },
   watch: {
     ntpServers() {
@@ -367,6 +430,7 @@ export default {
       this.$store.dispatch('dateTime/getNtpData'),
       this.$store.dispatch('userManagement/getAccountSettings'),
     ]).finally(() => {
+      this.showCollapse();
       this.setInitialNtpValues();
       this.endLoader();
     });
@@ -486,6 +550,23 @@ export default {
       );
       return new Date(utcDate);
     },
+    showCollapse() {
+      if (this.networkSuppliedServers.length == 0) {
+        this.showDhcpNtpServers = false;
+      } else {
+        this.showDhcpNtpServers = true;
+      }
+    },
   },
 };
 </script>
+<style lang="scss" scoped>
+.btn.collapsed {
+  svg {
+    transform: rotate(180deg);
+  }
+}
+.custom-form-group::placeholder {
+  color: black !important;
+}
+</style>


Reviews:
user: login: Nikhil-Ashoka
state: CHANGES_REQUESTED
author_association: COLLABORATOR
submitted_at: 2025-03-24T06:20:16Z
user: login: Nikhil-Ashoka
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-24T13:47:08Z
user: login: Nikhil-Ashoka
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-03-24T14:10:24Z
user: login: Nikhil-Ashoka
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-03-26T09:35:18Z
user: login: nabilpandiyalayil
state: APPROVED
author_association: NONE
submitted_at: 2025-03-28T11:10:47Z

Review comments:
diff_hunk: @@ -23,8 +27,11 @@ const DateTimeStore = {
         .then((response) => {
           const ntpServers = response.data.NTP.NTPServers;
           const isNtpProtocolEnabled = response.data.NTP.ProtocolEnabled;
+          const networkSuppliedServers =
+            response.data.NTP.NetworkSuppliedServers;
path: src/store/modules/Settings/DateTimeStore.js
user: login: Nikhil-Ashoka
body: Better to have: **response?.data?.NTP?.NetworkSuppliedServers**
created_at: 2025-03-24T06:10:15Z
author_association: COLLABORATOR
diff_hunk: @@ -276,6 +311,8 @@ export default {
         ntp: { firstAddress: '', secondAddress: '', thirdAddress: '' },
       },
       loading,
+      show: false,
path: src/views/Settings/DateTime/DateTime.vue
user: login: Nikhil-Ashoka
body: Lets have a more relative naming: **showDhcpNtpServers**
created_at: 2025-03-24T13:47:07Z
author_association: COLLABORATOR
diff_hunk: @@ -409,6 +409,9 @@
       "mfaMessage": "Changing date and time will affect MFA users."
     },
     "configureSettings": "Configure settings",
+    "viewDynamicNtp": "View Dynamic NTP servers ",
path: src/locales/en-US.json
user: login: Nikhil-Ashoka
body: Remove this additional space at the end.
created_at: 2025-03-26T09:35:18Z
author_association: COLLABORATOR

PR comments:
user: login: vedangimittal
created_at: 2025-03-20T08:28:02Z
body: To test, you can add IP addresses under showCollapse() function. Refer commit [13b1dba] to [0c2a0b4]
author_association: NONE
user: login: Nikhil-Ashoka
created_at: 2025-03-24T05:53:48Z
body: <img width="1718" alt="Screenshot 2025-03-24 at 11 21 40 AM" src="https://github.com/user-attachments/assets/6e0b9e65-8365-486b-9f6c-601509d8fa75" />

author_association: COLLABORATOR