[Sitemap] Accept an optional icon for each value/label mapping (#3809)

* [Sitemap] Accept an optional icon for each value/label mapping

When set by the user, the icon can be used by UIs for switch element with mappings to render a button with the icon rather than the label.

Related to #3441

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
pull/3819/head
lolodomo 2023-10-02 09:36:23 +02:00 committed by GitHub
parent fffa968263
commit f7d176570c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -134,6 +134,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
* @author Laurent Garnier - Added support for icon color
* @author Mark Herwege - Added pattern and unit fields
* @author Laurent Garnier - Added support for new sitemap element Buttongrid
* @author Laurent Garnier - Added icon field for mappings used for switch element
*/
@Component(service = { RESTResource.class, EventSubscriber.class })
@JaxrsResource
@ -558,6 +559,7 @@ public class SitemapResource
MappingDTO mappingBean = new MappingDTO();
mappingBean.command = mapping.getCmd();
mappingBean.label = mapping.getLabel();
mappingBean.icon = mapping.getIcon();
bean.mappings.add(mappingBean);
}
}

View File

@ -172,7 +172,7 @@ Button:
position=INT ':' cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;
Mapping:
cmd=Command '=' label=(ID | STRING);
cmd=Command '=' label=(ID | STRING) ('=' icon=Icon)?;
VisibilityRule:
(item=ID) (condition=('==' | '>' | '<' | '>=' | '<=' | '!=')) (sign=('-' | '+'))? (state=XState);

View File

@ -79,6 +79,7 @@ import org.slf4j.LoggerFactory;
* @author Yannick Schaus - Initial contribution
* @author Laurent Garnier - icon color support for all widgets
* @author Laurent Garnier - Added support for new element Buttongrid
* @author Laurent Garnier - Added icon field for mappings
*/
@NonNullByDefault
@Component(service = SitemapProvider.class)
@ -331,11 +332,14 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan
if (component.getConfig().get("mappings") instanceof Collection<?>) {
for (Object sourceMapping : (Collection<?>) component.getConfig().get("mappings")) {
if (sourceMapping instanceof String) {
String cmd = sourceMapping.toString().split("=")[0].trim();
String label = sourceMapping.toString().split("=")[1].trim();
String[] splitMapping = sourceMapping.toString().split("=");
String cmd = splitMapping[0].trim();
String label = splitMapping[1].trim();
String icon = splitMapping.length < 3 ? null : splitMapping[2].trim();
MappingImpl mapping = (MappingImpl) SitemapFactory.eINSTANCE.createMapping();
mapping.setCmd(cmd);
mapping.setLabel(label);
mapping.setIcon(icon);
mappings.add(mapping);
}
}