Skip to content

Commit cf382d4

Browse files
committed
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 <rohit.yadav@shapeblue.com>
1 parent cd49ac6 commit cf382d4

File tree

5 files changed

+49
-22
lines changed

5 files changed

+49
-22
lines changed

ui/src/config/section/compute.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export default {
8181
dataView: true,
8282
groupAction: true,
8383
show: (record) => { return ['Stopped'].includes(record.state) },
84-
args: ['podid', 'clusterid', 'hostid']
84+
args: ['podid', 'clusterid', 'hostid'],
85+
response: (result) => { return result.virtualmachine && result.virtualmachine.password ? `Password of the VM is ${result.virtualmachine.password}` : null }
8586
},
8687
{
8788
api: 'stopVirtualMachine',
@@ -214,7 +215,8 @@ export default {
214215
icon: 'key',
215216
label: 'Reset Instance Password',
216217
dataView: true,
217-
show: (record) => { return ['Stopped'].includes(record.state) }
218+
show: (record) => { return ['Stopped'].includes(record.state) },
219+
response: (result) => { return result.virtualmachine && result.virtualmachine.password ? `Password of the VM is ${result.virtualmachine.password}` : null }
218220
},
219221
{
220222
api: 'resetSSHKeyForVirtualMachine',

ui/src/config/section/image.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,17 @@ export default {
7272
icon: 'cloud-download',
7373
label: 'Download Template',
7474
dataView: true,
75-
args: ['zoneid', 'mode']
75+
show: (record) => { return record && record.isextractable },
76+
args: ['zoneid', 'mode'],
77+
mapping: {
78+
zoneid: {
79+
value: (record) => { return record.zoneid }
80+
},
81+
mode: {
82+
value: (record) => { return 'HTTP_DOWNLOAD' }
83+
}
84+
},
85+
response: (result) => { return `Please click <a href="${result.template.url}" target="_blank">${result.template.url}</a> to download.` }
7686
},
7787
{
7888
api: 'updateTemplatePermissions',
@@ -140,12 +150,17 @@ export default {
140150
icon: 'cloud-download',
141151
label: 'Download ISO',
142152
dataView: true,
153+
show: (record) => { return record && record.isextractable },
143154
args: ['zoneid', 'mode'],
144155
mapping: {
156+
zoneid: {
157+
value: (record) => { return record.zoneid }
158+
},
145159
mode: {
146160
value: (record) => { return 'HTTP_DOWNLOAD' }
147161
}
148-
}
162+
},
163+
response: (result) => { return `Please click <a href="${result.iso.url}" target="_blank">${result.iso.url}</a> to download.` }
149164
},
150165
{
151166
api: 'updateIsoPermissions',

ui/src/config/section/storage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export default {
133133
icon: 'cloud-download',
134134
label: 'Download Volume',
135135
dataView: true,
136+
show: (record) => { return record && record.state === 'Ready' },
136137
args: ['zoneid', 'mode'],
137138
mapping: {
138139
zoneid: {
@@ -141,7 +142,8 @@ export default {
141142
mode: {
142143
value: (record) => { return 'HTTP_DOWNLOAD' }
143144
}
144-
}
145+
},
146+
response: (result) => { return `Please click <a href="${result.volume.url}" target="_blank">${result.volume.url}</a> to download.` }
145147
},
146148
{
147149
api: 'createTemplate',

ui/src/utils/plugins.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const pollJobPlugin = {
3232
* @param {String} [catchMessage=Error caught]
3333
* @param {Function} [catchMethod=() => {}]
3434
* @param {Number} [loadingDuration=3]
35+
* @param {Object} [action=null]
3536
*/
3637
const {
3738
jobId,
@@ -42,25 +43,26 @@ export const pollJobPlugin = {
4243
loadingMessage = 'Loading...',
4344
catchMessage = 'Error caught',
4445
catchMethod = () => {},
45-
loadingDuration = 3
46+
loadingDuration = 3,
47+
action = null
4648
} = options
4749

4850
api('queryAsyncJobResult', { jobId }).then(json => {
4951
const result = json.queryasyncjobresultresponse
5052

5153
if (result.jobstatus === 1) {
5254
message.success(successMessage)
53-
successMethod()
55+
successMethod(result)
5456
} else if (result.jobstatus === 2) {
5557
notification.error({
5658
message: errorMessage,
5759
description: result.jobresult.errortext
5860
})
59-
errorMethod()
61+
errorMethod(result)
6062
} else if (result.jobstatus === 0) {
6163
message
6264
.loading(loadingMessage, loadingDuration)
63-
.then(() => this.$pollJob(options))
65+
.then(() => this.$pollJob(options, action))
6466
}
6567
}).catch(e => {
6668
console.error(`${catchMessage} - ${e}`)

ui/src/views/AutogenView.vue

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
<script>
244244
import { api } from '@/api'
245245
import { mixinDevice } from '@/utils/mixin.js'
246+
import { genericCompare } from '@/utils/sort.js'
246247
import config from '@/config/settings'
247248
import store from '@/store'
248249
@@ -252,7 +253,6 @@ import Status from '@/components/widgets/Status'
252253
import ListView from '@/components/view/ListView'
253254
import ResourceView from '@/components/view/ResourceView'
254255
import TreeView from '@/components/view/TreeView'
255-
import { genericCompare } from '@/utils/sort.js'
256256
257257
export default {
258258
name: 'Resource',
@@ -577,19 +577,25 @@ export default {
577577
})
578578
},
579579
pollActionCompletion (jobId, action) {
580-
api('queryAsyncJobResult', { jobid: jobId }).then(json => {
581-
var result = json.queryasyncjobresultresponse
582-
if (result.jobstatus === 1) {
583-
this.fetchData()
584-
} else if (result.jobstatus === 2) {
580+
this.$pollJob({
581+
jobId,
582+
successMethod: result => {
585583
this.fetchData()
586-
} else if (result.jobstatus === 0) {
587-
this.$message
588-
.loading(this.$t(action.label) + ' in progress for ' + this.resource.name, 3)
589-
.then(() => this.pollActionCompletion(jobId, action))
590-
}
591-
}).catch(function (e) {
592-
console.log('Error encountered while fetching async job result' + e)
584+
if (action.response) {
585+
const description = action.response(result.jobresult)
586+
if (description) {
587+
this.$notification.info({
588+
message: action.label,
589+
description: (<span domPropsInnerHTML={description}></span>),
590+
duration: 0
591+
})
592+
}
593+
}
594+
},
595+
errorMethod: () => this.fetchData(),
596+
loadingMessage: `${this.$t(action.label)} in progress for ${this.resource.name}`,
597+
catchMessage: 'Error encountered while fetching async job result',
598+
action
593599
})
594600
},
595601
handleSubmit (e) {

0 commit comments

Comments
 (0)