blob: 0349c8b700b41d1c622ed0c1366c6e82ca1ff774 [file] [log] [blame]
Sukanya Pandey34efde22020-12-02 19:04:09 +05301import api, { getResponseCount } from '@/store/api';
2import i18n from '@/i18n';
3
Sandeepa Singhb4406162021-07-26 15:05:39 +05304const SessionsStore = {
Sukanya Pandey34efde22020-12-02 19:04:09 +05305 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 Singhb4406162021-07-26 15:05:39 +053017 async getSessionsData({ commit }) {
Sukanya Pandey34efde22020-12-02 19:04:09 +053018 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 {
kirankumarb07568b8a92023-02-14 18:42:43 +053029 sessionID: sessionUri.data?.Id,
30 context: sessionUri.data?.Context
31 ? sessionUri.data?.Context
32 : '-',
Sukanya Pandey34efde22020-12-02 19:04:09 +053033 username: sessionUri.data?.UserName,
Jiaqing Zhaoe4c78cf2022-04-21 14:17:51 +080034 ipAddress: sessionUri.data?.ClientOriginIPAddress,
Sukanya Pandey34efde22020-12-02 19:04:09 +053035 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 Singhb4406162021-07-26 15:05:39 +053054 dispatch('getSessionsData');
Sukanya Pandey34efde22020-12-02 19:04:09 +053055 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 Singhb4406162021-07-26 15:05:39 +053064 'pageSessions.toast.successDelete',
Sukanya Pandey34efde22020-12-02 19:04:09 +053065 successCount
66 );
67 toastMessages.push({ type: 'success', message });
68 }
69
70 if (errorCount) {
71 const message = i18n.tc(
Sandeepa Singhb4406162021-07-26 15:05:39 +053072 'pageSessions.toast.errorDelete',
Sukanya Pandey34efde22020-12-02 19:04:09 +053073 errorCount
74 );
75 toastMessages.push({ type: 'error', message });
76 }
77 return toastMessages;
78 })
79 );
80 },
81 },
82};
Sandeepa Singhb4406162021-07-26 15:05:39 +053083export default SessionsStore;