From 7a1c669fb0e134753b3788f29606cf48d3deb692 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 19 Sep 2025 13:50:19 +0200 Subject: [PATCH] move getAnnotationParams to api-service - remove network.js --- EnvelopeGenerator.Web/bundleconfig.json | 6 ----- .../wwwroot/js/api-service.js | 16 ++++++++++++ .../wwwroot/js/api-service.min.js | 2 +- EnvelopeGenerator.Web/wwwroot/js/network.js | 26 ------------------- .../wwwroot/js/network.min.js | 1 - 5 files changed, 17 insertions(+), 34 deletions(-) delete mode 100644 EnvelopeGenerator.Web/wwwroot/js/network.js delete mode 100644 EnvelopeGenerator.Web/wwwroot/js/network.min.js diff --git a/EnvelopeGenerator.Web/bundleconfig.json b/EnvelopeGenerator.Web/bundleconfig.json index c66c7e1f..9242f40e 100644 --- a/EnvelopeGenerator.Web/bundleconfig.json +++ b/EnvelopeGenerator.Web/bundleconfig.json @@ -29,12 +29,6 @@ "wwwroot/js/event-binder.js" ] }, - { - "outputFileName": "wwwroot/js/network.min.js", - "inputFiles": [ - "wwwroot/js/network.js" - ] - }, { "outputFileName": "wwwroot/js/ui.min.js", "inputFiles": [ diff --git a/EnvelopeGenerator.Web/wwwroot/js/api-service.js b/EnvelopeGenerator.Web/wwwroot/js/api-service.js index 5069df20..20564c93 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/api-service.js +++ b/EnvelopeGenerator.Web/wwwroot/js/api-service.js @@ -47,6 +47,22 @@ function signEnvelope(annotations) { return postRequest(`/api/annotation`, annotations) } +async function getAnnotationParams(leftInInch = 0, topInInch = 0, inchToPointFactor = 72) { + const annotParams = await getRequest("/api/Config/Annotations") + .then(res => res.json()); + + for (var key in annotParams) { + var annot = annotParams[key]; + annot.width *= inchToPointFactor; + annot.height *= inchToPointFactor; + annot.left += leftInInch - 0.7; + annot.left *= inchToPointFactor; + annot.top += topInInch - 0.5; + annot.top *= inchToPointFactor; + } + return annotParams; +} + function rejectEnvelope(reason) { return postRequest(url.reject, reason); } diff --git a/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js b/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js index 7bb0fb35..ba73abde 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js +++ b/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js @@ -1 +1 @@ -function sendRequest(n,t,i=undefined){const r={credentials:"include",method:n,headers:{"X-XSRF-TOKEN":env.xsrfToken}};return i!==undefined&&(r.body=JSON.stringify(i),r.headers["Content-Type"]="application/json"),fetch(t,r)}function getRequest(n){return sendRequest("GET",n)}function postRequest(n,t=undefined){return sendRequest("POST",n,t)}function redirect(n){window.location.href=n}function signEnvelope(n){return postRequest(`/api/annotation`,n)}function rejectEnvelope(n){return postRequest(url.reject,n)}function shareEnvelope(n,t){return postRequest(url.share,{receiverMail:n,dateValid:t})}function redirRejected(){redirect(url.rejectRedir)}async function setLanguage(n){const t=await getRequest("/api/localization/lang").then(n=>n.json()).then(t=>t.includes(n));t&&postRequest(`/api/localization/lang/${n}`).then(n=>{n.redirected&&redirect(n.url)})}function logout(){return postRequest(`/auth/logout`).then(n=>{n.ok&&(window.location.href="/")})}const env=Object.freeze({xsrfToken:document.getElementsByName("__RequestVerificationToken")[0].value,envKey:document.querySelector('meta[name="env-key"]').getAttribute("content")}),url=Object.freeze({reject:`/api/annotation/reject`,rejectRedir:`/envelope/${env.envKey}`,share:`/api/readonly`}); \ No newline at end of file +function sendRequest(n,t,i=undefined){const r={credentials:"include",method:n,headers:{"X-XSRF-TOKEN":env.xsrfToken}};return i!==undefined&&(r.body=JSON.stringify(i),r.headers["Content-Type"]="application/json"),fetch(t,r)}function getRequest(n){return sendRequest("GET",n)}function postRequest(n,t=undefined){return sendRequest("POST",n,t)}function redirect(n){window.location.href=n}function signEnvelope(n){return postRequest(`/api/annotation`,n)}async function getAnnotationParams(n=0,t=0,i=72){var f,r;const u=await getRequest("/api/Config/Annotations").then(n=>n.json());for(f in u)r=u[f],r.width*=i,r.height*=i,r.left+=n-.7,r.left*=i,r.top+=t-.5,r.top*=i;return u}function rejectEnvelope(n){return postRequest(url.reject,n)}function shareEnvelope(n,t){return postRequest(url.share,{receiverMail:n,dateValid:t})}function redirRejected(){redirect(url.rejectRedir)}async function setLanguage(n){const t=await getRequest("/api/localization/lang").then(n=>n.json()).then(t=>t.includes(n));t&&postRequest(`/api/localization/lang/${n}`).then(n=>{n.redirected&&redirect(n.url)})}function logout(){return postRequest(`/auth/logout`).then(n=>{n.ok&&(window.location.href="/")})}const env=Object.freeze({xsrfToken:document.getElementsByName("__RequestVerificationToken")[0].value,envKey:document.querySelector('meta[name="env-key"]').getAttribute("content")}),url=Object.freeze({reject:`/api/annotation/reject`,rejectRedir:`/envelope/${env.envKey}`,share:`/api/readonly`}); \ No newline at end of file diff --git a/EnvelopeGenerator.Web/wwwroot/js/network.js b/EnvelopeGenerator.Web/wwwroot/js/network.js deleted file mode 100644 index 4cca189e..00000000 --- a/EnvelopeGenerator.Web/wwwroot/js/network.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Fetches CSRF Token from page - */ -function getCsrfToken() { - return { 'X-XSRF-TOKEN': document.getElementsByName('__RequestVerificationToken')[0].value } -} - -async function getAnnotationParams(leftInInch = 0, topInInch = 0, inchToPointFactor = 72) { - - const annotParams = await fetch(`${window.location.origin}/api/Config/Annotations`, { - credentials: 'include', - method: 'GET' - }) - .then(res => res.json()); - - for (var key in annotParams) { - var annot = annotParams[key]; - annot.width *= inchToPointFactor; - annot.height *= inchToPointFactor; - annot.left += leftInInch - 0.7; - annot.left *= inchToPointFactor; - annot.top += topInInch - 0.5; - annot.top *= inchToPointFactor; - } - return annotParams; -} \ No newline at end of file diff --git a/EnvelopeGenerator.Web/wwwroot/js/network.min.js b/EnvelopeGenerator.Web/wwwroot/js/network.min.js deleted file mode 100644 index 45b7fc73..00000000 --- a/EnvelopeGenerator.Web/wwwroot/js/network.min.js +++ /dev/null @@ -1 +0,0 @@ -function getCsrfToken(){return{"X-XSRF-TOKEN":document.getElementsByName("__RequestVerificationToken")[0].value}}async function getAnnotationParams(n=0,t=0,i=72){var f,r;const u=await fetch(`${window.location.origin}/api/Config/Annotations`,{credentials:"include",method:"GET"}).then(n=>n.json());for(f in u)r=u[f],r.width*=i,r.height*=i,r.left+=n-.7,r.left*=i,r.top+=t-.5,r.top*=i;return u} \ No newline at end of file