mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
signature: add index on PDFSignatureZone + init POST signature
This commit is contained in:
parent
39d3ba2f40
commit
77da2c1ac6
@ -16,7 +16,9 @@ use Chill\DocStoreBundle\Service\Signature\Driver\BaseSigner\RequestPdfSignMessa
|
||||
use Chill\DocStoreBundle\Service\Signature\PDFPage;
|
||||
use Chill\DocStoreBundle\Service\Signature\PDFSignatureZone;
|
||||
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\Routing\Annotation\Route;
|
||||
|
||||
@ -28,19 +30,41 @@ class SignatureRequestController
|
||||
) {}
|
||||
|
||||
#[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(
|
||||
0,
|
||||
new PDFSignatureZone(10.0, 10.0, 180.0, 180.0, new PDFPage(0, 500.0, 800.0)),
|
||||
0,
|
||||
'test signature',
|
||||
'Mme Caroline Diallo',
|
||||
$signatureId,
|
||||
$zone,
|
||||
$data['zone']['index'],
|
||||
'test signature', //reason (string)
|
||||
'Mme Caroline Diallo', //signerText (string)
|
||||
$content
|
||||
));
|
||||
|
||||
return new Response('<html><head><title>test</title></head><body><p>ok</p></body></html>');
|
||||
return new JsonResponse(null, JsonResponse::HTTP_OK, []);
|
||||
}
|
||||
}
|
||||
|
@ -68,11 +68,12 @@ export interface PDFPage {
|
||||
height: number,
|
||||
}
|
||||
export interface SignatureZone {
|
||||
PDFPage: PDFPage,
|
||||
index: number,
|
||||
x: number,
|
||||
y: number,
|
||||
width: number,
|
||||
height: number,
|
||||
PDFPage: PDFPage,
|
||||
}
|
||||
|
||||
export interface Signature {
|
||||
|
@ -110,6 +110,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, Ref, reactive } from "vue";
|
||||
import { Signature, SignatureZone } from "../../types";
|
||||
import { makeFetch } from "../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods";
|
||||
import * as pdfjsLib from "pdfjs-dist";
|
||||
import {
|
||||
PDFDocumentProxy,
|
||||
@ -321,11 +322,24 @@ const confirm_sign = () => {
|
||||
console.log(userSignatureZones.value);
|
||||
loading.value = true;
|
||||
//TODO POST userSignatureZones to backend
|
||||
setTimeout(() => {
|
||||
loading.value = false;
|
||||
modalOpen.value = false;
|
||||
signed.value = true;
|
||||
}, 3000); // FAKE
|
||||
const url = `/api/1.0/document/workflow/${signature.id}/signature-request`;
|
||||
const body = {
|
||||
storedObject: signature.storedObject,
|
||||
zone: userSignatureZones.value,
|
||||
};
|
||||
makeFetch('POST', url, body)
|
||||
.then(r => {
|
||||
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
});
|
||||
|
||||
// setTimeout(() => {
|
||||
// loading.value = false;
|
||||
// modalOpen.value = false;
|
||||
// signed.value = true;
|
||||
// }, 3000); // FAKE
|
||||
};
|
||||
|
||||
const undo_sign = async () => {
|
||||
|
@ -16,6 +16,8 @@ use Symfony\Component\Serializer\Annotation\Groups;
|
||||
final readonly class PDFSignatureZone
|
||||
{
|
||||
public function __construct(
|
||||
#[Groups(['read'])]
|
||||
public int $index,
|
||||
#[Groups(['read'])]
|
||||
public float $x,
|
||||
#[Groups(['read'])]
|
||||
@ -31,7 +33,8 @@ final readonly class PDFSignatureZone
|
||||
public function equals(self $other): bool
|
||||
{
|
||||
return
|
||||
$this->x == $other->x
|
||||
$this->index == $other->index
|
||||
&& $this->x == $other->x
|
||||
&& $this->y == $other->y
|
||||
&& $this->height == $other->height
|
||||
&& $this->width == $other->width
|
||||
|
@ -37,6 +37,7 @@ class PDFSignatureZoneParser
|
||||
$defaults = $pdf->getObjectsByType('Pages');
|
||||
$defaultPage = reset($defaults);
|
||||
$defaultPageDetails = $defaultPage->getDetails();
|
||||
$zoneIndex = 0;
|
||||
|
||||
foreach ($pdf->getPages() as $index => $page) {
|
||||
$details = $page->getDetails();
|
||||
@ -48,7 +49,8 @@ class PDFSignatureZoneParser
|
||||
|
||||
foreach ($page->getDataTm() as $dataTm) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ class RequestPdfSignMessageSerializerTest extends TestCase
|
||||
$envelope = new Envelope(
|
||||
$request = new RequestPdfSignMessage(
|
||||
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,
|
||||
'metadata to add to the signature',
|
||||
'Mme Caroline Diallo',
|
||||
@ -66,7 +66,7 @@ class RequestPdfSignMessageSerializerTest extends TestCase
|
||||
|
||||
$request = new RequestPdfSignMessage(
|
||||
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,
|
||||
'metadata to add to the signature',
|
||||
'Mme Caroline Diallo',
|
||||
@ -121,7 +121,7 @@ class RequestPdfSignMessageSerializerTest extends TestCase
|
||||
$denormalizer = new class () implements DenormalizerInterface {
|
||||
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)
|
||||
|
@ -58,6 +58,7 @@ class PDFSignatureZoneParserTest extends TestCase
|
||||
__DIR__.'/data/signature_2_signature_page_1.pdf',
|
||||
[
|
||||
new PDFSignatureZone(
|
||||
0,
|
||||
127.7,
|
||||
95.289,
|
||||
180.0,
|
||||
@ -65,6 +66,7 @@ class PDFSignatureZoneParserTest extends TestCase
|
||||
$page = new PDFPage(0, 595.30393, 841.8897)
|
||||
),
|
||||
new PDFSignatureZone(
|
||||
1,
|
||||
269.5,
|
||||
95.289,
|
||||
180.0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user