From d139eabc1ec26684ad251fe07d55524d9bd8a1af Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Tue, 13 Oct 2020 16:18:36 +0200
Subject: [PATCH] FEAT #15049 TIME 1 add msg action error

---
 .../send-to-record-management.component.html  | 195 ++++++++++--------
 .../send-to-record-management.component.scss  |  21 +-
 .../send-to-record-management.component.ts    |  14 +-
 src/lang/lang-fr.json                         |   3 +-
 4 files changed, 133 insertions(+), 100 deletions(-)

diff --git a/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.html b/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.html
index bd7ac8bb922..d2632241e7d 100644
--- a/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.html
+++ b/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.html
@@ -1,111 +1,126 @@
 <div class="mat-dialog-content-container">
     <h1 mat-dialog-title>{{data.action.label}}</h1>
     <div mat-dialog-content>
-        <div *ngIf="loading" class="loading" style="display:flex;height:100%;">
-            <mat-spinner style="margin:auto;"></mat-spinner>
+        <div *ngIf="checking" class="checking" color="primary"
+            style="display:flex;height:100%;justify-content: center;padding: 30px;">
+            <mat-spinner diameter="24"></mat-spinner>&nbsp;{{'lang.checkInProgress' | translate}} ...
         </div>
-        <form [formGroup]="actionFormGroup" style="display: contents;">
-            <mat-form-field appearance="outline">
-                <mat-label>{{'lang.slipLabel' | translate}}</mat-label>
-                <input type="text" matInput formControlName="packageName">
-            </mat-form-field>
-            <mat-form-field appearance="outline">
-                <mat-label>{{'lang.slipId' | translate}}</mat-label>
-                <input type="text" matInput formControlName="slipId">
-            </mat-form-field>
-            <div class="row">
-                <div class="col-md-6">
-                    <mat-form-field>
-                        <mat-label>{{'lang.archivalAgreement' | translate}}</mat-label>
-                        <mat-select formControlName="archivalAgreement" (selectionChange)="archivalAgreementSelected($event)">
-                            <mat-option *ngFor="let agreement of archivalAgreements" [value]="agreement.id">{{agreement.label}}</mat-option>
-                        </mat-select>
-                    </mat-form-field>
-                </div>
-                <div class="col-md-6">
-                    <mat-form-field>
-                        <mat-label>{{'lang.archivalAgency' | translate}}</mat-label>
-                        <mat-select formControlName="entityArchiveRecipient" (selectionChange)="entityArchiveRecipientSelected($event)">
-                            <mat-option *ngFor="let entity of recipientArchiveEntities" [value]="entity.id">{{entity.label}}</mat-option>
-                        </mat-select>
-                    </mat-form-field>
+        <div *ngIf="loading" class="loading" color="primary">
+            <mat-spinner></mat-spinner>
+        </div>
+        <ng-container *ngIf="!checking && resourcesErrors.length === 0">
+            <form [formGroup]="actionFormGroup" style="display: contents;">
+                <mat-form-field appearance="outline">
+                    <mat-label>{{'lang.slipLabel' | translate}}</mat-label>
+                    <input type="text" matInput formControlName="packageName">
+                </mat-form-field>
+                <mat-form-field appearance="outline">
+                    <mat-label>{{'lang.slipId' | translate}}</mat-label>
+                    <input type="text" matInput formControlName="slipId">
+                </mat-form-field>
+                <div class="row">
+                    <div class="col-md-6">
+                        <mat-form-field>
+                            <mat-label>{{'lang.archivalAgreement' | translate}}</mat-label>
+                            <mat-select formControlName="archivalAgreement"
+                                (selectionChange)="archivalAgreementSelected($event)">
+                                <mat-option *ngFor="let agreement of archivalAgreements" [value]="agreement.id">
+                                    {{agreement.label}}</mat-option>
+                            </mat-select>
+                        </mat-form-field>
+                    </div>
+                    <div class="col-md-6">
+                        <mat-form-field>
+                            <mat-label>{{'lang.archivalAgency' | translate}}</mat-label>
+                            <mat-select formControlName="entityArchiveRecipient"
+                                (selectionChange)="entityArchiveRecipientSelected($event)">
+                                <mat-option *ngFor="let entity of recipientArchiveEntities" [value]="entity.id">
+                                    {{entity.label}}</mat-option>
+                            </mat-select>
+                        </mat-form-field>
+                    </div>
                 </div>
-            </div>
-            <div class="form-group" style="display:flex;flex-direction: row; flex-wrap: wrap;">
-                <div class="formType ratio-2 col-sm-12">
-                    <div class="formType-title">
-                        {{'lang.transferEntity' | translate}}
+                <div class="form-group" style="display:flex;flex-direction: row; flex-wrap: wrap;">
+                    <div class="formType ratio-2 col-sm-12">
+                        <div class="formType-title">
+                            {{'lang.transferEntity' | translate}}
+                        </div>
+                        <mat-form-field>
+                            <mat-label>{{'lang.label' | translate}}</mat-label>
+                            <input type="text" matInput formControlName="entityLabelTransferEntity">
+                        </mat-form-field>
+                        <mat-form-field>
+                            <mat-label>{{'lang.producerService' | translate}}</mat-label>
+                            <input type="text" matInput formControlName="producerTransferEntity">
+                        </mat-form-field>
+                        <mat-form-field>
+                            <mat-label>{{'lang.senderArchiveEntity' | translate}}</mat-label>
+                            <input type="text" matInput formControlName="senderArchiveEntity">
+                        </mat-form-field>
+                    </div>
+                    <div class="formType ratio-2 col-sm-12">
+                        <div class="formType-title">
+                            {{'lang.doctype' | translate}}
+                        </div>
+                        <mat-form-field>
+                            <mat-label>{{'lang.label' | translate}}</mat-label>
+                            <input type="text" matInput formControlName="doctype">
+                        </mat-form-field>
+                        <mat-form-field>
+                            <mat-label>{{'lang.retentionRule' | translate}}</mat-label>
+                            <input type="text" matInput formControlName="entityRetentionRule">
+                        </mat-form-field>
+                        <mat-form-field>
+                            <mat-label>{{'lang.retentionFinalDisposition' | translate}}</mat-label>
+                            <input type="text" matInput formControlName="doctypeRetentionFinalDisposition">
+                        </mat-form-field>
                     </div>
-                    <mat-form-field>
-                        <mat-label>{{'lang.label' | translate}}</mat-label>
-                        <input type="text" matInput formControlName="entityLabelTransferEntity">
-                    </mat-form-field>
-                    <mat-form-field>
-                        <mat-label>{{'lang.producerService' | translate}}</mat-label>
-                        <input type="text" matInput formControlName="producerTransferEntity">
-                    </mat-form-field>
-                    <mat-form-field>
-                        <mat-label>{{'lang.senderArchiveEntity' | translate}}</mat-label>
-                        <input type="text" matInput formControlName="senderArchiveEntity">
-                    </mat-form-field>
                 </div>
-                <div class="formType ratio-2 col-sm-12">
-                    <div class="formType-title">
-                        {{'lang.doctype' | translate}}
+                <div class="row">
+                    <div class="col-md-6">
+                        <mat-form-field appearance="outline">
+                            <mat-label>{{'lang.archiveId' | translate}}</mat-label>
+                            <input type="text" matInput formControlName="archiveId">
+                        </mat-form-field>
+                    </div>
+                    <div class="col-md-6">
+                        <mat-form-field>
+                            <mat-label>{{'lang.descriptionLevel' | translate}}</mat-label>
+                            <mat-select formControlName="archiveDescriptionLevel">
+                                <mat-option *ngFor="let descriptionLevel of descriptionLevels"
+                                    [value]="descriptionLevel.id">{{descriptionLevel.label}}</mat-option>
+                            </mat-select>
+                        </mat-form-field>
                     </div>
+                </div>
+            </form>
+            <mat-tab-group>
+                <mat-tab *ngFor="let archive of archives; let i=index" label="Unité d'archive n°{{i + 1}}">
                     <mat-form-field>
-                        <mat-label>{{'lang.label' | translate}}</mat-label>
-                        <input type="text" matInput formControlName="doctype">
+                        <mat-label>{{'lang.id' | translate}}</mat-label>
+                        <input type="text" matInput [(ngModel)]="archive.id" disabled>
                     </mat-form-field>
                     <mat-form-field>
-                        <mat-label>{{'lang.retentionRule' | translate}}</mat-label>
-                        <input type="text" matInput formControlName="entityRetentionRule">
+                        <mat-label>{{'lang.label' | translate}}</mat-label>
+                        <input type="text" matInput [(ngModel)]="archive.label" disabled>
                     </mat-form-field>
                     <mat-form-field>
-                        <mat-label>{{'lang.retentionFinalDisposition' | translate}}</mat-label>
-                        <input type="text" matInput formControlName="doctypeRetentionFinalDisposition">
-                    </mat-form-field>
-                </div>
-            </div>
-            <div class="row">
-                <div class="col-md-6">
-                    <mat-form-field appearance="outline">
-                        <mat-label>{{'lang.archiveId' | translate}}</mat-label>
-                        <input type="text" matInput formControlName="archiveId">
+                        <mat-label>{{'lang.type' | translate}}</mat-label>
+                        <input type="text" matInput [(ngModel)]="archive.type" disabled>
                     </mat-form-field>
-                </div>
-                <div class="col-md-6">
                     <mat-form-field>
                         <mat-label>{{'lang.descriptionLevel' | translate}}</mat-label>
-                        <mat-select formControlName="archiveDescriptionLevel">
-                            <mat-option *ngFor="let descriptionLevel of descriptionLevels" [value]="descriptionLevel.id">{{descriptionLevel.label}}</mat-option>
+                        <mat-select [(ngModel)]="archive.descriptionLevel" required>
+                            <mat-option *ngFor="let descriptionLevel of descriptionLevels"
+                                [value]="descriptionLevel.id">{{descriptionLevel.label}}</mat-option>
                         </mat-select>
                     </mat-form-field>
-                </div>
-            </div>
-        </form>
-        <mat-tab-group>
-            <mat-tab *ngFor="let archive of archives; let i=index" label="Unité d'archive n°{{i + 1}}">
-                <mat-form-field>
-                    <mat-label>{{'lang.id' | translate}}</mat-label>
-                    <input type="text" matInput [(ngModel)]="archive.id" disabled>
-                </mat-form-field>
-                <mat-form-field>
-                    <mat-label>{{'lang.label' | translate}}</mat-label>
-                    <input type="text" matInput [(ngModel)]="archive.label" disabled>
-                </mat-form-field>
-                <mat-form-field>
-                    <mat-label>{{'lang.type' | translate}}</mat-label>
-                    <input type="text" matInput [(ngModel)]="archive.type" disabled>
-                </mat-form-field>
-                <mat-form-field>
-                    <mat-label>{{'lang.descriptionLevel' | translate}}</mat-label>
-                    <mat-select [(ngModel)]="archive.descriptionLevel" required>
-                        <mat-option *ngFor="let descriptionLevel of descriptionLevels" [value]="descriptionLevel.id">{{descriptionLevel.label}}</mat-option>
-                    </mat-select>
-                </mat-form-field>
-            </mat-tab>
-        </mat-tab-group>
+                </mat-tab>
+            </mat-tab-group>
+        </ng-container>
+        <div *ngIf="resourcesErrors.length > 0" class="alert-message alert-message-danger">
+            {{'lang.' + resourcesErrors[0].lang | translate}}
+        </div>
     </div>
     <span class="divider-modal"></span>
     <div mat-dialog-actions class="actions">
diff --git a/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.scss b/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.scss
index f3a780b9c92..65d9226ad24 100644
--- a/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.scss
+++ b/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.scss
@@ -1,15 +1,24 @@
 @import '../../../css/vars.scss';
 
 .loading {
-  display: flex;
   position: absolute;
-  top: 0;
-  left: 0;
+  display: flex;
+  height: 100%;
+  justify-content: center;
   width: 100%;
+  left: 0px;
+  top: 0px;
+  align-items: center;
+  z-index: 1;
+  background: rgba(255, 255, 255, 0.8);
+}
+
+.checking {
+  display: flex;
   height: 100%;
-  background: #ffffffb3;
-  z-index: 2;
-  overflow: hidden;
+  justify-content: center;
+  align-items: center;
+  padding: 30px;
 }
 
 .formType {
diff --git a/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.ts b/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.ts
index 2d21f05590c..7c8efbbca47 100644
--- a/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.ts
+++ b/src/frontend/app/actions/send-to-record-management-action/send-to-record-management.component.ts
@@ -16,6 +16,8 @@ import { catchError, finalize, tap } from 'rxjs/operators';
 export class SendToRecordManagementComponent implements OnInit {
 
     loading: boolean = false;
+    checking: boolean = false;
+    resourcesErrors: any[] = [];
     recipientArchiveEntities = [];
     archivalAgreements = [];
 
@@ -92,10 +94,15 @@ export class SendToRecordManagementComponent implements OnInit {
     }
 
     ngOnInit(): void {
-        this.getData();
+        if (this.data.resIds.length === 1) {
+            this.getData();
+        } else {
+            this.resourcesErrors.push({lang : 'onlySingleResourceAllowed'});
+        }
     }
 
     getData() {
+        this.checking = true;
         this.http.post(`../rest/resourcesList/users/${this.data.userId}/groups/${this.data.groupId}/baskets/${this.data.basketId}/actions/${this.data.action.id}/checkSendToRecordManagement`, { resources: this.data.resIds }).pipe(
             tap((data: any) => {
                 this.archives = data.archiveUnits;
@@ -120,9 +127,10 @@ export class SendToRecordManagementComponent implements OnInit {
                     doctypeRetentionFinalDisposition: [{value: data.data.doctype.retentionFinalDisposition, disabled: true}, Validators.required],
                 });
             }),
-            finalize(() => this.loading = false),
+            finalize(() => this.checking = false),
             catchError((err: any) => {
-                this.notify.handleErrors(err);
+                this.resourcesErrors.push(err.error);
+                // this.notify.handleErrors(err);
                 return of(false);
             })
         ).subscribe();
diff --git a/src/lang/lang-fr.json b/src/lang/lang-fr.json
index 2edd78a724e..94dd83d0fde 100644
--- a/src/lang/lang-fr.json
+++ b/src/lang/lang-fr.json
@@ -2079,5 +2079,6 @@
     "recordManagement_noReplyReference": "Aucun bordereau correspond à la réponse de transfert",
     "recordManagement_wrongReply": "La réponse de transfert n'est pas lié au bon courrier",
     "nextPage": "Page suivante",
-    "prevPage": "Page précédente"
+    "prevPage": "Page précédente",
+    "onlySingleResourceAllowed": "Seule une ressource peut être traité par cette action"
 }
-- 
GitLab