From 987761cc2a50000aefd391153b11021fd890cbb6 Mon Sep 17 00:00:00 2001
From: naji <naji@cines.fr>
Date: Tue, 8 Mar 2022 15:51:03 +0100
Subject: [PATCH] =?UTF-8?q?Work=20in=20progress=20=09=20-=20new=20dto=20pu?=
 =?UTF-8?q?aData=20=09=20-=20modification=20back=20pastis=20pour=20prioris?=
 =?UTF-8?q?e=20les=20controls=20pua=20sur=20les=20enumeration=20=09=20-=20?=
 =?UTF-8?q?maquette=20controle=20schemas=20non=20termin=C3=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../common/service/PuaPastisValidator.java    |  18 +-
 .../pastis/src/app/models/file-node.ts        |   4 +-
 .../pastis/src/app/models/pua-data.ts         |  12 ++
 .../file-tree-metadata.component.html         |   7 +-
 .../file-tree-metadata.component.ts           |  20 +-
 .../add-pua-control.component.html            |  48 +++++
 .../add-pua-control.component.scss            |   6 +
 .../add-pua-control.component.ts              | 174 ++++++++++++++++++
 .../app/user-actions/user-actions.module.ts   |   5 +-
 9 files changed, 279 insertions(+), 15 deletions(-)
 create mode 100644 ui/ui-frontend/projects/pastis/src/app/models/pua-data.ts
 create mode 100644 ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.html
 create mode 100644 ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.scss
 create mode 100644 ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.ts

diff --git a/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaPastisValidator.java b/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaPastisValidator.java
index 0b8df5805..14ffa7354 100644
--- a/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaPastisValidator.java
+++ b/api/api-pastis/pastis-commons/src/main/java/fr/gouv/vitamui/pastis/common/service/PuaPastisValidator.java
@@ -619,13 +619,17 @@ public class PuaPastisValidator {
             puaMetadataDetails.setMinItems(0);
             puaMetadataDetails.setMaxItems(1);
         }
-        if (!sedaElement.getEnumeration().isEmpty() && el.getValue() == null) {
-            puaMetadataDetails.setEnums(sedaElement.getEnumeration());
-        }
-        if (el.getValue() != null) {
-            ArrayList<String> list = new ArrayList<>();
-            list.add(el.getValue());
-            puaMetadataDetails.setEnums(list);
+        if(el.getPuaData() != null && el.getPuaData().getEnum() != null){
+            puaMetadataDetails.setEnums(el.getPuaData().getEnum());
+        }else{
+            if (!sedaElement.getEnumeration().isEmpty() && el.getValue() == null) {
+                puaMetadataDetails.setEnums(sedaElement.getEnumeration());
+            }
+            if (el.getValue() != null) {
+                ArrayList<String> list = new ArrayList<>();
+                list.add(el.getValue());
+                puaMetadataDetails.setEnums(list);
+            }
         }
 
     }
diff --git a/ui/ui-frontend/projects/pastis/src/app/models/file-node.ts b/ui/ui-frontend/projects/pastis/src/app/models/file-node.ts
index 29959356a..ac97385d4 100644
--- a/ui/ui-frontend/projects/pastis/src/app/models/file-node.ts
+++ b/ui/ui-frontend/projects/pastis/src/app/models/file-node.ts
@@ -35,7 +35,7 @@ same conditions as regards security.
 The fact that you are presently reading this means that you have had
 knowledge of the CeCILL-C license and that you accept its terms.
 */
-import { PUA } from './pua.model';
+import { PuaData } from './pua-data';
 import { SedaData } from './seda-data';
 
 /**
@@ -109,7 +109,7 @@ export interface FileNode {
   children: FileNode[];
   parent: FileNode;
   sedaData: SedaData;
-  puaData?: PUA;
+  puaData?: PuaData;
 }
 
 export interface FileNodeInsertParams {
diff --git a/ui/ui-frontend/projects/pastis/src/app/models/pua-data.ts b/ui/ui-frontend/projects/pastis/src/app/models/pua-data.ts
new file mode 100644
index 000000000..62508789f
--- /dev/null
+++ b/ui/ui-frontend/projects/pastis/src/app/models/pua-data.ts
@@ -0,0 +1,12 @@
+
+export interface PuaData {
+  additionalProperties: boolean;
+  Enum: string[];
+  pattern: string;
+  minLenght: number;
+  maxLenght: number;
+  minimum: number;
+  maximum: number;
+  exclusiveMinimum: boolean;
+  exclusiveMaximum: boolean;
+}
diff --git a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.html b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.html
index a941f1fdc..69de274cc 100644
--- a/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.html
+++ b/ui/ui-frontend/projects/pastis/src/app/profile/edit-profile/file-tree-metadata/file-tree-metadata.component.html
@@ -203,10 +203,11 @@
                 </button>
 
                 <!-- Contrôle de métadonées => PUA -->
-                <mat-divider *ngIf="this.profileService.profileMode === 'PUA' && !isElementComplex(element.nomDuChamp)"
+                <mat-divider
+                  *ngIf="this.profileService.profileMode === 'PUA' && !isElementComplex(element.nomDuChamp)"
                   style="border-top-color:#E0E0E0;">
                 </mat-divider>
-                <button *ngIf="this.profileService.profileMode === 'PUA' && !isElementComplex(element.nomDuChamp)"
+                <button (click)="onEditControlClick(element.id)" *ngIf="this.profileService.profileMode === 'PUA' && !isElementComplex(element.nomDuChamp)"
                   mat-menu-item>
                   <mat-icon style="color:#757575"><i class="vitamui-icon vitamui-icon-ic24-PUA"></i></mat-icon>
                   <span class="text normal">{{'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA.CONTROLE_METADONNEE' |
@@ -299,4 +300,4 @@
     </ng-template>
 
   </mat-sidenav-content>
-</mat-sidenav-container>
\ No newline at end of file
+</mat-sidenav-container>
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 0e256894e..7bdf05f46 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
@@ -68,6 +68,7 @@ import {CardinalityValues, MetadataHeaders} from '../../../models/models';
 import {NotificationService} from '../../../core/services/notification.service';
 import {PastisDialogData} from '../../../shared/pastis-dialog/classes/pastis-dialog-data';
 import {environment} from 'projects/pastis/src/environments/environment';
+import {UserActionAddPuaControlComponent} from '../../../user-actions/add-pua-control/add-pua-control.component';
 
 
 const FILE_TREE_METADATA_TRANSLATE_PATH = 'PROFILE.EDIT_PROFILE.FILE_TREE_METADATA';
@@ -191,7 +192,7 @@ export class FileTreeMetadataComponent {
 
   constructor(private fileService: FileService, private fileMetadataService: FileTreeMetadataService,
     private sedaService: SedaService, private fb: FormBuilder, private notificationService: NotificationService,
-    private router: Router, private startupService: StartupService, public profileService: ProfileService, 
+    private router: Router, private startupService: StartupService, public profileService: ProfileService,
     private fileTreeService:FileTreeService, private metadataLanguageService: PastisPopupMetadataLanguageService,
     private translateService: TranslateService) {
 
@@ -522,6 +523,23 @@ export class FileTreeMetadataComponent {
     }
   }
 
+  async onEditControlClick(fileNodeId: number) {
+    alert(fileNodeId)
+    let popData = {} as PastisDialogData;
+    if (fileNodeId) {
+      popData.fileNode = this.fileService.findChildById(fileNodeId, this.clickedNode);
+      popData.titleDialog = "Veuillez séléctionner un ou plusieurs contrôles";
+      popData.subTitleDialog = "Ajouter des contrôles supplémentaires à Title";
+      popData.width = '1120px';
+      popData.component = UserActionAddPuaControlComponent
+      popData.okLabel = 'AJOUTER LES CONTROLES'
+      popData.cancelLabel = this.popupAnnuler
+
+      let popUpAnswer = <AttributeData[]>await this.fileService.openPopup(popData);
+      console.log("The answer for edit attributte was ", popUpAnswer);
+    }
+  }
+
   onDeleteNode(nodeId: number) {
     const nodeToDelete = this.fileService.getFileNodeById(this.fileService.nodeChange.getValue(), nodeId);
     this.removeNode.emit(nodeToDelete)
diff --git a/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.html b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.html
new file mode 100644
index 000000000..f847c09e8
--- /dev/null
+++ b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.html
@@ -0,0 +1,48 @@
+<div>
+  <!-- The selected items -->
+  <div *ngIf="addedItems?.length > 0" class="pastis-container-selected-items">
+    <div *ngFor="let item of addedItems;let i =index" style="display: inline-flex">
+      <div class="selected-items-box">
+                <span style="padding: 12px;">
+                  <span class="item-text">{{item}}</span>
+                </span>
+        <mat-divider class="selected-items-separator" vertical></mat-divider>
+        <span (click)="onRemoveSelectedElement(item)" class="selected-items-close">&times;</span>
+      </div>
+    </div>
+  </div>
+
+  <!-- The list of items to be selected-->
+  <mat-list *ngIf="allowedChildren?.length; else noItemsLeftToAdd" class="list-box-head">
+        <span class="list-box-content-title">
+          <span [ngStyle]="{'margin-top': atLeastOneIsSelected ? '40px' : '0px'}"
+                class="paragraph-metadata-subtitle">Les contrôles à ajouter</span>
+          <i class="vitamui-icon vitamui-icon-chevron-down" style="margin-left: 20px; font-weight: bold;"></i>
+        </span>
+    <i class="vita"></i>
+    <mat-divider class="pastis-popup-separator"></mat-divider>
+    <mat-selection-list [disableRipple]="true"
+                        [ngModel]="addedItems" class="list-box">
+      <mat-list *ngFor="let element of allowedChildren"
+                class="list-item">
+                            <span class="list-box-content">
+                                <span
+                                  [matTooltipShowDelay]="0"
+                                  class="text medium"
+                                  matTooltip={{getDefinition(element)}}
+                                  matTooltipClass="pastis-tooltip-class"
+                                  placement="right">{{element}}</span>
+                            </span>
+        <span (click)="onAddSelectedElement(element)" class="ajouter">{{'USER_ACTION.ADD_METADATA.BOUTON_AJOUTER' | translate}}</span>
+        <mat-divider class="pastis-popup-separator"></mat-divider>
+
+      </mat-list>
+    </mat-selection-list>
+  </mat-list>
+
+  <ng-template #noItemsLeftToAdd>
+    <p class="paragraph-metadata-subtitle" style="margin-top: 40px;">
+      {{'USER_ACTION.ADD_METADATA.MESSAGE_PLUS_METADONNEE' | translate}}</p>
+  </ng-template>
+
+</div>
diff --git a/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.scss b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.scss
new file mode 100644
index 000000000..1e5ec2b22
--- /dev/null
+++ b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.scss
@@ -0,0 +1,6 @@
+@import '../add-metadata/add-metadata.component.scss';
+
+
+.pastis-container-selected-items{
+  margin-top: 10px;
+}
diff --git a/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.ts b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.ts
new file mode 100644
index 000000000..92bece8b2
--- /dev/null
+++ b/ui/ui-frontend/projects/pastis/src/app/user-actions/add-pua-control/add-pua-control.component.ts
@@ -0,0 +1,174 @@
+/*
+Copyright © CINES - Centre Informatique National pour l'Enseignement Supérieur (2020)
+
+[dad@cines.fr]
+
+This software is a computer program whose purpose is to provide
+a web application to create, edit, import and export archive
+profiles based on the french SEDA standard
+(https://redirect.francearchives.fr/seda/).
+
+
+This software is governed by the CeCILL-C  license under French law and
+abiding by the rules of distribution of free software.  You can  use,
+modify and/ or redistribute the software under the terms of the CeCILL-C
+license as circulated by CEA, CNRS and INRIA at the following URL
+"http://www.cecill.info".
+
+As a counterpart to the access to the source code and  rights to copy,
+modify and redistribute granted by the license, users are provided only
+with a limited warranty  and the software's author,  the holder of the
+economic rights,  and the successive licensors  have only  limited
+liability.
+
+In this respect, the user's attention is drawn to the risks associated
+with loading,  using,  modifying and/or developing or reproducing the
+software by the user in light of its specific status of free software,
+that may mean  that it is complicated to manipulate,  and  that  also
+therefore means  that it is reserved for developers  and  experienced
+professionals having in-depth computer knowledge. Users are therefore
+encouraged to load and test the software's suitability as regards their
+requirements in conditions enabling the security of their systems and/or
+data to be ensured and,  more generally, to use and operate it in the
+same conditions as regards security.
+
+The fact that you are presently reading this means that you have had
+knowledge of the CeCILL-C license and that you accept its terms.
+*/
+import { Component, OnInit, TemplateRef } from '@angular/core';
+import { SedaData, SedaElementConstants } from '../../models/seda-data';
+import { FileNode } from '../../models/file-node';
+import { FileService } from '../../core/services/file.service';
+import { SedaService } from '../../core/services/seda.service';
+import { MatDialogRef } from '@angular/material/dialog';
+import { PastisDialogConfirmComponent } from '../../shared/pastis-dialog/pastis-dialog-confirm/pastis-dialog-confirm.component';
+import { PastisDialogData } from '../../shared/pastis-dialog/classes/pastis-dialog-data';
+import { PopupService } from '../../core/services/popup.service';
+import { Subscription } from 'rxjs';
+import { PastisPopupMetadataLanguageService } from '../../shared/pastis-popup-metadata-language/pastis-popup-metadata-language.service';
+
+@Component({
+  selector: 'pastis-user-action-add-metadata',
+  templateUrl: './add-pua-control.component.html',
+  styleUrls: ['./add-pua-control.component.scss']
+})
+export class UserActionAddPuaControlComponent implements OnInit {
+
+  btnIsDisabled: boolean;
+
+  sedaData: SedaData;
+  allowedChildren: string[] = [
+    "Enumération",
+    "Expression régulière",
+    "Longueur Min/Max",
+    "Valeur Min/Max"
+  ]
+  namesFiltered: any = [];
+  sedaNodeFound: SedaData;
+  selectedSedaNode: SedaData;
+  addedItems: string[] = [];
+  dialogData: PastisDialogData;
+
+  atLeastOneIsSelected: boolean;
+  customTemplate: TemplateRef<any>
+  fileNode: FileNode;
+  sedaLanguage: boolean;
+  sedaLanguageSub: Subscription;
+
+
+  constructor(public dialogRef: MatDialogRef<PastisDialogConfirmComponent>,
+    private fileService: FileService, private sedaService: SedaService,
+    private popUpService: PopupService, private sedaLanguageService: PastisPopupMetadataLanguageService) { }
+
+  ngOnInit() {
+    this.sedaLanguageSub = this.sedaLanguageService.sedaLanguage.subscribe(
+      (value: boolean) => {
+        this.sedaLanguage = value;
+      },
+      (error) => {
+        console.log(error)
+      }
+    );
+    this.fileService.nodeChange.subscribe(fileNode => { this.fileNode = fileNode })
+    this.sedaData = this.sedaService.sedaRules[0];
+
+    this.sedaNodeFound = this.fileNode.sedaData;
+
+    // Subscribe observer to button status and
+    // set the inital state of the ok button to disabled
+    this.popUpService.btnYesShoudBeDisabled.subscribe(status => {
+      this.btnIsDisabled = status;
+    })
+  }
+
+
+  isElementSelected(element: string) {
+    if (this.addedItems) {
+      return this.addedItems.includes(element);
+    }
+  }
+
+  onRemoveSelectedElement(element: string) {
+    let indexOfElement = this.addedItems.indexOf(element)
+    console.log(indexOfElement)
+    if (indexOfElement >= 0) {
+      this.allowedChildren.push(this.addedItems.splice(indexOfElement, 1)[0])
+    }
+    console.error(this.allowedChildren)
+    this.addedItems.length > 0 ? this.atLeastOneIsSelected = true : this.atLeastOneIsSelected = false
+    this.upateButtonStatusAndDataToSend();
+  }
+
+  onAddSelectedElement(element: string) {
+    this.addedItems.push(element);
+
+    this.allowedChildren = this.allowedChildren.filter(e => e != element);
+    this.addedItems.length > 0 ? this.atLeastOneIsSelected = true : this.atLeastOneIsSelected = false
+    this.upateButtonStatusAndDataToSend();
+  }
+
+  upateButtonStatusAndDataToSend() {
+    this.popUpService.setPopUpDataOnClose(this.addedItems);
+    this.popUpService.disableYesButton(!this.atLeastOneIsSelected)
+  }
+
+  onAllItemsAdded() {
+    return this.allowedChildren.length === this.addedItems.length;
+  }
+
+  isElementComplex(element: SedaData) {
+    if (element) {
+      return element.Element === SedaElementConstants.complex;
+    }
+  }
+
+  getDefinition(element: SedaData): string {
+    return element ? element.Definition : '';
+  }
+
+  onYesClick(): void {
+    console.log("Clicked ok on dialog : %o", this.selectedSedaNode);
+
+  }
+  onNoClick(): void {
+    this.dialogRef.close();
+  }
+
+  onResolveName(element: SedaData): string {
+    if (this.sedaLanguage) {
+      return element.Name;
+    }
+    else {
+      if (element.NameFr) {
+        return element.NameFr;
+      }
+    }
+    return element.Name;
+  }
+  ngOnDestroy(): void {
+    if (this.sedaLanguageSub != null) {
+      this.sedaLanguageSub.unsubscribe();
+    }
+  }
+
+}
diff --git a/ui/ui-frontend/projects/pastis/src/app/user-actions/user-actions.module.ts b/ui/ui-frontend/projects/pastis/src/app/user-actions/user-actions.module.ts
index 0b0713892..e7decc26a 100644
--- a/ui/ui-frontend/projects/pastis/src/app/user-actions/user-actions.module.ts
+++ b/ui/ui-frontend/projects/pastis/src/app/user-actions/user-actions.module.ts
@@ -45,6 +45,7 @@ import {UserActionSaveProfileComponent} from './save-profile/save-profile.compon
 import {PastisMaterialModule} from '../material.module';
 import {UserActionsDownloadDocComponent} from './download-doc/download-doc.component';
 import {DuplicateMetadataComponent} from './duplicate-metadata/duplicate-metadata.component';
+import {UserActionAddPuaControlComponent} from './add-pua-control/add-pua-control.component';
 
 import {MatInputModule} from "@angular/material/input";
 import {FormsModule, ReactiveFormsModule} from "@angular/forms";
@@ -57,7 +58,7 @@ import {MatSlideToggleModule} from "@angular/material/slide-toggle";
 
 
 @NgModule({
-  declarations: [UserActionUploadProfileComponent,FilterByNamePipe, UserActionSaveProfileComponent, UserActionsDownloadDocComponent, DuplicateMetadataComponent, CreateNoticeComponent, SaveProfileOptionsComponent],
+  declarations: [UserActionUploadProfileComponent,FilterByNamePipe, UserActionSaveProfileComponent, UserActionsDownloadDocComponent, DuplicateMetadataComponent, CreateNoticeComponent, SaveProfileOptionsComponent, UserActionAddPuaControlComponent],
   imports: [
     CommonModule,
     PastisMaterialModule,
@@ -71,7 +72,7 @@ import {MatSlideToggleModule} from "@angular/material/slide-toggle";
     FormsModule,
     MatSlideToggleModule
   ],
-  exports: [UserActionUploadProfileComponent, UserActionSaveProfileComponent,UserActionsDownloadDocComponent,FilterByNamePipe ],
+  exports: [UserActionUploadProfileComponent, UserActionSaveProfileComponent,UserActionsDownloadDocComponent,FilterByNamePipe,UserActionAddPuaControlComponent ],
 })
 export class UserActionsModule {
 
-- 
GitLab