From 6936dd2ff12e0a31a66b2df2457c09b22574aeb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenzo=20Tilve=20=C3=81lvaro?= Date: Mon, 4 Feb 2013 20:01:19 +0100 Subject: [PATCH] Fixed issue regarding using labels and dates at the same time FEA: ItEr77S15FilteringEnhancements --- .../company/CompanyPlanningController.java | 24 +++++++++++--- .../planner/company/CompanyPlanningModel.java | 32 +++++-------------- .../company/ICompanyPlanningModel.java | 5 +-- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/CompanyPlanningController.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/CompanyPlanningController.java index 277aa12e0..9592082ce 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/CompanyPlanningController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/CompanyPlanningController.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.lang.Validate; +import org.joda.time.LocalDate; import org.libreplan.business.common.entities.ProgressType; import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.planner.entities.TaskElement; @@ -185,6 +186,23 @@ public class CompanyPlanningController implements Composer { .getFinderPattern(), user .getProjectsFilterLabel())); } + + // Calculate filter based on user preferences + if (user != null) { + if (filterStartDate.getValue() == null + && (user.getProjectsFilterPeriodSince() != null)) { + filterStartDate.setValue(new LocalDate() + .minusMonths(user.getProjectsFilterPeriodSince()) + .toDateTimeAtStartOfDay().toDate()); + } + if (filterFinishDate.getValue() == null + && (user.getProjectsFilterPeriodTo() != null)) { + filterFinishDate.setValue(new LocalDate() + .plusMonths(user.getProjectsFilterPeriodTo()) + .toDateMidnight().toDate()); + } + } + } /** @@ -343,12 +361,10 @@ public class CompanyPlanningController implements Composer { IPredicate predicate = model.getDefaultPredicate(includeOrderElements); //show filter dates calculated by default on screen if(model.getFilterStartDate() != null) { - filterStartDate.setValue(model.getFilterStartDate(). - toDateMidnight().toDate()); + filterStartDate.setValue(model.getFilterStartDate()); } if(model.getFilterFinishDate() != null) { - filterFinishDate.setValue(model.getFilterFinishDate(). - toDateMidnight().toDate()); + filterFinishDate.setValue(model.getFilterFinishDate()); } return predicate; diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/CompanyPlanningModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/CompanyPlanningModel.java index f6f58d44f..e4708b406 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/CompanyPlanningModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/CompanyPlanningModel.java @@ -745,23 +745,6 @@ public class CompanyPlanningModel implements ICompanyPlanningModel { throw new RuntimeException(e); } - // Calculate filter based on user preferences - if (user != null) { - if (calculateStartDate - && (user.getProjectsFilterPeriodSince() != null)) { - startDate = new LocalDate() - .minusMonths(user.getProjectsFilterPeriodSince()) - .toDateTimeAtStartOfDay().toDate(); - calculateStartDate = false; - } - if (calculateEndDate && (user.getProjectsFilterPeriodTo() != null)) { - endDate = new LocalDate() - .plusMonths(user.getProjectsFilterPeriodTo()) - .toDateMidnight().toDate(); - calculateEndDate = false; - } - } - // Filter predicate needs to be calculated based on the projects dates if ((calculateStartDate) || (calculateEndDate)) { if (currentScenario == null) { @@ -807,18 +790,19 @@ public class CompanyPlanningModel implements ICompanyPlanningModel { } @Override - public LocalDate getFilterStartDate() { - return filterStartDate; + public Date getFilterStartDate() { + return ((filterStartDate == null) ? null : filterStartDate + .toDateTimeAtStartOfDay().toDate()); } - @Override - public LocalDate getFilterFinishDate() { - return filterFinishDate; + public Date getFilterFinishDate() { + return ((filterStartDate == null) ? null : filterFinishDate + .toDateMidnight().toDate()); } private AvailabilityTimeLine.Interval getFilterInterval() { - return AvailabilityTimeLine.Interval.create(getFilterStartDate(), - getFilterFinishDate()); + return AvailabilityTimeLine.Interval.create(filterStartDate, + filterFinishDate); } private class CompanyLoadChartFiller extends StandardLoadChartFiller { diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/ICompanyPlanningModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/ICompanyPlanningModel.java index 01c5d12fc..86069ca2a 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/ICompanyPlanningModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/company/ICompanyPlanningModel.java @@ -22,6 +22,7 @@ package org.libreplan.web.planner.company; import java.util.Collection; +import java.util.Date; import org.joda.time.LocalDate; import org.libreplan.business.common.entities.ProgressType; @@ -45,9 +46,9 @@ public interface ICompanyPlanningModel { public void setTabsController(MultipleTabsPlannerController tabsController); - LocalDate getFilterStartDate(); + Date getFilterStartDate(); - LocalDate getFilterFinishDate(); + Date getFilterFinishDate(); ProgressType getProgressTypeFromConfiguration();