From e0d491ead82a9f5f1c1f06602100b170382c481d Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Fri, 17 Jan 2020 11:25:23 +0100
Subject: [PATCH] FEAT #10633 TIME 0:15 load parallel opinion

---
 .../send-avis-parallel-action.component.ts    | 32 +++++--------------
 .../app/avis/avis-workflow.component.ts       | 24 ++++++++++++++
 2 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/src/frontend/app/actions/avis-parallel-send-action/send-avis-parallel-action.component.ts b/src/frontend/app/actions/avis-parallel-send-action/send-avis-parallel-action.component.ts
index 41ea0befa73..d57ec93da64 100644
--- a/src/frontend/app/actions/avis-parallel-send-action/send-avis-parallel-action.component.ts
+++ b/src/frontend/app/actions/avis-parallel-send-action/send-avis-parallel-action.component.ts
@@ -1,4 +1,4 @@
-import { Component, OnInit, Inject, ViewChild } from '@angular/core';
+import { Component, OnInit, Inject, ViewChild, AfterViewInit } from '@angular/core';
 import { LANG } from '../../translate.component';
 import { NotificationService } from '../../notification.service';
 import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
@@ -13,7 +13,7 @@ import { AvisWorkflowComponent } from '../../avis/avis-workflow.component';
     templateUrl: "send-avis-parallel-action.component.html",
     styleUrls: ['send-avis-parallel-action.component.scss'],
 })
-export class SendAvisParallelComponent implements OnInit {
+export class SendAvisParallelComponent implements AfterViewInit {
 
     lang: any = LANG;
     loading: boolean = false;
@@ -38,31 +38,15 @@ export class SendAvisParallelComponent implements OnInit {
         @Inject(MAT_DIALOG_DATA) public data: any,
         public functions: FunctionsService) { }
 
-    async ngOnInit(): Promise<void> {
-        if (this.data.resIds.length > 0) {
-            this.loading = true;
-            await this.checkAvisParallel();
-            this.loading = false;
+    async ngAfterViewInit(): Promise<void> {
+        if (this.data.resIds.length === 1) {
+            await this.appAvisWorkflow.loadParallelWorkflow(this.data.resIds[0]);
+            if (this.appAvisWorkflow.emptyWorkflow()) {
+                this.appAvisWorkflow.loadDefaultWorkflow(this.data.resIds[0]);
+            }
         }
     }
 
-    checkAvisParallel() {
-        this.resourcesError = [];
-
-        return new Promise((resolve, reject) => {
-            this.http.post('../../rest/resourcesList/users/' + this.data.userId + '/groups/' + this.data.groupId + '/baskets/' + this.data.basketId + '/actions/' + this.data.action.id + '/checkOpinionInfo', { resources: this.data.resIds })
-                .subscribe((data: any) => {
-                    if (!this.functions.empty(data.resourcesInformations.noAttachment)) {
-                        this.resourcesError = data.resourcesInformations.noAttachment;
-                    }
-                    this.noResourceToProcess = this.data.resIds.length === this.resourcesError.length;
-                    resolve(true);
-                }, (err: any) => {
-                    this.notify.handleSoftErrors(err);
-                });
-        });
-    }
-
     async onSubmit() {
         this.loading = true;
         if (this.data.resIds.length === 0) {
diff --git a/src/frontend/app/avis/avis-workflow.component.ts b/src/frontend/app/avis/avis-workflow.component.ts
index a5a16f24177..16e0a9d928f 100644
--- a/src/frontend/app/avis/avis-workflow.component.ts
+++ b/src/frontend/app/avis/avis-workflow.component.ts
@@ -285,6 +285,30 @@ export class AvisWorkflowComponent implements OnInit {
         
     }
 
+    loadParallelWorkflow(resId: number) {
+        this.resId = resId;
+        this.loading = true;
+        this.avisWorkflow.items = [];
+        return new Promise((resolve, reject) => {
+            this.http.get("../../rest/resources/" + resId + "/parallelOpinion")
+            .subscribe((data: any) => {
+                data.forEach((element: any) => {
+                    this.avisWorkflow.items.push(
+                        {
+                            ...element,
+                            difflist_type: 'entity_id'
+                        });
+                });
+                this.avisWorkflowClone = JSON.parse(JSON.stringify(this.avisWorkflow.items))
+                this.loading = false;
+                resolve(true);
+            }, (err: any) => {
+                this.notify.handleErrors(err);
+            });
+        });
+        
+    }
+
     loadDefaultWorkflow(resId: number) {
         this.loading = true;
         this.avisWorkflow.items = [];
-- 
GitLab