From d7ed3aa149f1ee61bbdf5c4efb9b4cb82aee6c33 Mon Sep 17 00:00:00 2001 From: Javier Moran Rua Date: Sat, 13 Oct 2012 17:36:40 +0200 Subject: [PATCH] Recalculates the load ratios on changing the filtering dates and incorporates interface validations in the filtering dates dateboxes FEA: ItEr77S10ResourceAllocationLoadInformation --- .../components/NewAllocationSelector.java | 4 +- .../ResourceAllocationController.java | 1 - .../NewAllocationSelectorController.java | 68 ++++++++++++++++++- .../resources/search/allocation_selector.zul | 6 +- 4 files changed, 71 insertions(+), 8 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/common/components/NewAllocationSelector.java b/libreplan-webapp/src/main/java/org/libreplan/web/common/components/NewAllocationSelector.java index a9f3394d9..c61b06873 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/common/components/NewAllocationSelector.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/common/components/NewAllocationSelector.java @@ -168,11 +168,11 @@ public class NewAllocationSelector extends AllocationSelector { } public void setEndFilteringDate(Date d) { - selectorController.setEndFilteringDate(d); + getController().setEndFilteringDate(d); } public void setStartFilteringDate(Date d) { - selectorController.setStartFilteringDate(d); + getController().setStartFilteringDate(d); } } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java index 9902d4286..c0144bbea 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationController.java @@ -691,5 +691,4 @@ public class ResourceAllocationController extends GenericForwardComposer { || formBinder.isTaskUpdatedFromTimesheets(); } - } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resources/search/NewAllocationSelectorController.java b/libreplan-webapp/src/main/java/org/libreplan/web/resources/search/NewAllocationSelectorController.java index 17f6d82cc..3b6b13916 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resources/search/NewAllocationSelectorController.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resources/search/NewAllocationSelectorController.java @@ -21,6 +21,8 @@ package org.libreplan.web.resources.search; +import static org.libreplan.web.I18nHelper._; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; @@ -48,10 +50,12 @@ import org.libreplan.web.common.components.ResourceAllocationBehaviour; import org.libreplan.web.planner.allocation.INewAllocationsAdder; import org.zkoss.lang.Objects; import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.WrongValueException; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.InputEvent; +import org.zkoss.zul.Constraint; import org.zkoss.zul.Datebox; import org.zkoss.zul.Label; import org.zkoss.zul.Listbox; @@ -98,7 +102,6 @@ public class NewAllocationSelectorController extends private ResourceAllocationBehaviour behaviour; - public NewAllocationSelectorController(ResourceAllocationBehaviour behaviour) { this.behaviour = behaviour; } @@ -114,6 +117,23 @@ public class NewAllocationSelectorController extends initializeCriteriaTree(); initializeListboxResources(); initializeAllocationTypeSelector(); + initializeFilteringDates(); + } + + private void initializeFilteringDates() { + // Start and end filtering dates are initialized here because + // they cannot be empty and must have always a value. The + // task start date and task end date are not available at the first + // rendering. Thus, the current date and current date + 1 day are used + // as the value to initialize the components although will + // never be visible by the user. + Date initDate = new Date(); + setStartFilteringDate(initDate); + setEndFilteringDate(LocalDate.fromDateFields(initDate).plusDays(1) + .toDateTimeAtStartOfDay().toDate()); + startDateLoadRatiosDatebox + .setConstraint(checkConstraintFilteringDate()); + endDateLoadRatiosDatebox.setConstraint(checkConstraintFilteringDate()); } private void initializeCriteriaTree() { @@ -238,8 +258,7 @@ public class NewAllocationSelectorController extends .fromDateFields(startDateLoadRatiosDatebox .getValue()), LocalDate.fromDateFields(endDateLoadRatiosDatebox - .getValue()), - scenarioManager.getCurrent()); + .getValue()), scenarioManager.getCurrent()); result.add(new ResourceWithItsLoadRatios(each, t)); } @@ -648,4 +667,47 @@ public class NewAllocationSelectorController extends public void setStartFilteringDate(Date d) { startDateLoadRatiosDatebox.setValue(d); } + + public void updateLoadRatios() { + searchResources("", getSelectedCriterions()); + } + + public Constraint checkConstraintFilteringDate() { + return new Constraint() { + @Override + public void validate(Component comp, Object value) throws WrongValueException { + if (value == null) { + if (comp.getId().equals("startDateLoadRatiosDatebox")) { + throw new WrongValueException(comp, + _("Start filtering date cannot be empty")); + } else if (comp.getId().equals("endDateLoadRatiosDatebox")) { + throw new WrongValueException(comp, + _("End filtering date cannot be empty")); + } + } + + Date startDate = null; + if (comp.getId().equals("startDateLoadRatiosDatebox")) { + startDate = (Date) value; + } else { + startDate = (Date) startDateLoadRatiosDatebox.getRawValue(); + } + + Date endDate = null; + if (comp.getId().equals("endDateLoadRatiosDatebox")) { + endDate = (Date) value; + } else { + endDate = (Date) endDateLoadRatiosDatebox.getRawValue(); + } + + if ((startDate != null) && (endDate != null)) { + if ((startDate.after(endDate)) + || (startDate.equals(endDate))) { + throw new WrongValueException(comp,_("Start filtering date must be before than end filtering date")); + } + } + } + }; + } + } diff --git a/libreplan-webapp/src/main/webapp/resources/search/allocation_selector.zul b/libreplan-webapp/src/main/webapp/resources/search/allocation_selector.zul index 6738cce3e..ecf6a1caf 100644 --- a/libreplan-webapp/src/main/webapp/resources/search/allocation_selector.zul +++ b/libreplan-webapp/src/main/webapp/resources/search/allocation_selector.zul @@ -54,11 +54,13 @@