improve finish handling

This commit is contained in:
Jonathan Jenne 2023-10-11 12:35:30 +02:00
parent 8d5e24c6a7
commit e69dccb2e1
5 changed files with 50 additions and 23 deletions

View File

@ -111,9 +111,6 @@ namespace EnvelopeGenerator.Web.Handler
} }
} }
public async Task<IResult> HandlePostEnvelope(HttpContext ctx, DatabaseService database, LoggingService logging) public async Task<IResult> HandlePostEnvelope(HttpContext ctx, DatabaseService database, LoggingService logging)
{ {
var logger = logging.LogConfig.GetLogger("FileHandler"); var logger = logging.LogConfig.GetLogger("FileHandler");

View File

@ -0,0 +1,5 @@
@page "/EnvelopeKey/Finish"
<h3>Dokumente signiert</h3>
<p>Sie haben den Umschlag erfolgreich signiert!</p>

View File

@ -50,7 +50,7 @@ export class App {
// Load PSPDFKit // Load PSPDFKit
console.debug("Loading PSPDFKit..") console.debug("Loading PSPDFKit..")
App.Instance = await App.UI.loadPSPDFKit(arrayBuffer, container) App.Instance = await App.UI.loadPSPDFKit(arrayBuffer, container)
App.UI.configurePSPDFKit(this.Instance, App.handleClick) App.UI.configurePSPDFKit(this.Instance, App.handleClick)
// Load annotations into PSPDFKit // Load annotations into PSPDFKit
console.debug("Loading annotations..") console.debug("Loading annotations..")
@ -71,14 +71,18 @@ export class App {
} }
public static async handleFinish(event: any) { public static async handleFinish(event: any) {
await App.Instance.save(); await App.Instance.save();
// Export annotation data and save to database // Export annotation data and save to database
const json = await App.Instance.exportInstantJSON() const json = await App.Instance.exportInstantJSON()
console.log(json); console.log(json);
console.log(JSON.stringify(json)); console.log(JSON.stringify(json));
const result = await App.Network.postEnvelope(App.envelopeKey, App.currentDocument.id, JSON.stringify(json)) const result: boolean = await App.Network.postEnvelope(App.envelopeKey, App.currentDocument.id, JSON.stringify(json))
if (result == true) {
alert("Dokument erfolgreich signiert!")
}
// Flatten the annotations and save the document to disk // Flatten the annotations and save the document to disk
/* /*
@ -91,7 +95,7 @@ export class App {
public static async handleReset(event: any) { public static async handleReset(event: any) {
if (confirm("Wollen Sie das Dokument und alle erstellten Signaturen zurücksetzen?")) { if (confirm("Wollen Sie das Dokument und alle erstellten Signaturen zurücksetzen?")) {
const result = App.Annotation.deleteAnnotations(App.Instance) const result = App.Annotation.deleteAnnotations(App.Instance)
} }
} }
private static async downloadDocument() { private static async downloadDocument() {
@ -202,7 +206,7 @@ class Network {
.then(res => res.json()); .then(res => res.json());
} }
public postEnvelope(envelopeKey: string, documentId: number, jsonString: string): Promise<any> { public postEnvelope(envelopeKey: string, documentId: number, jsonString: string): Promise<boolean> {
const options: RequestInit = { const options: RequestInit = {
credentials: "include", credentials: "include",
method: "POST", method: "POST",
@ -210,11 +214,23 @@ class Network {
} }
return fetch(`/api/envelope/${envelopeKey}?index=${documentId}`, options) return fetch(`/api/envelope/${envelopeKey}?index=${documentId}`, options)
.then(res => { .then(this.handleResponse)
console.log(res) .then((res: Response) => {
res.json() if (!res.ok) {
return false;
};
return true;
}); });
} }
private handleResponse(res: Response) {
if (!res.ok) {
console.log(`Request failed with status ${res.status}`)
return res
} else {
return res
}
}
} }
@ -230,7 +246,7 @@ class UI {
"zoom-mode", "zoom-mode",
"spacer", "spacer",
"search" "search"
] ]
// Load the PSPDFKit UI by setting a target element as the container to render in // Load the PSPDFKit UI by setting a target element as the container to render in
// and a arraybuffer which represents the document that should be displayed. // and a arraybuffer which represents the document that should be displayed.

View File

@ -133,16 +133,12 @@ var App = /** @class */ (function () {
json = _a.sent(); json = _a.sent();
console.log(json); console.log(json);
console.log(JSON.stringify(json)); console.log(JSON.stringify(json));
return [4 /*yield*/, App.Network.postEnvelope(App.envelopeKey, App.currentDocument.id, JSON.stringify(json)) return [4 /*yield*/, App.Network.postEnvelope(App.envelopeKey, App.currentDocument.id, JSON.stringify(json))];
// Flatten the annotations and save the document to disk
/*
const buffer = await App.Instance.exportPDF({ flatten: true });
const result = await App.Network.postDocument(App.envelopeKey, App.currentDocument.id, buffer);
console.log(result)
*/
];
case 3: case 3:
result = _a.sent(); result = _a.sent();
if (result == true) {
alert("Dokument erfolgreich signiert!");
}
return [2 /*return*/]; return [2 /*return*/];
} }
}); });
@ -286,11 +282,24 @@ var Network = /** @class */ (function () {
body: jsonString body: jsonString
}; };
return fetch("/api/envelope/".concat(envelopeKey, "?index=").concat(documentId), options) return fetch("/api/envelope/".concat(envelopeKey, "?index=").concat(documentId), options)
.then(this.handleResponse)
.then(function (res) { .then(function (res) {
console.log(res); if (!res.ok) {
res.json(); return false;
}
;
return true;
}); });
}; };
Network.prototype.handleResponse = function (res) {
if (!res.ok) {
console.log("Request failed with status ".concat(res.status));
return res;
}
else {
return res;
}
};
return Network; return Network;
}()); }());
var UI = /** @class */ (function () { var UI = /** @class */ (function () {

File diff suppressed because one or more lines are too long