Skip to content

Commit 6282083

Browse files
author
Fabrício Duarte
committed
Merge branch 'search-accounts-to-import-vms' into '4.20.0.0-scclouds'
Listagem de contas por domínio ou projetos ao importar uma VM Closes #3002 See merge request scclouds/scclouds!1296
2 parents 5d9261e + e42ef1e commit 6282083

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')"/>
@@ -303,8 +253,8 @@
303253
<multi-network-selection
304254
:items="nics"
305255
:zoneId="cluster.zoneid"
306-
:domainid="form.domainid"
307-
:account="form.account"
256+
:domainid="this.owner.domainid"
257+
:accountid="this.owner.account"
308258
:selectionEnabled="false"
309259
:filterUnimplementedNetworks="true"
310260
:hypervisor="this.cluster.hypervisortype"
@@ -379,17 +329,20 @@ import { api } from '@/api'
379329
import _ from 'lodash'
380330
import InfoCard from '@/components/view/InfoCard'
381331
import TooltipLabel from '@/components/widgets/TooltipLabel'
332+
import OwnershipSelection from '@/views/compute/wizard/OwnershipSelection.vue'
382333
import ComputeOfferingSelection from '@views/compute/wizard/ComputeOfferingSelection'
383334
import ComputeSelection from '@views/compute/wizard/ComputeSelection'
384335
import MultiDiskSelection from '@views/compute/wizard/MultiDiskSelection'
385336
import MultiNetworkSelection from '@views/compute/wizard/MultiNetworkSelection'
386337
import OsLogo from '@/components/widgets/OsLogo'
387338
import ResourceIcon from '@/components/view/ResourceIcon'
388339
import CheckBoxSelectPair from '@/components/CheckBoxSelectPair'
340+
import store from '@/store'
389341
390342
export default {
391343
name: 'ImportUnmanagedInstances',
392344
components: {
345+
OwnershipSelection,
393346
InfoCard,
394347
TooltipLabel,
395348
ComputeOfferingSelection,
@@ -460,22 +413,20 @@ export default {
460413
},
461414
data () {
462415
return {
416+
owner: {
417+
projectid: store.getters.project?.id,
418+
domainid: store.getters.project?.id ? null : store.getters.userInfo.domainid,
419+
account: store.getters.project?.id ? null : store.getters.userInfo.account
420+
},
463421
options: {
464-
domains: [],
465-
projects: [],
466422
networks: [],
467423
templates: []
468424
},
469425
rowCount: {},
470426
optionsLoading: {
471-
domains: false,
472-
projects: false,
473427
networks: false,
474428
templates: false
475429
},
476-
domains: [],
477-
domainLoading: false,
478-
selectedDomainId: null,
479430
templates: [],
480431
templateLoading: false,
481432
templateType: this.defaultTemplateType(),
@@ -574,9 +525,20 @@ export default {
574525
showicon: true
575526
},
576527
field: 'templateid'
528+
},
529+
accounts: {
530+
list: 'listAccounts',
531+
isLoad: true,
532+
options: {
533+
domainid: this.domainid
534+
},
535+
field: 'accountid'
577536
}
578537
}
579538
},
539+
isNormalUserOrProject () {
540+
return ['User'].includes(this.$store.getters.userInfo.roletype) || store.getters.project?.id
541+
},
580542
isVmRunning () {
581543
if (this.resource && this.resource.powerstate === 'PowerOn') {
582544
return true
@@ -710,14 +672,30 @@ export default {
710672
forced: this.switches.forced,
711673
forcemstoimportvmfiles: this.switches.forceMsToImportVmFiles,
712674
domainid: null,
713-
account: null
675+
accountid: null
714676
})
715677
this.rules = reactive({
716678
displayname: [{ required: true, message: this.$t('message.error.input.value') }],
717679
templateid: [{ required: this.templateType !== 'auto', message: this.$t('message.error.input.value') }],
718680
rootdiskid: [{ required: this.templateType !== 'auto', message: this.$t('message.error.input.value') }]
719681
})
720682
},
683+
fetchOwnerOptions (OwnerOptions) {
684+
this.owner = {}
685+
if (OwnerOptions.selectedAccountType === 'Account') {
686+
if (!OwnerOptions.selectedAccount) {
687+
return
688+
}
689+
this.owner.account = OwnerOptions.selectedAccount
690+
this.owner.domainid = OwnerOptions.selectedDomain
691+
} else if (OwnerOptions.selectedAccountType === 'Project') {
692+
if (!OwnerOptions.selectedProject) {
693+
return
694+
}
695+
this.owner.projectid = OwnerOptions.selectedProject
696+
}
697+
this.fetchData()
698+
},
721699
fetchData () {
722700
_.each(this.params, (param, name) => {
723701
if (param.isLoad) {
@@ -1018,6 +996,12 @@ export default {
1018996
diskpath: this.diskpath,
1019997
temppath: this.tmppath
1020998
}
999+
values.domainid = this.owner.domainid
1000+
if (this.owner.projectid) {
1001+
values.projectid = this.owner.projectid
1002+
} else {
1003+
values.account = this.owner.account
1004+
}
10211005
var importapi = 'importUnmanagedInstance'
10221006
if (this.isExternalImport || this.isDiskImport || this.selectedVmwareVcenter) {
10231007
importapi = 'importVm'

0 commit comments

Comments
 (0)