use of de.symeda.sormas.api.utils.DateFilterOption in project SORMAS-Project by hzi-braunschweig.
the class EventSelectionField method buildWeekAndDateFilter.
public HorizontalLayout buildWeekAndDateFilter() {
applyButton = ButtonHelper.createButton(Captions.actionApplyDateFilter, null);
weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(false, false, null, null);
weekAndDateFilter.getWeekFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventEpiWeekFrom));
weekAndDateFilter.getWeekToFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventEpiWeekTo));
weekAndDateFilter.getDateFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventDateFrom));
weekAndDateFilter.getDateToFilter().setInputPrompt(I18nProperties.getString(Strings.promptEventDateTo));
applyButton.addClickListener(e -> {
DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue();
Date fromDate = null;
Date toDate = null;
if (dateFilterOption == DateFilterOption.DATE) {
if (weekAndDateFilter.getDateFromFilter().getValue() != null) {
fromDate = DateHelper.getStartOfDay(weekAndDateFilter.getDateFromFilter().getValue());
}
if (weekAndDateFilter.getDateToFilter().getValue() != null) {
toDate = DateHelper.getEndOfDay(weekAndDateFilter.getDateToFilter().getValue());
}
} else {
fromDate = DateHelper.getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue());
toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue());
}
if (setDefaultFilters != null) {
EventCriteria defaultCriteria = new EventCriteria();
setDefaultFilters.accept(defaultCriteria);
fromDate = fromDate == null ? defaultCriteria.getEventDateFrom() : fromDate;
toDate = toDate == null ? defaultCriteria.getEventDateTo() : toDate;
}
applyButton.removeStyleName(ValoTheme.BUTTON_PRIMARY);
criteria.eventDateBetween(fromDate, toDate, EventCriteriaDateType.EVENT_DATE, dateFilterOption);
eventGrid.setCriteria(criteria);
eventGrid.getSelectedItems();
});
Button resetButton = ButtonHelper.createButton(Captions.caseEventsResetDateFilter, null);
resetButton.addClickListener(e -> {
weekAndDateFilter.getDateFromFilter().setValue(null);
weekAndDateFilter.getDateToFilter().setValue(null);
weekAndDateFilter.getWeekFromFilter().setValue(null);
weekAndDateFilter.getWeekToFilter().setValue(null);
criteria.freeText(null);
if (setDefaultFilters != null) {
setDefaultFilters.accept(criteria);
} else {
criteria.eventDateBetween(null, null, null, DateFilterOption.DATE);
}
eventGrid.setCriteria(criteria);
eventGrid.getSelectedItems();
});
HorizontalLayout dateFilterRowLayout = new HorizontalLayout();
dateFilterRowLayout.setSpacing(true);
dateFilterRowLayout.setSizeUndefined();
dateFilterRowLayout.addComponent(weekAndDateFilter);
dateFilterRowLayout.addComponent(applyButton);
dateFilterRowLayout.addComponent(resetButton);
return dateFilterRowLayout;
}
use of de.symeda.sormas.api.utils.DateFilterOption in project SORMAS-Project by hzi-braunschweig.
the class SampleGridFilterForm method applyDependenciesOnNewValue.
@Override
protected void applyDependenciesOnNewValue(SampleCriteria criteria) {
UserDto user = currentUserDto();
ComboBox districtField = (ComboBox) getField(SampleCriteria.DISTRICT);
if (user.getRegion() != null) {
districtField.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(user.getRegion().getUuid()));
districtField.setEnabled(true);
} else {
RegionReferenceDto region = criteria.getRegion();
if (region != null) {
districtField.addItems(FacadeProvider.getDistrictFacade().getAllActiveByRegion(region.getUuid()));
districtField.setEnabled(true);
} else {
districtField.setEnabled(false);
}
}
HorizontalLayout dateFilterLayout = (HorizontalLayout) getMoreFiltersContainer().getComponent(WEEK_AND_DATE_FILTER);
EpiWeekAndDateFilterComponent<DateFilterOption> weekAndDateFilter;
weekAndDateFilter = (EpiWeekAndDateFilterComponent<DateFilterOption>) dateFilterLayout.getComponent(0);
weekAndDateFilter.getDateFilterOptionFilter().setValue(criteria.getDateFilterOption());
Date sampleDateFrom = criteria.getSampleReportDateFrom();
Date sampleDateTo = criteria.getSampleReportDateTo();
if (DateFilterOption.EPI_WEEK.equals(criteria.getDateFilterOption())) {
weekAndDateFilter.getWeekFromFilter().setValue(sampleDateFrom == null ? null : DateHelper.getEpiWeek(sampleDateFrom));
weekAndDateFilter.getWeekToFilter().setValue(sampleDateTo == null ? null : DateHelper.getEpiWeek(sampleDateTo));
} else {
weekAndDateFilter.getDateFromFilter().setValue(sampleDateFrom);
weekAndDateFilter.getDateToFilter().setValue(sampleDateTo);
}
}
use of de.symeda.sormas.api.utils.DateFilterOption in project SORMAS-Project by hzi-braunschweig.
the class SampleGridFilterForm method buildWeekAndDateFilter.
private HorizontalLayout buildWeekAndDateFilter() {
EpiWeekAndDateFilterComponent<DateFilterOption> weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(false, false, null, this);
weekAndDateFilter.getWeekFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptSampleEpiWeekFrom));
weekAndDateFilter.getWeekToFilter().setInputPrompt(I18nProperties.getString(Strings.promptSampleEpiWeekTo));
weekAndDateFilter.getDateFromFilter().setInputPrompt(I18nProperties.getString(Strings.promptSampleDateFrom));
weekAndDateFilter.getDateToFilter().setInputPrompt(I18nProperties.getString(Strings.promptSampleDateTo));
addApplyHandler(e -> onApplyClick(weekAndDateFilter));
HorizontalLayout dateFilterRowLayout = new HorizontalLayout();
dateFilterRowLayout.setSpacing(true);
dateFilterRowLayout.setSizeUndefined();
dateFilterRowLayout.addComponent(weekAndDateFilter);
return dateFilterRowLayout;
}
use of de.symeda.sormas.api.utils.DateFilterOption in project SORMAS-Project by hzi-braunschweig.
the class SampleGridFilterForm method onApplyClick.
private void onApplyClick(EpiWeekAndDateFilterComponent<DateFilterOption> weekAndDateFilter) {
SampleCriteria criteria = getValue();
DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue();
Date fromDate, toDate;
if (dateFilterOption == DateFilterOption.DATE) {
Date dateFrom = weekAndDateFilter.getDateFromFilter().getValue();
fromDate = dateFrom != null ? DateHelper.getStartOfDay(dateFrom) : null;
Date dateTo = weekAndDateFilter.getDateToFilter().getValue();
toDate = dateFrom != null ? DateHelper.getEndOfDay(dateTo) : null;
} else {
fromDate = DateHelper.getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue());
toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue());
}
if ((fromDate != null && toDate != null) || (fromDate == null && toDate == null)) {
criteria.reportDateBetween(fromDate, toDate, dateFilterOption);
} else {
weekAndDateFilter.setNotificationsForMissingFilters();
}
}
use of de.symeda.sormas.api.utils.DateFilterOption in project SORMAS-Project by hzi-braunschweig.
the class DashboardFilterLayout method createCustomDateFilterLayout.
private HorizontalLayout createCustomDateFilterLayout() {
// Custom filter
customDateFilterLayout = new HorizontalLayout();
customDateFilterLayout.setSpacing(true);
customDateFilterLayout.setVisible(false);
// 'Apply custom filter' button
Button applyButton = ButtonHelper.createButton(Captions.dashboardApplyCustomFilter, null, CssStyles.FORCE_CAPTION, CssStyles.BUTTON_FILTER_LIGHT);
// Date & Epi Week filter
EpiWeekAndDateFilterComponent<NewCaseDateType> weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(true, true, I18nProperties.getString(Strings.infoCaseDate), null);
customDateFilterLayout.addComponents(weekAndDateFilter, applyButton);
// Apply button listener
applyButton.addClickListener(e -> {
currentDateFilterType = DateFilterType.CUSTOM;
DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue();
Date fromDate = null;
Date toDate = null;
EpiWeek fromWeek = null;
EpiWeek toWeek = null;
if (dateFilterOption == DateFilterOption.DATE) {
fromDate = weekAndDateFilter.getDateFromFilter().getValue();
toDate = weekAndDateFilter.getDateToFilter().getValue();
setDateFilter(DateHelper.getStartOfDay(fromDate), DateHelper.getEndOfDay(toDate));
} else {
fromWeek = (EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue();
toWeek = (EpiWeek) weekAndDateFilter.getWeekToFilter().getValue();
setDateFilter(DateHelper.getEpiWeekStart(fromWeek), DateHelper.getEpiWeekEnd(toWeek));
}
if ((fromDate != null && toDate != null) || (fromWeek != null && toWeek != null)) {
if (dateFilterOption == DateFilterOption.DATE) {
btnCurrentPeriod.setCaption(DateFormatHelper.buildPeriodString(fromDate, toDate));
int activePeriodLength = DateHelper.getDaysBetween(fromDate, toDate);
btnPeriodBefore.setCaption(String.format(I18nProperties.getCaption(Captions.dashboardPeriodBefore), DateFormatHelper.buildPeriodString(DateHelper.subtractDays(fromDate, activePeriodLength), DateHelper.subtractDays(toDate, activePeriodLength))));
btnPeriodLastYear.setCaption(String.format(I18nProperties.getCaption(Captions.dashboardSamePeriodLastYear), DateFormatHelper.buildPeriodString(DateHelper.subtractYears(fromDate, 1), DateHelper.subtractYears(toDate, 1))));
} else {
btnCurrentPeriod.setCaption(fromWeek.toShortString() + " - " + toWeek.toShortString());
Date firstEpiWeekStart = DateHelper.getEpiWeekStart(fromWeek);
Date lastEpiWeekStart = DateHelper.getEpiWeekStart(toWeek);
int epiWeeksBetween = DateHelper.getWeeksBetween(firstEpiWeekStart, lastEpiWeekStart);
btnPeriodBefore.setCaption(String.format(I18nProperties.getCaption(Captions.dashboardPeriodBefore), DateHelper.getEpiWeek(DateHelper.subtractWeeks(firstEpiWeekStart, epiWeeksBetween)).toShortString() + " - " + DateHelper.getEpiWeek(DateHelper.subtractWeeks(lastEpiWeekStart, epiWeeksBetween)).toShortString()));
btnPeriodLastYear.setCaption(String.format(I18nProperties.getCaption(Captions.dashboardSamePeriodLastYear), DateHelper.getEpiWeekYearBefore(fromWeek).toShortString() + " - " + DateHelper.getEpiWeekYearBefore(toWeek).toShortString()));
}
updateComparisonButtons(DateFilterType.CUSTOM, null, null, true);
} else {
if (dateFilterOption == DateFilterOption.DATE) {
new Notification(I18nProperties.getString(Strings.headingMissingDateFilter), I18nProperties.getString(Strings.messageMissingDateFilter), Type.ERROR_MESSAGE, false).show(Page.getCurrent());
} else {
new Notification(I18nProperties.getString(Strings.headingMissingEpiWeekFilter), I18nProperties.getString(Strings.messageMissingEpiWeekFilter), Type.ERROR_MESSAGE, false).show(Page.getCurrent());
}
}
});
return customDateFilterLayout;
}
Aggregations