6262 <div class =" form__label" >
6363 <tooltip-label :title =" $t('label.templatename')" :tooltip =" createAutoScaleVmProfileApiParams.templateid.description" />
6464 </div >
65- {{ getTemplateName( templateid) }}
65+ {{ templateName || templateid }}
6666 </div >
6767 </div >
6868 <div class =" form" >
199199 <a-modal
200200 :title =" $t('label.edit.autoscale.vmprofile')"
201201 :visible =" editProfileModalVisible"
202- :afterClose =" closeModal "
202+ :afterClose =" onModalClosed "
203203 :maskClosable =" false"
204204 :closable =" true"
205205 :footer =" null"
284284 </div >
285285 </div >
286286 <div :span =" 24" class =" action-button" >
287- <a-button :loading =" loading" @click =" closeModal " >{{ $t('label.cancel') }}</a-button >
287+ <a-button :loading =" loading" @click =" editProfileModalVisible = false " >{{ $t('label.cancel') }}</a-button >
288288 <a-button :loading =" loading" ref =" submit" type =" primary" @click =" updateAutoScaleVmProfile" >{{ $t('label.ok') }}</a-button >
289289 </div >
290290 </a-modal >
308308
309309<script >
310310import { api } from ' @/api'
311+ import { addProjectFilter } from ' @/utils/util'
311312import { isAdmin , isAdminOrDomainAdmin } from ' @/role'
312313import Status from ' @/components/widgets/Status'
313314import TooltipButton from ' @/components/widgets/TooltipButton'
@@ -338,6 +339,7 @@ export default {
338339 autoscaleuserid: null ,
339340 expungevmgraceperiod: null ,
340341 templateid: null ,
342+ templateName: null ,
341343 serviceofferingid: null ,
342344 userdata: null ,
343345 userdataid: null ,
@@ -422,6 +424,7 @@ export default {
422424 domainid: this .resource .domainid ,
423425 account: this .resource .account
424426 }
427+ addProjectFilter (params, this .resource )
425428 if (isAdmin ()) {
426429 params .templatefilter = ' all'
427430 } else {
@@ -436,6 +439,7 @@ export default {
436439 listall: ' true' ,
437440 issystem: ' false'
438441 }
442+ addProjectFilter (params, this .resource )
439443 if (isAdminOrDomainAdmin ()) {
440444 params .isrecursive = ' true'
441445 }
@@ -446,15 +450,18 @@ export default {
446450 },
447451 fetchData () {
448452 this .loading = true
449- api ( ' listAutoScaleVmProfiles ' , {
453+ const params = {
450454 listAll: true ,
451455 id: this .resource .vmprofileid
452- }).then (response => {
456+ }
457+ addProjectFilter (params, this .resource )
458+ api (' listAutoScaleVmProfiles' , params).then (response => {
453459 this .profileid = response .listautoscalevmprofilesresponse ? .autoscalevmprofile ? .[0 ]? .id
454460 this .autoscaleuserid = response .listautoscalevmprofilesresponse ? .autoscalevmprofile ? .[0 ]? .autoscaleuserid
455461 this .expungevmgraceperiod = response .listautoscalevmprofilesresponse ? .autoscalevmprofile ? .[0 ]? .expungevmgraceperiod
456462 this .serviceofferingid = response .listautoscalevmprofilesresponse ? .autoscalevmprofile ? .[0 ]? .serviceofferingid
457463 this .templateid = response .listautoscalevmprofilesresponse ? .autoscalevmprofile ? .[0 ]? .templateid
464+ this .fetchTemplate (this .templateid )
458465 this .userdata = this .decodeUserData (decodeURIComponent (response .listautoscalevmprofilesresponse ? .autoscalevmprofile ? .[0 ]? .userdata || ' ' ))
459466 this .userdataid = response .listautoscalevmprofilesresponse ? .autoscalevmprofile ? .[0 ]? .userdataid
460467 this .userdataname = response .listautoscalevmprofilesresponse ? .autoscalevmprofile ? .[0 ]? .userdataname
@@ -468,13 +475,24 @@ export default {
468475 this .loading = false
469476 })
470477 },
471- getTemplateName (templateid ) {
472- for (const template of this .templatesList ) {
473- if (template .id === templateid) {
474- return template .name
475- }
478+ fetchTemplate (templateid ) {
479+ if (! templateid) {
480+ this .templateName = null
481+ return
476482 }
477- return ' '
483+ const params = {
484+ id: templateid,
485+ templatefilter: isAdmin () ? ' all' : ' executable'
486+ }
487+ addProjectFilter (params, this .resource )
488+ api (' listTemplates' , params).then (json => {
489+ // Ignore stale responses if templateid changed while this request was in flight.
490+ if (templateid !== this .templateid ) return
491+ this .templateName = json .listtemplatesresponse ? .template ? .[0 ]? .name || templateid
492+ }).catch (() => {
493+ if (templateid !== this .templateid ) return
494+ this .templateName = templateid
495+ })
478496 },
479497 getServiceOfferingName (serviceofferingid ) {
480498 for (const serviceoffering of this .serviceOfferingsList ) {
@@ -576,16 +594,21 @@ export default {
576594 this .$pollJob ({
577595 jobId: response .updateautoscalevmprofileresponse .jobid ,
578596 successMethod : (result ) => {
597+ this .fetchData ()
579598 },
580599 errorMessage: this .$t (' message.update.autoscale.vm.profile.failed' ),
581600 errorMethod : () => {
601+ this .fetchData ()
582602 }
583603 })
584- }).finally (() => {
604+ }).catch (() => {
605+ // fetchData() resets loading once the job completes; reset here only on submit failure.
585606 this .loading = false
586607 })
587608 },
588609 updateAutoScaleVmProfile () {
610+ if (this .loading ) return
611+ this .loading = true
589612 const params = {
590613 id: this .profileid ,
591614 expungevmgraceperiod: this .expungevmgraceperiod ,
@@ -604,21 +627,25 @@ export default {
604627 this .$pollJob ({
605628 jobId: response .updateautoscalevmprofileresponse .jobid ,
606629 successMethod : (result ) => {
630+ this .loading = false
631+ // Closing the modal triggers afterClose -> onModalClosed, which refreshes the data.
632+ this .editProfileModalVisible = false
607633 },
608634 errorMessage: this .$t (' message.update.autoscale.vm.profile.failed' ),
609635 errorMethod : () => {
636+ this .loading = false
610637 }
611638 })
612- }).finally (() => {
639+ }).catch (() => {
613640 this .loading = false
614641 })
615642 },
616643 decodeUserData (userdata ) {
617644 const decodedData = Buffer .from (userdata, ' base64' )
618645 return decodedData .toString (' utf-8' )
619646 },
620- closeModal () {
621- this .editProfileModalVisible = false
647+ onModalClosed () {
648+ this .fetchData ()
622649 }
623650 }
624651}
0 commit comments