1import api from '@/store/api'; 2import i18n from '@/i18n'; 3 4const MemoryStore = { 5 namespaced: true, 6 state: { 7 dimms: [], 8 }, 9 getters: { 10 dimms: (state) => state.dimms, 11 }, 12 mutations: { 13 setMemoryInfo: (state, data) => { 14 state.dimms = data.map(({ data }) => { 15 const { 16 Id, 17 Status = {}, 18 BaseModuleType, 19 BusWidthBits, 20 CapacityMiB, 21 DataWidthBits, 22 Enabled, 23 ErrorCorrection, 24 Manufacturer, 25 OperatingSpeedMhz, 26 PartNumber, 27 RankCount, 28 SerialNumber, 29 SparePartNumber, 30 Description, 31 MemoryType, 32 LocationIndicatorActive, 33 Location, 34 } = data; 35 return { 36 id: Id, 37 health: Status.Health, 38 baseModuleType: BaseModuleType, 39 busWidthBits: BusWidthBits, 40 capacityMiB: CapacityMiB, 41 dataWidthBits: DataWidthBits, 42 operatingSpeedMhz: OperatingSpeedMhz, 43 enabled: Enabled, 44 errorCorrection: ErrorCorrection, 45 manufacturer: Manufacturer, 46 partNumber: PartNumber, 47 rankCount: RankCount, 48 serialNumber: SerialNumber, 49 statusState: Status.State, 50 sparePartNumber: SparePartNumber, 51 description: Description, 52 memoryType: MemoryType, 53 identifyLed: LocationIndicatorActive, 54 uri: data['@odata.id'], 55 locationNumber: Location?.PartLocation?.ServiceLabel, 56 }; 57 }); 58 }, 59 }, 60 actions: { 61 async getDimms({ commit }) { 62 return await api 63 .get('/redfish/v1/Systems/system/Memory') 64 .then(({ data: { Members } }) => { 65 const promises = Members.map((item) => api.get(item['@odata.id'])); 66 return api.all(promises); 67 }) 68 .then((response) => commit('setMemoryInfo', response)) 69 .catch((error) => console.log(error)); 70 }, 71 async updateIdentifyLedValue({ dispatch }, led) { 72 const uri = led.uri; 73 const updatedIdentifyLedValue = { 74 LocationIndicatorActive: led.identifyLed, 75 }; 76 return await api.patch(uri, updatedIdentifyLedValue).catch((error) => { 77 dispatch('getDimms'); 78 console.log('error', error); 79 if (led.identifyLed) { 80 throw new Error(i18n.t('pageInventory.toast.errorEnableIdentifyLed')); 81 } else { 82 throw new Error( 83 i18n.t('pageInventory.toast.errorDisableIdentifyLed'), 84 ); 85 } 86 }); 87 }, 88 }, 89}; 90 91export default MemoryStore; 92