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