Skip to content

Commit f14ce4a

Browse files
committed
Fixes #13628: System configuration to visually distinguish different system types.
- Change the menu's background-color.
1 parent af6249b commit f14ce4a

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ bin
4646
/sormas-e2e-tests/logs
4747

4848
.DS_Store
49+
50+
/.run-configs

sormas-ui/src/main/java/de/symeda/sormas/ui/Menu.java

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*******************************************************************************
22
* SORMAS® - Surveillance Outbreak Response Management & Analysis System
33
* Copyright © 2016-2018 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
4-
*
4+
* <p>
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
77
* the Free Software Foundation, either version 3 of the License, or
88
* (at your option) any later version.
9-
*
9+
* <p>
1010
* This program is distributed in the hope that it will be useful,
1111
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
* GNU General Public License for more details.
14-
*
14+
* <p>
1515
* You should have received a copy of the GNU General Public License
1616
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*******************************************************************************/
@@ -23,11 +23,13 @@
2323
import java.util.Map;
2424

2525
import org.apache.commons.lang3.StringUtils;
26+
import org.jetbrains.annotations.NotNull;
2627

2728
import com.vaadin.icons.VaadinIcons;
2829
import com.vaadin.navigator.Navigator;
2930
import com.vaadin.navigator.View;
3031
import com.vaadin.server.FileResource;
32+
import com.vaadin.server.Page;
3133
import com.vaadin.server.Resource;
3234
import com.vaadin.server.ThemeResource;
3335
import com.vaadin.ui.Alignment;
@@ -57,22 +59,26 @@
5759
/**
5860
* Responsive navigation menu presenting a list of available views to the user.
5961
*/
60-
@SuppressWarnings("serial")
6162
public class Menu extends CssLayout {
6263

6364
private static final String VALO_MENUITEMS = "valo-menuitems";
6465
private static final String VALO_MENU_TOGGLE = "valo-menu-toggle";
6566
private static final String VALO_MENU_VISIBLE = "valo-menu-visible";
66-
private Navigator navigator;
67-
private Map<String, Button> viewButtons = new HashMap<String, Button>();
67+
private static final String BACKGROUND_COLOR_CONFIG_KEY = "MENU_BACKGROUND_COLOR";
6868

69-
private CssLayout menuItemsLayout;
70-
private CssLayout menuPart;
69+
private final Navigator navigator;
70+
private final Map<String, Button> viewButtons = new HashMap<>();
71+
72+
private final CssLayout menuItemsLayout;
73+
private final CssLayout menuPart;
7174

7275
public Menu(Navigator navigator) {
7376

7477
this.navigator = navigator;
7578
setPrimaryStyleName(ValoTheme.MENU_ROOT);
79+
80+
defineCustomColorBackgroundIfSystemConfigured();
81+
7682
menuPart = new CssLayout();
7783
menuPart.addStyleName(ValoTheme.MENU_PART);
7884

@@ -136,14 +142,54 @@ public Menu(Navigator navigator) {
136142
addComponent(menuPart);
137143
}
138144

145+
private void defineCustomColorBackgroundIfSystemConfigured() {
146+
String backgroundColor = FacadeProvider.getSystemConfigurationValueFacade().getValue(BACKGROUND_COLOR_CONFIG_KEY);
147+
148+
if (StringUtils.isNotBlank(backgroundColor) || "default".equals(backgroundColor)) {
149+
// no need to configure anything as we can keep the default color.
150+
return;
151+
}
152+
153+
addStyleName("color-background");
154+
155+
String actualColorBackgroundColor = determineActualColor(backgroundColor);
156+
157+
Page.Styles styles = Page.getCurrent().getStyles();
158+
styles.add(
159+
".valo-menu-color-background {\n" + " background-color: " + actualColorBackgroundColor + " !important;\n"
160+
+ " background-image: -webkit-linear-gradient(right, " + actualColorBackgroundColor + " 0%, #EEFA5F" + actualColorBackgroundColor
161+
+ " 8px) !important;\n" + " background-image: linear-gradient(to left, " + actualColorBackgroundColor + " 0%, "
162+
+ actualColorBackgroundColor + " 8px) !important;" + " }");
163+
}
164+
165+
private static @NotNull String determineActualColor(String backgroundColor) {
166+
String actualColorBackgroundColor;
167+
switch (backgroundColor) {
168+
case "green":
169+
actualColorBackgroundColor = "#108548";
170+
break;
171+
case "red":
172+
actualColorBackgroundColor = "#dd2b0e";
173+
break;
174+
case "indigo":
175+
actualColorBackgroundColor = "#7b58cf";
176+
break;
177+
case "gray":
178+
actualColorBackgroundColor = "#737278";
179+
break;
180+
default:
181+
actualColorBackgroundColor = backgroundColor;
182+
}
183+
return actualColorBackgroundColor;
184+
}
185+
139186
private void showSettingsPopup() {
140187

141188
Window window = VaadinUiUtil.createPopupWindow();
142189
window.setCaption(I18nProperties.getString(Strings.headingUserSettings));
143190
window.setModal(true);
144191

145-
CommitDiscardWrapperComponent<UserSettingsForm> component =
146-
ControllerProvider.getUserController().getUserSettingsComponent(() -> window.close());
192+
CommitDiscardWrapperComponent<UserSettingsForm> component = ControllerProvider.getUserController().getUserSettingsComponent(window::close);
147193

148194
window.setContent(component);
149195
UI.getCurrent().addWindow(window);

0 commit comments

Comments
 (0)