Skip to content

Commit

Permalink
Merge pull request #13015 from SORMAS-Foundation/bugfix-12661_checkbo…
Browse files Browse the repository at this point in the history
…x_tree_changes_cannot_be_discarded

#12661 - Checkbox trees don't trigger unsaved changes warning and can…
  • Loading branch information
sergiupacurariu authored Feb 27, 2024
2 parents 63e47c8 + 3aaffe5 commit a5da640
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 407 deletions.
97 changes: 15 additions & 82 deletions sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseDataForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -69,7 +66,6 @@
import com.vaadin.v7.ui.OptionGroup;
import com.vaadin.v7.ui.TextArea;
import com.vaadin.v7.ui.TextField;
import com.vaadin.v7.ui.VerticalLayout;

import de.symeda.sormas.api.CountryHelper;
import de.symeda.sormas.api.Disease;
Expand Down Expand Up @@ -129,7 +125,6 @@
import de.symeda.sormas.ui.ControllerProvider;
import de.symeda.sormas.ui.UiUtil;
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.caze.surveillancereport.CaseReinfectionCheckBoxTree;
import de.symeda.sormas.ui.clinicalcourse.HealthConditionsForm;
import de.symeda.sormas.ui.location.AccessibleTextField;
import de.symeda.sormas.ui.utils.AbstractEditForm;
Expand Down Expand Up @@ -216,10 +211,7 @@ public class CaseDataForm extends AbstractEditForm<CaseDataDto> {
fluidColumnLoc(3, 0, CaseDataDto.REINFECTION_STATUS),
fluidColumnLoc(4, 0, CaseDataDto.PREVIOUS_INFECTION_DATE)
) +
fluidRow(
fluidColumnLoc(6, 0, REINFECTION_DETAILS_COL_1_LOC),
fluidColumnLoc(6, 0, REINFECTION_DETAILS_COL_2_LOC)
) +
fluidRowLocs(CaseDataDto.REINFECTION_DETAILS) +
fluidRowLocs(9, CaseDataDto.OUTCOME, 3, CaseDataDto.OUTCOME_DATE) +
fluidRowLocs(3, CaseDataDto.SEQUELAE, 9, CaseDataDto.SEQUELAE_DETAILS) +
fluidRowLocs(CaseDataDto.CASE_IDENTIFICATION_SOURCE, CaseDataDto.SCREENING_TYPE) +
Expand Down Expand Up @@ -316,8 +308,6 @@ public class CaseDataForm extends AbstractEditForm<CaseDataDto> {
private FollowUpPeriodDto expectedFollowUpPeriodDto;
private boolean ignoreDifferentPlaceOfStayJurisdiction = false;

private final Map<ReinfectionDetailGroup, CaseReinfectionCheckBoxTree> reinfectionTrees = new EnumMap<>(ReinfectionDetailGroup.class);

public CaseDataForm(
String caseUuid,
PersonDto person,
Expand Down Expand Up @@ -644,40 +634,20 @@ protected void addFields() {
getContent().addComponent(reinfectionInfoLabel, REINFECTION_INFO_LOC);
reinfectionInfoLabel.setVisible(false);

final VerticalLayout reinfectionDetailsLeftLayout = new VerticalLayout();
CssStyles.style(reinfectionDetailsLeftLayout, CssStyles.VSPACE_3);
final VerticalLayout reinfectionDetailsRightLayout = new VerticalLayout();
CssStyles.style(reinfectionDetailsRightLayout, CssStyles.VSPACE_3);
for (ReinfectionDetailGroup group : ReinfectionDetailGroup.values()) {
CaseReinfectionCheckBoxTree reinfectionTree = new CaseReinfectionCheckBoxTree(
ReinfectionDetail.values(group).stream().map(e -> new CheckBoxTree.CheckBoxElement<>(null, e)).collect(Collectors.toList()),
() -> {
tfReinfectionStatus.setReadOnly(false);
tfReinfectionStatus.setValue(CaseLogic.calculateReinfectionStatus(mergeReinfectionTrees()));
tfReinfectionStatus.setReadOnly(true);
});
reinfectionTrees.put(group, reinfectionTree);
CheckBoxTree<ReinfectionDetail> reinfectionDetailGroupCheckBoxTree =
addField(CaseDataDto.REINFECTION_DETAILS, CheckBoxTree.class);
reinfectionDetailGroupCheckBoxTree
.setEnumType(ReinfectionDetail.class, ReinfectionDetail::getGroup, ReinfectionDetailGroup.class, 2);

if (StringUtils.isNotBlank(group.toString())) {
Label heading = new Label(group.toString());
CssStyles.style(heading, CssStyles.H4);
if (group.ordinal() < 2) {
reinfectionDetailsLeftLayout.addComponent(heading);
} else {
reinfectionDetailsRightLayout.addComponent(heading);
}
}
tfReinfectionStatus.setReadOnly(false);
tfReinfectionStatus.setValue(CaseLogic.calculateReinfectionStatus(reinfectionDetailGroupCheckBoxTree.getValue()));
tfReinfectionStatus.setReadOnly(true);

if (group.ordinal() < 2) {
reinfectionDetailsLeftLayout.addComponent(reinfectionTree);
} else {
reinfectionDetailsRightLayout.addComponent(reinfectionTree);
}
}
getContent().addComponent(reinfectionDetailsLeftLayout, REINFECTION_DETAILS_COL_1_LOC);
getContent().addComponent(reinfectionDetailsRightLayout, REINFECTION_DETAILS_COL_2_LOC);
reinfectionDetailsLeftLayout.setVisible(false);
reinfectionDetailsRightLayout.setVisible(false);
reinfectionDetailGroupCheckBoxTree.addValueChangeListener(e -> {
tfReinfectionStatus.setReadOnly(false);
tfReinfectionStatus.setValue(CaseLogic.calculateReinfectionStatus(reinfectionDetailGroupCheckBoxTree.getValue()));
tfReinfectionStatus.setReadOnly(true);
});

ogReinfection.addValueChangeListener(e -> {
if (((NullableOptionGroup) e.getProperty()).getNullableValue() == YesNoUnknown.YES) {
Expand Down Expand Up @@ -706,14 +676,11 @@ protected void addFields() {
reinfectionInfoLabel.setDescription(null);
reinfectionInfoLabel.setVisible(false);
}

reinfectionDetailsLeftLayout.setVisible(isVisibleAllowed(CaseDataDto.RE_INFECTION));
reinfectionDetailsRightLayout.setVisible(isVisibleAllowed(CaseDataDto.RE_INFECTION));
reinfectionDetailGroupCheckBoxTree.setVisible(isVisibleAllowed(CaseDataDto.RE_INFECTION));
} else {
reinfectionInfoLabel.setDescription(null);
reinfectionInfoLabel.setVisible(false);
reinfectionDetailsLeftLayout.setVisible(false);
reinfectionDetailsRightLayout.setVisible(false);
reinfectionDetailGroupCheckBoxTree.setVisible(false);
}
});
}
Expand Down Expand Up @@ -1415,9 +1382,6 @@ public String getFormattedHtmlMessage() {
.setInputPrompt(I18nProperties.getString(Strings.promptExternalIdExternalSurveillanceTool));
}

for (CaseReinfectionCheckBoxTree reinfectionTree : reinfectionTrees.values()) {
reinfectionTree.initCheckboxes();
}
});
}

Expand Down Expand Up @@ -1657,40 +1621,9 @@ private void updateFollowUpStatusComponents() {
}
}

private Map<ReinfectionDetail, Boolean> mergeReinfectionTrees() {
Map<ReinfectionDetail, Boolean> reinfectionDetails = new EnumMap<>(ReinfectionDetail.class);
reinfectionTrees.values().forEach(t -> {
if (t.getValues() != null) {
reinfectionDetails.putAll(t.getValues());
}
});
return reinfectionDetails;
}

@Override
public CaseDataDto getValue() {
final CaseDataDto caze = super.getValue();
caze.setReinfectionDetails(mergeReinfectionTrees());
return caze;
}

@Override
public void setValue(CaseDataDto newFieldValue) throws ReadOnlyException, ConversionException {

for (ReinfectionDetailGroup group : reinfectionTrees.keySet()) {
if (newFieldValue.getReinfectionDetails() != null) {
reinfectionTrees.get(group)
.setValues(
newFieldValue.getReinfectionDetails()
.entrySet()
.stream()
.filter(e -> e.getKey().getGroup() == group)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
} else {
reinfectionTrees.get(group).setValues(null);
}
}

super.setValue(newFieldValue);

ComboBox caseConfirmationBasisCombo = getField(CASE_CONFIRMATION_BASIS);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Map;

import com.vaadin.ui.Label;
import com.vaadin.v7.ui.ComboBox;
import com.vaadin.v7.ui.DateField;
import com.vaadin.v7.ui.TextArea;
import com.vaadin.v7.ui.TextField;
import com.vaadin.v7.ui.VerticalLayout;

import de.symeda.sormas.api.FacadeProvider;
import de.symeda.sormas.api.environment.EnvironmentDto;
Expand Down Expand Up @@ -45,7 +44,7 @@
public class EnvironmentDataForm extends AbstractEditForm<EnvironmentDto> {

private static final String LOCATION_HEADING_LOC = "locationHeadingLoc";
private static final String WATER_USE_LOC = "waterUseLoc";
private static final String WATER_USE_HEADING_LOC = "waterUseHeadingLoc";

//@formatter:off
private static final String HTML_LAYOUT = fluidRowLocs(EnvironmentDto.UUID, EnvironmentDto.EXTERNAL_ID) +
Expand All @@ -54,7 +53,7 @@ public class EnvironmentDataForm extends AbstractEditForm<EnvironmentDto> {
fluidRowLocs(EnvironmentDto.ENVIRONMENT_MEDIA, "") +
fluidRowLocs(EnvironmentDto.WATER_TYPE, EnvironmentDto.OTHER_WATER_TYPE) +
fluidRowLocs(EnvironmentDto.INFRASTUCTURE_DETAILS, EnvironmentDto.OTHER_INFRASTRUCTUIRE_DETAILS) +
fluidRowLocs(WATER_USE_LOC) +
fluidRowLocs(WATER_USE_HEADING_LOC) +
fluidRowLocs(EnvironmentDto.WATER_USE) +
fluidRowLocs(EnvironmentDto.OTHER_WATER_USE) +
fluidRowLocs(EnvironmentDto.ENVIRONMENT_NAME, "")+
Expand All @@ -66,8 +65,6 @@ public class EnvironmentDataForm extends AbstractEditForm<EnvironmentDto> {
fluidRowLocs(EnvironmentDto.OTHER_DELETION_REASON);
//@formatter:on

private WaterUseCheckBoxTree waterUseCheckBoxTree;

public EnvironmentDataForm(boolean isPseudonymized, boolean inJurisdiction, boolean isEditAllowed) {
super(
EnvironmentDto.class,
Expand Down Expand Up @@ -110,30 +107,26 @@ protected void addFields() {
TextField otherInfrastructureDetails = addField(EnvironmentDto.OTHER_INFRASTRUCTUIRE_DETAILS, TextField.class);
otherInfrastructureDetails.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));

final VerticalLayout useOfWaterLayout = new VerticalLayout();
CssStyles.style(useOfWaterLayout, CssStyles.VSPACE_3);

Label useOfWaterHeading = new Label(I18nProperties.getString(Strings.headingWaterUse));
CssStyles.style(useOfWaterHeading, CssStyles.LABEL_XLARGE, CssStyles.VSPACE_TOP_3);
useOfWaterLayout.addComponent(useOfWaterHeading);

getContent().addComponent(useOfWaterLayout, WATER_USE_LOC);
getContent().addComponent(useOfWaterHeading, WATER_USE_HEADING_LOC);

TextField otherWaterUse = addField(EnvironmentDto.OTHER_WATER_USE, TextField.class);
otherWaterUse.setInputPrompt(I18nProperties.getString(Strings.pleaseSpecify));

waterUseCheckBoxTree = new WaterUseCheckBoxTree(
Arrays.stream(WaterUse.values()).map(this::environmentEvidenceDetailToCheckBoxElement).collect(Collectors.toList()),
() -> {
if (isWaterUseOtherChecked()) {
CheckBoxTree<WaterUse> waterUseCheckBoxTree = addField(EnvironmentDto.WATER_USE, CheckBoxTree.class);
waterUseCheckBoxTree.setEnumType(WaterUse.class, null);

waterUseCheckBoxTree.addValueChangeListener((e) -> {
if (e.getProperty().getValue() != null) {
if (Boolean.TRUE.equals(((Map<WaterUse, Boolean>) e.getProperty().getValue()).get(WaterUse.OTHER))) {
otherWaterUse.setVisible(true);
} else {
otherWaterUse.setVisible(false);
otherWaterUse.clear();
}
});

useOfWaterLayout.addComponent(waterUseCheckBoxTree);
}
});

addField(EnvironmentDto.ENVIRONMENT_NAME, TextField.class);

Expand All @@ -153,7 +146,7 @@ protected void addFields() {
ComboBox districtField = (ComboBox) locationForm.getFieldGroup().getField(LocationDto.DISTRICT);

UserField responsibleUserField = addField(EnvironmentDto.RESPONSIBLE_USER, UserField.class);
responsibleUserField.setParentPseudonymizedSupplier(()-> getValue().isPseudonymized());
responsibleUserField.setParentPseudonymizedSupplier(() -> getValue().isPseudonymized());
responsibleUserField.setEnabled(true);

addField(EnvironmentDto.DELETION_REASON);
Expand Down Expand Up @@ -209,14 +202,19 @@ protected void addFields() {
if (EnvironmentMedia.WATER.equals(valueChangeEvent.getProperty().getValue())) {
waterType.setVisible(true);
infrastructureDetails.setVisible(true);
useOfWaterLayout.setVisible(true);
waterUseCheckBoxTree.setVisible(true);
useOfWaterHeading.setVisible(true);
} else {
useOfWaterHeading.setVisible(false);
waterType.setVisible(false);
infrastructureDetails.setVisible(false);
useOfWaterLayout.setVisible(false);
waterUseCheckBoxTree.setVisible(false);
otherWaterUse.setVisible(false);
waterType.clear();
infrastructureDetails.clear();
waterUseCheckBoxTree.clearCheckBoxTree();
waterUseCheckBoxTree.clear();
waterUseCheckBoxTree.clear();
otherWaterUse.clear();
}
});

Expand All @@ -229,29 +227,12 @@ protected void addFields() {
true);

addValueChangeListener(e -> {
waterUseCheckBoxTree.initCheckboxes();
otherWaterUse.setVisible(isWaterUseOtherChecked());
if (getValue().getWaterUse() != null && Boolean.TRUE.equals((getValue().getWaterUse().get(WaterUse.OTHER)))) {
otherWaterUse.setVisible(true);
} else {
otherWaterUse.setVisible(false);
otherWaterUse.clear();
}
});
}

private boolean isWaterUseOtherChecked() {
return Boolean.TRUE.equals(waterUseCheckBoxTree.getValues().get(WaterUse.OTHER));
}

private CheckBoxTree.CheckBoxElement<WaterUse> environmentEvidenceDetailToCheckBoxElement(WaterUse waterUse) {
return new CheckBoxTree.CheckBoxElement<>(null, waterUse);
}

@Override
public void setValue(EnvironmentDto newFieldValue) throws ReadOnlyException {
waterUseCheckBoxTree.setValues(newFieldValue.getWaterUse());
super.setValue(newFieldValue);
}

@Override
public EnvironmentDto getValue() {
final EnvironmentDto environmentDto = super.getValue();
environmentDto.setWaterUse(waterUseCheckBoxTree.getValues());
return environmentDto;
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit a5da640

Please sign in to comment.