mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
signature: check for signature state
This commit is contained in:
parent
77da2c1ac6
commit
421226c0dc
@ -17,6 +17,8 @@ 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 Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
|
||||||
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum;
|
||||||
|
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
@ -27,26 +29,20 @@ class SignatureRequestController
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private MessageBusInterface $messageBus,
|
private MessageBusInterface $messageBus,
|
||||||
private StoredObjectManagerInterface $storedObjectManager,
|
private StoredObjectManagerInterface $storedObjectManager,
|
||||||
|
private EntityWorkflowManager $entityWorkflowManager,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[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(EntityWorkflowStepSignature $signature): Response // using ParamConverter
|
|
||||||
public function processSignature(EntityWorkflowStepSignature $signature, Request $request): JsonResponse
|
public function processSignature(EntityWorkflowStepSignature $signature, Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
dump($signature);
|
dump($signature);
|
||||||
// $signature = $this->signatureRepository($signature); //not useful?
|
// $signature = $this->signatureRepository($signature); //not useful?
|
||||||
// $entityWorkflow = $signature->getStep()->getEntityWorkflow();
|
// $entityWorkflow = $signature->getStep()->getEntityWorkflow();
|
||||||
// $storedObject = $this->entityWorkflowManager->getAssociatedStoredObject($entityWorkflow);
|
// $storedObject = $this->entityWorkflowManager->getAssociatedStoredObject($entityWorkflow);
|
||||||
|
$content = 'blop';// $this->storedObjectManager->read($storedObject);
|
||||||
|
|
||||||
dump($request);
|
$data = \json_decode((string) $request->getContent(), true, 512, JSON_THROW_ON_ERROR); // TODO parse payload: json_decode ou, mieux, dataTransfertObject
|
||||||
// TODO parse payload: json_decode ou, mieux, dataTransfertObject
|
|
||||||
// dump($request);
|
|
||||||
$data = \json_decode((string) $request->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
|
||||||
dump($data);
|
dump($data);
|
||||||
$signatureId = 1;
|
|
||||||
$storedObjectId = 9; //$data['storedObject']['id'];
|
|
||||||
$content = 'blop';// $this->storedObjectManager->read($storedObjectId);
|
|
||||||
|
|
||||||
$zone = new PDFSignatureZone(
|
$zone = new PDFSignatureZone(
|
||||||
$data['zone']['index'],
|
$data['zone']['index'],
|
||||||
$data['zone']['x'],
|
$data['zone']['x'],
|
||||||
@ -57,7 +53,7 @@ class SignatureRequestController
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->messageBus->dispatch(new RequestPdfSignMessage(
|
$this->messageBus->dispatch(new RequestPdfSignMessage(
|
||||||
$signatureId,
|
$signature->getId(),
|
||||||
$zone,
|
$zone,
|
||||||
$data['zone']['index'],
|
$data['zone']['index'],
|
||||||
'test signature', //reason (string)
|
'test signature', //reason (string)
|
||||||
@ -67,4 +63,10 @@ class SignatureRequestController
|
|||||||
|
|
||||||
return new JsonResponse(null, JsonResponse::HTTP_OK, []);
|
return new JsonResponse(null, JsonResponse::HTTP_OK, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/api/1.0/document/workflow/{id}/check-signature', name: 'chill_docstore_check_signature')]
|
||||||
|
public function checkSignature(EntityWorkflowStepSignature $signature): JsonResponse
|
||||||
|
{
|
||||||
|
return new JsonResponse($signature->getState(), JsonResponse::HTTP_OK, []);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,4 +80,6 @@ export interface Signature {
|
|||||||
id: number,
|
id: number,
|
||||||
storedObject: StoredObject,
|
storedObject: StoredObject,
|
||||||
zones: SignatureZone[],
|
zones: SignatureZone[],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SignedState = 'pending' | 'signed' | 'rejected' | 'canceled' | 'error';
|
@ -32,7 +32,11 @@
|
|||||||
v-if="signature.zones.length > 1"
|
v-if="signature.zones.length > 1"
|
||||||
>
|
>
|
||||||
<div class="col-4 gap-2 d-grid">
|
<div class="col-4 gap-2 d-grid">
|
||||||
<button :disabled="zone < 1" class="btn btn-light btn-sm" @click="turn_signature(-1)">
|
<button
|
||||||
|
:disabled="zone < 1"
|
||||||
|
class="btn btn-light btn-sm"
|
||||||
|
@click="turn_signature(-1)"
|
||||||
|
>
|
||||||
{{ $t("last_sign_zone") }}
|
{{ $t("last_sign_zone") }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@ -71,7 +75,7 @@
|
|||||||
<canvas class="m-auto" id="canvas"></canvas>
|
<canvas class="m-auto" id="canvas"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12 p-4" id="action-buttons" v-if="!signed">
|
<div class="col-12 p-4" id="action-buttons" v-if="signedState !== 'signed'">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<button
|
<button
|
||||||
@ -109,7 +113,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, SignedState } from "../../types";
|
||||||
import { makeFetch } from "../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods";
|
import { makeFetch } from "../../../../../ChillMainBundle/Resources/public/lib/api/apiMethods";
|
||||||
import * as pdfjsLib from "pdfjs-dist";
|
import * as pdfjsLib from "pdfjs-dist";
|
||||||
import {
|
import {
|
||||||
@ -134,7 +138,7 @@ pdfjsLib.GlobalWorkerOptions.workerSrc = "pdfjs-dist/build/pdf.worker.mjs";
|
|||||||
|
|
||||||
const modalOpen: Ref<boolean> = ref(false);
|
const modalOpen: Ref<boolean> = ref(false);
|
||||||
const loading: Ref<boolean> = ref(false);
|
const loading: Ref<boolean> = ref(false);
|
||||||
const signed: Ref<boolean> = ref(false);
|
const signedState: Ref<SignedState> = ref("pending");
|
||||||
const page: Ref<number> = ref(1);
|
const page: Ref<number> = ref(1);
|
||||||
const pageCount: Ref<number> = ref(0);
|
const pageCount: Ref<number> = ref(0);
|
||||||
const zone: Ref<number> = ref(0);
|
const zone: Ref<number> = ref(0);
|
||||||
@ -235,10 +239,7 @@ const canvas_click = (e: PointerEvent, canvas: HTMLCanvasElement) =>
|
|||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
set_page(page.value);
|
set_page(page.value);
|
||||||
setTimeout(
|
setTimeout(() => draw_zone(z, ctx, canvas.width, canvas.height), 200);
|
||||||
() => draw_zone(z, ctx, canvas.width, canvas.height),
|
|
||||||
200
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
userSignatureZones.value = z;
|
userSignatureZones.value = z;
|
||||||
}
|
}
|
||||||
@ -318,28 +319,74 @@ const add_zones = (page: number) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const check_signature = () => {
|
||||||
|
const url = `/api/1.0/document/workflow/${signature.id}/check-signature`;
|
||||||
|
return makeFetch("GET", url)
|
||||||
|
.then((r) => {
|
||||||
|
signedState.value = r as SignedState;
|
||||||
|
if (signedState.value === "pending") {
|
||||||
|
check_for_ready();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
signedState.value = "error";
|
||||||
|
console.log('Error while checking the signature', error);
|
||||||
|
//TODO toast error
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const maxTryForReady = 60; //2 minutes for trying to sign
|
||||||
|
let tryForReady = 0;
|
||||||
|
|
||||||
|
const stop_try_signing = () => {
|
||||||
|
loading.value = false;
|
||||||
|
modalOpen.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const check_for_ready = () => {
|
||||||
|
if (tryForReady > maxTryForReady) {
|
||||||
|
signedState.value = "error";
|
||||||
|
stop_try_signing();
|
||||||
|
console.log("Reached the maximum number of tentative to try signing");
|
||||||
|
//TODO toast error
|
||||||
|
}
|
||||||
|
if (signedState.value === "rejected") {
|
||||||
|
stop_try_signing();
|
||||||
|
console.log("Signature rejected by the server");
|
||||||
|
//TODO toast error
|
||||||
|
}
|
||||||
|
if (signedState.value === "canceled") {
|
||||||
|
stop_try_signing();
|
||||||
|
console.log("Signature canceledconsole.log('Error while posting the signature', error);");
|
||||||
|
//TODO toast error
|
||||||
|
}
|
||||||
|
if (signedState.value === "pending") {
|
||||||
|
tryForReady = tryForReady + 1;
|
||||||
|
setTimeout(() => check_signature(), 2000);
|
||||||
|
} else {
|
||||||
|
stop_try_signing();
|
||||||
|
if (signedState.value === "signed") {
|
||||||
|
//TODO recharger le document signé
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const confirm_sign = () => {
|
const confirm_sign = () => {
|
||||||
console.log(userSignatureZones.value);
|
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
//TODO POST userSignatureZones to backend
|
|
||||||
const url = `/api/1.0/document/workflow/${signature.id}/signature-request`;
|
const url = `/api/1.0/document/workflow/${signature.id}/signature-request`;
|
||||||
const body = {
|
const body = {
|
||||||
storedObject: signature.storedObject,
|
storedObject: signature.storedObject,
|
||||||
zone: userSignatureZones.value,
|
zone: userSignatureZones.value,
|
||||||
};
|
};
|
||||||
makeFetch('POST', url, body)
|
makeFetch("POST", url, body)
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
|
check_for_ready();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
console.log('Error while posting the signature', error);
|
||||||
});
|
stop_try_signing();
|
||||||
|
//TODO toast
|
||||||
// setTimeout(() => {
|
});
|
||||||
// loading.value = false;
|
|
||||||
// modalOpen.value = false;
|
|
||||||
// signed.value = true;
|
|
||||||
// }, 3000); // FAKE
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const undo_sign = async () => {
|
const undo_sign = async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user