Skip to content

Commit 267d78b

Browse files
committed
Address comments
1 parent 21ca320 commit 267d78b

File tree

1 file changed

+40
-165
lines changed

1 file changed

+40
-165
lines changed

ui/src/components/view/SearchFilter.vue

Lines changed: 40 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export default {
5858
emits: ['close'],
5959
data () {
6060
return {
61-
alertTypes: {},
6261
searchFilter: {
6362
key: this.filterKey,
6463
value: this.filterKey
@@ -192,92 +191,55 @@ export default {
192191
}
193192
194193
if (key.includes('zoneid')) {
195-
formattedValue = await this.getZone(value)
194+
formattedValue = await this.getResourceName('listZones', 'listzonesresponse', 'zone', value)
196195
}
197196
198197
if (key.includes('domainid')) {
199-
formattedValue = await this.getDomain(value)
198+
formattedValue = await this.getResourceName('listDomains', 'listdomainsresponse', 'domain', value)
200199
}
201200
202201
if (key.includes('account')) {
203-
formattedValue = await this.getAccount(value)
202+
formattedValue = await this.getResourceName('listAccounts', 'listaccountsresponse', 'account', value)
204203
}
205204
206205
if (key.includes('hypervisor')) {
207206
formattedValue = await this.getHypervisor(value)
208207
}
209208
210209
if (key.includes('imagestoreid')) {
211-
formattedValue = await this.getImageStore(value)
210+
formattedValue = await this.getResourceName('listImageStores', 'listimagestoresresponse', 'imagestore', value)
212211
}
213212
214213
if (key.includes('storageid')) {
215-
formattedValue = await this.getStoragePool(value)
214+
formattedValue = await this.getResourceName('listStoragePools', 'liststoragepoolsresponse', 'storagepool', value)
216215
}
217216
218217
if (key.includes('podid')) {
219-
formattedValue = await this.getPod(value)
218+
formattedValue = await this.getResourceName('listPods', 'listpodsresponse', 'pod', value)
220219
}
221220
222221
if (key.includes('clusterid')) {
223-
formattedValue = await this.getCluster(value)
222+
formattedValue = await this.getResourceName('listClusters', 'listclustersresponse', 'cluster', value)
224223
}
225224
226225
if (key.includes('groupid')) {
227-
formattedValue = await this.getInstanceGroup(value)
226+
formattedValue = await this.getResourceName('listInstanceGroups', 'listinstancegroupsresponse', 'instancegroup', value)
228227
}
229228
230229
if (key.includes('managementserverid')) {
231-
formattedValue = await this.getManagementServer(value)
230+
formattedValue = await this.getResourceName('listManagementServers', 'listmanagementserversresponse', 'managementserver', value)
232231
}
233232
234233
if (key.includes('serviceofferingid')) {
235-
formattedValue = await this.getServiceOffering(value)
234+
formattedValue = await this.getResourceName('listServiceOfferings', 'listserviceofferingsresponse', 'serviceoffering', value)
236235
}
237236
238237
if (key.includes('diskofferingid')) {
239-
formattedValue = await this.getDiskOffering(value)
238+
formattedValue = await this.getResourceName('listDiskOfferings', 'listdiskofferingsresponse', 'diskoffering', value)
240239
}
241240
242241
return formattedValue
243242
},
244-
getZone (zoneId) {
245-
return new Promise((resolve) => {
246-
api('listZones', { showicon: true, id: zoneId }).then(json => {
247-
if (json?.listzonesresponse?.zone) {
248-
resolve(json.listzonesresponse.zone[0].name)
249-
}
250-
}).catch(() => {
251-
resolve(null)
252-
})
253-
})
254-
},
255-
getDomain (domainId) {
256-
return new Promise((resolve) => {
257-
api('listDomains', { listAll: true, showicon: true, id: domainId }).then(json => {
258-
if (json?.listdomainsresponse?.domain) {
259-
resolve(json.listdomainsresponse.domain[0].path)
260-
}
261-
}).catch(() => {
262-
resolve(null)
263-
})
264-
})
265-
},
266-
getAccount (accountId) {
267-
return new Promise((resolve) => {
268-
if (!this.$isValidUuid(accountId)) {
269-
resolve(accountId)
270-
}
271-
const params = { listAll: true, isrecursive: false, showicon: true, id: accountId }
272-
api('listAccounts', params).then(json => {
273-
if (json?.listaccountsresponse?.account) {
274-
resolve(json.listaccountsresponse.account[0].name)
275-
}
276-
}).catch(() => {
277-
resolve(null)
278-
})
279-
})
280-
},
281243
getHypervisor (value) {
282244
return new Promise((resolve) => {
283245
api('listHypervisors').then(json => {
@@ -294,139 +256,52 @@ export default {
294256
})
295257
})
296258
},
297-
getImageStore (storeId) {
298-
return new Promise((resolve) => {
299-
api('listImageStores', { listAll: true, showicon: true, id: storeId }).then(json => {
300-
if (json?.listimagestoresresponse?.imagestore) {
301-
resolve(json.listimagestoresresponse.imagestore[0].name)
302-
}
303-
}).catch(() => {
304-
resolve(null)
305-
})
306-
})
307-
},
308-
getStoragePool (poolId) {
309-
return new Promise((resolve) => {
310-
api('listStoragePools', { listAll: true, showicon: true, id: poolId }).then(json => {
311-
if (json?.liststoragepoolsresponse?.storagepool) {
312-
resolve(json.liststoragepoolsresponse.storagepool[0].name)
313-
}
314-
}).catch(() => {
315-
resolve(null)
316-
})
317-
})
318-
},
319-
getPod (podId) {
320-
return new Promise((resolve) => {
321-
api('listPods', { id: podId }).then(json => {
322-
if (json?.listpodsresponse?.pod) {
323-
resolve(json.listpodsresponse.pod[0].name)
324-
}
325-
}).catch(() => {
326-
resolve(null)
327-
})
328-
})
329-
},
330-
getCluster (clusterId) {
259+
getResourceName (apiName, responseKey1, responseKey2, id) {
331260
return new Promise((resolve) => {
332-
api('listClusters', { id: clusterId }).then(json => {
333-
if (json?.listclustersresponse?.cluster) {
334-
resolve(json.listclustersresponse.cluster[0].name)
335-
}
336-
}).catch(() => {
337-
resolve(null)
338-
})
339-
})
340-
},
341-
getInstanceGroup (groupId) {
342-
return new Promise((resolve) => {
343-
api('listInstanceGroups', { listAll: true, id: groupId }).then(json => {
344-
if (json?.listinstancegroupsresponse?.instancegroup) {
345-
resolve(json.listinstancegroupsresponse.instancegroup[0].name)
346-
}
347-
}).catch(() => {
348-
resolve(null)
349-
})
350-
})
351-
},
352-
getServiceOffering (offeringId) {
353-
return new Promise((resolve) => {
354-
api('listServiceOfferings', { listAll: true, id: offeringId }).then(json => {
355-
if (json?.listserviceofferingsresponse?.serviceoffering) {
356-
resolve(json.listserviceofferingsresponse.serviceoffering[0].name)
261+
if (!this.$isValidUuid(id)) {
262+
return resolve(null)
263+
}
264+
api(apiName, { listAll: true, id: id }).then(json => {
265+
if (json[responseKey1] && json[responseKey1][responseKey2]) {
266+
resolve(json[responseKey1][responseKey2][0].name)
357267
}
358268
}).catch(() => {
359269
resolve(null)
360270
})
361271
})
362272
},
363-
getDiskOffering (offeringId) {
273+
getAlertType (type) {
364274
return new Promise((resolve) => {
365-
api('listDiskOfferings', { listAll: true, id: offeringId }).then(json => {
366-
if (json?.listdiskofferingsresponse?.diskoffering) {
367-
resolve(json.listdiskofferingsresponse.diskoffering[0].name)
275+
api('listAlertTypes').then(json => {
276+
const alertTypes = {}
277+
for (const key in json.listalerttypesresponse.alerttype) {
278+
const alerttype = json.listalerttypesresponse.alerttype[key]
279+
alertTypes[alerttype.id] = alerttype.name
368280
}
281+
resolve(alertTypes[type])
369282
}).catch(() => {
370283
resolve(null)
371284
})
372285
})
373286
},
374-
getAlertType (type) {
375-
if (this.alertTypes.length > 0) {
376-
return new Promise((resolve) => {
377-
resolve(this.alertTypes[type])
378-
})
379-
} else {
380-
return new Promise((resolve) => {
381-
api('listAlertTypes').then(json => {
382-
const alertTypes = {}
383-
for (const key in json.listalerttypesresponse.alerttype) {
384-
const alerttype = json.listalerttypesresponse.alerttype[key]
385-
alertTypes[alerttype.id] = alerttype.name
386-
}
387-
this.alertTypes = alertTypes
388-
resolve(alertTypes[type])
389-
}).catch(() => {
390-
resolve(null)
391-
})
392-
})
393-
}
394-
},
395287
getAffinityGroupType (type) {
396-
if (this.alertTypes.length > 0) {
397-
return new Promise((resolve) => {
398-
resolve(this.alertTypes[type])
399-
})
400-
} else {
401-
return new Promise((resolve) => {
402-
api('listAffinityGroupTypes').then(json => {
403-
const alertTypes = {}
404-
for (const key in json.listaffinitygrouptypesresponse.affinityGroupType) {
405-
const affinityGroupType = json.listaffinitygrouptypesresponse.affinityGroupType[key]
406-
if (affinityGroupType.type === 'host anti-affinity') {
407-
alertTypes[affinityGroupType.type] = 'host anti-affinity (Strict)'
408-
} else if (affinityGroupType.type === 'host affinity') {
409-
alertTypes[affinityGroupType.type] = 'host affinity (Strict)'
410-
} else if (affinityGroupType.type === 'non-strict host anti-affinity') {
411-
alertTypes[affinityGroupType.type] = 'host anti-affinity (Non-Strict)'
412-
} else if (affinityGroupType.type === 'non-strict host affinity') {
413-
alertTypes[affinityGroupType.type] = 'host affinity (Non-Strict)'
414-
}
415-
}
416-
this.alertTypes = alertTypes
417-
resolve(alertTypes[type])
418-
}).catch(() => {
419-
resolve(null)
420-
})
421-
})
422-
}
423-
},
424-
getManagementServer (msId) {
425288
return new Promise((resolve) => {
426-
api('listManagementServers', { listAll: true, id: msId }).then(json => {
427-
if (json?.listmanagementserversresponse?.managementserver) {
428-
resolve(json.listmanagementserversresponse.managementserver[0].name)
289+
api('listAffinityGroupTypes').then(json => {
290+
const alertTypes = {}
291+
for (const key in json.listaffinitygrouptypesresponse.affinityGroupType) {
292+
const affinityGroupType = json.listaffinitygrouptypesresponse.affinityGroupType[key]
293+
if (affinityGroupType.type === 'host anti-affinity') {
294+
alertTypes[affinityGroupType.type] = 'host anti-affinity (Strict)'
295+
} else if (affinityGroupType.type === 'host affinity') {
296+
alertTypes[affinityGroupType.type] = 'host affinity (Strict)'
297+
} else if (affinityGroupType.type === 'non-strict host anti-affinity') {
298+
alertTypes[affinityGroupType.type] = 'host anti-affinity (Non-Strict)'
299+
} else if (affinityGroupType.type === 'non-strict host affinity') {
300+
alertTypes[affinityGroupType.type] = 'host affinity (Non-Strict)'
301+
}
429302
}
303+
this.alertTypes = alertTypes
304+
resolve(alertTypes[type])
430305
}).catch(() => {
431306
resolve(null)
432307
})

0 commit comments

Comments
 (0)