From 8d2a148614bed70ce2c3037f02996b1b4d33d085 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio@bekerle.com> Date: Wed, 17 Mar 2021 11:14:56 +0100 Subject: [PATCH] Add annotation updating and fix value setting --- src/dbp-official-signature-pdf-upload.js | 26 ++++++------------------ src/dbp-signature-lit-element.js | 16 +++++++++++++-- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/dbp-official-signature-pdf-upload.js b/src/dbp-official-signature-pdf-upload.js index 5efe145..4e3e3ff 100644 --- a/src/dbp-official-signature-pdf-upload.js +++ b/src/dbp-official-signature-pdf-upload.js @@ -777,28 +777,14 @@ class OfficialSignaturePdfUpload extends ScopedElementsMixin(DBPSignatureLitElem return results; } - // /** - // * Returns the list of files of annotations of a queued file - // */ - // getAnnotationsHtml(key) { - // const annotations = this.queuedFilesAnnotations[key] || []; - // return annotations.length > 0 ? - // html` - // <button class="button" - // title="Add annotation" - // @click="${() => { this.addAnnotation(key); }}"> - // <dbp-icon name="plus"></dbp-icon></button> - // ${this.getAnnotationLinesHtml(key)} - // ` : - // html``; - // } - /** * Returns the list of files of annotations of a queued file * * @returns {*[]} Array of html templates */ getAnnotationsHtml(key) { + // console.log("getAnnotationsHtml(key)", key); + const annotations = this.queuedFilesAnnotations[key] || []; const ids = Object.keys(annotations); let results = []; @@ -807,10 +793,10 @@ class OfficialSignaturePdfUpload extends ScopedElementsMixin(DBPSignatureLitElem const data = this.queuedFilesAnnotations[key][id] || []; results.push(html` - <div class="annotation-block"> - <input type="text" value="${data.key1}" placeholder="key1" /> - <input type="text" value="${data.key2}" placeholder="key2" /> - <input type="text" value="${data.value}" placeholder="value" /> + <div class="annotation-block" class="annotation-block-${key}-${id}"> + <input type="text" .value="${data.key1}" @change=${e => { this.updateAnnotation(key, id, 'key1', e.target.value); }} placeholder="key1" /> + <input type="text" .value="${data.key2}" @change=${e => { this.updateAnnotation(key, id, 'key2', e.target.value); }} placeholder="key2" /> + <input type="text" .value="${data.value}" @change=${e => { this.updateAnnotation(key, id, 'value', e.target.value); }} placeholder="value" /> <button class="button" title="Remove annotation" @click="${() => { this.removeAnnotation(key, id); }}"> diff --git a/src/dbp-signature-lit-element.js b/src/dbp-signature-lit-element.js index e6aabdc..d76f2d7 100644 --- a/src/dbp-signature-lit-element.js +++ b/src/dbp-signature-lit-element.js @@ -128,8 +128,6 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { // we just need this so the UI will update this.queuedFilesAnnotationsCount++; - - console.log("this.queuedFilesAnnotations", this.queuedFilesAnnotations); } /** @@ -146,6 +144,20 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { } } + /** + * Update an annotation of a file on the queue + * + * @param key + * @param id + * @param annotationKey + * @param value + */ + async updateAnnotation(key, id, annotationKey, value) { + if (this.queuedFilesAnnotations[key] && this.queuedFilesAnnotations[key][id]) { + this.queuedFilesAnnotations[key][id][annotationKey] = value; + } + } + /** * Add an annotation to a file on the queue * -- GitLab