SurenNeware | 090c2d4 | 2020-04-01 14:07:27 +0530 | [diff] [blame] | 1 | import api from '../../api'; |
SurenNeware | 31bf55a | 2020-06-22 21:53:33 +0530 | [diff] [blame^] | 2 | import i18n from '@/i18n'; |
SurenNeware | 090c2d4 | 2020-04-01 14:07:27 +0530 | [diff] [blame] | 3 | |
| 4 | const 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: { |
SurenNeware | aa7e832 | 2020-06-12 17:59:34 +0530 | [diff] [blame] | 18 | async getIndicatorValue({ commit }) { |
SurenNeware | 31bf55a | 2020-06-22 21:53:33 +0530 | [diff] [blame^] | 19 | return await api |
SurenNeware | 090c2d4 | 2020-04-01 14:07:27 +0530 | [diff] [blame] | 20 | .get('/redfish/v1/Systems/system') |
| 21 | .then(response => { |
| 22 | commit('setIndicatorValue', response.data.IndicatorLED); |
| 23 | }) |
| 24 | .catch(error => console.log(error)); |
| 25 | }, |
SurenNeware | aa7e832 | 2020-06-12 17:59:34 +0530 | [diff] [blame] | 26 | async saveIndicatorLedValue({ commit }, payload) { |
SurenNeware | 31bf55a | 2020-06-22 21:53:33 +0530 | [diff] [blame^] | 27 | return await api |
SurenNeware | 090c2d4 | 2020-04-01 14:07:27 +0530 | [diff] [blame] | 28 | .patch('/redfish/v1/Systems/system', { IndicatorLED: payload }) |
| 29 | .then(() => { |
| 30 | commit('setIndicatorValue', payload); |
SurenNeware | 31bf55a | 2020-06-22 21:53:33 +0530 | [diff] [blame^] | 31 | if (payload === 'Lit') { |
| 32 | return i18n.t('pageServerLed.toast.successServerLedOn'); |
| 33 | } else { |
| 34 | return i18n.t('pageServerLed.toast.successServerLedOff'); |
| 35 | } |
SurenNeware | 090c2d4 | 2020-04-01 14:07:27 +0530 | [diff] [blame] | 36 | }) |
SurenNeware | 31bf55a | 2020-06-22 21:53:33 +0530 | [diff] [blame^] | 37 | .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 | }); |
SurenNeware | 090c2d4 | 2020-04-01 14:07:27 +0530 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | export default ServerLedStore; |