From 190378a5cb5a04a1b505d362d1e276e03bb90b30 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Fri, 4 Dec 2020 14:53:10 +0100
Subject: [PATCH] FIX #15570 TIME 1 add control no doc in indexation + fix
 undefined resId visa model

---
 .../send-signature-book-action.component.html |  4 ++--
 .../send-signature-book-action.component.ts   | 19 +++++++++++++++----
 .../app/visa/visa-workflow.component.ts       |  4 +++-
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.html b/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.html
index b563b4fe451..ad31f1c37ae 100755
--- a/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.html
+++ b/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.html
@@ -46,10 +46,10 @@
                         </li>
                     </ul>
                 </div>
-                <app-visa-workflow *ngIf="data.resIds.length <= 1 || (!noResourceToProcess && data.resIds.length > 1)"
+                <app-visa-workflow *ngIf="!noResourceToProcess"
                     [adminMode]="true" (workflowUpdated)="checkMinMaxVisaSign($event)" #appVisaWorkflow>
                 </app-visa-workflow>
-                <div style="padding-top: 10px;">
+                <div *ngIf="!noResourceToProcess" style="padding-top: 10px;">
                     <app-note-editor #noteEditor [resIds]="data.resIds"></app-note-editor>
                 </div>
             </mat-sidenav-content>
diff --git a/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.ts b/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.ts
index c0d652897b8..20f547537e4 100644
--- a/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.ts
+++ b/src/frontend/app/actions/visa-send-signature-book-action/send-signature-book-action.component.ts
@@ -33,7 +33,7 @@ export class SendSignatureBookActionComponent implements AfterViewInit {
     visaNumberCorrect: any = true;
     signNumberCorrect: any = true;
 
-    @ViewChild('noteEditor', { static: true }) noteEditor: NoteEditorComponent;
+    @ViewChild('noteEditor', { static: false }) noteEditor: NoteEditorComponent;
     @ViewChild('appVisaWorkflow', { static: false }) appVisaWorkflow: VisaWorkflowComponent;
 
     constructor(
@@ -45,8 +45,19 @@ export class SendSignatureBookActionComponent implements AfterViewInit {
         public functions: FunctionsService) { }
 
     async ngAfterViewInit(): Promise<void> {
-        if (this.data.resIds.length === 0 && !this.functions.empty(this.data.resource.destination)) {
-            await this.appVisaWorkflow.loadListModel(this.data.resource.destination);
+        if (this.data.resIds.length === 0) {
+            if (this.data.resource.encodedFile === null) {
+                this.noResourceToProcess = true;
+                this.resourcesError = [
+                    {
+                        alt_identifier : this.translate.instant('lang.currentIndexingMail'),
+                        reason : 'noDocumentToSend'
+                    }
+                ];
+            } else if (!this.functions.empty(this.data.resource.destination)) {
+                this.noResourceToProcess = false;
+                await this.appVisaWorkflow.loadListModel(this.data.resource.destination);
+            }
             this.loading = false;
         } else if (this.data.resIds.length > 0) {
             await this.checkSignatureBook();
@@ -166,7 +177,7 @@ export class SendSignatureBookActionComponent implements AfterViewInit {
         this.http.put(this.data.indexActionRoute, { resource: resId, note: this.noteEditor.getNote() }).pipe(
             tap((data: any) => {
                 if (!data) {
-                    this.dialogRef.close('success');
+                    this.dialogRef.close(this.data.resIds);
                 }
                 if (data && data.errors != null) {
                     this.notify.error(data.errors);
diff --git a/src/frontend/app/visa/visa-workflow.component.ts b/src/frontend/app/visa/visa-workflow.component.ts
index d93ac9b759f..0a1c443b3b6 100644
--- a/src/frontend/app/visa/visa-workflow.component.ts
+++ b/src/frontend/app/visa/visa-workflow.component.ts
@@ -174,7 +174,7 @@ export class VisaWorkflowComponent implements OnInit {
     }
 
     async loadVisaModelList() {
-        if (this.resId !== null) {
+        if (!this.functions.empty(this.resId)) {
             await this.loadDefaultModel();
         }
 
@@ -441,6 +441,7 @@ export class VisaWorkflowComponent implements OnInit {
                     }),
                     catchError((err: any) => {
                         this.notify.handleSoftErrors(err);
+                        resolve(false);
                         return of(false);
                     })
                 ).subscribe();
@@ -459,6 +460,7 @@ export class VisaWorkflowComponent implements OnInit {
                     }),
                     catchError((err: any) => {
                         this.notify.handleSoftErrors(err);
+                        resolve(false);
                         return of(false);
                     })
                 ).subscribe();
-- 
GitLab