1import api from '@/store/api'; 2import i18n from '@/i18n'; 3 4const SystemStore = { 5 namespaced: true, 6 state: { 7 systems: [], 8 }, 9 getters: { 10 systems: (state) => state.systems, 11 }, 12 mutations: { 13 setSystemInfo: (state, data) => { 14 const system = {}; 15 system.assetTag = data.AssetTag; 16 system.description = data.Description; 17 system.firmwareVersion = data.BiosVersion; 18 system.hardwareType = data.Name; 19 system.health = data.Status?.Health; 20 system.totalSystemMemoryGiB = data.MemorySummary?.TotalSystemMemoryGiB; 21 system.id = data.Id; 22 system.locationIndicatorActive = data.LocationIndicatorActive; 23 system.locationNumber = data.Location?.PartLocation?.ServiceLabel; 24 system.manufacturer = data.Manufacturer; 25 system.model = data.Model; 26 system.processorSummaryCount = data.ProcessorSummary?.Count; 27 system.processorSummaryCoreCount = data.ProcessorSummary?.CoreCount; 28 system.powerState = data.PowerState; 29 system.serialNumber = data.SerialNumber; 30 system.serialConsoleEnabled = data.SerialConsole.ServiceEnabled; 31 system.serialConsoleMaxSessions = 32 data.SerialConsole.MaxConcurrentSessions; 33 system.healthRollup = data.Status?.HealthRollup; 34 system.subModel = data.SubModel; 35 system.statusState = data.Status?.State; 36 system.systemType = data.SystemType; 37 state.systems = [system]; 38 }, 39 }, 40 actions: { 41 async getSystem({ commit }) { 42 return await api 43 .get(`${await this.dispatch('global/getSystemPath')}`) 44 .then(({ data }) => commit('setSystemInfo', data)) 45 .catch((error) => console.log(error)); 46 }, 47 async changeIdentifyLedState({ commit }, ledState) { 48 return await api 49 .patch(`${await this.dispatch('global/getSystemPath')}`, { 50 LocationIndicatorActive: ledState, 51 }) 52 .then(() => { 53 if (ledState) { 54 return i18n.global.t( 55 'pageInventory.toast.successEnableIdentifyLed', 56 ); 57 } else { 58 return i18n.global.t( 59 'pageInventory.toast.successDisableIdentifyLed', 60 ); 61 } 62 }) 63 .catch((error) => { 64 commit('setSystemInfo', this.state.system.systems[0]); 65 console.log('error', error); 66 if (ledState) { 67 throw new Error( 68 i18n.global.t('pageInventory.toast.errorEnableIdentifyLed'), 69 ); 70 } else { 71 throw new Error( 72 i18n.global.t('pageInventory.toast.errorDisableIdentifyLed'), 73 ); 74 } 75 }); 76 }, 77 }, 78}; 79 80export default SystemStore; 81