Skip to content

Commit

Permalink
#12810 Hide jurisdiction-related filters and columns if the HIDE_JURI…
Browse files Browse the repository at this point in the history
…SDICTION_FIELDS feature is enabled
  • Loading branch information
Levente Gal committed Jan 16, 2024
1 parent dd4cd71 commit 0479b2a
Show file tree
Hide file tree
Showing 44 changed files with 308 additions and 126 deletions.
6 changes: 5 additions & 1 deletion sormas-ui/src/main/java/de/symeda/sormas/ui/UiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public static boolean permitted(UserRight userRight) {
}

public static boolean enabled(FeatureType featureType) {
return !FacadeProvider.getFeatureConfigurationFacade().isFeatureDisabled(featureType);
return !disabled(featureType);
}

public static boolean disabled(FeatureType featureType) {
return FacadeProvider.getFeatureConfigurationFacade().isFeatureDisabled(featureType);
}

public static boolean enabled(Set<FeatureType> features) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ public class CampaignFormDataFilterForm extends AbstractFilterForm<CampaignFormD

private Consumer<CampaignFormMetaReferenceDto> formMetaChangedCallback;
private ComboBox cbCampaignForm;
private ComboBox regionFilter;
private ComboBox districtFilter;
private ComboBox communityFilter;

protected CampaignFormDataFilterForm() {

super(CampaignFormDataCriteria.class, CampaignFormDataDto.I18N_PREFIX);
super(
CampaignFormDataCriteria.class,
CampaignFormDataDto.I18N_PREFIX,
JurisdictionFieldConfig
.of(CampaignFormDataCriteria.REGION, CampaignFormDataCriteria.DISTRICT, CampaignFormDataCriteria.COMMUNITY));
formActionButtonsComponent.style(CssStyles.FORCE_CAPTION);
formActionButtonsComponent.setSpacing(false);
formActionButtonsComponent.setSizeFull();
Expand Down Expand Up @@ -84,17 +85,17 @@ protected void addFields() {
});
}

regionFilter = addField(
ComboBox regionFilter = addField(
FieldConfiguration.withCaptionAndPixelSized(CampaignFormDataCriteria.REGION, I18nProperties.getCaption(Captions.Campaign_region), 200));
regionFilter.setInputPrompt(I18nProperties.getString(Strings.promptAllRegions));
regionFilter.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());

districtFilter = addField(
ComboBox districtFilter = addField(
FieldConfiguration
.withCaptionAndPixelSized(CampaignFormDataCriteria.DISTRICT, I18nProperties.getCaption(Captions.Campaign_district), 200));
districtFilter.setInputPrompt(I18nProperties.getString(Strings.promptAllDistricts));

communityFilter = addField(
ComboBox communityFilter = addField(
FieldConfiguration
.withCaptionAndPixelSized(CampaignFormDataCriteria.COMMUNITY, I18nProperties.getCaption(Captions.Campaign_community), 200));
communityFilter.setInputPrompt(I18nProperties.getString(Strings.promptAllCommunities));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ public class CampaignStatisticsFilterForm extends AbstractFilterForm<CampaignSta

private Consumer<CampaignFormMetaReferenceDto> formMetaChangedCallback;
private ComboBox cbCampaignForm;
private ComboBox regionFilter;
private ComboBox districtFilter;
private ComboBox communityFilter;

protected CampaignStatisticsFilterForm() {

super(CampaignStatisticsCriteria.class, CampaignStatisticsDto.I18N_PREFIX);
super(
CampaignStatisticsCriteria.class,
CampaignStatisticsDto.I18N_PREFIX,
JurisdictionFieldConfig
.of(CampaignStatisticsCriteria.REGION, CampaignStatisticsCriteria.DISTRICT, CampaignStatisticsCriteria.COMMUNITY));
formActionButtonsComponent.style(CssStyles.FORCE_CAPTION);
formActionButtonsComponent.setSpacing(false);
formActionButtonsComponent.setSizeFull();
Expand Down Expand Up @@ -68,17 +69,17 @@ protected void addFields() {
});
}

regionFilter = addField(
ComboBox regionFilter = addField(
FieldConfiguration.withCaptionAndPixelSized(CampaignStatisticsCriteria.REGION, I18nProperties.getCaption(Captions.Campaign_region), 200));
regionFilter.setInputPrompt(I18nProperties.getString(Strings.promptAllRegions));
regionFilter.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());

districtFilter = addField(
ComboBox districtFilter = addField(
FieldConfiguration
.withCaptionAndPixelSized(CampaignStatisticsCriteria.DISTRICT, I18nProperties.getCaption(Captions.Campaign_district), 200));
districtFilter.setInputPrompt(I18nProperties.getString(Strings.promptAllDistricts));

communityFilter = addField(
ComboBox communityFilter = addField(
FieldConfiguration
.withCaptionAndPixelSized(CampaignStatisticsCriteria.COMMUNITY, I18nProperties.getCaption(Captions.Campaign_community), 200));
communityFilter.setInputPrompt(I18nProperties.getString(Strings.promptAllCommunities));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import de.symeda.sormas.api.contact.ContactIndexDto;
import de.symeda.sormas.api.contact.FollowUpStatus;
import de.symeda.sormas.api.feature.FeatureType;
import de.symeda.sormas.api.followup.FollowUpLogic;
import de.symeda.sormas.api.i18n.Captions;
import de.symeda.sormas.api.i18n.I18nProperties;
import de.symeda.sormas.api.location.LocationDto;
Expand All @@ -45,6 +44,7 @@
import de.symeda.sormas.api.utils.DateHelper;
import de.symeda.sormas.api.utils.SortProperty;
import de.symeda.sormas.ui.ControllerProvider;
import de.symeda.sormas.ui.UiUtil;
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.ViewModelProviders;
import de.symeda.sormas.ui.utils.CssStyles;
Expand Down Expand Up @@ -105,7 +105,7 @@ protected void initColumns() {
Column<IndexDto, String> visitsColumn = addColumn(entry -> {
Integer numberOfVisits = entry.getVisitCount();
Integer numberOfMissedVisits = entry.getMissedVisitsCount();
if (numberOfVisits != null && numberOfMissedVisits != null ) {
if (numberOfVisits != null && numberOfMissedVisits != null) {
return String.format(I18nProperties.getCaption(Captions.formatNumberOfVisitsFormat), numberOfVisits, numberOfMissedVisits);
} else {
return "-";
Expand Down Expand Up @@ -200,6 +200,10 @@ protected void initColumns() {
LocationDto.I18N_PREFIX));
column.setStyleGenerator(FieldAccessColumnStyleGenerator.getDefault(getBeanType(), column.getId()));
}

if (UiUtil.enabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
getColumn(CaseIndexDto.RESPONSIBLE_DISTRICT_NAME).setHidden(true);
}
}

protected Stream<String> getGridColumns() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import de.symeda.sormas.api.user.JurisdictionLevel;
import de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers;
import de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers;
import de.symeda.sormas.ui.UiUtil;
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.location.LocationEditForm;
import de.symeda.sormas.ui.person.PersonCreateForm;
Expand Down Expand Up @@ -714,7 +715,7 @@ public void setValue(CaseDataDto caseDataDto) throws com.vaadin.v7.data.Property
PersonDto personByUuid = personUuid == null ? null : FacadeProvider.getPersonFacade().getByUuid(personUuid);
personCreateForm.setPerson(personByUuid);

if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
if (UiUtil.enabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
hideAndFillJurisdictionFields();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
import de.symeda.sormas.api.utils.fieldvisibility.checkers.CountryFieldVisibilityChecker;
import de.symeda.sormas.api.utils.fieldvisibility.checkers.UserRightFieldVisibilityChecker;
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;
Expand Down Expand Up @@ -1416,7 +1417,7 @@ public String getFormattedHtmlMessage() {
}
});

if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
if (UiUtil.enabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
hideJurisdictionFields();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ public class CaseFilterForm extends AbstractFilterForm<CaseCriteria> {
+ loc(WEEK_AND_DATE_FILTER);

protected CaseFilterForm() {
super(CaseCriteria.class, CaseDataDto.I18N_PREFIX, FieldVisibilityCheckers.withCountry(FacadeProvider.getConfigFacade().getCountryLocale()));
super(
CaseCriteria.class,
CaseDataDto.I18N_PREFIX,
FieldVisibilityCheckers.withCountry(FacadeProvider.getConfigFacade().getCountryLocale()),
JurisdictionFieldConfig.withPrefillOnHide(CaseDataDto.REGION, CaseDataDto.DISTRICT, CaseDataDto.COMMUNITY));
}

@Override
Expand Down Expand Up @@ -345,7 +349,8 @@ public void addMoreFilters(CustomLayout moreFiltersContainer) {
CaseCriteria.ONLY_CASES_WITH_EVENTS,
I18nProperties.getCaption(Captions.caseFilterRelatedToEvent),
I18nProperties.getDescription(Descriptions.descCaseFilterRelatedToEvent),
CssStyles.CHECKBOX_FILTER_INLINE)).setVisible(UiUtil.permitted(UserRight.EVENT_VIEW));
CssStyles.CHECKBOX_FILTER_INLINE))
.setVisible(UiUtil.permitted(UserRight.EVENT_VIEW));

addField(
moreFiltersContainer,
Expand Down Expand Up @@ -436,9 +441,6 @@ protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueC

final CaseCriteria criteria = getValue();

final ComboBox regionField = getField(CaseDataDto.REGION);
final ComboBox districtField = getField(CaseDataDto.DISTRICT);
final ComboBox communityField = getField(CaseDataDto.COMMUNITY);
final ComboBox facilityTypeGroupField = getField(CaseCriteria.FACILITY_TYPE_GROUP);
final ComboBox facilityTypeField = getField(CaseCriteria.FACILITY_TYPE);
final ComboBox facilityField = getField(CaseDataDto.HEALTH_FACILITY);
Expand All @@ -447,7 +449,7 @@ protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueC

final UserDto user = currentUserDto();
final DistrictReferenceDto currentDistrict =
user.getDistrict() != null ? user.getDistrict() : (DistrictReferenceDto) districtField.getValue();
user.getDistrict() != null ? user.getDistrict() : (DistrictReferenceDto) districtFilter.getValue();
final CaseOrigin currentCaseOrigin =
caseOriginField != null ? (CaseOrigin) getField(CaseDataDto.CASE_ORIGIN).getValue() : CaseOrigin.POINT_OF_ENTRY;

Expand All @@ -459,15 +461,15 @@ protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueC
final ComboBox officerField = getField(CaseDataDto.SURVEILLANCE_OFFICER);
officerField.removeAllItems();
if (region != null) {
enableFields(districtField);
FieldHelper.updateItems(districtField, FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
enableFields(districtFilter);
FieldHelper.updateItems(districtFilter, FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));

disableFields(pointOfEntryField);
clearAndDisableFields(communityField, facilityField, facilityTypeField, facilityTypeGroupField);
clearAndDisableFields(communityFilter, facilityField, facilityTypeField, facilityTypeGroupField);

addOfficers(officerField, region);
} else {
clearAndDisableFields(districtField, communityField, facilityField, facilityTypeField, facilityTypeGroupField);
clearAndDisableFields(districtFilter, communityFilter, facilityField, facilityTypeField, facilityTypeGroupField);
disableFields(pointOfEntryField);
addOfficers(officerField, user.getRegion());
}
Expand All @@ -482,7 +484,7 @@ protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueC
final ComboBox officerField = getField(CaseDataDto.SURVEILLANCE_OFFICER);
officerField.removeAllItems();
if (newDistrict != null) {
enableFields(communityField, facilityTypeGroupField);
enableFields(communityFilter, facilityTypeGroupField);

clearAndDisableFields(facilityField);
if (facilityTypeGroupField != null) {
Expand All @@ -497,7 +499,7 @@ protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueC
}
}

FieldHelper.updateItems(communityField, FacadeProvider.getCommunityFacade().getAllActiveByDistrict(newDistrict.getUuid()));
FieldHelper.updateItems(communityFilter, FacadeProvider.getCommunityFacade().getAllActiveByDistrict(newDistrict.getUuid()));

if (pointOfEntryField != null && currentCaseOrigin == CaseOrigin.POINT_OF_ENTRY) {
pointOfEntryField.setEnabled(true);
Expand All @@ -509,9 +511,9 @@ protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueC
officerField
.addItems(FacadeProvider.getUserFacade().getUserRefsByDistrict(newDistrict, selectedDisease, UserRight.CASE_RESPONSIBLE));
} else {
clearAndDisableFields(communityField, pointOfEntryField, facilityField, facilityTypeField, facilityTypeGroupField);
clearAndDisableFields(communityFilter, pointOfEntryField, facilityField, facilityTypeField, facilityTypeGroupField);

final RegionReferenceDto region = regionField != null ? (RegionReferenceDto) regionField.getValue() : null;
final RegionReferenceDto region = regionFilter != null ? (RegionReferenceDto) regionFilter.getValue() : null;
addOfficers(officerField, region != null ? region : user.getRegion());
}
}
Expand Down Expand Up @@ -566,7 +568,7 @@ protected void applyDependenciesOnFieldChange(String propertyId, Property.ValueC
enableFields(facilityField);
facilityField.setValue(null);

CommunityReferenceDto community = (CommunityReferenceDto) communityField.getValue();
CommunityReferenceDto community = (CommunityReferenceDto) communityFilter.getValue();
if (community != null) {
FieldHelper.updateItems(
facilityField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.symeda.sormas.api.caze.CaseCriteria;
import de.symeda.sormas.api.caze.CaseIndexDetailedDto;
import de.symeda.sormas.api.caze.CaseIndexDto;
import de.symeda.sormas.api.feature.FeatureType;
import de.symeda.sormas.api.i18n.I18nProperties;
import de.symeda.sormas.api.person.PersonHelper;
import de.symeda.sormas.api.symptoms.SymptomsDto;
Expand Down Expand Up @@ -153,5 +154,10 @@ protected void initColumns() {
.setRenderer(new DateRenderer(DateFormatHelper.getDateFormat()))
.setCaption(I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ONSET_DATE))
.setWidth(80);

if (UiUtil.enabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
getColumn(CaseIndexDetailedDto.RESPONSIBLE_REGION).setHidden(true);
getColumn(CaseIndexDetailedDto.RESPONSIBLE_COMMUNITY).setHidden(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import de.symeda.sormas.api.Disease;
import de.symeda.sormas.api.FacadeProvider;
import de.symeda.sormas.api.caze.CaseDataDto;
import de.symeda.sormas.api.feature.FeatureType;
import de.symeda.sormas.api.i18n.Captions;
import de.symeda.sormas.api.i18n.I18nProperties;
import de.symeda.sormas.api.i18n.Strings;
Expand All @@ -41,6 +42,7 @@
import de.symeda.sormas.api.user.UserRight;
import de.symeda.sormas.api.utils.UtilDate;
import de.symeda.sormas.api.utils.ValidationRuntimeException;
import de.symeda.sormas.ui.UiUtil;
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.utils.ButtonHelper;
import de.symeda.sormas.ui.utils.CssStyles;
Expand Down Expand Up @@ -101,7 +103,6 @@ public LineListingLayout(Window window) {
district = new ComboBox<>(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.RESPONSIBLE_DISTRICT));
district.setItemCaptionGenerator(item -> item.buildCaption());
district.setId("lineListingDistrict");
district.addValueChangeListener(e -> setEpidNumberPrefixes());
sharedInformationBar.addComponent(district);

typeGroup = new ComboBox<>(I18nProperties.getCaption(Captions.Facility_typeGroup));
Expand Down Expand Up @@ -160,6 +161,13 @@ public LineListingLayout(Window window) {
region.setItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
}

if (UiUtil.enabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
region.setVisible(false);
region.setValue(FacadeProvider.getRegionFacade().getDefaultInfrastructureReference());
district.setVisible(false);
district.setValue(FacadeProvider.getDistrictFacade().getDefaultInfrastructureReference());
}

HorizontalLayout actionBar = new HorizontalLayout();
Button addLine = ButtonHelper.createIconButton(Captions.lineListingAddLine, VaadinIcons.PLUS, e -> {
CaseLineLayout newLine = buildNewLine(lineComponent);
Expand Down Expand Up @@ -488,6 +496,11 @@ public CaseLineLayout(int lineIndex) {
} else {
formatAsOtherLine();
}

if (UiUtil.enabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
community.setVisible(false);
community.setValue(FacadeProvider.getCommunityFacade().getDefaultInfrastructureReference());
}
}

public void setBean(CaseLineDto bean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import de.symeda.sormas.api.infrastructure.community.CommunityDto;
import de.symeda.sormas.api.user.UserRight;
import de.symeda.sormas.ui.ControllerProvider;
import de.symeda.sormas.ui.UiUtil;
import de.symeda.sormas.ui.UserProvider;
import de.symeda.sormas.ui.ViewModelProviders;
import de.symeda.sormas.ui.utils.BooleanRenderer;
Expand Down Expand Up @@ -56,7 +57,7 @@ public CommunitiesGrid(CommunityCriteria criteria) {
CommunityDto.REGION,
CommunityDto.DISTRICT,
CommunityDto.EXTERNAL_ID };
if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
if (UiUtil.enabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
columns = ArrayUtils.add(columns, CommunityDto.DEFAULT_INFRASTRUCTURE);
}
setColumns(columns);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto;
import de.symeda.sormas.api.infrastructure.region.RegionDto;
import de.symeda.sormas.api.infrastructure.region.RegionReferenceDto;
import de.symeda.sormas.ui.UiUtil;
import de.symeda.sormas.ui.utils.AbstractEditForm;
import de.symeda.sormas.ui.utils.FieldHelper;

Expand Down Expand Up @@ -67,7 +68,7 @@ protected void addFields() {
ComboBox district = addInfrastructureField(CommunityDto.DISTRICT);
addField(RegionDto.EXTERNAL_ID, TextField.class);

if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
if (UiUtil.enabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
addField(InfrastructureDtoWithDefault.DEFAULT_INFRASTRUCTURE, CheckBox.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import de.symeda.sormas.api.infrastructure.InfrastructureDtoWithDefault;
import de.symeda.sormas.api.infrastructure.district.DistrictDto;
import de.symeda.sormas.api.infrastructure.region.RegionDto;
import de.symeda.sormas.ui.UiUtil;
import de.symeda.sormas.ui.utils.AbstractEditForm;

public class DistrictEditForm extends AbstractEditForm<DistrictDto> {
Expand Down Expand Up @@ -62,7 +63,7 @@ protected void addFields() {
ComboBox region = addInfrastructureField(DistrictDto.REGION);
addField(RegionDto.EXTERNAL_ID, TextField.class);

if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
if (UiUtil.enabled(FeatureType.HIDE_JURISDICTION_FIELDS)) {
addField(InfrastructureDtoWithDefault.DEFAULT_INFRASTRUCTURE, CheckBox.class);
}

Expand Down
Loading

0 comments on commit 0479b2a

Please sign in to comment.