Skip to content

Commit

Permalink
✨ Make session tracks more customizable closes #140
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Jul 6, 2024
1 parent 1b43e5d commit dd34274
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 61 deletions.
2 changes: 1 addition & 1 deletion frontend/themes/apus/views/room-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
position: relative;
}

.room-view .track img {
.room-view .track svg {
position: absolute;
bottom: 0;
right: 0;
Expand Down
76 changes: 38 additions & 38 deletions src/main/java/swiss/fihlon/apus/event/Track.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,43 @@
package swiss.fihlon.apus.event;

import org.jetbrains.annotations.NotNull;

@SuppressWarnings("checkstyle:LineLength")
public enum Track {

// Important: When adding a new track, modify the test accordingly!
NONE("", ""),
ARCHITECTURE("Architecture", "java.png"),
CONTAINER_CLOUD_INFRASTRUCTURE("Container, Cloud & Infrastructure", "java.png"),
DATA_STREAMING_AI("Data, Streaming & AI", "java.png"),
ENTERPRISE_JAVA("Enterprise Java", "java.png"),
JAVA("Core Java & JVM-Technologies", "java.png"),
LANGUAGES("Programming Languages", "java.png"),
METHODOLOGY_CULTURE("Methodology & Culture", "java.png"),
NEXT("What's next", "java.png"),
QUALITY_TESTING("Quality & Testing", "java.png"),
SECURITY("Security", "java.png"),
STUDIO("Studio", "java.png"),
TOOLS("Tools", "java.png"),
UI_UX("UI & UX", "java.png");

private static final String FILE_NAME_TEMPLATE = "icons/tracks/%s";

private final String trackName;
private final String fileName;

Track(@NotNull final String trackName, @NotNull final String fileName) {
this.trackName = trackName;
this.fileName = fileName.isBlank() ? "" : FILE_NAME_TEMPLATE.formatted(fileName);
}

@NotNull
public String getTrackName() {
return trackName;
}

@NotNull
public String getFileName() {
return fileName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

public record Track(String name, String svgCode) {

public static final Logger LOGGER = LoggerFactory.getLogger(Track.class);

public static final Track NONE = new Track(null, null);
public static final Track ARCHITECTURE = defaultTrack("Architecture", "architecture.svg");
public static final Track CLOUD = defaultTrack("Cloud", "cloud.svg");
public static final Track CORE = defaultTrack("Core", "core.svg");
public static final Track INFRASTRUCTURE = defaultTrack("Infrastructure", "infrastructure.svg");
public static final Track SECURITY = defaultTrack("Security", "security.svg");
public static final Track TOOLS = defaultTrack("Tools", "tools.svg");

private static final String FILE_NAME_TEMPLATE = "/icons/tracks/%s";

private static Track defaultTrack(@NotNull final String name, @NotNull final String svgFileName) {
try {
final String fileName = FILE_NAME_TEMPLATE.formatted(svgFileName);
final URL url = Track.class.getResource(fileName);
final URI uri = Objects.requireNonNull(url).toURI();
final Path path = Paths.get(uri);
final String svgCode = Files.readString(path);
return new Track(name, svgCode.trim());
} catch (final IOException | NullPointerException | URISyntaxException e) {
LOGGER.error("Unable to load default track icon '{}': {}", svgFileName, e.getMessage(), e);
}
return NONE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ public boolean isEnabled() {
}

private @NotNull Track getRandomTrack() {
Track track = Track.NONE;
while (track == Track.NONE) {
final var values = Arrays.asList(Track.values());
final int size = values.size();
track = values.get(RANDOM.nextInt(size));
}
return track;
return switch (RANDOM.nextInt(6)) {
case 0 -> Track.ARCHITECTURE;
case 1 -> Track.CLOUD;
case 2 -> Track.CORE;
case 3 -> Track.INFRASTRUCTURE;
case 4 -> Track.SECURITY;
case 5 -> Track.TOOLS;
default -> Track.NONE;
};
}
}
5 changes: 3 additions & 2 deletions src/main/java/swiss/fihlon/apus/ui/view/RoomView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Html;
import com.vaadin.flow.component.Svg;
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.html.Div;
Expand Down Expand Up @@ -49,7 +50,7 @@ public final class RoomView extends Div {
private final LocalTime startTime;
private final LocalTime endTime;
private final Language language;
private final Track track;
private final transient Track track;

private RoomStyle roomStyle = RoomStyle.NONE;

Expand Down Expand Up @@ -164,7 +165,7 @@ private Component createTrackComponent() {
final var trackComponent = new Div();
trackComponent.addClassName("track");
if (track != Track.NONE) {
final var trackImage = new Image(track.getFileName(), track.getTrackName());
final var trackImage = new Svg(track.svgCode());
trackComponent.add(trackImage);
}
return trackComponent;
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions src/main/resources/icons/tracks/architecture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/main/resources/icons/tracks/cloud.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/main/resources/icons/tracks/core.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/main/resources/icons/tracks/infrastructure.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/main/resources/icons/tracks/security.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/main/resources/icons/tracks/tools.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dd34274

Please sign in to comment.