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

Do variable name refactoring (#37)

parent 194ec1c9
Branches
No related tags found
No related merge requests found
Pipeline #18307 failed
...@@ -794,13 +794,13 @@ class OfficialSignaturePdfUpload extends ScopedElementsMixin(DBPSignatureLitElem ...@@ -794,13 +794,13 @@ class OfficialSignaturePdfUpload extends ScopedElementsMixin(DBPSignatureLitElem
results.push(html` results.push(html`
<div class="annotation-block" class="annotation-block-${key}-${id}"> <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> <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> </select>
<dbp-organization-select subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth" <dbp-organization-select subscribe="lang:lang,entry-point-url:entry-point-url,auth:auth"
value="${data.key2}" value="${data.organizationNumber}"
@change=${e => { this.updateAnnotation(key, id, 'key2', JSON.parse(e.target.getAttribute("data-object")).alternateName); }}></dbp-organization-select> @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" /> <input type="text" .value="${data.value}" @change=${e => { this.updateAnnotation(key, id, 'value', e.target.value); }} placeholder="value" />
<button class="button" <button class="button"
title="Remove annotation" title="Remove annotation"
......
...@@ -125,7 +125,7 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -125,7 +125,7 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
// TODO: remove key/value presets // TODO: remove key/value presets
const number = Math.floor((Math.random() * 1000) + 1); 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 // we just need this so the UI will update
this.queuedFilesAnnotationsCount++; this.queuedFilesAnnotationsCount++;
...@@ -142,23 +142,23 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -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 need to work with the AnnotationFactory because the pdf file is broken if
// we add the multiple annotations to the file itself // we add the multiple annotations to the file itself
let pdfFactory = await utils.getAnnotationFactoryFromFile(file); let pdfFactory = await utils.getAnnotationFactoryFromFile(file);
const appNameDE = this.activity.getName('de'); const activityNameDE = this.activity.getName('de');
const appNameEN = this.activity.getName('en'); const activityNameEN = this.activity.getName('en');
await commonUtils.asyncObjectForEach(annotations, async (annotation) => { await commonUtils.asyncObjectForEach(annotations, async (annotation) => {
const key1 = (annotation.key1 || '').trim(); const annotationType = (annotation.annotationType || '').trim();
const key2 = (annotation.key2 || '').trim(); const organizationNumber = (annotation.organizationNumber || '').trim();
const value = (annotation.value || '').trim(); const value = (annotation.value || '').trim();
if (key1 === '' || key2 === '' || value === '') { if (annotationType === '' || organizationNumber === '' || value === '') {
return; return;
} }
const annotationTypeNames = utils.getAnnotationTypes(key1); const annotationTypeNames = utils.getAnnotationTypes(annotationType);
pdfFactory = await utils.addKeyValuePdfAnnotationsToAnnotationFactory( pdfFactory = await utils.addKeyValuePdfAnnotationsToAnnotationFactory(
pdfFactory, appNameDE, appNameEN, this.auth['user-full-name'], key1, pdfFactory, activityNameDE, activityNameEN, this.auth['user-full-name'], annotationType,
annotationTypeNames.de, annotationTypeNames.en, key2, value); annotationTypeNames.de, annotationTypeNames.en, organizationNumber, value);
}); });
// output the AnnotationFactory as File again // output the AnnotationFactory as File again
...@@ -285,7 +285,7 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement { ...@@ -285,7 +285,7 @@ export default class DBPSignatureLitElement extends DBPSignatureBaseLitElement {
// Also send to the server so it gets included in the signature block // Also send to the server so it gets included in the signature block
let userText = []; let userText = [];
for (let ann of annotations) { 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)); formData.append("user_text", JSON.stringify(userText));
} }
......
...@@ -148,14 +148,14 @@ export const getPDFSignatureCount = async (file) => { ...@@ -148,14 +148,14 @@ export const getPDFSignatureCount = async (file) => {
* Adds an annotation to a PDF file * Adds an annotation to a PDF file
* *
* @param file * @param file
* @param appNameDE * @param activityNameDE
* @param appNameEN * @param activityNameEN
* @param personName * @param personName
* @param key * @param key
* @param value * @param value
* @returns {File} * @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(); key = key.trim();
value = value.trim(); value = value.trim();
...@@ -165,8 +165,8 @@ export const addKeyValuePdfAnnotation = async (file, appNameDE, appNameEN, perso ...@@ -165,8 +165,8 @@ export const addKeyValuePdfAnnotation = async (file, appNameDE, appNameEN, perso
} }
let annotationFactory = await getAnnotationFactoryFromFile(file); let annotationFactory = await getAnnotationFactoryFromFile(file);
annotationFactory = addKeyValuePdfAnnotationsToAnnotationFactory(annotationFactory, appNameDE, appNameEN, annotationFactory = addKeyValuePdfAnnotationsToAnnotationFactory(annotationFactory, activityNameDE, activityNameEN,
personName, key, 'Name DE', 'Name EN', 'key2', value); personName, key, 'Name DE', 'Name EN', 'organizationNumber', value);
return writeAnnotationFactoryToFile(annotationFactory, file); return writeAnnotationFactoryToFile(annotationFactory, file);
}; };
...@@ -200,37 +200,37 @@ export const getAnnotationFactoryFromFile = async (file) => { ...@@ -200,37 +200,37 @@ export const getAnnotationFactoryFromFile = async (file) => {
* Adds a key/value annotation to a AnnotationFactory and returns the AnnotationFactory * Adds a key/value annotation to a AnnotationFactory and returns the AnnotationFactory
* *
* @param annotationFactory * @param annotationFactory
* @param appNameDE * @param activityNameDE
* @param appNameEN * @param activityNameEN
* @param personName * @param personName
* @param key1 * @param annotationType
* @param key1NameDE * @param annotationTypeNameDE
* @param key1NameEN * @param annotationTypeNameEN
* @param key2 * @param organizationNumber
* @param value * @param value
* @returns PdfFactory * @returns PdfFactory
*/ */
export const addKeyValuePdfAnnotationsToAnnotationFactory = (annotationFactory, appNameDE, appNameEN, personName, export const addKeyValuePdfAnnotationsToAnnotationFactory = (annotationFactory, activityNameDE, activityNameEN, personName,
key1, key1NameDE, key1NameEN, key2, value) => { annotationType, annotationTypeNameDE, annotationTypeNameEN, organizationNumber, value) => {
key1 = key1.trim(); annotationType = annotationType.trim();
key1NameDE = key1NameDE.trim(); annotationTypeNameDE = annotationTypeNameDE.trim();
key1NameEN = key1NameEN.trim(); annotationTypeNameEN = annotationTypeNameEN.trim();
key2 = key2.trim(); organizationNumber = organizationNumber.trim();
value = value.trim(); value = value.trim();
// don't annotate if key or value are empty // don't annotate if key or value are empty
if (key1 === '' || key2 === '' || value === '') { if (annotationType === '' || organizationNumber === '' || value === '') {
return annotationFactory; return annotationFactory;
} }
// add human readable annotation // add human readable annotation
let author = personName + ' via "' + appNameDE + ' / ' + appNameEN + '"'; let author = personName + ' via "' + activityNameDE + ' / ' + activityNameEN + '"';
let content = key1NameDE + ': ' + value +"\n" + key1NameEN + ': ' + value; let content = annotationTypeNameDE + ': ' + value +"\n" + annotationTypeNameEN + ': ' + value;
annotationFactory = addPdfAnnotationToAnnotationFactory(annotationFactory, author, content); annotationFactory = addPdfAnnotationToAnnotationFactory(annotationFactory, author, content);
// add machine readable annotation // add machine readable annotation
author = 'Maschinell aufgebracht, bitte nicht entfernen / Applied automatically, please do not remove'; 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); annotationFactory = addPdfAnnotationToAnnotationFactory(annotationFactory, author, content);
return annotationFactory; return annotationFactory;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment