diff --git a/src/app/document/controllers/DocumentController.php b/src/app/document/controllers/DocumentController.php index 61d48e6cc6a4a81bb8090c6d854cf7900a20d704..6e9aec7b520a6a6fa1829497dd998ffc1758b677 100755 --- a/src/app/document/controllers/DocumentController.php +++ b/src/app/document/controllers/DocumentController.php @@ -499,7 +499,8 @@ class DocumentController return $response->withStatus(400)->withJson(['errors' => "Body workflow[{$key}] signaturePositions is not an array"]); } foreach ($workflow['signaturePositions'] as $keySP => $signaturePosition) { - if (empty($signaturePosition['positionX']) || empty($signaturePosition['positionY']) || empty($signaturePosition['page'])) { + if (!Validator::each(Validator::between(0, 100, true))->validate([$signaturePosition['positionX'], $signaturePosition['positionY']]) + || !Validator::intVal()->positive()->validate($signaturePosition['page'])) { return $response->withStatus(400)->withJson(['errors' => "Body workflow[{$key}][signaturePositions][{$keySP}] is wrong formatted"]); } } @@ -509,7 +510,8 @@ class DocumentController return $response->withStatus(400)->withJson(['errors' => "Body workflow[{$key}] datePositions is not an array"]); } foreach ($workflow['datePositions'] as $keyDP => $datePosition) { - if (empty($datePosition['positionX']) || empty($datePosition['positionY']) || empty($datePosition['page'])) { + if (!Validator::each(Validator::between(0, 100, true))->validate([$datePosition['positionX'], $datePosition['positionY']]) + || !Validator::intVal()->positive()->validate($datePosition['page'])) { return $response->withStatus(400)->withJson(['errors' => "Body workflow[{$key}][datePositions][{$keyDP}] is wrong formatted"]); } elseif (empty($datePosition['color']) || empty($datePosition['font']) || empty($datePosition['format']) || empty($datePosition['width'])) { return $response->withStatus(400)->withJson(['errors' => "Body workflow[{$key}][datePositions][{$keyDP}] is wrong formatted"]); diff --git a/src/frontend/app/document/visa-workflow/visa-workflow.component.ts b/src/frontend/app/document/visa-workflow/visa-workflow.component.ts index 21ee72d5939cbed3a12394d0af743914766b4108..db4cd09b78b9a64c00c95575ef4e54f932d91c63 100644 --- a/src/frontend/app/document/visa-workflow/visa-workflow.component.ts +++ b/src/frontend/app/document/visa-workflow/visa-workflow.component.ts @@ -22,7 +22,7 @@ import { FunctionsService } from '../../service/functions.service'; export class VisaWorkflowComponent implements OnInit { @Input() editMode: boolean = false; - @Input() visaWorkflow: any = []; + @Input() visaWorkflow: any[] = []; @ViewChild(IonReorderGroup) reorderGroup: IonReorderGroup; loading: boolean = false; @@ -37,6 +37,8 @@ export class VisaWorkflowComponent implements OnInit { hasConnector: boolean = false; userDelegated: boolean = false; + tmpArray: any[] = []; + constructor( public http: HttpClient, private translate: TranslateService, @@ -406,20 +408,55 @@ export class VisaWorkflowComponent implements OnInit { }); } - setPositionsWorkfow(resource: any, positions: any[]) { - this.clearPositionsFromResource(resource); + setPositionsWorkfow(resources: any[], index: number, positions: any[]) { + this.clearPositionsFromResource(resources[index]); if (positions.length > 0) { Object.keys(positions).forEach(key => { const objPos = { ...positions[key], - mainDocument : resource.mainDocument, + mainDocument : resources[index].mainDocument, }; - this.visaWorkflow[positions[key].sequence].signaturePositions = this.visaWorkflow[positions[key].sequence].signaturePositions.filter((pos: any) => pos.mainDocument !== resource.mainDocument); this.visaWorkflow[positions[key].sequence].signaturePositions.push(objPos); + + const existingObject: any = this.tmpArray.find((item: any) => item.key === positions[key].sequence && item.page === positions[key].page && item.docIndex === resources.indexOf(resources[index])); + if (existingObject !== undefined) { + this.tmpArray[this.tmpArray.indexOf(existingObject)].signaturePositions = positions[key].position; + } else { + this.tmpArray.push({ + key: positions[key].sequence, + page: positions[key].page, + docIndex: resources.indexOf(resources[index]), + signaturePositions: positions[key].position + }); + } + }); + + this.tmpArray.forEach((element: any) => { + const existingObject: any = (this.visaWorkflow[element.key].signaturePositions as any[]).find((item: any) => item.page === element.page && item.sequence === element.key && item.docIndex === element.docIndex); + if (existingObject !== undefined) { + this.updatePositionsWorkfow(existingObject, element); + } else { + (this.visaWorkflow[element.key].signaturePositions as any[]).push( + { + docIndex: element.docIndex, + page: element.page, + mainDocument: true, + sequence: element.key, + position: element.signaturePositions + } + ); + } }); } } + updatePositionsWorkfow(object: any, data: any) { + this.visaWorkflow.forEach((element: any) => { + element.signaturePositions[(element.signaturePositions as any[]).indexOf(object)].position = data.signaturePositions; + }); + } + + clearPositionsFromResource(resource: any) { this.visaWorkflow.forEach((user: any) => { user.signaturePositions = user.signaturePositions.filter((pos: any) => pos.mainDocument !== resource.mainDocument); diff --git a/src/frontend/app/indexation/indexation.component.ts b/src/frontend/app/indexation/indexation.component.ts index 3273ee61fd0d942b82f4a7d2aa6d732b159e9001..83fb369cdbdb3b5102a2e5218c945a00f5902c52 100644 --- a/src/frontend/app/indexation/indexation.component.ts +++ b/src/frontend/app/indexation/indexation.component.ts @@ -188,7 +188,7 @@ export class IndexationComponent implements OnInit { load.present(); const objTosend = this.formatData(data.note); for (let index = 0; index < objTosend.length; index++) { - await this.saveDocument(objTosend[index], index); + await this.saveDocument(objTosend, index); if (objTosend[0].workflow[0].userId === this.authService.user.id) { this.actionsService.setEvent('refreshList'); } @@ -207,14 +207,19 @@ export class IndexationComponent implements OnInit { } saveDocument(data: any, index: number) { + data.forEach((element: any) => { + (element.workflow as any[]).forEach((item: any) => { + item.signaturePositions = (item.signaturePositions as any[]).filter((el: any) => el.docIndex === data.indexOf(element)); + }); + }); return new Promise((resolve) => { - this.http.post('../rest/documents', data).pipe( + this.http.post('../rest/documents', data[index]).pipe( tap(() => { this.errors = []; }), finalize(() => resolve(true)), catchError((err: any) => { - this.errors.push(data.title); + this.errors.push(data[index].title); this.notificationService.handleErrors(err); return of(false); }) @@ -273,6 +278,7 @@ export class IndexationComponent implements OnInit { signatureMode: this.authService.getSignatureMode(item.role), signaturePositions: item.signaturePositions !== undefined ? this.formatPositions(item.signaturePositions.filter((pos: any) => pos.mainDocument === file.mainDocument && file.signPos !== undefined)).map((itemFile: any) => ({ page: itemFile.page, + docIndex: itemFile.docIndex, positionX: itemFile.position.positionX, positionY: itemFile.position.positionY, })) : [] @@ -360,6 +366,11 @@ export class IndexationComponent implements OnInit { deleteFile(index: number) { this.filesToUpload.splice(index, 1); + if (this.filesToUpload.length === 0) { + this.appVisaWorkflow.getCurrentWorkflow().forEach((element: any) => { + element.signaturePositions = []; + }); + } } async signPos(index: number) { @@ -378,16 +389,17 @@ export class IndexationComponent implements OnInit { component: SignaturePositionComponent, cssClass: 'custom-alert-fullscreen', componentProps: { - 'workflow': this.appVisaWorkflow.getCurrentWorkflow(), - 'resource': this.filesToUpload[index], - 'pdfContent': 'data:application/pdf;base64,' + this.filesToUpload[index].content, + workflow: this.appVisaWorkflow.getCurrentWorkflow(), + resource: this.filesToUpload[index], + pdfContent: 'data:application/pdf;base64,' + this.filesToUpload[index].content, + docIndex: this.filesToUpload.indexOf(this.filesToUpload[index]) } }); await modal.present(); const { data } = await modal.onWillDismiss(); if (data !== undefined) { this.filesToUpload[index].signPos = data; - this.appVisaWorkflow.setPositionsWorkfow(this.filesToUpload[index], data); + this.appVisaWorkflow.setPositionsWorkfow(this.filesToUpload, index, data); } } else { this.notificationService.error('lang.mustSetWorkflowBeforeSignPositions'); diff --git a/src/frontend/app/indexation/signature-position/signature-position.component.ts b/src/frontend/app/indexation/signature-position/signature-position.component.ts index 8e3bf242a28cf19c48f8840c24764c0326fefbeb..904e94434351c2dcb9c08421f17d0e9f6fc53b7c 100644 --- a/src/frontend/app/indexation/signature-position/signature-position.component.ts +++ b/src/frontend/app/indexation/signature-position/signature-position.component.ts @@ -14,6 +14,7 @@ export class SignaturePositionComponent implements OnInit { @Input() workflow: any[] = []; @Input() resource: any = []; @Input() pdfContent: any = null; + @Input() docIndex: number = null; loading: boolean = false; dragging: boolean = false; @@ -61,9 +62,10 @@ export class SignaturePositionComponent implements OnInit { initSignPos() { this.workflow.forEach((user: any, index: number) => { if (user.signaturePositions?.length > 0) { - this.signList = this.signList.concat(user.signaturePositions.filter((pos: any) => pos.mainDocument === this.resource.mainDocument).map((pos: any) => ({ + this.signList = this.signList.concat(user.signaturePositions.filter((pos: any) => pos.mainDocument === this.resource.mainDocument && pos.docIndex === this.docIndex).map((pos: any) => ({ ...pos, - sequence : index + sequence : index, + docIndex: this.docIndex, }))); } }); @@ -103,8 +105,14 @@ export class SignaturePositionComponent implements OnInit { } moveSign(event: any, i: number) { - const percentx = (event.x * 100) / this.workingAreaWidth; - const percenty = (event.y * 100) / this.workingAreaHeight; + let percentx = (event.x * 100) / this.workingAreaWidth; + let percenty = (event.y * 100) / this.workingAreaHeight; + + percentx = percentx < 0 ? 0 : percentx; + percentx = percentx > 100 ? 100 : percentx; + percenty = percenty < 0 ? 0 : percenty; + percenty = percenty > 100 ? 100 : percenty; + this.signList.filter((item: any) => item.sequence === this.currentUser && item.page === this.currentPage)[0].position.positionX = percentx; this.signList.filter((item: any) => item.sequence === this.currentUser && item.page === this.currentPage)[0].position.positionY = percenty; this.dragging = false; @@ -119,6 +127,7 @@ export class SignaturePositionComponent implements OnInit { { sequence: this.currentUser, page: this.currentPage, + docIndex: this.docIndex, position: { positionX: 75, positionY: 90