Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 1 | import api from '@/store/api'; |
Konstantin Aladyshev | d8c71c0 | 2023-02-15 12:49:11 +0000 | [diff] [blame] | 2 | import i18n from '@/i18n'; |
Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 3 | |
| 4 | const PostCodeLogsStore = { |
| 5 | namespaced: true, |
| 6 | state: { |
| 7 | allPostCodes: [], |
| 8 | }, |
| 9 | getters: { |
| 10 | allPostCodes: (state) => state.allPostCodes, |
| 11 | }, |
| 12 | mutations: { |
| 13 | setAllPostCodes: (state, allPostCodes) => |
| 14 | (state.allPostCodes = allPostCodes), |
| 15 | }, |
| 16 | actions: { |
| 17 | async getPostCodesLogData({ commit }) { |
| 18 | return await api |
| 19 | .get('/redfish/v1/Systems/system/LogServices/PostCodes/Entries') |
| 20 | .then(({ data: { Members = [] } = {} }) => { |
| 21 | const postCodeLogs = Members.map((log) => { |
| 22 | const { Created, MessageArgs, AdditionalDataURI } = log; |
| 23 | return { |
| 24 | date: new Date(Created), |
| 25 | bootCount: MessageArgs[0], |
| 26 | timeStampOffset: MessageArgs[1], |
| 27 | postCode: MessageArgs[2], |
| 28 | uri: AdditionalDataURI, |
| 29 | }; |
| 30 | }); |
| 31 | commit('setAllPostCodes', postCodeLogs); |
| 32 | }) |
| 33 | .catch((error) => { |
| 34 | console.log('POST Codes Log Data:', error); |
| 35 | }); |
| 36 | }, |
Konstantin Aladyshev | d8c71c0 | 2023-02-15 12:49:11 +0000 | [diff] [blame] | 37 | async deleteAllPostCodeLogs({ dispatch }, data) { |
| 38 | return await api |
| 39 | .post( |
| 40 | '/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog' |
| 41 | ) |
| 42 | .then(() => dispatch('getPostCodesLogData')) |
| 43 | .then(() => |
| 44 | i18n.tc('pagePostCodeLogs.toast.successDelete', data.length) |
| 45 | ) |
| 46 | .catch((error) => { |
| 47 | console.log(error); |
| 48 | throw new Error( |
| 49 | i18n.tc('pagePostCodeLogs.toast.errorDelete', data.length) |
| 50 | ); |
| 51 | }); |
| 52 | }, |
Sandeepa Singh | 06d5386 | 2021-05-24 13:51:09 +0530 | [diff] [blame] | 53 | }, |
| 54 | }; |
| 55 | |
| 56 | export default PostCodeLogsStore; |