From be3af3360cec7ba3eb2921662689c437f92e2fc7 Mon Sep 17 00:00:00 2001 From: Yoshie Muranaka Date: Mon, 11 May 2020 08:23:04 -0700 Subject: Add batch actions and row action to Event Logs Adds ability to export and delete event logs by row or in a table batch action. - Modifications to TableRowAction component to allow single row export functionality Signed-off-by: Yoshie Muranaka Change-Id: Ica50dd0868ac85cc2d6925a9448858b40da9c529 --- src/store/modules/Health/EventLogStore.js | 63 +++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 12 deletions(-) (limited to 'src/store/modules') diff --git a/src/store/modules/Health/EventLogStore.js b/src/store/modules/Health/EventLogStore.js index 2f0b800f..2b93ffa7 100644 --- a/src/store/modules/Health/EventLogStore.js +++ b/src/store/modules/Health/EventLogStore.js @@ -1,4 +1,5 @@ -import api from '../../api'; +import api, { getResponseCount } from '@/store/api'; +import i18n from '@/i18n'; const getHealthStatus = events => { let status = 'OK'; @@ -37,22 +38,60 @@ const EventLogStore = { return await api .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries') .then(({ data: { Members = [] } = {} }) => { - const eventLogs = Members.map( - ({ Id, Severity, Created, EntryType, Message }) => { - return { - id: Id, - severity: Severity, - date: new Date(Created), - type: EntryType, - description: Message - }; - } - ); + const eventLogs = Members.map(log => { + const { Id, Severity, Created, EntryType, Message } = log; + return { + id: Id, + severity: Severity, + date: new Date(Created), + type: EntryType, + description: Message, + uri: log['@odata.id'] + }; + }); commit('setAllEvents', eventLogs); }) .catch(error => { console.log('Event Log Data:', error); }); + }, + async deleteEventLogs({ dispatch }, uris = []) { + const promises = uris.map(uri => + api.delete(uri).catch(error => { + console.log(error); + return error; + }) + ); + return await api + .all(promises) + .then(response => { + dispatch('getEventLogData'); + return response; + }) + .then( + api.spread((...responses) => { + const { successCount, errorCount } = getResponseCount(responses); + const toastMessages = []; + + if (successCount) { + const message = i18n.tc( + 'pageEventLogs.toast.successDelete', + successCount + ); + toastMessages.push({ type: 'success', message }); + } + + if (errorCount) { + const message = i18n.tc( + 'pageEventLogs.toast.errorDelete', + errorCount + ); + toastMessages.push({ type: 'error', message }); + } + + return toastMessages; + }) + ); } } }; -- cgit v1.2.3