| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 1 | import api from '@/store/api'; | 
| Sandeepa Singh | 240c056 | 2021-05-06 21:59:20 +0530 | [diff] [blame] | 2 | import i18n from '@/i18n'; | 
| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 3 |  | 
|  | 4 | const ChassisStore = { | 
|  | 5 | namespaced: true, | 
|  | 6 | state: { | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 7 | chassis: [], | 
| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 8 | }, | 
|  | 9 | getters: { | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 10 | chassis: (state) => state.chassis, | 
| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 11 | }, | 
|  | 12 | mutations: { | 
|  | 13 | setChassisInfo: (state, data) => { | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 14 | state.chassis = data.map((chassis) => { | 
| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 15 | const { | 
|  | 16 | Id, | 
|  | 17 | Status = {}, | 
|  | 18 | PartNumber, | 
|  | 19 | SerialNumber, | 
|  | 20 | ChassisType, | 
|  | 21 | Manufacturer, | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 22 | PowerState, | 
| Sandeepa Singh | 240c056 | 2021-05-06 21:59:20 +0530 | [diff] [blame] | 23 | LocationIndicatorActive, | 
|  | 24 | AssetTag, | 
| MichalX Szopinski | fedc734 | 2022-02-25 17:07:53 +0100 | [diff] [blame] | 25 | Model, | 
| Sandeepa Singh | 240c056 | 2021-05-06 21:59:20 +0530 | [diff] [blame] | 26 | MaxPowerWatts, | 
|  | 27 | MinPowerWatts, | 
|  | 28 | Name, | 
| Sneha Patel | 9f61234 | 2021-09-02 12:23:42 -0500 | [diff] [blame] | 29 | Location, | 
| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 30 | } = chassis; | 
|  | 31 |  | 
|  | 32 | return { | 
|  | 33 | id: Id, | 
|  | 34 | health: Status.Health, | 
|  | 35 | partNumber: PartNumber, | 
|  | 36 | serialNumber: SerialNumber, | 
|  | 37 | chassisType: ChassisType, | 
|  | 38 | manufacturer: Manufacturer, | 
|  | 39 | powerState: PowerState, | 
|  | 40 | statusState: Status.State, | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 41 | healthRollup: Status.HealthRollup, | 
| Sandeepa Singh | 240c056 | 2021-05-06 21:59:20 +0530 | [diff] [blame] | 42 | assetTag: AssetTag, | 
| MichalX Szopinski | fedc734 | 2022-02-25 17:07:53 +0100 | [diff] [blame] | 43 | model: Model, | 
| Sandeepa Singh | 240c056 | 2021-05-06 21:59:20 +0530 | [diff] [blame] | 44 | maxPowerWatts: MaxPowerWatts, | 
|  | 45 | minPowerWatts: MinPowerWatts, | 
|  | 46 | name: Name, | 
|  | 47 | identifyLed: LocationIndicatorActive, | 
|  | 48 | uri: chassis['@odata.id'], | 
| Sneha Patel | 9f61234 | 2021-09-02 12:23:42 -0500 | [diff] [blame] | 49 | locationNumber: Location?.PartLocation?.ServiceLabel, | 
| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 50 | }; | 
|  | 51 | }); | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 52 | }, | 
| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 53 | }, | 
|  | 54 | actions: { | 
|  | 55 | async getChassisInfo({ commit }) { | 
|  | 56 | return await api | 
|  | 57 | .get('/redfish/v1/Chassis') | 
|  | 58 | .then(({ data: { Members = [] } }) => | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 59 | Members.map((member) => api.get(member['@odata.id'])) | 
| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 60 | ) | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 61 | .then((promises) => api.all(promises)) | 
|  | 62 | .then((response) => { | 
| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 63 | const data = response.map(({ data }) => data); | 
|  | 64 | commit('setChassisInfo', data); | 
|  | 65 | }) | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 66 | .catch((error) => console.log(error)); | 
|  | 67 | }, | 
| Sandeepa Singh | 240c056 | 2021-05-06 21:59:20 +0530 | [diff] [blame] | 68 | async updateIdentifyLedValue({ dispatch }, led) { | 
|  | 69 | const uri = led.uri; | 
|  | 70 | const updatedIdentifyLedValue = { | 
|  | 71 | LocationIndicatorActive: led.identifyLed, | 
|  | 72 | }; | 
|  | 73 | return await api | 
|  | 74 | .patch(uri, updatedIdentifyLedValue) | 
|  | 75 | .then(() => dispatch('getChassisInfo')) | 
|  | 76 | .catch((error) => { | 
|  | 77 | dispatch('getChassisInfo'); | 
|  | 78 | console.log('error', error); | 
|  | 79 | if (led.identifyLed) { | 
|  | 80 | throw new Error( | 
| Sandeepa Singh | 7affc52 | 2021-07-06 16:29:10 +0530 | [diff] [blame] | 81 | i18n.t('pageInventory.toast.errorEnableIdentifyLed') | 
| Sandeepa Singh | 240c056 | 2021-05-06 21:59:20 +0530 | [diff] [blame] | 82 | ); | 
|  | 83 | } else { | 
|  | 84 | throw new Error( | 
| Sandeepa Singh | 7affc52 | 2021-07-06 16:29:10 +0530 | [diff] [blame] | 85 | i18n.t('pageInventory.toast.errorDisableIdentifyLed') | 
| Sandeepa Singh | 240c056 | 2021-05-06 21:59:20 +0530 | [diff] [blame] | 86 | ); | 
|  | 87 | } | 
|  | 88 | }); | 
|  | 89 | }, | 
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 90 | }, | 
| Yoshie Muranaka | 09e8b5d | 2020-06-08 07:36:59 -0700 | [diff] [blame] | 91 | }; | 
|  | 92 |  | 
|  | 93 | export default ChassisStore; |