Skip to content

Commit a573fcd

Browse files
CreateNetwork isolated/L2 form, added accounts list under selected domain
1 parent ce98157 commit a573fcd

File tree

2 files changed

+96
-13
lines changed

2 files changed

+96
-13
lines changed

ui/src/views/network/CreateIsolatedNetworkForm.vue

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,24 @@
272272
v-model:value="form.networkdomain"
273273
:placeholder="apiParams.networkdomain.description"/>
274274
</a-form-item>
275-
<a-form-item
276-
ref="account"
277-
name="account"
278-
v-if="accountVisible">
275+
<a-form-item ref="account" name="account" v-if="accountVisible">
279276
<template #label>
280277
<tooltip-label :title="$t('label.account')" :tooltip="apiParams.account.description"/>
281278
</template>
282-
<a-input
279+
<a-select
283280
v-model:value="form.account"
284-
:placeholder="apiParams.account.description"/>
281+
showSearch
282+
optionFilterProp="label"
283+
:filterOption="(input, option) => {
284+
return option.children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0
285+
}"
286+
:loading="accountLoading"
287+
:placeholder="apiParams.account.description"
288+
@change="val => { handleAccountChange(accounts[val]) }">
289+
<a-select-option v-for="(opt, optIndex) in accounts" :key="optIndex">
290+
{{ opt.name || opt.description }}
291+
</a-select-option>
292+
</a-select>
285293
</a-form-item>
286294
<div :span="24" class="action-button">
287295
<a-button
@@ -339,6 +347,10 @@ export default {
339347
domains: [],
340348
domainLoading: false,
341349
selectedDomain: {},
350+
accountVisible: isAdminOrDomainAdmin(),
351+
accounts: [],
352+
accountLoading: false,
353+
selectedAccount: {},
342354
zones: [],
343355
zoneLoading: false,
344356
selectedZone: {},
@@ -348,7 +360,6 @@ export default {
348360
vpcs: [],
349361
vpcLoading: false,
350362
selectedVpc: {},
351-
accountVisible: isAdminOrDomainAdmin(),
352363
privateMtuMax: 1500,
353364
publicMtuMax: 1500,
354365
minMTU: 68,
@@ -466,8 +477,12 @@ export default {
466477
this.accountVisible = domain.id !== '-1'
467478
if (isAdminOrDomainAdmin()) {
468479
this.updateVPCCheckAndFetchNetworkOfferingData()
480+
this.fetchAccounts()
469481
}
470482
},
483+
handleAccountChange (account) {
484+
this.selectedAccount = account
485+
},
471486
updateVPCCheckAndFetchNetworkOfferingData () {
472487
if (this.vpc !== null) { // from VPC section
473488
this.fetchNetworkOfferingData(true)
@@ -544,6 +559,31 @@ export default {
544559
}
545560
})
546561
},
562+
fetchAccounts () {
563+
this.accountLoading = true
564+
var params = {}
565+
if (isAdminOrDomainAdmin() && this.selectedDomain.id !== '-1') { // domain is visible only for admins
566+
params.domainid = this.selectedDomain.id
567+
}
568+
this.accounts = [
569+
{
570+
id: '-1',
571+
name: ' '
572+
}
573+
]
574+
this.selectedAccount = {}
575+
api('listAccounts', params).then(json => {
576+
const listAccounts = json.listaccountsresponse.account
577+
this.accounts = this.accounts.concat(listAccounts)
578+
}).catch(error => {
579+
this.$notifyError(error)
580+
}).finally(() => {
581+
this.accountLoading = false
582+
if (this.arrayHasItems(this.accounts)) {
583+
this.form.accountid = 0
584+
}
585+
})
586+
},
547587
handleSubmit () {
548588
if (this.actionLoading) return
549589
this.formRef.value.validate().then(() => {
@@ -571,7 +611,7 @@ export default {
571611
if ('domainid' in values && values.domainid > 0) {
572612
params.domainid = this.selectedDomain.id
573613
if (this.isValidTextValueForKey(values, 'account')) {
574-
params.account = values.account
614+
params.account = this.selectedAccount.name
575615
}
576616
}
577617
api('createNetwork', params).then(json => {

ui/src/views/network/CreateL2NetworkForm.vue

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,20 @@
168168
<template #label>
169169
<tooltip-label :title="$t('label.account')" :tooltip="apiParams.account.description"/>
170170
</template>
171-
<a-input
172-
v-model:value="form.account"
173-
:placeholder="apiParams.account.description"/>
171+
<a-select
172+
v-model:value="form.account"
173+
showSearch
174+
optionFilterProp="label"
175+
:filterOption="(input, option) => {
176+
return option.children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0
177+
}"
178+
:loading="accountLoading"
179+
:placeholder="apiParams.account.description"
180+
@change="val => { handleAccountChange(accounts[val]) }">
181+
<a-select-option v-for="(opt, optIndex) in accounts" :key="optIndex">
182+
{{ opt.name || opt.description }}
183+
</a-select-option>
184+
</a-select>
174185
</a-form-item>
175186
<div :span="24" class="action-button">
176187
<a-button
@@ -227,13 +238,16 @@ export default {
227238
domains: [],
228239
domainLoading: false,
229240
selectedDomain: {},
241+
accountVisible: isAdminOrDomainAdmin(),
242+
accounts: [],
243+
accountLoading: false,
244+
selectedAccount: {},
230245
zones: [],
231246
zoneLoading: false,
232247
selectedZone: {},
233248
networkOfferings: [],
234249
networkOfferingLoading: false,
235250
selectedNetworkOffering: {},
236-
accountVisible: isAdminOrDomainAdmin(),
237251
isolatePvlanType: 'none'
238252
}
239253
},
@@ -336,8 +350,12 @@ export default {
336350
this.accountVisible = domain.id !== '-1'
337351
if (isAdminOrDomainAdmin()) {
338352
this.updateVPCCheckAndFetchNetworkOfferingData()
353+
this.fetchAccounts()
339354
}
340355
},
356+
handleAccountChange (account) {
357+
this.selectedAccount = account
358+
},
341359
updateVPCCheckAndFetchNetworkOfferingData () {
342360
if (this.vpc !== null) { // from VPC section
343361
this.fetchNetworkOfferingData(true)
@@ -390,6 +408,31 @@ export default {
390408
handleNetworkOfferingChange (networkOffering) {
391409
this.selectedNetworkOffering = networkOffering
392410
},
411+
fetchAccounts () {
412+
this.accountLoading = true
413+
var params = {}
414+
if (isAdminOrDomainAdmin() && this.selectedDomain.id !== '-1') { // domain is visible only for admins
415+
params.domainid = this.selectedDomain.id
416+
}
417+
this.accounts = [
418+
{
419+
id: '-1',
420+
name: ' '
421+
}
422+
]
423+
this.selectedAccount = {}
424+
api('listAccounts', params).then(json => {
425+
const listAccounts = json.listaccountsresponse.account
426+
this.accounts = this.accounts.concat(listAccounts)
427+
}).catch(error => {
428+
this.$notifyError(error)
429+
}).finally(() => {
430+
this.accountLoading = false
431+
if (this.arrayHasItems(this.accounts)) {
432+
this.form.accountid = 0
433+
}
434+
})
435+
},
393436
handleSubmit (e) {
394437
if (this.actionLoading) return
395438
this.formRef.value.validate().then(() => {
@@ -411,7 +454,7 @@ export default {
411454
if ('domainid' in values && values.domainid > 0) {
412455
params.domainid = this.selectedDomain.id
413456
if (this.isValidTextValueForKey(values, 'account')) {
414-
params.account = values.account
457+
params.account = this.selectedAccount.name
415458
}
416459
}
417460
if (this.isValidValueForKey(values, 'isolatedpvlantype') && values.isolatedpvlantype !== 'none') {

0 commit comments

Comments
 (0)