Skip to content

Commit

Permalink
#108 add memory for last stored time report, use it when initializing…
Browse files Browse the repository at this point in the history
… the form
  • Loading branch information
KlausRicharz committed May 16, 2022
1 parent fc57d8a commit f62f633
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/tb/chicoree/ChicoreeSessionStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static java.util.Locale.GERMAN;
import static org.tb.common.util.DateUtils.format;

import java.io.Serializable;
import java.time.Duration;
import java.time.LocalDate;
import java.util.Collections;
Expand All @@ -12,6 +13,7 @@
import java.util.Optional;
import java.util.stream.Collectors;
import javax.servlet.http.HttpSession;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.tb.common.OptionItem;
Expand Down Expand Up @@ -111,6 +113,14 @@ public void setCustomerorder(long customerorderId, List<Employeeorder> orders) {
httpSession.setAttribute("suborderOptions", suborderOptions);
}

public void setLastStoredTimereport(TimereportData timereportData) {
httpSession.setAttribute("timereportData", timereportData);
}

public Optional<TimereportData> getLastStoredTimereport() {
return Optional.ofNullable((TimereportData) httpSession.getAttribute("timereportData"));
}

public void invalidate() {
httpSession.removeAttribute("greeting");
httpSession.removeAttribute("loginEmployee");
Expand All @@ -128,6 +138,13 @@ public void invalidate() {
httpSession.removeAttribute("overtimeStatus");
httpSession.removeAttribute("orderOptions");
httpSession.removeAttribute("suborderOptions");
httpSession.removeAttribute("timereportData");
}

@Getter
@RequiredArgsConstructor
public static class TimereportData implements Serializable {
private final String orderId, suborderId;
}

}
4 changes: 2 additions & 2 deletions src/main/java/org/tb/chicoree/EditTimereportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ protected ActionForward executeAuthenticated(ActionMapping mapping, TimereportFo
// add new
String date = request.getParameter("date");
if(date != null && !date.isBlank() && validateDate(date)) {
form.initNew(parse(date));
form.initNew(parse(date), chicoreeSessionStore);
} else {
form.initNew(today());
form.initNew(today(), chicoreeSessionStore);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/tb/chicoree/StoreTimereportAction.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package org.tb.chicoree;

import static org.tb.common.util.DateUtils.parse;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.stereotype.Component;
import org.tb.chicoree.ChicoreeSessionStore.TimereportData;
import org.tb.common.exception.AuthorizationException;
import org.tb.common.exception.BusinessRuleException;
import org.tb.common.exception.InvalidDataException;
import org.tb.common.struts.LoginRequiredAction;
import org.tb.common.util.DateUtils;
import org.tb.dailyreport.service.TimereportService;
import org.tb.order.persistence.EmployeeorderDAO;

Expand Down Expand Up @@ -63,6 +61,7 @@ protected ActionForward executeAuthenticated(ActionMapping mapping, TimereportFo
addToMessages(request, e.getErrorCode());
return mapping.getInputForward();
}
chicoreeSessionStore.setLastStoredTimereport(new TimereportData(form.getOrderId(), form.getSuborderId()));
chicoreeSessionStore.setDashboardDate(form.getDateTyped());
return mapping.findForward("success");
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/tb/chicoree/TimereportForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ public void init(TimereportDTO timereport) {
comment = timereport.getTaskdescription();
}

public void initNew(LocalDate date) {
public void initNew(LocalDate date, ChicoreeSessionStore chicoreeSessionStore) {
id = null;
this.date = format(date);
orderId = "";
suborderId = "";
hours = null;
minutes = null;
comment = null;
chicoreeSessionStore.getLastStoredTimereport().ifPresent(lastTimereportForm -> {
orderId = lastTimereportForm.getOrderId();
suborderId = lastTimereportForm.getSuborderId();
});
}

}

0 comments on commit f62f633

Please sign in to comment.