Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spring:
boot:
admin:
ui:
theme:
color: "#4A1420"
palette:
50: "#F8EBE4"
100: "#F2D7CC"
200: "#E5AC9C"
300: "#D87B6C"
400: "#CB463B"
500: "#9F2A2A"
600: "#83232A"
700: "#661B26"
800: "#4A1420"
900: "#2E0C16"
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
:root {
--main-50: /*[(${@cssColorUtils.hexToRgb(uiSettings.theme.palette.getShade50())})]*/ #e8fbef;
--main-100: /*[(${@cssColorUtils.hexToRgb(uiSettings.theme.palette.getShade100())})]*/ #d0f7df;
--main-200: /*[(${@cssColorUtils.hexToRgb(uiSettings.theme.palette.getShade200())})]*/ #a1efbd;
--main-300: /*[(${@cssColorUtils.hexToRgb(uiSettings.theme.palette.getShade300())})]*/ #71e69c;
--main-400: /*[(${@cssColorUtils.hexToRgb(uiSettings.theme.palette.getShade400())})]*/ #41de7b;
--main-500: /*[(${@cssColorUtils.hexToRgb(uiSettings.theme.palette.getShade500())})]*/ #22c55e;
--main-600: /*[(${@cssColorUtils.hexToRgb(uiSettings.theme.palette.getShade600())})]*/ #1a9547;
--main-700: /*[(${@cssColorUtils.hexToRgb(uiSettings.theme.palette.getShade700())})]*/ #116530;
--main-800: /*[(${@cssColorUtils.hexToRgb(uiSettings.theme.palette.getShade800())})]*/ #09351a;
--main-900: /*[(${@cssColorUtils.hexToRgb(uiSettings.theme.palette.getShade900())})]*/ #010603;
--main-50: /*[(${palette.rgbColor50})]*/ #e8fbef;
--main-100: /*[(${palette.rgbColor100})]*/ #d0f7df;
--main-200: /*[(${palette.rgbColor200})]*/ #a1efbd;
--main-300: /*[(${palette.rgbColor300})]*/ #71e69c;
--main-400: /*[(${palette.rgbColor400})]*/ #41de7b;
--main-500: /*[(${palette.rgbColor500})]*/ #22c55e;
--main-600: /*[(${palette.rgbColor600})]*/ #1a9547;
--main-700: /*[(${palette.rgbColor700})]*/ #116530;
--main-800: /*[(${palette.rgbColor800})]*/ #09351a;
--main-900: /*[(${palette.rgbColor900})]*/ #010603;

--bg-color-start: /*[(${uiSettings.theme.palette.getShade300()})]*/ #71e69c;
--bg-color-stop: /*[(${uiSettings.theme.palette.getShade700()})]*/ #09351a;
--bg-color-start: /*[(${uiSettings.theme.palette.shade300})]*/ #71e69c;
--bg-color-stop: /*[(${uiSettings.theme.palette.shade700})]*/ #09351a;
}

.bg-color-start {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ public AdminServerUiAutoConfiguration(AdminServerUiProperties adminUi, AdminServ
this.applicationContext = applicationContext;
}

@Bean
public CssColorUtils cssColorUtils() {
return new CssColorUtils();
}

@Bean
@ConditionalOnMissingBean
public UiController homeUiController(UiExtensions uiExtensions) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@

import java.util.regex.Pattern;

public class CssColorUtils {
public final class CssColorUtils {

private CssColorUtils() {
}

private static final Pattern HEX_RGB_PATTERN = Pattern.compile("^#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$");

public String hexToRgb(String color) {
public static String hexToRgb(String color) {
if (!HEX_RGB_PATTERN.matcher(color).matches()) {
throw new IllegalArgumentException(String.format("Invalid hex rgb format %s", color));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ private static void registerReflectionHints(org.springframework.aot.hint.Runtime
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
.registerType(AdminServerUiProperties.PollTimer.class, MemberCategory.INVOKE_PUBLIC_METHODS,
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
.registerType(CssColorUtils.class, MemberCategory.INVOKE_PUBLIC_METHODS,
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
.registerType(InstanceDeregisteredEvent.class, MemberCategory.INVOKE_PUBLIC_METHODS,
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
.registerType(InstanceEndpointsDetectedEvent.class, MemberCategory.INVOKE_PUBLIC_METHODS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.security.Principal;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
Expand All @@ -31,8 +32,10 @@
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

import de.codecentric.boot.admin.server.ui.config.AdminServerUiProperties.Palette;
import de.codecentric.boot.admin.server.ui.config.AdminServerUiProperties.PollTimer;
import de.codecentric.boot.admin.server.ui.config.AdminServerUiProperties.UiTheme;
import de.codecentric.boot.admin.server.ui.config.CssColorUtils;
import de.codecentric.boot.admin.server.ui.extensions.UiExtension;
import de.codecentric.boot.admin.server.ui.extensions.UiExtensions;
import de.codecentric.boot.admin.server.web.AdminController;
Expand Down Expand Up @@ -97,6 +100,15 @@ public Map<String, Object> getUser(@Nullable Principal principal) {
return emptyMap();
}

@ModelAttribute(value = "palette", binding = false)
public Map<String, String> getPalette() {
return Map.ofEntries(hexToRgbColor(50, Palette::getShade50), hexToRgbColor(100, Palette::getShade100),
hexToRgbColor(200, Palette::getShade200), hexToRgbColor(300, Palette::getShade300),
hexToRgbColor(400, Palette::getShade400), hexToRgbColor(500, Palette::getShade500),
hexToRgbColor(600, Palette::getShade600), hexToRgbColor(700, Palette::getShade700),
hexToRgbColor(800, Palette::getShade800), hexToRgbColor(900, Palette::getShade900));
}

@GetMapping(path = "/", produces = MediaType.TEXT_HTML_VALUE)
@RegisterReflectionForBinding(String.class)
public String index() {
Expand All @@ -113,6 +125,11 @@ public String variablesCss() {
return "variables.css";
}

private Map.Entry<String, String> hexToRgbColor(int grade, Function<Palette, String> hexColorGetter) {
return Map.entry(("rgbColor" + grade).intern(),
CssColorUtils.hexToRgb(hexColorGetter.apply(uiSettings.getTheme().getPalette())));
}

@GetMapping(path = "/login", produces = MediaType.TEXT_HTML_VALUE)
public String login() {
return "login";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ public void should_return_defaults_for_pollTimers() {
//@formatter:on
}

@Test
public void should_render_palette_colors_in_variables_css() {
//@formatter:off
this.webClient.get()
.uri("/variables.css")
.accept(MediaType.parseMediaType("text/css"), MediaType.ALL)
.exchange()
.expectStatus().isOk()
.expectHeader().contentTypeCompatibleWith(MediaType.parseMediaType("text/css"))
.expectBody(String.class)
.value((body) -> assertThat(body).contains("--main-50: rgb(238, 252, 250)"))
.value((body) -> assertThat(body).contains("--main-100: rgb(217, 247, 244)"))
.value((body) -> assertThat(body).contains("--main-200: rgb(183, 240, 234)"))
.value((body) -> assertThat(body).contains("--main-300: rgb(145, 232, 224)"))
.value((body) -> assertThat(body).contains("--main-400: rgb(107, 224, 213)"))
.value((body) -> assertThat(body).contains("--main-500: rgb(71, 217, 203)"))
.value((body) -> assertThat(body).contains("--main-600: rgb(39, 190, 175)"))
.value((body) -> assertThat(body).contains("--main-700: rgb(30, 144, 132)"))
.value((body) -> assertThat(body).contains("--main-800: rgb(20, 97, 90)"))
.value((body) -> assertThat(body).contains("--main-900: rgb(10, 47, 43)"))
.value((body) -> assertThat(body).contains("--bg-color-start: #91E8E0"))
.value((body) -> assertThat(body).contains("--bg-color-stop: #1E9084"));
//@formatter:on
}

protected WebTestClient createWebClient(int port) {
return WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ class CssColorUtilsTest implements WithAssertions {

@Test
void hexToRgb() {
CssColorUtils cssColorUtils = new CssColorUtils();

assertThat(cssColorUtils.hexToRgb(new AdminServerUiProperties.Palette().getShade50()))
assertThat(CssColorUtils.hexToRgb(new AdminServerUiProperties.Palette().getShade50()))
.isEqualTo("rgb(238, 252, 250)");
}

@Test
void hexToRgb_throws_exception_on_invalid_format() {
CssColorUtils cssColorUtils = new CssColorUtils();

assertThatThrownBy(() -> cssColorUtils.hexToRgb("EEFCFA")).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> CssColorUtils.hexToRgb("EEFCFA")).isInstanceOf(IllegalArgumentException.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@
package de.codecentric.boot.admin.server.ui.web;

import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import de.codecentric.boot.admin.server.ui.config.AdminServerUiProperties;
import de.codecentric.boot.admin.server.ui.config.CssColorUtils;
import de.codecentric.boot.admin.server.ui.extensions.UiExtensions;
import de.codecentric.boot.admin.server.web.servlet.AdminControllerHandlerMapping;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
Expand Down Expand Up @@ -98,8 +102,43 @@ void should_validate_external_views(String label, String url, boolean hasChildre
}
}

@Test
void should_populate_palette_with_matching_rgb_colors_for_all_grades() {
AdminServerUiProperties.Palette palette = new AdminServerUiProperties.Palette();
palette.set50("#010203");
palette.set100("#111213");
palette.set200("#212223");
palette.set300("#313233");
palette.set400("#414243");
palette.set500("#515253");
palette.set600("#616263");
palette.set700("#717273");
palette.set800("#818283");
palette.set900("#919293");

AdminServerUiProperties.UiTheme theme = new AdminServerUiProperties.UiTheme();
theme.setPalette(palette);

UiController.Settings settings = UiController.Settings.builder().theme(theme).build();
UiController controller = new UiController("", UiExtensions.EMPTY, settings);

Map<String, String> actualPalette = controller.getPalette();

assertThat(actualPalette)
.containsExactlyInAnyOrderEntriesOf(Map.of("rgbColor50", CssColorUtils.hexToRgb(palette.getShade50()),
"rgbColor100", CssColorUtils.hexToRgb(palette.getShade100()), "rgbColor200",
CssColorUtils.hexToRgb(palette.getShade200()), "rgbColor300",
CssColorUtils.hexToRgb(palette.getShade300()), "rgbColor400",
CssColorUtils.hexToRgb(palette.getShade400()), "rgbColor500",
CssColorUtils.hexToRgb(palette.getShade500()), "rgbColor600",
CssColorUtils.hexToRgb(palette.getShade600()), "rgbColor700",
CssColorUtils.hexToRgb(palette.getShade700()), "rgbColor800",
CssColorUtils.hexToRgb(palette.getShade800()), "rgbColor900",
CssColorUtils.hexToRgb(palette.getShade900())));
}

private MockMvc setupController(String publicUrl, List<UiController.ExternalView> externalViews) {
var uiControllerSettings = UiController.Settings.builder();
var uiControllerSettings = UiController.Settings.builder().theme(new AdminServerUiProperties.UiTheme());
if (!isEmpty(externalViews)) {
uiControllerSettings.externalViews(externalViews);
}
Expand Down