Refaktorisierte 'Annotation'-Funktionen zu statischen Methoden.
This commit is contained in:
parent
c4a66ee5bb
commit
39cc257466
@ -1,5 +1,5 @@
|
||||
class Annotation {
|
||||
createAnnotations(document) {
|
||||
static createAnnotations(document) {
|
||||
const annotations = []
|
||||
|
||||
document.elements.forEach((element) => {
|
||||
@ -11,7 +11,7 @@
|
||||
return annotations
|
||||
}
|
||||
|
||||
async getAnnotations(instance) {
|
||||
static async getAnnotations(instance) {
|
||||
const array = await Promise.all(
|
||||
Array.from({ length: instance.totalPageCount }).map((_, pageIndex) =>
|
||||
instance.getAnnotations(pageIndex)
|
||||
@ -23,14 +23,14 @@
|
||||
)
|
||||
}
|
||||
|
||||
async deleteAnnotations(instance) {
|
||||
static async deleteAnnotations(instance) {
|
||||
const allAnnotations = await this.getAnnotations(instance)
|
||||
const pageAnnotations = allAnnotations.filter(this.isSignature)
|
||||
//deleting all Annotations
|
||||
return await instance.delete(pageAnnotations)
|
||||
}
|
||||
|
||||
async validateAnnotations(instance) {
|
||||
static async validateAnnotations(instance) {
|
||||
const allAnnotations = await this.getAnnotations(instance)
|
||||
const pageAnnotations = allAnnotations
|
||||
.map((annotation) => {
|
||||
@ -40,11 +40,11 @@
|
||||
return true
|
||||
}
|
||||
|
||||
isSignature(annotation) {
|
||||
static isSignature(annotation) {
|
||||
return !!annotation.isSignature || annotation.description == 'FRAME'
|
||||
}
|
||||
|
||||
createAnnotationFromElement(element) {
|
||||
static createAnnotationFromElement(element) {
|
||||
const id = PSPDFKit.generateInstantId()
|
||||
const width = this.inchToPoint(element.width)
|
||||
const height = this.inchToPoint(element.height)
|
||||
@ -68,7 +68,7 @@
|
||||
return [annotation, formField]
|
||||
}
|
||||
|
||||
createSignatureAnnotation(id, width, height, top, left, pageIndex) {
|
||||
static createSignatureAnnotation(id, width, height, top, left, pageIndex) {
|
||||
const annotation = new PSPDFKit.Annotations.WidgetAnnotation({
|
||||
id: id,
|
||||
pageIndex: pageIndex,
|
||||
@ -86,7 +86,7 @@
|
||||
return annotation
|
||||
}
|
||||
|
||||
createImageAnnotation(boundingBox, pageIndex, imageAttachmentId) {
|
||||
static createImageAnnotation(boundingBox, pageIndex, imageAttachmentId) {
|
||||
const frameAnnotation = new PSPDFKit.Annotations.ImageAnnotation({
|
||||
pageIndex: pageIndex,
|
||||
isSignature: false,
|
||||
@ -101,7 +101,7 @@
|
||||
return frameAnnotation
|
||||
}
|
||||
|
||||
async createAnnotationFrameBlob(receiverName, receiverSignature, timestamp, width, height) {
|
||||
static async createAnnotationFrameBlob(receiverName, receiverSignature, timestamp, width, height) {
|
||||
const canvas = document.createElement('canvas')
|
||||
const scale = 4
|
||||
const fontSize = 10
|
||||
@ -154,7 +154,7 @@
|
||||
})
|
||||
}
|
||||
|
||||
inchToPoint(inch) {
|
||||
static inchToPoint(inch) {
|
||||
return inch * 72
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,6 @@ class App {
|
||||
|
||||
this.UI = new UI()
|
||||
this.Network = new Network()
|
||||
this.Annotation = new Annotation()
|
||||
|
||||
this.Instance = null
|
||||
this.currentDocument = null
|
||||
@ -72,7 +71,7 @@ class App {
|
||||
// Load annotations into PSPDFKit
|
||||
try {
|
||||
this.signatureCount = this.currentDocument.elements.length
|
||||
const annotations = this.Annotation.createAnnotations(
|
||||
const annotations = Annotation.createAnnotations(
|
||||
this.currentDocument
|
||||
)
|
||||
await this.Instance.create(annotations)
|
||||
@ -113,7 +112,7 @@ class App {
|
||||
const height = 75
|
||||
const timestamp = new Date()
|
||||
|
||||
const imageUrl = await this.Annotation.createAnnotationFrameBlob(
|
||||
const imageUrl = await Annotation.createAnnotationFrameBlob(
|
||||
this.envelopeReceiver.name,
|
||||
this.currentReceiver.signature,
|
||||
timestamp,
|
||||
@ -125,7 +124,7 @@ class App {
|
||||
const blob = await request.blob()
|
||||
const imageAttachmentId = await this.Instance.createAttachment(blob)
|
||||
|
||||
const frameAnnotation = this.Annotation.createImageAnnotation(
|
||||
const frameAnnotation = Annotation.createImageAnnotation(
|
||||
new PSPDFKit.Geometry.Rect({
|
||||
left: left,
|
||||
top: top,
|
||||
@ -247,7 +246,7 @@ class App {
|
||||
|
||||
|
||||
async validateAnnotations(totalSignatures) {
|
||||
const annotations = await this.Annotation.getAnnotations(this.Instance)
|
||||
const annotations = await Annotation.getAnnotations(this.Instance)
|
||||
const filtered = annotations
|
||||
.map(a => a.toJS())
|
||||
.filter(a => a.isSignature)
|
||||
@ -268,7 +267,7 @@ class App {
|
||||
})
|
||||
|
||||
if (result.isConfirmed) {
|
||||
const result = await this.Annotation.deleteAnnotations(this.Instance)
|
||||
const result = await Annotation.deleteAnnotations(this.Instance)
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user