ItEr60S15AnA04S11RFAdaptacionFiltradosInformes : filters by criterions in the HoursWorkedPerWorker report.
This commit is contained in:
parent
18ac416125
commit
29dcd81a68
7 changed files with 309 additions and 10 deletions
|
|
@ -131,7 +131,8 @@ public interface IResourceDAO extends IIntegrationEntityDAO<Resource> {
|
|||
* @return
|
||||
*/
|
||||
public List<HoursWorkedPerResourceDTO> getWorkingHoursPerWorker(
|
||||
List<Resource> resources, List<Label> labels, Date startingDate,
|
||||
List<Resource> resources, List<Label> labels,
|
||||
List<Criterion> criterions, Date startingDate,
|
||||
Date endingDate);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -223,7 +223,8 @@ public class ResourceDAO extends IntegrationEntityDAO<Resource> implements
|
|||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<HoursWorkedPerResourceDTO> getWorkingHoursPerWorker(
|
||||
List<Resource> resources, List<Label> labels, Date startingDate,
|
||||
List<Resource> resources, List<Label> labels,
|
||||
List<Criterion> criterions, Date startingDate,
|
||||
Date endingDate) {
|
||||
|
||||
String strQuery = "SELECT new org.navalplanner.business.reports.dtos.HoursWorkedPerResourceDTO(resource, wrl) "
|
||||
|
|
@ -253,6 +254,12 @@ public class ResourceDAO extends IntegrationEntityDAO<Resource> implements
|
|||
+ "OR EXISTS (FROM wrl.workReport.labels as etqwr WHERE etqwr IN (:labels))) ";
|
||||
}
|
||||
|
||||
// Set Criterions
|
||||
if (criterions != null && !criterions.isEmpty()) {
|
||||
strQuery += "AND EXISTS (FROM resource.criterionSatisfactions as satisfaction "
|
||||
+ " WHERE satisfaction.criterion IN (:criterions))";
|
||||
}
|
||||
|
||||
// Order by
|
||||
strQuery += "ORDER BY resource.id, wrl.date";
|
||||
|
||||
|
|
@ -270,6 +277,9 @@ public class ResourceDAO extends IntegrationEntityDAO<Resource> implements
|
|||
if (labels != null && !labels.isEmpty()) {
|
||||
query.setParameterList("labels", labels);
|
||||
}
|
||||
if (criterions != null && !criterions.isEmpty()) {
|
||||
query.setParameterList("criterions", criterions);
|
||||
}
|
||||
|
||||
// Get result
|
||||
return query.list();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* This file is part of ###PROJECT_NAME###
|
||||
*
|
||||
* Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
|
||||
* Desenvolvemento Tecnolóxico de Galicia
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.web.common.components.finders;
|
||||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.navalplanner.business.resources.daos.ICriterionDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.zkoss.zul.Listcell;
|
||||
import org.zkoss.zul.Listitem;
|
||||
import org.zkoss.zul.ListitemRenderer;
|
||||
|
||||
/**
|
||||
* Bandbox finder for {@link Criterion}.
|
||||
* @author Susana Montes Pedreira <smontes@wirelessgalicia.com>
|
||||
*/
|
||||
@Repository
|
||||
public class CriterionBandboxFinder extends BandboxFinder implements IBandboxFinder {
|
||||
|
||||
@Autowired
|
||||
private ICriterionDAO criterionDAO;
|
||||
|
||||
private final String headers[] = { _("Type"), _("Criterion Name") };
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<Criterion> getAll() {
|
||||
List<Criterion> criterions = criterionDAO.findAll();
|
||||
forLoadCriterions(criterions);
|
||||
return criterions;
|
||||
}
|
||||
|
||||
private void forLoadCriterions(List<Criterion> criterions) {
|
||||
for (Criterion criterion : criterions) {
|
||||
criterion.getName();
|
||||
criterion.getType().getName();
|
||||
if (criterion.getParent() != null) {
|
||||
criterion.getParent().getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean entryMatchesText(Object obj, String text) {
|
||||
Criterion criterion = (Criterion) obj;
|
||||
text = text.trim().toLowerCase();
|
||||
return (criterion.getType().getName().toLowerCase().contains(text) || getNamesHierarchy(
|
||||
criterion, new String())
|
||||
.toLowerCase().contains(text));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public String objectToString(Object obj) {
|
||||
Criterion criterion = (Criterion) obj;
|
||||
return criterion.getType().getName() + " :: "
|
||||
+ getNamesHierarchy(criterion, new String());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHeaders() {
|
||||
return headers.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListitemRenderer getItemRenderer() {
|
||||
return orderRenderer;
|
||||
}
|
||||
|
||||
private final ListitemRenderer orderRenderer = new ListitemRenderer() {
|
||||
|
||||
@Override
|
||||
public void render(Listitem item, Object data) throws Exception {
|
||||
Criterion criterion = (Criterion)data;
|
||||
item.setValue(criterion);
|
||||
|
||||
Listcell criterionType = new Listcell();
|
||||
criterionType.setLabel(criterion.getType().getName());
|
||||
criterionType.setParent(item);
|
||||
|
||||
Listcell criterionName = new Listcell();
|
||||
criterionName.setLabel(getNamesHierarchy(criterion,new String()));
|
||||
criterionName.setParent(item);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private String getNamesHierarchy(Criterion criterion,String etiqueta){
|
||||
Criterion parent = criterion.getParent();
|
||||
if(parent != null){
|
||||
etiqueta = getNamesHierarchy(parent,etiqueta);
|
||||
etiqueta = etiqueta.concat(" -> ");
|
||||
}
|
||||
return etiqueta.concat(criterion.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ import java.util.Set;
|
|||
import net.sf.jasperreports.engine.JRDataSource;
|
||||
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.web.common.Util;
|
||||
|
|
@ -64,6 +65,8 @@ public class HoursWorkedPerWorkerController extends NavalplannerReportController
|
|||
|
||||
private Listbox lbLabels;
|
||||
|
||||
private Listbox lbCriterions;
|
||||
|
||||
private Datebox startingDate;
|
||||
|
||||
private Datebox endingDate;
|
||||
|
|
@ -72,12 +75,15 @@ public class HoursWorkedPerWorkerController extends NavalplannerReportController
|
|||
|
||||
private BandboxSearch bdLabels;
|
||||
|
||||
private BandboxSearch bdCriterions;
|
||||
|
||||
private ResourceListRenderer resourceListRenderer = new ResourceListRenderer();
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
comp.setVariable("controller", this, true);
|
||||
hoursWorkedPerWorkerModel.init();
|
||||
}
|
||||
|
||||
public Set<Resource> getResources() {
|
||||
|
|
@ -93,6 +99,7 @@ public class HoursWorkedPerWorkerController extends NavalplannerReportController
|
|||
protected JRDataSource getDataSource() {
|
||||
return hoursWorkedPerWorkerModel.getHoursWorkedPerWorkerReport(
|
||||
getSelectedResources(), getSelectedLabels(),
|
||||
getSelectedCriterions(),
|
||||
getStartingDate(), getEndingDate());
|
||||
}
|
||||
|
||||
|
|
@ -278,4 +285,34 @@ public class HoursWorkedPerWorkerController extends NavalplannerReportController
|
|||
public List<Label> getSelectedLabels() {
|
||||
return hoursWorkedPerWorkerModel.getSelectedLabels();
|
||||
}
|
||||
|
||||
public List<Criterion> getAllCriterions() {
|
||||
return hoursWorkedPerWorkerModel.getCriterions();
|
||||
}
|
||||
|
||||
public void onSelectCriterion() {
|
||||
Criterion criterion = (Criterion) bdCriterions.getSelectedElement();
|
||||
if (criterion == null) {
|
||||
throw new WrongValueException(bdCriterions,
|
||||
_("please, select a Criterion"));
|
||||
}
|
||||
boolean result = hoursWorkedPerWorkerModel
|
||||
.addSelectedCriterion(criterion);
|
||||
if (!result) {
|
||||
throw new WrongValueException(bdCriterions,
|
||||
_("This Criterion has already been added."));
|
||||
} else {
|
||||
Util.reloadBindings(lbCriterions);
|
||||
}
|
||||
}
|
||||
|
||||
public void onRemoveCriterion(Criterion criterion) {
|
||||
hoursWorkedPerWorkerModel.removeSelectedCriterion(criterion);
|
||||
Util.reloadBindings(lbCriterions);
|
||||
}
|
||||
|
||||
public List<Criterion> getSelectedCriterions() {
|
||||
return hoursWorkedPerWorkerModel.getSelectedCriterions();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -33,8 +33,12 @@ import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
|
|||
import org.navalplanner.business.labels.daos.ILabelDAO;
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.reports.dtos.HoursWorkedPerResourceDTO;
|
||||
import org.navalplanner.business.resources.daos.ICriterionTypeDAO;
|
||||
import org.navalplanner.business.resources.daos.IResourceDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.CriterionType;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.ResourceEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
|
@ -55,19 +59,33 @@ public class HoursWorkedPerWorkerModel implements IHoursWorkedPerWorkerModel {
|
|||
@Autowired
|
||||
private ILabelDAO labelDAO;
|
||||
|
||||
@Autowired
|
||||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
|
||||
private Set<Resource> selectedResources = new HashSet<Resource>();
|
||||
|
||||
private List<Label> selectedLabels = new ArrayList<Label>();
|
||||
|
||||
private List<Criterion> selectedCriterions = new ArrayList<Criterion>();
|
||||
|
||||
private List<Criterion> allCriterions = new ArrayList<Criterion>();
|
||||
|
||||
private static List<ResourceEnum> applicableResources = new ArrayList<ResourceEnum>();
|
||||
|
||||
static {
|
||||
applicableResources.add(ResourceEnum.RESOURCE);
|
||||
applicableResources.add(ResourceEnum.WORKER);
|
||||
}
|
||||
|
||||
private boolean showReportMessage = false;
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public JRDataSource getHoursWorkedPerWorkerReport(List<Resource> resources,
|
||||
List<Label> labels,
|
||||
Date startingDate, Date endingDate) {
|
||||
List<Label> labels, List<Criterion> criterions, Date startingDate,
|
||||
Date endingDate) {
|
||||
|
||||
final List<HoursWorkedPerResourceDTO> workingHoursPerWorkerList = resourceDAO
|
||||
.getWorkingHoursPerWorker(resources, labels, startingDate,
|
||||
.getWorkingHoursPerWorker(resources, labels, criterions, startingDate,
|
||||
endingDate);
|
||||
|
||||
if (workingHoursPerWorkerList != null && !workingHoursPerWorkerList.isEmpty()) {
|
||||
|
|
@ -80,8 +98,14 @@ public class HoursWorkedPerWorkerModel implements IHoursWorkedPerWorkerModel {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public void init() {
|
||||
this.selectedResources.clear();
|
||||
this.selectedLabels.clear();
|
||||
this.selectedCriterions.clear();
|
||||
|
||||
allCriterions.clear();
|
||||
loadAllCriterions();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -141,4 +165,65 @@ public class HoursWorkedPerWorkerModel implements IHoursWorkedPerWorkerModel {
|
|||
public List<Label> getSelectedLabels() {
|
||||
return selectedLabels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Criterion> getCriterions() {
|
||||
return this.allCriterions;
|
||||
}
|
||||
|
||||
private void loadAllCriterions() {
|
||||
List<CriterionType> listTypes = getCriterionTypes();
|
||||
for (CriterionType criterionType : listTypes) {
|
||||
if (criterionType.isEnabled()) {
|
||||
Set<Criterion> listCriterion = getDirectCriterions(criterionType);
|
||||
addCriterionWithItsType(listCriterion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Set<Criterion> getDirectCriterions(
|
||||
CriterionType criterionType) {
|
||||
Set<Criterion> criterions = new HashSet<Criterion>();
|
||||
for (Criterion criterion : criterionType.getCriterions()) {
|
||||
if (criterion.getParent() == null) {
|
||||
criterions.add(criterion);
|
||||
}
|
||||
}
|
||||
return criterions;
|
||||
}
|
||||
|
||||
private void addCriterionWithItsType(Set<Criterion> children) {
|
||||
for (Criterion criterion : children) {
|
||||
if (criterion.isActive()) {
|
||||
// Add to the list
|
||||
allCriterions.add(criterion);
|
||||
addCriterionWithItsType(criterion.getChildren());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<CriterionType> getCriterionTypes() {
|
||||
return criterionTypeDAO
|
||||
.getCriterionTypesByResources(applicableResources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSelectedCriterion(Criterion criterion) {
|
||||
this.selectedCriterions.remove(criterion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addSelectedCriterion(Criterion criterion) {
|
||||
if (this.selectedCriterions.contains(criterion)) {
|
||||
return false;
|
||||
}
|
||||
this.selectedCriterions.add(criterion);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Criterion> getSelectedCriterions() {
|
||||
return selectedCriterions;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.util.Set;
|
|||
import net.sf.jasperreports.engine.JRDataSource;
|
||||
|
||||
import org.navalplanner.business.labels.entities.Label;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
|
||||
/**
|
||||
|
|
@ -37,7 +38,7 @@ import org.navalplanner.business.resources.entities.Resource;
|
|||
public interface IHoursWorkedPerWorkerModel {
|
||||
|
||||
JRDataSource getHoursWorkedPerWorkerReport(List<Resource> resources,
|
||||
List<Label> labels,
|
||||
List<Label> labels, List<Criterion> criterions,
|
||||
Date startingDate, Date endingDate);
|
||||
|
||||
void init();
|
||||
|
|
@ -58,4 +59,11 @@ public interface IHoursWorkedPerWorkerModel {
|
|||
|
||||
List<Label> getAllLabels();
|
||||
|
||||
List<Criterion> getSelectedCriterions();
|
||||
|
||||
void removeSelectedCriterion(Criterion criterion);
|
||||
|
||||
boolean addSelectedCriterion(Criterion criterion);
|
||||
|
||||
List<Criterion> getCriterions();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,11 +112,10 @@
|
|||
<hbox>
|
||||
<bandboxSearch id="bdLabels" finder="LabelBandboxFinder"
|
||||
model="@{controller.allLabels}" />
|
||||
<button label="${i18n:_('Assign')}"
|
||||
<button label="${i18n:_('Add')}"
|
||||
onClick="controller.onSelectLabel()"
|
||||
style="margin-top: -4px" />
|
||||
</hbox>
|
||||
</vbox>
|
||||
<separator spacing="10px"/>
|
||||
<listbox id="lbLabels"
|
||||
width="700px"
|
||||
|
|
@ -142,6 +141,47 @@
|
|||
</panelchildren>
|
||||
</panel>
|
||||
|
||||
<!-- Assign Criterion -->
|
||||
<panel title="${i18n:_('Filter by criterions')}" border="normal"
|
||||
style="overflow:auto">
|
||||
<panelchildren>
|
||||
<vbox>
|
||||
<separator spacing="5px"/>
|
||||
<hbox>
|
||||
<bandboxSearch id="bdCriterions" finder="CriterionBandboxFinder"
|
||||
model="@{controller.allCriterions}" />
|
||||
<button label="${i18n:_('Add')}"
|
||||
onClick="controller.onSelectCriterion()"
|
||||
style="margin-top: -4px" />
|
||||
</hbox>
|
||||
</vbox>
|
||||
<separator spacing="10px"/>
|
||||
<listbox id="lbCriterions"
|
||||
width="700px"
|
||||
multiple="true"
|
||||
model="@{controller.selectedCriterions}">
|
||||
<listhead>
|
||||
<listheader label="${i18n:_('Type')}" align="center" />
|
||||
<listheader label="${i18n:_('Name')}" align="center" />
|
||||
<listheader label="${i18n:_('Operations')}" align="center" width="100px"/>
|
||||
</listhead>
|
||||
<listitem self="@{each='criterion'}" value="@{criterion}">
|
||||
<listcell label="@{criterion.type.name}" />
|
||||
<listcell label="@{criterion.name}" />
|
||||
<listcell>
|
||||
<button sclass="icono" image="/common/img/ico_borrar1.png"
|
||||
hoverImage="/common/img/ico_borrar.png"
|
||||
tooltiptext="${i18n:_('Delete')}"
|
||||
onClick="controller.onRemoveCriterion(self.parent.parent.value);">
|
||||
</button>
|
||||
</listcell>
|
||||
</listitem>
|
||||
</listbox>
|
||||
</panelchildren>
|
||||
</panel>
|
||||
|
||||
<separator spacing="10px" orient="horizontal" />
|
||||
|
||||
<!-- Select output format -->
|
||||
<panel title="${i18n:_('Format')}" border="normal"
|
||||
style="overflow:auto">
|
||||
|
|
@ -162,8 +202,6 @@
|
|||
</panelchildren>
|
||||
</panel>
|
||||
|
||||
<separator spacing="10px" orient="horizontal" />
|
||||
|
||||
<hbox style="display: none" id="URItext">
|
||||
<label value="${i18n:_('Click on ')}" />
|
||||
<toolbarbutton id="URIlink" class="z-label" zclass="z-label"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue