Compare commits
6 Commits
eb024acfa7
...
eef6bf27f1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eef6bf27f1 | ||
|
|
2dfe508552 | ||
|
|
a7b980bd28 | ||
|
|
2d7c0a292b | ||
|
|
91f1296e9b | ||
|
|
80e1e7dcf3 |
@@ -1,4 +1,5 @@
|
|||||||
using EnvelopeGenerator.Web.Models;
|
using AngleSharp.Common;
|
||||||
|
using EnvelopeGenerator.Web.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
@@ -18,6 +19,6 @@ public class ConfigController : ControllerBase
|
|||||||
[HttpGet("Annotations")]
|
[HttpGet("Annotations")]
|
||||||
public IActionResult GetAnnotationParams()
|
public IActionResult GetAnnotationParams()
|
||||||
{
|
{
|
||||||
return Ok(_annotParams);
|
return Ok(_annotParams.Annotations.ToDictionary(a => a.Name.ToLower(), a => a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,65 +15,41 @@ public record Annotation
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Layout
|
#region Layout
|
||||||
internal double _marginLeft = default;
|
|
||||||
|
|
||||||
internal double _marginTop = default;
|
|
||||||
|
|
||||||
internal double _width = default;
|
|
||||||
|
|
||||||
internal double _height = default;
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public double MarginLeft
|
public double? MarginLeft { get; set; }
|
||||||
{
|
|
||||||
get => _marginLeft;
|
|
||||||
init => _marginLeft = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public double MarginLeftRatio { get; init; } = 1;
|
public double MarginLeftRatio { get; init; } = 1;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public double MarginTop
|
public double? MarginTop { get; set; }
|
||||||
{
|
|
||||||
get => _marginTop;
|
|
||||||
init => _marginTop = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public double MarginTopRatio { get; init; } = 1;
|
public double MarginTopRatio { get; init; } = 1;
|
||||||
|
|
||||||
public double Width
|
public double? Width { get; set; }
|
||||||
{
|
|
||||||
get => _width;
|
|
||||||
init => _width = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public double WidthRatio { get; init; } = 1;
|
public double WidthRatio { get; init; } = 1;
|
||||||
|
|
||||||
public double Height
|
public double? Height { get; set; }
|
||||||
{
|
|
||||||
get => _height;
|
|
||||||
init => _height = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public double HeightRatio { get; init; } = 1;
|
public double HeightRatio { get; init; } = 1;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Position
|
#region Position
|
||||||
public double Left => MarginLeft + (HorBoundAnnot?.HorBoundary ?? 0);
|
public double Left => (MarginLeft ?? 0) + (HorBoundAnnot?.HorBoundary ?? 0);
|
||||||
|
|
||||||
public double Top => MarginTop + (VerBoundAnnot?.VerBoundary ?? 0);
|
public double Top => (MarginTop ?? 0) + (VerBoundAnnot?.VerBoundary ?? 0);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Boundary
|
#region Boundary
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public double HorBoundary => Left + Width;
|
public double HorBoundary => Left + (Width ?? 0);
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public double VerBoundary => Top + Height;
|
public double VerBoundary => Top + (Height ?? 0);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region BoundAnnot
|
#region BoundAnnot
|
||||||
@@ -89,18 +65,18 @@ public record Annotation
|
|||||||
{
|
{
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// To set default value, annotation must have default (0) value but default must has non-default value
|
// To set null value, annotation must have null (0) value but null must has non-null value
|
||||||
if (_marginLeft == default && value.MarginLeft != default)
|
if (MarginLeft == null && value.MarginLeft != null)
|
||||||
_marginLeft = value.MarginLeft * MarginLeftRatio;
|
MarginLeft = value.MarginLeft * MarginLeftRatio;
|
||||||
|
|
||||||
if (_marginTop == default && value.MarginTop != default)
|
if (MarginTop == null && value.MarginTop != null)
|
||||||
_marginTop = value.MarginTop * MarginTopRatio;
|
MarginTop = value.MarginTop * MarginTopRatio;
|
||||||
|
|
||||||
if (_width == default && value.Width != default)
|
if (Width == null && value.Width != null)
|
||||||
_width = value.Width * WidthRatio;
|
Width = value.Width * WidthRatio;
|
||||||
|
|
||||||
if (_height == default && value.Height != default)
|
if (Height == null && value.Height != null)
|
||||||
_height = value.Height * HeightRatio;
|
Height = value.Height * HeightRatio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -153,19 +153,27 @@
|
|||||||
"AnnotationParams": {
|
"AnnotationParams": {
|
||||||
"DefaultAnnotation": {
|
"DefaultAnnotation": {
|
||||||
"Width": 1,
|
"Width": 1,
|
||||||
"Height": 0.5
|
"Height": 0.5,
|
||||||
|
"MarginTop": 1
|
||||||
},
|
},
|
||||||
"Annotations": [
|
"Annotations": [
|
||||||
{
|
{
|
||||||
"Name": "Signature"
|
"Name": "Signature",
|
||||||
|
"MarginTop": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name": "City",
|
"Name": "City",
|
||||||
"VerBoundAnnotName": "Signature"
|
"VerBoundAnnotName": "Signature",
|
||||||
|
"WidthRatio": 1.2,
|
||||||
|
"HeightRatio": 0.5,
|
||||||
|
"MarginTopRatio": 0.48
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name": "Date",
|
"Name": "Date",
|
||||||
"VerBoundAnnotName": "City"
|
"VerBoundAnnotName": "City",
|
||||||
|
"WidthRatio": 1.55,
|
||||||
|
"HeightRatio": 0.5,
|
||||||
|
"MarginTopRatio": 0.45
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
* Creates a GET HTTP request to `url`
|
* Creates a GET HTTP request to `url`
|
||||||
* @param {any} url
|
* @param {any} url
|
||||||
*/
|
*/
|
||||||
getRequest(url, body) {
|
getRequest(url) {
|
||||||
const token = this.getCSRFToken()
|
const token = this.getCSRFToken()
|
||||||
const options = {
|
const options = {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
@@ -79,10 +79,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body !== undefined) {
|
|
||||||
options.body = JSON.stringify(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fetch(url, options)
|
return fetch(url, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,3 +203,11 @@ async function logout() {
|
|||||||
window.location.href = "/";
|
window.location.href = "/";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAnnotationParams() {
|
||||||
|
return fetch(`${window.location.origin}/api/Config/Annotations`, {
|
||||||
|
credentials: 'include',
|
||||||
|
method: 'GET'
|
||||||
|
})
|
||||||
|
.then(res => res.json());
|
||||||
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
async function setLangAsync(n,t){document.getElementById("selectedFlag").className="fi "+t+" me-2";await fetch(`/lang/${n}`,{method:"POST",headers:{"Content-Type":"application/json"}})}async function setLanguage(n){const t=await fetch("/lang",{method:"GET",headers:{"Content-Type":"application/json"}}).then(n=>n.json()).then(t=>t.includes(n)).catch(()=>!1);if(t)return await fetch(`/lang/${n}`,{method:"POST",headers:{"Content-Type":"application/json"}}).then(n=>{if(n.redirected)window.location.href=n.url;else if(!n.ok)return Promise.reject("Failed to set language")})}async function logout(){return await fetch(`/auth/logout`,{method:"POST",headers:{"Content-Type":"application/json"}}).then(n=>{n.ok&&(window.location.href="/")})}class Network{async getEnvelope(n){return this.getRequest(`/api/envelope/${n}`).then(this.wrapJsonResponse.bind(this))}async postEnvelope(n,t,i){return this.postRequest(`/api/envelope/${n}?index=${t}`,i).then(this.wrapJsonResponse.bind(this))}async getDocument(n,t){return this.getRequest(`/api/document/${n}?index=${t}`).then(this.wrapBinaryResponse.bind(this))}async openDocument(n){return this.postRequest(`/api/document/${n}`,{}).then(this.wrapJsonResponse.bind(this))}withCSRFToken(n){const t=getCSRFToken;let i=n.headers;return n.headers={...i,...t},n}getCSRFToken(){const n=document.getElementsByName("__RequestVerificationToken")[0].value;return{"X-XSRF-TOKEN":n}}getRequest(n,t){const r=this.getCSRFToken(),i={credentials:"include",method:"GET",headers:{...r}};return t!==undefined&&(i.body=JSON.stringify(t)),fetch(n,i)}postRequest(n,t){const i=this.getCSRFToken(),r={credentials:"include",method:"POST",headers:{...i,"Content-Type":"application/json; charset=utf-8"},body:JSON.stringify(t)};return fetch(n,r)}async wrapJsonResponse(n){return await this.wrapResponse(n,async n=>await n.json())}async wrapBinaryResponse(n){return await this.wrapResponse(n,async n=>await n.arrayBuffer())}async wrapResponse(n,t){let i;if(n.status===200){const r=await t(n);i=new WrappedResponse(r,null)}else if(n.status===403){const t=await n.json();i=new WrappedResponse(null,t)}else i=new WrappedResponse(null,null);return i}}class WrappedResponse{constructor(n,t){this.data=n;this.error=t;this.fatal=n===null&&t===null}}
|
async function setLangAsync(n,t){document.getElementById("selectedFlag").className="fi "+t+" me-2";await fetch(`/lang/${n}`,{method:"POST",headers:{"Content-Type":"application/json"}})}async function setLanguage(n){const t=await fetch("/lang",{method:"GET",headers:{"Content-Type":"application/json"}}).then(n=>n.json()).then(t=>t.includes(n)).catch(()=>!1);if(t)return await fetch(`/lang/${n}`,{method:"POST",headers:{"Content-Type":"application/json"}}).then(n=>{if(n.redirected)window.location.href=n.url;else if(!n.ok)return Promise.reject("Failed to set language")})}async function logout(){return await fetch(`/auth/logout`,{method:"POST",headers:{"Content-Type":"application/json"}}).then(n=>{n.ok&&(window.location.href="/")})}function getAnnotationParams(){return fetch(`${window.location.origin}/api/Config/Annotations`,{credentials:"include",method:"GET"}).then(n=>n.json())}class Network{async getEnvelope(n){return this.getRequest(`/api/envelope/${n}`).then(this.wrapJsonResponse.bind(this))}async postEnvelope(n,t,i){return this.postRequest(`/api/envelope/${n}?index=${t}`,i).then(this.wrapJsonResponse.bind(this))}async getDocument(n,t){return this.getRequest(`/api/document/${n}?index=${t}`).then(this.wrapBinaryResponse.bind(this))}async openDocument(n){return this.postRequest(`/api/document/${n}`,{}).then(this.wrapJsonResponse.bind(this))}withCSRFToken(n){const t=getCSRFToken;let i=n.headers;return n.headers={...i,...t},n}getCSRFToken(){const n=document.getElementsByName("__RequestVerificationToken")[0].value;return{"X-XSRF-TOKEN":n}}getRequest(n){const t=this.getCSRFToken(),i={credentials:"include",method:"GET",headers:{...t}};return fetch(n,i)}postRequest(n,t){const i=this.getCSRFToken(),r={credentials:"include",method:"POST",headers:{...i,"Content-Type":"application/json; charset=utf-8"},body:JSON.stringify(t)};return fetch(n,r)}async wrapJsonResponse(n){return await this.wrapResponse(n,async n=>await n.json())}async wrapBinaryResponse(n){return await this.wrapResponse(n,async n=>await n.arrayBuffer())}async wrapResponse(n,t){let i;if(n.status===200){const r=await t(n);i=new WrappedResponse(r,null)}else if(n.status===403){const t=await n.json();i=new WrappedResponse(null,t)}else i=new WrappedResponse(null,null);return i}}class WrappedResponse{constructor(n,t){this.data=n;this.error=t;this.fatal=n===null&&t===null}}
|
||||||
Reference in New Issue
Block a user