@@ -31,52 +31,62 @@ export class RegistrySettingsModalComponent implements OnInit {
3131
3232 public confirm ( ) {
3333 this . loading = true ;
34+ this . dialogRef . disableClose = true ;
35+
3436 this . registryFormGroup . disable ( ) ;
35- let obs : Observable < any > ;
37+ let obs : Observable < any > = of ( null ) ;
3638
37- const registrySettings = this . registryFormGroup . getRawValue ( ) as DockerRegistrySettings ;
39+ const credentialsNeedTesting = this . registryFormGroup . get ( 'username' ) . dirty
40+ || this . registryFormGroup . get ( 'url' ) . dirty
41+ || this . registryFormGroup . get ( 'password' ) . dirty ;
3842
39- if ( registrySettings . isDockerHub ) {
40- const username = registrySettings . username ;
41- const password = registrySettings . password ;
42- if ( username ) {
43- obs = this . dockerHub . logIn ( username , password )
43+ if ( ! credentialsNeedTesting ) {
44+ // If username/password did not change, do not revalidate them
45+ this . registryFormGroup . enable ( ) ;
46+ this . dialogRef . close ( this . registryFormGroup ) ;
47+ } else {
48+ const registrySettings = this . registryFormGroup . getRawValue ( ) as DockerRegistrySettings ;
49+ if ( registrySettings . isDockerHub ) {
50+ const username = registrySettings . username ;
51+ const password = registrySettings . password ;
52+ if ( username ) {
53+ obs = this . dockerHub . logIn ( username , password )
54+ . pipe ( catchError ( ( error : HttpErrorResponse ) => {
55+ this . notification . open ( error . error . detail || error . message , null , {
56+ panelClass : 'tim-bg-warn'
57+ } ) ;
58+ return throwError ( error ) ;
59+ } ) ) ;
60+ } else {
61+ obs = of ( null ) ;
62+ }
63+ } else {
64+ obs = this . registry . testRegistrySettings ( registrySettings )
4465 . pipe ( catchError ( ( error : HttpErrorResponse ) => {
45- this . notification . open ( error . error . detail || error . message , null , {
66+ this . notification . open ( error . error || error . message , null , {
4667 panelClass : 'tim-bg-warn'
4768 } ) ;
4869 return throwError ( error ) ;
4970 } ) ) ;
50- } else {
51- obs = of ( null ) ;
5271 }
53- } else {
54- obs = this . registry . testRegistrySettings ( registrySettings )
55- . pipe ( catchError ( ( error : HttpErrorResponse ) => {
56- this . notification . open ( error . error || error . message , null , {
57- panelClass : 'tim-bg-warn'
72+ obs
73+ . pipe ( take ( 1 ) )
74+ . subscribe ( ( ) => {
75+ this . registryFormGroup . enable ( ) ;
76+ this . dialogRef . close ( this . registryFormGroup ) ;
77+ this . notification . open ( 'Login succeded' , null , {
78+ panelClass : 'tim-bg-primary'
5879 } ) ;
59- return throwError ( error ) ;
60- } ) ) ;
61- }
62-
63- obs
64- . pipe ( take ( 1 ) )
65- . subscribe ( ( ) => {
66- this . registryFormGroup . enable ( ) ;
67- this . dialogRef . close ( this . registryFormGroup ) ;
68- this . notification . open ( 'Login succeded' , null , {
69- panelClass : 'tim-bg-primary'
70- } ) ;
71- } , error => {
72- this . loading = false ;
73- this . registryFormGroup . enable ( ) ;
80+ } , error => {
81+ this . loading = false ;
82+ this . registryFormGroup . enable ( ) ;
7483
75- if ( this . registryFormGroup . value . isDockerHub ) {
76- this . registryFormGroup . get ( 'url' ) . disable ( ) ;
77- }
84+ if ( this . registryFormGroup . value . isDockerHub ) {
85+ this . registryFormGroup . get ( 'url' ) . disable ( ) ;
86+ }
7887
79- console . error ( error ) ;
80- } ) ;
88+ console . error ( error ) ;
89+ } ) ;
90+ }
8191 }
8292}
0 commit comments