Skip to content
Snippets Groups Projects
Unverified Commit e1f9a678 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire:
Browse files

Write annotation to pdf (#37)

parent f3101d68
No related branches found
No related tags found
No related merge requests found
Pipeline #18026 passed with warnings
...@@ -168,7 +168,8 @@ class OfficialSignaturePdfUpload extends ScopedElementsMixin(DBPSignatureLitElem ...@@ -168,7 +168,8 @@ class OfficialSignaturePdfUpload extends ScopedElementsMixin(DBPSignatureLitElem
fileSize: humanFileSize(file.size, false), fileSize: humanFileSize(file.size, false),
}); });
await this.uploadFile(file, params); const annotations = this.takeAnnotationsFromQueue(key);
await this.uploadFile(file, params, annotations, i18n);
this.uploadInProgress = false; this.uploadInProgress = false;
} }
......
import * as utils from "./utils"; import * as utils from "./utils";
import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element"; import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element";
import JSONLD from "@dbp-toolkit/common/jsonld"; import JSONLD from "@dbp-toolkit/common/jsonld";
import * as commonUtils from "@dbp-toolkit/common/utils";
export class DBPSignatureBaseLitElement extends AdapterLitElement { export class DBPSignatureBaseLitElement extends AdapterLitElement {
constructor() { constructor() {
...@@ -90,9 +91,9 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -90,9 +91,9 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
/** /**
* @param file * @param file
* @returns {Promise<string>} key of the queued item * @returns key of the queued item
*/ */
async queueFile(file) { queueFile(file) {
this._queueKey++; this._queueKey++;
const key = this._queueKey; const key = this._queueKey;
this.queuedFiles[key] = file; this.queuedFiles[key] = file;
...@@ -118,25 +119,49 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -118,25 +119,49 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
* *
* @param key * @param key
*/ */
async addAnnotation(key) { addAnnotation(key) {
if (!this.queuedFilesAnnotations[key]) { if (!this.queuedFilesAnnotations[key]) {
this.queuedFilesAnnotations[key] = []; this.queuedFilesAnnotations[key] = [];
this.queuedFilesAnnotationsCount = 0; this.queuedFilesAnnotationsCount = 0;
} }
this.queuedFilesAnnotations[key].push({'key1': 'my key 1', 'key2': 'my key 2', 'value': 'my value'}); // TODO: remove key/value presets
const number = Math.floor((Math.random() * 1000) + 1);
this.queuedFilesAnnotations[key].push({'key1': 'geschaeftszahl', 'key2': 'F' + number, 'value': 'my value ' + number});
// we just need this so the UI will update // we just need this so the UI will update
this.queuedFilesAnnotationsCount++; this.queuedFilesAnnotationsCount++;
} }
async addAnnotationsToFile(file, annotations, i18n) {
await commonUtils.asyncObjectForEach(annotations, async (annotation) => {
console.log("annotation", annotation);
console.log("file before", file);
const key1 = annotation.key1.trim();
const key2 = annotation.key2.trim();
const value = annotation.value.trim();
if (key1 === '' || key2 === '' || value === '') {
return;
}
const annotationKey = key1 + '-' + key2;
file = await utils.addKeyValuePdfAnnotation(file, i18n, 'AppName', this.auth['user-full-name'], annotationKey, value);
console.log("file after", file);
});
console.log("addAnnotationsToFile file", file);
return file;
}
/** /**
* Remove an annotation of a file on the queue * Remove an annotation of a file on the queue
* *
* @param key * @param key
* @param id * @param id
*/ */
async removeAnnotation(key, id) { removeAnnotation(key, id) {
if (this.queuedFilesAnnotations[key] && this.queuedFilesAnnotations[key][id]) { if (this.queuedFilesAnnotations[key] && this.queuedFilesAnnotations[key][id]) {
delete this.queuedFilesAnnotations[key][id]; delete this.queuedFilesAnnotations[key][id];
// we just need this so the UI will update // we just need this so the UI will update
...@@ -144,6 +169,18 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -144,6 +169,18 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
} }
} }
/**
* Takes the annotations of a file off of the queue
*
* @param key
*/
takeAnnotationsFromQueue(key) {
const annotations = this.queuedFilesAnnotations[key];
delete this.queuedFilesAnnotations[key];
return annotations;
}
/** /**
* Update an annotation of a file on the queue * Update an annotation of a file on the queue
* *
...@@ -152,7 +189,7 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -152,7 +189,7 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
* @param annotationKey * @param annotationKey
* @param value * @param value
*/ */
async updateAnnotation(key, id, annotationKey, value) { updateAnnotation(key, id, annotationKey, value) {
if (this.queuedFilesAnnotations[key] && this.queuedFilesAnnotations[key][id]) { if (this.queuedFilesAnnotations[key] && this.queuedFilesAnnotations[key][id]) {
this.queuedFilesAnnotations[key][id][annotationKey] = value; this.queuedFilesAnnotations[key][id][annotationKey] = value;
} }
...@@ -222,11 +259,20 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -222,11 +259,20 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
/** /**
* @param file * @param file
* @param params * @param params
* @param annotations
* @param i18n
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async uploadFile(file, params = {}) { async uploadFile(file, params = {}, annotations = [], i18n = {}) {
this.uploadInProgress = true; this.uploadInProgress = true;
this.uploadStatusFileName = file.name; this.uploadStatusFileName = file.name;
// add annotations
if (annotations.length > 0) {
file = await this.addAnnotationsToFile(file, annotations, i18n)
console.log("uploadFile file", file);
}
let url = new URL(this.fileSourceUrl); let url = new URL(this.fileSourceUrl);
let formData = new FormData(); let formData = new FormData();
formData.append('file', file); formData.append('file', file);
......
...@@ -143,6 +143,14 @@ export const getPDFSignatureCount = async (file) => { ...@@ -143,6 +143,14 @@ export const getPDFSignatureCount = async (file) => {
}; };
export const addKeyValuePdfAnnotation = async (file, i18n, appName, personName, key, value) => { export const addKeyValuePdfAnnotation = async (file, i18n, appName, personName, key, value) => {
key = key.trim();
value = value.trim();
// don't annotate if key or value are empty
if (key === '' || value === '') {
return file;
}
const data = await readArrayBufferFileContent(file); const data = await readArrayBufferFileContent(file);
let pdfFactory = new AnnotationFactory(data); let pdfFactory = new AnnotationFactory(data);
...@@ -154,7 +162,7 @@ export const addKeyValuePdfAnnotation = async (file, i18n, appName, personName, ...@@ -154,7 +162,7 @@ export const addKeyValuePdfAnnotation = async (file, i18n, appName, personName,
appName: appName, appName: appName,
personName: personName personName: personName
}); });
const contents = 'DBP-SIGNATURE-' + key + ': ' + value; const contents = 'dbp-annotation-' + key + '=' + value;
// pdfFactory.checkRect(4, rect); // pdfFactory.checkRect(4, rect);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment