Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit 6f5c95c

Browse files
SORMAS-Foundation#2943 fix Adjust Quarantine popup always appearing
1 parent e0acea4 commit 6f5c95c

2 files changed

Lines changed: 50 additions & 24 deletions

File tree

sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseDataForm.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ protected void addFields() {
523523
addField(CaseDataDto.FOLLOW_UP_STATUS, ComboBox.class);
524524
addField(CaseDataDto.FOLLOW_UP_COMMENT, TextArea.class).setRows(1);
525525
dfFollowUpUntil = addDateField(CaseDataDto.FOLLOW_UP_UNTIL, DateField.class, -1);
526-
dfFollowUpUntil.addValueChangeListener(v -> onFollowUpUntilChanged(v, quarantineTo, quarantineExtended));
526+
dfFollowUpUntil.addValueChangeListener(v -> onFollowUpUntilChanged(v, quarantineTo, quarantineExtended, quarantineReduced));
527527
addField(CaseDataDto.OVERWRITE_FOLLOW_UP_UNTIL, CheckBox.class);
528528

529529
setReadOnly(true, CaseDataDto.FOLLOW_UP_STATUS);
@@ -910,10 +910,13 @@ protected void addFields() {
910910
});
911911
}
912912

913-
private void onFollowUpUntilChanged(Property.ValueChangeEvent valueChangeEvent, DateField quarantineTo, CheckBox quarantineExtendedCheckBox) {
913+
private void onFollowUpUntilChanged(Property.ValueChangeEvent valueChangeEvent, DateField quarantineTo, CheckBox quarantineExtendedCheckBox, CheckBox quarantineReducedCheckBox) {
914914
Property<Date> followUpUntilField = valueChangeEvent.getProperty();
915-
Date followUpUntil = followUpUntilField.getValue();
916-
if (quarantineTo.getValue() != null && (followUpUntil == null || followUpUntil.compareTo(quarantineTo.getValue()) != 0)) {
915+
Date newFollowUpUntil = followUpUntilField.getValue();
916+
CaseDataDto originalCase = getInternalValue();
917+
Date oldFollowUpUntil = originalCase.getFollowUpUntil();
918+
Date oldQuarantineEnd = originalCase.getQuarantineTo();
919+
if (adjustQuarantine(quarantineTo, newFollowUpUntil, oldFollowUpUntil)) {
917920
VaadinUiUtil.showConfirmationPopup(
918921
I18nProperties.getString(Strings.headingExtendQuarantine),
919922
new Label(I18nProperties.getString(Strings.confirmationAlsoExtendQuarantine)),
@@ -923,15 +926,25 @@ private void onFollowUpUntilChanged(Property.ValueChangeEvent valueChangeEvent,
923926
confirmed -> {
924927
if (confirmed) {
925928
quarantineChangedByFollowUpUntilChange = true;
926-
quarantineTo.setValue(followUpUntil);
927-
if (followUpUntil.after(getInternalValue().getFollowUpUntil())) {
928-
quarantineExtendedCheckBox.setValue(true);
929+
quarantineTo.setValue(newFollowUpUntil);
930+
if (oldQuarantineEnd != null) {
931+
boolean quarantineExtended = newFollowUpUntil.after(oldQuarantineEnd);
932+
quarantineExtendedCheckBox.setValue(quarantineExtended);
933+
quarantineReducedCheckBox.setValue(!quarantineExtended);
934+
setVisible(quarantineExtended, CaseDataDto.QUARANTINE_EXTENDED);
935+
setVisible(!quarantineExtended, CaseDataDto.QUARANTINE_REDUCED);
929936
}
930937
}
931938
});
932939
}
933940
}
934941

942+
private boolean adjustQuarantine(DateField quarantineTo, Date newFollowUpUntil, Date oldFollowUpUntil) {
943+
return newFollowUpUntil != null &&
944+
(oldFollowUpUntil == null || newFollowUpUntil.after(oldFollowUpUntil)) &&
945+
quarantineTo.getValue() != null && newFollowUpUntil.compareTo(quarantineTo.getValue()) != 0;
946+
}
947+
935948
private void onQuarantineEndChange(Property.ValueChangeEvent valueChangeEvent, CheckBox quarantineExtendedCheckBox, CheckBox quarantineReducedCheckBox, DateField followUpUntilField) {
936949
if (quarantineChangedByFollowUpUntilChange) {
937950
quarantineChangedByFollowUpUntilChange = false;

sormas-ui/src/main/java/de/symeda/sormas/ui/contact/ContactDataForm.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ protected void addFields() {
332332
addField(ContactDto.FOLLOW_UP_STATUS, ComboBox.class);
333333
addField(ContactDto.FOLLOW_UP_COMMENT, TextArea.class).setRows(1);
334334
DateField dfFollowUpUntil = addDateField(ContactDto.FOLLOW_UP_UNTIL, DateField.class, -1);
335+
dfFollowUpUntil.addValueChangeListener(v -> onFollowUpUntilChanged(v, quarantineTo, quarantineExtended, quarantineReduced));
335336
quarantineTo.addValueChangeListener(e -> onQuarantineEndChange(e, quarantineExtended, quarantineReduced, dfFollowUpUntil));
336337
this.addValueChangeListener(e -> onValueChange());
337338

@@ -489,7 +490,6 @@ protected void addFields() {
489490
minimumFollowUpUntilDate,
490491
null,
491492
Resolution.DAY));
492-
dfFollowUpUntil.addValueChangeListener(v -> onFollowUpUntilChanged(v, quarantineTo, quarantineExtended));
493493
}
494494

495495
// Overwrite visibility for quarantine fields
@@ -654,28 +654,41 @@ protected String createHtmlLayout() {
654654
return HTML_LAYOUT;
655655
}
656656

657-
private void onFollowUpUntilChanged(Property.ValueChangeEvent valueChangeEvent, DateField quarantineTo, CheckBox quarantineExtendedCheckBox) {
657+
private void onFollowUpUntilChanged(Property.ValueChangeEvent valueChangeEvent, DateField quarantineTo, CheckBox quarantineExtendedCheckBox, CheckBox quarantineReducedCheckBox) {
658658
Property<Date> followUpUntilField = valueChangeEvent.getProperty();
659-
Date followUpUntil = followUpUntilField.getValue();
660-
if (quarantineTo.getValue() != null && (followUpUntil == null || followUpUntil.compareTo(quarantineTo.getValue()) != 0)) {
659+
Date newFollowUpUntil = followUpUntilField.getValue();
660+
ContactDto originalContact = getInternalValue();
661+
Date oldFollowUpUntil = originalContact.getFollowUpUntil();
662+
Date oldQuarantineEnd = originalContact.getQuarantineTo();
663+
if (adjustQuarantine(quarantineTo, newFollowUpUntil, oldFollowUpUntil)) {
661664
VaadinUiUtil.showConfirmationPopup(
662-
I18nProperties.getString(Strings.headingExtendQuarantine),
663-
new Label(I18nProperties.getString(Strings.confirmationAlsoExtendQuarantine)),
664-
I18nProperties.getString(Strings.yes),
665-
I18nProperties.getString(Strings.no),
666-
640,
667-
confirmed -> {
668-
if (confirmed) {
669-
quarantineChangedByFollowUpUntilChange = true;
670-
quarantineTo.setValue(followUpUntil);
671-
if (followUpUntil.after(getInternalValue().getFollowUpUntil())) {
672-
quarantineExtendedCheckBox.setValue(true);
673-
}
665+
I18nProperties.getString(Strings.headingExtendQuarantine),
666+
new Label(I18nProperties.getString(Strings.confirmationAlsoExtendQuarantine)),
667+
I18nProperties.getString(Strings.yes),
668+
I18nProperties.getString(Strings.no),
669+
640,
670+
confirmed -> {
671+
if (confirmed) {
672+
quarantineChangedByFollowUpUntilChange = true;
673+
quarantineTo.setValue(newFollowUpUntil);
674+
if (oldQuarantineEnd != null) {
675+
boolean quarantineExtended = newFollowUpUntil.after(oldQuarantineEnd);
676+
quarantineExtendedCheckBox.setValue(quarantineExtended);
677+
quarantineReducedCheckBox.setValue(!quarantineExtended);
678+
setVisible(quarantineExtended, ContactDto.QUARANTINE_EXTENDED);
679+
setVisible(!quarantineExtended, ContactDto.QUARANTINE_REDUCED);
674680
}
675-
});
681+
}
682+
});
676683
}
677684
}
678685

686+
private boolean adjustQuarantine(DateField quarantineTo, Date newFollowUpUntil, Date oldFollowUpUntil) {
687+
return newFollowUpUntil != null &&
688+
(oldFollowUpUntil == null || newFollowUpUntil.after(oldFollowUpUntil)) &&
689+
quarantineTo.getValue() != null && newFollowUpUntil.compareTo(quarantineTo.getValue()) != 0;
690+
}
691+
679692
private void onQuarantineEndChange(Property.ValueChangeEvent valueChangeEvent, CheckBox quarantineExtendedCheckBox, CheckBox quarantineReducedCheckBox, DateField followUpUntilField) {
680693
if (quarantineChangedByFollowUpUntilChange) {
681694
quarantineChangedByFollowUpUntilChange = false;

0 commit comments

Comments
 (0)