autogenview: display actual name from API args in notification

Fixes #336

With this fix, any API action will use the name and similar parameters
to display in the notification instead of resource.name. This also fixes
the issue of removal of all jobs in the notification menu (the ones in
progress shouldn't be cleared).

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2020-05-21 14:38:11 +05:30
parent a21342dc80
commit 615d90216e
2 changed files with 14 additions and 8 deletions

View File

@ -25,7 +25,7 @@
overlayClassName="header-notice-popover">
<template slot="content">
<a-spin :spinning="loading">
<a-list style="min-width: 200px">
<a-list style="min-width: 200px; max-width: 300px">
<a-list-item>
<a-list-item-meta title="Notifications">
<a-avatar :style="{backgroundColor: '#6887d0', verticalAlign: 'middle'}" icon="notification" slot="avatar"/>
@ -72,9 +72,8 @@ export default {
this.visible = !this.visible
},
clearJobs () {
this.visible = false
this.jobs = []
this.$store.commit('SET_ASYNC_JOB_IDS', [])
this.jobs = this.jobs.filter(x => x.status === 'progress')
this.$store.commit('SET_ASYNC_JOB_IDS', this.jobs)
},
startPolling () {
this.poller = setInterval(() => {

View File

@ -694,7 +694,7 @@ export default {
}).then(function () {
})
},
pollActionCompletion (jobId, action) {
pollActionCompletion (jobId, action, resourceName) {
this.$pollJob({
jobId,
successMethod: result => {
@ -711,7 +711,7 @@ export default {
}
},
errorMethod: () => this.fetchData(),
loadingMessage: `${this.$t(action.label)} in progress for ${this.resource.name}`,
loadingMessage: `${this.$t(action.label)} in progress for ${resourceName}`,
catchMessage: 'Error encountered while fetching async job result',
action
})
@ -791,16 +791,23 @@ export default {
console.log(this.resource)
console.log(params)
const resourceName = params.displayname || params.displaytext || params.name || params.hostname || params.username || params.ipaddress || params.virtualmachinename || this.resource.name
var hasJobId = false
api(this.currentAction.api, params).then(json => {
for (const obj in json) {
if (obj.includes('response')) {
for (const res in json[obj]) {
if (res === 'jobid') {
this.$store.dispatch('AddAsyncJob', { title: this.$t(this.currentAction.label), jobid: json[obj][res], description: this.resource.name, status: 'progress' })
this.pollActionCompletion(json[obj][res], this.currentAction)
this.$store.dispatch('AddAsyncJob', { title: this.$t(this.currentAction.label), jobid: json[obj][res], description: resourceName, status: 'progress' })
this.pollActionCompletion(json[obj][res], this.currentAction, resourceName)
hasJobId = true
break
} else {
this.$notification.success({
message: this.$t(this.currentAction.label),
description: resourceName
})
}
}
break