notification: job messaging improvements

With this change, pollJob and notification widget will end up displaying
the same message (instead of notification). Notifications on right-top
side will only be shown in case of error or response (such as a password
or a download link etc).

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2020-05-31 06:26:45 +05:30
parent 13ca67b15e
commit a04c8db8b1
4 changed files with 37 additions and 18 deletions

View File

@ -88,9 +88,12 @@ export default {
var result = json.queryasyncjobresultresponse var result = json.queryasyncjobresultresponse
if (result.jobstatus === 1 && this.jobs[i].status !== 'done') { if (result.jobstatus === 1 && this.jobs[i].status !== 'done') {
hasUpdated = true hasUpdated = true
this.$notification.success({ const title = this.jobs[i].title
message: this.jobs[i].title, const description = this.jobs[i].description
description: this.jobs[i].description this.$message.success({
content: title + (description ? ' - ' + description : ''),
key: this.jobs[i].jobid,
duration: 2
}) })
this.jobs[i].status = 'done' this.jobs[i].status = 'done'
} else if (result.jobstatus === 2 && this.jobs[i].status !== 'failed') { } else if (result.jobstatus === 2 && this.jobs[i].status !== 'failed') {
@ -101,7 +104,8 @@ export default {
} }
this.$notification.error({ this.$notification.error({
message: this.jobs[i].title, message: this.jobs[i].title,
description: this.jobs[i].description description: this.jobs[i].description,
duration: 0
}) })
} }
}).catch(function (e) { }).catch(function (e) {

View File

@ -16,6 +16,7 @@
// under the License. // under the License.
import _ from 'lodash' import _ from 'lodash'
import i18n from '@/locales'
import { api } from '@/api' import { api } from '@/api'
import { message, notification } from 'ant-design-vue' import { message, notification } from 'ant-design-vue'
@ -25,6 +26,7 @@ export const pollJobPlugin = {
Vue.prototype.$pollJob = function (options) { Vue.prototype.$pollJob = function (options) {
/** /**
* @param {String} jobId * @param {String} jobId
* @param {String} [name='']
* @param {String} [successMessage=Success] * @param {String} [successMessage=Success]
* @param {Function} [successMethod=() => {}] * @param {Function} [successMethod=() => {}]
* @param {String} [errorMessage=Error] * @param {String} [errorMessage=Error]
@ -32,11 +34,11 @@ export const pollJobPlugin = {
* @param {String} [loadingMessage=Loading...] * @param {String} [loadingMessage=Loading...]
* @param {String} [catchMessage=Error caught] * @param {String} [catchMessage=Error caught]
* @param {Function} [catchMethod=() => {}] * @param {Function} [catchMethod=() => {}]
* @param {Number} [loadingDuration=3]
* @param {Object} [action=null] * @param {Object} [action=null]
*/ */
const { const {
jobId, jobId,
name = '',
successMessage = 'Success', successMessage = 'Success',
successMethod = () => {}, successMethod = () => {},
errorMessage = 'Error', errorMessage = 'Error',
@ -44,26 +46,41 @@ export const pollJobPlugin = {
loadingMessage = 'Loading...', loadingMessage = 'Loading...',
catchMessage = 'Error caught', catchMessage = 'Error caught',
catchMethod = () => {}, catchMethod = () => {},
loadingDuration = 3,
action = null action = null
} = options } = options
api('queryAsyncJobResult', { jobId }).then(json => { api('queryAsyncJobResult', { jobId }).then(json => {
const result = json.queryasyncjobresultresponse const result = json.queryasyncjobresultresponse
if (result.jobstatus === 1) { if (result.jobstatus === 1) {
message.success(successMessage) var content = successMessage
if (successMessage === 'Success' && action && action.label) {
content = i18n.t(action.label)
}
if (name) {
content = content + ' - ' + name
}
message.success({
content: content,
key: jobId,
duration: 2
})
successMethod(result) successMethod(result)
} else if (result.jobstatus === 2) { } else if (result.jobstatus === 2) {
notification.error({ notification.error({
message: errorMessage, message: errorMessage,
description: result.jobresult.errortext description: result.jobresult.errortext,
duration: 0
}) })
errorMethod(result) errorMethod(result)
} else if (result.jobstatus === 0) { } else if (result.jobstatus === 0) {
message message.loading({
.loading(loadingMessage, loadingDuration) content: loadingMessage,
.then(() => this.$pollJob(options, action)) key: jobId,
duration: 0
})
setTimeout(() => {
this.$pollJob(options, action)
}, 3000)
} }
}).catch(e => { }).catch(e => {
console.error(`${catchMessage} - ${e}`) console.error(`${catchMessage} - ${e}`)

View File

@ -17,8 +17,8 @@
import Vue from 'vue' import Vue from 'vue'
import axios from 'axios' import axios from 'axios'
import store from '@/store'
import config from '@/config/settings' import config from '@/config/settings'
import store from '@/store'
import { VueAxios } from './axios' import { VueAxios } from './axios'
import notification from 'ant-design-vue/es/notification' import notification from 'ant-design-vue/es/notification'
import { ACCESS_TOKEN, CURRENT_PROJECT } from '@/store/mutation-types' import { ACCESS_TOKEN, CURRENT_PROJECT } from '@/store/mutation-types'

View File

@ -701,6 +701,7 @@ export default {
pollActionCompletion (jobId, action, resourceName) { pollActionCompletion (jobId, action, resourceName) {
this.$pollJob({ this.$pollJob({
jobId, jobId,
name: resourceName,
successMethod: result => { successMethod: result => {
this.fetchData() this.fetchData()
if (action.response) { if (action.response) {
@ -715,7 +716,7 @@ export default {
} }
}, },
errorMethod: () => this.fetchData(), errorMethod: () => this.fetchData(),
loadingMessage: `${this.$t(action.label)} in progress for ${resourceName}`, loadingMessage: `${this.$t(action.label)} - ${resourceName}`,
catchMessage: 'Error encountered while fetching async job result', catchMessage: 'Error encountered while fetching async job result',
action action
}) })
@ -808,10 +809,7 @@ export default {
hasJobId = true hasJobId = true
break break
} else { } else {
this.$notification.success({ this.$message.success(this.$t(this.currentAction.label) + (resourceName ? ' - ' + resourceName : ''))
message: this.$t(this.currentAction.label),
description: resourceName
})
} }
} }
break break