From 34399ed6413dde119d7a34de2c8d53c5a195c7b2 Mon Sep 17 00:00:00 2001
From: Baptiste Toulemonde <toulemonde@cines.fr>
Date: Thu, 22 Jul 2021 12:45:15 +0200
Subject: [PATCH] add id to dialog

---
 src/app/app.module.ts                         |  2 +-
 src/app/datasets/datasets.component.ts        |  4 +--
 .../datasets/services/dataset-crud.service.ts |  7 ++++-
 src/app/mapping/mapping.component.ts          | 26 ++++++++++++-------
 4 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 72982d943..c40405f3e 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -96,7 +96,7 @@ import { DatasetsDialogComponent } from './datasets/datasets-dialog/datasets-dia
     NbToastrModule.forRoot(),
     NbDialogModule.forRoot(),
   ],
-  entryComponents: [DatasetsDialogComponent],
+  entryComponents: [DatasetsDialogComponent, FeedbackDialogComponent],
   providers: [
     AppConfiguration,
     ParseXmlService,
diff --git a/src/app/datasets/datasets.component.ts b/src/app/datasets/datasets.component.ts
index f80db3dc7..f7db5d4bd 100644
--- a/src/app/datasets/datasets.component.ts
+++ b/src/app/datasets/datasets.component.ts
@@ -56,7 +56,7 @@ export class DatasetsComponent implements OnInit, OnChanges {
   }
 
   ngOnInit() {
-    this.dataSetService.itemsDataset = [];
+    this.dataSetService.resetDataset()
 
   }
 
@@ -315,7 +315,7 @@ export class DatasetsComponent implements OnInit, OnChanges {
     for (const id of datasetId) {
       const requestPromise = this.launchRequest(datasetRequestPathName, datasetRequestHttpMethod, false, id)
         .then((dataset) => {
-          this.dataSetService.saveDatasets(dataset);
+          this.dataSetService.saveDatasets(dataset, id);
         });
       requestPromises.push(requestPromise);
     }
diff --git a/src/app/datasets/services/dataset-crud.service.ts b/src/app/datasets/services/dataset-crud.service.ts
index 0199c6eb7..8bf3cae90 100644
--- a/src/app/datasets/services/dataset-crud.service.ts
+++ b/src/app/datasets/services/dataset-crud.service.ts
@@ -15,6 +15,7 @@ export class DatasetCrudService {
   fds2Token: string = this.sessionStorage.getFDPToken();
   public results: string[] = [];
   itemsDataset: Object[] = [];
+  ids: number[] = [];
   constructor(private http: HttpClient, private appConfig: AppConfiguration, private parserService: ParseXmlService, private sessionStorage: TokenStorageService) { }
 
   
@@ -104,12 +105,16 @@ export class DatasetCrudService {
   getLocally<T = any>(path: string): Observable<T> {
     return this.http.get<T>(`${path}`);
   }
-  saveDatasets(obj: Object) {
+  saveDatasets(obj: Object, id: number) {
     this.itemsDataset.push(obj);
+    this.ids.push(id);
   }
   resetDataset() {
     this.itemsDataset = [];
+    this.ids = [];
   }
 
+  
+
 
 }
diff --git a/src/app/mapping/mapping.component.ts b/src/app/mapping/mapping.component.ts
index 77c68742f..b274ed694 100644
--- a/src/app/mapping/mapping.component.ts
+++ b/src/app/mapping/mapping.component.ts
@@ -32,8 +32,8 @@ export class MappingComponent implements OnInit {
   first: boolean = true;
   loading: boolean = false;
   FDP_URL = environment.fdpUrl;
-  postedDatastes: string[];
-  notPostedDatasets: string[];
+
+  ids: number [];
   @ViewChild('autoInput') input;
   @Input() catalogId: any;
 
@@ -58,6 +58,8 @@ export class MappingComponent implements OnInit {
 
   populatecatalogue() {
     this.itemsdataset = this.dataSetService.itemsDataset;
+    this.ids = this.dataSetService.ids;
+    this.ids
     this.keys = [];
     for (let i = 0; i < this.itemsdataset.length; i++) {
       if (i === 0) {
@@ -82,8 +84,8 @@ export class MappingComponent implements OnInit {
   publishDataset() {
     let data: string = '';
     let properties: string = '';
-    this.postedDatastes = [];
-    this.notPostedDatasets = [];
+    let postedDatastes = [];
+    let notPostedDatasets = [];
     this.loading = true;
     for (let i = 0; i < this.mappedMetadatas.length; i++) {
       let title = "";
@@ -126,21 +128,27 @@ export class MappingComponent implements OnInit {
 
       this.dataSetService.createDataset(data).subscribe(
         (error: Error) => {
-          this.notPostedDatasets.push(title);
+          notPostedDatasets.push(this.ids[i]);
           if (i === this.mappedMetadatas.length - 1) {
             this.loading = false;
+            this.dialog.open(FeedbackDialogComponent, {
+              data: {
+                postedMetadatas: postedDatastes,
+                notPostedMetadatas: notPostedDatasets
+              }
+            }).afterClosed().subscribe(() => this.route.navigateByUrl('/dashboard'));
           }
         },
         () => {
-          this.postedDatastes.push(title);
+          postedDatastes.push(this.ids[i]);
           if (i === this.mappedMetadatas.length - 1) {
             this.loading = false;
             this.dialog.open(FeedbackDialogComponent, {
               data: {
-                postedMetadatas: this.postedDatastes,
-                notPostedMetadatas: this.notPostedDatasets
+                postedMetadatas: postedDatastes,
+                notPostedMetadatas: notPostedDatasets
               }
-            }).afterClosed().subscribe(() => this.route.navigateByUrl('/dashboard'))
+            }).afterClosed().subscribe(() => this.route.navigateByUrl('/dashboard'));
 
           }
 
-- 
GitLab