From cf382d4b5a996f8cf78d0da6b8958693e649204a Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Fri, 20 Dec 2019 05:29:56 +0530 Subject: [PATCH] autogen: implement action response handler notification framework This fixes #35 This fixes #51 This closes #78 This adds the following: - Download iso, template, volume handler to show link - Show VM password on VM start and upon reset password action Signed-off-by: Rohit Yadav --- ui/src/config/section/compute.js | 6 ++++-- ui/src/config/section/image.js | 19 +++++++++++++++++-- ui/src/config/section/storage.js | 4 +++- ui/src/utils/plugins.js | 10 ++++++---- ui/src/views/AutogenView.vue | 32 +++++++++++++++++++------------- 5 files changed, 49 insertions(+), 22 deletions(-) diff --git a/ui/src/config/section/compute.js b/ui/src/config/section/compute.js index 0fcd458f5b9..4af84c7a28d 100644 --- a/ui/src/config/section/compute.js +++ b/ui/src/config/section/compute.js @@ -81,7 +81,8 @@ export default { dataView: true, groupAction: true, show: (record) => { return ['Stopped'].includes(record.state) }, - args: ['podid', 'clusterid', 'hostid'] + args: ['podid', 'clusterid', 'hostid'], + response: (result) => { return result.virtualmachine && result.virtualmachine.password ? `Password of the VM is ${result.virtualmachine.password}` : null } }, { api: 'stopVirtualMachine', @@ -214,7 +215,8 @@ export default { icon: 'key', label: 'Reset Instance Password', dataView: true, - show: (record) => { return ['Stopped'].includes(record.state) } + show: (record) => { return ['Stopped'].includes(record.state) }, + response: (result) => { return result.virtualmachine && result.virtualmachine.password ? `Password of the VM is ${result.virtualmachine.password}` : null } }, { api: 'resetSSHKeyForVirtualMachine', diff --git a/ui/src/config/section/image.js b/ui/src/config/section/image.js index e00de65109b..f4005ea93e9 100644 --- a/ui/src/config/section/image.js +++ b/ui/src/config/section/image.js @@ -72,7 +72,17 @@ export default { icon: 'cloud-download', label: 'Download Template', dataView: true, - args: ['zoneid', 'mode'] + show: (record) => { return record && record.isextractable }, + args: ['zoneid', 'mode'], + mapping: { + zoneid: { + value: (record) => { return record.zoneid } + }, + mode: { + value: (record) => { return 'HTTP_DOWNLOAD' } + } + }, + response: (result) => { return `Please click ${result.template.url} to download.` } }, { api: 'updateTemplatePermissions', @@ -140,12 +150,17 @@ export default { icon: 'cloud-download', label: 'Download ISO', dataView: true, + show: (record) => { return record && record.isextractable }, args: ['zoneid', 'mode'], mapping: { + zoneid: { + value: (record) => { return record.zoneid } + }, mode: { value: (record) => { return 'HTTP_DOWNLOAD' } } - } + }, + response: (result) => { return `Please click ${result.iso.url} to download.` } }, { api: 'updateIsoPermissions', diff --git a/ui/src/config/section/storage.js b/ui/src/config/section/storage.js index 51e83832e28..22b1bd6b1c0 100644 --- a/ui/src/config/section/storage.js +++ b/ui/src/config/section/storage.js @@ -133,6 +133,7 @@ export default { icon: 'cloud-download', label: 'Download Volume', dataView: true, + show: (record) => { return record && record.state === 'Ready' }, args: ['zoneid', 'mode'], mapping: { zoneid: { @@ -141,7 +142,8 @@ export default { mode: { value: (record) => { return 'HTTP_DOWNLOAD' } } - } + }, + response: (result) => { return `Please click ${result.volume.url} to download.` } }, { api: 'createTemplate', diff --git a/ui/src/utils/plugins.js b/ui/src/utils/plugins.js index 020491601f6..c0081e02c63 100644 --- a/ui/src/utils/plugins.js +++ b/ui/src/utils/plugins.js @@ -32,6 +32,7 @@ export const pollJobPlugin = { * @param {String} [catchMessage=Error caught] * @param {Function} [catchMethod=() => {}] * @param {Number} [loadingDuration=3] + * @param {Object} [action=null] */ const { jobId, @@ -42,7 +43,8 @@ export const pollJobPlugin = { loadingMessage = 'Loading...', catchMessage = 'Error caught', catchMethod = () => {}, - loadingDuration = 3 + loadingDuration = 3, + action = null } = options api('queryAsyncJobResult', { jobId }).then(json => { @@ -50,17 +52,17 @@ export const pollJobPlugin = { if (result.jobstatus === 1) { message.success(successMessage) - successMethod() + successMethod(result) } else if (result.jobstatus === 2) { notification.error({ message: errorMessage, description: result.jobresult.errortext }) - errorMethod() + errorMethod(result) } else if (result.jobstatus === 0) { message .loading(loadingMessage, loadingDuration) - .then(() => this.$pollJob(options)) + .then(() => this.$pollJob(options, action)) } }).catch(e => { console.error(`${catchMessage} - ${e}`) diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue index 1a2f551ac26..f18459f814a 100644 --- a/ui/src/views/AutogenView.vue +++ b/ui/src/views/AutogenView.vue @@ -243,6 +243,7 @@