blob: 87d2810bd1999db5fffb45c9b5473bcc582250ac [file] [log] [blame]
Yoshie Muranaka56ee7692020-05-28 13:28:29 -07001import api from '@/store/api';
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +05302import i18n from '@/i18n';
Yoshie Muranaka56ee7692020-05-28 13:28:29 -07003
4const SystemStore = {
5 namespaced: true,
6 state: {
Derick Montague602e98a2020-10-21 16:20:00 -05007 systems: [],
Yoshie Muranaka56ee7692020-05-28 13:28:29 -07008 },
9 getters: {
Derick Montague602e98a2020-10-21 16:20:00 -050010 systems: (state) => state.systems,
Yoshie Muranaka56ee7692020-05-28 13:28:29 -070011 },
12 mutations: {
13 setSystemInfo: (state, data) => {
14 const system = {};
15 system.assetTag = data.AssetTag;
16 system.description = data.Description;
Yoshie Muranakac687f102020-06-02 12:01:27 -070017 system.firmwareVersion = data.BiosVersion;
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053018 system.hardwareType = data.Name;
Sukanya Pandey05388962021-06-10 15:35:21 +053019 system.health = data.Status?.Health;
Nikhil Ashoka18cde3c2022-01-05 22:21:24 +053020 system.totalSystemMemoryGiB = data.MemorySummary?.TotalSystemMemoryGiB;
Yoshie Muranaka56ee7692020-05-28 13:28:29 -070021 system.id = data.Id;
SurenNewarebbf896c2021-01-27 21:50:22 +053022 system.locationIndicatorActive = data.LocationIndicatorActive;
Sneha Patel9f612342021-09-02 12:23:42 -050023 system.locationNumber = data.Location?.PartLocation?.ServiceLabel;
Yoshie Muranakac687f102020-06-02 12:01:27 -070024 system.manufacturer = data.Manufacturer;
Yoshie Muranaka56ee7692020-05-28 13:28:29 -070025 system.model = data.Model;
Sukanya Pandey05388962021-06-10 15:35:21 +053026 system.processorSummaryCount = data.ProcessorSummary?.Count;
Nikhil Ashoka18cde3c2022-01-05 22:21:24 +053027 system.processorSummaryCoreCount = data.ProcessorSummary?.CoreCount;
Yoshie Muranaka56ee7692020-05-28 13:28:29 -070028 system.powerState = data.PowerState;
29 system.serialNumber = data.SerialNumber;
Sukanya Pandey05388962021-06-10 15:35:21 +053030 system.healthRollup = data.Status?.HealthRollup;
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053031 system.subModel = data.SubModel;
Sukanya Pandey05388962021-06-10 15:35:21 +053032 system.statusState = data.Status?.State;
Yoshie Muranaka56ee7692020-05-28 13:28:29 -070033 system.systemType = data.SystemType;
34 state.systems = [system];
Derick Montague602e98a2020-10-21 16:20:00 -050035 },
Yoshie Muranaka56ee7692020-05-28 13:28:29 -070036 },
37 actions: {
38 async getSystem({ commit }) {
39 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030040 .get(`${await this.dispatch('global/getSystemPath')}`)
Yoshie Muranaka56ee7692020-05-28 13:28:29 -070041 .then(({ data }) => commit('setSystemInfo', data))
Derick Montague602e98a2020-10-21 16:20:00 -050042 .catch((error) => console.log(error));
43 },
Sukanya Pandey05388962021-06-10 15:35:21 +053044 async changeIdentifyLedState({ commit }, ledState) {
45 return await api
Sean Zhang8841b7d2024-06-15 08:42:41 +030046 .patch(`${await this.dispatch('global/getSystemPath')}`, {
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053047 LocationIndicatorActive: ledState,
48 })
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053049 .then(() => {
50 if (ledState) {
51 return i18n.t('pageInventory.toast.successEnableIdentifyLed');
52 } else {
53 return i18n.t('pageInventory.toast.successDisableIdentifyLed');
54 }
55 })
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053056 .catch((error) => {
Sukanya Pandey05388962021-06-10 15:35:21 +053057 commit('setSystemInfo', this.state.system.systems[0]);
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053058 console.log('error', error);
59 if (ledState) {
60 throw new Error(
Ed Tanous81323992024-02-27 11:26:24 -080061 i18n.t('pageInventory.toast.errorEnableIdentifyLed'),
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053062 );
63 } else {
64 throw new Error(
Ed Tanous81323992024-02-27 11:26:24 -080065 i18n.t('pageInventory.toast.errorDisableIdentifyLed'),
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053066 );
67 }
68 });
69 },
Derick Montague602e98a2020-10-21 16:20:00 -050070 },
Yoshie Muranaka56ee7692020-05-28 13:28:29 -070071};
72
73export default SystemStore;