From ec1e7aa896bc052865e082bc29a012001d87d2a6 Mon Sep 17 00:00:00 2001
From: naji <naji@cines.fr>
Date: Wed, 29 Sep 2021 10:27:39 +0200
Subject: [PATCH] =?UTF-8?q?fix:=20ajouter=20m=C3=A9tadonn=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../pastis/src/app/main/main.component.ts        |  3 ++-
 .../profile/edit-profile/classes/file-node.ts    |  2 +-
 .../file-tree-metadata.component.ts              | 16 +++++++++++++++-
 .../file-tree/file-tree.component.ts             |  9 +++++----
 .../add-metadata/add-metadata.component.html     |  2 +-
 .../add-metadata/add-metadata.component.ts       | 11 ++++-------
 6 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/ui/ui-frontend/projects/pastis/src/app/main/main.component.ts b/ui/ui-frontend/projects/pastis/src/app/main/main.component.ts
index 472f719f0..031da7645 100644
--- a/ui/ui-frontend/projects/pastis/src/app/main/main.component.ts
+++ b/ui/ui-frontend/projects/pastis/src/app/main/main.component.ts
@@ -111,7 +111,8 @@ export class MainComponent implements OnInit, OnDestroy {
   }
 
   insertionItem($event: FileNodeInsertParams) {
-    this.editProfileComponent.fileTreeComponent.insertItem($event.node, $event.elementsToAdd);
+    let names: string[] = $event.elementsToAdd.map(e => e.Name);
+    this.editProfileComponent.fileTreeComponent.insertItem($event.node, names);
     console.log("Params : ", $event);
   }
 
diff --git a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/classes/file-node.ts b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/classes/file-node.ts
index 2a0f23a3f..d83cfd4ca 100644
--- a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/classes/file-node.ts
+++ b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/classes/file-node.ts
@@ -114,7 +114,7 @@ export interface FileNode {
 
 export interface FileNodeInsertParams {
   node: FileNode;
-  elementsToAdd:string[];
+  elementsToAdd:SedaData[];
 }
 
 export interface FileNodeInsertAttributeParams {
diff --git a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.ts b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.ts
index 6a5140c12..bbe427529 100644
--- a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.ts
+++ b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.ts
@@ -422,9 +422,23 @@ export class FileTreeMetadataComponent {
   onAddNode() {
     if (this.clickedNode.name === 'DescriptiveMetadata') {
       console.log("Yes")
+      let elements: SedaData[];
+      elements.push({
+        Name: 'ArchiveUnit',
+        NameFr: null,
+        Type: null,
+        Element:null,
+        Cardinality:null,
+        Definition:null,
+        Extensible:null,
+        Choice:null,
+        Children: null,
+        Enumeration:null,
+        Collection: null
+      });
       let params: FileNodeInsertParams = {
         node: this.clickedNode,
-        elementsToAdd: ['ArchiveUnit']
+        elementsToAdd: elements
       }
       this.insertItem.emit(params);
       this.notificationService.showSuccess(this.notificationAjoutMetadonnee);
diff --git a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree/file-tree.component.ts b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree/file-tree.component.ts
index dfb24a75e..f7ea8a56a 100644
--- a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree/file-tree.component.ts
+++ b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree/file-tree.component.ts
@@ -265,13 +265,14 @@ export class FileTreeComponent implements OnDestroy {
     dataToSendToPopUp.cancelLabel = this.popupAddCancelLabel;
     dataToSendToPopUp.component = UserActionAddMetadataComponent;
     dataToSendToPopUp.disableBtnOuiOnInit = true;
-    const elementsToAdd = <string[]>await this.fileService.openPopup(dataToSendToPopUp);
+    const elementsToAdd = <SedaData[]>await this.fileService.openPopup(dataToSendToPopUp);
+    let names: string[] = elementsToAdd.map(e => e.Name);
     if (elementsToAdd) {
       //this.sedaService.selectedSedaNode.next(sedaNode);
-      this.insertItem(node, elementsToAdd);
+      this.insertItem(node, names);
       elementsToAdd.length > 1 ?
-        this.loggingService.showSuccess(this.notificationAddMetadonneePOne + " " + elementsToAdd.join(', ') + this.notificationAddMetadonneePTwo) :
-        this.loggingService.showSuccess(this.notificationAddmetadonneeSOne + " " + elementsToAdd + " " + this.notificationAddmetadonneeSTwo)
+        this.loggingService.showSuccess(this.notificationAddMetadonneePOne + " " + names.join(', ') + this.notificationAddMetadonneePTwo) :
+        this.loggingService.showSuccess(this.notificationAddmetadonneeSOne + " " + names + " " + this.notificationAddmetadonneeSTwo)
     }
   }
 
diff --git a/ui/ui-frontend/projects/pastis/src/app/user-actions/add-metadata/add-metadata.component.html b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-metadata/add-metadata.component.html
index 2e6bf3ae2..228484030 100644
--- a/ui/ui-frontend/projects/pastis/src/app/user-actions/add-metadata/add-metadata.component.html
+++ b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-metadata/add-metadata.component.html
@@ -33,7 +33,7 @@
             <mat-list *ngFor="let element of allowedChildren | filterByName:filterName:sedaLanguage;"
                              class="list-item">
                             <span class="list-box-content">
-                                <i id ="pastis-ico-complex-element" *ngIf="isElementComplex(element.Name)" class="vitamui-icon vitamui-icon-complex-element-1-1">
+                                <i id ="pastis-ico-complex-element" *ngIf="isElementComplex(element)" class="vitamui-icon vitamui-icon-complex-element-1-1">
                                   <span class="path1"></span><span class="path2"></span>
                                   <span class="path3"></span><span class="path4"></span>
                                   <span class="path5"></span>
diff --git a/ui/ui-frontend/projects/pastis/src/app/user-actions/add-metadata/add-metadata.component.ts b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-metadata/add-metadata.component.ts
index bf56455f3..c4244484a 100644
--- a/ui/ui-frontend/projects/pastis/src/app/user-actions/add-metadata/add-metadata.component.ts
+++ b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-metadata/add-metadata.component.ts
@@ -129,10 +129,9 @@ export class UserActionAddMetadataComponent implements OnInit {
   }
 
   onAddSelectedElement(element: SedaData){
-    let sedaNode = this.sedaService.findSedaChildByName(element.Name, this.sedaNodeFound);
       this.addedItems.push(element);
 
-      if (sedaNode.Cardinality !== (SedaCardinalityConstants.zeroOrMore || SedaCardinalityConstants.oreOrMore)) {
+      if (element.Cardinality !== (SedaCardinalityConstants.zeroOrMore || SedaCardinalityConstants.oreOrMore)) {
         this.allowedChildren = this.allowedChildren.filter(e => e != element);
       }
       this.addedItems.length > 0 ? this.atLeastOneIsSelected = true : this.atLeastOneIsSelected = false
@@ -148,15 +147,13 @@ export class UserActionAddMetadataComponent implements OnInit {
     return this.allowedChildren.length === this.addedItems.length;
   }
 
-  isElementComplex(elementName: string){
-    let childFound = this.allowedChildren.find(el=> el.Name === elementName);
-    if (childFound){
-      return childFound.Element === SedaElementConstants.complex;
+  isElementComplex(element: SedaData){
+    if (element){
+      return element.Element === SedaElementConstants.complex;
     }
   }
 
   getDefinition(element:SedaData):string {
-
     return element ? element.Definition : '';
   }
 
-- 
GitLab