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(`${await this.dispatch('global/getSystemPath')}/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 77 .patch(uri, updatedIdentifyLedValue) 78 .then(() => { 79 if (led.identifyLed) { 80 return i18n.t('pageInventory.toast.successEnableIdentifyLed'); 81 } else { 82 return i18n.t('pageInventory.toast.successDisableIdentifyLed'); 83 } 84 }) 85 .catch((error) => { 86 dispatch('getDimms'); 87 console.log('error', error); 88 if (led.identifyLed) { 89 throw new Error( 90 i18n.t('pageInventory.toast.errorEnableIdentifyLed'), 91 ); 92 } else { 93 throw new Error( 94 i18n.t('pageInventory.toast.errorDisableIdentifyLed'), 95 ); 96 } 97 }); 98 }, 99 }, 100}; 101 102export default MemoryStore; 103