fix(backend): Consider textarea elements in PDF output
This commit is contained in:
@@ -39,8 +39,9 @@ class ApplicationFormFormatService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun filterVisibleElements(applicationForm: ApplicationForm): ApplicationForm {
|
private fun filterVisibleElements(applicationForm: ApplicationForm): ApplicationForm {
|
||||||
val formElementsByRef = buildFormElementsMap(applicationForm)
|
val allElements = collectAllFormElements(applicationForm)
|
||||||
val visibilityMap = evaluateVisibility(formElementsByRef)
|
val formElementsByRef = buildFormElementsByRefMap(allElements)
|
||||||
|
val visibilityMap = evaluateVisibility(allElements, formElementsByRef)
|
||||||
|
|
||||||
val filteredSections =
|
val filteredSections =
|
||||||
applicationForm.formElementSections
|
applicationForm.formElementSections
|
||||||
@@ -51,7 +52,7 @@ class ApplicationFormFormatService(
|
|||||||
.mapNotNull { subsection ->
|
.mapNotNull { subsection ->
|
||||||
val filteredElements =
|
val filteredElements =
|
||||||
subsection.formElements.filter { element ->
|
subsection.formElements.filter { element ->
|
||||||
visibilityMap[element.id] == true
|
visibilityMap[element.id] ?: true
|
||||||
}
|
}
|
||||||
if (filteredElements.isEmpty()) {
|
if (filteredElements.isEmpty()) {
|
||||||
null
|
null
|
||||||
@@ -97,22 +98,23 @@ class ApplicationFormFormatService(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildFormElementsMap(applicationForm: ApplicationForm): Map<String, FormElement> {
|
private fun collectAllFormElements(applicationForm: ApplicationForm): List<FormElement> =
|
||||||
val map = mutableMapOf<String, FormElement>()
|
applicationForm.formElementSections
|
||||||
applicationForm.formElementSections.forEach { section ->
|
.flatMap { it.formElementSubSections }
|
||||||
section.formElementSubSections.forEach { subsection ->
|
.flatMap { it.formElements }
|
||||||
subsection.formElements.forEach { element ->
|
|
||||||
element.reference?.let { map[it] = element }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return map
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun evaluateVisibility(formElementsByRef: Map<String, FormElement>): Map<UUID?, Boolean> {
|
private fun buildFormElementsByRefMap(allElements: List<FormElement>): Map<String, FormElement> =
|
||||||
|
allElements
|
||||||
|
.mapNotNull { elem -> elem.reference?.let { it to elem } }
|
||||||
|
.toMap()
|
||||||
|
|
||||||
|
private fun evaluateVisibility(
|
||||||
|
allElements: List<FormElement>,
|
||||||
|
formElementsByRef: Map<String, FormElement>,
|
||||||
|
): Map<UUID?, Boolean> {
|
||||||
val visibilityMap = mutableMapOf<UUID?, Boolean>()
|
val visibilityMap = mutableMapOf<UUID?, Boolean>()
|
||||||
|
|
||||||
formElementsByRef.values.forEach { element ->
|
allElements.forEach { element ->
|
||||||
visibilityMap[element.id] = isElementVisible(element, formElementsByRef)
|
visibilityMap[element.id] = isElementVisible(element, formElementsByRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +141,15 @@ class ApplicationFormFormatService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getFormElementValue(element: FormElement): String =
|
private fun getFormElementValue(element: FormElement): String =
|
||||||
element.options.firstOrNull { it.value == "true" }?.label ?: ""
|
when (element.type.name) {
|
||||||
|
"SELECT",
|
||||||
|
"RADIOBUTTON",
|
||||||
|
-> element.options.firstOrNull { it.value == "true" }?.label ?: ""
|
||||||
|
"CHECKBOX",
|
||||||
|
"SWITCH",
|
||||||
|
-> if (element.options.any { it.value == "true" }) "true" else "false"
|
||||||
|
else -> element.options.firstOrNull()?.value ?: ""
|
||||||
|
}
|
||||||
|
|
||||||
private fun evaluateCondition(
|
private fun evaluateCondition(
|
||||||
actualValue: String,
|
actualValue: String,
|
||||||
|
|||||||
@@ -156,6 +156,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<p th:if="${elem.options.isEmpty() || elem.options.?[!value.isEmpty()].isEmpty()}">Keine Eingabe</p>
|
<p th:if="${elem.options.isEmpty() || elem.options.?[!value.isEmpty()].isEmpty()}">Keine Eingabe</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div th:case="'TEXTAREA'">
|
||||||
|
<div th:each="option : ${elem.options}">
|
||||||
|
<p th:if="${!option.value.isEmpty()}" th:text="${option.value}"></p>
|
||||||
|
</div>
|
||||||
|
<p th:if="${elem.options.isEmpty() || elem.options.?[!value.isEmpty()].isEmpty()}">Keine Eingabe</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div th:case="'DATE'">
|
<div th:case="'DATE'">
|
||||||
<div th:each="option : ${elem.options}">
|
<div th:each="option : ${elem.options}">
|
||||||
@@ -187,6 +194,18 @@
|
|||||||
<p th:each="option : ${elem.options}" th:if="${option.value == 'true'}" th:text="${option.label}"></p>
|
<p th:each="option : ${elem.options}" th:if="${option.value == 'true'}" th:text="${option.label}"></p>
|
||||||
<p th:if="${elem.options.?[value == 'true'].isEmpty()}">Keine Auswahl getroffen</p>
|
<p th:if="${elem.options.?[value == 'true'].isEmpty()}">Keine Auswahl getroffen</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div th:case="'CHECKBOX'">
|
||||||
|
<ul>
|
||||||
|
<li th:each="option : ${elem.options}" th:if="${option.value == 'true'}" th:text="${option.label}"></li>
|
||||||
|
</ul>
|
||||||
|
<p th:if="${elem.options.?[value == 'true'].isEmpty()}">Keine Auswahl getroffen</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div th:case="'SWITCH'">
|
||||||
|
<p th:if="${elem.options.?[value == 'true'].isEmpty()}">Nein</p>
|
||||||
|
<p th:if="${!elem.options.?[value == 'true'].isEmpty()}">Ja</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div th:case="*">
|
<div th:case="*">
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user