move getAnnotationParams to api-service

- remove network.js
This commit is contained in:
tekh 2025-09-19 13:50:19 +02:00
parent 62411b4d2b
commit 7a1c669fb0
5 changed files with 17 additions and 34 deletions

View File

@ -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": [

View File

@ -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);
}

View File

@ -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`});
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`});

View File

@ -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;
}

View File

@ -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}