Skip to content

Commit a9fbc6b

Browse files
authored
UI: Filter accounts by domain while creating templates - from Volume / Snapshot (#10455)
* UI: Filter accounts by domain while creating templates - from Volume / Snapshot * use optional chaining
1 parent 217e534 commit a9fbc6b

File tree

2 files changed

+63
-71
lines changed

2 files changed

+63
-71
lines changed

ui/src/config/section/storage.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -258,25 +258,8 @@ export default {
258258
((record.type === 'ROOT' && record.vmstate === 'Stopped') ||
259259
(record.type !== 'ROOT' && !record.virtualmachineid && !['Allocated', 'Uploaded'].includes(record.state)))
260260
},
261-
args: (record, store) => {
262-
var fields = ['volumeid', 'name', 'displaytext', 'ostypeid', 'isdynamicallyscalable', 'requireshvm', 'passwordenabled']
263-
if (['Admin', 'DomainAdmin'].includes(store.userInfo.roletype)) {
264-
fields.push('domainid')
265-
fields.push('account')
266-
}
267-
if (['Admin'].includes(store.userInfo.roletype) || store.features.userpublictemplateenabled) {
268-
fields.push('ispublic')
269-
}
270-
if (['Admin'].includes(store.userInfo.roletype)) {
271-
fields.push('isfeatured')
272-
}
273-
return fields
274-
},
275-
mapping: {
276-
volumeid: {
277-
value: (record) => { return record.id }
278-
}
279-
}
261+
popup: true,
262+
component: shallowRef(defineAsyncComponent(() => import('@/views/storage/CreateTemplate.vue')))
280263
},
281264
{
282265
api: 'recoverVolume',

ui/src/views/storage/CreateTemplate.vue

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
v-model:value="form.displaytext"
4444
:placeholder="apiParams.displaytext.description" />
4545
</a-form-item>
46-
<a-form-item ref="zoneid" name="zoneid">
46+
<a-form-item v-if="resource.intervaltype" ref="zoneid" name="zoneid">
4747
<template #label>
4848
<tooltip-label :title="$t('label.zoneid')" :tooltip="apiParams.zoneid.description"/>
4949
</template>
@@ -130,41 +130,40 @@
130130
</a-select>
131131
</a-form-item>
132132
<a-row :gutter="12">
133-
<a-col :md="24" :lg="24">
134-
<a-form-item ref="groupenabled" name="groupenabled">
135-
<a-checkbox-group
136-
v-model:value="form.groupenabled"
137-
style="width: 100%;"
138-
>
139-
<a-row>
140-
<a-col :span="12">
141-
<a-checkbox value="passwordenabled">
142-
{{ $t('label.passwordenabled') }}
143-
</a-checkbox>
144-
</a-col>
145-
<a-col :span="12">
146-
<a-checkbox value="isdynamicallyscalable">
147-
{{ $t('label.isdynamicallyscalable') }}
148-
</a-checkbox>
149-
</a-col>
150-
<a-col :span="12">
151-
<a-checkbox value="requireshvm">
152-
{{ $t('label.requireshvm') }}
153-
</a-checkbox>
154-
</a-col>
155-
<a-col :span="12" v-if="isAdminRole">
156-
<a-checkbox value="isfeatured">
157-
{{ $t('label.isfeatured') }}
158-
</a-checkbox>
159-
</a-col>
160-
<a-col :span="12" v-if="isAdminRole || $store.getters.features.userpublictemplateenabled">
161-
<a-checkbox value="ispublic">
162-
{{ $t('label.ispublic') }}
163-
</a-checkbox>
164-
</a-col>
165-
</a-row>
166-
</a-checkbox-group>
133+
<a-col :md="24" :lg="12">
134+
<a-form-item ref="isdynamicallyscalable" name="isdynamicallyscalable">
135+
<template #label>
136+
<tooltip-label :title="$t('label.isdynamicallyscalable')" :tooltip="apiParams.isdynamicallyscalable.description"/>
137+
</template>
138+
<a-switch v-model:checked="form.isdynamicallyscalable" />
167139
</a-form-item>
140+
<a-form-item ref="requireshvm" name="requireshvm">
141+
<template #label>
142+
<tooltip-label :title="$t('label.requireshvm')" :tooltip="apiParams.requireshvm.description"/>
143+
</template>
144+
<a-switch v-model:checked="form.requireshvm" />
145+
</a-form-item>
146+
<a-form-item ref="passwordenabled" name="passwordenabled">
147+
<template #label>
148+
<tooltip-label :title="$t('label.passwordenabled')" :tooltip="apiParams.passwordenabled.description"/>
149+
</template>
150+
<a-switch v-model:checked="form.passwordenabled" />
151+
</a-form-item>
152+
<a-form-item
153+
ref="ispublic"
154+
name="ispublic"
155+
v-if="$store.getters.userInfo.roletype === 'Admin' || $store.getters.features.userpublictemplateenabled" >
156+
<template #label>
157+
<tooltip-label :title="$t('label.ispublic')" :tooltip="apiParams.ispublic.description"/>
158+
</template>
159+
<a-switch v-model:checked="form.ispublic" />
160+
</a-form-item>
161+
<a-form-item ref="isfeatured" name="isfeatured" v-if="$store.getters.userInfo.roletype === 'Admin'">
162+
<template #label>
163+
<tooltip-label :title="$t('label.isfeatured')" :tooltip="apiParams.isfeatured.description"/>
164+
</template>
165+
<a-switch v-model:checked="form.isfeatured" />
166+
</a-form-item>
168167
</a-col>
169168
</a-row>
170169
<div :span="24" class="action-button">
@@ -234,7 +233,9 @@ export default {
234233
},
235234
fetchData () {
236235
this.fetchOsTypes()
237-
this.fetchSnapshotZones()
236+
if (this.resource.intervaltype) {
237+
this.fetchSnapshotZones()
238+
}
238239
if ('listDomains' in this.$store.getters.apis) {
239240
this.fetchDomains()
240241
}
@@ -300,21 +301,24 @@ export default {
300301
this.handleDomainChange(null)
301302
})
302303
},
303-
handleDomainChange (domain) {
304+
async handleDomainChange (domain) {
304305
this.domainid = domain
305306
this.form.account = null
306307
this.account = null
307308
if ('listAccounts' in this.$store.getters.apis) {
308-
this.fetchAccounts()
309+
await this.fetchAccounts()
309310
}
310311
},
311312
fetchAccounts () {
312-
api('listAccounts', {
313-
domainid: this.domainid
314-
}).then(response => {
315-
this.accounts = response.listaccountsresponse.account || []
316-
}).catch(error => {
317-
this.$notifyError(error)
313+
return new Promise((resolve, reject) => {
314+
api('listAccounts', {
315+
domainid: this.domainid
316+
}).then(response => {
317+
this.accounts = response?.listaccountsresponse?.account || []
318+
resolve(this.accounts)
319+
}).catch(error => {
320+
this.$notifyError(error)
321+
})
318322
})
319323
},
320324
handleAccountChange (acc) {
@@ -329,17 +333,22 @@ export default {
329333
this.formRef.value.validate().then(() => {
330334
const formRaw = toRaw(this.form)
331335
const values = this.handleRemoveFields(formRaw)
332-
values.snapshotid = this.resource.id
333-
if (values.groupenabled) {
334-
const input = values.groupenabled
335-
for (const index in input) {
336-
const name = input[index]
337-
values[name] = true
336+
const params = {}
337+
if (this.resource.intervaltype) {
338+
params.snapshotid = this.resource.id
339+
} else {
340+
params.volumeid = this.resource.id
341+
}
342+
343+
for (const key in values) {
344+
const input = values[key]
345+
if (input === undefined) {
346+
continue
338347
}
339-
delete values.groupenabled
348+
params[key] = input
340349
}
341350
this.loading = true
342-
api('createTemplate', values).then(response => {
351+
api('createTemplate', params).then(response => {
343352
this.$pollJob({
344353
jobId: response.createtemplateresponse.jobid,
345354
title: this.$t('message.success.create.template'),

0 commit comments

Comments
 (0)