From 37ae9a0089c224b59730094df3525e6bbeaea609 Mon Sep 17 00:00:00 2001 From: Theo Reichert Date: Sun, 12 Nov 2023 14:42:07 +0100 Subject: [PATCH] Add calender to OrderController calender can't count orders per day --- .../java/catering/order/OrderController.java | 40 ++++++++- src/main/resources/templates/layout.html | 6 +- .../resources/templates/orders_calender.html | 85 +++++++++++++++++++ 3 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/templates/orders_calender.html diff --git a/src/main/java/catering/order/OrderController.java b/src/main/java/catering/order/OrderController.java index 0ec5538..f6f3de8 100644 --- a/src/main/java/catering/order/OrderController.java +++ b/src/main/java/catering/order/OrderController.java @@ -1,15 +1,15 @@ package catering.order; -import org.salespointframework.quantity.Quantity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import java.time.LocalDateTime; +import java.time.LocalDate; import java.util.ArrayList; -import java.util.Map; import java.util.Optional; + @Controller public class OrderController { @@ -88,4 +88,40 @@ public class OrderController { return "redirect:/event"; } + + @GetMapping("/orders/calender") + public String calender(Model model) { + LocalDate startDate = LocalDate.now(); + + ArrayList>> weeksOfMonth = new ArrayList>>(4); + for (int i = 0; i < 4; i++) { + ArrayList datesOfTheWeek = new ArrayList(7); + LocalDate startOfWeek = startDate.plusDays(7*i); + LocalDate endOfWeekDate = startOfWeek.plusDays(6); + for (LocalDate date = startOfWeek; !date.isAfter(endOfWeekDate); date = date.plusDays(1)) { + datesOfTheWeek.add(date); + } + + ArrayList> week_to_add_to_month = new ArrayList>(7); + for (LocalDate date : datesOfTheWeek) { + ArrayList x = new ArrayList(2); + x.add(Integer.toString(date.getDayOfMonth())); + x.add("#OrdersToday"); + week_to_add_to_month.add(x); + } + //datesOfTheWeek.clear(); + weeksOfMonth.add(week_to_add_to_month); + } + + // calender header with names of week + LocalDate endOfWeekDate = startDate.plusDays(6); + ArrayList dayNames = new ArrayList(7); + for (LocalDate date = startDate; !date.isAfter(endOfWeekDate); date = date.plusDays(1)) { + dayNames.add(date.getDayOfWeek().toString()); + } + + model.addAttribute("weeksOfMonth", weeksOfMonth); + model.addAttribute("dayNames", dayNames); + return "orders_calender"; + } } diff --git a/src/main/resources/templates/layout.html b/src/main/resources/templates/layout.html index 6d1e688..ec9a5ff 100644 --- a/src/main/resources/templates/layout.html +++ b/src/main/resources/templates/layout.html @@ -6,13 +6,13 @@ - + + Catering -
+

Catering

diff --git a/src/main/resources/templates/orders_calender.html b/src/main/resources/templates/orders_calender.html new file mode 100644 index 0000000..2169407 --- /dev/null +++ b/src/main/resources/templates/orders_calender.html @@ -0,0 +1,85 @@ + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+
+
+
+
+
+
+ + +
+
+
+ + +