mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-08 08:49:52 +00:00
FEATURE signature: show full pages - WIP
This commit is contained in:
parent
b9e515f4e6
commit
c2882b1079
@ -57,6 +57,29 @@
|
|||||||
❯
|
❯
|
||||||
</button>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-if="pageCount > 1">
|
||||||
|
<button
|
||||||
|
class="btn btn-light btn-xs p-1"
|
||||||
|
:disabled="page <= 1"
|
||||||
|
@click="turnPage(-1)"
|
||||||
|
>
|
||||||
|
❮
|
||||||
|
</button>
|
||||||
|
<span>{{ page }}/{{ pageCount }}</span>
|
||||||
|
<button
|
||||||
|
class="btn btn-light btn-xs p-1"
|
||||||
|
:disabled="page >= pageCount"
|
||||||
|
@click="turnPage(1)"
|
||||||
|
>
|
||||||
|
❯
|
||||||
|
</button>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="checkbox"
|
||||||
|
v-model="multiPage"
|
||||||
|
@change="toggleMultiPage"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="signature.zones.length > 1"
|
v-if="signature.zones.length > 1"
|
||||||
@ -148,6 +171,12 @@
|
|||||||
>
|
>
|
||||||
❯
|
❯
|
||||||
</button>
|
</button>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="checkbox"
|
||||||
|
v-model="multiPage"
|
||||||
|
@change="toggleMultiPage"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@ -233,12 +262,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
v-if="multiPage"
|
||||||
|
class="col-xs-12 col-md-12 col-lg-9 m-auto my-5 text-center"
|
||||||
|
:class="{ onAddZone: canvasEvent === 'add' }"
|
||||||
|
>
|
||||||
|
<canvas
|
||||||
|
v-for="p in pageCount"
|
||||||
|
:key="p"
|
||||||
|
class="m-auto"
|
||||||
|
:id="`canvas-${p}`"
|
||||||
|
></canvas>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
class="col-xs-12 col-md-12 col-lg-9 m-auto my-5 text-center"
|
class="col-xs-12 col-md-12 col-lg-9 m-auto my-5 text-center"
|
||||||
:class="{ onAddZone: canvasEvent === 'add' }"
|
:class="{ onAddZone: canvasEvent === 'add' }"
|
||||||
>
|
>
|
||||||
<canvas class="m-auto" id="canvas"></canvas>
|
<canvas class="m-auto" id="canvas"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-xs-12 col-md-12 col-lg-9 m-auto p-4" id="action-buttons">
|
<div class="col-xs-12 col-md-12 col-lg-9 m-auto p-4" id="action-buttons">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col d-flex">
|
<div class="col d-flex">
|
||||||
@ -298,6 +339,7 @@ import {download_and_decrypt_doc, download_doc_as_pdf} from "../StoredObjectButt
|
|||||||
|
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc = "pdfjs-dist/build/pdf.worker.mjs";
|
pdfjsLib.GlobalWorkerOptions.workerSrc = "pdfjs-dist/build/pdf.worker.mjs";
|
||||||
|
|
||||||
|
const multiPage: Ref<boolean> = ref(true);
|
||||||
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 adding: Ref<boolean> = ref(false);
|
const adding: Ref<boolean> = ref(false);
|
||||||
@ -363,24 +405,34 @@ declare global {
|
|||||||
const $toast = useToast();
|
const $toast = useToast();
|
||||||
|
|
||||||
const signature = window.signature;
|
const signature = window.signature;
|
||||||
|
console.log("signature", signature);
|
||||||
|
|
||||||
const setZoomLevel = (zoomLevel: string) => {
|
const setZoomLevel = (zoomLevel: string) => {
|
||||||
zoom.value = Number.parseFloat(zoomLevel);
|
zoom.value = Number.parseFloat(zoomLevel);
|
||||||
setPage(page.value);
|
setPage(page.value);
|
||||||
setTimeout(() => drawAllZones(page.value), 200);
|
setTimeout(drawAllZones, 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
const mountPdf = async (doc: ArrayBuffer) => {
|
const mountPdf = async (doc: ArrayBuffer) => {
|
||||||
const loadingTask = pdfjsLib.getDocument(doc);
|
const loadingTask = pdfjsLib.getDocument(doc);
|
||||||
pdf = await loadingTask.promise;
|
pdf = await loadingTask.promise;
|
||||||
pageCount.value = pdf.numPages;
|
pageCount.value = pdf.numPages;
|
||||||
await setPage(page.value);
|
if (multiPage.value) {
|
||||||
|
await setAllPages();
|
||||||
|
} else {
|
||||||
|
await setPage(1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getCanvas = (page: number) =>
|
||||||
|
multiPage.value
|
||||||
|
? (document.getElementById(`canvas-${page}`) as HTMLCanvasElement)
|
||||||
|
: (document.querySelectorAll("canvas")[0] as HTMLCanvasElement);
|
||||||
|
|
||||||
const getRenderContext = (pdfPage: PDFPageProxy) => {
|
const getRenderContext = (pdfPage: PDFPageProxy) => {
|
||||||
const scale = 1 * zoom.value;
|
const scale = 1 * zoom.value;
|
||||||
const viewport = pdfPage.getViewport({ scale });
|
const viewport = pdfPage.getViewport({ scale });
|
||||||
const canvas = document.querySelectorAll("canvas")[0] as HTMLCanvasElement;
|
const canvas = getCanvas(pdfPage.pageNumber);
|
||||||
const context = canvas.getContext("2d") as CanvasRenderingContext2D;
|
const context = canvas.getContext("2d") as CanvasRenderingContext2D;
|
||||||
canvas.height = viewport.height;
|
canvas.height = viewport.height;
|
||||||
canvas.width = viewport.width;
|
canvas.width = viewport.width;
|
||||||
@ -391,6 +443,9 @@ const getRenderContext = (pdfPage: PDFPageProxy) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setAllPages = async () =>
|
||||||
|
Array.from(Array(pageCount.value).keys()).map((p) => setPage(p + 1));
|
||||||
|
|
||||||
const setPage = async (page: number) => {
|
const setPage = async (page: number) => {
|
||||||
const pdfPage = await pdf.getPage(page);
|
const pdfPage = await pdf.getPage(page);
|
||||||
const renderContext = getRenderContext(pdfPage);
|
const renderContext = getRenderContext(pdfPage);
|
||||||
@ -415,9 +470,19 @@ async function downloadAndOpen(): Promise<Blob> {
|
|||||||
const initPdf = () => {
|
const initPdf = () => {
|
||||||
const canvas = document.querySelectorAll("canvas")[0] as HTMLCanvasElement;
|
const canvas = document.querySelectorAll("canvas")[0] as HTMLCanvasElement;
|
||||||
canvas.addEventListener("pointerup", canvasClick, false);
|
canvas.addEventListener("pointerup", canvasClick, false);
|
||||||
setTimeout(() => drawAllZones(page.value), 800);
|
setTimeout(drawAllZones, 800);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function toggleMultiPage() {
|
||||||
|
if (multiPage.value) {
|
||||||
|
await setAllPages();
|
||||||
|
setTimeout(drawAllZones, 200);
|
||||||
|
} else {
|
||||||
|
await setPage(1);
|
||||||
|
setTimeout(drawAllZones, 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const scaleXToCanvas = (x: number, canvasWidth: number, PDFWidth: number) =>
|
const scaleXToCanvas = (x: number, canvasWidth: number, PDFWidth: number) =>
|
||||||
Math.round((x * canvasWidth) / PDFWidth);
|
Math.round((x * canvasWidth) / PDFWidth);
|
||||||
|
|
||||||
@ -445,7 +510,7 @@ const selectZone = (z: SignatureZone, canvas: HTMLCanvasElement) => {
|
|||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
setPage(page.value);
|
setPage(page.value);
|
||||||
setTimeout(() => drawAllZones(page.value), 200);
|
setTimeout(drawAllZones, 200);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -467,7 +532,7 @@ const selectZoneEvent = (e: PointerEvent, canvas: HTMLCanvasElement) =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
const canvasClick = (e: PointerEvent) => {
|
const canvasClick = (e: PointerEvent) => {
|
||||||
const canvas = document.querySelectorAll("canvas")[0] as HTMLCanvasElement;
|
const canvas = document.querySelectorAll("canvas")[0] as HTMLCanvasElement; //TODO change canvas as a function of multiOption
|
||||||
canvasEvent.value === "select"
|
canvasEvent.value === "select"
|
||||||
? selectZoneEvent(e, canvas)
|
? selectZoneEvent(e, canvas)
|
||||||
: addZoneEvent(e, canvas);
|
: addZoneEvent(e, canvas);
|
||||||
@ -477,7 +542,7 @@ const turnPage = async (upOrDown: number) => {
|
|||||||
//userSignatureZone.value = null; // desactivate the reset of the zone when turning page
|
//userSignatureZone.value = null; // desactivate the reset of the zone when turning page
|
||||||
page.value = page.value + upOrDown;
|
page.value = page.value + upOrDown;
|
||||||
await setPage(page.value);
|
await setPage(page.value);
|
||||||
setTimeout(() => drawAllZones(page.value), 200);
|
setTimeout(drawAllZones, 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
const turnSignature = async (upOrDown: number) => {
|
const turnSignature = async (upOrDown: number) => {
|
||||||
@ -540,13 +605,19 @@ const drawZone = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawAllZones = (page: number) => {
|
const drawAllZones = () => {
|
||||||
const canvas = document.querySelectorAll("canvas")[0];
|
if (signedState.value !== "signed") {
|
||||||
const ctx = canvas.getContext("2d");
|
|
||||||
if (ctx && signedState.value !== "signed") {
|
|
||||||
signature.zones
|
signature.zones
|
||||||
.filter((z) => z.PDFPage.index + 1 === page)
|
.filter(
|
||||||
|
(z) =>
|
||||||
|
multiPage.value ||
|
||||||
|
(z.PDFPage.index + 1 === page.value && !multiPage.value)
|
||||||
|
)
|
||||||
.map((z) => {
|
.map((z) => {
|
||||||
|
console.log('drawAllZones: z is ', z)
|
||||||
|
const canvas = getCanvas(z.PDFPage.index + 1);
|
||||||
|
const ctx = canvas.getContext("2d");
|
||||||
|
if (ctx) {
|
||||||
if (userSignatureZone.value) {
|
if (userSignatureZone.value) {
|
||||||
if (userSignatureZone.value?.index === z.index) {
|
if (userSignatureZone.value?.index === z.index) {
|
||||||
drawZone(z, ctx, canvas.width, canvas.height);
|
drawZone(z, ctx, canvas.width, canvas.height);
|
||||||
@ -554,6 +625,7 @@ const drawAllZones = (page: number) => {
|
|||||||
} else {
|
} else {
|
||||||
drawZone(z, ctx, canvas.width, canvas.height);
|
drawZone(z, ctx, canvas.width, canvas.height);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -639,7 +711,7 @@ const confirmSign = () => {
|
|||||||
const undoSign = async () => {
|
const undoSign = async () => {
|
||||||
signature.zones = signature.zones.filter((z) => z.index !== null);
|
signature.zones = signature.zones.filter((z) => z.index !== null);
|
||||||
await setPage(page.value);
|
await setPage(page.value);
|
||||||
setTimeout(() => drawAllZones(page.value), 200);
|
setTimeout(drawAllZones, 200);
|
||||||
userSignatureZone.value = null;
|
userSignatureZone.value = null;
|
||||||
adding.value = false;
|
adding.value = false;
|
||||||
canvasEvent.value = "select";
|
canvasEvent.value = "select";
|
||||||
@ -680,7 +752,7 @@ const addZoneEvent = async (e: PointerEvent, canvas: HTMLCanvasElement) => {
|
|||||||
userSignatureZone.value = newZone;
|
userSignatureZone.value = newZone;
|
||||||
|
|
||||||
await setPage(page.value);
|
await setPage(page.value);
|
||||||
setTimeout(() => drawAllZones(page.value), 200);
|
setTimeout(drawAllZones, 200);
|
||||||
canvasEvent.value = "select";
|
canvasEvent.value = "select";
|
||||||
adding.value = true;
|
adding.value = true;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user