1b440616cSSandeepa Singhimport api, { getResponseCount } from '@/store/api'; 2b440616cSSandeepa Singhimport i18n from '@/i18n'; 3b440616cSSandeepa Singh 4b440616cSSandeepa Singhconst SessionsStore = { 5b440616cSSandeepa Singh namespaced: true, 6b440616cSSandeepa Singh state: { 7b440616cSSandeepa Singh allConnections: [], 8b440616cSSandeepa Singh }, 9b440616cSSandeepa Singh getters: { 10b440616cSSandeepa Singh allConnections: (state) => state.allConnections, 11b440616cSSandeepa Singh }, 12b440616cSSandeepa Singh mutations: { 13b440616cSSandeepa Singh setAllConnections: (state, allConnections) => 14b440616cSSandeepa Singh (state.allConnections = allConnections), 15b440616cSSandeepa Singh }, 16b440616cSSandeepa Singh actions: { 17b440616cSSandeepa Singh async getSessionsData({ commit }) { 18b440616cSSandeepa Singh return await api 19b440616cSSandeepa Singh .get('/redfish/v1/SessionService/Sessions') 20b440616cSSandeepa Singh .then((response) => 218132399cSEd Tanous response.data.Members.map((sessionLogs) => sessionLogs['@odata.id']), 22b440616cSSandeepa Singh ) 23b440616cSSandeepa Singh .then((sessionUris) => 248132399cSEd Tanous api.all(sessionUris.map((sessionUri) => api.get(sessionUri))), 25b440616cSSandeepa Singh ) 26b440616cSSandeepa Singh .then((sessionUris) => { 27b440616cSSandeepa Singh const allConnectionsData = sessionUris.map((sessionUri) => { 28b440616cSSandeepa Singh return { 29568b8a93Skirankumarb07 sessionID: sessionUri.data?.Id, 30568b8a93Skirankumarb07 context: sessionUri.data?.Context 31568b8a93Skirankumarb07 ? sessionUri.data?.Context 32568b8a93Skirankumarb07 : '-', 33b440616cSSandeepa Singh username: sessionUri.data?.UserName, 34e4c78cf3SJiaqing Zhao ipAddress: sessionUri.data?.ClientOriginIPAddress, 35b440616cSSandeepa Singh uri: sessionUri.data['@odata.id'], 36b440616cSSandeepa Singh }; 37b440616cSSandeepa Singh }); 38b440616cSSandeepa Singh commit('setAllConnections', allConnectionsData); 39b440616cSSandeepa Singh }) 40b440616cSSandeepa Singh .catch((error) => { 41b440616cSSandeepa Singh console.log('Client Session Data:', error); 42b440616cSSandeepa Singh }); 43b440616cSSandeepa Singh }, 44b440616cSSandeepa Singh async disconnectSessions({ dispatch }, uris = []) { 45b440616cSSandeepa Singh const promises = uris.map((uri) => 46b440616cSSandeepa Singh api.delete(uri).catch((error) => { 47b440616cSSandeepa Singh console.log(error); 48b440616cSSandeepa Singh return error; 498132399cSEd Tanous }), 50b440616cSSandeepa Singh ); 51b440616cSSandeepa Singh return await api 52b440616cSSandeepa Singh .all(promises) 53b440616cSSandeepa Singh .then((response) => { 54b440616cSSandeepa Singh dispatch('getSessionsData'); 55b440616cSSandeepa Singh return response; 56b440616cSSandeepa Singh }) 57b440616cSSandeepa Singh .then( 58b440616cSSandeepa Singh api.spread((...responses) => { 59b440616cSSandeepa Singh const { successCount, errorCount } = getResponseCount(responses); 60b440616cSSandeepa Singh const toastMessages = []; 61b440616cSSandeepa Singh 62b440616cSSandeepa Singh if (successCount) { 63*de23ea23SSurya V const message = i18n.global.t( 64b440616cSSandeepa Singh 'pageSessions.toast.successDelete', 658132399cSEd Tanous successCount, 66b440616cSSandeepa Singh ); 67b440616cSSandeepa Singh toastMessages.push({ type: 'success', message }); 68b440616cSSandeepa Singh } 69b440616cSSandeepa Singh 70b440616cSSandeepa Singh if (errorCount) { 71*de23ea23SSurya V const message = i18n.global.t( 72b440616cSSandeepa Singh 'pageSessions.toast.errorDelete', 738132399cSEd Tanous errorCount, 74b440616cSSandeepa Singh ); 75b440616cSSandeepa Singh toastMessages.push({ type: 'error', message }); 76b440616cSSandeepa Singh } 77b440616cSSandeepa Singh return toastMessages; 788132399cSEd Tanous }), 79b440616cSSandeepa Singh ); 80b440616cSSandeepa Singh }, 81b440616cSSandeepa Singh }, 82b440616cSSandeepa Singh}; 83b440616cSSandeepa Singhexport default SessionsStore; 84