Skip to content

Commit

Permalink
[BasicUI] Add a new setting to choose the nb of columns
Browse files Browse the repository at this point in the history
Also allow 3 columns on desktop.

Possible number of columns on desktop: 1 or 2 or 3.
Possible number of columns on tablet: 1 or 2
Possible number of columns on phone: 1

Closes #1836

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo committed Aug 13, 2023
1 parent 0d34818 commit b8e8921
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ public class WebAppConfig {
private static final String DEFAULT_INLINE_SVG = "false";
private static final String DEFAULT_WEB_AUDIO = "false";

private static final String DEFAULT_CONFIG_NB_COLUMNS = "3-2";
private static final int DEFAULT_NB_COLUMNS_DESKTOP = 3;
private static final int DEFAULT_NB_COLUMNS_TABLET = 2;

private String defaultSitemap = DEFAULT_SITEMAP;
private String theme = DEFAULT_THEME;
private int nbColsDesktop = DEFAULT_NB_COLUMNS_DESKTOP;
private int nbColsTablet = DEFAULT_NB_COLUMNS_TABLET;
private boolean iconify = Boolean.parseBoolean(DEFAULT_ICONIFY);
private boolean inlineSvg = Boolean.parseBoolean(DEFAULT_INLINE_SVG);
private boolean webAudio = Boolean.parseBoolean(DEFAULT_WEB_AUDIO);
Expand All @@ -53,6 +59,7 @@ public class WebAppConfig {

private static final String CONFIG_ENABLE_ICONS = "enableIcons";
private static final String CONFIG_CONDENSED_LAYOUT = "condensedLayout";
private static final String CONFIG_NB_COLUMNS = "nbColumns";
private static final String CONFIG_CAPITALIZE = "capitalizeValues";

static {
Expand Down Expand Up @@ -81,6 +88,9 @@ private void applyCssClasses(Map<String, Object> configProps) {
cssClassList.add(entry.getValue());
}
}
if (nbColsDesktop == 3) {
cssClassList.add("ui-large-window");
}
}

public void applyConfig(Map<String, Object> configProps) {
Expand All @@ -90,6 +100,22 @@ public void applyConfig(Map<String, Object> configProps) {
if ("default".equals(theme)) {
theme = DEFAULT_THEME;
}
String nbColumns = (String) configProps.getOrDefault(CONFIG_NB_COLUMNS, DEFAULT_CONFIG_NB_COLUMNS);
if (nbColumns.length() == 3) {
try {
nbColsDesktop = Integer.parseInt(nbColumns.substring(0, 1));
} catch (NumberFormatException e) {
nbColsDesktop = DEFAULT_NB_COLUMNS_DESKTOP;
}
try {
nbColsTablet = Integer.parseInt(nbColumns.substring(2, 3));
} catch (NumberFormatException e) {
nbColsTablet = DEFAULT_NB_COLUMNS_TABLET;
}
} else {
nbColsDesktop = DEFAULT_NB_COLUMNS_DESKTOP;
nbColsTablet = DEFAULT_NB_COLUMNS_TABLET;
}
iconify = "true".equalsIgnoreCase((String) configProps.getOrDefault("enableIconify", DEFAULT_ICONIFY));
inlineSvg = "true".equalsIgnoreCase((String) configProps.getOrDefault("inlineSvg", DEFAULT_INLINE_SVG));
webAudio = "true".equalsIgnoreCase((String) configProps.getOrDefault("webAudio", DEFAULT_WEB_AUDIO));
Expand All @@ -113,6 +139,14 @@ public String getCssClassList() {
return result;
}

public int getNbColsDesktop() {
return nbColsDesktop;
}

public int getNbColsTablet() {
return nbColsTablet;
}

public boolean isIconifyEnabled() {
return iconify;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ protected String preprocessSnippet(String originalSnippet, Widget w) {
protected String preprocessSnippet(String originalSnippet, Widget w, boolean ignoreStateForIcon) {
String snippet = preprocessIcon(originalSnippet, w, ignoreStateForIcon);

snippet = snippet.replace("%cells%", String.valueOf(12 / config.getNbColsDesktop()));
snippet = snippet.replace("%cells_tablet%", String.valueOf(8 / config.getNbColsTablet()));
snippet = snippet.replace("%widget_id%", itemUIRegistry.getWidgetId(w));
snippet = snippet.replace("%item%", w.getItem() != null ? w.getItem() : "");
// Optimization: avoid calling 3 times itemUIRegistry.getLabel(w)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@
</options>
<default>false</default>
</parameter>
<parameter name="nbColumns" type="text">
<label>Number Columns</label>
<description>The number of columns to consider to fill the grid in large screen width (desktop) and medium screen
width (tablet).</description>
<options>
<option value="1-1">1 column on desktop and tablet</option>
<option value="2-1">2 columns on desktop but only 1 on tablet</option>
<option value="2-2">2 columns on desktop and tablet</option>
<option value="3-1">3 columns on desktop but only 1 on tablet</option>
<option value="3-2">3 columns on desktop but only 2 on tablet</option>
</options>
<default>3-2</default>
</parameter>
<parameter name="capitalizeValues" type="text" required="true">
<label>Capitalize Values</label>
<description>Displays all widget states in uppercase.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ ui.config.basic.inlineSvg.label = Inline SVG
ui.config.basic.inlineSvg.description = If enabled, any SVG icon provided by the openHAB icon server will automatically be converted to an inline SVG in the WEB page, allowing control of its color with the sitemap widget property "iconcolor" in the case where the SVG icon sets "currentColor" as the fill color. Note that this will work with custom SVG icons but not with all the packaged icons from the classic iconset since they are defined with a hard-coded color palette. This feature is disabled by default.
ui.config.basic.inlineSvg.option.true = Enable
ui.config.basic.inlineSvg.option.false = Disable
ui.config.basic.nbColumns.label = Number Columns
ui.config.basic.nbColumns.description = The number of columns to consider to fill the grid in large screen width (desktop) and medium screen width (tablet).
ui.config.basic.nbColumns.option.1-1 = 1 column on desktop and tablet
ui.config.basic.nbColumns.option.2-1 = 2 columns on desktop but only 1 on tablet
ui.config.basic.nbColumns.option.2-2 = 2 columns on desktop and tablet
ui.config.basic.nbColumns.option.3-1 = 3 columns on desktop but only 1 on tablet
ui.config.basic.nbColumns.option.3-2 = 3 columns on desktop but only 2 on tablet
ui.config.basic.theme.label = Theme
ui.config.basic.theme.description = Defines the UI theme.
ui.config.basic.theme.option.bright = Bright
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-form__link %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet mdl-form__link %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--12-col %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-form__link %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet mdl-form__link %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-form__link %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--%cells%-col mdl-cell--%cells_tablet%-col-tablet mdl-form__link %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<div class="mdl-form__row mdl-cell mdl-cell--12-col %visibility_class%">
<span %iconstyle% class="mdl-form__icon">
%icon_snippet%
</span>
Expand Down
3 changes: 3 additions & 0 deletions bundles/org.openhab.ui.basic/web-src/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@

.page-content {
max-width: 1080px;
html.ui-large-window & {
max-width: 1620px;
}
@media screen and (max-width: $layout-tablet-size-threshold) {
padding: 0;
}
Expand Down

0 comments on commit b8e8921

Please sign in to comment.