ItEr29S08CUCreacionProxectoPlanificacionItEr28S09: Completed filtering resource load view for an order.
This commit is contained in:
parent
709ca66731
commit
34026b9b51
6 changed files with 77 additions and 11 deletions
|
|
@ -19,7 +19,6 @@
|
|||
*/
|
||||
package org.navalplanner.web.planner;
|
||||
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.web.common.ViewSwitcher;
|
||||
import org.zkoss.ganttz.extensions.ICommand;
|
||||
|
|
@ -30,7 +29,6 @@ import org.zkoss.ganttz.extensions.ICommand;
|
|||
*/
|
||||
public interface IResourceLoadForOrderCommand extends ICommand<TaskElement>{
|
||||
|
||||
public void initialize(Order order, ViewSwitcher switcher,
|
||||
PlanningState planningState);
|
||||
public void initialize(ViewSwitcher switcher, PlanningState planningState);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
|
|||
configuration.addGlobalCommand(saveCommand);
|
||||
|
||||
IResourceLoadForOrderCommand resourceLoadForOrderCommand = getResourceLoadForOrderCommand();
|
||||
resourceLoadForOrderCommand.initialize(order, switcher, planningState);
|
||||
resourceLoadForOrderCommand.initialize(switcher, planningState);
|
||||
configuration.addGlobalCommand(resourceLoadForOrderCommand);
|
||||
|
||||
IResourceAllocationCommand resourceAllocationCommand = getResourceAllocationCommand();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ package org.navalplanner.web.planner;
|
|||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import org.navalplanner.business.orders.entities.Order;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.web.common.ViewSwitcher;
|
||||
import org.navalplanner.web.resourceload.ResourceLoadController;
|
||||
|
|
@ -46,14 +45,14 @@ public class ResourceLoadForOrderCommand implements
|
|||
private ResourceLoadController resourceLoadController;
|
||||
|
||||
@Override
|
||||
public void initialize(Order order, ViewSwitcher switcher,
|
||||
PlanningState planningState) {
|
||||
public void initialize(ViewSwitcher switcher, PlanningState planningState) {
|
||||
this.switcher = switcher;
|
||||
this.planningState = planningState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(IContext<TaskElement> context) {
|
||||
resourceLoadController.filterBy(planningState);
|
||||
switcher.goToResourceLoad(resourceLoadController);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.navalplanner.web.resourceload;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.web.planner.PlanningState;
|
||||
import org.zkoss.ganttz.data.resourceload.LoadTimelinesGroup;
|
||||
import org.zkoss.ganttz.util.Interval;
|
||||
|
||||
|
|
@ -29,6 +30,8 @@ public interface IResourceLoadModel {
|
|||
|
||||
void initGlobalView();
|
||||
|
||||
void initGlobalView(PlanningState filterBy);
|
||||
|
||||
List<LoadTimelinesGroup> getLoadTimeLines();
|
||||
|
||||
Interval getViewInterval();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.navalplanner.web.planner.PlanningState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -47,6 +48,8 @@ public class ResourceLoadController extends GenericForwardComposer {
|
|||
|
||||
private List<IToolbarCommand> commands = new ArrayList<IToolbarCommand>();
|
||||
|
||||
private PlanningState filterBy;
|
||||
|
||||
public ResourceLoadController() {
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +60,11 @@ public class ResourceLoadController extends GenericForwardComposer {
|
|||
|
||||
@Override
|
||||
public void doAfterCompose(org.zkoss.zk.ui.Component comp) throws Exception {
|
||||
resourceLoadModel.initGlobalView();
|
||||
if (filterBy == null) {
|
||||
resourceLoadModel.initGlobalView();
|
||||
} else {
|
||||
resourceLoadModel.initGlobalView(filterBy);
|
||||
}
|
||||
ResourcesLoadPanel resourcesLoadPanel = buildResourcesLoadPanel();
|
||||
comp.appendChild(resourcesLoadPanel);
|
||||
resourcesLoadPanel.afterCompose();
|
||||
|
|
@ -72,4 +79,8 @@ public class ResourceLoadController extends GenericForwardComposer {
|
|||
return new ResourcesLoadPanel(resourceLoadModel.getLoadTimeLines(),
|
||||
new TimeTracker(resourceLoadModel.getViewInterval()));
|
||||
}
|
||||
|
||||
public void filterBy(PlanningState planningState) {
|
||||
this.filterBy = planningState;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import static org.navalplanner.web.I18nHelper._;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
|
@ -38,9 +39,11 @@ import org.navalplanner.business.planner.entities.GenericResourceAllocation;
|
|||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.SpecificResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.web.planner.PlanningState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -64,6 +67,8 @@ public class ResourceLoadModel implements IResourceLoadModel {
|
|||
private List<LoadTimelinesGroup> loadTimeLines;
|
||||
private Interval viewInterval;
|
||||
|
||||
private PlanningState filterBy;
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void initGlobalView() {
|
||||
|
|
@ -75,6 +80,13 @@ public class ResourceLoadModel implements IResourceLoadModel {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void initGlobalView(PlanningState filterBy) {
|
||||
this.filterBy = filterBy;
|
||||
initGlobalView();
|
||||
}
|
||||
|
||||
private Date plusFiveYears(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
|
|
@ -84,12 +96,54 @@ public class ResourceLoadModel implements IResourceLoadModel {
|
|||
|
||||
private List<LoadTimelinesGroup> calculateLoadTimelinesGroups() {
|
||||
List<LoadTimelinesGroup> result = new ArrayList<LoadTimelinesGroup>();
|
||||
List<Resource> allResources = resourcesDAO.list(Resource.class);
|
||||
result.addAll(groupsFor(allResources));
|
||||
result.addAll(groupsFor(resourceAllocationDAO.findGenericAllocationsByCriterion()));
|
||||
result.addAll(groupsFor(resourcesToShow()));
|
||||
result.addAll(groupsFor(genericAllocationsByCriterion()));
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<Criterion, List<GenericResourceAllocation>> genericAllocationsByCriterion() {
|
||||
if (filter()) {
|
||||
return resourceAllocationDAO
|
||||
.findGenericAllocationsByCriterionFor(justTasks(filterBy
|
||||
.getTasksToSave()));
|
||||
} else {
|
||||
return resourceAllocationDAO.findGenericAllocationsByCriterion();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private List<Resource> resourcesToShow() {
|
||||
if (filter()) {
|
||||
return resourcesForActiveTasks();
|
||||
} else {
|
||||
return allResources();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean filter() {
|
||||
return filterBy != null;
|
||||
}
|
||||
|
||||
private List<Resource> resourcesForActiveTasks() {
|
||||
filterBy.reassociateResourcesWithSession(resourcesDAO);
|
||||
return resourcesDAO
|
||||
.findResourcesRelatedTo(justTasks(filterBy.getTasksToSave()));
|
||||
}
|
||||
|
||||
private List<Task> justTasks(Collection<? extends TaskElement> tasks) {
|
||||
List<Task> result = new ArrayList<Task>();
|
||||
for (TaskElement taskElement : tasks) {
|
||||
if (taskElement instanceof Task) {
|
||||
result.add((Task) taskElement);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Resource> allResources() {
|
||||
return resourcesDAO.list(Resource.class);
|
||||
}
|
||||
|
||||
private List<LoadTimelinesGroup> groupsFor(
|
||||
Map<Criterion, List<GenericResourceAllocation>> genericAllocationsByCriterion) {
|
||||
List<LoadTimelinesGroup> result = new ArrayList<LoadTimelinesGroup>();
|
||||
|
|
@ -237,6 +291,7 @@ public class ResourceLoadModel implements IResourceLoadModel {
|
|||
public Interval getViewInterval() {
|
||||
return viewInterval;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class PeriodsBuilder {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue