From b1d44c9bcc6f52526d435a426d739ec46252a052 Mon Sep 17 00:00:00 2001
From: Baptiste Toulemonde <toulemonde@cines.fr>
Date: Thu, 17 Feb 2022 14:16:44 +0100
Subject: [PATCH] fix autocomplete

---
 src/app/mapping/mapping.component.html |  8 +++----
 src/app/mapping/mapping.component.ts   | 29 +++++++++++---------------
 2 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/src/app/mapping/mapping.component.html b/src/app/mapping/mapping.component.html
index dfc5f8d47..5d697b338 100644
--- a/src/app/mapping/mapping.component.html
+++ b/src/app/mapping/mapping.component.html
@@ -60,15 +60,15 @@
                                             <input *ngIf="!isMandatory(dataset.card)" fullWidth name=" data{{index}}"
                                                 nbInput (ngModelChange)="onModelChange($event)" [nbAutocomplete]="auto"
                                                 [(ngModel)]="selectedPaths[index]" [value]="selectedPaths[index]? selectedPaths[index] : ''" (focus)="reset()" />
-
-                                            <nb-autocomplete #auto > 
-                                                <div *ngIf="!isJsonPath"> 
+                                           
+                                                <nb-autocomplete #auto  > 
                                                     <nb-option  *ngFor="let option of filteredOptions | async"
                                                     [value]="option">
                                                     {{ option }}
                                                 </nb-option>
-                                                </div>
                                             </nb-autocomplete>
+                                            
+                                            
                                         </nb-form-field>
                                     </div>
                                     <div class="col-2" *ngIf="isReplicable(dataset.card) " style="margin-left: 10px;">
diff --git a/src/app/mapping/mapping.component.ts b/src/app/mapping/mapping.component.ts
index d856f73d6..afaaef818 100644
--- a/src/app/mapping/mapping.component.ts
+++ b/src/app/mapping/mapping.component.ts
@@ -6,14 +6,14 @@ import { MatDialog } from '@angular/material/dialog';
 import { Router } from '@angular/router';
 
 
-import { Observable, of, Subscription } from 'rxjs';
+import { Observable, of } from 'rxjs';
 import { map } from 'rxjs/operators';
 import { environment } from 'src/environments/environment';
 import { TokenStorageService } from '../authentication/services/token-storage.service';
 import { DatasetCrudService } from '../datasets/services/dataset-crud.service';
 
 import { Property, DatasetPath, Distribution, ResponseFileTsv, OldProperty } from './class/dataset';
-import { Path, RequestMapping, ResponseMapping } from './class/requestMapping';
+import { Path, RequestMapping } from './class/requestMapping';
 import { FeedbackDialogComponent } from './dialog/feedback-dialog/feedback-dialog.component';
 import { MappingService } from './service/mapping.service';
 import { JSONPath } from 'jsonpath-plus';
@@ -70,7 +70,7 @@ export class MappingComponent implements OnInit {
       console.log(this.itemsdataset)
       this.ids = this.dataSetService.ids;
       this.keys = [];
-      this.type == "Dataverse" ? this.getKeysFromMetadataCustom(this.itemsdataset[0], '') : this.getKeysFromMetadataCustom(this.itemsdataset[0], '');
+      this.getKeysFromMetadataCustom(this.itemsdataset[0], '');
       this.keys = Array.from(new Set(this.keys));
       this.filteredOptions = of(this.keys);
     }
@@ -108,16 +108,14 @@ export class MappingComponent implements OnInit {
     this.itemsdataset = [];
     let requestPromises: Promise<any>[] = [];
     this.urls.forEach((url: string) => {
-      let requestPromise: Promise<void>;
-
-      requestPromise = this.dataSetService.getDcatFromApi(this.catalogId, url)
+      let requestPromise = this.dataSetService.getDcatFromApi(this.catalogId, url)
         .then((response: Response) => {
           response.text()
             .then((text) => {
               this.itemsdataset.push(text);
             });
         });
-
+      requestPromises.push(requestPromise);
     });
     Promise.all(requestPromises).finally(() => this.loading = false);
   }
@@ -161,16 +159,12 @@ export class MappingComponent implements OnInit {
     let requestPromise = this.mappingService.postToFdpFropSmartharvester(this.catalogId, data, this.isJsonPath).then( resp => {
       if (resp) {
         console.log(resp);
-        resp.json().then((data: any) => {
-          console.log(data.message);
-          data.publishedUrl.forEach(e => postedDatasets.push(e));
-          data.notPublishedUrl.forEach(e => notPostedDatasets.push(e));
+        resp.json().then((datas: any) => {
+          console.log(datas.message);
+          datas.publishedUrl.forEach(e => postedDatasets.push(e));
+          datas.notPublishedUrl.forEach(e => notPostedDatasets.push(e));
         });
       }
-    
-      /*const location = resp.headers.get("location");
-      const datasetId = location.substring(location.search("dataset/") + 8, location.length);*/
-
     });
     requestPromises.push(requestPromise);
 
@@ -602,10 +596,10 @@ private getValueJsonPath(jsonPath: string, item: Object) {
     );
   }
   onModelChange(value: string) {
-    this.filteredOptions = of(this.filter(value));
+    if (!this.isJsonPath) this.filteredOptions = of(this.filter(value));
   }
   reset() {
-    this.filteredOptions = of(this.keys);
+    if (!this.isJsonPath) this.filteredOptions = of(this.keys);
   }
 
   toggle(checked: boolean) {
@@ -614,6 +608,7 @@ private getValueJsonPath(jsonPath: string, item: Object) {
 
   toggleJsonPath(checked: boolean) {
     this.isJsonPath = checked;
+    if (this.isJsonPath) this.filteredOptions = of([]);
   }
 
   toggleDistri(checked: boolean) {
-- 
GitLab