From 86cedc04c5b34dde0cce6091b8edfe5a4b2859cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenzo=20Tilve=20=C3=81lvaro?= Date: Mon, 28 Jan 2013 12:45:26 +0100 Subject: [PATCH] Used stored user settings parameters for ResourceLoad date filtering FEA: ItEr77S15FilteringEnhancements --- .../resourceload/ResourceLoadController.java | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadController.java b/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadController.java index 5734ab57b..67fe5cb2e 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadController.java @@ -3,7 +3,7 @@ * * Copyright (C) 2009-2010 Fundación para o Fomento da Calidade Industrial e * Desenvolvemento Tecnolóxico de Galicia - * Copyright (C) 2010-2012 Igalia, S.L. + * Copyright (C) 2010-2013 Igalia, S.L. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -28,8 +28,10 @@ import static org.libreplan.web.resourceload.ResourceLoadModel.toLocal; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Date; import java.util.List; + import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.Validate; import org.joda.time.LocalDate; @@ -38,6 +40,7 @@ import org.libreplan.business.common.BaseEntity; import org.libreplan.business.common.IAdHocTransactionService; import org.libreplan.business.common.IOnTransaction; import org.libreplan.business.common.daos.IConfigurationDAO; +import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.orders.entities.Order; import org.libreplan.business.planner.chart.ILoadChartData; import org.libreplan.business.planner.chart.ResourceLoadChartData; @@ -46,6 +49,8 @@ import org.libreplan.business.planner.entities.TaskElement; import org.libreplan.business.resources.daos.IResourcesSearcher; import org.libreplan.business.resources.entities.Criterion; import org.libreplan.business.resources.entities.Resource; +import org.libreplan.business.users.daos.IUserDAO; +import org.libreplan.business.users.entities.User; import org.libreplan.web.common.components.bandboxsearch.BandboxMultipleSearch; import org.libreplan.web.common.components.finders.FilterPair; import org.libreplan.web.planner.chart.Chart; @@ -77,6 +82,7 @@ import org.zkoss.ganttz.timetracker.zoom.SeveralModificators; import org.zkoss.ganttz.timetracker.zoom.ZoomLevel; import org.zkoss.ganttz.util.Emitter; import org.zkoss.ganttz.util.Interval; +import org.zkoss.zk.ui.Sessions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; @@ -98,6 +104,7 @@ import org.zkoss.zul.api.Combobox; * * @author Óscar González Fernández * @author Manuel Rego Casasnovas + * @author Lorenzo Tilve Álvaro */ @Component @Scope(BeanDefinition.SCOPE_PROTOTYPE) @@ -112,6 +119,9 @@ public class ResourceLoadController implements Composer { @Autowired private IAdHocTransactionService transactionService; + @Autowired + private IUserDAO userDAO; + private List commands = new ArrayList(); private PlanningState filterBy; @@ -268,7 +278,33 @@ public class ResourceLoadController implements Composer { FilterTypeChanger filterTypeChanger = new FilterTypeChanger(onChange, filterBy); result.add(filterTypeChanger); - result.add(new ByDatesFilter(onChange, filterBy)); + + User user; + LocalDate startDate = null; + LocalDate endDate = null; + try { + user = this.userDAO.findByLoginName(SecurityUtils + .getSessionUserLoginName()); + } catch (InstanceNotFoundException e) { + throw new RuntimeException(e); + } + // Calculate filter based on user preferences + if (user != null) { + if (user.getResourcesLoadFilterPeriodSince() != null) { + startDate = new LocalDate() +.minusMonths(user + .getResourcesLoadFilterPeriodSince()); + } else { + startDate = new LocalDate().minusDays(1); + } + if (user.getResourcesLoadFilterPeriodTo() != null) { + endDate = new LocalDate() +.plusMonths(user + .getResourcesLoadFilterPeriodTo()); + } + } + + result.add(new ByDatesFilter(onChange, filterBy, startDate, endDate)); WorkersOrCriteriaBandbox bandbox = new WorkersOrCriteriaBandbox( onChange, filterBy, filterTypeChanger, resourcesSearcher); result.add(bandbox); @@ -412,10 +448,14 @@ public class ResourceLoadController implements Composer { private final Datebox endBox = new Datebox(); - private ByDatesFilter(Runnable onChange, PlanningState filterBy) { + private ByDatesFilter(Runnable onChange, PlanningState filterBy, + LocalDate startDate, LocalDate endDate) { super(onChange, filterBy); - startDateValue = isAppliedToOrder() ? null : new LocalDate() - .minusDays(1); + startDateValue = (isAppliedToOrder() || (startDate == null)) ? null + : startDate + .toDateTimeAtStartOfDay().toLocalDate(); + endDateValue = (endDate == null) ? null : endDate + .toDateMidnight().toLocalDate(); } @Override @@ -439,6 +479,7 @@ public class ResourceLoadController implements Composer { } } }); + endBox.setValue(asDate(endDateValue)); endBox.setWidth("100px"); endBox.addEventListener(Events.ON_CHANGE, new EventListener() { @@ -451,6 +492,7 @@ public class ResourceLoadController implements Composer { } } }); + Hbox hbox = new Hbox(); hbox.appendChild(new Label(_("From") + ":")); hbox.appendChild(startBox);