From 47f67435e3ebfcc3ec3c44895d26fdc2a2b9f8e4 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Wed, 4 Dec 2019 10:39:01 +0100
Subject: [PATCH] FEAT #12331 TIME 0:25 fix indexingFormId + update data in
 modal

---
 .../app/process/process.component.html        | 26 ++++++++---------
 src/frontend/app/process/process.component.ts | 28 +++++++++++++++++--
 2 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/src/frontend/app/process/process.component.html b/src/frontend/app/process/process.component.html
index bfcb2429477..51c681f3d50 100644
--- a/src/frontend/app/process/process.component.html
+++ b/src/frontend/app/process/process.component.html
@@ -76,21 +76,21 @@
                 </div>
             </ng-container>
             <ng-container *ngIf="!isModalOpen(); else elseTemplate">
-                <app-notes-list *ngIf="currentTool === 'notes'" #appNotesList [editMode]="true"
+                <app-notes-list *ngIf="currentTool === 'notes' && !loading" #appNotesList [editMode]="true"
                     [resId]="currentResourceInformations.resId">
                 </app-notes-list>
-                <app-diffusions-list *ngIf="currentTool === 'diffusionList'" #appDiffusionsList [adminMode]="false"
+                <app-diffusions-list *ngIf="currentTool === 'diffusionList' && !loading" #appDiffusionsList [adminMode]="false"
                     [resId]="currentResourceInformations.resId" [expanded]="true">
                 </app-diffusions-list>
-                <app-visa-workflow *ngIf="currentTool === 'visa'" #appVisaWorkflow
+                <app-visa-workflow *ngIf="currentTool === 'visa' && !loading" #appVisaWorkflow
                     [resId]="currentResourceInformations.resId"></app-visa-workflow>
-                <app-avis-workflow *ngIf="currentTool === 'avis'" #appAvisWorkflow
+                <app-avis-workflow *ngIf="currentTool === 'avis' && !loading" #appAvisWorkflow
                     [resId]="currentResourceInformations.resId"></app-avis-workflow>
-                <app-attachments-list *ngIf="currentTool === 'attachments'" #appAttachmentsList
+                <app-attachments-list *ngIf="currentTool === 'attachments' && !loading" #appAttachmentsList
                     [resId]="currentResourceInformations.resId" [target]="'process'">
                 </app-attachments-list>
-                <app-indexing-form *ngIf="currentTool === 'info'" #indexingForm [groupId]="currentGroupId"
-                    [indexingFormId]="1" [resId]="currentResourceInformations.resId" [mode]="'process'"></app-indexing-form>
+                <app-indexing-form *ngIf="currentTool === 'info' && !loading" #indexingForm [groupId]="currentGroupId"
+                    [resId]="currentResourceInformations.resId" [indexingFormId]="currentResourceInformations.modelId" [mode]="'process'"></app-indexing-form>
             </ng-container>
             <ng-template #elseTemplate>
                 <div class="openedModal">
@@ -224,20 +224,20 @@
         </button>
     </div>
     <div class="modal-module-content">
-        <app-notes-list *ngIf="modal.id === 'notes'" #appNotesList [editMode]="true"
+        <app-notes-list *ngIf="modal.id === 'notes' && !loading" #appNotesList [editMode]="true"
             [resId]="currentResourceInformations.resId">
         </app-notes-list>
-        <app-diffusions-list *ngIf="modal.id === 'diffusionList'" #appDiffusionsList [adminMode]="false"
+        <app-diffusions-list *ngIf="modal.id === 'diffusionList' && !loading" #appDiffusionsList [adminMode]="false"
             [resId]="currentResourceInformations.resId" [expanded]="true">
         </app-diffusions-list>
-        <app-visa-workflow *ngIf="modal.id === 'visa'" #appVisaWorkflow [resId]="currentResourceInformations.resId">
+        <app-visa-workflow *ngIf="modal.id === 'visa' && !loading" #appVisaWorkflow [resId]="currentResourceInformations.resId">
         </app-visa-workflow>
-        <app-avis-workflow *ngIf="modal.id === 'avis'" #appAvisWorkflow [resId]="currentResourceInformations.resId">
+        <app-avis-workflow *ngIf="modal.id === 'avis' && !loading" #appAvisWorkflow [resId]="currentResourceInformations.resId">
         </app-avis-workflow>
-        <app-attachments-list *ngIf="modal.id === 'attachments'" #appAttachmentsList
+        <app-attachments-list *ngIf="modal.id === 'attachments'  && !loading" #appAttachmentsList
             [resId]="currentResourceInformations.resId" (reloadBadgeAttachments)="reloadBadgeAttachments($event)">
         </app-attachments-list>
-        <app-indexing-form *ngIf="modal.id === 'info'" #indexingForm [groupId]="currentGroupId" [indexingFormId]="1" [resId]="currentResourceInformations.resId" [mode]="'process'">
+        <app-indexing-form *ngIf="modal.id === 'info' && !loading" #indexingForm [groupId]="currentGroupId" [indexingFormId]="currentResourceInformations.modelId" [resId]="currentResourceInformations.resId" [mode]="'process'">
         </app-indexing-form>
     </div>
 </div>
diff --git a/src/frontend/app/process/process.component.ts b/src/frontend/app/process/process.component.ts
index 2f22ea313f2..173da4856dd 100644
--- a/src/frontend/app/process/process.component.ts
+++ b/src/frontend/app/process/process.component.ts
@@ -288,7 +288,31 @@ export class ProcessComponent implements OnInit {
     }
 
     removeModal(index: number) {
-        this.modalModule.splice(index, 1);
+        if (this.modalModule[index].id === 'info' && this.indexingForm.isResourceModified()) {
+            const dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.confirm, msg: this.lang.saveModifiedData } });
+
+                dialogRef.afterClosed().pipe(
+                    tap((data: string) => {
+                        if (data !== 'ok') {
+                            this.modalModule.splice(index, 1);
+                        }
+                    }),
+                    filter((data: string) => data === 'ok'),
+                    tap(() => {
+                        this.indexingForm.saveData(this.currentUserId, this.currentGroupId, this.currentBasketId);
+                        setTimeout(() => {
+                            this.loadResource();
+                        }, 400);
+                        this.modalModule.splice(index, 1);
+                    }),
+                    catchError((err: any) => {
+                        this.notify.handleErrors(err);
+                        return of(false);
+                    })
+                ).subscribe();
+        } else {
+            this.modalModule.splice(index, 1);
+        }
     }
 
     isModalOpen() {
@@ -301,7 +325,7 @@ export class ProcessComponent implements OnInit {
     }
 
     changeTab(tabId: string) {
-        if (this.currentTool === 'info' && this.indexingForm.isResourceModified()) {
+        if (this.currentTool === 'info' && this.indexingForm.isResourceModified() && !this.isModalOpen()) {
             const dialogRef = this.dialog.open(ConfirmComponent, { autoFocus: false, disableClose: true, data: { title: this.lang.confirm, msg: this.lang.saveModifiedData } });
 
                 dialogRef.afterClosed().pipe(
-- 
GitLab