@@ -466,6 +466,7 @@ export default {
466466 return available <= 0 ? ' #ff4d4f' : ' #52c41a'
467467 },
468468 fetchData () {
469+ this .loading = true
469470 if (store .getters .project .id ) {
470471 this .listProject ()
471472 } else {
@@ -474,22 +475,18 @@ export default {
474475 this .updateData ()
475476 },
476477 listAccount () {
477- this .loading = true
478478 getAPI (' listAccounts' , { id: this .$store .getters .userInfo .accountid }).then (json => {
479- this .loading = false
480479 if (json && json .listaccountsresponse && json .listaccountsresponse .account ) {
481480 this .account = json .listaccountsresponse .account [0 ]
482481 }
483482 })
484483 },
485484 listProject () {
486- this .loading = true
487485 const params = {
488486 id: store .getters .project .id ,
489487 listall: true
490488 }
491489 getAPI (' listProjects' , params).then (json => {
492- this .loading = false
493490 if (json? .listprojectsresponse ? .project ) {
494491 this .project = json .listprojectsresponse .project [0 ]
495492 }
@@ -510,82 +507,94 @@ export default {
510507 }
511508 this .listInstances ()
512509 this .listEvents ()
510+
511+ const promises = []
513512 if (' listKubernetesClusters' in this .$store .getters .apis ) {
514- this .loading = true
515- getAPI (' listKubernetesClusters' , { listall: true , page: 1 , pagesize: 1 }).then (json => {
516- this .loading = false
517- this .data .kubernetes = json? .listkubernetesclustersresponse ? .count
518- })
513+ promises .push (getAPI (' listKubernetesClusters' , { listall: true , page: 1 , pagesize: 1 }))
519514 }
520515 if (' listVolumes' in this .$store .getters .apis ) {
521- this .loading = true
522- getAPI (' listVolumes' , { listall: true , page: 1 , pagesize: 1 }).then (json => {
523- this .loading = false
524- this .data .volumes = json? .listvolumesresponse ? .count
525- })
516+ promises .push (getAPI (' listVolumes' , { listall: true , page: 1 , pagesize: 1 }))
526517 }
527518 if (' listSnapshots' in this .$store .getters .apis ) {
528- this .loading = true
529- getAPI (' listSnapshots' , { listall: true , page: 1 , pagesize: 1 }).then (json => {
530- this .loading = false
531- this .data .snapshots = json? .listsnapshotsresponse ? .count
532- })
519+ promises .push (getAPI (' listSnapshots' , { listall: true , page: 1 , pagesize: 1 }))
533520 }
534521 if (' listNetworks' in this .$store .getters .apis ) {
535- this .loading = true
536- getAPI (' listNetworks' , { listall: true , page: 1 , pagesize: 1 }).then (json => {
537- this .loading = false
538- this .data .networks = json? .listnetworksresponse ? .count
539- })
522+ promises .push (getAPI (' listNetworks' , { listall: true , page: 1 , pagesize: 1 }))
540523 }
541524 if (' listVPCs' in this .$store .getters .apis ) {
542- this .loading = true
543- getAPI (' listVPCs' , { listall: true , page: 1 , pagesize: 1 }).then (json => {
544- this .loading = false
545- this .data .vpcs = json? .listvpcsresponse ? .count
546- })
525+ promises .push (getAPI (' listVPCs' , { listall: true , page: 1 , pagesize: 1 }))
547526 }
548527 if (' listPublicIpAddresses' in this .$store .getters .apis ) {
549- this .loading = true
550- getAPI (' listPublicIpAddresses' , { listall: true , page: 1 , pagesize: 1 }).then (json => {
551- this .loading = false
552- this .data .ips = json? .listpublicipaddressesresponse ? .count
553- })
528+ promises .push (getAPI (' listPublicIpAddresses' , { listall: true , page: 1 , pagesize: 1 }))
554529 }
555530 if (' listTemplates' in this .$store .getters .apis ) {
556- this . loading = true
557- getAPI ( ' listTemplates ' , { templatefilter : ' self ' , listall : true , page : 1 , pagesize : 1 }). then ( json => {
558- this . loading = false
559- this . data . templates = json ? . listtemplatesresponse ? . count
560- })
531+ promises . push ( getAPI ( ' listTemplates ' , { templatefilter : ' self ' , listall : true , page : 1 , pagesize : 1 }))
532+ }
533+
534+ if ( promises . length === 0 ) {
535+ return
561536 }
537+
538+ this .loading = true
539+ Promise .all (promises).then (json => {
540+ let index = 0
541+ if (' listKubernetesClusters' in this .$store .getters .apis ) {
542+ this .data .kubernetes = json[index]? .listkubernetesclustersresponse ? .count || 0
543+ index++
544+ }
545+ if (' listVolumes' in this .$store .getters .apis ) {
546+ this .data .volumes = json[index]? .listvolumesresponse ? .count || 0
547+ index++
548+ }
549+ if (' listSnapshots' in this .$store .getters .apis ) {
550+ this .data .snapshots = json[index]? .listsnapshotsresponse ? .count || 0
551+ index++
552+ }
553+ if (' listNetworks' in this .$store .getters .apis ) {
554+ this .data .networks = json[index]? .listnetworksresponse ? .count || 0
555+ index++
556+ }
557+ if (' listVPCs' in this .$store .getters .apis ) {
558+ this .data .vpcs = json[index]? .listvpcsresponse ? .count || 0
559+ index++
560+ }
561+ if (' listPublicIpAddresses' in this .$store .getters .apis ) {
562+ this .data .ips = json[index]? .listpublicipaddressesresponse ? .count || 0
563+ index++
564+ }
565+ if (' listTemplates' in this .$store .getters .apis ) {
566+ this .data .templates = json[index]? .listtemplatesresponse ? .count || 0
567+ }
568+ }).finally (() => {
569+ this .loading = false
570+ })
562571 },
563572 listInstances () {
564573 if (! (' listVirtualMachines' in this .$store .getters .apis )) {
565574 return
566575 }
567576 this .loading = true
568- getAPI (' listVirtualMachines' , { listall: true , details: ' min' , page: 1 , pagesize: 1 }).then (json => {
569- this .loading = false
570- this .data .instances = json? .listvirtualmachinesresponse ? .count
571- })
572- getAPI (' listVirtualMachines' , { listall: true , details: ' min' , state: ' running' , page: 1 , pagesize: 1 }).then (json => {
573- this .loading = false
574- this .data .running = json? .listvirtualmachinesresponse ? .count
575- })
576- getAPI (' listVirtualMachines' , { listall: true , details: ' min' , state: ' stopped' , page: 1 , pagesize: 1 }).then (json => {
577- this .loading = false
578- this .data .stopped = json? .listvirtualmachinesresponse ? .count
579- })
577+
578+ const promises = [
579+ getAPI (' listVirtualMachines' , { listall: true , details: ' min' , page: 1 , pagesize: 1 }),
580+ getAPI (' listVirtualMachines' , { listall: true , details: ' min' , state: ' running' , page: 1 , pagesize: 1 }),
581+ getAPI (' listVirtualMachines' , { listall: true , details: ' min' , state: ' stopped' , page: 1 , pagesize: 1 })
582+ ]
583+
580584 if (this .isLeaseFeatureEnabled ) {
581- getAPI (' listVirtualMachines' , { leased: true , listall: true , details: ' min' , page: 1 , pagesize: 1 }).then (json => {
582- this .loading = false
583- this .data .leasedinstances = json? .listvirtualmachinesresponse ? .count
584- if (! this .data .leasedinstances ) {
585- this .data .leasedinstances = 0
586- }
587- })
585+ promises .push (getAPI (' listVirtualMachines' , { leased: true , listall: true , details: ' min' , page: 1 , pagesize: 1 }))
588586 }
587+
588+ Promise .all (promises).then (json => {
589+ this .data .instances = json[0 ]? .listvirtualmachinesresponse ? .count || 0
590+ this .data .running = json[1 ]? .listvirtualmachinesresponse ? .count || 0
591+ this .data .stopped = json[2 ]? .listvirtualmachinesresponse ? .count || 0
592+ if (this .isLeaseFeatureEnabled ) {
593+ this .data .leasedinstances = json[3 ]? .listvirtualmachinesresponse ? .count || 0
594+ }
595+ }).finally (() => {
596+ this .loading = false
597+ })
589598 },
590599 listEvents () {
591600 if (! (' listEvents' in this .$store .getters .apis )) {
@@ -596,10 +605,8 @@ export default {
596605 pagesize: 8 ,
597606 listall: true
598607 }
599- this .loading = true
600608 getAPI (' listEvents' , params).then (json => {
601609 this .events = []
602- this .loading = false
603610 if (json && json .listeventsresponse && json .listeventsresponse .event ) {
604611 this .events = json .listeventsresponse .event
605612 }
0 commit comments