mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Fix days in calendar and display of events per calendar day
This commit is contained in:
parent
b836a38942
commit
e83b6380be
|
@ -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<CustomOrder> 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<ArrayList<ArrayList<String>>> weeksOfMonth = new ArrayList<ArrayList<ArrayList<String>>>();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
weeksOfMonth.add(new ArrayList<ArrayList<String>>(7));
|
||||
for (int j = 0; j < 7; j++) {
|
||||
weeksOfMonth.get(i).add(new ArrayList<String>());
|
||||
weeksOfMonth.get(i).get(j).addAll(datesOfMonth.get(
|
||||
(i==0) ? j : (j==0) ? i : i*j
|
||||
i*7+j
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue