From dd34274f599d2289bfe06e9b96ad26729454fd13 Mon Sep 17 00:00:00 2001 From: Marcus Fihlon Date: Sat, 6 Jul 2024 19:49:51 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Make=20session=20tracks=20more=20cu?= =?UTF-8?q?stomizable=20closes=20#140?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcus Fihlon --- frontend/themes/apus/views/room-view.css | 2 +- .../java/swiss/fihlon/apus/event/Track.java | 76 +++++++++--------- .../apus/plugin/event/demo/DemoPlugin.java | 16 ++-- .../swiss/fihlon/apus/ui/view/RoomView.java | 5 +- .../META-INF/resources/icons/tracks/java.png | Bin 1477 -> 0 bytes .../resources/icons/tracks/architecture.svg | 4 + src/main/resources/icons/tracks/cloud.svg | 17 ++++ src/main/resources/icons/tracks/core.svg | 2 + .../resources/icons/tracks/infrastructure.svg | 2 + src/main/resources/icons/tracks/security.svg | 22 +++++ src/main/resources/icons/tracks/tools.svg | 2 + .../swiss/fihlon/apus/event/TrackTest.java | 54 ++++++++++--- 12 files changed, 141 insertions(+), 61 deletions(-) delete mode 100644 src/main/resources/META-INF/resources/icons/tracks/java.png create mode 100644 src/main/resources/icons/tracks/architecture.svg create mode 100644 src/main/resources/icons/tracks/cloud.svg create mode 100644 src/main/resources/icons/tracks/core.svg create mode 100644 src/main/resources/icons/tracks/infrastructure.svg create mode 100644 src/main/resources/icons/tracks/security.svg create mode 100644 src/main/resources/icons/tracks/tools.svg diff --git a/frontend/themes/apus/views/room-view.css b/frontend/themes/apus/views/room-view.css index f4e4f02..c7ee898 100644 --- a/frontend/themes/apus/views/room-view.css +++ b/frontend/themes/apus/views/room-view.css @@ -67,7 +67,7 @@ position: relative; } -.room-view .track img { +.room-view .track svg { position: absolute; bottom: 0; right: 0; diff --git a/src/main/java/swiss/fihlon/apus/event/Track.java b/src/main/java/swiss/fihlon/apus/event/Track.java index 029bf85..487859e 100644 --- a/src/main/java/swiss/fihlon/apus/event/Track.java +++ b/src/main/java/swiss/fihlon/apus/event/Track.java @@ -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; } } diff --git a/src/main/java/swiss/fihlon/apus/plugin/event/demo/DemoPlugin.java b/src/main/java/swiss/fihlon/apus/plugin/event/demo/DemoPlugin.java index c78511c..0840f65 100644 --- a/src/main/java/swiss/fihlon/apus/plugin/event/demo/DemoPlugin.java +++ b/src/main/java/swiss/fihlon/apus/plugin/event/demo/DemoPlugin.java @@ -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; + }; } } diff --git a/src/main/java/swiss/fihlon/apus/ui/view/RoomView.java b/src/main/java/swiss/fihlon/apus/ui/view/RoomView.java index eeb0c00..1fd274a 100644 --- a/src/main/java/swiss/fihlon/apus/ui/view/RoomView.java +++ b/src/main/java/swiss/fihlon/apus/ui/view/RoomView.java @@ -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; @@ -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; @@ -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; diff --git a/src/main/resources/META-INF/resources/icons/tracks/java.png b/src/main/resources/META-INF/resources/icons/tracks/java.png deleted file mode 100644 index 68c8e35f2aa0bb117dbfdbd0911f7d3b7b509626..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1477 zcmV;$1v>hPP)C|p*ypMN)&HFMdO1P1aAmhc4j&# z#fUEu@REQe_+p*Tj8aK#Y9)4d=w)YSCF;fpHR6jJL?Id<#J-rQ5fmZtq7Bq`cfBxv zXD-`i?RK~Awto}(l9S1vnfd?k-2QWBtE$f6e}n=qBA5O=) zcUW^7HC(6qqD-9I2lAQhPX2nYj8zOC@S z+Yz0aF(VJ1*imyi3w|RaYw)Ym2LFdoo`2PKtIo>Z>!`gM`fkV$x0Ab!CC_1jX7wUS zpMw0IpEh**Af1x9e>B|@UCNTWQW(bF58#fVyYNE?xLfv3Aq(|g04*9ZFgJF2f_#jhk>bIyhE z@^RF`fqZ>lYLO8sR{Y8WO`Ak?(1_j<>e5E-Tts0oG$PXxeV8T3k^tH5h{S$ZshXCj z+mJH=a}i5^B@r|;3q&{P>tV$1pqLM`;#M}u`(EywwF^RB#*D5ABGAK^Z06#3kK&K+^1YCDl4k#APLQZmD-@?swbg&nVOrL0Pe* zilR)**EeX^6WGIr5lSVwR|$Gz87=HDZXd(73D@Nmc2ViB3x!fa)~rR6p14O)6D!EG zAhVtb;rSlOCwTX3c)Lqbl3d|Faw>JU9|gO&q6QFRntiRL+8aP-CrEsVjlRM4CodwZ z^?RNi#B)F3xvy}2pHc$47X-~}AR|ZGV~vuWf%Q(|ozE+7z+?ahH&c`;aud1{6)qKV zIdxDjL^UD7^I5FhQmHkI0$w@_>BDB5B{gxcto7VjuXNQkw(Oc2imW^HB-ObcUR?=t zTfG`ktuOG-Dx9^s?_?@uLARd;`Cq(ylL5+S5c?9O{t1h_l;GLlkl(xM00@s>L2+)N z<5Oz3*U7D^$^T-bo&c{d368%eQMF&mljj;V=P_Bg@1$ttdp$&Ko6Yub6*~6To96V= zPfkHlA3*rOmzBg#!+AG^*R-_cHPTD=t&_>GB#_Uq59POY0>8gQUF^m6V^1`DU(gS- zx#v`SkEAB=Vn&(@Eu2&6^bnivM-hpSKyF}!;-x}A1Vbz;{ zMIh+TQtA~IThNNd@4AHAJBYuAjXr=82fSwF7vrDU^k>MoUg3K8tyF=$N5xEo894y&9Pw&JwGRjH zvB5KZ)<2Ile$b+(yypE#bkIQx=jm$I-VDslmpxZ(^@+!#0XuOW; z)>VbG6Ricq9;E1^e)f~l=sscOy}3nm7NYg9m2~H6f6lR%&^G|dY2OAYcJF&3C~B`; zW7-5^JD7=nrDGP?w<(oMec4qUlwy?2 + + + \ No newline at end of file diff --git a/src/main/resources/icons/tracks/cloud.svg b/src/main/resources/icons/tracks/cloud.svg new file mode 100644 index 0000000..d7cf3c6 --- /dev/null +++ b/src/main/resources/icons/tracks/cloud.svg @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/src/main/resources/icons/tracks/core.svg b/src/main/resources/icons/tracks/core.svg new file mode 100644 index 0000000..d548e8f --- /dev/null +++ b/src/main/resources/icons/tracks/core.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/main/resources/icons/tracks/infrastructure.svg b/src/main/resources/icons/tracks/infrastructure.svg new file mode 100644 index 0000000..038b84a --- /dev/null +++ b/src/main/resources/icons/tracks/infrastructure.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/main/resources/icons/tracks/security.svg b/src/main/resources/icons/tracks/security.svg new file mode 100644 index 0000000..a3971a1 --- /dev/null +++ b/src/main/resources/icons/tracks/security.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + diff --git a/src/main/resources/icons/tracks/tools.svg b/src/main/resources/icons/tracks/tools.svg new file mode 100644 index 0000000..3d5b483 --- /dev/null +++ b/src/main/resources/icons/tracks/tools.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/test/java/swiss/fihlon/apus/event/TrackTest.java b/src/test/java/swiss/fihlon/apus/event/TrackTest.java index 6262bcd..8b402e3 100644 --- a/src/test/java/swiss/fihlon/apus/event/TrackTest.java +++ b/src/test/java/swiss/fihlon/apus/event/TrackTest.java @@ -1,29 +1,57 @@ package swiss.fihlon.apus.event; +import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; class TrackTest { @Test - void values() { - assertEquals(14, Track.values().length); + void noneTrack() { + final Track testee = new Track(null, null); + assertEquals(Track.NONE, testee); + assertNull(testee.name()); + assertNull(testee.svgCode()); + } + + @ParameterizedTest + @MethodSource("provideArgumentsForDefaultTrack") + void defaultTracks(@NotNull final Track testee, @NotNull final String expectedName) { + final String message = String.format("Error while testing track '%s'!", expectedName); + assertNotNull(testee, message); + assertNotNull(testee.name(), message); + assertNotNull(testee.svgCode(), message); + assertEquals(expectedName, testee.name(), message); + assertTrue(testee.svgCode().startsWith(""), message); + } + + private static Stream provideArgumentsForDefaultTrack() { + return Stream.of( + Arguments.of(Track.ARCHITECTURE, "Architecture"), + Arguments.of(Track.CLOUD, "Cloud"), + Arguments.of(Track.CORE, "Core"), + Arguments.of(Track.INFRASTRUCTURE, "Infrastructure"), + Arguments.of(Track.SECURITY, "Security"), + Arguments.of(Track.TOOLS, "Tools") + ); } @Test - void getTrackIcon() { - for (final Track track : Track.values()) { - if (track.equals(Track.NONE)) { - assertTrue(track.getTrackName().isBlank()); - assertTrue(track.getFileName().isBlank()); - } else { - assertFalse(track.getTrackName().isBlank()); - assertFalse(track.getFileName().isBlank()); - } - } + void customTrack() { + final Track testee = new Track("testName", "testSvgCode"); + assertEquals("testName", testee.name()); + assertEquals("testSvgCode", testee.svgCode()); } }