blob: 3023a9c7de9215b1f8a9b3bd26989dc97cf068a0 [file] [log] [blame]
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -07001import api from '@/store/api';
Sandeepa Singh240c0562021-05-06 21:59:20 +05302import i18n from '@/i18n';
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -07003
4const ChassisStore = {
5 namespaced: true,
6 state: {
Derick Montague602e98a2020-10-21 16:20:00 -05007 chassis: [],
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -07008 },
9 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050010 chassis: (state) => state.chassis,
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070011 },
12 mutations: {
13 setChassisInfo: (state, data) => {
Derick Montague602e98a2020-10-21 16:20:00 -050014 state.chassis = data.map((chassis) => {
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070015 const {
16 Id,
17 Status = {},
18 PartNumber,
19 SerialNumber,
20 ChassisType,
21 Manufacturer,
Derick Montague602e98a2020-10-21 16:20:00 -050022 PowerState,
Sandeepa Singh240c0562021-05-06 21:59:20 +053023 LocationIndicatorActive,
24 AssetTag,
MichalX Szopinskifedc7342022-02-25 17:07:53 +010025 Model,
Sandeepa Singh240c0562021-05-06 21:59:20 +053026 MaxPowerWatts,
27 MinPowerWatts,
28 Name,
Sneha Patel9f612342021-09-02 12:23:42 -050029 Location,
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070030 } = chassis;
31
32 return {
33 id: Id,
34 health: Status.Health,
35 partNumber: PartNumber,
36 serialNumber: SerialNumber,
37 chassisType: ChassisType,
38 manufacturer: Manufacturer,
39 powerState: PowerState,
40 statusState: Status.State,
Derick Montague602e98a2020-10-21 16:20:00 -050041 healthRollup: Status.HealthRollup,
Sandeepa Singh240c0562021-05-06 21:59:20 +053042 assetTag: AssetTag,
MichalX Szopinskifedc7342022-02-25 17:07:53 +010043 model: Model,
Sandeepa Singh240c0562021-05-06 21:59:20 +053044 maxPowerWatts: MaxPowerWatts,
45 minPowerWatts: MinPowerWatts,
46 name: Name,
47 identifyLed: LocationIndicatorActive,
48 uri: chassis['@odata.id'],
Sneha Patel9f612342021-09-02 12:23:42 -050049 locationNumber: Location?.PartLocation?.ServiceLabel,
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070050 };
51 });
Derick Montague602e98a2020-10-21 16:20:00 -050052 },
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070053 },
54 actions: {
55 async getChassisInfo({ commit }) {
56 return await api
57 .get('/redfish/v1/Chassis')
58 .then(({ data: { Members = [] } }) =>
Ed Tanous81323992024-02-27 11:26:24 -080059 Members.map((member) => api.get(member['@odata.id'])),
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070060 )
Derick Montague602e98a2020-10-21 16:20:00 -050061 .then((promises) => api.all(promises))
62 .then((response) => {
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -070063 const data = response.map(({ data }) => data);
64 commit('setChassisInfo', data);
65 })
Derick Montague602e98a2020-10-21 16:20:00 -050066 .catch((error) => console.log(error));
67 },
Sandeepa Singh240c0562021-05-06 21:59:20 +053068 async updateIdentifyLedValue({ dispatch }, led) {
69 const uri = led.uri;
70 const updatedIdentifyLedValue = {
71 LocationIndicatorActive: led.identifyLed,
72 };
73 return await api
74 .patch(uri, updatedIdentifyLedValue)
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053075 .then(() => {
76 dispatch('getChassisInfo');
77 if (led.identifyLed) {
Surya Vde23ea22024-07-11 15:19:46 +053078 return i18n.global.t(
79 'pageInventory.toast.successEnableIdentifyLed',
80 );
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053081 } else {
Surya Vde23ea22024-07-11 15:19:46 +053082 return i18n.global.t(
83 'pageInventory.toast.successDisableIdentifyLed',
84 );
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053085 }
86 })
Sandeepa Singh240c0562021-05-06 21:59:20 +053087 .catch((error) => {
88 dispatch('getChassisInfo');
89 console.log('error', error);
90 if (led.identifyLed) {
91 throw new Error(
Surya Vde23ea22024-07-11 15:19:46 +053092 i18n.global.t('pageInventory.toast.errorEnableIdentifyLed'),
Sandeepa Singh240c0562021-05-06 21:59:20 +053093 );
94 } else {
95 throw new Error(
Surya Vde23ea22024-07-11 15:19:46 +053096 i18n.global.t('pageInventory.toast.errorDisableIdentifyLed'),
Sandeepa Singh240c0562021-05-06 21:59:20 +053097 );
98 }
99 });
100 },
Derick Montague602e98a2020-10-21 16:20:00 -0500101 },
Yoshie Muranaka09e8b5d2020-06-08 07:36:59 -0700102};
103
104export default ChassisStore;