Sukanya Pandey | 34efde2 | 2020-12-02 19:04:09 +0530 | [diff] [blame] | 1 | import api, { getResponseCount } from '@/store/api'; |
| 2 | import i18n from '@/i18n'; |
| 3 | |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 4 | const SessionsStore = { |
Sukanya Pandey | 34efde2 | 2020-12-02 19:04:09 +0530 | [diff] [blame] | 5 | namespaced: true, |
| 6 | state: { |
| 7 | allConnections: [], |
| 8 | }, |
| 9 | getters: { |
| 10 | allConnections: (state) => state.allConnections, |
| 11 | }, |
| 12 | mutations: { |
| 13 | setAllConnections: (state, allConnections) => |
| 14 | (state.allConnections = allConnections), |
| 15 | }, |
| 16 | actions: { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 17 | async getSessionsData({ commit }) { |
Sukanya Pandey | 34efde2 | 2020-12-02 19:04:09 +0530 | [diff] [blame] | 18 | return await api |
| 19 | .get('/redfish/v1/SessionService/Sessions') |
| 20 | .then((response) => |
| 21 | response.data.Members.map((sessionLogs) => sessionLogs['@odata.id']) |
| 22 | ) |
| 23 | .then((sessionUris) => |
| 24 | api.all(sessionUris.map((sessionUri) => api.get(sessionUri))) |
| 25 | ) |
| 26 | .then((sessionUris) => { |
| 27 | const allConnectionsData = sessionUris.map((sessionUri) => { |
| 28 | return { |
kirankumarb07 | 568b8a9 | 2023-02-14 18:42:43 +0530 | [diff] [blame^] | 29 | sessionID: sessionUri.data?.Id, |
| 30 | context: sessionUri.data?.Context |
| 31 | ? sessionUri.data?.Context |
| 32 | : '-', |
Sukanya Pandey | 34efde2 | 2020-12-02 19:04:09 +0530 | [diff] [blame] | 33 | username: sessionUri.data?.UserName, |
Jiaqing Zhao | e4c78cf | 2022-04-21 14:17:51 +0800 | [diff] [blame] | 34 | ipAddress: sessionUri.data?.ClientOriginIPAddress, |
Sukanya Pandey | 34efde2 | 2020-12-02 19:04:09 +0530 | [diff] [blame] | 35 | uri: sessionUri.data['@odata.id'], |
| 36 | }; |
| 37 | }); |
| 38 | commit('setAllConnections', allConnectionsData); |
| 39 | }) |
| 40 | .catch((error) => { |
| 41 | console.log('Client Session Data:', error); |
| 42 | }); |
| 43 | }, |
| 44 | async disconnectSessions({ dispatch }, uris = []) { |
| 45 | const promises = uris.map((uri) => |
| 46 | api.delete(uri).catch((error) => { |
| 47 | console.log(error); |
| 48 | return error; |
| 49 | }) |
| 50 | ); |
| 51 | return await api |
| 52 | .all(promises) |
| 53 | .then((response) => { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 54 | dispatch('getSessionsData'); |
Sukanya Pandey | 34efde2 | 2020-12-02 19:04:09 +0530 | [diff] [blame] | 55 | return response; |
| 56 | }) |
| 57 | .then( |
| 58 | api.spread((...responses) => { |
| 59 | const { successCount, errorCount } = getResponseCount(responses); |
| 60 | const toastMessages = []; |
| 61 | |
| 62 | if (successCount) { |
| 63 | const message = i18n.tc( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 64 | 'pageSessions.toast.successDelete', |
Sukanya Pandey | 34efde2 | 2020-12-02 19:04:09 +0530 | [diff] [blame] | 65 | successCount |
| 66 | ); |
| 67 | toastMessages.push({ type: 'success', message }); |
| 68 | } |
| 69 | |
| 70 | if (errorCount) { |
| 71 | const message = i18n.tc( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 72 | 'pageSessions.toast.errorDelete', |
Sukanya Pandey | 34efde2 | 2020-12-02 19:04:09 +0530 | [diff] [blame] | 73 | errorCount |
| 74 | ); |
| 75 | toastMessages.push({ type: 'error', message }); |
| 76 | } |
| 77 | return toastMessages; |
| 78 | }) |
| 79 | ); |
| 80 | }, |
| 81 | }, |
| 82 | }; |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 83 | export default SessionsStore; |