blob: 50c8b6f7d72216e9f2abb18c7595df8524607124 [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) {
Surya V603cfbf2024-07-11 15:19:46 +053051 return i18n.global.t(
52 'pageInventory.toast.successEnableIdentifyLed',
53 );
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053054 } else {
Surya V603cfbf2024-07-11 15:19:46 +053055 return i18n.global.t(
56 'pageInventory.toast.successDisableIdentifyLed',
57 );
Nikhil Ashokaf11a1902024-05-09 15:17:44 +053058 }
59 })
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053060 .catch((error) => {
Sukanya Pandey05388962021-06-10 15:35:21 +053061 commit('setSystemInfo', this.state.system.systems[0]);
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053062 console.log('error', error);
63 if (ledState) {
64 throw new Error(
Surya V603cfbf2024-07-11 15:19:46 +053065 i18n.global.t('pageInventory.toast.errorEnableIdentifyLed'),
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053066 );
67 } else {
68 throw new Error(
Surya V603cfbf2024-07-11 15:19:46 +053069 i18n.global.t('pageInventory.toast.errorDisableIdentifyLed'),
Sukanya Pandeyeb4cef32021-04-09 15:40:27 +053070 );
71 }
72 });
73 },
Derick Montague602e98a2020-10-21 16:20:00 -050074 },
Yoshie Muranaka56ee7692020-05-28 13:28:29 -070075};
76
77export default SystemStore;