@@ -161,6 +161,7 @@ import { isAdmin } from '@/role'
161161import TooltipButton from ' @/components/widgets/TooltipButton'
162162import ResourceIcon from ' @/components/view/ResourceIcon'
163163import Status from ' @/components/widgets/Status'
164+ import { i18n } from ' @/locales'
164165
165166export 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' ].includes (item)
294+ ' type' , ' scope' , ' managementserverid' , ' usagetype ' ].includes (item)
290295 ) {
291296 type = ' list'
292297 } else if (item === ' tags' ) {
@@ -406,6 +411,7 @@ export default {
406411 let clusterIndex = - 1
407412 let groupIndex = - 1
408413 let managementServerIdIndex = - 1
414+ let usageTypeIndex = - 1
409415
410416 if (arrayField .includes (' type' )) {
411417 if (this .$route .path === ' /alert' ) {
@@ -479,6 +485,13 @@ export default {
479485 promises .push (await this .fetchManagementServers (searchKeyword))
480486 }
481487
488+ if (arrayField .includes (' usagetype' )) {
489+ usageTypeIndex = this .fields .findIndex (item => item .name === ' usagetype' )
490+ }
491+
492+ this .fields [usageTypeIndex].loading = true
493+ promises .push (await this .fetchUsageTypes ())
494+
482495 Promise .all (promises).then (response => {
483496 if (typeIndex > - 1 ) {
484497 const types = response .filter (item => item .type === ' type' )
@@ -546,6 +559,12 @@ export default {
546559 this .fields [managementServerIdIndex].opts = this .sortArray (managementServers[0 ].data )
547560 }
548561 }
562+ if (usageTypeIndex > - 1 ) {
563+ const usageTypes = response .filter (item => item .type === ' usagetype' )
564+ if (usageTypes? .length > 0 ) {
565+ this .fields [usageTypeIndex].opts = this .sortArray (usageTypes[0 ].data )
566+ }
567+ }
549568 }).finally (() => {
550569 if (typeIndex > - 1 ) {
551570 this .fields [typeIndex].loading = false
@@ -574,6 +593,9 @@ export default {
574593 if (managementServerIdIndex > - 1 ) {
575594 this .fields [managementServerIdIndex].loading = false
576595 }
596+ if (usageTypeIndex > - 1 ) {
597+ this .fields [usageTypeIndex].loading = false
598+ }
577599 this .fillFormFieldValues ()
578600 })
579601 },
@@ -1083,6 +1105,27 @@ export default {
10831105 })
10841106 return levels
10851107 },
1108+ fetchUsageTypes () {
1109+ return new Promise ((resolve , reject ) => {
1110+ api (' listUsageTypes' )
1111+ .then (json => {
1112+ const usageTypes = json .listusagetypesresponse .usagetype .map (entry => {
1113+ return {
1114+ id: entry .id ,
1115+ name: i18n .global .t (entry .name )
1116+ }
1117+ })
1118+
1119+ resolve ({
1120+ type: ' usagetype' ,
1121+ data: usageTypes
1122+ })
1123+ })
1124+ .catch (error => {
1125+ reject (error .response .headers [' x-description' ])
1126+ })
1127+ })
1128+ },
10861129 onSearch (value ) {
10871130 this .paramsFilter = {}
10881131 this .searchQuery = value
0 commit comments