diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/IResourceLoadModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/IResourceLoadModel.java index dd3abb5f1..6ea40c601 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/IResourceLoadModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/IResourceLoadModel.java @@ -23,6 +23,7 @@ package org.libreplan.web.resourceload; import org.libreplan.business.orders.entities.Order; import org.libreplan.business.planner.entities.TaskElement; +import org.libreplan.business.users.entities.User; public interface IResourceLoadModel { @@ -35,4 +36,6 @@ public interface IResourceLoadModel { boolean isExpandResourceLoadViewCharts(); + User getUser(); + } 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 98402b415..1ef04c51c 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 @@ -152,6 +152,7 @@ public class ResourceLoadController implements Composer { this.parent = comp; } + public void reload() { reloader.resetToInitialState(); reloadWithoutReset(); @@ -280,21 +281,12 @@ public class ResourceLoadController implements Composer { filterBy); result.add(filterTypeChanger); - User user; LocalDate startDate = (LocalDate) Sessions.getCurrent().getAttribute( "resourceLoadStartDate"); LocalDate endDate = (LocalDate) Sessions.getCurrent().getAttribute( "resourceLoadEndDate"); - List bandboxFilterPairs = (List) Sessions - .getCurrent() - .getAttribute( - "resourceLoadFilterWorkerOrCriterion"); - try { - user = this.userDAO.findByLoginName(SecurityUtils - .getSessionUserLoginName()); - } catch (InstanceNotFoundException e) { - throw new RuntimeException(e); - } + + User user = resourceLoadModel.getUser(); // Calculate filter based on user preferences if (user != null) { @@ -315,20 +307,14 @@ public class ResourceLoadController implements Composer { } result.add(new ByDatesFilter(onChange, filterBy, startDate, endDate)); - WorkersOrCriteriaBandbox bandbox = new WorkersOrCriteriaBandbox( - onChange, filterBy, filterTypeChanger, resourcesSearcher); - if (bandboxFilterPairs != null && !bandboxFilterPairs.isEmpty()) { - for (FilterPair filterPair : bandboxFilterPairs) { - bandbox.getBandBox().addSelectedElement(filterPair); - } - } else if ((user != null) - && (user.getResourcesLoadFilterCriterion() != null)) { - bandboxFilterPairs = new ArrayList(); - bandboxFilterPairs.add(new FilterPair(ResourceFilterEnum.Criterion, - user.getResourcesLoadFilterCriterion().getFinderPattern(), - user.getResourcesLoadFilterCriterion())); - } + List filterPairs = (List) Sessions + .getCurrent().getAttribute( + "resourceLoadFilterWorkerOrCriterion"); + + WorkersOrCriteriaBandbox bandbox = new WorkersOrCriteriaBandbox( + onChange, filterBy, filterTypeChanger, resourcesSearcher, filterPairs); + result.add(bandbox); result.add(new ByNamePaginator(onChange, filterBy, filterTypeChanger, bandbox)); @@ -572,19 +558,19 @@ public class ResourceLoadController implements Composer { private List entitiesSelected = null; + private List bandboxParameters = null; + private final IResourcesSearcher resourcesSearcher; private Label label = new Label(); - public BandboxMultipleSearch getBandBox() { - return bandBox; - } - private WorkersOrCriteriaBandbox(Runnable onChange, PlanningState filterBy, FilterTypeChanger filterType, - IResourcesSearcher resourcesSearcher) { + IResourcesSearcher resourcesSearcher, + List bandboxParameters) { super(onChange, filterBy, filterType); this.resourcesSearcher = resourcesSearcher; + this.bandboxParameters = bandboxParameters; } @Override @@ -613,6 +599,14 @@ public class ResourceLoadController implements Composer { } }); + // Seems to fill combobox, but does not filter + if ((bandboxParameters != null) && !bandboxParameters.isEmpty()) { + for (FilterPair filterPair : bandboxParameters) { + bandBox.addSelectedElement(filterPair); + } + entitiesSelected = getSelected(); + } + Hbox hbox = new Hbox(); hbox.appendChild(getLabel()); hbox.appendChild(bandBox); @@ -685,6 +679,27 @@ public class ResourceLoadController implements Composer { return resources; } + private List calculateManualResourcesToShow() { + List resources = new ArrayList(); + List criteria = new ArrayList(); + + + for (Object each : entitiesSelected) { + if (each instanceof Resource) { + resources.add((Resource) each); + } else { + criteria.add((Criterion) each); + } + } + + if (!criteria.isEmpty()) { + resources.addAll(resourcesSearcher.searchBoth() + .byCriteria(criteria).execute()); + } + + return resources; + } + public boolean hasEntitiesSelected() { return entitiesSelected != null && !entitiesSelected.isEmpty(); } @@ -699,12 +714,6 @@ public class ResourceLoadController implements Composer { return result; } - public void addSelectedElementsToBandbox(List criterion) { - for (FilterPair object : criterion) { - bandBox.addSelectedElement(object); - } - } - } private static class ByNamePaginator extends DependingOnFiltering diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadModel.java b/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadModel.java index 0836720a7..e3e6782ed 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadModel.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/resourceload/ResourceLoadModel.java @@ -1065,6 +1065,23 @@ public class ResourceLoadModel implements IResourceLoadModel { return user.isExpandResourceLoadViewCharts(); } + @Override + @Transactional(readOnly = true) + public User getUser() { + User user; + try { + user = this.userDAO.findByLoginName(SecurityUtils + .getSessionUserLoginName()); + } catch (InstanceNotFoundException e) { + throw new RuntimeException(e); + } + // Attach filter bandbox elements + if (user.getResourcesLoadFilterCriterion() != null) { + user.getResourcesLoadFilterCriterion().getFinderPattern(); + } + return user; + } + } class PeriodBuilderFactory {