@@ -508,6 +508,22 @@ export default {
508508 }).then (function () {
509509 })
510510 },
511+ pollActionCompletion (jobId , action ) {
512+ api (' queryAsyncJobResult' , { jobid: jobId }).then (json => {
513+ var result = json .queryasyncjobresultresponse
514+ if (result .jobstatus === 1 ) {
515+ this .fetchData ()
516+ } else if (result .jobstatus === 2 ) {
517+ this .fetchData ()
518+ } else {
519+ this .$message
520+ .loading (this .$t (action .label ) + ' in progress for ' + this .resource .name , 3 )
521+ .then (() => this .pollActionCompletion (jobId, action))
522+ }
523+ }).catch (function (e ) {
524+ console .log (' Error encountered while fetching async job result' + e)
525+ })
526+ },
511527 handleSubmit (e ) {
512528 e .preventDefault ()
513529 this .form .validateFields ((err , values ) => {
@@ -544,12 +560,15 @@ export default {
544560 params .id = this .resource .id
545561 }
546562
563+ var hasJobId = false
547564 api (this .currentAction .api , params).then (json => {
548565 for (const obj in json) {
549566 if (obj .includes (' response' )) {
550567 for (const res in json[obj]) {
551568 if (res === ' jobid' ) {
552569 this .$store .dispatch (' AddAsyncJob' , { title: this .$t (this .currentAction .label ), jobid: json[obj][res], description: this .resource .name , status: ' progress' })
570+ this .pollActionCompletion (json[obj][res], this .currentAction )
571+ hasJobId = true
553572 break
554573 }
555574 }
@@ -558,6 +577,10 @@ export default {
558577 }
559578 if (this .currentAction .icon === ' delete' ) {
560579 this .$router .go (- 1 )
580+ } else {
581+ if (! hasJobId) {
582+ this .fetchData ()
583+ }
561584 }
562585 }).catch (error => {
563586 console .log (error)
@@ -568,12 +591,6 @@ export default {
568591 }).finally (f => {
569592 this .closeAction ()
570593 })
571-
572- // TODO: listen for notification success/fail and refresh
573- const fetchData = this .fetchData
574- setTimeout (function () {
575- fetchData ()
576- }, 2500 )
577594 }
578595 })
579596 },
0 commit comments