mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
DX change function names to camelCase format in vue app signature
This commit is contained in:
parent
67395f52b5
commit
111305d09c
@ -20,7 +20,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<template v-slot:footer>
|
||||
<button class="btn btn-action" @click.prevent="confirm_sign">
|
||||
<button class="btn btn-action" @click.prevent="confirmSign">
|
||||
{{ $t("yes") }}
|
||||
</button>
|
||||
</template>
|
||||
@ -35,13 +35,13 @@
|
||||
<button
|
||||
:disabled="zone < 1"
|
||||
class="btn btn-light btn-sm"
|
||||
@click="turn_signature(-1)"
|
||||
@click="turnSignature(-1)"
|
||||
>
|
||||
{{ $t("last_sign_zone") }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-4 gap-2 d-grid">
|
||||
<button class="btn btn-light btn-sm" @click="turn_signature(1)">
|
||||
<button class="btn btn-light btn-sm" @click="turnSignature(1)">
|
||||
{{ $t("next_sign_zone") }}
|
||||
</button>
|
||||
</div>
|
||||
@ -56,7 +56,7 @@
|
||||
<button
|
||||
class="btn btn-light btn-sm"
|
||||
:disabled="page <= 1"
|
||||
@click="turn_page(-1)"
|
||||
@click="turnPage(-1)"
|
||||
>
|
||||
❮
|
||||
</button>
|
||||
@ -64,7 +64,7 @@
|
||||
<button
|
||||
class="btn btn-light btn-sm"
|
||||
:disabled="page >= pageCount"
|
||||
@click="turn_page(1)"
|
||||
@click="turnPage(1)"
|
||||
>
|
||||
❯
|
||||
</button>
|
||||
@ -88,7 +88,7 @@
|
||||
<button
|
||||
class="btn btn-misc"
|
||||
:hidden="!userSignatureZones"
|
||||
@click="undo_sign"
|
||||
@click="undoSign"
|
||||
v-if="signature.zones.length > 1"
|
||||
>
|
||||
{{ $t("choose_another_signature") }}
|
||||
@ -96,14 +96,14 @@
|
||||
<button
|
||||
class="btn btn-misc"
|
||||
:hidden="!userSignatureZones"
|
||||
@click="undo_sign"
|
||||
@click="undoSign"
|
||||
v-else
|
||||
>
|
||||
{{ $t("cancel") }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<button class="btn float-end btn-delete" @click="undo_sign">
|
||||
<button class="btn float-end btn-delete" @click="undoSign">
|
||||
{{ $t("cancel_signing") }}
|
||||
</button>
|
||||
</div>
|
||||
@ -155,14 +155,14 @@ declare global {
|
||||
const signature = window.signature;
|
||||
const urlInfo = build_download_info_link(signature.storedObject.filename);
|
||||
|
||||
const mount_pdf = async (url: string) => {
|
||||
const mountPdf = async (url: string) => {
|
||||
const loadingTask = pdfjsLib.getDocument(url);
|
||||
pdf = await loadingTask.promise;
|
||||
pageCount.value = pdf.numPages;
|
||||
await set_page(1);
|
||||
await setPage(1);
|
||||
};
|
||||
|
||||
const get_render_context = (pdfPage: PDFPageProxy) => {
|
||||
const getRenderContext = (pdfPage: PDFPageProxy) => {
|
||||
const scale = 1;
|
||||
const viewport = pdfPage.getViewport({ scale });
|
||||
const canvas = document.querySelectorAll("canvas")[0] as HTMLCanvasElement;
|
||||
@ -176,13 +176,13 @@ const get_render_context = (pdfPage: PDFPageProxy) => {
|
||||
};
|
||||
};
|
||||
|
||||
const set_page = async (page: number) => {
|
||||
const setPage = async (page: number) => {
|
||||
const pdfPage = await pdf.getPage(page);
|
||||
const renderContext = get_render_context(pdfPage);
|
||||
const renderContext = getRenderContext(pdfPage);
|
||||
await pdfPage.render(renderContext);
|
||||
};
|
||||
|
||||
async function download_and_open(): Promise<Blob> {
|
||||
async function downloadAndOpen(): Promise<Blob> {
|
||||
let raw;
|
||||
try {
|
||||
raw = await download_and_decrypt_doc(
|
||||
@ -194,22 +194,22 @@ async function download_and_open(): Promise<Blob> {
|
||||
console.error("error while downloading and decrypting document", e);
|
||||
throw e;
|
||||
}
|
||||
await mount_pdf(URL.createObjectURL(raw));
|
||||
init_pdf();
|
||||
await mountPdf(URL.createObjectURL(raw));
|
||||
initPdf();
|
||||
return raw;
|
||||
}
|
||||
|
||||
const init_pdf = () => {
|
||||
const initPdf = () => {
|
||||
const canvas = document.querySelectorAll("canvas")[0] as HTMLCanvasElement;
|
||||
canvas.addEventListener(
|
||||
"pointerup",
|
||||
(e: PointerEvent) => canvas_click(e, canvas),
|
||||
(e: PointerEvent) => canvasClick(e, canvas),
|
||||
false
|
||||
);
|
||||
setTimeout(() => add_zones(page.value), 800);
|
||||
setTimeout(() => addZones(page.value), 800);
|
||||
};
|
||||
|
||||
const hit_signature = (
|
||||
const hitSignature = (
|
||||
zone: SignatureZone,
|
||||
xy: number[],
|
||||
canvasWidth: number,
|
||||
@ -229,30 +229,30 @@ const hit_signature = (
|
||||
);
|
||||
};
|
||||
|
||||
const canvas_click = (e: PointerEvent, canvas: HTMLCanvasElement) =>
|
||||
const canvasClick = (e: PointerEvent, canvas: HTMLCanvasElement) =>
|
||||
signature.zones
|
||||
.filter((z) => z.PDFPage.index + 1 === page.value)
|
||||
.map((z) => {
|
||||
if (
|
||||
hit_signature(z, [e.offsetX, e.offsetY], canvas.width, canvas.height)
|
||||
hitSignature(z, [e.offsetX, e.offsetY], canvas.width, canvas.height)
|
||||
) {
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (ctx) {
|
||||
set_page(page.value);
|
||||
setTimeout(() => draw_zone(z, ctx, canvas.width, canvas.height), 200);
|
||||
setPage(page.value);
|
||||
setTimeout(() => drawZone(z, ctx, canvas.width, canvas.height), 200);
|
||||
}
|
||||
userSignatureZones.value = z;
|
||||
}
|
||||
});
|
||||
|
||||
const turn_page = async (upOrDown: number) => {
|
||||
const turnPage = async (upOrDown: number) => {
|
||||
userSignatureZones.value = null;
|
||||
page.value = page.value + upOrDown;
|
||||
await set_page(page.value);
|
||||
setTimeout(() => add_zones(page.value), 200);
|
||||
await setPage(page.value);
|
||||
setTimeout(() => addZones(page.value), 200);
|
||||
};
|
||||
|
||||
const turn_signature = async (upOrDown: number) => {
|
||||
const turnSignature = async (upOrDown: number) => {
|
||||
userSignatureZones.value = null;
|
||||
if (zone.value < signature.zones.length - 1) {
|
||||
zone.value = zone.value + upOrDown;
|
||||
@ -262,12 +262,12 @@ const turn_signature = async (upOrDown: number) => {
|
||||
let currentZone = signature.zones[zone.value];
|
||||
if (currentZone) {
|
||||
page.value = currentZone.PDFPage.index + 1;
|
||||
await set_page(page.value);
|
||||
setTimeout(() => add_zones(page.value), 200);
|
||||
await setPage(page.value);
|
||||
setTimeout(() => addZones(page.value), 200);
|
||||
}
|
||||
};
|
||||
|
||||
const draw_zone = (
|
||||
const drawZone = (
|
||||
zone: SignatureZone,
|
||||
ctx: CanvasRenderingContext2D,
|
||||
canvasWidth: number,
|
||||
@ -309,23 +309,23 @@ const draw_zone = (
|
||||
}
|
||||
};
|
||||
|
||||
const add_zones = (page: number) => {
|
||||
const addZones = (page: number) => {
|
||||
const canvas = document.querySelectorAll("canvas")[0];
|
||||
const ctx = canvas.getContext("2d");
|
||||
if (ctx) {
|
||||
signature.zones
|
||||
.filter((z) => z.PDFPage.index + 1 === page)
|
||||
.map((z) => draw_zone(z, ctx, canvas.width, canvas.height));
|
||||
.map((z) => drawZone(z, ctx, canvas.width, canvas.height));
|
||||
}
|
||||
};
|
||||
|
||||
const check_signature = () => {
|
||||
const checkSignature = () => {
|
||||
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();
|
||||
checkForReady();
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
@ -338,40 +338,40 @@ const check_signature = () => {
|
||||
const maxTryForReady = 60; //2 minutes for trying to sign
|
||||
let tryForReady = 0;
|
||||
|
||||
const stop_try_signing = () => {
|
||||
const stopTrySigning = () => {
|
||||
loading.value = false;
|
||||
modalOpen.value = false;
|
||||
};
|
||||
|
||||
const check_for_ready = () => {
|
||||
const checkForReady = () => {
|
||||
if (tryForReady > maxTryForReady) {
|
||||
signedState.value = "error";
|
||||
stop_try_signing();
|
||||
stopTrySigning();
|
||||
console.log("Reached the maximum number of tentative to try signing");
|
||||
//TODO toast error
|
||||
}
|
||||
if (signedState.value === "rejected") {
|
||||
stop_try_signing();
|
||||
stopTrySigning();
|
||||
console.log("Signature rejected by the server");
|
||||
//TODO toast error
|
||||
}
|
||||
if (signedState.value === "canceled") {
|
||||
stop_try_signing();
|
||||
stopTrySigning();
|
||||
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);
|
||||
setTimeout(() => checkSignature(), 2000);
|
||||
} else {
|
||||
stop_try_signing();
|
||||
stopTrySigning();
|
||||
if (signedState.value === "signed") {
|
||||
//TODO recharger le document signé
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const confirm_sign = () => {
|
||||
const confirmSign = () => {
|
||||
loading.value = true;
|
||||
const url = `/api/1.0/document/workflow/${signature.id}/signature-request`;
|
||||
const body = {
|
||||
@ -380,27 +380,27 @@ const confirm_sign = () => {
|
||||
};
|
||||
makeFetch("POST", url, body)
|
||||
.then((r) => {
|
||||
check_for_ready();
|
||||
checkForReady();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('Error while posting the signature', error);
|
||||
stop_try_signing();
|
||||
stopTrySigning();
|
||||
//TODO toast
|
||||
});
|
||||
};
|
||||
|
||||
const undo_sign = async () => {
|
||||
const undoSign = async () => {
|
||||
// const canvas = document.querySelectorAll("canvas")[0];
|
||||
// const ctx = canvas.getContext("2d");
|
||||
// if (ctx && userSignatureZones.value) {
|
||||
// //draw_zone(userSignatureZones.value, ctx, canvas.width, canvas.height);
|
||||
// //drawZone(userSignatureZones.value, ctx, canvas.width, canvas.height);
|
||||
// }
|
||||
await set_page(page.value);
|
||||
setTimeout(() => add_zones(page.value), 200);
|
||||
await setPage(page.value);
|
||||
setTimeout(() => addZones(page.value), 200);
|
||||
userSignatureZones.value = null;
|
||||
};
|
||||
|
||||
download_and_open();
|
||||
downloadAndOpen();
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
Loading…
x
Reference in New Issue
Block a user