summaryrefslogtreecommitdiff
path: root/src/store/modules/HardwareStatus/MemoryStore.js
blob: c166d83183ce943663f6e2cd64dc29fdf93dc204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import api from '@/store/api';
import i18n from '@/i18n';

const MemoryStore = {
  namespaced: true,
  state: {
    dimms: [],
  },
  getters: {
    dimms: (state) => state.dimms,
  },
  mutations: {
    setMemoryInfo: (state, data) => {
      state.dimms = data.map(({ data }) => {
        const {
          Id,
          Status = {},
          BaseModuleType,
          BusWidthBits,
          CapacityMiB,
          DataWidthBits,
          Enabled,
          OperatingSpeedMhz,
          PartNumber,
          SerialNumber,
          SparePartNumber,
          Description,
          MemoryType,
          LocationIndicatorActive,
          Location,
        } = data;
        return {
          id: Id,
          health: Status.Health,
          baseModuleType: BaseModuleType,
          busWidthBits: BusWidthBits,
          capacityMiB: CapacityMiB,
          dataWidthBits: DataWidthBits,
          operatingSpeedMhz: OperatingSpeedMhz,
          enabled: Enabled,
          partNumber: PartNumber,
          serialNumber: SerialNumber,
          statusState: Status.State,
          sparePartNumber: SparePartNumber,
          description: Description,
          memoryType: MemoryType,
          identifyLed: LocationIndicatorActive,
          uri: data['@odata.id'],
          locationNumber: Location?.PartLocation?.ServiceLabel,
        };
      });
    },
  },
  actions: {
    async getDimms({ commit }) {
      return await api
        .get('/redfish/v1/Systems/system/Memory')
        .then(({ data: { Members } }) => {
          const promises = Members.map((item) => api.get(item['@odata.id']));
          return api.all(promises);
        })
        .then((response) => commit('setMemoryInfo', response))
        .catch((error) => console.log(error));
    },
    async updateIdentifyLedValue({ dispatch }, led) {
      const uri = led.uri;
      const updatedIdentifyLedValue = {
        LocationIndicatorActive: led.identifyLed,
      };
      return await api.patch(uri, updatedIdentifyLedValue).catch((error) => {
        dispatch('getDimms');
        console.log('error', error);
        if (led.identifyLed) {
          throw new Error(i18n.t('pageInventory.toast.errorEnableIdentifyLed'));
        } else {
          throw new Error(
            i18n.t('pageInventory.toast.errorDisableIdentifyLed')
          );
        }
      });
    },
  },
};

export default MemoryStore;