17affc529SSandeepa Singhimport api from '@/store/api'; 27affc529SSandeepa Singh 37affc529SSandeepa Singhconst FanStore = { 47affc529SSandeepa Singh namespaced: true, 57affc529SSandeepa Singh state: { 67affc529SSandeepa Singh fans: [], 77affc529SSandeepa Singh }, 87affc529SSandeepa Singh getters: { 97affc529SSandeepa Singh fans: (state) => state.fans, 107affc529SSandeepa Singh }, 117affc529SSandeepa Singh mutations: { 127affc529SSandeepa Singh setFanInfo: (state, data) => { 137affc529SSandeepa Singh state.fans = data.map((fan) => { 147affc529SSandeepa Singh const { 15582ac0d4SSivaprabu Ganesan Id, 16582ac0d4SSivaprabu Ganesan Name, 17582ac0d4SSivaprabu Ganesan PartNumber, 18582ac0d4SSivaprabu Ganesan SerialNumber, 19582ac0d4SSivaprabu Ganesan SpeedPercent = {}, 20582ac0d4SSivaprabu Ganesan Status = {}, 21582ac0d4SSivaprabu Ganesan } = fan; 22582ac0d4SSivaprabu Ganesan return { 23582ac0d4SSivaprabu Ganesan id: Id, 24582ac0d4SSivaprabu Ganesan health: Status.Health, 25582ac0d4SSivaprabu Ganesan name: Name, 26582ac0d4SSivaprabu Ganesan speed: SpeedPercent.Reading, 27582ac0d4SSivaprabu Ganesan statusState: Status.State, 28582ac0d4SSivaprabu Ganesan healthRollup: Status.HealthRollup, 29582ac0d4SSivaprabu Ganesan partNumber: PartNumber, 30582ac0d4SSivaprabu Ganesan serialNumber: SerialNumber, 31582ac0d4SSivaprabu Ganesan }; 327affc529SSandeepa Singh }); 337affc529SSandeepa Singh }, 347affc529SSandeepa Singh }, 357affc529SSandeepa Singh actions: { 366c5418f5SMichalX Szopinski async getChassisCollection() { 377affc529SSandeepa Singh return await api 386c5418f5SMichalX Szopinski .get('/redfish/v1/Chassis') 396c5418f5SMichalX Szopinski .then(({ data: { Members } }) => 406c5418f5SMichalX Szopinski api.all( 416c5418f5SMichalX Szopinski Members.map((member) => 42*8132399cSEd Tanous api.get(member['@odata.id']).then((response) => response.data), 43*8132399cSEd Tanous ), 44*8132399cSEd Tanous ), 456c5418f5SMichalX Szopinski ) 466c5418f5SMichalX Szopinski .catch((error) => console.log(error)); 476c5418f5SMichalX Szopinski }, 486c5418f5SMichalX Szopinski async getFanInfo({ dispatch, commit }) { 496c5418f5SMichalX Szopinski const collection = await dispatch('getChassisCollection'); 506c5418f5SMichalX Szopinski if (!collection || collection.length === 0) return; 516c5418f5SMichalX Szopinski return await api 526c5418f5SMichalX Szopinski .all(collection.map((chassis) => dispatch('getChassisFans', chassis))) 536c5418f5SMichalX Szopinski .then((fansFromChassis) => commit('setFanInfo', fansFromChassis.flat())) 546c5418f5SMichalX Szopinski .catch((error) => console.log(error)); 556c5418f5SMichalX Szopinski }, 566c5418f5SMichalX Szopinski async getChassisFans(_, chassis) { 57582ac0d4SSivaprabu Ganesan return await api 58582ac0d4SSivaprabu Ganesan .get(chassis.ThermalSubsystem['@odata.id']) 59582ac0d4SSivaprabu Ganesan .then((response) => { 60582ac0d4SSivaprabu Ganesan return api.get(`${response.data.Fans['@odata.id']}`); 61582ac0d4SSivaprabu Ganesan }) 62582ac0d4SSivaprabu Ganesan .then(({ data: { Members } }) => { 63582ac0d4SSivaprabu Ganesan const promises = Members.map((member) => 64*8132399cSEd Tanous api.get(member['@odata.id']), 65582ac0d4SSivaprabu Ganesan ); 66582ac0d4SSivaprabu Ganesan return api.all(promises); 67582ac0d4SSivaprabu Ganesan }) 68582ac0d4SSivaprabu Ganesan .then((response) => { 69582ac0d4SSivaprabu Ganesan const data = response.map(({ data }) => data); 70582ac0d4SSivaprabu Ganesan return data; 71582ac0d4SSivaprabu Ganesan }) 72582ac0d4SSivaprabu Ganesan .catch((error) => console.log(error)); 737affc529SSandeepa Singh }, 747affc529SSandeepa Singh }, 757affc529SSandeepa Singh}; 767affc529SSandeepa Singh 777affc529SSandeepa Singhexport default FanStore; 78