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.virtualmachineid && !['Allocated', 'Uploaded'].includes(record.state)))
},
args: (record, store) => {
var fields = ['volumeid', 'name', 'displaytext', 'ostypeid', 'isdynamicallyscalable', 'requireshvm', 'passwordenabled']
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 }
}
}
popup: true,
component: shallowRef(defineAsyncComponent(() => import('@/views/storage/CreateTemplate.vue')))
},
{
api: 'recoverVolume',

View File

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