mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Update Signature App.vue to use a converted pdf
Introduced a new helper ts function to download documents as PDFs and integrated with the existing workflow. Enhanced `PDFSignatureZoneAvailable` to implement `LocaleAwareInterface` for better locale management and added PDF conversion handling for non-PDF documents. Updated App.vue to use the new PDF download method.
This commit is contained in:
parent
a312b45777
commit
03fe9a6d86
@ -277,7 +277,7 @@ console.log(PdfWorker); // incredible but this is needed
|
|||||||
// pdfjsLib.GlobalWorkerOptions.workerSrc = PdfWorker;
|
// pdfjsLib.GlobalWorkerOptions.workerSrc = PdfWorker;
|
||||||
|
|
||||||
import Modal from "ChillMainAssets/vuejs/_components/Modal.vue";
|
import Modal from "ChillMainAssets/vuejs/_components/Modal.vue";
|
||||||
import { download_and_decrypt_doc } from "../StoredObjectButton/helpers";
|
import {download_and_decrypt_doc, download_doc_as_pdf} from "../StoredObjectButton/helpers";
|
||||||
|
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc = "pdfjs-dist/build/pdf.worker.mjs";
|
pdfjsLib.GlobalWorkerOptions.workerSrc = "pdfjs-dist/build/pdf.worker.mjs";
|
||||||
|
|
||||||
@ -385,10 +385,7 @@ const init = () => downloadAndOpen().then(initPdf);
|
|||||||
async function downloadAndOpen(): Promise<Blob> {
|
async function downloadAndOpen(): Promise<Blob> {
|
||||||
let raw;
|
let raw;
|
||||||
try {
|
try {
|
||||||
raw = await download_and_decrypt_doc(
|
raw = await download_doc_as_pdf(signature.storedObject);
|
||||||
signature.storedObject,
|
|
||||||
signature.storedObject.currentVersion
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("error while downloading and decrypting document", e);
|
console.error("error while downloading and decrypting document", e);
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -197,6 +197,32 @@ async function download_and_decrypt_doc(storedObject: StoredObject, atVersion: n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the stored object as a pdf.
|
||||||
|
*
|
||||||
|
* If the document is already in a pdf on the server side, the document is retrieved "as is" from the usual
|
||||||
|
* storage.
|
||||||
|
*/
|
||||||
|
async function download_doc_as_pdf(storedObject: StoredObject): Promise<Blob>
|
||||||
|
{
|
||||||
|
if (null === storedObject.currentVersion) {
|
||||||
|
throw new Error("the stored object does not count any version");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (storedObject.currentVersion?.type === 'application/pdf') {
|
||||||
|
return download_and_decrypt_doc(storedObject, storedObject.currentVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
const convertLink = build_convert_link(storedObject.uuid);
|
||||||
|
const response = await fetch(convertLink);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Could not convert the document: " + response.status);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.blob();
|
||||||
|
}
|
||||||
|
|
||||||
async function is_object_ready(storedObject: StoredObject): Promise<StoredObjectStatusChange>
|
async function is_object_ready(storedObject: StoredObject): Promise<StoredObjectStatusChange>
|
||||||
{
|
{
|
||||||
const new_status_response = await window
|
const new_status_response = await window
|
||||||
@ -214,6 +240,7 @@ export {
|
|||||||
build_wopi_editor_link,
|
build_wopi_editor_link,
|
||||||
download_and_decrypt_doc,
|
download_and_decrypt_doc,
|
||||||
download_doc,
|
download_doc,
|
||||||
|
download_doc_as_pdf,
|
||||||
is_extension_editable,
|
is_extension_editable,
|
||||||
is_extension_viewable,
|
is_extension_viewable,
|
||||||
is_object_ready,
|
is_object_ready,
|
||||||
|
@ -17,15 +17,30 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum;
|
|||||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep;
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStep;
|
||||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflowStepSignature;
|
||||||
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
||||||
|
use Chill\WopiBundle\Service\WopiConverter;
|
||||||
|
use Symfony\Contracts\Translation\LocaleAwareInterface;
|
||||||
|
|
||||||
class PDFSignatureZoneAvailable
|
class PDFSignatureZoneAvailable implements LocaleAwareInterface
|
||||||
{
|
{
|
||||||
|
private string $locale;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly EntityWorkflowManager $entityWorkflowManager,
|
private readonly EntityWorkflowManager $entityWorkflowManager,
|
||||||
private readonly PDFSignatureZoneParser $pdfSignatureZoneParser,
|
private readonly PDFSignatureZoneParser $pdfSignatureZoneParser,
|
||||||
private readonly StoredObjectManagerInterface $storedObjectManager,
|
private readonly StoredObjectManagerInterface $storedObjectManager,
|
||||||
|
private readonly WopiConverter $converter,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
public function setLocale(string $locale)
|
||||||
|
{
|
||||||
|
$this->locale = $locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLocale()
|
||||||
|
{
|
||||||
|
return $this->locale;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return list<PDFSignatureZone>
|
* @return list<PDFSignatureZone>
|
||||||
*/
|
*/
|
||||||
@ -38,10 +53,16 @@ class PDFSignatureZoneAvailable
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('application/pdf' !== $storedObject->getType()) {
|
if ('application/pdf' !== $storedObject->getType()) {
|
||||||
throw new \RuntimeException('Only PDF documents are supported');
|
$content = $this->converter->convert($this->getLocale(), $this->storedObjectManager->read($storedObject), $storedObject->getType());
|
||||||
|
} else {
|
||||||
|
$content = $this->storedObjectManager->read($storedObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
$zones = $this->pdfSignatureZoneParser->findSignatureZones($this->storedObjectManager->read($storedObject));
|
$zones = $this->pdfSignatureZoneParser->findSignatureZones($content);
|
||||||
|
|
||||||
|
// free some memory as soon as possible...
|
||||||
|
unset($content);
|
||||||
|
|
||||||
$signatureZonesIndexes = array_map(
|
$signatureZonesIndexes = array_map(
|
||||||
fn (EntityWorkflowStepSignature $step) => $step->getZoneSignatureIndex(),
|
fn (EntityWorkflowStepSignature $step) => $step->getZoneSignatureIndex(),
|
||||||
$this->collectSignaturesInUse($entityWorkflow)
|
$this->collectSignaturesInUse($entityWorkflow)
|
||||||
|
@ -22,6 +22,7 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum;
|
|||||||
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
||||||
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
|
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\WopiBundle\Service\WopiConverter;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
use Symfony\Component\Clock\MockClock;
|
use Symfony\Component\Clock\MockClock;
|
||||||
@ -65,6 +66,7 @@ class PDFSignatureZoneAvailableTest extends TestCase
|
|||||||
$entityWorkflowManager->reveal(),
|
$entityWorkflowManager->reveal(),
|
||||||
$parser->reveal(),
|
$parser->reveal(),
|
||||||
$storedObjectManager->reveal(),
|
$storedObjectManager->reveal(),
|
||||||
|
$this->prophesize(WopiConverter::class)->reveal(),
|
||||||
);
|
);
|
||||||
|
|
||||||
$actual = $filter->getAvailableSignatureZones($entityWorkflow);
|
$actual = $filter->getAvailableSignatureZones($entityWorkflow);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user