From 111305d09ccc103a1dfe117539b48e591005a4d0 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 19 Jul 2024 10:00:16 +0200 Subject: [PATCH] DX change function names to camelCase format in vue app signature --- .../public/vuejs/DocumentSignature/App.vue | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue index 268e75636..6773b5590 100644 --- a/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue +++ b/src/Bundle/ChillDocStoreBundle/Resources/public/vuejs/DocumentSignature/App.vue @@ -20,7 +20,7 @@ @@ -35,13 +35,13 @@
-
@@ -56,7 +56,7 @@ @@ -64,7 +64,7 @@ @@ -88,7 +88,7 @@
-
@@ -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 { +async function downloadAndOpen(): Promise { let raw; try { raw = await download_and_decrypt_doc( @@ -194,22 +194,22 @@ async function download_and_open(): Promise { 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();