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 482612ba0..a9f3394d9 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 @@ -21,6 +21,7 @@ package org.libreplan.web.common.components; +import java.util.Date; import java.util.List; import org.libreplan.business.resources.daos.IResourcesSearcher; @@ -36,6 +37,7 @@ import org.zkoss.zul.Radiogroup; /** * @author Diego Pino García + * @author Javier Moran Rua * * ZK macro component for searching {@link Worker} entities * @@ -148,6 +150,7 @@ public class NewAllocationSelector extends AllocationSelector { } // AllocationType + @Override public NewAllocationSelectorController getController() { if (selectorController == null) { selectorController = new NewAllocationSelectorController(behaviour); @@ -164,4 +167,12 @@ public class NewAllocationSelector extends AllocationSelector { this.behaviour = ResourceAllocationBehaviour.valueOf(behaviour); } + public void setEndFilteringDate(Date d) { + selectorController.setEndFilteringDate(d); + } + + public void setStartFilteringDate(Date d) { + selectorController.setStartFilteringDate(d); + } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/IResourceAllocationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/IResourceAllocationModel.java index 5eaf7b981..ba55287c9 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/IResourceAllocationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/IResourceAllocationModel.java @@ -38,6 +38,7 @@ import org.zkoss.ganttz.extensions.IContextWithPlannerTask; * * @author Manuel Rego Casasnovas * @author Diego Pino García + * @author Javier Moran Rua */ public interface IResourceAllocationModel extends INewAllocationsAdder { @@ -84,4 +85,6 @@ public interface IResourceAllocationModel extends INewAllocationsAdder { Date getTaskEnd(); -} \ No newline at end of file + Date getTaskStart(); + +} 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 0b2509bc2..9902d4286 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 @@ -82,8 +82,10 @@ import org.zkoss.zul.Window; /** * Controller for {@link ResourceAllocation} view. + * * @author Manuel Rego Casasnovas * @author Diego Pino Garcia + * @author Javier Moran Rua */ @org.springframework.stereotype.Component("resourceAllocationController") @Scope(BeanDefinition.SCOPE_PROTOTYPE) @@ -162,6 +164,7 @@ public class ResourceAllocationController extends GenericForwardComposer { assignedEffortComponent.setWidth("80px"); } + @Override public ResourceAllocationController getController() { return this; } @@ -228,12 +231,14 @@ public class ResourceAllocationController extends GenericForwardComposer { return allocationConfiguration.getTaskWorkableDays(); } - private Label getTaskStart() { - return allocationConfiguration.getTaskStart(); + public Label getTaskStart() { + return (allocationConfiguration != null) ? allocationConfiguration + .getTaskStart() : null; } - private Label getTaskEnd() { - return allocationConfiguration.getTaskEnd(); + public Label getTaskEnd() { + return (allocationConfiguration != null) ? allocationConfiguration + .getTaskEnd() : null; } private Radiogroup getCalculationTypeSelector() { @@ -317,8 +322,15 @@ public class ResourceAllocationController extends GenericForwardComposer { } public void goToAdvancedSearch() { + newAllocationSelector.setStartFilteringDate(resourceAllocationModel + .getTaskStart()); + newAllocationSelector.setEndFilteringDate(resourceAllocationModel + .getTaskEnd()); applyButton.setVisible(false); workerSearchTab.setSelected(true); + // The initial search and ratio load calculations is raised + // on going to advanced search + newAllocationSelector.clearAll(); } /** @@ -679,4 +691,5 @@ public class ResourceAllocationController extends GenericForwardComposer { || formBinder.isTaskUpdatedFromTimesheets(); } + } diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationModel.java index bfd8d0e46..9ef30078b 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/planner/allocation/ResourceAllocationModel.java @@ -54,13 +54,14 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.zkoss.ganttz.data.GanttDate; import org.zkoss.ganttz.extensions.IContextWithPlannerTask; /** * Model for UI operations related to {@link Task} + * * @author Manuel Rego Casasnovas * @author Diego Pino García + * @author Javier Moran Rua */ @Service @Scope(BeanDefinition.SCOPE_PROTOTYPE) @@ -325,4 +326,17 @@ public class ResourceAllocationModel implements IResourceAllocationModel { return task.getEndDate(); } + @Override + public Date getTaskStart() { + Date result; + + if (task == null) { + result = null; + } else { + result = task.getStartDate(); + } + + return result; + } + } 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 740a36fc1..aacfd2b02 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 @@ -22,8 +22,6 @@ package org.libreplan.web.resources.search; import java.math.BigDecimal; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -72,7 +70,6 @@ import org.zkoss.zul.Treeitem; import org.zkoss.zul.TreeitemRenderer; import org.zkoss.zul.Treerow; - /** * Controller for searching for {@link Resource}. * @@ -101,6 +98,7 @@ public class NewAllocationSelectorController extends private ResourceAllocationBehaviour behaviour; + public NewAllocationSelectorController(ResourceAllocationBehaviour behaviour) { this.behaviour = behaviour; } @@ -113,23 +111,11 @@ public class NewAllocationSelectorController extends } private void initializeComponents() { - initializeResourceLoadRatiosFilterDates(); initializeCriteriaTree(); initializeListboxResources(); initializeAllocationTypeSelector(); } - private void initializeResourceLoadRatiosFilterDates() { - try { - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); - startDateLoadRatiosDatebox.setValue(sdf.parse("01/09/2012")); - endDateLoadRatiosDatebox.setValue(sdf.parse("01/10/2012")); - } catch (ParseException e) { - System.out.println("Parse exception"); - throw new RuntimeException(); - } - } - private void initializeCriteriaTree() { // Initialize criteria tree if (criterionsTree != null) { @@ -152,14 +138,14 @@ public class NewAllocationSelectorController extends listBoxResources.addEventListener(Events.ON_SELECT, new EventListener() { - @Override - public void onEvent(Event event) { - if (isGenericType()) { - returnToSpecificDueToResourceSelection(); - } - showSelectedAllocations(); - } - }); + @Override + public void onEvent(Event event) { + if (isGenericType()) { + returnToSpecificDueToResourceSelection(); + } + showSelectedAllocations(); + } + }); listBoxResources.setMultiple(behaviour.allowMultipleSelection()); listBoxResources.setItemRenderer(getListitemRenderer()); } @@ -183,7 +169,7 @@ public class NewAllocationSelectorController extends } }); // Feed with values - for (AllocationType each: behaviour.allocationTypes()) { + for (AllocationType each : behaviour.allocationTypes()) { allocationTypeSelector.appendChild(radio(each)); } doInitialSelection(); @@ -224,18 +210,21 @@ public class NewAllocationSelectorController extends private List getAllResources() { - List listResources = query().byResourceType( - getType()).execute(); + List result = new ArrayList(); - return addLoadRatiosCalculations(listResources); - } + // The search is only done in case that the endFilteringDate and + // startFilteringDate are initialized. This happens when the + // user does the advanced search visible by clicking on the + // AdvancedSearch button + if ((startDateLoadRatiosDatebox.getValue() != null) + && (endDateLoadRatiosDatebox.getValue() != null)) { - public Date getStartDateForLoadRatiosCalc() { - return new Date(); - } + List listResources = query().byResourceType( + getType()).execute(); - public Date getEndDateForLoadRatiosCalc() { - return new Date(); + result = addLoadRatiosCalculations(listResources); + } + return result; } private List addLoadRatiosCalculations( @@ -245,9 +234,12 @@ public class NewAllocationSelectorController extends for (Resource each : listResources) { ILoadRatiosDataType t = resourceLoadRatiosCalculator - .calculateLoadRatios(each, new LocalDate( - 2012, 8, 1), new LocalDate(2012, 9, 30), scenarioManager - .getCurrent()); + .calculateLoadRatios(each, LocalDate + .fromDateFields(startDateLoadRatiosDatebox + .getValue()), + LocalDate.fromDateFields(endDateLoadRatiosDatebox + .getValue()), + scenarioManager.getCurrent()); result.add(new ResourceWithItsLoadRatios(each, t)); } @@ -317,8 +309,8 @@ public class NewAllocationSelectorController extends @SuppressWarnings("unchecked") private void clearSelection(Listbox listBox) { - Set selectedItems = new HashSet(listBox - .getSelectedItems()); + Set selectedItems = new HashSet( + listBox.getSelectedItems()); for (Listitem each : selectedItems) { listBox.removeItemFromSelection(each); } @@ -326,7 +318,8 @@ public class NewAllocationSelectorController extends @SuppressWarnings("unchecked") private void clearSelection(Tree tree) { - Set selectedItems = new HashSet(tree.getSelectedItems()); + Set selectedItems = new HashSet( + tree.getSelectedItems()); for (Treeitem each : selectedItems) { tree.removeItemFromSelection(each); } @@ -349,9 +342,7 @@ public class NewAllocationSelectorController extends */ private void searchResources(String name, List criterions) { final List resources = query().byName(name) - .byCriteria(criterions) - .byResourceType(getType()) - .execute(); + .byCriteria(criterions).byResourceType(getType()).execute(); refreshListBoxResources(addLoadRatiosCalculations(resources)); } @@ -585,7 +576,7 @@ public class NewAllocationSelectorController extends BigDecimal overtime = dataToRender.getRatios().getOvertimeRatio(); cellOvertime.appendChild(new Label(overtime.toString())); item.appendChild(cellOvertime); - } + } } public CriterionRenderer getCriterionRenderer() { @@ -646,4 +637,11 @@ public class NewAllocationSelectorController extends return listBoxResources.isMultiple(); } + public void setEndFilteringDate(Date d) { + endDateLoadRatiosDatebox.setValue(d); + } + + public void setStartFilteringDate(Date d) { + startDateLoadRatiosDatebox.setValue(d); + } }