Skip to content

Commit 170947e

Browse files
author
toni.zamparetti
committed
List accounts by domain or projects when importing a VM
1 parent a7c2a05 commit 170947e

1 file changed

Lines changed: 47 additions & 63 deletions

File tree

ui/src/views/tools/ImportUnmanagedInstance.vue

Lines changed: 47 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
:showIcon="true"
4141
:message="$t('message.import.running.instance.warning')"
4242
/>
43+
<div v-if="!isNormalUserOrProject">
44+
<ownership-selection @fetch-owner="fetchOwnerOptions" />
45+
</div>
4346
<a-form-item name="displayname" ref="displayname">
4447
<template #label>
4548
<tooltip-label :title="$t('label.displayname')" :tooltip="apiParams.displayname.description"/>
@@ -58,59 +61,6 @@
5861
v-model:value="form.hostname"
5962
:placeholder="apiParams.hostname.description" />
6063
</a-form-item>
61-
<a-form-item name="domainid" ref="domainid">
62-
<template #label>
63-
<tooltip-label :title="$t('label.domainid')" :tooltip="apiParams.domainid.description"/>
64-
</template>
65-
<a-select
66-
v-model:value="form.domainid"
67-
showSearch
68-
optionFilterProp="label"
69-
:filterOption="(input, option) => {
70-
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
71-
}"
72-
:loading="optionsLoading.domains"
73-
:placeholder="apiParams.domainid.description"
74-
@change="val => { this.selectedDomainId = val }">
75-
<a-select-option v-for="dom in domainSelectOptions" :key="dom.value" :label="dom.label">
76-
<span>
77-
<resource-icon v-if="dom.icon" :image="dom.icon" size="1x" style="margin-right: 5px"/>
78-
<block-outlined v-else-if="dom.value !== null" style="margin-right: 5px" />
79-
{{ dom.label }}
80-
</span>
81-
</a-select-option>
82-
</a-select>
83-
</a-form-item>
84-
<a-form-item name="account" ref="account" v-if="selectedDomainId">
85-
<template #label>
86-
<tooltip-label :title="$t('label.account')" :tooltip="apiParams.account.description"/>
87-
</template>
88-
<a-input
89-
v-model:value="form.account"
90-
:placeholder="apiParams.account.description"/>
91-
</a-form-item>
92-
<a-form-item name="projectid" ref="projectid">
93-
<template #label>
94-
<tooltip-label :title="$t('label.project')" :tooltip="apiParams.projectid.description"/>
95-
</template>
96-
<a-select
97-
v-model:value="form.projectid"
98-
showSearch
99-
optionFilterProp="label"
100-
:filterOption="(input, option) => {
101-
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
102-
}"
103-
:loading="optionsLoading.projects"
104-
:placeholder="apiParams.projectid.description">
105-
<a-select-option v-for="proj in projectSelectOptions" :key="proj.value" :label="proj.label">
106-
<span>
107-
<resource-icon v-if="proj.icon" :image="proj.icon" size="1x" style="margin-right: 5px"/>
108-
<project-outlined v-else-if="proj.value !== null" style="margin-right: 5px" />
109-
{{ proj.label }}
110-
</span>
111-
</a-select-option>
112-
</a-select>
113-
</a-form-item>
11464
<a-form-item name="templateid" ref="templateid" v-if="cluster.hypervisortype === 'VMware' || (cluster.hypervisortype === 'KVM' && !selectedVmwareVcenter && !isDiskImport && !isExternalImport)">
11565
<template #label>
11666
<tooltip-label :title="$t('label.templatename')" :tooltip="apiParams.templateid.description + '. ' + $t('message.template.import.vm.temporary')"/>
@@ -315,8 +265,8 @@
315265
<multi-network-selection
316266
:items="nics"
317267
:zoneId="cluster.zoneid"
318-
:domainid="form.domainid"
319-
:account="form.account"
268+
:domainid="this.owner.domainid"
269+
:accountid="this.owner.account"
320270
:selectionEnabled="false"
321271
:filterUnimplementedNetworks="true"
322272
:hypervisor="this.cluster.hypervisortype"
@@ -391,17 +341,20 @@ import { api } from '@/api'
391341
import _ from 'lodash'
392342
import InfoCard from '@/components/view/InfoCard'
393343
import TooltipLabel from '@/components/widgets/TooltipLabel'
344+
import OwnershipSelection from '@/views/compute/wizard/OwnershipSelection.vue'
394345
import ComputeOfferingSelection from '@views/compute/wizard/ComputeOfferingSelection'
395346
import ComputeSelection from '@views/compute/wizard/ComputeSelection'
396347
import MultiDiskSelection from '@views/compute/wizard/MultiDiskSelection'
397348
import MultiNetworkSelection from '@views/compute/wizard/MultiNetworkSelection'
398349
import OsLogo from '@/components/widgets/OsLogo'
399350
import ResourceIcon from '@/components/view/ResourceIcon'
400351
import CheckBoxSelectPair from '@/components/CheckBoxSelectPair'
352+
import store from '@/store'
401353
402354
export default {
403355
name: 'ImportUnmanagedInstances',
404356
components: {
357+
OwnershipSelection,
405358
InfoCard,
406359
TooltipLabel,
407360
ComputeOfferingSelection,
@@ -472,22 +425,20 @@ export default {
472425
},
473426
data () {
474427
return {
428+
owner: {
429+
projectid: store.getters.project?.id,
430+
domainid: store.getters.project?.id ? null : store.getters.userInfo.domainid,
431+
account: store.getters.project?.id ? null : store.getters.userInfo.account
432+
},
475433
options: {
476-
domains: [],
477-
projects: [],
478434
networks: [],
479435
templates: []
480436
},
481437
rowCount: {},
482438
optionsLoading: {
483-
domains: false,
484-
projects: false,
485439
networks: false,
486440
templates: false
487441
},
488-
domains: [],
489-
domainLoading: false,
490-
selectedDomainId: null,
491442
templates: [],
492443
templateLoading: false,
493444
templateType: this.defaultTemplateType(),
@@ -588,9 +539,20 @@ export default {
588539
showicon: true
589540
},
590541
field: 'templateid'
542+
},
543+
accounts: {
544+
list: 'listAccounts',
545+
isLoad: true,
546+
options: {
547+
domainid: this.domainid
548+
},
549+
field: 'accountid'
591550
}
592551
}
593552
},
553+
isNormalUserOrProject () {
554+
return ['User'].includes(this.$store.getters.userInfo.roletype) || store.getters.project?.id
555+
},
594556
isVmRunning () {
595557
if (this.resource && this.resource.powerstate === 'PowerOn') {
596558
return true
@@ -724,14 +686,30 @@ export default {
724686
forced: this.switches.forced,
725687
forcemstoimportvmfiles: this.switches.forceMsToImportVmFiles,
726688
domainid: null,
727-
account: null
689+
accountid: null
728690
})
729691
this.rules = reactive({
730692
displayname: [{ required: true, message: this.$t('message.error.input.value') }],
731693
templateid: [{ required: this.templateType !== 'auto', message: this.$t('message.error.input.value') }],
732694
rootdiskid: [{ required: this.templateType !== 'auto', message: this.$t('message.error.input.value') }]
733695
})
734696
},
697+
fetchOwnerOptions (OwnerOptions) {
698+
this.owner = {}
699+
if (OwnerOptions.selectedAccountType === 'Account') {
700+
if (!OwnerOptions.selectedAccount) {
701+
return
702+
}
703+
this.owner.account = OwnerOptions.selectedAccount
704+
this.owner.domainid = OwnerOptions.selectedDomain
705+
} else if (OwnerOptions.selectedAccountType === 'Project') {
706+
if (!OwnerOptions.selectedProject) {
707+
return
708+
}
709+
this.owner.projectid = OwnerOptions.selectedProject
710+
}
711+
this.fetchData()
712+
},
735713
fetchData () {
736714
_.each(this.params, (param, name) => {
737715
if (param.isLoad) {
@@ -1068,6 +1046,12 @@ export default {
10681046
diskpath: this.diskpath,
10691047
temppath: this.tmppath
10701048
}
1049+
values.domainid = this.owner.domainid
1050+
if (this.owner.projectid) {
1051+
values.projectid = this.owner.projectid
1052+
} else {
1053+
values.account = this.owner.account
1054+
}
10711055
var importapi = 'importUnmanagedInstance'
10721056
if (this.isExternalImport || this.isDiskImport || this.selectedVmwareVcenter) {
10731057
importapi = 'importVm'

0 commit comments

Comments
 (0)