Update representation of personal timesheets in the UI depending on periodicity

FEA: ItEr77S07PersonalTimesheetsPeriodictyConfiguration
This commit is contained in:
Manuel Rego Casasnovas 2012-08-28 11:15:24 +02:00
parent 7e24ddb8ac
commit 6ce91d6da9
6 changed files with 41 additions and 22 deletions

View file

@ -211,4 +211,10 @@ public interface IMonthlyTimesheetModel {
*/ */
PersonalTimesheetsPeriodicityEnum getPersonalTimesheetsPeriodicity(); PersonalTimesheetsPeriodicityEnum getPersonalTimesheetsPeriodicity();
/**
* Returns the string that represents the personal timesheet depending on
* the configured periodicity.
*/
String getTimesheetString();
} }

View file

@ -598,8 +598,8 @@ public class MonthlyTimesheetController extends GenericForwardComposer
columns.appendChild(total); columns.appendChild(total);
} }
public String getDate() { public String getTimesheetString() {
return monthlyTimesheetModel.getDate().toString("MMMM y"); return monthlyTimesheetModel.getTimesheetString();
} }
public String getResource() { public String getResource() {

View file

@ -92,13 +92,17 @@ public class MonthlyTimesheetDTO {
} }
public String toString(PersonalTimesheetsPeriodicityEnum periodicity) { public String toString(PersonalTimesheetsPeriodicityEnum periodicity) {
return toString(periodicity, date);
}
public static String toString(PersonalTimesheetsPeriodicityEnum periodicity, LocalDate date) {
switch (periodicity) { switch (periodicity) {
case WEEKLY: case WEEKLY:
return _("Week {0}", date.toString("w")); return _("Week {0}", date.toString("w"));
case TWICE_MONTHLY: case TWICE_MONTHLY:
return (date.getDayOfMonth() <= 15) ? return (date.getDayOfMonth() <= 15) ?
_("{0} 1st fortnight",date.toString("MMMM")) : _("{0} 1st fortnight", date.toString("MMMM")) :
_("{0} 2nd fortnight",date.toString("MMMM")); _("{0} 2nd fortnight", date.toString("MMMM"));
case MONTHLY: case MONTHLY:
default: default:
return date.toString("MMMM y"); return date.toString("MMMM y");

View file

@ -566,4 +566,9 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
.getPersonalTimesheetsPeriodicity(); .getPersonalTimesheetsPeriodicity();
} }
@Override
public String getTimesheetString() {
return MonthlyTimesheetDTO.toString(periodicity, date);
}
} }

View file

@ -23,6 +23,7 @@ import static org.libreplan.web.I18nHelper._;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.libreplan.business.common.Registry;
import org.libreplan.web.common.IMessagesForUser; import org.libreplan.web.common.IMessagesForUser;
import org.libreplan.web.common.Level; import org.libreplan.web.common.Level;
import org.libreplan.web.common.MessagesForUser; import org.libreplan.web.common.MessagesForUser;
@ -54,8 +55,11 @@ public class UserDashboardController extends GenericForwardComposer {
String timesheetSave = Executions.getCurrent().getParameter( String timesheetSave = Executions.getCurrent().getParameter(
"timesheet_saved"); "timesheet_saved");
if (!StringUtils.isBlank(timesheetSave)) { if (!StringUtils.isBlank(timesheetSave)) {
String monthlyTimesheet = new LocalDate(timesheetSave) String monthlyTimesheet = MonthlyTimesheetDTO.toString(Registry
.toString("MMMM y"); .getConfigurationDAO()
.getConfigurationWithReadOnlyTransaction()
.getPersonalTimesheetsPeriodicity(), new LocalDate(
timesheetSave));
messagesForUser.showMessage(Level.INFO, messagesForUser.showMessage(Level.INFO,
_("Personal timesheet \"{0}\" saved", monthlyTimesheet)); _("Personal timesheet \"{0}\" saved", monthlyTimesheet));
} }

View file

@ -48,22 +48,22 @@
<rows> <rows>
<row> <row>
<label value="${i18n:_('Date')}" /> <label value="${i18n:_('Date')}" />
<hbox align="pack"> <hbox align="pack">
<div visible="@{controller.currentUser}"> <div visible="@{controller.currentUser}">
<button id="previousMonth" <button id="previousMonth"
image="/common/img/ico_step_left.png" sclass="icono" image="/common/img/ico_step_left.png" sclass="icono"
onClick="controller.previousMonth();" onClick="controller.previousMonth();"
tooltiptext="${i18n:_('Previous')}" tooltiptext="${i18n:_('Previous')}"
disabled="@{controller.firstMonth}" /> disabled="@{controller.firstMonth}" />
</div> </div>
<label value="@{controller.timesheetString}" />
<label value="@{controller.date}" /> <div visible="@{controller.currentUser}">
<div visible="@{controller.currentUser}"> <button id="nextMonth"
<button id="nextMonth" onClick="controller.nextMonth();" image="/common/img/ico_step_right.png"
onClick="controller.nextMonth();" image="/common/img/ico_step_right.png" tooltiptext="${i18n:_('Next')}" sclass="icono"
tooltiptext="${i18n:_('Next')}" sclass="icono" disabled="@{controller.lastMonth}" />
disabled="@{controller.lastMonth}" /> </div>
</div></hbox> </hbox>
</row> </row>
<row> <row>
<label value="${i18n:_('Resource')}" /> <label value="${i18n:_('Resource')}" />