Disable finished checkbox in work reports UI if the task is already finished

FEA: ItEr77S12AdaptPlanningAccordingTimesheets
This commit is contained in:
Manuel Rego Casasnovas 2012-11-02 12:36:27 +01:00
parent 6c3a915b8d
commit d07686af7e
4 changed files with 47 additions and 0 deletions

View file

@ -27,6 +27,16 @@ import java.util.Collection;
*/
public class Util {
public static boolean equals(BaseEntity entity1, BaseEntity entity2) {
if (entity1 == null || entity2 == null) {
return false;
}
if (entity1.getId() == null || entity2.getId() == null) {
return false;
}
return entity1.getId().equals(entity2.getId());
}
public static boolean contains(Collection<? extends BaseEntity> collection,
BaseEntity entity) {
for (BaseEntity each : collection) {

View file

@ -245,4 +245,10 @@ public interface IWorkReportModel extends IIntegrationEntityModel {
WorkReportLine getFirstWorkReportLine();
/**
* Checks if an {@link OrderElement} is finished or not in any
* {@link WorkReportLine} of this report or other report.
*/
boolean isFinished(OrderElement orderElement);
}

View file

@ -1249,6 +1249,11 @@ public class WorkReportCRUDController extends GenericForwardComposer implements
}
});
if (!line.isFinished()
&& workReportModel.isFinished(line.getOrderElement())) {
finished.setDisabled(true);
}
row.appendChild(finished);
}

View file

@ -34,6 +34,7 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
import org.hibernate.Hibernate;
import org.libreplan.business.common.IntegrationEntity;
import org.libreplan.business.common.Util;
import org.libreplan.business.common.daos.IConfigurationDAO;
import org.libreplan.business.common.entities.EntityNameEnum;
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
@ -51,6 +52,7 @@ import org.libreplan.business.resources.daos.IWorkerDAO;
import org.libreplan.business.resources.entities.Resource;
import org.libreplan.business.resources.entities.Worker;
import org.libreplan.business.workreports.daos.IWorkReportDAO;
import org.libreplan.business.workreports.daos.IWorkReportLineDAO;
import org.libreplan.business.workreports.daos.IWorkReportTypeDAO;
import org.libreplan.business.workreports.entities.WorkReport;
import org.libreplan.business.workreports.entities.WorkReportLabelTypeAssigment;
@ -86,6 +88,9 @@ public class WorkReportModel extends IntegrationEntityModel implements
@Autowired
private IWorkReportDAO workReportDAO;
@Autowired
private IWorkReportLineDAO workReportLineDAO;
@Autowired
private IOrderElementDAO orderElementDAO;
@ -653,4 +658,25 @@ public class WorkReportModel extends IntegrationEntityModel implements
return workReport.getWorkReportLines().iterator().next();
}
@Override
@Transactional(readOnly = true)
public boolean isFinished(OrderElement orderElement) {
for (WorkReportLine line : workReport.getWorkReportLines()) {
if (line.isFinished()
&& Util.equals(line.getOrderElement(), orderElement)) {
return true;
}
}
List<WorkReportLine> lines = workReportLineDAO
.findByOrderElementNotInWorkReportAnotherTransaction(
orderElement, workReport);
for (WorkReportLine line : lines) {
if (line.isFinished()) {
return true;
}
}
return false;
}
}