@@ -21,7 +21,7 @@ import { NgbdModalConfirmComponent } from 'src/app/_helpers/confirmation-dialog'
2121 selector : 'app-ext-gitops' ,
2222 templateUrl : './ext-gitops.component.html' ,
2323 styleUrls : [
24- '../common/css/detail.component.css' ,
24+ '../common/css/detail.component.css' ,
2525 './ext-gitops.component.css'
2626 ]
2727} )
@@ -54,7 +54,7 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
5454 private readonly toastService : ToastService ,
5555 private readonly modalService : NgbModal ,
5656 private readonly fb : FormBuilder
57- ) {
57+ ) {
5858 this . activatedRoute . parent . params . subscribe ( params => {
5959 this . domainId = params . domainid ;
6060 this . domainName = decodeURIComponent ( params . name ) ;
@@ -83,7 +83,7 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
8383 const dialogRef = this . dialog . open ( GitOpsEnvSelectionComponent , {
8484 width : '400px' ,
8585 minWidth : window . innerWidth < 450 ? '95vw' : '' ,
86- data : {
86+ data : {
8787 excludeEnvironments : this . gitOpsAccounts
8888 . filter ( account => account . ID )
8989 . map ( account => account . environment ) ,
@@ -92,10 +92,7 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
9292 } ) ;
9393
9494 dialogRef . afterClosed ( ) . subscribe ( result => {
95- this . gitOpsAccounts = this . gitOpsAccounts . filter ( account => account . ID ) ;
96- if ( this . gitOpsAccounts . length > 0 ) {
97- this . selectAccount ( this . gitOpsAccounts [ 0 ] ) ;
98- }
95+ this . purgePendingAccounts ( ) ;
9996
10097 if ( result ) {
10198 const account = buildNewGitOpsAccount ( result . environment , this . domainId , this . domainName ) ;
@@ -128,16 +125,30 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
128125 return ;
129126 }
130127
131- this . toastService . showSuccess ( 'GitOps account created successfully' ) ;
132- this . gitOpsSelected . ID = 'new' ;
133- this . selectAccount ( this . gitOpsSelected ) ;
128+ this . gitOpsService . subscribeGitOpsAccount ( this . gitOpsSelected )
129+ . pipe ( takeUntil ( this . unsubscribe ) )
130+ . subscribe ( {
131+ next : data => {
132+ this . selectAccount ( data , false ) ;
133+ this . gitOpsAccounts = this . gitOpsAccounts . map ( account => account . environment === data . environment ? data : account ) ;
134+
135+ this . toastService . showSuccess ( 'GitOps account created successfully' ) ;
136+ } ,
137+ error : ( ) => {
138+ this . toastService . showError ( 'Failed to create GitOps account' ) ;
139+ }
140+ } ) ;
141+ }
142+
143+ onDiscard ( ) : void {
144+ this . purgePendingAccounts ( ) ;
134145 }
135146
136147 onUpdateTokens ( ) : void {
137148 const dialogRef = this . dialog . open ( GitOpsUpdateTokensComponent , {
138149 width : '400px' ,
139150 minWidth : window . innerWidth < 450 ? '95vw' : '' ,
140- data : {
151+ data : {
141152 environments : this . gitOpsAccounts
142153 . filter ( account => account . ID )
143154 . map ( account => account . environment )
@@ -146,7 +157,20 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
146157
147158 dialogRef . afterClosed ( ) . subscribe ( result => {
148159 if ( result ) {
149- this . toastService . showSuccess ( 'GitOps account tokens updated successfully' ) ;
160+ this . gitOpsService . updateGitOpsAccountTokens ( result . token , this . domainId , result . environments )
161+ . pipe ( takeUntil ( this . unsubscribe ) )
162+ . subscribe ( {
163+ next : data => {
164+ if ( data ?. result ) {
165+ this . toastService . showSuccess ( 'GitOps account tokens updated successfully' ) ;
166+ } else {
167+ this . toastService . showError ( 'Failed to update GitOps account tokens: ' + data ?. message ) ;
168+ }
169+ } ,
170+ error : ( ) => {
171+ this . toastService . showError ( 'Failed to update GitOps account tokens' ) ;
172+ }
173+ } ) ;
150174 }
151175 } ) ;
152176 }
@@ -157,13 +181,22 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
157181 modalConfirmation . componentInstance . question = 'Are you sure you want to delete this GitOps account?' ;
158182 modalConfirmation . result . then ( ( result ) => {
159183 if ( result ) {
160- this . gitOpsAccounts . splice ( this . gitOpsAccounts . indexOf ( this . gitOpsSelected ) , 1 ) ;
161-
162- if ( this . gitOpsAccounts . length > 0 ) {
163- this . selectAccount ( this . gitOpsAccounts [ 0 ] ) ;
164- }
165-
166- this . toastService . showSuccess ( 'GitOps account unsubscribed successfully' ) ;
184+ this . gitOpsService . unsubscribeGitOpsAccount ( this . gitOpsSelected )
185+ . pipe ( takeUntil ( this . unsubscribe ) )
186+ . subscribe ( {
187+ next : ( ) => {
188+ this . gitOpsAccounts . splice ( this . gitOpsAccounts . indexOf ( this . gitOpsSelected ) , 1 ) ;
189+
190+ if ( this . gitOpsAccounts . length > 0 ) {
191+ this . selectAccount ( this . gitOpsAccounts [ 0 ] ) ;
192+ }
193+
194+ this . toastService . showSuccess ( 'GitOps account unsubscribed successfully' ) ;
195+ } ,
196+ error : ( ) => {
197+ this . toastService . showError ( 'Failed to unsubscribe GitOps account' ) ;
198+ }
199+ } ) ;
167200 }
168201 } ) ;
169202 }
@@ -174,6 +207,8 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
174207 . subscribe ( {
175208 next : data => {
176209 this . selectAccount ( data , false ) ;
210+ this . gitOpsAccounts = this . gitOpsAccounts . map ( account => account . environment === data . environment ? data : account ) ;
211+
177212 this . toastService . showSuccess ( 'GitOps account refresh command sent successfully' ) ;
178213 } ,
179214 error : ( ) => {
@@ -184,16 +219,17 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
184219
185220 onReload ( ) : void {
186221 this . reloading = true ;
187-
222+
188223 this . gitOpsService . findGitOpsAccount ( this . gitOpsSelected )
189224 . pipe ( takeUntil ( this . unsubscribe ) )
190225 . subscribe ( {
191226 next : data => {
227+ if ( data . length ) {
228+ this . selectAccount ( data [ 0 ] , false ) ;
229+ this . gitOpsAccounts = this . gitOpsAccounts . map ( account => account . environment === data [ 0 ] . environment ? data [ 0 ] : account ) ;
230+ }
231+
192232 setTimeout ( ( ) => {
193- if ( data . length ) {
194- this . selectAccount ( data [ 0 ] , false ) ;
195- }
196-
197233 this . reloading = false ;
198234 } , 5000 ) ;
199235 } ,
@@ -220,7 +256,11 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
220256 }
221257
222258 canRefresh ( ) : boolean {
223- return this . gitOpsSelected . ID && this . gitOpsSelected . domain . lastcommit !== 'refresh' ;
259+ return this . gitOpsSelected . ID && this . gitOpsSelected . domain . lastcommit !== 'refresh' ;
260+ }
261+
262+ canReload ( ) : boolean {
263+ return this . gitOpsSelected . ID ?. length && ! this . reloading ;
224264 }
225265
226266 private formInit ( ) : void {
@@ -242,8 +282,8 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
242282 }
243283
244284 private readFeatureFlag ( ) : void {
245- this . featureService . isEnabled ( {
246- feature : 'GITOPS_INTEGRATION' ,
285+ this . featureService . isEnabled ( {
286+ feature : 'GITOPS_INTEGRATION' ,
247287 parameters : {
248288 value : this . domainId
249289 }
@@ -286,12 +326,12 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
286326 }
287327 } ) ;
288328 }
289- ) ;
329+ ) ;
290330 }
291331
292332 private updateRoute ( ) : void {
293333 if ( this . fetch ) {
294- this . domainRouteService . updatePath ( this . domainId , this . domainName , Types . DOMAIN_TYPE ,
334+ this . domainRouteService . updatePath ( this . domainId , this . domainName , Types . DOMAIN_TYPE ,
295335 `/dashboard/domain/${ this . domainName } /${ this . domainId } ` ) ;
296336 }
297337 }
@@ -336,7 +376,7 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
336376 }
337377
338378 const gitOpsSelectedForm = this . formGroup . value ;
339-
379+
340380 this . gitOpsSelected . repository = gitOpsSelectedForm . repository ;
341381 this . gitOpsSelected . branch = gitOpsSelectedForm . branch ;
342382 this . gitOpsSelected . path = gitOpsSelectedForm . path ;
@@ -347,4 +387,11 @@ export class ExtGitOpsComponent implements OnInit, OnDestroy {
347387
348388 return true ;
349389 }
390+
391+ private purgePendingAccounts ( ) : void {
392+ this . gitOpsAccounts = this . gitOpsAccounts . filter ( account => account . ID ) ;
393+ if ( this . gitOpsAccounts . length > 0 ) {
394+ this . selectAccount ( this . gitOpsAccounts [ 0 ] ) ;
395+ }
396+ }
350397}
0 commit comments