Refaktorisierte 'Annotation'-Funktionen zu statischen Methoden.

This commit is contained in:
Developer 02 2024-06-18 18:58:56 +02:00
parent c4a66ee5bb
commit 39cc257466
2 changed files with 15 additions and 16 deletions

View File

@ -1,5 +1,5 @@
class Annotation { class Annotation {
createAnnotations(document) { static createAnnotations(document) {
const annotations = [] const annotations = []
document.elements.forEach((element) => { document.elements.forEach((element) => {
@ -11,7 +11,7 @@
return annotations return annotations
} }
async getAnnotations(instance) { static async getAnnotations(instance) {
const array = await Promise.all( const array = await Promise.all(
Array.from({ length: instance.totalPageCount }).map((_, pageIndex) => Array.from({ length: instance.totalPageCount }).map((_, pageIndex) =>
instance.getAnnotations(pageIndex) instance.getAnnotations(pageIndex)
@ -23,14 +23,14 @@
) )
} }
async deleteAnnotations(instance) { static async deleteAnnotations(instance) {
const allAnnotations = await this.getAnnotations(instance) const allAnnotations = await this.getAnnotations(instance)
const pageAnnotations = allAnnotations.filter(this.isSignature) const pageAnnotations = allAnnotations.filter(this.isSignature)
//deleting all Annotations //deleting all Annotations
return await instance.delete(pageAnnotations) return await instance.delete(pageAnnotations)
} }
async validateAnnotations(instance) { static async validateAnnotations(instance) {
const allAnnotations = await this.getAnnotations(instance) const allAnnotations = await this.getAnnotations(instance)
const pageAnnotations = allAnnotations const pageAnnotations = allAnnotations
.map((annotation) => { .map((annotation) => {
@ -40,11 +40,11 @@
return true return true
} }
isSignature(annotation) { static isSignature(annotation) {
return !!annotation.isSignature || annotation.description == 'FRAME' return !!annotation.isSignature || annotation.description == 'FRAME'
} }
createAnnotationFromElement(element) { static createAnnotationFromElement(element) {
const id = PSPDFKit.generateInstantId() const id = PSPDFKit.generateInstantId()
const width = this.inchToPoint(element.width) const width = this.inchToPoint(element.width)
const height = this.inchToPoint(element.height) const height = this.inchToPoint(element.height)
@ -68,7 +68,7 @@
return [annotation, formField] return [annotation, formField]
} }
createSignatureAnnotation(id, width, height, top, left, pageIndex) { static createSignatureAnnotation(id, width, height, top, left, pageIndex) {
const annotation = new PSPDFKit.Annotations.WidgetAnnotation({ const annotation = new PSPDFKit.Annotations.WidgetAnnotation({
id: id, id: id,
pageIndex: pageIndex, pageIndex: pageIndex,
@ -86,7 +86,7 @@
return annotation return annotation
} }
createImageAnnotation(boundingBox, pageIndex, imageAttachmentId) { static createImageAnnotation(boundingBox, pageIndex, imageAttachmentId) {
const frameAnnotation = new PSPDFKit.Annotations.ImageAnnotation({ const frameAnnotation = new PSPDFKit.Annotations.ImageAnnotation({
pageIndex: pageIndex, pageIndex: pageIndex,
isSignature: false, isSignature: false,
@ -101,7 +101,7 @@
return frameAnnotation return frameAnnotation
} }
async createAnnotationFrameBlob(receiverName, receiverSignature, timestamp, width, height) { static async createAnnotationFrameBlob(receiverName, receiverSignature, timestamp, width, height) {
const canvas = document.createElement('canvas') const canvas = document.createElement('canvas')
const scale = 4 const scale = 4
const fontSize = 10 const fontSize = 10
@ -154,7 +154,7 @@
}) })
} }
inchToPoint(inch) { static inchToPoint(inch) {
return inch * 72 return inch * 72
} }
} }

View File

@ -16,7 +16,6 @@ class App {
this.UI = new UI() this.UI = new UI()
this.Network = new Network() this.Network = new Network()
this.Annotation = new Annotation()
this.Instance = null this.Instance = null
this.currentDocument = null this.currentDocument = null
@ -72,7 +71,7 @@ class App {
// Load annotations into PSPDFKit // Load annotations into PSPDFKit
try { try {
this.signatureCount = this.currentDocument.elements.length this.signatureCount = this.currentDocument.elements.length
const annotations = this.Annotation.createAnnotations( const annotations = Annotation.createAnnotations(
this.currentDocument this.currentDocument
) )
await this.Instance.create(annotations) await this.Instance.create(annotations)
@ -113,7 +112,7 @@ class App {
const height = 75 const height = 75
const timestamp = new Date() const timestamp = new Date()
const imageUrl = await this.Annotation.createAnnotationFrameBlob( const imageUrl = await Annotation.createAnnotationFrameBlob(
this.envelopeReceiver.name, this.envelopeReceiver.name,
this.currentReceiver.signature, this.currentReceiver.signature,
timestamp, timestamp,
@ -125,7 +124,7 @@ class App {
const blob = await request.blob() const blob = await request.blob()
const imageAttachmentId = await this.Instance.createAttachment(blob) const imageAttachmentId = await this.Instance.createAttachment(blob)
const frameAnnotation = this.Annotation.createImageAnnotation( const frameAnnotation = Annotation.createImageAnnotation(
new PSPDFKit.Geometry.Rect({ new PSPDFKit.Geometry.Rect({
left: left, left: left,
top: top, top: top,
@ -247,7 +246,7 @@ class App {
async validateAnnotations(totalSignatures) { async validateAnnotations(totalSignatures) {
const annotations = await this.Annotation.getAnnotations(this.Instance) const annotations = await Annotation.getAnnotations(this.Instance)
const filtered = annotations const filtered = annotations
.map(a => a.toJS()) .map(a => a.toJS())
.filter(a => a.isSignature) .filter(a => a.isSignature)
@ -268,7 +267,7 @@ class App {
}) })
if (result.isConfirmed) { if (result.isConfirmed) {
const result = await this.Annotation.deleteAnnotations(this.Instance) const result = await Annotation.deleteAnnotations(this.Instance)
} }
return result return result