From 9123716b55d809bf8d1cc4727b3b10c127b405a0 Mon Sep 17 00:00:00 2001 From: Vitalii Lysak Date: Wed, 31 Aug 2022 14:47:02 +0300 Subject: SILABMC-259: add live time from bmc --- src/store/modules/GlobalStore.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/store') diff --git a/src/store/modules/GlobalStore.js b/src/store/modules/GlobalStore.js index 39eb597e..a2b55db6 100644 --- a/src/store/modules/GlobalStore.js +++ b/src/store/modules/GlobalStore.js @@ -31,6 +31,9 @@ const GlobalStore = { state: { assetTag: null, bmcTime: null, + liveBmcTime: null, + liveClock: null, + clockInterval: null, modelType: null, serialNumber: null, serverStatus: 'unreachable', @@ -47,6 +50,8 @@ const GlobalStore = { serialNumber: (state) => state.serialNumber, serverStatus: (state) => state.serverStatus, bmcTime: (state) => state.bmcTime, + liveBmcTime: (state) => state.liveBmcTime, + liveClock: (state) => state.liveClock, languagePreference: (state) => state.languagePreference, isUtcDisplay: (state) => state.isUtcDisplay, username: (state) => state.username, @@ -58,6 +63,10 @@ const GlobalStore = { setSerialNumber: (state, serialNumber) => (state.serialNumber = serialNumber), setBmcTime: (state, bmcTime) => (state.bmcTime = bmcTime), + setLiveBmcTime: (state, liveBmcTime) => (state.liveBmcTime = liveBmcTime), + setLiveClock: (state, liveClock) => (state.liveClock = liveClock), + setClockInterval: (state, clockInterval) => + (state.clockInterval = clockInterval), setServerStatus: (state, serverState) => (state.serverStatus = serverStateMapper(serverState)), setLanguagePreference: (state, language) => @@ -72,13 +81,36 @@ const GlobalStore = { }, }, actions: { - async getBmcTime({ commit }) { + async getBmcTime({ commit, state }) { return await api .get('/redfish/v1/Managers/bmc') .then((response) => { const bmcDateTime = response.data.DateTime; const date = new Date(bmcDateTime); commit('setBmcTime', date); + + if (state.clockInterval) { + clearInterval(state.clockInterval); + commit('setClockInterval', null); + } + + let clockData = date; + let clockInterval = setInterval(() => { + clockData.setSeconds(clockData.getSeconds() + 1); + commit('setLiveBmcTime', clockData.toString()); + + let hours = clockData.getHours(); + let minutes = clockData.getMinutes(); + let sec = clockData.getSeconds(); + if (minutes < 10) { + minutes = '0' + minutes; + } + if (sec < 10) { + sec = '0' + sec; + } + commit('setLiveClock', hours + ':' + minutes + ':' + sec); + }, 1000); + commit('setClockInterval', clockInterval); }) .catch((error) => console.log(error)); }, -- cgit v1.2.3