signature: add index on PDFSignatureZone + init POST signature

This commit is contained in:
nobohan 2024-07-11 08:06:18 +02:00
parent 39d3ba2f40
commit 77da2c1ac6
7 changed files with 66 additions and 20 deletions

View File

@ -16,7 +16,9 @@ use Chill\DocStoreBundle\Service\Signature\Driver\BaseSigner\RequestPdfSignMessa
use Chill\DocStoreBundle\Service\Signature\PDFPage; use Chill\DocStoreBundle\Service\Signature\PDFPage;
use Chill\DocStoreBundle\Service\Signature\PDFSignatureZone; use Chill\DocStoreBundle\Service\Signature\PDFSignatureZone;
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface; use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
use Symfony\Component\HttpFoundation\Response; use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
@ -28,19 +30,41 @@ class SignatureRequestController
) {} ) {}
#[Route('/api/1.0/document/workflow/{id}/signature-request', name: 'chill_docstore_signature_request')] #[Route('/api/1.0/document/workflow/{id}/signature-request', name: 'chill_docstore_signature_request')]
public function processSignature(StoredObject $storedObject): Response //public function processSignature(EntityWorkflowStepSignature $signature): Response // using ParamConverter
public function processSignature(EntityWorkflowStepSignature $signature, Request $request): JsonResponse
{ {
$content = $this->storedObjectManager->read($storedObject); dump($signature);
// $signature = $this->signatureRepository($signature); //not useful?
// $entityWorkflow = $signature->getStep()->getEntityWorkflow();
// $storedObject = $this->entityWorkflowManager->getAssociatedStoredObject($entityWorkflow);
dump($request);
// TODO parse payload: json_decode ou, mieux, dataTransfertObject
// dump($request);
$data = \json_decode((string) $request->getContent(), true, 512, JSON_THROW_ON_ERROR);
dump($data);
$signatureId = 1;
$storedObjectId = 9; //$data['storedObject']['id'];
$content = 'blop';// $this->storedObjectManager->read($storedObjectId);
$zone = new PDFSignatureZone(
$data['zone']['index'],
$data['zone']['x'],
$data['zone']['y'],
$data['zone']['height'],
$data['zone']['width'],
$page = new PDFPage($data['zone']['PDFPage']['index'], $data['zone']['PDFPage']['width'], $data['zone']['PDFPage']['height'])
);
$this->messageBus->dispatch(new RequestPdfSignMessage( $this->messageBus->dispatch(new RequestPdfSignMessage(
0, $signatureId,
new PDFSignatureZone(10.0, 10.0, 180.0, 180.0, new PDFPage(0, 500.0, 800.0)), $zone,
0, $data['zone']['index'],
'test signature', 'test signature', //reason (string)
'Mme Caroline Diallo', 'Mme Caroline Diallo', //signerText (string)
$content $content
)); ));
return new Response('<html><head><title>test</title></head><body><p>ok</p></body></html>'); return new JsonResponse(null, JsonResponse::HTTP_OK, []);
} }
} }

View File

@ -68,11 +68,12 @@ export interface PDFPage {
height: number, height: number,
} }
export interface SignatureZone { export interface SignatureZone {
PDFPage: PDFPage, index: number,
x: number, x: number,
y: number, y: number,
width: number, width: number,
height: number, height: number,
PDFPage: PDFPage,
} }
export interface Signature { export interface Signature {

View File

@ -110,6 +110,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, Ref, reactive } from "vue"; import { ref, Ref, reactive } from "vue";
import { Signature, SignatureZone } from "../../types"; import { Signature, SignatureZone } from "../../types";
import { makeFetch } from "../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods";
import * as pdfjsLib from "pdfjs-dist"; import * as pdfjsLib from "pdfjs-dist";
import { import {
PDFDocumentProxy, PDFDocumentProxy,
@ -321,11 +322,24 @@ const confirm_sign = () => {
console.log(userSignatureZones.value); console.log(userSignatureZones.value);
loading.value = true; loading.value = true;
//TODO POST userSignatureZones to backend //TODO POST userSignatureZones to backend
setTimeout(() => { const url = `/api/1.0/document/workflow/${signature.id}/signature-request`;
loading.value = false; const body = {
modalOpen.value = false; storedObject: signature.storedObject,
signed.value = true; zone: userSignatureZones.value,
}, 3000); // FAKE };
makeFetch('POST', url, body)
.then(r => {
})
.catch((error) => {
});
// setTimeout(() => {
// loading.value = false;
// modalOpen.value = false;
// signed.value = true;
// }, 3000); // FAKE
}; };
const undo_sign = async () => { const undo_sign = async () => {

View File

@ -16,6 +16,8 @@ use Symfony\Component\Serializer\Annotation\Groups;
final readonly class PDFSignatureZone final readonly class PDFSignatureZone
{ {
public function __construct( public function __construct(
#[Groups(['read'])]
public int $index,
#[Groups(['read'])] #[Groups(['read'])]
public float $x, public float $x,
#[Groups(['read'])] #[Groups(['read'])]
@ -31,7 +33,8 @@ final readonly class PDFSignatureZone
public function equals(self $other): bool public function equals(self $other): bool
{ {
return return
$this->x == $other->x $this->index == $other->index
&& $this->x == $other->x
&& $this->y == $other->y && $this->y == $other->y
&& $this->height == $other->height && $this->height == $other->height
&& $this->width == $other->width && $this->width == $other->width

View File

@ -37,6 +37,7 @@ class PDFSignatureZoneParser
$defaults = $pdf->getObjectsByType('Pages'); $defaults = $pdf->getObjectsByType('Pages');
$defaultPage = reset($defaults); $defaultPage = reset($defaults);
$defaultPageDetails = $defaultPage->getDetails(); $defaultPageDetails = $defaultPage->getDetails();
$zoneIndex = 0;
foreach ($pdf->getPages() as $index => $page) { foreach ($pdf->getPages() as $index => $page) {
$details = $page->getDetails(); $details = $page->getDetails();
@ -48,7 +49,8 @@ class PDFSignatureZoneParser
foreach ($page->getDataTm() as $dataTm) { foreach ($page->getDataTm() as $dataTm) {
if (str_starts_with($dataTm[1], self::ZONE_SIGNATURE_START)) { if (str_starts_with($dataTm[1], self::ZONE_SIGNATURE_START)) {
$zones[] = new PDFSignatureZone((float) $dataTm[0][4], (float) $dataTm[0][5], $this->defaultHeight, $this->defaultWidth, $pdfPage); $zones[] = new PDFSignatureZone((int) $zoneIndex, (float) $dataTm[0][4], (float) $dataTm[0][5], $this->defaultHeight, $this->defaultWidth, $pdfPage);
$zoneIndex++;
} }
} }
} }

View File

@ -36,7 +36,7 @@ class RequestPdfSignMessageSerializerTest extends TestCase
$envelope = new Envelope( $envelope = new Envelope(
$request = new RequestPdfSignMessage( $request = new RequestPdfSignMessage(
0, 0,
new PDFSignatureZone(10.0, 10.0, 180.0, 180.0, new PDFPage(0, 500.0, 800.0)), new PDFSignatureZone(0, 10.0, 10.0, 180.0, 180.0, new PDFPage(0, 500.0, 800.0)),
0, 0,
'metadata to add to the signature', 'metadata to add to the signature',
'Mme Caroline Diallo', 'Mme Caroline Diallo',
@ -66,7 +66,7 @@ class RequestPdfSignMessageSerializerTest extends TestCase
$request = new RequestPdfSignMessage( $request = new RequestPdfSignMessage(
0, 0,
new PDFSignatureZone(10.0, 10.0, 180.0, 180.0, new PDFPage(0, 500.0, 800.0)), new PDFSignatureZone(0, 10.0, 10.0, 180.0, 180.0, new PDFPage(0, 500.0, 800.0)),
0, 0,
'metadata to add to the signature', 'metadata to add to the signature',
'Mme Caroline Diallo', 'Mme Caroline Diallo',
@ -121,7 +121,7 @@ class RequestPdfSignMessageSerializerTest extends TestCase
$denormalizer = new class () implements DenormalizerInterface { $denormalizer = new class () implements DenormalizerInterface {
public function denormalize($data, string $type, ?string $format = null, array $context = []) public function denormalize($data, string $type, ?string $format = null, array $context = [])
{ {
return new PDFSignatureZone(10.0, 10.0, 180.0, 180.0, new PDFPage(0, 500.0, 800.0)); return new PDFSignatureZone(0, 10.0, 10.0, 180.0, 180.0, new PDFPage(0, 500.0, 800.0));
} }
public function supportsDenormalization($data, string $type, ?string $format = null) public function supportsDenormalization($data, string $type, ?string $format = null)

View File

@ -58,6 +58,7 @@ class PDFSignatureZoneParserTest extends TestCase
__DIR__.'/data/signature_2_signature_page_1.pdf', __DIR__.'/data/signature_2_signature_page_1.pdf',
[ [
new PDFSignatureZone( new PDFSignatureZone(
0,
127.7, 127.7,
95.289, 95.289,
180.0, 180.0,
@ -65,6 +66,7 @@ class PDFSignatureZoneParserTest extends TestCase
$page = new PDFPage(0, 595.30393, 841.8897) $page = new PDFPage(0, 595.30393, 841.8897)
), ),
new PDFSignatureZone( new PDFSignatureZone(
1,
269.5, 269.5,
95.289, 95.289,
180.0, 180.0,