Add history inserts, add controllers

This commit is contained in:
Jonathan Jenne
2023-11-02 16:30:57 +01:00
parent 3f4f4681b5
commit 47d02aefee
14 changed files with 428 additions and 135 deletions

View File

@@ -1,4 +1,4 @@
import PSPDFKitType, { AnnotationsUnion, SignatureFormField as SignatureFormFieldType } from "./index";
import PSPDFKitType, { Action, AnnotationsUnion, SignatureFormField as SignatureFormFieldType } from "./index";
import { Instance, WidgetAnnotation, ToolbarItem } from "./index";
import { EnvelopeResponse, Envelope, User, Element, Document, IFunction } from "./interfaces";
@@ -10,6 +10,17 @@ const { SignatureFormField } = PSPDFKit.FormFields;
const { DRAW, TYPE } = PSPDFKit.ElectronicSignatureCreationMode;
const { DISABLED } = PSPDFKit.AutoSaveMode;
enum ActionType {
Created = 0,
Saved = 1,
Sent = 2,
EmailSent = 3,
Delivered = 4,
Seen = 5,
Signed = 6,
Rejected = 7,
}
export class App {
public static Instance: Instance;
public static currentDocument: Document;
@@ -56,6 +67,9 @@ export class App {
console.debug("Loading annotations..")
const annotations = App.Annotation.createAnnotations(App.currentDocument)
const createdAnnotations = await App.Instance.create(annotations)
const description = "Umschlag wurde ge<67>ffnet"
await App.Network.postHistory(App.envelopeKey, ActionType.Seen, description);
}
public static async handleClick(eventType: string) {
@@ -125,6 +139,14 @@ export class App {
return false;
}
try {
const description = "Dokument wurde signiert"
await App.Network.postHistory(App.envelopeKey, ActionType.Signed, description);
} catch (e) {
console.error(e);
return false;
}
return true;
}
@@ -242,7 +264,7 @@ class Network {
}
public postDocument(envelopeKey: string, documentId: number, buffer: ArrayBuffer): Promise<any> {
const url = `/api/document/${envelopeKey}/${documentId}`;
const url = `/api/document/${envelopeKey}?index=${documentId}`;
const options: RequestInit = {
credentials: "include",
method: "POST",
@@ -279,6 +301,34 @@ class Network {
});
}
public postHistory(envelopeKey: string, actionType: ActionType, actionDescription: string): Promise<boolean> {
const url = `/api/history/${envelopeKey}`;
const data = {
actionDescription: actionDescription,
actionType: actionType.toString()
}
const options: RequestInit = {
credentials: "include",
method: "POST",
headers: {
'Content-Type': "application/json; charset=utf-8"
},
body: JSON.stringify(data)
}
console.debug("PostHistory/Calling url: " + url)
return fetch(url, options)
.then(this.handleResponse)
.then((res: Response) => {
if (!res.ok) {
return false;
};
return true;
});
}
private handleResponse(res: Response) {
if (!res.ok) {
console.log(`Request failed with status ${res.status}`)