blob: 6ea0473c8f8d761c00d19ef2ba4166f3a99e13a6 [file] [log] [blame]
SurenNeware090c2d42020-04-01 14:07:27 +05301import api from '../../api';
SurenNeware31bf55a2020-06-22 21:53:33 +05302import i18n from '@/i18n';
SurenNeware090c2d42020-04-01 14:07:27 +05303
4const ServerLedStore = {
5 namespaced: true,
6 state: {
7 indicatorValue: 'Off'
8 },
9 getters: {
10 getIndicatorValue: state => state.indicatorValue
11 },
12 mutations: {
13 setIndicatorValue(state, indicatorValue) {
14 state.indicatorValue = indicatorValue;
15 }
16 },
17 actions: {
SurenNewareaa7e8322020-06-12 17:59:34 +053018 async getIndicatorValue({ commit }) {
SurenNeware31bf55a2020-06-22 21:53:33 +053019 return await api
SurenNeware090c2d42020-04-01 14:07:27 +053020 .get('/redfish/v1/Systems/system')
21 .then(response => {
22 commit('setIndicatorValue', response.data.IndicatorLED);
23 })
24 .catch(error => console.log(error));
25 },
SurenNewareaa7e8322020-06-12 17:59:34 +053026 async saveIndicatorLedValue({ commit }, payload) {
SurenNeware31bf55a2020-06-22 21:53:33 +053027 return await api
SurenNeware090c2d42020-04-01 14:07:27 +053028 .patch('/redfish/v1/Systems/system', { IndicatorLED: payload })
29 .then(() => {
30 commit('setIndicatorValue', payload);
SurenNeware31bf55a2020-06-22 21:53:33 +053031 if (payload === 'Lit') {
32 return i18n.t('pageServerLed.toast.successServerLedOn');
33 } else {
34 return i18n.t('pageServerLed.toast.successServerLedOff');
35 }
SurenNeware090c2d42020-04-01 14:07:27 +053036 })
SurenNeware31bf55a2020-06-22 21:53:33 +053037 .catch(error => {
38 console.log(error);
39 if (payload === 'Lit') {
40 throw new Error(i18n.t('pageServerLed.toast.errorServerLedOn'));
41 } else {
42 throw new Error(i18n.t('pageServerLed.toast.errorServerLedOff'));
43 }
44 });
SurenNeware090c2d42020-04-01 14:07:27 +053045 }
46 }
47};
48
49export default ServerLedStore;