From 739e459610d92a6fd3021a65398ecb4517cced89 Mon Sep 17 00:00:00 2001 From: Dixsie Wolmers Date: Fri, 5 Jun 2020 07:00:06 -0500 Subject: Add date and time settings Adds ablity to change date and time manually, or configure using NTP servers. - If NTP is selected, user is required to enter at least one NTP address - Date and time are ISO formatted Signed-off-by: Dixsie Wolmers Change-Id: I0d67c80487fdd815eacc3539ccd702b23618260e --- src/store/index.js | 2 + .../modules/Configuration/DateTimeSettingsStore.js | 68 ++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/store/modules/Configuration/DateTimeSettingsStore.js (limited to 'src/store') diff --git a/src/store/index.js b/src/store/index.js index 6ad05390..392344d0 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -22,6 +22,7 @@ import ChassisStore from './modules/Health/ChassisStore'; import BmcStore from './modules/Health/BmcStore'; import WebSocketPlugin from './plugins/WebSocketPlugin'; +import DateTimeStore from './modules/Configuration/DateTimeSettingsStore'; Vue.use(Vuex); @@ -32,6 +33,7 @@ export default new Vuex.Store({ modules: { global: GlobalStore, authentication: AuthenticationStore, + dateTime: DateTimeStore, ldap: LdapStore, localUsers: LocalUserManagementStore, firmware: FirmwareStore, diff --git a/src/store/modules/Configuration/DateTimeSettingsStore.js b/src/store/modules/Configuration/DateTimeSettingsStore.js new file mode 100644 index 00000000..9da0cb41 --- /dev/null +++ b/src/store/modules/Configuration/DateTimeSettingsStore.js @@ -0,0 +1,68 @@ +import api from '../../api'; +import i18n from '@/i18n'; + +const DateTimeStore = { + namespaced: true, + state: { + ntpServers: [], + isNtpProtocolEnabled: null + }, + getters: { + ntpServers: state => state.ntpServers, + isNtpProtocolEnabled: state => state.isNtpProtocolEnabled + }, + mutations: { + setNtpServers: (state, ntpServers) => (state.ntpServers = ntpServers), + setIsNtpProtocolEnabled: (state, isNtpProtocolEnabled) => + (state.isNtpProtocolEnabled = isNtpProtocolEnabled) + }, + actions: { + async getNtpData({ commit }) { + return await api + .get('/redfish/v1/Managers/bmc/NetworkProtocol') + .then(response => { + const ntpServers = response.data.NTP.NTPServers; + const isNtpProtocolEnabled = response.data.NTP.ProtocolEnabled; + commit('setNtpServers', ntpServers); + commit('setIsNtpProtocolEnabled', isNtpProtocolEnabled); + }) + .catch(error => { + console.log(error); + }); + }, + async updateDateTimeSettings(_, dateTimeForm) { + const ntpData = { + NTP: { + ProtocolEnabled: dateTimeForm.ntpProtocolEnabled + } + }; + + if (dateTimeForm.ntpProtocolEnabled) { + ntpData.NTP.NTPServers = dateTimeForm.ntpServersArray; + } + return await api + .patch(`/redfish/v1/Managers/bmc/NetworkProtocol`, ntpData) + .then(() => { + if (!dateTimeForm.ntpProtocolEnabled) { + const dateTimeData = { + DateTime: dateTimeForm.updatedDateTime + }; + api.patch(`/redfish/v1/Managers/bmc`, dateTimeData); + } + }) + .then(() => { + return i18n.t( + 'pageDateTimeSettings.toast.successSaveDateTimeSettings' + ); + }) + .catch(error => { + console.log(error); + throw new Error( + i18n.t('pageDateTimeSettings.toast.errorSaveDateTimeSettings') + ); + }); + } + } +}; + +export default DateTimeStore; -- cgit v1.2.3