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