UI: Add router links to notifications and show error description (#5402)

This commit is contained in:
Pearl Dsilva 2021-09-07 09:26:12 +05:30 committed by GitHub
parent d1db7f4b7b
commit ff4b49bdb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 27 deletions

View File

@ -33,11 +33,12 @@
</a-list-item-meta>
</a-list-item>
<a-list-item v-for="(notice, index) in notices" :key="index">
<a-list-item-meta :title="notice.title" :description="notice.description">
<div slot="title"> {{ notice.path }} </div>
<a-list-item-meta :title="notice.title">
<a-avatar :style="notificationAvatar[notice.status].style" :icon="notificationAvatar[notice.status].icon" slot="avatar"/>
<span v-if="getResourceName(notice.description, 'name') && notice.path" slot="description"><router-link :to="{ path: notice.path}"> {{ getResourceName(notice.description, "name") + ' - ' }}</router-link></span>
<span v-if="getResourceName(notice.description, 'name') && notice.path" slot="description"> {{ getResourceName(notice.description, "msg") }}</span>
<span v-else slot="description"> {{ notice.description }} </span>
<span slot="description" v-if="getResourceName(notice.description, 'name') && notice.path"><router-link :to="{ path: notice.path}"> {{ getResourceName(notice.description, "name") + ' - ' }}</router-link></span>
<span slot="description" v-if="getResourceName(notice.description, 'name') && notice.path"> {{ getResourceName(notice.description, "msg") }}</span>
<span slot="description" v-else> {{ notice.description }} </span>
</a-list-item-meta>
</a-list-item>
</a-list>

View File

@ -40,6 +40,7 @@ export const pollJobPlugin = {
* @param {Function} [catchMethod=() => {}]
* @param {Object} [action=null]
* @param {Object} [bulkAction=false]
* @param {String} resourceId
*/
const {
jobId,
@ -55,7 +56,8 @@ export const pollJobPlugin = {
catchMessage = i18n.t('label.error.caught'),
catchMethod = () => {},
action = null,
bulkAction = false
bulkAction = false,
resourceId = null
} = options
store.dispatch('AddHeaderNotice', {
@ -65,9 +67,26 @@ export const pollJobPlugin = {
status: 'progress'
})
eventBus.$on('update-job-details', (jobId, resourceId) => {
const fullPath = this.$route.fullPath
const path = this.$route.path
var jobs = this.$store.getters.headerNotices.map(job => {
if (job.key === jobId) {
if (resourceId && !path.includes(resourceId)) {
job.path = path + '/' + resourceId
} else {
job.path = fullPath
}
}
return job
})
this.$store.commit('SET_HEADER_NOTICES', jobs)
})
options.originalPage = options.originalPage || this.$router.currentRoute.path
api('queryAsyncJobResult', { jobId }).then(json => {
const result = json.queryasyncjobresultresponse
eventBus.$emit('update-job-details', jobId, resourceId)
if (result.jobstatus === 1) {
var content = successMessage
if (successMessage === 'Success' && action && action.label) {
@ -88,7 +107,7 @@ export const pollJobPlugin = {
status: 'done',
duration: 2
})
eventBus.$emit('update-job-details', jobId, resourceId)
// Ensure we refresh on the same / parent page
const currentPage = this.$router.currentRoute.path
const samePage = options.originalPage === currentPage || options.originalPage.startsWith(currentPage + '/')
@ -123,11 +142,11 @@ export const pollJobPlugin = {
store.dispatch('AddHeaderNotice', {
key: jobId,
title: title,
description: description,
description: desc,
status: 'failed',
duration: 2
})
eventBus.$emit('update-job-details', jobId, resourceId)
// Ensure we refresh on the same / parent page
const currentPage = this.$router.currentRoute.path
const samePage = options.originalPage === currentPage || options.originalPage.startsWith(currentPage + '/')

View File

@ -500,21 +500,6 @@ export default {
})
}
})
eventBus.$on('update-job-details', (jobId, resourceId) => {
const fullPath = this.$route.fullPath
const path = this.$route.path
var jobs = this.$store.getters.headerNotices.map(job => {
if (job.jobid === jobId) {
if (resourceId && !path.includes(resourceId)) {
job.path = path + '/' + resourceId
} else {
job.path = fullPath
}
}
return job
})
this.$store.commit('SET_HEADER_NOTICES', jobs)
})
eventBus.$on('update-resource-state', (selectedItems, resource, state, jobid) => {
if (selectedItems.length === 0) {
@ -1064,7 +1049,8 @@ export default {
showLoading: showLoading,
catchMessage: this.$t('error.fetching.async.job.result'),
action,
bulkAction: `${this.selectedItems.length > 0}` && this.showGroupActionModal
bulkAction: `${this.selectedItems.length > 0}` && this.showGroupActionModal,
resourceId: resource
})
})
},

View File

@ -100,7 +100,6 @@
<script>
import { api } from '@/api'
import eventBus from '@/config/eventBus'
import TooltipLabel from '@/components/widgets/TooltipLabel'
export default {
@ -232,8 +231,6 @@ export default {
successMessage: `${this.$t('label.action.start.instance')} ${this.resource.name}`,
response: (result) => { return result.virtualmachine && result.virtualmachine.password ? `The password of VM <b>${result.virtualmachine.displayname}</b> is <b>${result.virtualmachine.password}</b>` : null }
})
const resourceId = this.resource.id
eventBus.$emit('update-job-details', jobId, resourceId)
this.closeAction()
}).catch(error => {
this.$notifyError(error)