From 29297f14bd7d4296664f15adba85e44b8bf3ee87 Mon Sep 17 00:00:00 2001 From: davidjumani Date: Mon, 14 Sep 2020 11:41:44 +0530 Subject: [PATCH] Fixing currentAction null while processing the response Signed-off-by: Rohit Yadav --- ui/src/config/section/event.js | 2 + ui/src/config/section/infra/zones.js | 2 +- ui/src/locales/en.json | 4 +- ui/src/views/AutogenView.vue | 148 ++++++++++++++------------- 4 files changed, 81 insertions(+), 75 deletions(-) diff --git a/ui/src/config/section/event.js b/ui/src/config/section/event.js index 1411fb024de..9dab6964729 100644 --- a/ui/src/config/section/event.js +++ b/ui/src/config/section/event.js @@ -37,6 +37,7 @@ export default { message: 'message.confirm.archive.selected.events', docHelp: 'adminguide/events.html#deleting-and-archiving-events-and-alerts', dataView: true, + successMessage: 'label.event.archived', groupAction: true, groupMap: (selection) => { return [{ ids: selection.join(',') }] }, args: ['ids'], @@ -55,6 +56,7 @@ export default { message: 'message.confirm.remove.selected.events', docHelp: 'adminguide/events.html#deleting-and-archiving-events-and-alerts', dataView: true, + successMessage: 'label.event.deleted', groupAction: true, groupMap: (selection) => { return [{ ids: selection.join(',') }] }, args: ['ids'], diff --git a/ui/src/config/section/infra/zones.js b/ui/src/config/section/infra/zones.js index 44e24e7d637..7254155f906 100644 --- a/ui/src/config/section/infra/zones.js +++ b/ui/src/config/section/infra/zones.js @@ -201,7 +201,7 @@ export default { icon: 'block', label: 'label.update.vmware.datacenter', message: 'message.restart.mgmt.server', - successMessage: 'message.restart.mgmt.server', + additionalMessage: 'message.restart.mgmt.server', dataView: true, show: record => record.vmwaredc, args: ['zoneid', 'name', 'vcenter', 'username', 'password'], diff --git a/ui/src/locales/en.json b/ui/src/locales/en.json index b926f20dcb1..b7af2d0bf28 100644 --- a/ui/src/locales/en.json +++ b/ui/src/locales/en.json @@ -863,8 +863,8 @@ "label.esplifetime": "ESP Lifetime (second)", "label.esppolicy": "ESP policy", "label.event": "Event", -"label.event.archived": "Event Archived", -"label.event.deleted": "Event Deleted", +"label.event.archived": "Event(s) Archived", +"label.event.deleted": "Event(s) Deleted", "label.event.timeline": "Event Timeline", "label.events": "Events", "label.every": "Every", diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue index 5e627599b37..75a23d2b2b6 100644 --- a/ui/src/views/AutogenView.vue +++ b/ui/src/views/AutogenView.vue @@ -876,30 +876,32 @@ export default { } }, callGroupApi (params, resourceName) { - api(this.currentAction.api, params).then(json => { - this.handleResponse(json, resourceName, false) + const action = this.currentAction + api(action.api, params).then(json => { + this.handleResponse(json, resourceName, action, false) }).catch(error => { this.$notifyError(error) }) }, - handleResponse (response, resourceName, showLoading = true) { + handleResponse (response, resourceName, action, showLoading = true) { for (const obj in response) { if (obj.includes('response')) { if (response[obj].jobid) { const jobid = response[obj].jobid - this.$store.dispatch('AddAsyncJob', { title: this.$t(this.currentAction.label), jobid: jobid, description: resourceName, status: 'progress' }) - this.pollActionCompletion(jobid, this.currentAction, resourceName, showLoading) + this.$store.dispatch('AddAsyncJob', { title: this.$t(action.label), jobid: jobid, description: resourceName, status: 'progress' }) + this.pollActionCompletion(jobid, action, resourceName, showLoading) return true } else { - var message = this.$t(this.currentAction.label) + (resourceName ? ' - ' + resourceName : '') + var message = action.successMessage ? this.$t(action.successMessage) : this.$t(action.label) + + (resourceName ? ' - ' + resourceName : '') var duration = 2 - if (this.currentAction.successMessage) { - message = message + ' - ' + this.$t(this.currentAction.successMessage) + if (action.additionalMessage) { + message = message + ' - ' + this.$t(action.successMessage) duration = 5 } this.$message.success({ content: message, - key: this.currentAction.label + resourceName, + key: action.label + resourceName, duration: duration }) } @@ -911,76 +913,78 @@ export default { execSubmit (e) { e.preventDefault() this.form.validateFields((err, values) => { - if (!err) { - const params = {} - if ('id' in this.resource && this.currentAction.params.map(i => { return i.name }).includes('id')) { - params.id = this.resource.id - } - for (const key in values) { - const input = values[key] - for (const param of this.currentAction.params) { - if (param.name !== key) { - continue - } - if (input === undefined || input === null || input === '') { - if (param.type === 'boolean') { - params[key] = false - } - break - } - if (this.currentAction.mapping && key in this.currentAction.mapping && this.currentAction.mapping[key].options) { - params[key] = this.currentAction.mapping[key].options[input] - } else if (param.type === 'list') { - params[key] = input.map(e => { return param.opts[e].id }).reduce((str, name) => { return str + ',' + name }) - } else if (param.name === 'account' || param.name === 'keypair') { - if (['addAccountToProject', 'createAccount'].includes(this.currentAction.api)) { - params[key] = input - } else { - params[key] = param.opts[input].name - } - } else { - params[key] = input + if (err) { + return + } + const params = {} + const action = this.currentAction + if ('id' in this.resource && action.params.map(i => { return i.name }).includes('id')) { + params.id = this.resource.id + } + for (const key in values) { + const input = values[key] + for (const param of action.params) { + if (param.name !== key) { + continue + } + if (input === undefined || input === null || input === '') { + if (param.type === 'boolean') { + params[key] = false } break } - } - - for (const key in this.currentAction.defaultArgs) { - if (!params[key]) { - params[key] = this.currentAction.defaultArgs[key] - } - } - - if (this.currentAction.mapping) { - for (const key in this.currentAction.mapping) { - if (!this.currentAction.mapping[key].value) { - continue + if (action.mapping && key in action.mapping && action.mapping[key].options) { + params[key] = action.mapping[key].options[input] + } else if (param.type === 'list') { + params[key] = input.map(e => { return param.opts[e].id }).reduce((str, name) => { return str + ',' + name }) + } else if (param.name === 'account' || param.name === 'keypair') { + if (['addAccountToProject', 'createAccount'].includes(action.api)) { + params[key] = input + } else { + params[key] = param.opts[input].name } - params[key] = this.currentAction.mapping[key].value(this.resource, params) - } - } - - const resourceName = params.displayname || params.displaytext || params.name || params.hostname || params.username || params.ipaddress || params.virtualmachinename || this.resource.name - - var hasJobId = false - this.actionLoading = true - api(this.currentAction.api, params).then(json => { - hasJobId = this.handleResponse(json, resourceName) - if ((this.currentAction.icon === 'delete' || ['archiveEvents', 'archiveAlerts'].includes(this.currentAction.api)) && this.dataView) { - this.$router.go(-1) } else { - if (!hasJobId) { - this.fetchData() - } + params[key] = input } - }).catch(error => { - console.log(error) - this.$notifyError(error) - }).finally(f => { - this.actionLoading = false - this.closeAction() - }) + break + } } + + for (const key in action.defaultArgs) { + if (!params[key]) { + params[key] = action.defaultArgs[key] + } + } + + if (action.mapping) { + for (const key in action.mapping) { + if (!action.mapping[key].value) { + continue + } + params[key] = action.mapping[key].value(this.resource, params) + } + } + + const resourceName = params.displayname || params.displaytext || params.name || params.hostname || params.username || params.ipaddress || params.virtualmachinename || this.resource.name + + var hasJobId = false + this.actionLoading = true + api(action.api, params).then(json => { + hasJobId = this.handleResponse(json, resourceName, action) + if ((action.icon === 'delete' || ['archiveEvents', 'archiveAlerts'].includes(action.api)) && this.dataView) { + this.$router.go(-1) + } else { + if (!hasJobId) { + this.fetchData() + } + } + }).catch(error => { + console.log(error) + this.$notifyError(error) + }).finally(f => { + this.actionLoading = false + this.closeAction() + }) }) }, changeFilter (filter) {