From 8471ffc4b9f9ea5270107044111bb6dc23ba7c2c Mon Sep 17 00:00:00 2001
From: "hamza.hramchi" <hamza.hramchi@xelians.fr>
Date: Fri, 14 May 2021 18:20:02 +0200
Subject: [PATCH] FEAT #16992 TIME 1:28 admin: check selected modes of each
 connector

---
 .../app/administration/otp/otp.component.html |  2 +-
 .../app/administration/otp/otp.component.ts   | 43 +++++++++++--------
 2 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/src/frontend/app/administration/otp/otp.component.html b/src/frontend/app/administration/otp/otp.component.html
index 27cbe34622..4903668e0c 100644
--- a/src/frontend/app/administration/otp/otp.component.html
+++ b/src/frontend/app/administration/otp/otp.component.html
@@ -7,7 +7,7 @@
         <ion-title>{{title}}</ion-title>
     </ion-toolbar>
 </ion-header>
-<form style="display: contents;" id="adminForm" (ngSubmit)="onSubmit()" #adminForm="ngForm">
+<form *ngIf="!loading" style="display: contents;" id="adminForm" (ngSubmit)="onSubmit()" #adminForm="ngForm">
     <ion-content>
         <ion-item>
             <ion-label color="secondary" position="floating">{{'lang.label' | translate}} *</ion-label>
diff --git a/src/frontend/app/administration/otp/otp.component.ts b/src/frontend/app/administration/otp/otp.component.ts
index bfae98079f..02683519e9 100644
--- a/src/frontend/app/administration/otp/otp.component.ts
+++ b/src/frontend/app/administration/otp/otp.component.ts
@@ -76,7 +76,7 @@ export class OtpComponent implements OnInit {
     }
 
     ngOnInit(): void {
-        this.route.params.subscribe((params: any) => {
+        this.route.params.subscribe(async (params: any) => {
             if (params['id'] === undefined) {
                 this.creationMode = true;
                 this.title = this.translate.instant('lang.otpConnectorCreation');
@@ -84,28 +84,33 @@ export class OtpComponent implements OnInit {
                 this.connectorClone = JSON.parse(JSON.stringify(this.connector));
             } else {
                 this.creationMode = false;
-
-                this.http.get('../rest/connectors/' + params['id'])
-                    .pipe(
-                        map((data: any) => data.otp),
-                        tap((data: any) => {
-                            this.connector = data;
-                            this.connectorClone = JSON.parse(JSON.stringify(this.connector));
-                            this.title = this.connector.label;
-                        }),
-                        finalize(() => {
-                            this.loading = false;
-                        }),
-                        catchError((err: any) => {
-                            this.notificationService.handleErrors(err);
-                            return of(false);
-                        })
-                    )
-                    .subscribe();
+                await this.getConfig(params['id']);
             }
         });
     }
 
+    getConfig(id: any) {
+        return new Promise((resolve) => {
+            this.http.get('../rest/connectors/' + id)
+                .pipe(
+                    map((data: any) => data.otp),
+                    tap((data: any) => {
+                        this.connector = data;
+                        this.connectorClone = JSON.parse(JSON.stringify(this.connector));
+                        this.title = this.connector.label;
+                    }),
+                    finalize(() => {
+                        this.loading = false;
+                    }),
+                    catchError((err: any) => {
+                        this.notificationService.handleErrors(err);
+                        return of(false);
+                    })
+                )
+                .subscribe();
+        });
+    }
+
     getConnectorTypes() {
         this.connectorTypes = this.otpService.getConnectorTypes().map((item: any) => ({
             id: item,
-- 
GitLab