From e83b6380be8c6e8ef8da5764d4a911f77157f623 Mon Sep 17 00:00:00 2001 From: Theo Reichert Date: Wed, 22 Nov 2023 06:00:43 +0100 Subject: [PATCH] Fix days in calendar and display of events per calendar day --- .../java/catering/order/OrderController.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/catering/order/OrderController.java b/src/main/java/catering/order/OrderController.java index 96d7b91..78fa576 100644 --- a/src/main/java/catering/order/OrderController.java +++ b/src/main/java/catering/order/OrderController.java @@ -13,6 +13,7 @@ import org.salespointframework.useraccount.web.LoggedIn; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.query.Procedure; +import org.springframework.data.util.Streamable; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -211,12 +212,24 @@ public class OrderController { datesOfMonth.add(x); } - // add each order overlapping with the calender to the days it overlaps with - for (CustomOrder order : this.orderManagement.findBy(Interval.from(startDateTime).to(endDateTime))) { + /* + * FIXME: Do not load all orders into java, + * instead query orderManagement better to only return orders overlapping with interval [startDate,endDate] + * by using "query creation" of the jpa + * e.g. this.orderManagement.findByFinishDateIsNotBeforeAndStartDateIsNotAfter(LocalDateTime startDateTime, LocalDateTime endDateTime) + */ + Streamable x = this.orderManagement.findAll(Pageable.unpaged()).filter(e -> + !e.getFinish().toLocalDate().isBefore(startDate) && // end is not before today + !e.getStart().toLocalDate().isAfter(endDate) + ); + + // add each order overlapping with the calendar to the days it overlaps with + for (CustomOrder order : x) { int start_index_inclusive = Math.max((int) startDate.until(order.getStart().toLocalDate(), ChronoUnit.DAYS),0); int end_index_exclusive = Math.min((int) startDate.until(order.getFinish().toLocalDate(), ChronoUnit.DAYS), 27) + 1; String order_id = Objects.requireNonNull(order.getId()).toString(); for (int i = start_index_inclusive; i < end_index_exclusive; i++) { + // FIXME: exchange order ids for a short name or a color datesOfMonth.get(i).add(order_id); } } @@ -228,13 +241,15 @@ public class OrderController { dayNames.add(date.getDayOfWeek().toString()); } + // FIXME: Get rid of the following paragraph of code by change of order_calender.html + // put data of datesOfMonth inside current structure used in order_calender.html ArrayList>> weeksOfMonth = new ArrayList>>(); for (int i = 0; i < 4; i++) { weeksOfMonth.add(new ArrayList>(7)); for (int j = 0; j < 7; j++) { weeksOfMonth.get(i).add(new ArrayList()); weeksOfMonth.get(i).get(j).addAll(datesOfMonth.get( - (i==0) ? j : (j==0) ? i : i*j + i*7+j ) ); }