From ddf2a040f1f4adeabb7df756e55b1be82822310c Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Wed, 25 Nov 2020 18:01:17 +0100
Subject: [PATCH] FEAT #14568 TIME 1 detailMode for document

---
 lang/fr.json                                  |  3 +-
 .../app/document/document.component.html      |  4 +-
 .../app/document/document.component.ts        | 41 ++++++++++++++-----
 src/frontend/app/search/search.component.html |  4 +-
 src/frontend/app/search/search.component.ts   |  2 +-
 src/frontend/app/service/auth.guard.ts        |  3 --
 6 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/lang/fr.json b/lang/fr.json
index 77dabc5fc3..a396199d8a 100755
--- a/lang/fr.json
+++ b/lang/fr.json
@@ -366,6 +366,7 @@
 		"adminSignaturesPositions" : "Gérer les positions de signatures",
 		"accessToPage": "Accéder à la page",
 		"createSignaturePosition": "Positionner la signature",
-		"prePositionings": "pré-positionnement(s)"
+		"prePositionings": "pré-positionnement(s)",
+		"back": "Retour"
 	}
 }
diff --git a/src/frontend/app/document/document.component.html b/src/frontend/app/document/document.component.html
index ad1a3d03a9..bcc2275113 100755
--- a/src/frontend/app/document/document.component.html
+++ b/src/frontend/app/document/document.component.html
@@ -33,7 +33,7 @@
                 </ion-badge>
             </ion-segment-button>
         </ion-segment>
-        <ion-buttons slot="end">
+        <ion-buttons slot="end" *ngIf="!detailMode">
             <ion-button color="primary" (click)="openAction()">
               <ion-icon slot="icon-only" name="settings-sharp"></ion-icon>
             </ion-button>
@@ -87,7 +87,7 @@
         <drag-scroll style="overflow:auto;height: 100%;width: 100%;margin: auto;"
             [drag-scroll-disabled]="(signaturesService.dragging || signaturesService.resizing) && signaturesService.mobileMode"
             [drag-disabled]="(signaturesService.dragging || signaturesService.resizing) && !signaturesService.mobileMode"
-            [style.maxWidth.px]="signaturesService.workingAreaWidth" #nav (click)="currentDoc == 0 ? openAction() : false"  (dblclick)="currentDoc == 0 ? openNoteEditor($event) : false">
+            [style.maxWidth.px]="signaturesService.workingAreaWidth" #nav (click)="currentDoc == 0 && !detailMode ? openAction() : false">
             <div style="position:relative;cursor: grab;" [style.width.px]="signaturesService.workingAreaWidth"
                 [style.height.px]="signaturesService.workingAreaHeight" id="myBounds" #myBounds>
                 <app-document-note-list *ngIf="currentDoc == 0 && !loadingImage">
diff --git a/src/frontend/app/document/document.component.ts b/src/frontend/app/document/document.component.ts
index 04f9329c1c..b8087fdfb0 100755
--- a/src/frontend/app/document/document.component.ts
+++ b/src/frontend/app/document/document.component.ts
@@ -16,7 +16,7 @@ import { TranslateService } from '@ngx-translate/core';
 import { DocumentListComponent } from './document-list/document-list.component';
 import { AuthService } from '../service/auth.service';
 import { LocalStorageService } from '../service/local-storage.service';
-import { ActionSheetController, AlertController, LoadingController, MenuController, ModalController } from '@ionic/angular';
+import { ActionSheetController, AlertController, LoadingController, MenuController, ModalController, NavController } from '@ionic/angular';
 import { NgxExtendedPdfViewerService } from 'ngx-extended-pdf-viewer';
 import { catchError, tap } from 'rxjs/operators';
 import { of } from 'rxjs';
@@ -29,6 +29,7 @@ import { of } from 'rxjs';
 export class DocumentComponent implements OnInit {
 
     enterApp: boolean = true;
+    detailMode: boolean = false;
     pageNum: number = 1;
     signaturesContent: any = [];
     totalPages: number;
@@ -112,6 +113,7 @@ export class DocumentComponent implements OnInit {
         public modalController: ModalController,
         private pdfViewerService: NgxExtendedPdfViewerService,
         public alertController: AlertController,
+        public navCtrl: NavController
     ) {
         this.draggable = false;
     }
@@ -337,16 +339,29 @@ export class DocumentComponent implements OnInit {
                             this.menu.enable(true, 'right-menu');
                             this.initDoc();
 
-                            const realUserWorkflow = this.mainDocument.workflow.filter((line: { current: boolean; }) => line.current === true)[0];
-
-                            if (realUserWorkflow.userId !== this.authService.user.id) {
-                                this.http.get('../rest/users/' + realUserWorkflow.userId + '/signatures')
-                                    .subscribe((dataSign: any) => {
-                                        this.signaturesService.signaturesListSubstituted = dataSign.signatures;
-                                        this.signaturesService.loadingSign = false;
-                                    });
+                            const realUserWorkflow = this.mainDocument.workflow.filter((line: { current: boolean; }) => line.current === true);
+
+                            if (realUserWorkflow.length === 0) {
+                                this.actionsList = [
+                                    {
+                                        id: 4,
+                                        label: 'lang.back',
+                                        color: 'medium',
+                                        logo: 'chevron-back-outline',
+                                        event: 'back'
+                                    },
+                                ];
+                                this.detailMode = true;
                             } else {
-                                this.signaturesService.signaturesListSubstituted = [];
+                                if (realUserWorkflow[0].userId !== this.authService.user.id) {
+                                    this.http.get('../rest/users/' + realUserWorkflow[0].userId + '/signatures')
+                                        .subscribe((dataSign: any) => {
+                                            this.signaturesService.signaturesListSubstituted = dataSign.signatures;
+                                            this.signaturesService.loadingSign = false;
+                                        });
+                                } else {
+                                    this.signaturesService.signaturesListSubstituted = [];
+                                }
                             }
 
                             this.docList.push({ 'id': this.mainDocument.id, 'title': this.mainDocument.title, 'pages': this.mainDocument.pages, 'imgContent': [], 'imgUrl': '../rest/documents/' + this.mainDocument.id + '/thumbnails' });
@@ -359,7 +374,7 @@ export class DocumentComponent implements OnInit {
                             this.loadingdocument = false;
                         }),
                         catchError((err: any) => {
-                            // console.log('error');
+                            console.log('error', err);
                             setTimeout(() => {
                                 this.load.dismiss();
                             }, 200);
@@ -885,6 +900,10 @@ export class DocumentComponent implements OnInit {
         }
     }
 
+    back() {
+        this.navCtrl.back();
+    }
+
     ionViewWillLeave() {
         this.signaturesService.detachTemplate('rightContent');
     }
diff --git a/src/frontend/app/search/search.component.html b/src/frontend/app/search/search.component.html
index c8f289f003..a8049475df 100644
--- a/src/frontend/app/search/search.component.html
+++ b/src/frontend/app/search/search.component.html
@@ -30,7 +30,7 @@
                                     <ion-icon *ngIf="i>0" name="chevron-forward-outline"></ion-icon>
                                     <span class="workflow-item success" [class.success]="itemW.processDate!==null && itemW.status!=='STOP'"
                                         [class.typist-interrupt]="itemW.status==='REF'"
-                                        [class.interrupt]="(itemW.processDate===null && itemW.statu === 'END') || itemW.status === 'STOP'"
+                                        [class.interrupt]="(itemW.processDate===null && itemW.status === 'END') || itemW.status === 'STOP'"
                                         [class.current]="itemW.current"
                                         [class.no-visa]="itemW.processDate===null && itemW.status===null && !itemW.current">{{itemW.userDisplay}}&nbsp;
                                         <ion-icon *ngIf="itemW.processDate!==null && itemW.status!=='REF' && itemW.status!=='STOP'"
@@ -69,7 +69,7 @@
                                 </p>
                             </ion-label>
                             <ion-buttons slot="end">
-                                <ion-button *ngIf="element.currentUser === authService.user.id" [title]="'lang.accessDocument' | translate" slot="icon-only" fill="clear" shape="round" (click)="goTo(element.id)">
+                                <ion-button [title]="'lang.accessDocument' | translate" slot="icon-only" fill="clear" shape="round" (click)="goTo(element.id)">
                                     <ion-icon color="primary" slot="icon-only" name="reader-outline"></ion-icon>
                                 </ion-button>
                                 <ion-button *ngIf="openedLine===element.id" slot="icon-only" fill="clear" shape="round"
diff --git a/src/frontend/app/search/search.component.ts b/src/frontend/app/search/search.component.ts
index 0e18fdc5ae..086f0f4604 100644
--- a/src/frontend/app/search/search.component.ts
+++ b/src/frontend/app/search/search.component.ts
@@ -191,7 +191,7 @@ export class SearchComponent implements OnInit {
             }
         });
         const actionSheet = await this.actionSheetController.create({
-            header: this.translate.instant('lang.actions') + ' - ' + item.reference,
+            header: this.translate.instant('lang.actions') + (item.reference !== null ? ' - ' + item.reference : '' ),
             buttons: buttons
         });
         await actionSheet.present();
diff --git a/src/frontend/app/service/auth.guard.ts b/src/frontend/app/service/auth.guard.ts
index fa7889f2f2..29d692715d 100644
--- a/src/frontend/app/service/auth.guard.ts
+++ b/src/frontend/app/service/auth.guard.ts
@@ -43,9 +43,6 @@ export class AuthGuard implements CanActivate {
             if (tokenInfo !== null) {
                 if (this.authService.user.id === undefined) {
                     this.authService.user = JSON.parse(atob(tokenInfo.split('.')[1])).user;
-                    console.log(this.authService.user);
-                    
-
                     this.translate.use(this.authService.user.preferences.lang);
                     this.cookieService.set('maarchParapheurLang', this.authService.user.preferences.lang);
 
-- 
GitLab