Skip to content

Commit

Permalink
🚸 show empty sessions / closed rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
McPringle committed Mar 30, 2024
1 parent 0853b5e commit 255a2c8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 24 deletions.
6 changes: 5 additions & 1 deletion frontend/themes/apus/views/session-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
background-color: #9bf4ff;
}

.next-session {
.next-session, .empty-session {
background-color: #62d7e3;
}

.empty-session {
opacity: 0.5;
}
38 changes: 25 additions & 13 deletions src/main/java/swiss/fihlon/apus/ui/view/ConferenceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,34 @@ private void updateScheduler() {

private void updateConferenceSessions() {
sessionContainer.removeAll();
final var sessionCounter = new AtomicInteger(0);
final var today = LocalDate.now();
for (final Map.Entry<String, List<Session>> stringListEntry : conferenceService.getRoomsWithSessions().entrySet()) {
if (sessionCounter.get() >= MAX_ROOMS_IN_VIEW) {
Notification.show("Too many rooms to display, no more space left on screen!");
final var roomCounter = new AtomicInteger(0);
final var roomsWithSessions = conferenceService.getRoomsWithSessions().entrySet();
for (final Map.Entry<String, List<Session>> roomWithSession : roomsWithSessions) {
if (roomCounter.get() >= MAX_ROOMS_IN_VIEW) {
Notification.show(String.format("Too many rooms (%d) to display, no more space left on screen!",
roomsWithSessions.size()));
break;
}
final List<Session> sessions = stringListEntry.getValue();
if (!sessions.isEmpty()) {
final Session session = sessions.getFirst();
if (session.startDate().toLocalDate().isEqual(today)) {
final var sessionView = new SessionView(session);
sessionView.setId("session-" + sessionCounter.getAndIncrement());
sessionContainer.add(sessionView);
}
}
final SessionView sessionView = createSessionView(roomWithSession, today, roomCounter);
sessionContainer.add(sessionView);
}
}

@NotNull
private static SessionView createSessionView(@NotNull final Map.Entry<String, List<Session>> roomWithSession,
@NotNull final LocalDate today,
@NotNull final AtomicInteger roomCounter) {
final String room = roomWithSession.getKey();
final List<Session> sessions = roomWithSession.getValue();
final Session session = sessions.isEmpty() ? null : sessions.getFirst();
final SessionView sessionView;
if (session != null && session.startDate().toLocalDate().isEqual(today)) {
sessionView = new SessionView(session);
} else {
sessionView = new SessionView(room);
}
sessionView.setId("session-" + roomCounter.getAndIncrement());
return sessionView;
}
}
50 changes: 40 additions & 10 deletions src/main/java/swiss/fihlon/apus/ui/view/SessionView.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,65 @@
*/
package swiss.fihlon.apus.ui.view;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Html;
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import swiss.fihlon.apus.conference.Session;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;

@CssImport(value = "./themes/apus/views/session-view.css")
public final class SessionView extends Div {

public SessionView(@NotNull final String room) {
this(room, null, null, null, null);
}

public SessionView(@NotNull final Session session) {
this(
session.room(),
session.title(),
session.speaker(),
session.startDate().toLocalTime(),
session.endDate().toLocalTime()
);
}

public SessionView(@NotNull final String room,
@Nullable final String title,
@Nullable final String speaker,
@Nullable final LocalTime startTime,
@Nullable final LocalTime endTime) {
addClassName("session-view");
add(new H3(session.title()));
add(new Div(String.format("\uD83D\uDC64 %s", session.speaker())));
add(new Div(String.format("\uD83D\uDCCD %s", session.room())));
add(new H3(new Text(title == null ? "CLOSED" : title)));
add(new Div(speaker == null ? nbsp() : new Text(String.format("\uD83D\uDC64 %s", speaker))));
add(new Div(new Text(String.format("\uD83D\uDCCD %s", room))));

final var now = LocalDateTime.now();
if (session.startDate().isBefore(now) && session.endDate().isAfter(now)) { // running session
final Duration duration = Duration.between(LocalDateTime.now(), session.endDate());
final var now = LocalTime.now();
if (startTime == null || endTime == null) { // empty session
add(new Div(nbsp()));
addClassName("empty-session");
} else if (startTime.isBefore(now) && endTime.isAfter(now)) { // running session
final Duration duration = Duration.between(now, endTime);
final long timeLeft = Math.round(duration.getSeconds() / 60f);
final String timeUnit = timeLeft == 1 ? "minute" : "minutes";
add(new Div(String.format("⌛ %d %s left", timeLeft, timeUnit)));
add(new Div(new Text(String.format("⌛ %d %s left", timeLeft, timeUnit))));
addClassName("running-session");
} else {
add(new Div(String.format("⌚ %s - %s", session.startDate().toLocalTime(), session.endDate().toLocalTime())));
} else { // next session
add(new Div(new Text(String.format("⌚ %s - %s", startTime, endTime))));
addClassName("next-session");
}
}

@NotNull
private static Component nbsp() {
return new Html("<span>&nbsp;</span>");
}

}

0 comments on commit 255a2c8

Please sign in to comment.