blob: 9ee12390b0f6d5e3ff46063a49fb6d1aed9160f3 [file] [log] [blame]
Sukanya Pandeybe6858c2020-12-16 20:08:01 +05301import api from '@/store/api';
2import i18n from '@/i18n';
3
Kenneth Fullbright80a87852022-01-07 13:12:30 -06004const PowerPolicyStore = {
Sukanya Pandeybe6858c2020-12-16 20:08:01 +05305 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) => {
Surya V603cfbf2024-07-11 15:19:46 +053032 let desc = `${i18n.global.t(
Ed Tanous81323992024-02-27 11:26:24 -080033 `pagePowerRestorePolicy.policies.${powerState}`,
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053034 )} - ${PowerRestorePolicyTypes.enumDescriptions[powerState]}`;
35 return {
36 state: powerState,
37 desc,
38 };
Ed Tanous81323992024-02-27 11:26:24 -080039 },
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053040 );
41 commit('setPowerRestorePolicies', powerPoliciesData);
Ed Tanous81323992024-02-27 11:26:24 -080042 },
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053043 );
44 },
45 async getPowerRestoreCurrentPolicy({ commit }) {
Kenneth Fullbright80a87852022-01-07 13:12:30 -060046 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030047 .get(`${await this.dispatch('global/getSystemPath')}`)
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053048 .then(({ data: { PowerRestorePolicy } }) => {
49 commit('setPowerRestoreCurrentPolicy', PowerRestorePolicy);
50 })
51 .catch((error) => console.log(error));
52 },
Kenneth Fullbright80a87852022-01-07 13:12:30 -060053 async setPowerRestorePolicy({ dispatch }, powerPolicy) {
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053054 const data = { PowerRestorePolicy: powerPolicy };
55
56 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030057 .patch(`${await this.dispatch('global/getSystemPath')}`, data)
Kenneth Fullbright80a87852022-01-07 13:12:30 -060058 .then(() => {
59 dispatch('getPowerRestoreCurrentPolicy');
Surya V603cfbf2024-07-11 15:19:46 +053060 return i18n.global.t(
61 'pagePowerRestorePolicy.toast.successSaveSettings',
62 );
Kenneth Fullbright80a87852022-01-07 13:12:30 -060063 })
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053064 .catch((error) => {
65 console.log(error);
66 throw new Error(
Surya V603cfbf2024-07-11 15:19:46 +053067 i18n.global.t('pagePowerRestorePolicy.toast.errorSaveSettings'),
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053068 );
69 });
70 },
71 },
72};
73
Kenneth Fullbright80a87852022-01-07 13:12:30 -060074export default PowerPolicyStore;