From 0cba5e7b918e0df9d678732a31ddfbe0bbfb279f Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Thu, 16 Jan 2020 15:47:45 +0100
Subject: [PATCH] FEAT #10633 TIME 0:35 add opinion limit date + reason

---
 .../send-avis-workflow-action.component.html  | 20 ++++++++++++++----
 .../send-avis-workflow-action.component.ts    | 12 +++++++----
 .../app/notes/note-editor.component.html      |  2 +-
 .../app/notes/note-editor.component.ts        |  1 +
 src/frontend/lang/lang-en.ts                  |  1 +
 src/frontend/lang/lang-fr.ts                  |  1 +
 src/frontend/lang/lang-nl.ts                  |  1 +
 src/frontend/service/functions.service.ts     | 21 +++++++++++--------
 8 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/src/frontend/app/actions/avis-workflow-send-action/send-avis-workflow-action.component.html b/src/frontend/app/actions/avis-workflow-send-action/send-avis-workflow-action.component.html
index 54c812860cd..8f3a8cf5e1b 100644
--- a/src/frontend/app/actions/avis-workflow-send-action/send-avis-workflow-action.component.html
+++ b/src/frontend/app/actions/avis-workflow-send-action/send-avis-workflow-action.component.html
@@ -22,11 +22,23 @@
                     </li>
                 </ul>
             </div>
-            <app-avis-workflow *ngIf="data.resIds.length == 1 || (!noResourceToProcess && data.resIds.length > 1)" [adminMode]="true" #appAvisWorkflow>
+            <mat-form-field (click)="picker.open()" appearance="outline" style="cursor:pointer;margin-top: 10px;">
+                <mat-label>Date limite de l'avis</mat-label>
+                <input matInput [(ngModel)]="opinionLimitDate" [matDatepicker]="picker" [placeholder]="lang.chooseDate"
+                    [min]="today" readonly style="cursor:pointer;" required>
+                <mat-datepicker-toggle matSuffix [for]="picker" *ngIf="!opinionLimitDate">
+                </mat-datepicker-toggle>
+                <mat-datepicker #picker></mat-datepicker>
+                <button mat-button color="warn" matSuffix mat-icon-button *ngIf="opinionLimitDate"
+                    (click)="$event.stopPropagation();opinionLimitDate = null;" [title]="lang.eraseValue">
+                    <mat-icon color="warn" class="fa fa-calendar-times">
+                    </mat-icon>
+                </button>
+            </mat-form-field>
+            <app-note-editor #noteEditor [title]="lang.addOpinionReason" [resIds]="data.resIds"></app-note-editor>
+            <app-avis-workflow *ngIf="data.resIds.length == 1 || (!noResourceToProcess && data.resIds.length > 1)"
+                [adminMode]="true" #appAvisWorkflow>
             </app-avis-workflow>
-            <div style="padding-top: 10px;">
-                <app-note-editor #noteEditor [resIds]="data.resIds"></app-note-editor>
-            </div>
         </mat-sidenav-content>
     </mat-sidenav-container>
 </div>
diff --git a/src/frontend/app/actions/avis-workflow-send-action/send-avis-workflow-action.component.ts b/src/frontend/app/actions/avis-workflow-send-action/send-avis-workflow-action.component.ts
index a0239883639..56ef6800876 100644
--- a/src/frontend/app/actions/avis-workflow-send-action/send-avis-workflow-action.component.ts
+++ b/src/frontend/app/actions/avis-workflow-send-action/send-avis-workflow-action.component.ts
@@ -22,6 +22,10 @@ export class SendAvisWorkflowComponent implements OnInit {
 
     noResourceToProcess: boolean = null;
 
+    opinionLimitDate: Date = null;
+
+    today: Date = new Date();
+
     @ViewChild('noteEditor', { static: true }) noteEditor: NoteEditorComponent;
     @ViewChild('appAvisWorkflow', { static: false }) appAvisWorkflow: AvisWorkflowComponent;
 
@@ -32,7 +36,7 @@ export class SendAvisWorkflowComponent implements OnInit {
         @Inject(MAT_DIALOG_DATA) public data: any,
         public functions: FunctionsService) { }
 
-    async ngOnInit(): Promise<void> {        
+    async ngOnInit(): Promise<void> {
         if (this.data.resIds.length > 0) {
             this.loading = true;
             await this.checkAvisWorkflow();
@@ -103,8 +107,8 @@ export class SendAvisWorkflowComponent implements OnInit {
     }
 
     executeAction(realResSelected: number[]) {
-
-        this.http.put(this.data.processActionRoute, { resources: realResSelected, note: this.noteEditor.getNoteContent() }).pipe(
+        const noteContent: string = `[POUR AVIS] ${this.noteEditor.getNoteContent()}`;
+        this.http.put(this.data.processActionRoute, { resources: realResSelected, note: noteContent, data: { opinionLimitDate: this.functions.formatDateObjectToFrenchDateString(this.opinionLimitDate, true) } }).pipe(
             tap((data: any) => {
                 if (!data) {
                     this.dialogRef.close('success');
@@ -122,7 +126,7 @@ export class SendAvisWorkflowComponent implements OnInit {
     }
 
     isValidAction() {
-        if (!this.noResourceToProcess && this.appAvisWorkflow !== undefined && !this.appAvisWorkflow.emptyWorkflow() && !this.appAvisWorkflow.workflowEnd()) {
+        if (!this.noResourceToProcess && this.appAvisWorkflow !== undefined && !this.appAvisWorkflow.emptyWorkflow() && !this.appAvisWorkflow.workflowEnd() && !this.functions.empty(this.noteEditor.getNoteContent()) && !this.functions.empty(this.functions.formatDateObjectToFrenchDateString(this.opinionLimitDate))) {
             return true;
         } else {
             return false;
diff --git a/src/frontend/app/notes/note-editor.component.html b/src/frontend/app/notes/note-editor.component.html
index dba19614f01..e9e1a410d9a 100644
--- a/src/frontend/app/notes/note-editor.component.html
+++ b/src/frontend/app/notes/note-editor.component.html
@@ -1,5 +1,5 @@
 <mat-form-field appearance="outline" class="noteEditorContent">
-    <textarea matInput placeholder="{{lang.addNote}}" [(ngModel)]="content"></textarea>
+    <textarea matInput placeholder="{{title}}" [(ngModel)]="content"></textarea>
     <button matSuffix color="primary" mat-icon-button title="{{lang.noteTemplates}}" [matMenuTriggerFor]="menu"
         (click)="getTemplatesNote()">
         <mat-icon fontSet="fas" fontIcon="fa-file-alt fa-2x"></mat-icon>
diff --git a/src/frontend/app/notes/note-editor.component.ts b/src/frontend/app/notes/note-editor.component.ts
index b2a28eaa35d..064070dc694 100644
--- a/src/frontend/app/notes/note-editor.component.ts
+++ b/src/frontend/app/notes/note-editor.component.ts
@@ -18,6 +18,7 @@ export class NoteEditorComponent implements AfterViewInit {
 
     content: string = '';
 
+    @Input('title') title: string = this.lang.addNote;
     @Input('resIds') resIds: any[];
     @Input('addMode') addMode: boolean;
     @Output('refreshNotes') refreshNotes = new EventEmitter<string>();
diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts
index fedc794c793..45a5093ad42 100755
--- a/src/frontend/lang/lang-en.ts
+++ b/src/frontend/lang/lang-en.ts
@@ -1419,4 +1419,5 @@ export const LANG_EN = {
     "userHasntSigned": "The assignee hasn't signed any document",
     "noCircuitAvailable": "No workflow defined",
     "interrupted": "Interrupted",
+    "addOpinionReason": "Please fill the opinion reason",
 };
diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts
index 646077465b7..a5ae9593b4f 100755
--- a/src/frontend/lang/lang-fr.ts
+++ b/src/frontend/lang/lang-fr.ts
@@ -1459,4 +1459,5 @@ export const LANG_FR = {
     "userHasntSigned": "Le signataire n'a pas signé de document",
     "noCircuitAvailable": "Aucun circuit défini",
     "interrupted": "Interrompu",
+    "addOpinionReason": "Veuillez renseigner le motif de l'avis",
 };
diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts
index c08f33ac01c..e0ceed6e24b 100755
--- a/src/frontend/lang/lang-nl.ts
+++ b/src/frontend/lang/lang-nl.ts
@@ -1444,4 +1444,5 @@ export const LANG_NL = {
     "userHasntSigned": "The assignee hasn't signed any document",  //_TO_TRANSLATE
     "noCircuitAvailable": "No workflow defined", //_TO_TRANSLATE
     "interrupted": "Interrupted", //_TO_TRANSLATE
+    "addOpinionReason": "Please fill the opinion reason", //_TO_TRANSLATE
 };
diff --git a/src/frontend/service/functions.service.ts b/src/frontend/service/functions.service.ts
index 12a3ebe634f..dfdfdc5014a 100644
--- a/src/frontend/service/functions.service.ts
+++ b/src/frontend/service/functions.service.ts
@@ -8,7 +8,7 @@ export class FunctionsService {
 
     constructor() { }
 
-    empty(value: string) {
+    empty(value: any) {
         if (value === null || value === undefined) {
             return true;
 
@@ -40,14 +40,17 @@ export class FunctionsService {
     }
 
     formatDateObjectToFrenchDateString(date: Date, limitMode: boolean = false) {
-        
-        let day = date.getDate();
-        let month = date.getMonth() + 1;
-        let year = date.getFullYear();
-        let limit = '';
-        if (limitMode) {
-            limit = ' 23:59:59';
+        if (date !== null) {
+            let day = date.getDate();
+            let month = date.getMonth() + 1;
+            let year = date.getFullYear();
+            let limit = '';
+            if (limitMode) {
+                limit = ' 23:59:59';
+            }
+            return `${('00' + day).slice(-2)}-${('00' + month).slice(-2)}-${year}${limit}`;
+        } else {
+            return date;
         }
-        return `${('00' + day).slice(-2)}-${('00' + month).slice(-2)}-${year}${limit}`;
     }
 }
-- 
GitLab