Allow to sort monthly timesheest in user dashboard

Moved internal class MonthlyTimesheet to a proper file and renamed to
MonthlyTimesheetDTO.

In MonthlyTimesheetDTO all the data showed in the list will be precalculated.

FEA: ItEr76S28UserDashboard
This commit is contained in:
Manuel Rego Casasnovas 2012-06-07 11:15:55 +02:00
parent bf0f733b90
commit bf1553829f
5 changed files with 126 additions and 77 deletions

View file

@ -34,18 +34,18 @@ import org.libreplan.business.workreports.entities.WorkReport;
public interface IMonthlyTimesheetsAreaModel {
/**
* Returns the list of {@link MonthlyTimesheet MonthlyTimesheets} for the
* Returns the list of {@link MonthlyTimesheetDTO MonthlyTimesheets} for the
* resource bound to current {@link User}.<br />
*
* There's no need that a {@link WorkReport} is saved in order to a
* {@link MonthlyTimesheet} exists for a month.<br />
* {@link MonthlyTimesheetDTO} exists for a month.<br />
*
* The list of {@link MonthlyTimesheet MonthlyTimesheets} will be since the
* The list of {@link MonthlyTimesheetDTO MonthlyTimesheets} will be since the
* date the resource is activated in the system (checking
* {@link CalendarAvailability} for the resource) to next month of current
* date.
*/
List<MonthlyTimesheet> getMonthlyTimesheets();
List<MonthlyTimesheetDTO> getMonthlyTimesheets();
/**
* Returns the number of different {@link OrderElement OrderElements} with

View file

@ -0,0 +1,92 @@
/*
* This file is part of LibrePlan
*
* Copyright (C) 2012 Igalia, S.L.
*
* 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.libreplan.web.users.dashboard;
import org.joda.time.LocalDate;
import org.libreplan.business.workingday.EffortDuration;
import org.libreplan.business.workreports.entities.WorkReport;
/**
* Simple class to represent the monthly timesheets to be shown in the list.<br />
*
* This is only a utility class for the UI, everything will be saved using
* {@link WorkReport} class.
*
* @author Manuel Rego Casasnovas <mrego@igalia.com>
*/
public class MonthlyTimesheetDTO {
private LocalDate date;
private WorkReport workReport;
private EffortDuration resourceCapacity;
private EffortDuration totalHours;
private int tasksNumber;
/**
* @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.
* @param resourceCapacity
* The capacity of the resource bound to current user in the
* month of this timesheet.
* @param totalHours
* Total hours worked by the resource bound to the current user
* in the monthly timesheet
* @param tasksNumber
* Number of tasks in the monthly timesheet
*/
MonthlyTimesheetDTO(LocalDate date, WorkReport workReport,
EffortDuration resourceCapacity, EffortDuration totalHours,
int tasksNumber) {
this.date = date.dayOfMonth().withMaximumValue();
this.workReport = workReport;
this.resourceCapacity = resourceCapacity;
this.totalHours = totalHours;
this.tasksNumber = tasksNumber;
}
public LocalDate getDate() {
return date;
}
public WorkReport getWorkReport() {
return workReport;
}
public EffortDuration getResourceCapacity() {
return resourceCapacity;
}
public EffortDuration getTotalHours() {
return totalHours;
}
public int getTasksNumber() {
return tasksNumber;
}
}

View file

@ -23,9 +23,6 @@ import java.util.List;
import javax.annotation.Resource;
import org.joda.time.LocalDate;
import org.libreplan.business.workingday.EffortDuration;
import org.libreplan.business.workreports.entities.WorkReport;
import org.libreplan.web.common.Util;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
@ -51,23 +48,15 @@ public class MonthlyTimesheetsAreaController extends GenericForwardComposer {
@Override
public void render(Row row, Object data) throws Exception {
final MonthlyTimesheet monthlyTimesheet = (MonthlyTimesheet) data;
final MonthlyTimesheetDTO monthlyTimesheet = (MonthlyTimesheetDTO) data;
row.setValue(monthlyTimesheet);
Util.appendLabel(row, monthlyTimesheet.getDate().toString("MMMM y"));
Util.appendLabel(row, monthlyTimesheet.getResourceCapacity()
.toFormattedString());
WorkReport workReport = monthlyTimesheet.getWorkReport();
EffortDuration hours = EffortDuration.zero();
int tasksNumber = 0;
if (workReport != null) {
hours = workReport.getTotalEffortDuration();
tasksNumber = monthlyTimesheetsAreaModel
.getNumberOfOrderElementsWithTrackedTime(workReport);
}
Util.appendLabel(row, hours.toFormattedString());
Util.appendLabel(row, tasksNumber + "");
Util.appendLabel(row, monthlyTimesheet.getTotalHours()
.toFormattedString());
Util.appendLabel(row, monthlyTimesheet.getTasksNumber() + "");
Util.appendOperationsAndOnClickEvent(row, new EventListener() {
@ -87,7 +76,7 @@ public class MonthlyTimesheetsAreaController extends GenericForwardComposer {
comp.setAttribute("controller", this);
}
public List<MonthlyTimesheet> getMonthlyTimesheets() {
public List<MonthlyTimesheetDTO> getMonthlyTimesheets() {
return monthlyTimesheetsAreaModel.getMonthlyTimesheets();
}
@ -95,50 +84,4 @@ public class MonthlyTimesheetsAreaController extends GenericForwardComposer {
return monthlyTimesheetsRenderer;
}
}
/**
* Simple class to represent the monthly timesheets to be shown in the list.<br />
*
* This is only a simple class for the UI, everything will be saved using
* {@link WorkReport}.
*/
class MonthlyTimesheet {
private LocalDate date;
private WorkReport workReport;
private EffortDuration resourceCapacity;
/**
* @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.
* @param resourceCapacity
* The capacity of the resource bound to current user in the
* month of this timesheet.
*/
MonthlyTimesheet(LocalDate date, WorkReport workReport,
EffortDuration resourceCapacity) {
this.date = date.dayOfMonth().withMaximumValue();
this.workReport = workReport;
this.resourceCapacity = resourceCapacity;
}
public LocalDate getDate() {
return date;
}
public WorkReport getWorkReport() {
return workReport;
}
public EffortDuration getResourceCapacity() {
return resourceCapacity;
}
}
}

View file

@ -58,7 +58,7 @@ public class MonthlyTimesheetsAreaModel implements IMonthlyTimesheetsAreaModel {
@Override
@Transactional(readOnly = true)
public List<MonthlyTimesheet> getMonthlyTimesheets() {
public List<MonthlyTimesheetDTO> getMonthlyTimesheets() {
User user = UserUtil.getUserFromSession();
if (!user.isBound()) {
return Collections.emptyList();
@ -72,19 +72,28 @@ public class MonthlyTimesheetsAreaModel implements IMonthlyTimesheetsAreaModel {
currentDate.plusMonths(1));
}
private List<MonthlyTimesheet> getMonthlyTimesheets(Resource resource,
private List<MonthlyTimesheetDTO> getMonthlyTimesheets(Resource resource,
LocalDate start, LocalDate end) {
int months = Months.monthsBetween(start, end).getMonths();
List<MonthlyTimesheet> result = new ArrayList<MonthlyTimesheet>();
List<MonthlyTimesheetDTO> result = new ArrayList<MonthlyTimesheetDTO>();
// In decreasing order to provide a list sorted with the more recent
// monthly timesheets at the beginning
for (int i = months; i >= 0; i--) {
LocalDate date = start.plusMonths(i);
result.add(new MonthlyTimesheet(date,
getWorkReport(resource, date), getResourceCapcity(resource,
date)));
WorkReport workReport = getWorkReport(resource, date);
EffortDuration hours = EffortDuration.zero();
int tasksNumber = 0;
if (workReport != null) {
hours = workReport.getTotalEffortDuration();
tasksNumber = getNumberOfOrderElementsWithTrackedTime(workReport);
}
result.add(new MonthlyTimesheetDTO(date, workReport,
getResourceCapcity(resource, date), hours, tasksNumber));
}
return result;

View file

@ -25,10 +25,15 @@
pageSize="10" rowRenderer="@{controller.monthlyTimesheetsRenderer}"
sclass="clickable-rows">
<columns sizable="true">
<column label="${i18n:_('Date')}" />
<column label="${i18n:_('Available hours')}" />
<column label="${i18n:_('Total work')}" />
<column label="${i18n:_('Number of tasks')}" />
<column label="${i18n:_('Date')}"
sort="auto(date)"
sortDirection="descending" />
<column label="${i18n:_('Available hours')}"
sort="auto(resourceCapacity)" />
<column label="${i18n:_('Total work')}"
sort="auto(totalHours)" />
<column label="${i18n:_('Number of tasks')}"
sort="auto(tasksNumber)" />
<column label="${i18n:_('Operations')}" />
</columns>
</grid>