Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 1 | import api from '@/store/api'; |
| 2 | |
| 3 | const FanStore = { |
| 4 | namespaced: true, |
| 5 | state: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 6 | fans: [], |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 7 | }, |
| 8 | getters: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 9 | fans: (state) => state.fans, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 10 | }, |
| 11 | mutations: { |
| 12 | setFanInfo: (state, data) => { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 13 | state.fans = data.map((fan) => { |
Dixsie Wolmers | dd652d7 | 2021-05-13 09:08:53 -0500 | [diff] [blame] | 14 | const { |
| 15 | IndicatorLED, |
| 16 | Location, |
| 17 | MemberId, |
| 18 | Name, |
| 19 | Reading, |
| 20 | ReadingUnits, |
| 21 | Status = {}, |
| 22 | PartNumber, |
| 23 | SerialNumber, |
| 24 | } = fan; |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 25 | return { |
| 26 | id: MemberId, |
| 27 | health: Status.Health, |
| 28 | partNumber: PartNumber, |
| 29 | serialNumber: SerialNumber, |
Dixsie Wolmers | dd652d7 | 2021-05-13 09:08:53 -0500 | [diff] [blame] | 30 | healthRollup: Status.HealthRollup, |
| 31 | identifyLed: IndicatorLED, |
| 32 | locationNumber: Location, |
| 33 | name: Name, |
| 34 | speed: Reading + ' ' + ReadingUnits, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 35 | statusState: Status.State, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 36 | }; |
| 37 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 38 | }, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 39 | }, |
| 40 | actions: { |
MichalX Szopinski | 6c5418f | 2022-02-25 13:13:27 +0100 | [diff] [blame] | 41 | async getChassisCollection() { |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 42 | return await api |
MichalX Szopinski | 6c5418f | 2022-02-25 13:13:27 +0100 | [diff] [blame] | 43 | .get('/redfish/v1/Chassis') |
| 44 | .then(({ data: { Members } }) => |
| 45 | api.all( |
| 46 | Members.map((member) => |
| 47 | api.get(member['@odata.id']).then((response) => response.data) |
| 48 | ) |
| 49 | ) |
| 50 | ) |
| 51 | .catch((error) => console.log(error)); |
| 52 | }, |
| 53 | async getFanInfo({ dispatch, commit }) { |
| 54 | const collection = await dispatch('getChassisCollection'); |
| 55 | if (!collection || collection.length === 0) return; |
| 56 | return await api |
| 57 | .all(collection.map((chassis) => dispatch('getChassisFans', chassis))) |
| 58 | .then((fansFromChassis) => commit('setFanInfo', fansFromChassis.flat())) |
| 59 | .catch((error) => console.log(error)); |
| 60 | }, |
| 61 | async getChassisFans(_, chassis) { |
| 62 | return await api |
| 63 | .get(chassis.Thermal['@odata.id']) |
| 64 | .then(({ data: { Fans } }) => Fans || []) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 65 | .catch((error) => console.log(error)); |
| 66 | }, |
| 67 | }, |
Yoshie Muranaka | b89a53c | 2020-06-15 13:25:46 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | export default FanStore; |