Skip to content

Commit

Permalink
[basicui] Remove iconType configuration setting (#114)
Browse files Browse the repository at this point in the history
Icon type is now SVG by default.
Customized icons, even in only PNG format, are still handled.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo authored and kaikreuzer committed Sep 3, 2019
1 parent c5b3049 commit 742fc0b
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 43 deletions.
Expand Up @@ -25,14 +25,12 @@
*/
public class WebAppConfig {
private static final String DEFAULT_SITEMAP = "default";
private static final String DEFAULT_ICON_TYPE = "png";

public static final String THEME_NAME_DEFAULT = "default";
public static final String THEME_NAME_DARK = "dark";
private static final String DEFAULT_THEME = THEME_NAME_DEFAULT;

private String defaultSitemap = DEFAULT_SITEMAP;
private String iconType = DEFAULT_ICON_TYPE;
private String theme = DEFAULT_THEME;

private List<String> cssClassList = new ArrayList<String>();
Expand Down Expand Up @@ -72,25 +70,17 @@ private void applyCssClasses(Map<String, Object> configProps) {

public void applyConfig(Map<String, Object> configProps) {
String configDefaultSitemap = (String) configProps.get("defaultSitemap");
String configIconType = (String) configProps.get("iconType");
String configTheme = (String) configProps.get("theme");

if (configDefaultSitemap == null) {
configDefaultSitemap = DEFAULT_SITEMAP;
}

if (configIconType == null) {
configIconType = DEFAULT_ICON_TYPE;
} else if (!configIconType.equalsIgnoreCase("svg") && !configIconType.equalsIgnoreCase("png")) {
configIconType = DEFAULT_ICON_TYPE;
}

if (configTheme == null) {
configTheme = DEFAULT_THEME;
}

defaultSitemap = configDefaultSitemap;
iconType = configIconType;
theme = configTheme;

applyCssClasses(configProps);
Expand All @@ -100,10 +90,6 @@ public String getDefaultSitemap() {
return defaultSitemap;
}

public String getIconType() {
return iconType;
}

public String getTheme() {
return theme;
}
Expand Down
Expand Up @@ -52,6 +52,8 @@ public abstract class AbstractWidgetRenderer implements WidgetRenderer {

private final Logger logger = LoggerFactory.getLogger(AbstractWidgetRenderer.class);

public static final String ICON_TYPE = "svg";

protected ItemUIRegistry itemUIRegistry;
protected TranslationProvider i18nProvider;
protected LocaleProvider localeProvider;
Expand Down Expand Up @@ -115,7 +117,7 @@ protected void deactivate(BundleContext context) {
protected String preprocessSnippet(String originalSnippet, Widget w) {
String snippet = originalSnippet;
snippet = StringUtils.replace(snippet, "%widget_id%", itemUIRegistry.getWidgetId(w));
snippet = StringUtils.replace(snippet, "%icon_type%", config.getIconType());
snippet = StringUtils.replace(snippet, "%icon_type%", ICON_TYPE);
snippet = StringUtils.replace(snippet, "%item%", w.getItem() != null ? w.getItem() : "");
// Optimization: avoid calling 3 times itemUIRegistry.getLabel(w)
String text = itemUIRegistry.getLabel(w);
Expand Down
Expand Up @@ -84,11 +84,11 @@ public void removeWidgetRenderer(WidgetRenderer widgetRenderer) {
/**
* This is the main method, which is called to produce the HTML code for a servlet request.
*
* @param id the id of the parent widget whose children are about to appear on this page
* @param sitemap the sitemap to use
* @param label the title of this page
* @param id the id of the parent widget whose children are about to appear on this page
* @param sitemap the sitemap to use
* @param label the title of this page
* @param children a list of widgets that should appear on this page
* @param async true, if this is an asynchronous request. This will use a different HTML skeleton
* @param async true, if this is an asynchronous request. This will use a different HTML skeleton
* @return a string builder with the produced HTML code
* @throws RenderException if an error occurs during the processing
*/
Expand All @@ -112,7 +112,7 @@ public StringBuilder processPage(String id, String sitemap, String label, EList<
snippet = StringUtils.replace(snippet, "%servletname%", WebAppServlet.SERVLET_NAME);
snippet = StringUtils.replace(snippet, "%sitemap%", sitemap);
snippet = StringUtils.replace(snippet, "%htmlclass%", config.getCssClassList());
snippet = StringUtils.replace(snippet, "%icon_type%", config.getIconType());
snippet = StringUtils.replace(snippet, "%icon_type%", ICON_TYPE);
snippet = StringUtils.replace(snippet, "%theme%", config.getTheme());

String[] parts = snippet.split("%children%");
Expand Down
Expand Up @@ -14,15 +14,6 @@
</options>
<default>default</default>
</parameter>
<parameter name="iconType" type="text" required="true">
<label>Icon Format</label>
<description>Defines whether bitmap or vector icons are used by the UI.</description>
<options>
<option value="png">Bitmap</option>
<option value="svg">Vector</option>
</options>
<default>svg</default>
</parameter>
<parameter name="enableIcons" type="text" required="true">
<label>Enable Icons</label>
<description>Defines whether UI renders icons for the widgets or not.</description>
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%&anyFormat=true" />
</span>
<span %labelstyle% class="mdl-form__label">
%label%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?state=%icon_state%&format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?state=%icon_state%&format=%icon_type%&anyFormat=true" />
</span>
<span class="mdl-form__label">
%label%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-form__link %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%&anyFormat=true" />
</span>
<span %labelstyle% class="mdl-form__label">
%label%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?format=%icon_type%&anyFormat=true" />
</span>
<span %labelstyle% class="mdl-form__label">
%label%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%&anyFormat=true" />
</span>
<span class="mdl-form__label">
%label%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-form__link %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%&anyFormat=true" />
</span>
<span %labelstyle% class="mdl-form__label">
%label_header%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%&anyFormat=true" />
</span>
<span class="mdl-form__label">
%label%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%&anyFormat=true" />
</span>
<span %labelstyle% class="mdl-form__label">
%label%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%&anyFormat=true" />
</span>
<span %labelstyle% class="mdl-form__label">
%label%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%&anyFormat=true" />
</span>
<span %labelstyle% class="mdl-form__label">
%label%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet mdl-form__link %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?state=%state%&format=%icon_type%&anyFormat=true" />
</span>
<span %labelstyle% class="mdl-form__label">
%label%
Expand Down
@@ -1,6 +1,6 @@
<div class="mdl-form__row mdl-cell mdl-cell--6-col mdl-cell--8-col-tablet %visibility_class%">
<span class="mdl-form__icon">
<img data-icon="%category%" src="../icon/%category%?format=%icon_type%" />
<img data-icon="%category%" src="../icon/%category%?format=%icon_type%&anyFormat=true" />
</span>
<span %labelstyle% class="mdl-form__label">
%label%
Expand Down
6 changes: 4 additions & 2 deletions bundles/org.openhab.ui.basic/web-src/smarthome.js
Expand Up @@ -358,14 +358,16 @@
"?state=" +
encodeURIComponent(state) +
"&format=" +
smarthome.UI.iconType
smarthome.UI.iconType +
"&anyFormat=true"
);
} else {
_t.icon.setAttribute("src",
"/icon/" +
_t.iconName +
"?format=" +
smarthome.UI.iconType
smarthome.UI.iconType +
"&anyFormat=true"
);
}
}
Expand Down

0 comments on commit 742fc0b

Please sign in to comment.