Add total work column in monthly timesheets area

FEA: ItEr76S28UserDashboard
This commit is contained in:
Manuel Rego Casasnovas 2012-05-30 16:00:40 +02:00
parent c373c454fa
commit 991599fc80
4 changed files with 50 additions and 8 deletions

View file

@ -48,7 +48,9 @@ public interface IWorkReportDAO extends IIntegrationEntityDAO<WorkReport> {
/**
* Returns the {@link WorkReport} of the predefined type monthly timesheet
* for the given <code>resource</code> in the specified <code>date</code>.
* for the given <code>resource</code> in the specified <code>date</code>.<br />
*
* If there isn't any, it returns <code>null</code>.
*/
WorkReport getMonthlyTimesheetWorkReport(Resource resource, LocalDate date);

View file

@ -55,6 +55,10 @@ public class MonthlyTimesheetsAreaController extends GenericForwardComposer {
Util.appendLabel(row, monthlyTimesheet.getDate().toString("MMMM y"));
WorkReport workReport = monthlyTimesheet.getWorkReport();
Util.appendLabel(row, workReport.getTotalEffortDuration()
.toFormattedString());
Util.appendOperationsAndOnClickEvent(row, new EventListener() {
@Override
@ -90,17 +94,30 @@ public class MonthlyTimesheetsAreaController extends GenericForwardComposer {
* {@link WorkReport}.
*/
class MonthlyTimesheet {
private LocalDate date;
private WorkReport workReport;
/**
* Only the year and month are used, the day is reseted to first day of the
* month. As there's only one timesheet per month.
* @param date
* Only the year and month are used, the day is reseted to first
* day of the month. As there's only one timesheet per month.
* @param workReport
* The work report of the monthly timesheet, it could be
* <code>null</code> if it doesn't exist yet.
*/
MonthlyTimesheet(LocalDate date) {
this.date = new LocalDate(date.getYear(), date.getMonthOfYear(), 1);
MonthlyTimesheet(LocalDate date, WorkReport workReport) {
this.date = date.dayOfMonth().withMaximumValue();
this.workReport = workReport;
}
public LocalDate getDate() {
return date;
}
public WorkReport getWorkReport() {
return workReport;
}
}

View file

@ -25,9 +25,14 @@ import java.util.List;
import org.joda.time.LocalDate;
import org.joda.time.Months;
import org.libreplan.business.resources.entities.Resource;
import org.libreplan.business.resources.entities.Worker;
import org.libreplan.business.users.entities.User;
import org.libreplan.business.workreports.daos.IWorkReportDAO;
import org.libreplan.business.workreports.entities.WorkReport;
import org.libreplan.business.workreports.entities.WorkReportType;
import org.libreplan.web.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
@ -42,6 +47,9 @@ import org.springframework.transaction.annotation.Transactional;
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class MonthlyTimesheetsAreaModel implements IMonthlyTimesheetsAreaModel {
@Autowired
private IWorkReportDAO workReportDAO;
@Override
@Transactional(readOnly = true)
public List<MonthlyTimesheet> getMonthlyTimesheets() {
@ -52,10 +60,11 @@ public class MonthlyTimesheetsAreaModel implements IMonthlyTimesheetsAreaModel {
LocalDate activationDate = getActivationDate(user.getWorker());
LocalDate currentDate = new LocalDate();
return getMonthlyTimesheets(activationDate, currentDate.plusMonths(1));
return getMonthlyTimesheets(user.getWorker(), activationDate,
currentDate.plusMonths(1));
}
private List<MonthlyTimesheet> getMonthlyTimesheets(
private List<MonthlyTimesheet> getMonthlyTimesheets(Resource resource,
LocalDate start, LocalDate end) {
int months = Months.monthsBetween(start, end).getMonths();
@ -64,12 +73,25 @@ public class MonthlyTimesheetsAreaModel implements IMonthlyTimesheetsAreaModel {
// In decreasing order to provide a list sorted with the more recent
// monthly timesheets at the beginning
for (int i = months; i >= 0; i--) {
result.add(new MonthlyTimesheet(start.plusMonths(i)));
LocalDate date = start.plusMonths(i);
WorkReport workReport = workReportDAO
.getMonthlyTimesheetWorkReport(resource, date);
forceLoad(workReport);
result.add(new MonthlyTimesheet(date, workReport));
}
return result;
}
private void forceLoad(WorkReport workReport) {
if (workReport != null) {
WorkReportType workReportType = workReport.getWorkReportType();
workReportType.getLineFields().size();
workReportType.getWorkReportLabelTypeAssigments().size();
workReportType.getHeadingFields().size();
}
}
private LocalDate getActivationDate(Worker worker) {
return worker.getCalendar().getFistCalendarAvailability()
.getStartDate();

View file

@ -25,6 +25,7 @@
pageSize="10" rowRenderer="@{controller.monthlyTimesheetsRenderer}">
<columns sizable="true">
<column label="${i18n:_('Date')}" />
<column label="${i18n:_('Total work')}" />
<column label="${i18n:_('Operations')}" />
</columns>
</grid>