mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add calender to OrderController
calender displays `order.id`s per day
This commit is contained in:
parent
397027a650
commit
1777e268db
|
@ -58,5 +58,19 @@ public class CustomOrderDataInitializer implements DataInitializer {
|
||||||
true,
|
true,
|
||||||
4000.0
|
4000.0
|
||||||
));
|
));
|
||||||
|
|
||||||
|
products = new HashMap<>();
|
||||||
|
products.put("Koch", Quantity.of(3));
|
||||||
|
products.put("Wasser (still)", Quantity.of(101));
|
||||||
|
products.put("Käseplatte", Quantity.of(1000));
|
||||||
|
products.put("Wiener Würstchen", Quantity.of(150));
|
||||||
|
orderRepository.addOrder(new CustomOrder(
|
||||||
|
CustomOrder.OrderType.EVENT_CATERING,
|
||||||
|
LocalDateTime.of(2023, 11, 20, 11, 0),
|
||||||
|
LocalDateTime.of(2023, 11, 21, 8, 0),
|
||||||
|
products,
|
||||||
|
true,
|
||||||
|
1001.0
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package catering.order;
|
package catering.order;
|
||||||
|
|
||||||
|
import org.springframework.data.util.Streamable;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -7,6 +8,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,14 +108,36 @@ public class OrderController {
|
||||||
for (LocalDate date : datesOfTheWeek) {
|
for (LocalDate date : datesOfTheWeek) {
|
||||||
ArrayList<String> x = new ArrayList<String>(2);
|
ArrayList<String> x = new ArrayList<String>(2);
|
||||||
x.add(Integer.toString(date.getDayOfMonth()));
|
x.add(Integer.toString(date.getDayOfMonth()));
|
||||||
x.add("#OrdersToday");
|
|
||||||
week_to_add_to_month.add(x);
|
week_to_add_to_month.add(x);
|
||||||
}
|
}
|
||||||
//datesOfTheWeek.clear();
|
//datesOfTheWeek.clear();
|
||||||
weeksOfMonth.add(week_to_add_to_month);
|
weeksOfMonth.add(week_to_add_to_month);
|
||||||
}
|
}
|
||||||
|
|
||||||
// calender header with names of week
|
LocalDate endDate = startDate.plusDays(27);
|
||||||
|
|
||||||
|
// get orders_in_next_month (in future sorted by endDate)
|
||||||
|
Iterable<CustomOrder> orders_in_next_month = this.orderRepository.getOrders().stream().filter(e ->
|
||||||
|
!e.getFinish().toLocalDate().isBefore(startDate) && // end is not before today
|
||||||
|
!e.getStart().toLocalDate().isAfter(endDate)).toList();
|
||||||
|
|
||||||
|
|
||||||
|
for (CustomOrder order : orders_in_next_month) {
|
||||||
|
int start_index_inclusive = Math.max(order.getStart().toLocalDate().compareTo(startDate),0);
|
||||||
|
int end_index_exclusive = Math.min(order.getFinish().toLocalDate().compareTo(startDate), 27) + 1;
|
||||||
|
for (int i = start_index_inclusive; i < end_index_exclusive; i++) {
|
||||||
|
weeksOfMonth.get((int) i/7).get(Math.floorMod(i,7)).add(Integer.toString(order.getId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// for (List<List<String>> orders_in_next_week : orders_in_next_month) {
|
||||||
|
// orders_in_next_weeks.stream().filter(e ->
|
||||||
|
// e.start.toLocalDate().isEqual(calender_day) || // start day
|
||||||
|
// e.end.toLocalDate().isEqual(calender_day) || // end day
|
||||||
|
// e.start.toLocalDate().isBefore(calender_day) && end.toLocalDate().isAfter(calender_day) // day in between start and end
|
||||||
|
// ).toList().count();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// calendar header with names of week
|
||||||
LocalDate endOfWeekDate = startDate.plusDays(6);
|
LocalDate endOfWeekDate = startDate.plusDays(6);
|
||||||
ArrayList<String> dayNames = new ArrayList<String>(7);
|
ArrayList<String> dayNames = new ArrayList<String>(7);
|
||||||
for (LocalDate date = startDate; !date.isAfter(endOfWeekDate); date = date.plusDays(1)) {
|
for (LocalDate date = startDate; !date.isAfter(endOfWeekDate); date = date.plusDays(1)) {
|
||||||
|
|
|
@ -71,8 +71,10 @@
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<a
|
<a
|
||||||
class="description"
|
class="description"
|
||||||
th:text="${day.get(1)}"
|
|
||||||
>
|
>
|
||||||
|
<span th:text="${#lists.size(day)-1}"></span><br>
|
||||||
|
<span th:each="item, stat : ${day}" th:if="${stat.index} >= 1" th:text="${item}"></span>
|
||||||
|
<!-- <span th:text="${99+2}"></span>-->
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
Loading…
Reference in a new issue