Skip to content

Commit 01e5c25

Browse files
search in (too) large result sets (#7766)
Co-authored-by: Pearl Dsilva <pearl1594@gmail.com>
1 parent cdf0187 commit 01e5c25

File tree

1 file changed

+62
-48
lines changed

1 file changed

+62
-48
lines changed

ui/src/components/view/SearchView.vue

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
:filterOption="(input, option) => {
6666
return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
6767
}"
68-
:loading="field.loading">
68+
:loading="field.loading"
69+
@input="onchange($event, field.name)">
6970
<a-select-option
7071
v-for="(opt, idx) in field.opts"
7172
:key="idx"
@@ -236,6 +237,9 @@ export default {
236237
}
237238
},
238239
methods: {
240+
onchange: async function (event, fieldname) {
241+
this.fetchDynamicFieldData(fieldname, event.target.value)
242+
},
239243
onVisibleForm () {
240244
this.visibleFilter = !this.visibleFilter
241245
if (!this.visibleFilter) return
@@ -254,7 +258,7 @@ export default {
254258
}
255259
return this.$t('label.' + fieldName)
256260
},
257-
async initFormFieldData () {
261+
initFields () {
258262
const arrayField = []
259263
this.fields = []
260264
this.searchFilters.forEach(item => {
@@ -291,14 +295,9 @@ export default {
291295
})
292296
arrayField.push(item)
293297
})
294-
295-
const promises = []
296-
let zoneIndex = -1
297-
let domainIndex = -1
298-
let podIndex = -1
299-
let clusterIndex = -1
300-
let groupIndex = -1
301-
298+
return arrayField
299+
},
300+
fetchStaticFieldData (arrayField) {
302301
if (arrayField.includes('type')) {
303302
if (this.$route.path === '/guestnetwork' || this.$route.path.includes('/guestnetwork/')) {
304303
const typeIndex = this.fields.findIndex(item => item.name === 'type')
@@ -322,57 +321,65 @@ export default {
322321
this.fields[levelIndex].loading = false
323322
}
324323
324+
if (arrayField.includes('entitytype')) {
325+
const entityTypeIndex = this.fields.findIndex(item => item.name === 'entitytype')
326+
this.fields[entityTypeIndex].loading = true
327+
this.fields[entityTypeIndex].opts = this.fetchEntityType()
328+
this.fields[entityTypeIndex].loading = false
329+
}
330+
331+
if (arrayField.includes('resourcetype')) {
332+
const resourceTypeIndex = this.fields.findIndex(item => item.name === 'resourcetype')
333+
this.fields[resourceTypeIndex].loading = true
334+
this.fields[resourceTypeIndex].opts = [
335+
{ value: 'Account' },
336+
{ value: 'Domain' },
337+
{ value: 'Iso' },
338+
{ value: 'Network' },
339+
{ value: 'Template' },
340+
{ value: 'User' },
341+
{ value: 'VirtualMachine' },
342+
{ value: 'Volume' }
343+
]
344+
this.fields[resourceTypeIndex].loading = false
345+
}
346+
},
347+
async fetchDynamicFieldData (arrayField, searchKeyword) {
348+
const promises = []
349+
let zoneIndex = -1
350+
let domainIndex = -1
351+
let podIndex = -1
352+
let clusterIndex = -1
353+
let groupIndex = -1
354+
325355
if (arrayField.includes('zoneid')) {
326356
zoneIndex = this.fields.findIndex(item => item.name === 'zoneid')
327357
this.fields[zoneIndex].loading = true
328-
promises.push(await this.fetchZones())
358+
promises.push(await this.fetchZones(searchKeyword))
329359
}
330360
331361
if (arrayField.includes('domainid')) {
332362
domainIndex = this.fields.findIndex(item => item.name === 'domainid')
333363
this.fields[domainIndex].loading = true
334-
promises.push(await this.fetchDomains())
364+
promises.push(await this.fetchDomains(searchKeyword))
335365
}
336366
337367
if (arrayField.includes('podid')) {
338368
podIndex = this.fields.findIndex(item => item.name === 'podid')
339369
this.fields[podIndex].loading = true
340-
promises.push(await this.fetchPods())
370+
promises.push(await this.fetchPods(searchKeyword))
341371
}
342372
343373
if (arrayField.includes('clusterid')) {
344374
clusterIndex = this.fields.findIndex(item => item.name === 'clusterid')
345375
this.fields[clusterIndex].loading = true
346-
promises.push(await this.fetchClusters())
376+
promises.push(await this.fetchClusters(searchKeyword))
347377
}
348378
349379
if (arrayField.includes('groupid')) {
350380
groupIndex = this.fields.findIndex(item => item.name === 'groupid')
351381
this.fields[groupIndex].loading = true
352-
promises.push(await this.fetchInstanceGroups())
353-
}
354-
355-
if (arrayField.includes('entitytype')) {
356-
const entityTypeIndex = this.fields.findIndex(item => item.name === 'entitytype')
357-
this.fields[entityTypeIndex].loading = true
358-
this.fields[entityTypeIndex].opts = this.fetchEntityType()
359-
this.fields[entityTypeIndex].loading = false
360-
}
361-
362-
if (arrayField.includes('resourcetype')) {
363-
const resourceTypeIndex = this.fields.findIndex(item => item.name === 'resourcetype')
364-
this.fields[resourceTypeIndex].loading = true
365-
this.fields[resourceTypeIndex].opts = [
366-
{ value: 'Account' },
367-
{ value: 'Domain' },
368-
{ value: 'Iso' },
369-
{ value: 'Network' },
370-
{ value: 'Template' },
371-
{ value: 'User' },
372-
{ value: 'VirtualMachine' },
373-
{ value: 'Volume' }
374-
]
375-
this.fields[resourceTypeIndex].loading = false
382+
promises.push(await this.fetchInstanceGroups(searchKeyword))
376383
}
377384
378385
Promise.all(promises).then(response => {
@@ -425,6 +432,13 @@ export default {
425432
this.fillFormFieldValues()
426433
})
427434
},
435+
initFormFieldData () {
436+
const arrayField = this.initFields()
437+
438+
this.fetchStaticFieldData(arrayField)
439+
440+
this.fetchDynamicFieldData(arrayField)
441+
},
428442
sortArray (data, key = 'name') {
429443
return data.sort(function (a, b) {
430444
if (a[key] < b[key]) { return -1 }
@@ -447,9 +461,9 @@ export default {
447461
this.inputKey = this.fieldValues['tags[0].key'] || null
448462
this.inputValue = this.fieldValues['tags[0].value'] || null
449463
},
450-
fetchZones () {
464+
fetchZones (searchKeyword) {
451465
return new Promise((resolve, reject) => {
452-
api('listZones', { showicon: true }).then(json => {
466+
api('listZones', { showicon: true, keyword: searchKeyword }).then(json => {
453467
const zones = json.listzonesresponse.zone
454468
resolve({
455469
type: 'zoneid',
@@ -460,9 +474,9 @@ export default {
460474
})
461475
})
462476
},
463-
fetchDomains () {
477+
fetchDomains (searchKeyword) {
464478
return new Promise((resolve, reject) => {
465-
api('listDomains', { listAll: true, showicon: true }).then(json => {
479+
api('listDomains', { listAll: true, showicon: true, keyword: searchKeyword }).then(json => {
466480
const domain = json.listdomainsresponse.domain
467481
resolve({
468482
type: 'domainid',
@@ -473,9 +487,9 @@ export default {
473487
})
474488
})
475489
},
476-
fetchPods () {
490+
fetchPods (searchKeyword) {
477491
return new Promise((resolve, reject) => {
478-
api('listPods').then(json => {
492+
api('listPods', { keyword: searchKeyword }).then(json => {
479493
const pods = json.listpodsresponse.pod
480494
resolve({
481495
type: 'podid',
@@ -486,9 +500,9 @@ export default {
486500
})
487501
})
488502
},
489-
fetchClusters () {
503+
fetchClusters (searchKeyword) {
490504
return new Promise((resolve, reject) => {
491-
api('listClusters').then(json => {
505+
api('listClusters', { keyword: searchKeyword }).then(json => {
492506
const clusters = json.listclustersresponse.cluster
493507
resolve({
494508
type: 'clusterid',
@@ -499,9 +513,9 @@ export default {
499513
})
500514
})
501515
},
502-
fetchInstanceGroups () {
516+
fetchInstanceGroups (searchKeyword) {
503517
return new Promise((resolve, reject) => {
504-
api('listInstanceGroups', { listAll: true }).then(json => {
518+
api('listInstanceGroups', { listAll: true, keyword: searchKeyword }).then(json => {
505519
const instancegroups = json.listinstancegroupsresponse.instancegroup
506520
resolve({
507521
type: 'groupid',

0 commit comments

Comments
 (0)