Sneha Patel | a02c6f9 | 2021-09-09 12:40:38 -0500 | [diff] [blame] | 1 | import api from '@/store/api'; |
| 2 | import i18n from '@/i18n'; |
| 3 | |
| 4 | const AssemblyStore = { |
| 5 | namespaced: true, |
| 6 | state: { |
| 7 | assemblies: null, |
| 8 | }, |
| 9 | getters: { |
| 10 | assemblies: (state) => state.assemblies, |
| 11 | }, |
| 12 | mutations: { |
| 13 | setAssemblyInfo: (state, data) => { |
| 14 | state.assemblies = data.map((assembly) => { |
| 15 | const { |
| 16 | MemberId, |
| 17 | PartNumber, |
| 18 | SerialNumber, |
| 19 | SparePartNumber, |
| 20 | Model, |
| 21 | Name, |
| 22 | Location, |
| 23 | LocationIndicatorActive, |
| 24 | } = assembly; |
| 25 | return { |
| 26 | id: MemberId, |
| 27 | partNumber: PartNumber, |
| 28 | serialNumber: SerialNumber, |
| 29 | sparePartNumber: SparePartNumber, |
| 30 | model: Model, |
| 31 | name: Name, |
| 32 | locationNumber: Location?.PartLocation?.ServiceLabel, |
| 33 | identifyLed: LocationIndicatorActive, |
| 34 | uri: assembly['@odata.id'], |
| 35 | }; |
| 36 | }); |
| 37 | }, |
| 38 | }, |
| 39 | actions: { |
| 40 | async getAssemblyInfo({ commit }) { |
| 41 | return await api |
| 42 | .get('/redfish/v1/Chassis/chassis/Assembly') |
| 43 | .then(({ data }) => commit('setAssemblyInfo', data?.Assemblies)) |
| 44 | .catch((error) => console.log(error)); |
| 45 | }, |
| 46 | async updateIdentifyLedValue({ dispatch }, led) { |
| 47 | const uri = led.uri; |
| 48 | const updatedIdentifyLedValue = { |
Kenneth Fullbright | d600bb5 | 2021-12-20 17:01:31 -0600 | [diff] [blame] | 49 | Assemblies: [ |
| 50 | { |
| 51 | MemberId: led.memberId, |
| 52 | LocationIndicatorActive: led.identifyLed, |
| 53 | }, |
| 54 | ], |
Sneha Patel | a02c6f9 | 2021-09-09 12:40:38 -0500 | [diff] [blame] | 55 | }; |
Kenneth Fullbright | d600bb5 | 2021-12-20 17:01:31 -0600 | [diff] [blame] | 56 | |
Nikhil Ashoka | f11a190 | 2024-05-09 15:17:44 +0530 | [diff] [blame] | 57 | return await api |
| 58 | .patch(uri, updatedIdentifyLedValue) |
| 59 | .then(() => { |
| 60 | if (led.identifyLed) { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 61 | return i18n.global.t( |
| 62 | 'pageInventory.toast.successEnableIdentifyLed', |
| 63 | ); |
Nikhil Ashoka | f11a190 | 2024-05-09 15:17:44 +0530 | [diff] [blame] | 64 | } else { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 65 | return i18n.global.t( |
| 66 | 'pageInventory.toast.successDisableIdentifyLed', |
| 67 | ); |
Nikhil Ashoka | f11a190 | 2024-05-09 15:17:44 +0530 | [diff] [blame] | 68 | } |
| 69 | }) |
| 70 | .catch((error) => { |
| 71 | dispatch('getAssemblyInfo'); |
| 72 | console.log('error', error); |
| 73 | if (led.identifyLed) { |
| 74 | throw new Error( |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 75 | i18n.global.t('pageInventory.toast.errorEnableIdentifyLed'), |
Nikhil Ashoka | f11a190 | 2024-05-09 15:17:44 +0530 | [diff] [blame] | 76 | ); |
| 77 | } else { |
| 78 | throw new Error( |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 79 | i18n.global.t('pageInventory.toast.errorDisableIdentifyLed'), |
Nikhil Ashoka | f11a190 | 2024-05-09 15:17:44 +0530 | [diff] [blame] | 80 | ); |
| 81 | } |
| 82 | }); |
Sneha Patel | a02c6f9 | 2021-09-09 12:40:38 -0500 | [diff] [blame] | 83 | }, |
| 84 | }, |
| 85 | }; |
| 86 | |
| 87 | export default AssemblyStore; |