Skip to content

Commit

Permalink
fix: options not hiding/showing with program rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Balcan committed Dec 4, 2024
1 parent 3a43b54 commit 2ee4dbf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
18 changes: 16 additions & 2 deletions form/src/main/java/org/dhis2/form/data/FormRepositoryImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FormRepositoryImpl(
private var runDataIntegrity: Boolean = false
private var calculationLoop: Int = 0
private var backupList: List<FieldUiModel> = emptyList()
private val fieldsWithOptionEffects = mutableListOf<FieldUiModel>()

private val disableCollapsableSections: Boolean? =
dataEntryRepository.disableCollapsableSections()
Expand Down Expand Up @@ -522,9 +523,22 @@ class FormRepositoryImpl(
}
}

fieldsWithOptionEffects.forEach { field ->
field.optionSet?.let { optionSetUid ->
fetchOptions(field.uid, optionSetUid)
}
}

fieldsWithOptionEffects.clear()

ruleEffectsResult?.fieldsWithOptionEffects()?.forEach { fieldWithOptionEffect ->
itemList.find { it.uid == fieldWithOptionEffect }?.let {
it.optionSet?.let { optionSetUid -> fetchOptions(it.uid, optionSetUid) }
val item = itemList.find { it.uid == fieldWithOptionEffect }

item?.let { field ->
field.optionSet?.let { optionSetUid ->
fetchOptions(field.uid, optionSetUid)
}
fieldsWithOptionEffects.add(field)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,28 @@ open class FormBaseConfiguration(private val d2: D2) {
.getPagingData(10)
}.map { pagingData ->
pagingData.filter { option ->
!optionsToHide.contains(option.uid()) &&
!optionGroupsToHide.contains(option.uid()) &&
(
optionGroupsToShow.isEmpty() ||
optionGroupsToShow.contains(option.uid())
)

val optionInGroupToHide = d2.optionModule().optionGroups()
.withOptions()
.byUid().`in`(optionGroupsToHide)
.blockingGet().find { optionGroup ->
optionGroup.options()?.map { it.uid() }?.contains(option.uid()) == true
} != null

val optionInGroupToShow = d2.optionModule().optionGroups()
.withOptions()
.byUid().`in`(optionGroupsToShow)
.blockingGet().find { optionGroup ->
optionGroup.options()?.map { it.uid() }?.contains(option.uid()) == true
} != null

val hideOption = if (optionGroupsToShow.isEmpty()) {
optionsToHide.contains(option.uid()) || optionInGroupToHide
} else {
!optionInGroupToShow
}

!hideOption
}
}
}
Expand Down

0 comments on commit 2ee4dbf

Please sign in to comment.