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 |
Nikhil Ashoka | 4130397 | 2024-09-30 20:38:43 +0530 | [diff] [blame] | 23 | .get('/redfish/v1/JsonSchemas/ComputerSystem') |
| 24 | .then(async (response) => { |
| 25 | if ( |
| 26 | response.data?.Location.length > 0 && |
| 27 | response.data?.Location[0].Uri |
| 28 | ) { |
| 29 | return await api.get(response.data?.Location[0].Uri).then( |
| 30 | ({ |
| 31 | data: { |
| 32 | definitions: { PowerRestorePolicyTypes = {} }, |
| 33 | }, |
| 34 | }) => { |
| 35 | let powerPoliciesData = PowerRestorePolicyTypes.enum.map( |
| 36 | (powerState) => { |
| 37 | let desc = `${i18n.t( |
| 38 | `pagePowerRestorePolicy.policies.${powerState}`, |
| 39 | )} - ${ |
| 40 | PowerRestorePolicyTypes.enumDescriptions[powerState] |
| 41 | }`; |
| 42 | return { |
| 43 | state: powerState, |
| 44 | desc, |
| 45 | }; |
| 46 | }, |
| 47 | ); |
| 48 | commit('setPowerRestorePolicies', powerPoliciesData); |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 49 | }, |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 50 | ); |
Nikhil Ashoka | 4130397 | 2024-09-30 20:38:43 +0530 | [diff] [blame] | 51 | } |
| 52 | }); |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 53 | }, |
| 54 | async getPowerRestoreCurrentPolicy({ commit }) { |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 55 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 56 | .get(`${await this.dispatch('global/getSystemPath')}`) |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 57 | .then(({ data: { PowerRestorePolicy } }) => { |
| 58 | commit('setPowerRestoreCurrentPolicy', PowerRestorePolicy); |
| 59 | }) |
| 60 | .catch((error) => console.log(error)); |
| 61 | }, |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 62 | async setPowerRestorePolicy({ dispatch }, powerPolicy) { |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 63 | const data = { PowerRestorePolicy: powerPolicy }; |
| 64 | |
| 65 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame] | 66 | .patch(`${await this.dispatch('global/getSystemPath')}`, data) |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 67 | .then(() => { |
| 68 | dispatch('getPowerRestoreCurrentPolicy'); |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 69 | return i18n.global.t( |
| 70 | 'pagePowerRestorePolicy.toast.successSaveSettings', |
| 71 | ); |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 72 | }) |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 73 | .catch((error) => { |
| 74 | console.log(error); |
| 75 | throw new Error( |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 76 | i18n.global.t('pagePowerRestorePolicy.toast.errorSaveSettings'), |
Sukanya Pandey | be6858c | 2020-12-16 20:08:01 +0530 | [diff] [blame] | 77 | ); |
| 78 | }); |
| 79 | }, |
| 80 | }, |
| 81 | }; |
| 82 | |
Kenneth Fullbright | 80a8785 | 2022-01-07 13:12:30 -0600 | [diff] [blame] | 83 | export default PowerPolicyStore; |