xref: /openbmc/webui-vue/src/store/modules/HardwareStatus/ChassisStore.js (revision de23ea23d88451a2fa2774ec72053772603c23ae)
17affc529SSandeepa Singhimport api from '@/store/api';
27affc529SSandeepa Singhimport i18n from '@/i18n';
37affc529SSandeepa Singh
47affc529SSandeepa Singhconst ChassisStore = {
57affc529SSandeepa Singh  namespaced: true,
67affc529SSandeepa Singh  state: {
77affc529SSandeepa Singh    chassis: [],
87affc529SSandeepa Singh  },
97affc529SSandeepa Singh  getters: {
107affc529SSandeepa Singh    chassis: (state) => state.chassis,
117affc529SSandeepa Singh  },
127affc529SSandeepa Singh  mutations: {
137affc529SSandeepa Singh    setChassisInfo: (state, data) => {
147affc529SSandeepa Singh      state.chassis = data.map((chassis) => {
157affc529SSandeepa Singh        const {
167affc529SSandeepa Singh          Id,
177affc529SSandeepa Singh          Status = {},
187affc529SSandeepa Singh          PartNumber,
197affc529SSandeepa Singh          SerialNumber,
207affc529SSandeepa Singh          ChassisType,
217affc529SSandeepa Singh          Manufacturer,
227affc529SSandeepa Singh          PowerState,
237affc529SSandeepa Singh          LocationIndicatorActive,
247affc529SSandeepa Singh          AssetTag,
25fedc7344SMichalX Szopinski          Model,
267affc529SSandeepa Singh          MaxPowerWatts,
277affc529SSandeepa Singh          MinPowerWatts,
287affc529SSandeepa Singh          Name,
299f61234aSSneha Patel          Location,
307affc529SSandeepa Singh        } = chassis;
317affc529SSandeepa Singh
327affc529SSandeepa Singh        return {
337affc529SSandeepa Singh          id: Id,
347affc529SSandeepa Singh          health: Status.Health,
357affc529SSandeepa Singh          partNumber: PartNumber,
367affc529SSandeepa Singh          serialNumber: SerialNumber,
377affc529SSandeepa Singh          chassisType: ChassisType,
387affc529SSandeepa Singh          manufacturer: Manufacturer,
397affc529SSandeepa Singh          powerState: PowerState,
407affc529SSandeepa Singh          statusState: Status.State,
417affc529SSandeepa Singh          healthRollup: Status.HealthRollup,
427affc529SSandeepa Singh          assetTag: AssetTag,
43fedc7344SMichalX Szopinski          model: Model,
447affc529SSandeepa Singh          maxPowerWatts: MaxPowerWatts,
457affc529SSandeepa Singh          minPowerWatts: MinPowerWatts,
467affc529SSandeepa Singh          name: Name,
477affc529SSandeepa Singh          identifyLed: LocationIndicatorActive,
487affc529SSandeepa Singh          uri: chassis['@odata.id'],
499f61234aSSneha Patel          locationNumber: Location?.PartLocation?.ServiceLabel,
507affc529SSandeepa Singh        };
517affc529SSandeepa Singh      });
527affc529SSandeepa Singh    },
537affc529SSandeepa Singh  },
547affc529SSandeepa Singh  actions: {
557affc529SSandeepa Singh    async getChassisInfo({ commit }) {
567affc529SSandeepa Singh      return await api
577affc529SSandeepa Singh        .get('/redfish/v1/Chassis')
587affc529SSandeepa Singh        .then(({ data: { Members = [] } }) =>
598132399cSEd Tanous          Members.map((member) => api.get(member['@odata.id'])),
607affc529SSandeepa Singh        )
617affc529SSandeepa Singh        .then((promises) => api.all(promises))
627affc529SSandeepa Singh        .then((response) => {
637affc529SSandeepa Singh          const data = response.map(({ data }) => data);
647affc529SSandeepa Singh          commit('setChassisInfo', data);
657affc529SSandeepa Singh        })
667affc529SSandeepa Singh        .catch((error) => console.log(error));
677affc529SSandeepa Singh    },
687affc529SSandeepa Singh    async updateIdentifyLedValue({ dispatch }, led) {
697affc529SSandeepa Singh      const uri = led.uri;
707affc529SSandeepa Singh      const updatedIdentifyLedValue = {
717affc529SSandeepa Singh        LocationIndicatorActive: led.identifyLed,
727affc529SSandeepa Singh      };
737affc529SSandeepa Singh      return await api
747affc529SSandeepa Singh        .patch(uri, updatedIdentifyLedValue)
75f11a1901SNikhil Ashoka        .then(() => {
76f11a1901SNikhil Ashoka          dispatch('getChassisInfo');
77f11a1901SNikhil Ashoka          if (led.identifyLed) {
78*de23ea23SSurya V            return i18n.global.t(
79*de23ea23SSurya V              'pageInventory.toast.successEnableIdentifyLed',
80*de23ea23SSurya V            );
81f11a1901SNikhil Ashoka          } else {
82*de23ea23SSurya V            return i18n.global.t(
83*de23ea23SSurya V              'pageInventory.toast.successDisableIdentifyLed',
84*de23ea23SSurya V            );
85f11a1901SNikhil Ashoka          }
86f11a1901SNikhil Ashoka        })
877affc529SSandeepa Singh        .catch((error) => {
887affc529SSandeepa Singh          dispatch('getChassisInfo');
897affc529SSandeepa Singh          console.log('error', error);
907affc529SSandeepa Singh          if (led.identifyLed) {
917affc529SSandeepa Singh            throw new Error(
92*de23ea23SSurya V              i18n.global.t('pageInventory.toast.errorEnableIdentifyLed'),
937affc529SSandeepa Singh            );
947affc529SSandeepa Singh          } else {
957affc529SSandeepa Singh            throw new Error(
96*de23ea23SSurya V              i18n.global.t('pageInventory.toast.errorDisableIdentifyLed'),
977affc529SSandeepa Singh            );
987affc529SSandeepa Singh          }
997affc529SSandeepa Singh        });
1007affc529SSandeepa Singh    },
1017affc529SSandeepa Singh  },
1027affc529SSandeepa Singh};
1037affc529SSandeepa Singh
1047affc529SSandeepa Singhexport default ChassisStore;
105