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
This commit is contained in:
Pearl Dsilva 2025-03-03 12:19:44 -05:00 committed by GitHub
parent 217e534446
commit a9fbc6b056
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 63 additions and 71 deletions

View File

@ -258,25 +258,8 @@ export default {
((record.type === 'ROOT' && record.vmstate === 'Stopped') || ((record.type === 'ROOT' && record.vmstate === 'Stopped') ||
(record.type !== 'ROOT' && !record.virtualmachineid && !['Allocated', 'Uploaded'].includes(record.state))) (record.type !== 'ROOT' && !record.virtualmachineid && !['Allocated', 'Uploaded'].includes(record.state)))
}, },
args: (record, store) => { popup: true,
var fields = ['volumeid', 'name', 'displaytext', 'ostypeid', 'isdynamicallyscalable', 'requireshvm', 'passwordenabled'] component: shallowRef(defineAsyncComponent(() => import('@/views/storage/CreateTemplate.vue')))
if (['Admin', 'DomainAdmin'].includes(store.userInfo.roletype)) {
fields.push('domainid')
fields.push('account')
}
if (['Admin'].includes(store.userInfo.roletype) || store.features.userpublictemplateenabled) {
fields.push('ispublic')
}
if (['Admin'].includes(store.userInfo.roletype)) {
fields.push('isfeatured')
}
return fields
},
mapping: {
volumeid: {
value: (record) => { return record.id }
}
}
}, },
{ {
api: 'recoverVolume', api: 'recoverVolume',

View File

@ -43,7 +43,7 @@
v-model:value="form.displaytext" v-model:value="form.displaytext"
:placeholder="apiParams.displaytext.description" /> :placeholder="apiParams.displaytext.description" />
</a-form-item> </a-form-item>
<a-form-item ref="zoneid" name="zoneid"> <a-form-item v-if="resource.intervaltype" ref="zoneid" name="zoneid">
<template #label> <template #label>
<tooltip-label :title="$t('label.zoneid')" :tooltip="apiParams.zoneid.description"/> <tooltip-label :title="$t('label.zoneid')" :tooltip="apiParams.zoneid.description"/>
</template> </template>
@ -130,40 +130,39 @@
</a-select> </a-select>
</a-form-item> </a-form-item>
<a-row :gutter="12"> <a-row :gutter="12">
<a-col :md="24" :lg="24"> <a-col :md="24" :lg="12">
<a-form-item ref="groupenabled" name="groupenabled"> <a-form-item ref="isdynamicallyscalable" name="isdynamicallyscalable">
<a-checkbox-group <template #label>
v-model:value="form.groupenabled" <tooltip-label :title="$t('label.isdynamicallyscalable')" :tooltip="apiParams.isdynamicallyscalable.description"/>
style="width: 100%;" </template>
> <a-switch v-model:checked="form.isdynamicallyscalable" />
<a-row> </a-form-item>
<a-col :span="12"> <a-form-item ref="requireshvm" name="requireshvm">
<a-checkbox value="passwordenabled"> <template #label>
{{ $t('label.passwordenabled') }} <tooltip-label :title="$t('label.requireshvm')" :tooltip="apiParams.requireshvm.description"/>
</a-checkbox> </template>
</a-col> <a-switch v-model:checked="form.requireshvm" />
<a-col :span="12"> </a-form-item>
<a-checkbox value="isdynamicallyscalable"> <a-form-item ref="passwordenabled" name="passwordenabled">
{{ $t('label.isdynamicallyscalable') }} <template #label>
</a-checkbox> <tooltip-label :title="$t('label.passwordenabled')" :tooltip="apiParams.passwordenabled.description"/>
</a-col> </template>
<a-col :span="12"> <a-switch v-model:checked="form.passwordenabled" />
<a-checkbox value="requireshvm"> </a-form-item>
{{ $t('label.requireshvm') }} <a-form-item
</a-checkbox> ref="ispublic"
</a-col> name="ispublic"
<a-col :span="12" v-if="isAdminRole"> v-if="$store.getters.userInfo.roletype === 'Admin' || $store.getters.features.userpublictemplateenabled" >
<a-checkbox value="isfeatured"> <template #label>
{{ $t('label.isfeatured') }} <tooltip-label :title="$t('label.ispublic')" :tooltip="apiParams.ispublic.description"/>
</a-checkbox> </template>
</a-col> <a-switch v-model:checked="form.ispublic" />
<a-col :span="12" v-if="isAdminRole || $store.getters.features.userpublictemplateenabled"> </a-form-item>
<a-checkbox value="ispublic"> <a-form-item ref="isfeatured" name="isfeatured" v-if="$store.getters.userInfo.roletype === 'Admin'">
{{ $t('label.ispublic') }} <template #label>
</a-checkbox> <tooltip-label :title="$t('label.isfeatured')" :tooltip="apiParams.isfeatured.description"/>
</a-col> </template>
</a-row> <a-switch v-model:checked="form.isfeatured" />
</a-checkbox-group>
</a-form-item> </a-form-item>
</a-col> </a-col>
</a-row> </a-row>
@ -234,7 +233,9 @@ export default {
}, },
fetchData () { fetchData () {
this.fetchOsTypes() this.fetchOsTypes()
if (this.resource.intervaltype) {
this.fetchSnapshotZones() this.fetchSnapshotZones()
}
if ('listDomains' in this.$store.getters.apis) { if ('listDomains' in this.$store.getters.apis) {
this.fetchDomains() this.fetchDomains()
} }
@ -300,22 +301,25 @@ export default {
this.handleDomainChange(null) this.handleDomainChange(null)
}) })
}, },
handleDomainChange (domain) { async handleDomainChange (domain) {
this.domainid = domain this.domainid = domain
this.form.account = null this.form.account = null
this.account = null this.account = null
if ('listAccounts' in this.$store.getters.apis) { if ('listAccounts' in this.$store.getters.apis) {
this.fetchAccounts() await this.fetchAccounts()
} }
}, },
fetchAccounts () { fetchAccounts () {
return new Promise((resolve, reject) => {
api('listAccounts', { api('listAccounts', {
domainid: this.domainid domainid: this.domainid
}).then(response => { }).then(response => {
this.accounts = response.listaccountsresponse.account || [] this.accounts = response?.listaccountsresponse?.account || []
resolve(this.accounts)
}).catch(error => { }).catch(error => {
this.$notifyError(error) this.$notifyError(error)
}) })
})
}, },
handleAccountChange (acc) { handleAccountChange (acc) {
if (acc) { if (acc) {
@ -329,17 +333,22 @@ export default {
this.formRef.value.validate().then(() => { this.formRef.value.validate().then(() => {
const formRaw = toRaw(this.form) const formRaw = toRaw(this.form)
const values = this.handleRemoveFields(formRaw) const values = this.handleRemoveFields(formRaw)
values.snapshotid = this.resource.id const params = {}
if (values.groupenabled) { if (this.resource.intervaltype) {
const input = values.groupenabled params.snapshotid = this.resource.id
for (const index in input) { } else {
const name = input[index] params.volumeid = this.resource.id
values[name] = true
} }
delete values.groupenabled
for (const key in values) {
const input = values[key]
if (input === undefined) {
continue
}
params[key] = input
} }
this.loading = true this.loading = true
api('createTemplate', values).then(response => { api('createTemplate', params).then(response => {
this.$pollJob({ this.$pollJob({
jobId: response.createtemplateresponse.jobid, jobId: response.createtemplateresponse.jobid,
title: this.$t('message.success.create.template'), title: this.$t('message.success.create.template'),