From 09294be1b43209d84180074a3deb1ee551bbf189 Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Fri, 22 Nov 2019 18:33:54 +0100
Subject: [PATCH] FEAT #11691 TIME 0:20 fix some bug

---
 .../controllers/AttachmentController.php      |   2 +-
 .../attachments-list.component.html           | 148 ++++++++++--------
 .../attachments-list.component.scss           |  11 ++
 .../attachment-page.component.html            |   2 +-
 .../attachment-page.component.ts              |   5 +-
 .../app/viewer/document-viewer.component.ts   |   3 +-
 6 files changed, 99 insertions(+), 72 deletions(-)

diff --git a/src/app/attachment/controllers/AttachmentController.php b/src/app/attachment/controllers/AttachmentController.php
index a62f925f6d6..d50d5821a0a 100755
--- a/src/app/attachment/controllers/AttachmentController.php
+++ b/src/app/attachment/controllers/AttachmentController.php
@@ -95,7 +95,7 @@ class AttachmentController
             return $response->withStatus(400)->withJson(['errors' => 'Attachment does not exist']);
         }
 
-        if (!ResController::hasRightByResId(['resId' => [$attachment['res_id_master']], 'userId' => $GLOBALS['id']])) {
+        if (!ResController::hasRightByResId(['resId' => [$attachment['resIdMaster']], 'userId' => $GLOBALS['id']])) {
             return $response->withStatus(400)->withJson(['errors' => 'Attachment out of perimeter']);
         }
 
diff --git a/src/frontend/app/attachments/attachments-list.component.html b/src/frontend/app/attachments/attachments-list.component.html
index 4ad9a846126..1e6c1095fe5 100644
--- a/src/frontend/app/attachments/attachments-list.component.html
+++ b/src/frontend/app/attachments/attachments-list.component.html
@@ -1,74 +1,88 @@
-<div *ngIf="!loading" (mouseover)="resetToggleInfo()">
-    <div *ngIf="attachments.length == 0" style="text-align:center;font-size:24px;font-weight:bold;opacity:0.3;">
-        {{lang.noAttachment}}
+<ng-container *ngIf="loading; else elseLoading">
+    <div class="loading">
+        <mat-spinner></mat-spinner>
     </div>
-    <button mat-button color="primary" (click)="createAttachment()">{{lang.addAttachment}}</button>
-    <mat-form-field [style.visibility]="attachments.length > 0 ? 'visible' : 'hidden'" floatLabel="never"
-        style="padding-left:20px;padding-right:20px;">
-        <input matInput placeholder="{{lang.searchByAttachmentType}}" #listFilter>
-    </mat-form-field>
-    <mat-card *ngFor="let attachment of attachments | filterList:listFilter.value:'typeLabel'"
-        [class.signed]="attachment.status==='SIGN'" [style.background-image]="'url('+attachment.thumbnailUrl+')'"
-        style="padding:0;margin: 30px;min-height: 300px;background-size: cover;overflow: hidden;"
-        (mouseover)="$event.stopPropagation();toggleInfo(attachment,true)">
-        <div class="layout" *ngIf="attachment.hideMainInfo" [@myAnimation] (click)="showAttachment(attachment)">
-            <button mat-raised-button color="primary" (click)="$event.stopPropagation();showAttachment(attachment)">{{lang.viewResource}}</button>
-            <button mat-raised-button color="warn" *ngIf="attachment.status!=='SIGN'"
-                (click)="$event.stopPropagation();deleteAttachment(attachment)" [disabled]="!attachment.canDelete">{{lang.deleteResource}}</button>
+</ng-container>
+<ng-template #elseLoading>
+    <div (mouseover)="resetToggleInfo()">
+        <div *ngIf="attachments.length == 0" style="text-align:center;font-size:24px;font-weight:bold;opacity:0.3;">
+            {{lang.noAttachment}}
         </div>
-        <div class="pjToolsContent">
-            <button *ngIf="attachment.relation > 1" color="primary" class="versionButton" mat-button
-                [matMenuTriggerFor]="menu">{{lang.version}} <b color="secondary">{{attachment.relation}}</b></button>
-            <mat-menu #menu="matMenu">
-                <button mat-menu-item *ngFor="let version of attachment.versions; let i = index"
-                    (click)="showAttachment(version)">{{lang.version}} {{i+1}}</button>
-            </mat-menu>
-            <button color="primary" class="actionsButton" mat-icon-button [matMenuTriggerFor]="menuPjAction">
-                <mat-icon fontSet="fas" fontIcon="fa-ellipsis-v"></mat-icon>
-            </button>
-            <mat-menu #menuPjAction="matMenu">
-                <button mat-menu-item (click)="setInSignatureBook(attachment)">
-                    <mat-checkbox color="primary" [(ngModel)]="attachment.inSignatureBook"></mat-checkbox>
-                    {{lang.putInSignatureBook}}
-                </button>
-                <button mat-menu-item (click)="setInSendAttachment(attachment)" [disabled]="!mailevaEnabled">
-                    <mat-checkbox color="primary" [(ngModel)]="attachment.inSendAttach" [disabled]="!mailevaEnabled">
-                    </mat-checkbox>
-                    {{lang.putInSendAttach}}
-                </button>
-            </mat-menu>
-        </div>
-
-        <div class="infosPj">
-            <div class="stateInfo">
-                <i class="fas fa-file-signature" *ngIf="attachment.inSignatureBook"></i>&nbsp;
-                <i class="fa fa-shipping-fast" *ngIf="attachment.inSendAttach"></i>
-            </div>
-            <div class="mainInfos" *ngIf="!attachment.hideMainInfo">
-                {{attachment.chrono}}&nbsp;
-            </div>
-            <div class="mainInfos" *ngIf="attachment.hideMainInfo">
-                {{attachment.title | shorten : 40:'...'}}
+        <button mat-button color="primary" (click)="createAttachment()">{{lang.addAttachment}}</button>
+        <mat-form-field [style.visibility]="attachments.length > 0 ? 'visible' : 'hidden'" floatLabel="never"
+            style="padding-left:20px;padding-right:20px;">
+            <input matInput placeholder="{{lang.searchByAttachmentType}}" #listFilter>
+        </mat-form-field>
+        <mat-card *ngFor="let attachment of attachments | filterList:listFilter.value:'typeLabel'"
+            [class.signed]="attachment.status==='SIGN'" [style.background-image]="'url('+attachment.thumbnailUrl+')'"
+            style="padding:0;margin: 30px;min-height: 300px;background-size: cover;overflow: hidden;"
+            (mouseover)="$event.stopPropagation();toggleInfo(attachment,true)">
+            <div class="layout" *ngIf="attachment.hideMainInfo" [@myAnimation] (click)="showAttachment(attachment)">
+                <button mat-raised-button color="primary"
+                    (click)="$event.stopPropagation();showAttachment(attachment)">{{lang.viewResource}}</button>
+                <button mat-raised-button color="warn" *ngIf="attachment.status!=='SIGN'"
+                    (click)="$event.stopPropagation();deleteAttachment(attachment)"
+                    [disabled]="!attachment.canDelete">{{lang.deleteResource}}</button>
             </div>
-            <div class="subInfos" *ngIf="!attachment.hideMainInfo">
-                {{attachment.typeLabel}}
+            <div class="pjToolsContent">
+                <button *ngIf="attachment.relation > 1" color="primary" class="versionButton" mat-button
+                    [matMenuTriggerFor]="menu">{{lang.version}} <b
+                        color="secondary">{{attachment.relation}}</b></button>
+                <mat-menu #menu="matMenu">
+                    <button mat-menu-item *ngFor="let version of attachment.versions; let i = index"
+                        (click)="showAttachment(version)">{{lang.version}} {{i+1}}</button>
+                </mat-menu>
+                <button color="primary" class="actionsButton" mat-icon-button [matMenuTriggerFor]="menuPjAction">
+                    <mat-icon fontSet="fas" fontIcon="fa-ellipsis-v"></mat-icon>
+                </button>
+                <mat-menu #menuPjAction="matMenu">
+                    <button mat-menu-item (click)="setInSignatureBook(attachment)">
+                        <mat-checkbox color="primary" [(ngModel)]="attachment.inSignatureBook"></mat-checkbox>
+                        {{lang.putInSignatureBook}}
+                    </button>
+                    <button mat-menu-item (click)="setInSendAttachment(attachment)" [disabled]="!mailevaEnabled">
+                        <mat-checkbox color="primary" [(ngModel)]="attachment.inSendAttach"
+                            [disabled]="!mailevaEnabled">
+                        </mat-checkbox>
+                        {{lang.putInSendAttach}}
+                    </button>
+                </mat-menu>
             </div>
-            <div class="subInfos" *ngIf="attachment.hideMainInfo">
-                <ng-container *ngIf="attachment.signDate !== undefined; else elseTemplate">
-                    {{lang.signedAlt}} <b>{{attachment.signDate | timeAgo : 'full'}}</b> {{lang.by | lowercase}} <b>{{attachment.signatory}}</b>
-                </ng-container>
-                <ng-template #elseTemplate>
-                    <ng-container *ngIf="attachment.modificationDate !== null; else creationTemplate">
-                        {{lang.modified}} <b>{{attachment.modificationDate | timeAgo : 'full'}}</b> {{lang.by | lowercase}} <b>{{attachment.modifiedBy}}</b>
+
+            <div class="infosPj">
+                <div class="stateInfo">
+                    <i class="fas fa-file-signature" *ngIf="attachment.inSignatureBook"></i>&nbsp;
+                    <i class="fa fa-shipping-fast" *ngIf="attachment.inSendAttach"></i>
+                </div>
+                <div class="mainInfos" *ngIf="!attachment.hideMainInfo">
+                    {{attachment.chrono}}&nbsp;
+                </div>
+                <div class="mainInfos" *ngIf="attachment.hideMainInfo">
+                    {{attachment.title | shorten : 40:'...'}}
+                </div>
+                <div class="subInfos" *ngIf="!attachment.hideMainInfo">
+                    {{attachment.typeLabel}}
+                </div>
+                <div class="subInfos" *ngIf="attachment.hideMainInfo">
+                    <ng-container *ngIf="attachment.signDate !== undefined; else elseTemplate">
+                        {{lang.signedAlt}} <b>{{attachment.signDate | timeAgo : 'full'}}</b> {{lang.by | lowercase}}
+                        <b>{{attachment.signatory}}</b>
                     </ng-container>
-                    <ng-template #creationTemplate>
-                        {{lang.created}} <b>{{attachment.creationDate | timeAgo : 'full'}}</b> {{lang.by | lowercase}} <b>{{attachment.typistLabel}}</b>
+                    <ng-template #elseTemplate>
+                        <ng-container *ngIf="attachment.modificationDate !== null; else creationTemplate">
+                            {{lang.modified}} <b>{{attachment.modificationDate | timeAgo : 'full'}}</b>
+                            {{lang.by | lowercase}} <b>{{attachment.modifiedBy}}</b>
+                        </ng-container>
+                        <ng-template #creationTemplate>
+                            {{lang.created}} <b>{{attachment.creationDate | timeAgo : 'full'}}</b>
+                            {{lang.by | lowercase}} <b>{{attachment.typistLabel}}</b>
+                        </ng-template>
                     </ng-template>
-                </ng-template>
-            </div>
-            <div class="statusInfo">
-                {{lang['attachment_'+attachment.status]}}
+                </div>
+                <div class="statusInfo">
+                    {{lang['attachment_'+attachment.status]}}
+                </div>
             </div>
-        </div>
-    </mat-card>
-</div>
\ No newline at end of file
+        </mat-card>
+    </div>
+</ng-template>
\ No newline at end of file
diff --git a/src/frontend/app/attachments/attachments-list.component.scss b/src/frontend/app/attachments/attachments-list.component.scss
index 0ca307e89a0..15506e4f64c 100644
--- a/src/frontend/app/attachments/attachments-list.component.scss
+++ b/src/frontend/app/attachments/attachments-list.component.scss
@@ -130,4 +130,15 @@
         top: -7px;
         font-size: 10px;
     }
+}
+
+.loading {
+    display:flex;
+    justify-content: center;
+    top: 0;
+    left: 0;
+    width: 100%;
+    background: #ffffffb3;
+    z-index: 1;
+    overflow: hidden;
 }
\ No newline at end of file
diff --git a/src/frontend/app/attachments/attachments-page/attachment-page.component.html b/src/frontend/app/attachments/attachments-page/attachment-page.component.html
index 85dfc79280f..b8346234af8 100644
--- a/src/frontend/app/attachments/attachments-page/attachment-page.component.html
+++ b/src/frontend/app/attachments/attachments-page/attachment-page.component.html
@@ -186,7 +186,7 @@
                             <span style="color:#135f7f">{{lang.attachment}}</span>
                         </ng-template>
                         <app-document-viewer #appAttachmentViewer style="height:100%;width:100%;" [editMode]="editMode"
-                            [resId]="data.resId" [mode]="'attachment'" [attachType]="attachment['type'].value"
+                            [resId]="data.resId" [resIdMaster]="attachment['resIdMaster'].value" [mode]="'attachment'" [attachType]="attachment['type'].value"
                             [infoPanel]="snavLeft" (triggerEvent)="setDatasViewer()"
                             [title]="attachment.chrono.value + ' - ' + attachment.title.value">
                         </app-document-viewer>
diff --git a/src/frontend/app/attachments/attachments-page/attachment-page.component.ts b/src/frontend/app/attachments/attachments-page/attachment-page.component.ts
index 6b4690c9881..afb4b0f58b1 100644
--- a/src/frontend/app/attachments/attachments-page/attachment-page.component.ts
+++ b/src/frontend/app/attachments/attachments-page/attachment-page.component.ts
@@ -84,7 +84,7 @@ export class AttachmentPageComponent implements OnInit {
                     resId: new FormControl({ value: this.data.resId, disabled: true }, [Validators.required]),
                     chrono: new FormControl({ value: data.chrono, disabled: true }),
                     originId: new FormControl({ value: data.originId, disabled: true }),
-                    resIdMaster: new FormControl({ value: data.res_id_master, disabled: true }, [Validators.required]),
+                    resIdMaster: new FormControl({ value: data.resIdMaster, disabled: true }, [Validators.required]),
                     status: new FormControl({ value: data.status, disabled: true }, [Validators.required]),
                     relation: new FormControl({ value: data.relation, disabled: true }, [Validators.required]),
                     title: new FormControl({ value: data.title, disabled: !this.editMode }, [Validators.required]),
@@ -186,9 +186,10 @@ export class AttachmentPageComponent implements OnInit {
         let datas: any = {};
         Object.keys(this.attachment).forEach(element => {
             if (['title', 'validationDate', 'effectiveDate'].indexOf(element) > -1) {
-                datas[element] = this.attachment[element].value;
+                datas['attachment_' + element] = this.attachment[element].value;
             }
         });
+        datas['resId'] = this.attachment['resIdMaster'].value;
         this.attachment.encodedFile.setValue(this.appAttachmentViewer.getFile().content);
         this.appAttachmentViewer.setDatas(datas);
     }
diff --git a/src/frontend/app/viewer/document-viewer.component.ts b/src/frontend/app/viewer/document-viewer.component.ts
index 4c8fc7c41e6..e6ae0474073 100644
--- a/src/frontend/app/viewer/document-viewer.component.ts
+++ b/src/frontend/app/viewer/document-viewer.component.ts
@@ -59,6 +59,7 @@ export class DocumentViewerComponent implements OnInit {
     templateListForm = new FormControl();
 
     @Input('resId') resId: number = null;
+    @Input('resIdMaster') resIdMaster: number = null;
     @Input('infoPanel') infoPanel: MatSidenav = null;
     @Input('editMode') editMode: boolean = false;
     @Input('title') title: string = '';
@@ -109,7 +110,7 @@ export class DocumentViewerComponent implements OnInit {
                     this.loadRessource(this.resId, this.mode);
                     if (this.editMode) {
                         if (this.attachType !== null && this.mode === 'attachment') {
-                            this.loadTemplatesByResId(this.resId, this.attachType);
+                            this.loadTemplatesByResId(this.resIdMaster, this.attachType);
                         } else {
                             this.loadTemplates();
                         }
-- 
GitLab