diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormFormatService.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormFormatService.kt index aec106c..de31438 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormFormatService.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormFormatService.kt @@ -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 { - val map = mutableMapOf() - 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 = + applicationForm.formElementSections + .flatMap { it.formElementSubSections } + .flatMap { it.formElements } - private fun evaluateVisibility(formElementsByRef: Map): Map { + private fun buildFormElementsByRefMap(allElements: List): Map = + allElements + .mapNotNull { elem -> elem.reference?.let { it to elem } } + .toMap() + + private fun evaluateVisibility( + allElements: List, + formElementsByRef: Map, + ): Map { val visibilityMap = mutableMapOf() - 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, diff --git a/legalconsenthub-backend/src/main/resources/templates/application_form_template.html b/legalconsenthub-backend/src/main/resources/templates/application_form_template.html index 2453f63..24a6d83 100644 --- a/legalconsenthub-backend/src/main/resources/templates/application_form_template.html +++ b/legalconsenthub-backend/src/main/resources/templates/application_form_template.html @@ -156,6 +156,13 @@

Keine Eingabe

+ +
+
+

+
+

Keine Eingabe

+
@@ -187,6 +194,18 @@

Keine Auswahl getroffen

+ +
+
    +
  • +
+

Keine Auswahl getroffen

+
+ +
+

Nein

+

Ja

+