blob: 5ee3619680ed7c33687ecb9ef07483a861d1e50e [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
Nikhil Ashoka41303972024-09-30 20:38:43 +053023 .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 Tanous81323992024-02-27 11:26:24 -080049 },
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053050 );
Nikhil Ashoka41303972024-09-30 20:38:43 +053051 }
52 });
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053053 },
54 async getPowerRestoreCurrentPolicy({ commit }) {
Kenneth Fullbright80a87852022-01-07 13:12:30 -060055 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030056 .get(`${await this.dispatch('global/getSystemPath')}`)
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053057 .then(({ data: { PowerRestorePolicy } }) => {
58 commit('setPowerRestoreCurrentPolicy', PowerRestorePolicy);
59 })
60 .catch((error) => console.log(error));
61 },
Kenneth Fullbright80a87852022-01-07 13:12:30 -060062 async setPowerRestorePolicy({ dispatch }, powerPolicy) {
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053063 const data = { PowerRestorePolicy: powerPolicy };
64
65 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030066 .patch(`${await this.dispatch('global/getSystemPath')}`, data)
Kenneth Fullbright80a87852022-01-07 13:12:30 -060067 .then(() => {
68 dispatch('getPowerRestoreCurrentPolicy');
Surya Vde23ea22024-07-11 15:19:46 +053069 return i18n.global.t(
70 'pagePowerRestorePolicy.toast.successSaveSettings',
71 );
Kenneth Fullbright80a87852022-01-07 13:12:30 -060072 })
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053073 .catch((error) => {
74 console.log(error);
75 throw new Error(
Surya Vde23ea22024-07-11 15:19:46 +053076 i18n.global.t('pagePowerRestorePolicy.toast.errorSaveSettings'),
Sukanya Pandeybe6858c2020-12-16 20:08:01 +053077 );
78 });
79 },
80 },
81};
82
Kenneth Fullbright80a87852022-01-07 13:12:30 -060083export default PowerPolicyStore;