From 4a040a429b3ba23f4c540e33d19de28cd3423d09 Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio@bekerle.com>
Date: Wed, 24 Mar 2021 11:47:54 +0100
Subject: [PATCH] Do variable name refactoring (#37)

---
 src/dbp-official-signature-pdf-upload.js |  8 ++---
 src/dbp-signature-lit-element.js         | 20 +++++------
 src/utils.js                             | 42 ++++++++++++------------
 3 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/src/dbp-official-signature-pdf-upload.js b/src/dbp-official-signature-pdf-upload.js
index 4bd76b3..2eb9eb6 100644
--- a/src/dbp-official-signature-pdf-upload.js
+++ b/src/dbp-official-signature-pdf-upload.js
@@ -794,13 +794,13 @@ class OfficialSignaturePdfUpload extends ScopedElementsMixin(DBPSignatureLitElem
 
             results.push(html`
                 <div class="annotation-block" class="annotation-block-${key}-${id}">
-                    <select class="select" @change=${e => { this.updateAnnotation(key, id, 'key1', e.target.value); }}>
+                    <select class="select" @change=${e => { this.updateAnnotation(key, id, 'annotationType', e.target.value); }}>
                         <option value="">${i18n.t('official-pdf-upload.annotation-type-please-select')}</option>
-                        ${utils.getAnnotationTypeSelectOptionsHtml(data.key1, this.lang)}
+                        ${utils.getAnnotationTypeSelectOptionsHtml(data.annotationType, this.lang)}
                     </select>
                     <dbp-organization-select subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth"
-                                             value="${data.key2}"
-                                             @change=${e => { this.updateAnnotation(key, id, 'key2', JSON.parse(e.target.getAttribute("data-object")).alternateName); }}></dbp-organization-select>
+                                             value="${data.organizationNumber}"
+                                             @change=${e => { this.updateAnnotation(key, id, 'organizationNumber', JSON.parse(e.target.getAttribute("data-object")).alternateName); }}></dbp-organization-select>
                     <input type="text" .value="${data.value}" @change=${e => { this.updateAnnotation(key, id, 'value', e.target.value); }} placeholder="value" />
                     <button class="button"
                         title="Remove annotation"
diff --git a/src/dbp-signature-lit-element.js b/src/dbp-signature-lit-element.js
index 33140be..d324aae 100644
--- a/src/dbp-signature-lit-element.js
+++ b/src/dbp-signature-lit-element.js
@@ -125,7 +125,7 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
 
         // TODO: remove key/value presets
         const number =  Math.floor((Math.random() * 1000) + 1);
-        this.queuedFilesAnnotations[key].push({'key1': 'geschaeftszahl', 'value': 'my value ' + number});
+        this.queuedFilesAnnotations[key].push({'annotationType': 'geschaeftszahl', 'value': 'my value ' + number});
 
         // we just need this so the UI will update
         this.queuedFilesAnnotationsCount++;
@@ -142,23 +142,23 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
         // We need to work with the AnnotationFactory because the pdf file is broken if
         // we add the multiple annotations to the file itself
         let pdfFactory = await utils.getAnnotationFactoryFromFile(file);
-        const appNameDE = this.activity.getName('de');
-        const appNameEN = this.activity.getName('en');
+        const activityNameDE = this.activity.getName('de');
+        const activityNameEN = this.activity.getName('en');
 
         await commonUtils.asyncObjectForEach(annotations, async (annotation) => {
-            const key1 = (annotation.key1 || '').trim();
-            const key2 = (annotation.key2 || '').trim();
+            const annotationType = (annotation.annotationType || '').trim();
+            const organizationNumber = (annotation.organizationNumber || '').trim();
             const value = (annotation.value || '').trim();
 
-            if (key1 === '' || key2 === '' || value === '') {
+            if (annotationType === '' || organizationNumber === '' || value === '') {
                 return;
             }
 
-            const annotationTypeNames = utils.getAnnotationTypes(key1);
+            const annotationTypeNames = utils.getAnnotationTypes(annotationType);
 
             pdfFactory = await utils.addKeyValuePdfAnnotationsToAnnotationFactory(
-                pdfFactory, appNameDE, appNameEN, this.auth['user-full-name'], key1,
-                annotationTypeNames.de, annotationTypeNames.en, key2, value);
+                pdfFactory, activityNameDE, activityNameEN, this.auth['user-full-name'], annotationType,
+                annotationTypeNames.de, annotationTypeNames.en, organizationNumber, value);
         });
 
         // output the AnnotationFactory as File again
@@ -285,7 +285,7 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
             // Also send to the server so it gets included in the signature block
             let userText = [];
             for (let ann of annotations) {
-                userText.push({"description": ann["key1"], "value": `${ann["value"]} (${ann["key2"]})`});
+                userText.push({"description": ann["annotationType"], "value": `${ann["value"]} (${ann["organizationNumber"]})`});
             }
             formData.append("user_text", JSON.stringify(userText));
         }
diff --git a/src/utils.js b/src/utils.js
index e031a46..cc7c91c 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -148,14 +148,14 @@ export const getPDFSignatureCount = async (file) => {
  * Adds an annotation to a PDF file
  *
  * @param file
- * @param appNameDE
- * @param appNameEN
+ * @param activityNameDE
+ * @param activityNameEN
  * @param personName
  * @param key
  * @param value
  * @returns {File}
  */
-export const addKeyValuePdfAnnotation = async (file, appNameDE, appNameEN, personName, key, value) => {
+export const addKeyValuePdfAnnotation = async (file, activityNameDE, activityNameEN, personName, key, value) => {
     key = key.trim();
     value = value.trim();
 
@@ -165,8 +165,8 @@ export const addKeyValuePdfAnnotation = async (file, appNameDE, appNameEN, perso
     }
 
     let annotationFactory = await getAnnotationFactoryFromFile(file);
-    annotationFactory = addKeyValuePdfAnnotationsToAnnotationFactory(annotationFactory, appNameDE, appNameEN,
-        personName, key, 'Name DE', 'Name EN', 'key2', value);
+    annotationFactory = addKeyValuePdfAnnotationsToAnnotationFactory(annotationFactory, activityNameDE, activityNameEN,
+        personName, key, 'Name DE', 'Name EN', 'organizationNumber', value);
 
     return writeAnnotationFactoryToFile(annotationFactory, file);
 };
@@ -200,37 +200,37 @@ export const getAnnotationFactoryFromFile = async (file) => {
  * Adds a key/value annotation to a AnnotationFactory and returns the AnnotationFactory
  *
  * @param annotationFactory
- * @param appNameDE
- * @param appNameEN
+ * @param activityNameDE
+ * @param activityNameEN
  * @param personName
- * @param key1
- * @param key1NameDE
- * @param key1NameEN
- * @param key2
+ * @param annotationType
+ * @param annotationTypeNameDE
+ * @param annotationTypeNameEN
+ * @param organizationNumber
  * @param value
  * @returns PdfFactory
  */
-export const addKeyValuePdfAnnotationsToAnnotationFactory = (annotationFactory, appNameDE, appNameEN, personName,
-                                                             key1, key1NameDE, key1NameEN, key2, value) => {
-    key1 = key1.trim();
-    key1NameDE = key1NameDE.trim();
-    key1NameEN = key1NameEN.trim();
-    key2 = key2.trim();
+export const addKeyValuePdfAnnotationsToAnnotationFactory = (annotationFactory, activityNameDE, activityNameEN, personName,
+                                                             annotationType, annotationTypeNameDE, annotationTypeNameEN, organizationNumber, value) => {
+    annotationType = annotationType.trim();
+    annotationTypeNameDE = annotationTypeNameDE.trim();
+    annotationTypeNameEN = annotationTypeNameEN.trim();
+    organizationNumber = organizationNumber.trim();
     value = value.trim();
 
     // don't annotate if key or value are empty
-    if (key1 === '' || key2 === '' || value === '') {
+    if (annotationType === '' || organizationNumber === '' || value === '') {
         return annotationFactory;
     }
 
     // add human readable annotation
-    let author = personName + ' via  "' + appNameDE + ' / ' + appNameEN + '"';
-    let content = key1NameDE + ': ' + value +"\n" + key1NameEN + ': ' + value;
+    let author = personName + ' via  "' + activityNameDE + ' / ' + activityNameEN + '"';
+    let content = annotationTypeNameDE + ': ' + value +"\n" + annotationTypeNameEN + ': ' + value;
     annotationFactory = addPdfAnnotationToAnnotationFactory(annotationFactory, author, content);
 
     // add machine readable annotation
     author = 'Maschinell aufgebracht, bitte nicht entfernen / Applied automatically, please do not remove';
-    content = 'dbp-annotation-' + key1 + '-' + key2 + '=' + value;
+    content = 'dbp-annotation-' + annotationType + '-' + organizationNumber + '=' + value;
     annotationFactory = addPdfAnnotationToAnnotationFactory(annotationFactory, author, content);
 
     return annotationFactory;
-- 
GitLab