Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 1 | import api from '@/store/api'; |
Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 2 | import i18n from '@/i18n'; |
Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 3 | |
| 4 | const SystemStore = { |
| 5 | namespaced: true, |
| 6 | state: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 7 | systems: [], |
Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 8 | }, |
| 9 | getters: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 10 | systems: (state) => state.systems, |
Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 11 | }, |
| 12 | mutations: { |
| 13 | setSystemInfo: (state, data) => { |
| 14 | const system = {}; |
| 15 | system.assetTag = data.AssetTag; |
| 16 | system.description = data.Description; |
Yoshie Muranaka | c687f10 | 2020-06-02 12:01:27 -0700 | [diff] [blame] | 17 | system.firmwareVersion = data.BiosVersion; |
Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 18 | system.hardwareType = data.Name; |
Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 19 | system.health = data.Status?.Health; |
Nikhil Ashoka | 18cde3c | 2022-01-05 22:21:24 +0530 | [diff] [blame] | 20 | system.totalSystemMemoryGiB = data.MemorySummary?.TotalSystemMemoryGiB; |
Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 21 | system.id = data.Id; |
SurenNeware | bbf896c | 2021-01-27 21:50:22 +0530 | [diff] [blame] | 22 | system.locationIndicatorActive = data.LocationIndicatorActive; |
Sneha Patel | 9f61234 | 2021-09-02 12:23:42 -0500 | [diff] [blame] | 23 | system.locationNumber = data.Location?.PartLocation?.ServiceLabel; |
Yoshie Muranaka | c687f10 | 2020-06-02 12:01:27 -0700 | [diff] [blame] | 24 | system.manufacturer = data.Manufacturer; |
Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 25 | system.model = data.Model; |
Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 26 | system.processorSummaryCount = data.ProcessorSummary?.Count; |
Nikhil Ashoka | 18cde3c | 2022-01-05 22:21:24 +0530 | [diff] [blame] | 27 | system.processorSummaryCoreCount = data.ProcessorSummary?.CoreCount; |
Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 28 | system.powerState = data.PowerState; |
| 29 | system.serialNumber = data.SerialNumber; |
Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 30 | system.healthRollup = data.Status?.HealthRollup; |
Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 31 | system.subModel = data.SubModel; |
Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 32 | system.statusState = data.Status?.State; |
Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 33 | system.systemType = data.SystemType; |
| 34 | state.systems = [system]; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 35 | }, |
Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 36 | }, |
| 37 | actions: { |
| 38 | async getSystem({ commit }) { |
| 39 | return await api |
Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 40 | .get('/redfish/v1') |
| 41 | .then((response) => |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 42 | api.get(`${response.data.Systems['@odata.id']}/system`), |
Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 43 | ) |
Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 44 | .then(({ data }) => commit('setSystemInfo', data)) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 45 | .catch((error) => console.log(error)); |
| 46 | }, |
Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 47 | async changeIdentifyLedState({ commit }, ledState) { |
| 48 | return await api |
Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 49 | .patch('/redfish/v1/Systems/system', { |
| 50 | LocationIndicatorActive: ledState, |
| 51 | }) |
Nikhil Ashoka | f11a190 | 2024-05-09 15:17:44 +0530 | [diff] [blame^] | 52 | .then(() => { |
| 53 | if (ledState) { |
| 54 | return i18n.t('pageInventory.toast.successEnableIdentifyLed'); |
| 55 | } else { |
| 56 | return i18n.t('pageInventory.toast.successDisableIdentifyLed'); |
| 57 | } |
| 58 | }) |
Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 59 | .catch((error) => { |
Sukanya Pandey | 0538896 | 2021-06-10 15:35:21 +0530 | [diff] [blame] | 60 | commit('setSystemInfo', this.state.system.systems[0]); |
Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 61 | console.log('error', error); |
| 62 | if (ledState) { |
| 63 | throw new Error( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 64 | i18n.t('pageInventory.toast.errorEnableIdentifyLed'), |
Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 65 | ); |
| 66 | } else { |
| 67 | throw new Error( |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 68 | i18n.t('pageInventory.toast.errorDisableIdentifyLed'), |
Sukanya Pandey | eb4cef3 | 2021-04-09 15:40:27 +0530 | [diff] [blame] | 69 | ); |
| 70 | } |
| 71 | }); |
| 72 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 73 | }, |
Yoshie Muranaka | 56ee769 | 2020-05-28 13:28:29 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | export default SystemStore; |