Fix Kalender-Page for multiple rooms
This commit is contained in:
6
TODO.md
Normal file
6
TODO.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# TODO
|
||||
|
||||
- unpoly
|
||||
- Feiertage mit Cache
|
||||
- API via API-Key
|
||||
- Verkehrsmodul via Google-Maps: E-Mail, Telegram
|
||||
@@ -67,7 +67,7 @@ public class KalenderResource {
|
||||
User currentUser = userService.getCurrentUser();
|
||||
Room room = currentUser.getRoom();
|
||||
try {
|
||||
KalenderTag tag = KalenderTag.find("day = ?1 and room = ?2", dayParsed, room).singleResult();
|
||||
KalenderTag tag = KalenderTag.findByDayAndRoomId(dayParsed, room == null ? null : room.id);
|
||||
if (kalenderForm.isInOffice() && tag.getInOffice() == null) {
|
||||
tag.setInOffice(currentUser);
|
||||
} else if (!kalenderForm.isInOffice() && currentUser.equals(tag.getInOffice())) {
|
||||
@@ -76,7 +76,7 @@ public class KalenderResource {
|
||||
} catch (NoResultException e) {
|
||||
KalenderTag tag = new KalenderTag(dayParsed, room);
|
||||
tag.setInOffice(currentUser);
|
||||
tag.setRoom(currentUser.getRoom());
|
||||
tag.setRoom(room);
|
||||
tag.persist();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import de.mbremer.secutity.UserService;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.NoResultException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -24,9 +25,12 @@ public class KalenderService {
|
||||
return Stream.iterate(0, i -> i < 5, i -> ++i)
|
||||
.map(d -> {
|
||||
LocalDate day = montag.plusDays(d);
|
||||
KalenderTag tag =
|
||||
(KalenderTag) KalenderTag.find("day = ?1 and room = ?2", day, room).singleResultOptional()
|
||||
.orElse(new KalenderTag(day, room));
|
||||
KalenderTag tag;
|
||||
try {
|
||||
tag = KalenderTag.findByDayAndRoomId(day, room == null ? null : room.id);
|
||||
} catch (NoResultException e) {
|
||||
tag = new KalenderTag(day, room);
|
||||
}
|
||||
tag.setCurrentUserInOffice(currentUser.equals(tag.getInOffice()));
|
||||
tag.setToday(LocalDate.now().equals(day));
|
||||
return tag;
|
||||
|
||||
@@ -32,4 +32,13 @@ public class KalenderTag extends PanacheEntity {
|
||||
this.day = day;
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws javax.persistence.NoResultException
|
||||
*/
|
||||
public static KalenderTag findByDayAndRoomId(LocalDate day, Long roomId) {
|
||||
return roomId == null ?
|
||||
(KalenderTag) KalenderTag.find("day = ?1 and room_id is null", day).singleResult() :
|
||||
(KalenderTag) KalenderTag.find("day = ?1 and room_id = ?2", day, roomId).singleResult();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ alter table users add column room_id bigint references room;
|
||||
alter table kalendertag add column room_id bigint references room;
|
||||
|
||||
alter table kalendertag drop constraint kalendertag_day_key;
|
||||
|
||||
alter table kalendertag add constraint kalendertag_day_room_unique unique(day,room_id);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
</div>
|
||||
|
||||
<div class="mt-2">
|
||||
<img src="/room/plan" alt="kein Raumplan vorhanden">
|
||||
<img src="/room/plan" class="img-fluid" alt="kein Raumplan vorhanden">
|
||||
</div>
|
||||
|
||||
{#if is_admin}
|
||||
|
||||
Reference in New Issue
Block a user