From 7226fe231867ffef6e6b03296e89c7ea6fb18627 Mon Sep 17 00:00:00 2001
From: Hugo <hnouts.dev@gmail.com>
Date: Mon, 26 Jul 2021 15:26:16 +0200
Subject: [PATCH] sonar fix + loader circle while locating user

---
 .../structure-print-header.component.ts       |  2 +-
 .../orientation-form.component.html           |  7 +++--
 .../orientation-form.component.scss           |  4 +++
 .../orientation-form.component.ts             | 26 +++++++++++--------
 4 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/src/app/form/orientation-form/component/structure-print-header/structure-print-header.component.ts b/src/app/form/orientation-form/component/structure-print-header/structure-print-header.component.ts
index 5e6ed970b..20c827dec 100644
--- a/src/app/form/orientation-form/component/structure-print-header/structure-print-header.component.ts
+++ b/src/app/form/orientation-form/component/structure-print-header/structure-print-header.component.ts
@@ -36,7 +36,7 @@ export class StructurePrintHeaderComponent implements OnInit {
       minute: 'numeric',
     });
 
-    this.filters.map((elem) => {
+    this.filters.forEach((elem) => {
       switch (elem.name) {
         case 'proceduresAccompaniment':
           this.assistances.push(elem);
diff --git a/src/app/form/orientation-form/orientation-form.component.html b/src/app/form/orientation-form/orientation-form.component.html
index ec209f992..bcb1bfd7d 100644
--- a/src/app/form/orientation-form/orientation-form.component.html
+++ b/src/app/form/orientation-form/orientation-form.component.html
@@ -229,15 +229,18 @@
             (selectedAddress)="setAddressBeneficiary($event)"
           ></app-address-autocomplete>
           <app-svg-icon
-            *ngIf="getOrientationControl('address').valid"
+            *ngIf="getOrientationControl('address').valid && !isLoading"
             [iconClass]="'validation'"
             [type]="'form'"
             [icon]="'validate'"
             class="validateIcon"
           ></app-svg-icon>
-          <div *ngIf="!getOrientationControl('address').valid" (click)="getAddress()">
+          <div *ngIf="!getOrientationControl('address').valid && !isLoading" (click)="getAddress()">
             <app-svg-icon [type]="'ico'" [icon]="'locateMe'" class="markerIcon"></app-svg-icon>
           </div>
+          <div *ngIf="isLoading">
+            <img class="loader-gif" src="/assets/gif/loader_circle.gif" alt />
+          </div>
         </div>
       </div>
       <div class="title">
diff --git a/src/app/form/orientation-form/orientation-form.component.scss b/src/app/form/orientation-form/orientation-form.component.scss
index 7fd2cb3df..315456fee 100644
--- a/src/app/form/orientation-form/orientation-form.component.scss
+++ b/src/app/form/orientation-form/orientation-form.component.scss
@@ -136,3 +136,7 @@
   @media #{$large-phone} {
   }
 }
+
+.loader-gif {
+  width: 20%;
+}
diff --git a/src/app/form/orientation-form/orientation-form.component.ts b/src/app/form/orientation-form/orientation-form.component.ts
index e2563d09f..c5c8c8d35 100644
--- a/src/app/form/orientation-form/orientation-form.component.ts
+++ b/src/app/form/orientation-form/orientation-form.component.ts
@@ -27,6 +27,7 @@ export class OrientationFormComponent implements OnInit {
   public locate = false;
   public noPassNumeric = false;
   public isMapPhone = false;
+  public isLoading = false;
 
   public orientationForm: FormGroup;
 
@@ -372,7 +373,7 @@ export class OrientationFormComponent implements OnInit {
   }
 
   public removeDoublonFilters(): void {
-    this.uncheckedFilters.map((elem) => {
+    this.uncheckedFilters.forEach((elem) => {
       this.filters = this.filters.filter((filter) => filter.value != elem.value);
     });
     this.setStructuresAndCoord();
@@ -380,7 +381,7 @@ export class OrientationFormComponent implements OnInit {
 
   public findEquipmentName(equipment): string {
     let name;
-    this.equipmentReferentiel.modules.map((elem) => {
+    this.equipmentReferentiel.modules.forEach((elem) => {
       if (elem.id === equipment) {
         name = elem.text;
       }
@@ -390,7 +391,7 @@ export class OrientationFormComponent implements OnInit {
 
   public findAssistanceName(skill): string {
     let name;
-    this.assistanceReferentiel.modules.map((elem) => {
+    this.assistanceReferentiel.modules.forEach((elem) => {
       if (elem.id === skill) {
         name = elem.text;
       }
@@ -401,31 +402,31 @@ export class OrientationFormComponent implements OnInit {
 
   public findTrainingCategoryForSkill(skill): any {
     let infos = { categ: '', name: '' };
-    this.baseSkillssReferentiel.modules.map((elem) => {
+    this.baseSkillssReferentiel.modules.forEach((elem) => {
       if (elem.id === skill) {
         infos.categ = this.baseSkillssReferentiel.id;
         infos.name = elem.text;
       }
     });
-    this.accessRightsReferentiel.modules.map((elem) => {
+    this.accessRightsReferentiel.modules.forEach((elem) => {
       if (elem.id === skill) {
         infos.categ = this.accessRightsReferentiel.id;
         infos.name = elem.text;
       }
     });
-    this.parentingHelpsReferentiel.modules.map((elem) => {
+    this.parentingHelpsReferentiel.modules.forEach((elem) => {
       if (elem.id === skill) {
         infos.categ = this.parentingHelpsReferentiel.id;
         infos.name = elem.text;
       }
     });
-    this.socialAndProfessionalsReferentiel.modules.map((elem) => {
+    this.socialAndProfessionalsReferentiel.modules.forEach((elem) => {
       if (elem.id === skill) {
         infos.categ = this.socialAndProfessionalsReferentiel.id;
         infos.name = elem.text;
       }
     });
-    this.digitalCultureSecuritysReferentiel.modules.map((elem) => {
+    this.digitalCultureSecuritysReferentiel.modules.forEach((elem) => {
       if (elem.id === skill) {
         infos.categ = this.digitalCultureSecuritysReferentiel.id;
         infos.name = elem.text;
@@ -510,16 +511,19 @@ export class OrientationFormComponent implements OnInit {
 
   public getAddress(): void {
     navigator.geolocation.getCurrentPosition((position) => {
+      this.isLoading = true;
       this.geoJsonService.getAddressByCoord(position.coords.longitude, position.coords.latitude).subscribe(
         (location) => {
-          location.properties.housenumber
-            ? this.getOrientationControl('address').get('numero').setValue(location.properties.housenumber)
-            : null;
+          if (location.properties.housenumber) {
+            this.getOrientationControl('address').get('numero').setValue(location.properties.housenumber);
+          }
           this.getOrientationControl('address').get('street').setValue(location.properties.street);
           this.getOrientationControl('address').get('commune').setValue(location.properties.city);
           this.setValidationsForm();
+          this.isLoading = false;
         },
         (err) => {
+          this.isLoading = false;
           throw new Error(err);
         }
       );
-- 
GitLab