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 {
|
||||
val formElementsByRef = buildFormElementsMap(applicationForm)
|
||||
val visibilityMap = evaluateVisibility(formElementsByRef)
|
||||
val allElements = collectAllFormElements(applicationForm)
|
||||
val formElementsByRef = buildFormElementsByRefMap(allElements)
|
||||
val visibilityMap = evaluateVisibility(allElements, formElementsByRef)
|
||||
|
||||
val filteredSections =
|
||||
applicationForm.formElementSections
|
||||
@@ -51,7 +52,7 @@ class ApplicationFormFormatService(
|
||||
.mapNotNull { subsection ->
|
||||
val filteredElements =
|
||||
subsection.formElements.filter { element ->
|
||||
visibilityMap[element.id] == true
|
||||
visibilityMap[element.id] ?: true
|
||||
}
|
||||
if (filteredElements.isEmpty()) {
|
||||
null
|
||||
@@ -97,22 +98,23 @@ class ApplicationFormFormatService(
|
||||
)
|
||||
}
|
||||
|
||||
private fun buildFormElementsMap(applicationForm: ApplicationForm): Map<String, FormElement> {
|
||||
val map = mutableMapOf<String, FormElement>()
|
||||
applicationForm.formElementSections.forEach { section ->
|
||||
section.formElementSubSections.forEach { subsection ->
|
||||
subsection.formElements.forEach { element ->
|
||||
element.reference?.let { map[it] = element }
|
||||
}
|
||||
}
|
||||
}
|
||||
return map
|
||||
}
|
||||
private fun collectAllFormElements(applicationForm: ApplicationForm): List<FormElement> =
|
||||
applicationForm.formElementSections
|
||||
.flatMap { it.formElementSubSections }
|
||||
.flatMap { it.formElements }
|
||||
|
||||
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>()
|
||||
|
||||
formElementsByRef.values.forEach { element ->
|
||||
allElements.forEach { element ->
|
||||
visibilityMap[element.id] = isElementVisible(element, formElementsByRef)
|
||||
}
|
||||
|
||||
@@ -139,7 +141,15 @@ class ApplicationFormFormatService(
|
||||
}
|
||||
|
||||
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(
|
||||
actualValue: String,
|
||||
|
||||
@@ -157,6 +157,13 @@
|
||||
<p th:if="${elem.options.isEmpty() || elem.options.?[!value.isEmpty()].isEmpty()}">Keine Eingabe</p>
|
||||
</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:each="option : ${elem.options}">
|
||||
<p th:if="${!option.value.isEmpty()}"
|
||||
@@ -188,6 +195,18 @@
|
||||
<p th:if="${elem.options.?[value == 'true'].isEmpty()}">Keine Auswahl getroffen</p>
|
||||
</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="*">
|
||||
<ul>
|
||||
<li th:each="option : ${elem.options}" th:if="${option.value == 'true'}" th:text="${option.label}"></li>
|
||||
|
||||
Reference in New Issue
Block a user