100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
UI updates: Moved icon set into core to break circular dependency
Rich Turnerce5195f096dd
diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.tsindex ab4794bcf..5c2faf6f2 100644--- a/ui/component/core/src/index.ts+++ b/ui/component/core/src/index.ts@@ -1,7 +1,6 @@import "url-search-params-polyfill";import {Console} from "./console";import rest from "@openremote/rest";-import {IconSets} from "@openremote/or-icon";import {AxiosRequestConfig} from "axios";import {EventProvider, EventProviderFactory, EventProviderStatus, WebSocketEventProvider} from "./event";import i18next from "i18next";@@ -9,12 +8,12 @@ import i18nextXhr from "i18next-xhr-backend";import moment from "moment";import {AssetDescriptor,- Attribute,AttributeDescriptor,AttributeValueDescriptor,MetaItemDescriptor} from "@openremote/model";import * as Util from "./util";+import orIconSet from "./or-icon-set";// Re-exportsexport {Util};@@ -23,6 +22,8 @@ export * from "./console";export * from "./event";export * from "./defaults";+export const DEFAULT_ICONSET: string = "mdi";+export declare type KeycloakPromise<T> = {success<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | KeycloakPromise<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | KeycloakPromise<TResult2>) | undefined | null): KeycloakPromise<TResult1 | TResult2>;error<TResult = never>(onrejected?: ((reason: any) => TResult | KeycloakPromise<TResult>) | undefined | null): Promise<T | TResult>;@@ -105,6 +106,78 @@ export interface ManagerConfig {configureTranslationsOptions?: (i18next: i18next.InitOptions) => void;}+export class IconSetAddedEvent extends CustomEvent<void> {++ public static readonly NAME = "or-iconset-added";++ constructor() {+ super(IconSetAddedEvent.NAME, {+ bubbles: true,+ composed: true+ });+ }+}++declare global {+ export interface HTMLElementEventMap {+ [IconSetAddedEvent.NAME]: IconSetAddedEvent;+ }+}++export interface IconSetSvg {+ size: number;+ icons: {[name: string]: string};+}++export class ORIconSets {+ private _icons: {[name: string]: IconSetSvg} = {};++ addIconSet(name: string, iconset: IconSetSvg) {+ this._icons[name] = iconset;+ window.dispatchEvent(new IconSetAddedEvent());+ }++ getIconSet(name: string) {+ return this._icons[name];+ }++ getIcon(icon: string | undefined): Element | undefined {+ if (!icon) {+ return undefined;+ }++ let parts = (icon || "").split(":");+ let iconName = parts.pop();+ let iconSetName = parts.pop() || DEFAULT_ICONSET;+ if (!iconSetName || iconSetName === "" || !iconName || iconName === "") {+ return;+ }++ let iconSet = IconSets.getIconSet(iconSetName);+ //iconName = iconName.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });++ if (!iconSet || !iconSet.icons.hasOwnProperty(iconName)) {+ return;+ }++ const iconData = iconSet.icons[iconName];+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");+ svg.setAttribute("viewBox", "0 0 " + iconSet.size + " " + iconSet.size);+ svg.style.cssText = "pointer-events: none; display: block; width: 100%; height: 100%;";+ svg.setAttribute("preserveAspectRatio", "xMidYMid meet");+ svg.setAttribute("focusable", "false");+ if (iconData.startsWith("<")) {+ svg.innerHTML = iconData;+ } else {+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");+ path.setAttribute("d", iconData);+ path.style.pointerEvents = "pointer-events: var(--or-icon-pointer-events, none);";+ svg.appendChild(path);+ }+ return svg;+ }+}+export class AssetModelUtil {public static _assetDescriptors: AssetDescriptor[] = [];@@ -496,11 +569,12 @@ export class Manager implements EventProviderFactory {});this._managerVersion = json && json.version ? json.version : "";- // Load material design icons if requested+ // Load material design and OR icon sets if requestedif (this._config.loadIcons) {const response = await fetch(manager.config.managerUrl + "/shared/mdi-icons.json");- const iconSet = await response.json();- IconSets.addIconSet("mdi", iconSet);+ const mdiIconSet = await response.json();+ IconSets.addIconSet("mdi", mdiIconSet);+ IconSets.addIconSet("or", orIconSet);}return true;@@ -943,7 +1017,7 @@ export class Manager implements EventProviderFactory {}const manager = new Manager();+const _iconSets = new ORIconSets();-export {manager};-+export const IconSets = _iconSets;export default manager;diff --git a/ui/component/or-icon/src/or-icon-set.ts b/ui/component/core/src/or-icon-set.tssimilarity index 100%rename from ui/component/or-icon/src/or-icon-set.tsrename to ui/component/core/src/or-icon-set.tsdiff --git a/ui/component/or-icon/src/index.ts b/ui/component/or-icon/src/index.tsindex e9868e4de..93d7e008c 100644--- a/ui/component/or-icon/src/index.ts+++ b/ui/component/or-icon/src/index.ts@@ -1,7 +1,6 @@import {css, customElement, html, LitElement, property, PropertyValues, TemplateResult} from "lit-element";-import orIconSet from "./or-icon-set";import {AssetDescriptor, AssetType} from "@openremote/model";-import {AssetModelUtil} from "@openremote/core";+import {IconSetAddedEvent, ORIconSets, AssetModelUtil} from "@openremote/core";export function getAssetDescriptorIconTemplate(descriptor: AssetDescriptor | undefined, fallbackColor?: string | undefined, fallbackIcon?: string | undefined, overrideColor?: string | undefined, overrideIcon?: string | undefined): TemplateResult {const color = overrideColor ? overrideColor : AssetModelUtil.getAssetDescriptorColor(descriptor, fallbackColor);@@ -9,86 +8,13 @@ export function getAssetDescriptorIconTemplate(descriptor: AssetDescriptor | undreturn html`<or-icon style="--or-icon-fill: ${color ? "#" + color : "unset"}" icon="${icon ? icon : AssetType.THING.icon}"></or-icon>`;}-export interface IconSetSvg {- size: number;- icons: {[name: string]: string};-}-export class IconSetAddedEvent extends CustomEvent<void> {-- public static readonly NAME = "or-icon-iconset-added";-- constructor() {- super(IconSetAddedEvent.NAME, {- bubbles: true,- composed: true- });- }-}--declare global {- export interface HTMLElementEventMap {- [IconSetAddedEvent.NAME]: IconSetAddedEvent;- }-}--class _IconSets {- private _icons: {[name: string]: IconSetSvg} = {- or: orIconSet- };-- addIconSet(name: string, iconset: IconSetSvg) {- this._icons[name] = iconset;- window.dispatchEvent(new IconSetAddedEvent());- }-- getIconSet(name: string) {- return this._icons[name];- }-- getIcon(icon: string | undefined): Element | undefined {- if (!icon) {- return undefined;- }+const _iconSets = new ORIconSets();- let parts = (icon || "").split(":");- let iconName = parts.pop();- let iconSetName = parts.pop() || OrIcon.DEFAULT_ICONSET;- if (!iconSetName || iconSetName === "" || !iconName || iconName === "") {- return;- }-- let iconSet = IconSets.getIconSet(iconSetName);- //iconName = iconName.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });-- if (!iconSet || !iconSet.icons.hasOwnProperty(iconName)) {- return;- }-- const iconData = iconSet.icons[iconName];- const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");- svg.setAttribute("viewBox", "0 0 " + iconSet.size + " " + iconSet.size);- svg.style.cssText = "pointer-events: none; display: block; width: 100%; height: 100%;";- svg.setAttribute("preserveAspectRatio", "xMidYMid meet");- svg.setAttribute("focusable", "false");- if (iconData.startsWith("<")) {- svg.innerHTML = iconData;- } else {- const path = document.createElementNS("http://www.w3.org/2000/svg", "path");- path.setAttribute("d", iconData);- path.style.pointerEvents = "pointer-events: var(--or-icon-pointer-events, none);";- svg.appendChild(path);- }- return svg;- }-}--export const IconSets = new _IconSets();+export const IconSets = _iconSets;@customElement("or-icon")export class OrIcon extends LitElement {- static DEFAULT_ICONSET: string = "mdi";-static styles = css`:host {diff --git a/ui/component/or-rules-editor/tsconfig.json b/ui/component/or-rules-editor/tsconfig.jsonindex 72c588fcb..377f5de34 100644--- a/ui/component/or-rules-editor/tsconfig.json+++ b/ui/component/or-rules-editor/tsconfig.json@@ -16,6 +16,7 @@{ "path": "../or-icon" },{ "path": "../or-panel" },{ "path": "../or-asset-viewer" },+ { "path": "../or-asset-tree" },{ "path": "../or-mwc-components" },{ "path": "../rest" }]