From fe9610a9408660f5e21ac4e9e1d919bcd8b2f200 Mon Sep 17 00:00:00 2001 From: Alex ORLUC <alex.orluc@maarch.org> Date: Fri, 17 Jan 2020 17:24:06 +0100 Subject: [PATCH] FEAT #10633 TIME 1:30 add front validate parallel opinion --- migration/20.03/2003.sql | 2 +- .../controllers/ActionMethodController.php | 4 +- src/frontend/app/actions/actions.service.ts | 23 ++++ ...lidate-avis-parallel-action.component.html | 59 ++++++++ ...lidate-avis-parallel-action.component.scss | 128 +++++++++++++++++ ...validate-avis-parallel-action.component.ts | 130 ++++++++++++++++++ src/frontend/app/app.module.ts | 3 + .../app/notes/note-editor.component.ts | 3 +- src/frontend/lang/lang-en.ts | 6 +- src/frontend/lang/lang-fr.ts | 6 +- src/frontend/lang/lang-nl.ts | 6 +- 11 files changed, 362 insertions(+), 8 deletions(-) create mode 100644 src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.html create mode 100644 src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.scss create mode 100644 src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.ts diff --git a/migration/20.03/2003.sql b/migration/20.03/2003.sql index 6137732b6f7..1b65b6487b7 100644 --- a/migration/20.03/2003.sql +++ b/migration/20.03/2003.sql @@ -99,7 +99,7 @@ UPDATE actions SET component = 'sendToOpinionCircuitAction' WHERE action_page = UPDATE actions SET component = 'continueOpinionCircuitAction' WHERE action_page = 'avis_workflow'; UPDATE actions SET component = 'giveOpinionParallelAction' WHERE action_page = 'avis_workflow_simple'; UPDATE actions SET component = 'sendToParallelOpinion' WHERE action_page = 'send_docs_to_recommendation'; -UPDATE actions SET component = 'validateRecommendationAction' WHERE action_page = 'validate_recommendation'; +UPDATE actions SET component = 'validateParallelOpinionDiffusionAction' WHERE action_page = 'validate_recommendation'; DELETE FROM actions_groupbaskets WHERE id_action IN (SELECT id FROM actions WHERE action_page = 'put_in_copy'); DELETE FROM actions_categories WHERE action_id IN (SELECT id FROM actions WHERE action_page = 'put_in_copy'); diff --git a/src/app/action/controllers/ActionMethodController.php b/src/app/action/controllers/ActionMethodController.php index 515d24523e8..30fb2430f8e 100644 --- a/src/app/action/controllers/ActionMethodController.php +++ b/src/app/action/controllers/ActionMethodController.php @@ -66,7 +66,7 @@ class ActionMethodController 'sendToOpinionCircuitAction' => 'sendToOpinionCircuit', 'continueOpinionCircuitAction' => 'continueOpinionCircuit', 'giveOpinionParallelAction' => 'giveOpinionParallel', - 'validateRecommendationAction' => 'validateRecommendation', + 'validateParallelOpinionDiffusionAction' => 'validateParallelOpinionDiffusion', 'noConfirmAction' => null ]; @@ -736,7 +736,7 @@ class ActionMethodController return true; } - public static function validateRecommendation(array $args) + public static function validateParallelOpinionDiffusion(array $args) { ValidatorModel::notEmpty($args, ['resId']); ValidatorModel::intVal($args, ['resId']); diff --git a/src/frontend/app/actions/actions.service.ts b/src/frontend/app/actions/actions.service.ts index 4ef2814ce01..55cb775513e 100644 --- a/src/frontend/app/actions/actions.service.ts +++ b/src/frontend/app/actions/actions.service.ts @@ -31,6 +31,7 @@ import { SendAvisWorkflowComponent } from './avis-workflow-send-action/send-avis import { ContinueAvisCircuitActionComponent } from './avis-continue-circuit-action/continue-avis-circuit-action.component'; import { SendAvisParallelComponent } from './avis-parallel-send-action/send-avis-parallel-action.component'; import { GiveAvisParallelActionComponent } from './avis-give-parallel-action/give-avis-parallel-action.component'; +import { ValidateAvisParallelComponent } from './avis-parallel-validate-action/validate-avis-parallel-action.component'; @Injectable() export class ActionsService { @@ -821,5 +822,27 @@ export class ActionsService { ).subscribe(); } + validateParallelOpinionDiffusionAction(options: any = null) { + const dialogRef = this.dialog.open(ValidateAvisParallelComponent, { + autoFocus: false, + disableClose: true, + data: this.setDatasActionToSend() + }); + dialogRef.afterClosed().pipe( + tap((data: any) => { + this.unlockResourceAfterActionModal(data); + }), + filter((data: string) => data === 'success'), + tap((result: any) => { + this.endAction(result); + }), + finalize(() => this.loading = false), + catchError((err: any) => { + this.notify.handleErrors(err); + return of(false); + }) + ).subscribe(); + } + } diff --git a/src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.html b/src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.html new file mode 100644 index 00000000000..70b3fb63550 --- /dev/null +++ b/src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.html @@ -0,0 +1,59 @@ +<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> + <mat-sidenav-container autosize style="height:100%;"> + <mat-sidenav-content style="background: white;padding:10px;"> + <div> + {{lang.makeActionOn}} + <b *ngIf="data.resIds.length === 0" color="primary" class="highlight">{{lang.currentIndexingMail}}</b> + <b *ngIf="data.resIds.length == 1" color="primary" class="highlight">{{data.resource.chrono}}</b> + <b *ngIf="data.resIds.length > 1" color="primary" class="highlight">{{data.resIds.length}} + {{lang.elements}}</b> ? + </div> + <div class="alert-message alert-message-info" + *ngIf="data.resIds.length == 1 && !noResourceToProcess" + role="alert" style="margin-top: 30px;" + [innerHTML]="lang.validateAvisParallelSingle + ' <b>' + ownerOpinion + '</b>'"> + </div> + + <div class="alert-message alert-message-info" + *ngIf="data.resIds.length > 1 && !noResourceToProcess" + role="alert" style="margin-top: 30px;" [innerHTML]="lang.validateAvisParallel"></div> + + <div *ngIf="resourcesErrors.length > 0" class="alert-message alert-message-danger mailList" role="alert"> + <p> + {{lang.canNotMakeAction}} : + </p> + <ul> + <li *ngFor="let ressource of resourcesErrors"> + <b>{{ressource.alt_identifier}}</b> : {{lang[ressource.reason]}} + </li> + </ul> + </div> + <mat-form-field *ngIf="data.resIds.length === 1 && !noResourceToProcess" (click)="picker.open()" appearance="outline" style="cursor:pointer;margin-top: 10px;"> + <mat-label>{{lang.opinionLimitDate}}</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 *ngIf="data.resIds.length === 1 && !noResourceToProcess" #noteEditor [title]="lang.addOpinionReason" [content]="opinionContent" [resIds]="data.resIds"></app-note-editor> + <app-avis-workflow *ngIf="data.resIds.length === 1 && !noResourceToProcess" + [adminMode]="true" [mode]="'parallel'" #appAvisWorkflow> + </app-avis-workflow> + </mat-sidenav-content> + </mat-sidenav-container> +</div> +<div mat-dialog-actions class="actions"> + <button mat-raised-button mat-button color="primary" [disabled]="loading || !isValidAction()" + (click)="onSubmit()">{{lang.validate}}</button> + <button mat-raised-button mat-button [disabled]="loading" [mat-dialog-close]="">{{lang.cancel}}</button> +</div> \ No newline at end of file diff --git a/src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.scss b/src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.scss new file mode 100644 index 00000000000..9424211bb4a --- /dev/null +++ b/src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.scss @@ -0,0 +1,128 @@ +@import '../../../css/vars.scss'; + +.fullHeight { + height: 70vh; +} + +.fullWidth { + width: 70vw; +} + +.highlight { + font-size: 110%; +} + +.loading { + display: flex; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: #ffffffb3; + z-index: 2; + overflow: hidden; +} + +.mailList { + ul { + font-size: 12px; + max-height: 100px; + overflow: auto; + padding-left: 25px; + padding-right: 5px; + padding-bottom: 10px; + margin-top: 10px; + } + + p { + //font-size: 18px; + margin: 0; + text-decoration: underline; + } + + b { + font-size: 120%; + } +} + +.formType { + align-items: center; + display: flex; + margin: 10px; + border-radius: 4px; + border: solid 1px #ccc; + position: relative; + padding: 10px; + + &-title { + white-space: pre; + overflow: hidden; + max-width: 85%; + text-overflow: ellipsis; + z-index: 1; + font-size: 10px; + font-weight: bold; + background: white; + position: absolute; + top: -7px; + left: 10px; + padding: 0px; + margin: 0px; + color: #135f7f; + } + + ::ng-deep.mat-form-field-suffix { + color: $secondary; + font-size: 15px; + top: 0; + } + + ::ng-deep.mat-form-field-wrapper { + padding: 0; + } +} + +.priceContent { + display: flex; + align-items: center; + justify-content: flex-end; + width: 100%; + + &-label { + text-align: right; + color: $primary; + flex: 1; + justify-content: flex-end; + display: flex; + padding-right: 10px; + } + + .mat-form-field { + width: 90px !important; + + input { + font-weight: bold; + user-select: none; + } + } +} + +.priceInfo { + padding-right: 20px; + font-size: 10px; + opacity: 0.5; + width: 100%; +} + +.pjList { + display: flex; + width: 100%; + overflow: auto; + flex-direction: column; + background: #666; + + img { + margin: 10px; + } +} \ No newline at end of file diff --git a/src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.ts b/src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.ts new file mode 100644 index 00000000000..0cabda374cf --- /dev/null +++ b/src/frontend/app/actions/avis-parallel-validate-action/validate-avis-parallel-action.component.ts @@ -0,0 +1,130 @@ +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'; +import { HttpClient } from '@angular/common/http'; +import { NoteEditorComponent } from '../../notes/note-editor.component'; +import { tap, finalize, catchError } from 'rxjs/operators'; +import { of } from 'rxjs'; +import { FunctionsService } from '../../../service/functions.service'; +import { AvisWorkflowComponent } from '../../avis/avis-workflow.component'; +import { HeaderService } from '../../../service/header.service'; + +@Component({ + templateUrl: "validate-avis-parallel-action.component.html", + styleUrls: ['validate-avis-parallel-action.component.scss'], +}) +export class ValidateAvisParallelComponent implements AfterViewInit { + + lang: any = LANG; + loading: boolean = false; + + resourcesWarnings: any[] = []; + resourcesErrors: any[] = []; + + ownerOpinion: string = ''; + opinionContent: string = ''; + + noResourceToProcess: boolean = null; + + opinionLimitDate: Date = null; + + today: Date = new Date(); + + availableRoles: any[] = []; + + @ViewChild('noteEditor', { static: true }) noteEditor: NoteEditorComponent; + @ViewChild('appAvisWorkflow', { static: false }) appAvisWorkflow: AvisWorkflowComponent; + + constructor( + public http: HttpClient, + private notify: NotificationService, + public dialogRef: MatDialogRef<ValidateAvisParallelComponent>, + @Inject(MAT_DIALOG_DATA) public data: any, + public functions: FunctionsService, + private headerService: HeaderService) { } + + ngOnInit() { + this.checkAvisCircuit(); + } + + checkAvisCircuit() { + this.loading = true; + this.resourcesErrors = []; + this.resourcesWarnings = []; + this.http.post('../../rest/resourcesList/users/' + this.data.userId + '/groups/' + this.data.groupId + '/baskets/' + this.data.basketId + '/actions/' + this.data.action.id + '/checkValidateParallelOpinion', { resources: this.data.resIds }).pipe( + tap((data: any) => { + if (!this.functions.empty(data.resourcesInformations.warning)) { + this.resourcesWarnings = data.resourcesInformations.warning; + } + + if (!this.functions.empty(data.resourcesInformations.error)) { + this.resourcesErrors = data.resourcesInformations.error; + this.noResourceToProcess = this.resourcesErrors.length === this.data.resIds.length; + } + + if (!this.noResourceToProcess) { + this.ownerOpinion = data.resourcesInformations.success[0].avisUserAsk; + this.opinionContent = data.resourcesInformations.success[0].note; + this.opinionLimitDate = new Date(data.resourcesInformations.success[0].opinionLimitDate) + } + }), + finalize(() => this.loading = false), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + this.dialogRef.close(); + return of(false); + }) + ).subscribe(); + } + + async ngAfterViewInit(): Promise<void> { + if (this.data.resIds.length === 1) { + await this.appAvisWorkflow.loadParallelWorkflow(this.data.resIds[0]); + } + } + + async onSubmit() { + + const realResSelected: number[] = this.data.resIds.filter((resId: any) => this.resourcesErrors.map(resErr => resErr.res_id).indexOf(resId) === -1); + + this.executeAction(realResSelected); + + } + + executeAction(realResSelected: number[]) { + const noteContent: string = `[${this.lang.avisUserAsk.toUpperCase()}] ${this.noteEditor.getNoteContent()} ↠${this.lang.validateBy} ${this.headerService.user.firstname} ${this.headerService.user.lastname}`; + this.http.put(this.data.processActionRoute, { resources: realResSelected, data: { note: noteContent, opinionLimitDate: this.functions.formatDateObjectToFrenchDateString(this.opinionLimitDate, true), opinionCircuit: this.appAvisWorkflow.getWorkflow() } }).pipe( + tap((data: any) => { + if (!data) { + this.dialogRef.close('success'); + } + if (data && data.errors != null) { + this.notify.error(data.errors); + } + }), + finalize(() => this.loading = false), + catchError((err: any) => { + this.notify.handleErrors(err); + return of(false); + }) + ).subscribe(); + } + + isValidAction() { + if (this.data.resIds.length === 1) { + if (!this.noResourceToProcess && this.noteEditor !== undefined && 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; + } + } else { + if (!this.noResourceToProcess) { + return true; + } else { + return false; + } + } + + } +} diff --git a/src/frontend/app/app.module.ts b/src/frontend/app/app.module.ts index d36e56761c2..b64cb2d2da1 100755 --- a/src/frontend/app/app.module.ts +++ b/src/frontend/app/app.module.ts @@ -63,6 +63,7 @@ import { ContinueAvisCircuitActionComponent } from './actions/avis import { SendAvisWorkflowComponent } from './actions/avis-workflow-send-action/send-avis-workflow-action.component'; import { SendAvisParallelComponent } from './actions/avis-parallel-send-action/send-avis-parallel-action.component'; import { GiveAvisParallelActionComponent } from './actions/avis-give-parallel-action/give-avis-parallel-action.component'; +import { ValidateAvisParallelComponent } from './actions/avis-parallel-validate-action/validate-avis-parallel-action.component'; import { FiltersListComponent } from './list/filters/filters-list.component'; import { FiltersToolComponent } from './list/filters/filters-tool.component'; @@ -161,6 +162,7 @@ import { AddAvisModelModalComponent } from './avis/addAvisModel/add-avis-model-m SendAvisWorkflowComponent, SendAvisParallelComponent, GiveAvisParallelActionComponent, + ValidateAvisParallelComponent, ActionsListComponent, PrintSeparatorComponent, FolderPinnedComponent, @@ -215,6 +217,7 @@ import { AddAvisModelModalComponent } from './avis/addAvisModel/add-avis-model-m ContinueVisaCircuitActionComponent, ContinueAvisCircuitActionComponent, GiveAvisParallelActionComponent, + ValidateAvisParallelComponent, ProcessActionComponent, RedirectActionComponent, SendShippingActionComponent, diff --git a/src/frontend/app/notes/note-editor.component.ts b/src/frontend/app/notes/note-editor.component.ts index 064070dc694..206d036c8a3 100644 --- a/src/frontend/app/notes/note-editor.component.ts +++ b/src/frontend/app/notes/note-editor.component.ts @@ -16,9 +16,8 @@ export class NoteEditorComponent implements AfterViewInit { loading: boolean = false; templatesNote: any = []; - content: string = ''; - @Input('title') title: string = this.lang.addNote; + @Input('content') content: string = ''; @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 3db903c5fa3..f5071c978c8 100755 --- a/src/frontend/lang/lang-en.ts +++ b/src/frontend/lang/lang-en.ts @@ -1429,6 +1429,10 @@ export const LANG_EN = { "avisUserAsk": "for opinion", "avisUserState": "opinion", "userNotInDiffusionList": "You are not in opinion diffusion list", - "noOpinionLimiteDate": "The opinion limit date is not defined", + "noOpinionLimitDate": "The opinion limit date is not defined", "noOpinionNote": "The reason is not defined", + "opinionLimitDateOutdated": "The opinion limit date is outdated", + "validateBy": "Validate by", + "validateAvisParallel": "Your are validating an opinion request", + "validateAvisParallelSingle": "Your are validating an opinion request of", }; diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts index 5ba65656d73..d977e78194b 100755 --- a/src/frontend/lang/lang-fr.ts +++ b/src/frontend/lang/lang-fr.ts @@ -1469,6 +1469,10 @@ export const LANG_FR = { "avisUserAsk": "pour avis", "avisUserState": "avis", "userNotInDiffusionList": "Vous n'êtes pas dans la liste de diffusion des avis", - "noOpinionLimiteDate": "La date limite de l'avis n'est pas défini", + "noOpinionLimitDate": "La date limite de l'avis n'est pas défini", "noOpinionNote": "Aucun motif défini", + "opinionLimitDateOutdated": "La date limit de l'avis est dépassée", + "validateBy": "Validé par", + "validateAvisParallel": "Vous allez valider des demandes d'avis", + "validateAvisParallelSingle": "Vous allez valider la demande d'avis de", }; diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts index b59104669e6..06aec503a78 100755 --- a/src/frontend/lang/lang-nl.ts +++ b/src/frontend/lang/lang-nl.ts @@ -1454,6 +1454,10 @@ export const LANG_NL = { "avisUserAsk": "for opinion", //_TO_TRANSLATE "avisUserState": "opinion", //_TO_TRANSLATE "userNotInDiffusionList": "You are not in opinion diffusion list", //_TO_TRANSLATE - "noOpinionLimiteDate": "The opinion limit date is not defined", //_TO_TRANSLATE + "noOpinionLimitDate": "The opinion limit date is not defined", //_TO_TRANSLATE "noOpinionNote": "The reason is not defined", //_TO_TRANSLATE + "opinionLimitDateOutdated": "The opinion limit date is outdated", //_TO_TRANSLATE + "validateBy": "Validate by", //_TO_TRANSLATE + "validateAvisParallel": "Your are validating an opinion request", //_TO_TRANSLATE + "validateAvisParallelSingle": "Your are validating an opinion request of", //_TO_TRANSLATE }; -- GitLab