Skip to content

Commit

Permalink
fix: [ANDROAPP-6187] Reloads forms when event details fields are upda…
Browse files Browse the repository at this point in the history
…ted when creating a new event (#3697)
  • Loading branch information
ferdyrod authored Jun 27, 2024
1 parent ce20719 commit 8cd2d4d
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.dhis2.commons.Constants.EVENT_MODE;
import static org.dhis2.commons.extensions.ViewExtensionsKt.closeKeyboard;
import static org.dhis2.form.data.EventRepository.EVENT_ORG_UNIT_UID;
import static org.dhis2.usescases.eventsWithoutRegistration.eventCapture.ui.NonEditableReasonBlockKt.showNonEditableReasonMessage;
import static org.dhis2.utils.granularsync.SyncStatusDialogNavigatorKt.OPEN_ERROR_LOCATION;

Expand All @@ -22,13 +23,15 @@
import org.dhis2.commons.featureconfig.data.FeatureConfigRepository;
import org.dhis2.commons.featureconfig.model.Feature;
import org.dhis2.databinding.SectionSelectorFragmentBinding;
import org.dhis2.form.model.ActionType;
import org.dhis2.form.model.EventMode;
import org.dhis2.form.model.EventRecords;
import org.dhis2.form.ui.FormView;
import org.dhis2.usescases.eventsWithoutRegistration.eventCapture.EventCaptureAction;
import org.dhis2.usescases.eventsWithoutRegistration.eventCapture.EventCaptureActivity;
import org.dhis2.usescases.eventsWithoutRegistration.eventCapture.EventCaptureContract;
import org.dhis2.usescases.general.FragmentGlobalAbstract;
import org.hisp.dhis.android.core.common.ValueType;
import org.jetbrains.annotations.NotNull;

import javax.inject.Inject;
Expand Down Expand Up @@ -78,6 +81,13 @@ public void onAttach(@NotNull Context context) {
public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
String eventUid = getArguments().getString(Constants.EVENT_UID, "");
EventMode eventMode = EventMode.valueOf(getArguments().getString(EVENT_MODE));
loadForm(eventUid, eventMode);

activity.setFormEditionListener(this);
super.onCreate(savedInstanceState);
}

private void loadForm(String eventUid, EventMode eventMode) {
formView = new FormView.Builder()
.locationProvider(locationProvider)
.onLoadingListener(loading -> {
Expand All @@ -87,6 +97,12 @@ public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedI
activity.hideProgress();
}
return Unit.INSTANCE;
}).onItemChangeListener( action -> {
if(action.isEventDetailsRow()){
presenter.showOrHideSaveButton();
}
return Unit.INSTANCE;

})
.onFocused(() -> {
activity.hideNavigationBar();
Expand All @@ -107,8 +123,6 @@ public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedI
featureConfig.isFeatureEnable(Feature.COMPOSE_FORMS)
)
.build();
activity.setFormEditionListener(this);
super.onCreate(savedInstanceState);
}

@Nullable
Expand Down Expand Up @@ -190,6 +204,8 @@ public void onReopen() {

@Override
public void showNonEditableMessage(@NonNull String reason, boolean canBeReOpened) {
binding.editableReasonContainer.setVisibility(View.VISIBLE);

showNonEditableReasonMessage(
binding.editableReasonContainer,
reason,
Expand All @@ -203,6 +219,6 @@ public void showNonEditableMessage(@NonNull String reason, boolean canBeReOpened

@Override
public void hideNonEditableMessage() {
binding.editableReasonContainer.removeAllViews();
binding.editableReasonContainer.setVisibility(View.GONE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class EventCaptureFormPresenter(
when (isEditable) {
is EventEditableStatus.Editable -> {
view.showSaveButton()
view.hideNonEditableMessage()
}

is EventEditableStatus.NonEditable -> {
Expand Down
16 changes: 7 additions & 9 deletions form/src/main/java/org/dhis2/form/data/EventRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ class EventRepository(
private val eventMode: EventMode,
) : DataEntryBaseRepository(FormBaseConfiguration(d2), fieldFactory) {

private val event by lazy {
d2.eventModule().events().uid(eventUid)
.blockingGet()
}
private var event = d2.eventModule().events().uid(eventUid).blockingGet()

private val programStage by lazy {
d2.programModule()
Expand Down Expand Up @@ -139,7 +136,7 @@ class EventRepository(

override fun list(): Flowable<List<FieldUiModel>> {
return d2.programModule().programStageSections()
.byProgramStageUid().eq(event?.programStage())
.byProgramStageUid().eq(programStage?.uid())
.withDataElements()
.get()
.flatMap { programStageSection ->
Expand Down Expand Up @@ -167,7 +164,7 @@ class EventRepository(
sectionUid = EVENT_DATA_SECTION_UID,
sectionName = resources.formatWithEventLabel(
stringResource = R.string.event_data_section_title,
programStageUid = event?.programStage(),
programStageUid = programStage?.uid(),
),
description = null,
isOpen = true,
Expand All @@ -183,6 +180,7 @@ class EventRepository(
}

private fun getEventDetails(): MutableList<FieldUiModel> {
event = d2.eventModule().events().uid(eventUid).blockingGet()
val eventDataItems = mutableListOf<FieldUiModel>()
eventDataItems.apply {
add(createEventDetailsSection())
Expand Down Expand Up @@ -459,7 +457,7 @@ class EventRepository(
sectionUid = EVENT_DETAILS_SECTION_UID,
sectionName = resources.formatWithEventLabel(
stringResource = R.string.event_details_section_title,
programStageUid = event?.programStage(),
programStageUid = programStage?.uid(),
),
description = programStage?.description(),
isOpen = false,
Expand Down Expand Up @@ -487,7 +485,7 @@ class EventRepository(
return Single.fromCallable {
val stageDataElements =
d2.programModule().programStageDataElements().withRenderType()
.byProgramStage().eq(event?.programStage())
.byProgramStage().eq(programStage?.uid())
.orderBySortOrder(RepositoryScope.OrderByDirection.ASC)
.blockingGet()

Expand All @@ -510,7 +508,7 @@ class EventRepository(
)
programStageSection.dataElements()?.forEach { dataElement ->
d2.programModule().programStageDataElements().withRenderType()
.byProgramStage().eq(event?.programStage())
.byProgramStage().eq(programStage?.uid())
.byDataElement().eq(dataElement.uid())
.one().blockingGet()?.let {
fields.add(
Expand Down
1 change: 1 addition & 0 deletions form/src/main/java/org/dhis2/form/model/RowAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ data class RowAction(
val error: Throwable? = null,
val type: ActionType,
val valueType: ValueType? = null,
val isEventDetailsRow: Boolean = false,
)
Loading

0 comments on commit 8cd2d4d

Please sign in to comment.