Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 1 | import api from '@/store/api'; |
| 2 | import i18n from '@/i18n'; |
| 3 | |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame^] | 4 | const PowerPolicyStore = { |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 5 | namespaced: true, |
| 6 | state: { |
| 7 | powerRestoreCurrentPolicy: null, |
| 8 | powerRestorePolicies: [], |
| 9 | }, |
| 10 | getters: { |
| 11 | powerRestoreCurrentPolicy: (state) => state.powerRestoreCurrentPolicy, |
| 12 | powerRestorePolicies: (state) => state.powerRestorePolicies, |
| 13 | }, |
| 14 | mutations: { |
| 15 | setPowerRestoreCurrentPolicy: (state, powerRestoreCurrentPolicy) => |
| 16 | (state.powerRestoreCurrentPolicy = powerRestoreCurrentPolicy), |
| 17 | setPowerRestorePolicies: (state, powerRestorePolicies) => |
| 18 | (state.powerRestorePolicies = powerRestorePolicies), |
| 19 | }, |
| 20 | actions: { |
| 21 | async getPowerRestorePolicies({ commit }) { |
| 22 | return await api |
| 23 | .get('/redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json') |
| 24 | .then( |
| 25 | ({ |
| 26 | data: { |
| 27 | definitions: { PowerRestorePolicyTypes = {} }, |
| 28 | }, |
| 29 | }) => { |
| 30 | let powerPoliciesData = PowerRestorePolicyTypes.enum.map( |
| 31 | (powerState) => { |
| 32 | let desc = `${i18n.t( |
| 33 | `pagePowerRestorePolicy.policies.${powerState}` |
| 34 | )} - ${PowerRestorePolicyTypes.enumDescriptions[powerState]}`; |
| 35 | return { |
| 36 | state: powerState, |
| 37 | desc, |
| 38 | }; |
| 39 | } |
| 40 | ); |
| 41 | commit('setPowerRestorePolicies', powerPoliciesData); |
| 42 | } |
| 43 | ); |
| 44 | }, |
| 45 | async getPowerRestoreCurrentPolicy({ commit }) { |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame^] | 46 | return await api |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 47 | .get('/redfish/v1/Systems/system') |
| 48 | .then(({ data: { PowerRestorePolicy } }) => { |
| 49 | commit('setPowerRestoreCurrentPolicy', PowerRestorePolicy); |
| 50 | }) |
| 51 | .catch((error) => console.log(error)); |
| 52 | }, |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame^] | 53 | async setPowerRestorePolicy({ dispatch }, powerPolicy) { |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 54 | const data = { PowerRestorePolicy: powerPolicy }; |
| 55 | |
| 56 | return await api |
| 57 | .patch('/redfish/v1/Systems/system', data) |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame^] | 58 | .then(() => { |
| 59 | dispatch('getPowerRestoreCurrentPolicy'); |
| 60 | return i18n.t('pagePowerRestorePolicy.toast.successSaveSettings'); |
| 61 | }) |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 62 | .catch((error) => { |
| 63 | console.log(error); |
| 64 | throw new Error( |
| 65 | i18n.t('pagePowerRestorePolicy.toast.errorSaveSettings') |
| 66 | ); |
| 67 | }); |
| 68 | }, |
| 69 | }, |
| 70 | }; |
| 71 | |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame^] | 72 | export default PowerPolicyStore; |