Skip to content

Commit e8354c3

Browse files
add keyword and usagetype filter on UI
1 parent 949247f commit e8354c3

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

ui/src/components/view/SearchView.vue

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ import { isAdmin } from '@/role'
161161
import TooltipButton from '@/components/widgets/TooltipButton'
162162
import ResourceIcon from '@/components/view/ResourceIcon'
163163
import Status from '@/components/widgets/Status'
164+
import { i18n } from '@/locales'
164165
165166
export default {
166167
name: 'SearchView',
@@ -284,9 +285,13 @@ export default {
284285
if (item === 'groupid' && !('listInstanceGroups' in this.$store.getters.apis)) {
285286
return true
286287
}
288+
if (item === 'usagetype' && !('listUsageTypes' in this.$store.getters.apis)) {
289+
return true
290+
}
291+
287292
if (['zoneid', 'domainid', 'imagestoreid', 'storageid', 'state', 'account', 'hypervisor', 'level',
288293
'clusterid', 'podid', 'groupid', 'entitytype', 'accounttype', 'systemvmtype', 'scope', 'provider',
289-
'type', 'scope', 'managementserverid', 'serviceofferingid', 'diskofferingid'].includes(item)
294+
'type', 'scope', 'managementserverid', 'serviceofferingid', 'diskofferingid', 'usagetype'].includes(item)
290295
) {
291296
type = 'list'
292297
} else if (item === 'tags') {
@@ -408,6 +413,7 @@ export default {
408413
let managementServerIdIndex = -1
409414
let serviceOfferingIndex = -1
410415
let diskOfferingIndex = -1
416+
let usageTypeIndex = -1
411417
412418
if (arrayField.includes('type')) {
413419
if (this.$route.path === '/alert') {
@@ -493,6 +499,13 @@ export default {
493499
promises.push(await this.fetchDiskOfferings(searchKeyword))
494500
}
495501
502+
if (arrayField.includes('usagetype')) {
503+
usageTypeIndex = this.fields.findIndex(item => item.name === 'usagetype')
504+
}
505+
506+
this.fields[usageTypeIndex].loading = true
507+
promises.push(await this.fetchUsageTypes())
508+
496509
Promise.all(promises).then(response => {
497510
if (typeIndex > -1) {
498511
const types = response.filter(item => item.type === 'type')
@@ -575,6 +588,12 @@ export default {
575588
this.fields[diskOfferingIndex].opts = this.sortArray(diskOfferings[0].data)
576589
}
577590
}
591+
if (usageTypeIndex > -1) {
592+
const usageTypes = response.filter(item => item.type === 'usagetype')
593+
if (usageTypes?.length > 0) {
594+
this.fields[usageTypeIndex].opts = this.sortArray(usageTypes[0].data)
595+
}
596+
}
578597
}).finally(() => {
579598
if (typeIndex > -1) {
580599
this.fields[typeIndex].loading = false
@@ -609,6 +628,9 @@ export default {
609628
if (diskOfferingIndex > -1) {
610629
this.fields[diskOfferingIndex].loading = false
611630
}
631+
if (usageTypeIndex > -1) {
632+
this.fields[usageTypeIndex].loading = false
633+
}
612634
this.fillFormFieldValues()
613635
})
614636
},
@@ -1144,6 +1166,27 @@ export default {
11441166
})
11451167
return levels
11461168
},
1169+
fetchUsageTypes () {
1170+
return new Promise((resolve, reject) => {
1171+
api('listUsageTypes')
1172+
.then(json => {
1173+
const usageTypes = json.listusagetypesresponse.usagetype.map(entry => {
1174+
return {
1175+
id: entry.id,
1176+
name: i18n.global.t(entry.name)
1177+
}
1178+
})
1179+
1180+
resolve({
1181+
type: 'usagetype',
1182+
data: usageTypes
1183+
})
1184+
})
1185+
.catch(error => {
1186+
reject(error.response.headers['x-description'])
1187+
})
1188+
})
1189+
},
11471190
onSearch (value) {
11481191
this.paramsFilter = {}
11491192
this.searchQuery = value

0 commit comments

Comments
 (0)