From 53e003b2502a8b01afdd65ff1c3fd2c485419bd5 Mon Sep 17 00:00:00 2001 From: Vitalii Lysak Date: Thu, 1 Sep 2022 10:43:25 +0300 Subject: SILABMC-259: upd bmc time if server status change --- src/store/modules/GlobalStore.js | 54 ++++++++++++++++++++---------------- src/store/plugins/WebSocketPlugin.js | 2 +- 2 files changed, 31 insertions(+), 25 deletions(-) (limited to 'src/store') diff --git a/src/store/modules/GlobalStore.js b/src/store/modules/GlobalStore.js index a2b55db6..72f1c473 100644 --- a/src/store/modules/GlobalStore.js +++ b/src/store/modules/GlobalStore.js @@ -81,36 +81,42 @@ const GlobalStore = { }, }, actions: { - async getBmcTime({ commit, state }) { + changeServerStatus({ commit, dispatch }, status) { + commit('setServerStatus', status); + dispatch('getBmcTime'); + }, + initLiveClock({ commit, state }) { + if (state.clockInterval) { + clearInterval(state.clockInterval); + commit('setClockInterval', null); + } + + let clockData = state.bmcTime; + 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); + }, + async getBmcTime({ commit, dispatch }) { 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); + dispatch('initLiveClock'); }) .catch((error) => console.log(error)); }, diff --git a/src/store/plugins/WebSocketPlugin.js b/src/store/plugins/WebSocketPlugin.js index afad6718..29a98c20 100644 --- a/src/store/plugins/WebSocketPlugin.js +++ b/src/store/plugins/WebSocketPlugin.js @@ -39,7 +39,7 @@ const WebSocketPlugin = (store) => { if (eventInterface === 'xyz.openbmc_project.State.Host') { const { properties: { CurrentHostState } = {} } = data; if (CurrentHostState) { - store.commit('global/setServerStatus', CurrentHostState); + store.dispatch('global/changeServerStatus', CurrentHostState); } } else if (path === '/xyz/openbmc_project/logging') { store.dispatch('eventLog/getEventLogData'); -- cgit v1.2.3