From 243a93943eb52a3dc96d3e516c9455dd264e088e Mon Sep 17 00:00:00 2001
From: Baptiste Toulemonde <toulemonde@cines.fr>
Date: Mon, 19 Jul 2021 11:12:26 +0200
Subject: [PATCH] mapping: upgrade features

---
 .../datasets/services/dataset-crud.service.ts | 11 +---
 src/app/mapping/mapping.component.html        | 15 ++++--
 src/app/mapping/mapping.component.ts          | 53 ++++++++++---------
 src/app/publishapi/publishapi.component.html  |  4 +-
 4 files changed, 44 insertions(+), 39 deletions(-)

diff --git a/src/app/datasets/services/dataset-crud.service.ts b/src/app/datasets/services/dataset-crud.service.ts
index f894912d4..5334b4c92 100644
--- a/src/app/datasets/services/dataset-crud.service.ts
+++ b/src/app/datasets/services/dataset-crud.service.ts
@@ -17,7 +17,7 @@ export class DatasetCrudService {
   itemsDataset: Object[] = [] ;
   constructor(private http: HttpClient,private appConfig: AppConfiguration, private parserService: ParseXmlService, private sessionStorage: TokenStorageService) { }
 
-  createDataSet(data:string){
+  createDataSet(data:string): Observable<Object> {
       if (this.fds2Token) {
         const httpOptions = {
           headers: new HttpHeaders({
@@ -27,14 +27,7 @@ export class DatasetCrudService {
           })
         };
         
-        this.http.post(FDP_URL +"/dataset", data, httpOptions ).subscribe( r => {
-            console.log("resultat: " + JSON.stringify(r));
-        },
-        error => console.error("The repository has not been published: " + error) ,
-        () => console.log("The datasets has benn published")
-        
-        ) ;
-       
+        return this.http.post(FDP_URL +"/dataset", data, httpOptions );
       }
     
     
diff --git a/src/app/mapping/mapping.component.html b/src/app/mapping/mapping.component.html
index cd2e7483b..e1becf1b9 100644
--- a/src/app/mapping/mapping.component.html
+++ b/src/app/mapping/mapping.component.html
@@ -12,7 +12,8 @@
                             <div class="col-4">
 
                                 <nb-form-field>
-                                    <input nbInput fullWidth type="text" value="{{dataset.identifier}}" disabled />
+                                    <input *ngIf=" dataset.identifier !== 'dct:hasVersion'" nbInput fullWidth type="text" value="{{dataset.identifier}} " disabled />
+                                    <input *ngIf=" dataset.identifier === 'dct:hasVersion' " nbInput fullWidth type="text" value="{{dataset.identifier}} *" disabled  />
                                     <button nbSuffix nbTooltip="{{dataset.name}}: {{dataset.usageNote}}"
                                         nbTooltipStatus="info" nbButton status="basic" ghost>
                                         <nb-icon [icon]=" 'question-mark-circle-outline' " pack="eva">
@@ -24,9 +25,14 @@
                             <div class="col-8">
 
                                 <nb-form-field>
-                                    <input #autoInput #{{dataset.identifier}} fullWidth id="{{dataset.identifier}}"
+                                    <input  *ngIf=" dataset.identifier === 'dct:hasVersion' " required #autoInput #{{dataset.identifier}} fullWidth id="{{dataset.identifier}}"
                                         nbInput (input)="onChange()" placeholder="Enter value" [nbAutocomplete]="auto"
-                                        [(ngModel)]="selectedPaths[index]" (focus)="reset()" />
+                                        [(ngModel)]="selectedPaths[index]" (focus)="reset()"  autocomplete="false"/>
+                                        
+                                        <input  *ngIf=" dataset.identifier !== 'dct:hasVersion' "  #autoInput #{{dataset.identifier}} fullWidth id="{{dataset.identifier}}"
+                                        nbInput (input)="onChange()" placeholder="Enter value" [nbAutocomplete]="auto"
+                                        [(ngModel)]="selectedPaths[index]" (focus)="reset()" autocomplete="false"/>
+                                        
 
                                     <nb-autocomplete #auto>
 
@@ -70,7 +76,7 @@
 
                 </nb-list>
                 <div class="row">
-                    <button class="button-center" nbButton status="danger" (click)="mappedMetadatas.splice(index, 1); prev()">Delete datset<nb-icon icon="trash-2-outline">
+                    <button class="button-center" nbButton status="danger" *ngIf=" !first " (click)="mappedMetadatas.splice(index, 1); prev()">Delete datset<nb-icon icon="trash-2-outline">
                         </nb-icon></button>
                 </div>
             </nb-card-body>
@@ -87,6 +93,7 @@
                         <button nbButton (click)=" publishDataset()">Publish</button>
                     </div>
                 </div>
+                
             </nb-card-footer>
         </nb-card>
     </div>
diff --git a/src/app/mapping/mapping.component.ts b/src/app/mapping/mapping.component.ts
index eecf8e06c..e49b91e25 100644
--- a/src/app/mapping/mapping.component.ts
+++ b/src/app/mapping/mapping.component.ts
@@ -3,7 +3,6 @@ import { Component, Input, OnInit, ViewChild } from '@angular/core';
 import { Observable, of } from 'rxjs';
 import { map } from 'rxjs/operators';
 import { environment } from 'src/environments/environment.prod';
-import { AppConfiguration } from '../AppConfiguration';
 import { DatasetCrudService } from '../datasets/services/dataset-crud.service';
 import { Dataset } from './class/dataset';
 
@@ -28,11 +27,12 @@ export class MappingComponent implements OnInit {
   index: number = 0
   first: boolean = true;
   loading: boolean = false;
-  FDP_URL  = environment.fdpUrl;
+  FDP_URL = environment.fdpUrl;
+
   @ViewChild('autoInput') input;
   @Input() catalogId: any;
 
-  constructor(private appConfig: AppConfiguration, private dataSetService: DatasetCrudService) { }
+  constructor(private dataSetService: DatasetCrudService) { }
 
 
   ngOnInit() {
@@ -56,7 +56,7 @@ export class MappingComponent implements OnInit {
   populatecatalogue() {
     this.itemsdataset = this.dataSetService.itemsDataset;
     this.keys = [];
-    for (let i = 0; i< this.itemsdataset.length; i++){
+    for (let i = 0; i < this.itemsdataset.length; i++) {
       if (i === 0) {
         this.getKeysFromMetadata(this.itemsdataset[i], '');
         this.keysMap.set(this.itemsdataset.length, this.keys);
@@ -78,21 +78,23 @@ export class MappingComponent implements OnInit {
 
   }
 
-  
 
-publishDataset() {
-  let data: string = '';
-  let properties: string = '';
 
-  this.mappedMetadatas.forEach((value: Map<string, string>, key: number) => {
-    properties = "";
-    value.forEach( (value: string, key: string) => {
-     
-      properties += key+ ' "' + value + '";\n';
-    })
-   
+  publishDataset() {
+    let data: string = '';
+    let properties: string = '';
+
+    this.mappedMetadatas.forEach((value: Map<string, string>, key: number) => {
+      this.ok = false;
+      this.err  = false;
+      properties = "";
+      value.forEach((value: string, key: string) => {
 
-    data = '\@prefix dcat: <http://www.w3.org/ns/dcat#>.\n\
+        properties += key + ' "' + value + '";\n';
+      })
+
+
+      data = '\@prefix dcat: <http://www.w3.org/ns/dcat#>.\n\
   @prefix dct: <http://purl.org/dc/terms/>.\n\
   @prefix language: <http://id.loc.gov/vocabulary/iso639-1/>.\n\
   @prefix s: <'+ this.FDP_URL + '/>.\n\
@@ -102,12 +104,15 @@ s:new\n\
 a dcat:Dataset, dcat:Resource;\n\
 dct:isPartOf c:'+ this.catalogId + ';\n' + properties + '.';
 
-  console.log('data: ' + data);
-  this.dataSetService.createDataSet(data);
-  })
-  
-}
- 
+      console.log('data: ' + data);
+      this.dataSetService.createDataSet(data).subscribe(
+        () => this.ok = true,
+        error => this.err = true
+      );
+    })
+
+  }
+
 
   private getValue(tab: string[], item: Object): string {
     let obj: Object
@@ -146,10 +151,10 @@ dct:isPartOf c:'+ this.catalogId + ';\n' + properties + '.';
     }
   }
   prev() {
-    if(this.index > 0){
+    if (this.index > 0) {
       this.index -= 1;
     }
-    
+
     this.createDataset(this.itemsdataset[this.index])
     console.log('index = ' + this.index);
   }
diff --git a/src/app/publishapi/publishapi.component.html b/src/app/publishapi/publishapi.component.html
index 1640975f8..29bd36ed7 100644
--- a/src/app/publishapi/publishapi.component.html
+++ b/src/app/publishapi/publishapi.component.html
@@ -292,7 +292,7 @@
         <h4>Use parameters & launch request</h4>
         <app-datasets [openApi]="openApi"></app-datasets>
         <button class="prev-button" nbButton nbStepperPrevious>prev</button>
-        <button class="next-button" nbButton nbStepperNext (click)="initLabelThree = true">next</button>
+        <button class="next-button" nbButton nbStepperNext (click)="initLabelThree=true">next</button>
       </nb-step>
       <nb-step [label]="labelThree" >
         <ng-template #labelThree>Third step</ng-template>
@@ -301,7 +301,7 @@
           Map your metadata schema with DCAT schema
         </p> 
           <app-mapping *ngIf="initLabelThree" [catalogId]="openApi.info['x-catalog-id']"></app-mapping>
-        <button class="prev-button" nbButton nbStepperPrevious (click)="initLabelThree = false">prev</button>
+        <button class="prev-button" nbButton nbStepperPrevious (click)="initLabelThree=false">prev</button>
         <button class="next-button" nbButton disabled nbStepperNext>next</button>
       </nb-step>
       <!--<nb-step [label]="labelFour">
-- 
GitLab