Skip to content

Commit

Permalink
#105 fix month selection
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausRicharz committed May 16, 2022
1 parent 1e0f6a3 commit e6d082c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
30 changes: 16 additions & 14 deletions src/main/java/org/tb/dailyreport/action/ShowDailyReportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static org.tb.common.util.DateUtils.formatDayOfMonth;
import static org.tb.common.util.DateUtils.formatMonth;
import static org.tb.common.util.DateUtils.formatYear;
import static org.tb.common.util.DateUtils.getDateAsStringArray;
import static org.tb.common.util.DateUtils.today;
import static org.tb.common.util.TimeFormatUtils.timeFormatMinutes;

Expand Down Expand Up @@ -171,8 +172,11 @@ public ActionForward executeAuthenticated(ActionMapping mapping, ShowDailyReport
actionResult = mapping.findForward("success");
} else {
//*** initialisation ***
init(request, reportForm);
//TODO: Hier bitte findForward zurückgeben.
var initForward = init(request, reportForm);
if(initForward != null) {
return mapping.findForward(initForward);
}

if (request.getParameter("day") != null && request.getParameter("month") != null && request.getParameter("year") != null) {
// these parameters are only set when user clicked on day in matrix view -> redirected to showDailyReport with specific date
String date = request.getParameter("year") + "-" + getMonthMMStringFromShortstring(request.getParameter("month")) + "-" + request.getParameter("day");
Expand Down Expand Up @@ -651,23 +655,21 @@ private LocalDate changeDate(LocalDate date, int change) {
* logged-in user.
*/
private String init(HttpServletRequest request, ShowDailyReportForm reportForm) {
String forward = "success";
Employee loginEmployee = (Employee) request.getSession().getAttribute("loginEmployee");
Employeecontract ec = new EmployeeViewHelper().getAndInitCurrentEmployee(request, employeeDAO, employeecontractDAO);
if (ec == null) {
request.setAttribute("errorMessage", "No employee contract found for employee - please call system administrator.");
forward = "error";
return forward;
return "error";
}
List<Employeecontract> employeecontracts = employeecontractDAO.getVisibleEmployeeContractsForAuthorizedUser();
if (employeecontracts == null || employeecontracts.isEmpty()) {
request.setAttribute("errorMessage", "No employees with valid contracts found - please call system administrator.");
forward = "error";
return forward;
return "error";
}

reportForm.setView(GlobalConstants.VIEW_DAILY);
reportForm.setShowOnlyValid(true);

request.getSession().setAttribute("view", GlobalConstants.VIEW_DAILY);
request.getSession().setAttribute("employeecontracts", employeecontracts);
request.getSession().setAttribute("years", getYearsToDisplay());
Expand Down Expand Up @@ -705,8 +707,8 @@ private String init(HttpServletRequest request, ShowDailyReportForm reportForm)
try {
workingday = refreshWorkingday(reportForm, request, workingdayDAO);
} catch (Exception e) {
forward = "error";
return forward;
log.error("Could not refreshWorkingday.", e);
return "error";
}

if (workingday != null) {
Expand Down Expand Up @@ -743,13 +745,13 @@ private String init(HttpServletRequest request, ShowDailyReportForm reportForm)

// call from main menu: set current month, year, timereports,
// orders, suborders...
LocalDate dt = today();
var dateStringArray = getDateAsStringArray(today());
// get day string (e.g., '31') from java.time.LocalDate
String dayString = formatDayOfMonth(dt);
String dayString = dateStringArray[0];
// get month string (e.g., 'Jan') from java.time.LocalDate
String monthString = formatMonth(dt);
String monthString = dateStringArray[1];
// get year string (e.g., '2006') from java.time.LocalDate
String yearString = formatYear(dt);
String yearString = dateStringArray[2];
request.getSession().setAttribute("currentDay", dayString);
request.getSession().setAttribute("currentMonth", monthString);
request.getSession().setAttribute("currentYear", yearString);
Expand Down Expand Up @@ -807,7 +809,7 @@ private String init(HttpServletRequest request, ShowDailyReportForm reportForm)
request.getSession().setAttribute("currentOrder", "ALL ORDERS");
request.getSession().setAttribute("currentOrderId", -1L);

return forward;
return null; // nothing to forward to
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions src/main/webapp/dailyreport/showDailyReport.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@
</html:image>
</c:when>
<c:otherwise>
<html:select property="month" value="<%=(String) request.getSession().getAttribute(\"currentMonth\")%>"
onchange="setUpdateTimereportsAction(this.form)" styleClass="make-select2">
<html:select property="month" onchange="setUpdateTimereportsAction(this.form)" styleClass="make-select2">
<html:option value="Jan">
<bean:message key="main.timereport.select.month.jan.text" />
</html:option>
Expand Down

0 comments on commit e6d082c

Please sign in to comment.