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: Various updates see below: 38 - or-rules-editor overhaul (to align with UI requirements) #38, #40, #41, #42 - Added support for matchedAssets in RuleActionTarget (to align with UI requirements) - Added or-mwc-components for all MWC wrapper components (e.g. MDCMenu) - Added or-language to or-header
Rich Turnere572561a0467
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.jsonindex 284f46016..3e3efe2c3 100644--- a/deployment/manager/shared/locales/en/or.json+++ b/deployment/manager/shared/locales/en/or.json@@ -1,8 +1,8 @@{"map": "Map",- "maps": "Maps",+ "map_plural": "Maps","rule": "Rule",- "rules": "Rules",+ "rule_plural": "Rules","asset": "Asset","asset_plural": "Assets","attribute": "Attribute",@@ -61,11 +61,10 @@"confirmDelete": "Are you sure you want to delete?","when": "When","then": "Then",- "and": "and",- "or": "or",+ "orWhen": "Or when","datetime": "Datetime","timer": "Timer",- "rulesEditorAddCondition": "Add condition",+ "rulesEditorAddCondition": "Add another condition","rulesEditorAddGroup": "Add group","rulesEditorAddAction": "Add action","sortBy": "Sort by",@@ -92,9 +91,15 @@"year": "Year","period": "Period","ending": "Ending",- "English": "English",- "Dutch": "Dutch",- "French": "French",- "German": "German",- "Spanish": "Spanish"+ "english": "English",+ "dutch": "Dutch",+ "french": "French",+ "german": "German",+ "spanish": "Spanish",+ "noRuleSelected": "Please select a rule on the left",+ "anyOfThisType": "Any of this type",+ "notification": "Notification",+ "matched": "Matched",+ "unmatched": "Unmatched",+ "wait": "Wait"}\ No newline at end of filediff --git a/deployment/manager/shared/locales/nl/or.json b/deployment/manager/shared/locales/nl/or.jsonindex b1b884b90..2c23f8841 100644--- a/deployment/manager/shared/locales/nl/or.json+++ b/deployment/manager/shared/locales/nl/or.json@@ -2,7 +2,7 @@"map": "Kaart","maps": "Kaarten","rule": "Regel",- "rules": "Regels",+ "rule_plural": "Regels","asset": "Asset","asset_plural": "Assets","attribute": "Attribute",@@ -59,15 +59,14 @@"active": "Actief","continueWithoutSaving": "Als je doorgaat worden je veranderingen niet opgeslagen. Doorgaan zonder opslaan?","confirmDelete": "Weet je zeker dat je dit wil verwijderen?",- "when": "als",- "then": "dan",- "and": "en",- "or": "of",+ "when": "Als",+ "then": "Dan",+ "orWhen": "Of als","datetime": "Datum en tijd","timer": "Timer",- "rulesEditorAddCondition": "Voorwaarde",+ "rulesEditorAddCondition": "Voeg nog een voorwaarde toe","rulesEditorAddGroup": "Groep",- "rulesEditorAddAction": "Actie",+ "rulesEditorAddAction": "Voeg nog een actie toe","sortBy": "Sorteren op","assetType": "Asset type","creationDate": "Aangemaakt op",@@ -92,9 +91,12 @@"year": "Year","period": "Period","ending": "Ending",- "English": "Engels",- "Dutch": "Nederlands",- "French": "Frans",- "German": "Duits",- "Spanish": "Spaans"+ "english": "Engels",+ "dutch": "Nederlands",+ "french": "Frans",+ "german": "Duits",+ "spanish": "Spaans",+ "noRuleSelected": "Please select a rule on the left",+ "anyOfThisType": "Elk van dit type",+ "notification": "Aankondiging"}\ No newline at end of filediff --git a/manager/src/main/java/org/openremote/manager/rules/JsonRulesBuilder.java b/manager/src/main/java/org/openremote/manager/rules/JsonRulesBuilder.javaindex b5d693596..59af5de88 100644--- a/manager/src/main/java/org/openremote/manager/rules/JsonRulesBuilder.java+++ b/manager/src/main/java/org/openremote/manager/rules/JsonRulesBuilder.java@@ -640,7 +640,7 @@ public class JsonRulesBuilder extends RulesBuilder {// Override the notification targets if set in the ruleNotification.TargetType targetType = Notification.TargetType.ASSET;- Collection<String> ids = getRuleActionTargetIds(ruleAction.target, useUnmatched, triggerStateMap, assetsFacade, usersFacade);+ Collection<String> ids = getRuleActionTargetIds(ruleAction.target, useUnmatched, triggerStateMap, assetsFacade, usersFacade, facts);if (targetIsNotAssets(ruleAction.target)) {targetType = Notification.TargetType.USER;}@@ -669,7 +669,7 @@ public class JsonRulesBuilder extends RulesBuilder {return null;}- Collection<String> ids = getRuleActionTargetIds(ruleAction.target, useUnmatched, triggerStateMap, assetsFacade, usersFacade);+ Collection<String> ids = getRuleActionTargetIds(ruleAction.target, useUnmatched, triggerStateMap, assetsFacade, usersFacade, facts);if (ids == null || ids.isEmpty()) {log(Level.FINEST, "No targets for write attribute rule action so skipping: " + rule.name + " '" + actionsName + "' action index " + index);@@ -710,7 +710,7 @@ public class JsonRulesBuilder extends RulesBuilder {if (ruleAction.target != null && ruleAction.target.users != null) {throw new IllegalStateException("Cannot use action type '" + RuleActionUpdateAttribute.class.getSimpleName() + "' with user target");}- matchingAssetIds = new ArrayList<>(getRuleActionTargetIds(ruleAction.target, useUnmatched, triggerStateMap, assetsFacade, usersFacade));+ matchingAssetIds = new ArrayList<>(getRuleActionTargetIds(ruleAction.target, useUnmatched, triggerStateMap, assetsFacade, usersFacade, facts));} else {matchingAssetIds = facts.matchAssetState(ruleAction.target.assets)@@ -815,7 +815,7 @@ public class JsonRulesBuilder extends RulesBuilder {return null;}- protected static Collection<String> getRuleActionTargetIds(RuleActionTarget target, boolean useUnmatched, Map<String, RuleTriggerState> triggerStateMap, Assets assetsFacade, Users usersFacade) {+ protected static Collection<String> getRuleActionTargetIds(RuleActionTarget target, boolean useUnmatched, Map<String, RuleTriggerState> triggerStateMap, Assets assetsFacade, Users usersFacade, RulesFacts facts) {if (target != null) {if (!TextUtil.isNullOrEmpty(target.ruleConditionTag) && triggerStateMap != null) {RuleTriggerState triggerState = triggerStateMap.get(target.ruleConditionTag);@@ -826,6 +826,19 @@ public class JsonRulesBuilder extends RulesBuilder {return triggerState != null ? triggerState.getUnmatchedAssetIds() : Collections.emptyList();}+ if (target.matchedAssets != null) {+ List<String> compareAssetIds = triggerStateMap.values().stream()+ .flatMap(triggerState ->+ useUnmatched ? triggerState.getUnmatchedAssetIds().stream() : triggerState.getMatchedAssetIds().stream())+ .collect(Collectors.toList());++ return facts.matchAssetState(target.matchedAssets)+ .map(AssetState::getId)+ .distinct()+ .filter(matchedAssetId -> compareAssetIds.indexOf(matchedAssetId) >= 0)+ .collect(Collectors.toList());+ }+if (target.assets != null) {return getAssetIds(assetsFacade, target.assets);}diff --git a/model/src/main/java/org/openremote/model/rules/json/RuleActionTarget.java b/model/src/main/java/org/openremote/model/rules/json/RuleActionTarget.javaindex 8ae9f0cf8..54682da7b 100644--- a/model/src/main/java/org/openremote/model/rules/json/RuleActionTarget.java+++ b/model/src/main/java/org/openremote/model/rules/json/RuleActionTarget.java@@ -32,6 +32,7 @@ import org.openremote.model.query.UserQuery;*/public class RuleActionTarget {public String ruleConditionTag;+ public AssetQuery matchedAssets;public AssetQuery assets;public UserQuery users;}diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.tsindex 68dc2764f..ab4794bcf 100644--- a/ui/component/core/src/index.ts+++ b/ui/component/core/src/index.ts@@ -215,20 +215,6 @@ export class AssetModelUtil {return attributeValueDescriptor1.name === attributeValueDescriptor2.name && attributeValueDescriptor1.valueType === attributeValueDescriptor2.valueType;}- public static getMetaValue(metaItemUrn: string | MetaItemDescriptor, attribute: Attribute | undefined, descriptor: AttributeDescriptor | undefined): any {- const urn = typeof metaItemUrn === "string" ? metaItemUrn : (metaItemUrn as MetaItemDescriptor).urn;-- if (attribute && attribute.meta) {- const metaItem = attribute.meta.find((mi) => mi.name === urn);- return metaItem ? metaItem.value : undefined;- }-- if (descriptor && descriptor.metaItemDescriptors) {- const metaItemDescriptor = descriptor.metaItemDescriptors.find((mid) => mid.urn === urn);- return metaItemDescriptor ? metaItemDescriptor.initialValue : undefined;- }- }-public static getMetaInitialValueFromMetaDescriptors(metaItemUrn: MetaItemDescriptor | string, metaItemDescriptors: MetaItemDescriptor[] | undefined): any | undefined {if (!metaItemDescriptors) {return;@@ -250,6 +236,22 @@ export class AssetModelUtil {newMetaItem.initialValue = initialValue;return newMetaItem;}++ public static getAssetDescriptorColor(descriptor: AssetDescriptor | undefined, fallbackColor?: string): string | undefined {+ return descriptor && descriptor.color ? descriptor.color : fallbackColor;+ }++ public static getAssetDescriptorIcon(descriptor: AssetDescriptor | undefined, fallbackIcon?: string): string | undefined {+ return descriptor && descriptor.icon ? descriptor.icon : fallbackIcon;+ }++ public static hasMetaItem(descriptor: AttributeDescriptor | undefined, name: string): boolean {+ if (!descriptor || !descriptor.metaItemDescriptors) {+ return false;+ }++ return !!descriptor.metaItemDescriptors.find((mid) => mid.urn === name);+ }}export type EventCallback = (event: OREvent) => any;diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.tsindex dcccc59f9..d8e721342 100644--- a/ui/component/core/src/util.ts+++ b/ui/component/core/src/util.ts@@ -10,8 +10,13 @@ import {Attribute,AttributeEvent,MetaItem,- AssetAttribute+ AssetAttribute,+ AttributeDescriptor,+ MetaItemType,+ MetaItemDescriptor} from "@openremote/model";+import {AssetModelUtil} from "./index";+import i18next from "i18next";export class Deferred<T> {@@ -233,6 +238,34 @@ export function getFirstMetaItem(attribute: Attribute | undefined, name: string)return attribute.meta.find((metaItem) => metaItem.name === name);}+export function hasMetaItem(attribute: Attribute, name: string): boolean {+ return !!getFirstMetaItem(attribute, name);+}++export function getMetaValue(metaItemUrn: string | MetaItemDescriptor, attribute: Attribute | undefined, descriptor: AttributeDescriptor | undefined): any {+ const urn = typeof metaItemUrn === "string" ? metaItemUrn : (metaItemUrn as MetaItemDescriptor).urn;++ if (attribute && attribute.meta) {+ const metaItem = attribute.meta.find((mi) => mi.name === urn);+ return metaItem ? metaItem.value : undefined;+ }++ if (descriptor && descriptor.metaItemDescriptors) {+ const metaItemDescriptor = descriptor.metaItemDescriptors.find((mid) => mid.urn === urn);+ return metaItemDescriptor ? metaItemDescriptor.initialValue : undefined;+ }+}++export function getAttributeLabel(attribute: Attribute | undefined, descriptor: AttributeDescriptor | undefined, fallback?: string): string {+ if (!attribute && !descriptor) {+ return fallback || "";+ }++ const labelMetaValue = getMetaValue(MetaItemType.LABEL, attribute, descriptor);+ const name = attribute ? attribute.name : descriptor!.attributeName;+ return i18next.t([name, fallback || labelMetaValue || name]);+}+/*** Immutable update of an asset using the supplied attribute event*/diff --git a/ui/component/model/build.gradle b/ui/component/model/build.gradleindex 01d118cdc..a06bd40f2 100644--- a/ui/component/model/build.gradle+++ b/ui/component/model/build.gradle@@ -72,6 +72,9 @@ generateTypeScript {]}+build.dependsOn generateTypeScript, npmBuild+npmBuild.dependsOn generateTypeScript+clean {doLast {delete "dist"diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.tsindex 7912ede02..17ffe6f29 100644--- a/ui/component/or-asset-tree/src/index.ts+++ b/ui/component/or-asset-tree/src/index.ts@@ -7,6 +7,7 @@ import {style} from "./style";import manager, {AssetModelUtil, OREvent, EventCallback} from "@openremote/core";import {OrInputChangedEvent, InputType} from "@openremote/or-input";import Qs from "qs";+import {getAssetDescriptorIconTemplate} from "@openremote/or-icon";export interface UiAssetTreeNode extends AssetTreeNode {selected: boolean;@@ -26,6 +27,8 @@ interface NodeClickEventDetail {clickEvent: MouseEvent}+export {style}+export class OrAssetTreeRequestSelectEvent extends CustomEvent<RequestEventDetail<NodeClickEventDetail>> {public static readonly NAME = "or-asset-tree-request-select";@@ -166,8 +169,6 @@ export class OrAssetTree extends LitElement {@property()protected _showLoading: boolean = true;- protected _selectedNodes: UiAssetTreeNode[] = [];-@query("#sort-menu")protected _sortMenu!: HTMLDivElement;@@ -177,9 +178,14 @@ export class OrAssetTree extends LitElement {@query("#delete-confirm-modal")protected _deleteConfirmModal!: HTMLDivElement;+ protected _selectedNodes: UiAssetTreeNode[] = [];protected _initCallback?: EventCallback;protected _ready = false;+ public get selectedNodes(): UiAssetTreeNode[] {+ return this._selectedNodes ? [...this._selectedNodes] : [];+ }+protected _onReady() {this._ready = true;this._loadRealms();@@ -225,8 +231,8 @@ export class OrAssetTree extends LitElement {</div><div id="header-btns">- <button style="display:none;" ?hidden="${!this.selectedIds || this.selectedIds.length === 0}" @click="${() => this._onCopyClicked()}"><or-icon icon="content-copy"></or-icon></button>- <button ?hidden="${!this.selectedIds || this.selectedIds.length === 0}" @click="${() => this._onDeleteClicked()}"><or-icon icon="delete"></or-icon></button>+ <button style="display:none;" ?hidden="${!manager.hasRole("write:rules") || !this.selectedIds || this.selectedIds.length === 0}" @click="${() => this._onCopyClicked()}"><or-icon icon="content-copy"></or-icon></button>+ <button ?hidden="${!manager.hasRole("write:rules") || !this.selectedIds || this.selectedIds.length === 0}" @click="${() => this._onDeleteClicked()}"><or-icon icon="delete"></or-icon></button><button hidden @click="${() => this._onAddClicked()}"><or-icon icon="plus"></or-icon></button><button hidden @click="${() => this._onSearchClicked()}"><or-icon icon="magnify"></or-icon></button><button @click="${() => this._onSortClicked()}"><or-icon icon="sort-variant"></or-icon></button>@@ -297,7 +303,7 @@ export class OrAssetTree extends LitElement {<div class="node-container" style="padding-left: ${level*22}px"><div class="node-name"><div class="expander" ?data-expandable="${treeNode.expandable}"></div>- <or-icon style="--or-icon-fill: ${descriptor && descriptor.color ? "#" + descriptor.color : "unset"}" icon="${descriptor && descriptor.icon ? descriptor.icon : AssetType.THING.icon}"></or-icon>+ ${getAssetDescriptorIconTemplate(descriptor)}<span>${treeNode.asset!.name}</span></div></div>@@ -342,10 +348,6 @@ export class OrAssetTree extends LitElement {}}- public get selectedNodes(): UiAssetTreeNode[] {- return this._selectedNodes ? [...this._selectedNodes] : [];- }-protected _updateSelectedNodes() {const actuallySelectedIds: string[] = [];const selectedNodes: UiAssetTreeNode[] = [];@@ -370,7 +372,6 @@ export class OrAssetTree extends LitElement {this.dispatchEvent(new OrAssetTreeSelectionChangedEvent(this._selectedNodes));}-protected _updateSort(nodes: UiAssetTreeNode[], sortFunction: (a: UiAssetTreeNode, b: UiAssetTreeNode) => number) {if (!nodes) {return;@@ -472,7 +473,7 @@ export class OrAssetTree extends LitElement {}}- this.selectedIds = selectedIds;+ this.selectedIds = selectedIds;}protected _showDeleteModal() {@@ -544,6 +545,28 @@ export class OrAssetTree extends LitElement {}}+ protected _getRealm(): string | undefined {+ if (manager.isSuperUser() && this.realm) {+ return this.realm;+ }++ return manager.getRealm();+ }++ protected _onRealmChanged(evt: OrInputChangedEvent) {+ this.realm = evt.detail.value;+ this.assets = undefined;+ }++ protected _doRequest<T>(event: CustomEvent<RequestEventDetail<T>>, handler: (detail: T) => void) {+ this.dispatchEvent(event);+ window.setTimeout(() => {+ if (event.detail.allow) {+ handler(event.detail.detail);+ }+ })+ }+protected _loadAssets() {if (!this._ready) {@@ -587,37 +610,37 @@ export class OrAssetTree extends LitElement {protected _buildTreeNodes(assets: Asset[], sortFunction: (a: UiAssetTreeNode, b: UiAssetTreeNode) => number) {if (!assets || assets.length === 0) {this._nodes = [];- }-- let rootAssetIds: string[] | undefined;+ } else {+ let rootAssetIds: string[] | undefined;- if (this.rootAssetIds) {- rootAssetIds = this.rootAssetIds;- } else if (this.rootAssets) {- rootAssetIds = this.rootAssets.map((ra) => ra.id!);- }+ if (this.rootAssetIds) {+ rootAssetIds = this.rootAssetIds;+ } else if (this.rootAssets) {+ rootAssetIds = this.rootAssets.map((ra) => ra.id!);+ }- let rootAssets: UiAssetTreeNode[];+ let rootAssets: UiAssetTreeNode[];- if (rootAssetIds) {- rootAssets = assets.filter((asset) => rootAssetIds!.indexOf(asset.id!) >= 0).map((asset) => {- return {- asset: asset- } as UiAssetTreeNode;- });- } else {- rootAssets = assets.filter((asset) => !asset.parentId).map((asset) => {- return {- asset: asset- } as UiAssetTreeNode;- });- }+ if (rootAssetIds) {+ rootAssets = assets.filter((asset) => rootAssetIds!.indexOf(asset.id!) >= 0).map((asset) => {+ return {+ asset: asset+ } as UiAssetTreeNode;+ });+ } else {+ rootAssets = assets.filter((asset) => !asset.parentId).map((asset) => {+ return {+ asset: asset+ } as UiAssetTreeNode;+ });+ }- rootAssets.sort(sortFunction);- rootAssets.forEach((rootAsset) => this._buildChildTreeNodes(rootAsset, assets, sortFunction));+ rootAssets.sort(sortFunction);+ rootAssets.forEach((rootAsset) => this._buildChildTreeNodes(rootAsset, assets, sortFunction));- this._nodes = rootAssets;- if(this.selectedIds && this.selectedIds.length > 0) {+ this._nodes = rootAssets;+ }+ if (this.selectedIds && this.selectedIds.length > 0) {this._updateSelectedNodes();}this._showLoading = false;@@ -640,28 +663,6 @@ export class OrAssetTree extends LitElement {});}- protected _getRealm(): string | undefined {- if (manager.isSuperUser() && this.realm) {- return this.realm;- }-- return manager.getRealm();- }-- protected _onRealmChanged(evt: OrInputChangedEvent) {- this.realm = evt.detail.value;- this.assets = undefined;- }-- protected _doRequest<T>(event: CustomEvent<RequestEventDetail<T>>, handler: (detail: T) => void) {- this.dispatchEvent(event);- window.setTimeout(() => {- if (event.detail.allow) {- handler(event.detail.detail);- }- })- }-protected static _forEachNodeRecursive(nodes: UiAssetTreeNode[], fn: (node: UiAssetTreeNode) => void) {if (!nodes) {return;diff --git a/ui/component/or-asset-tree/src/style.ts b/ui/component/or-asset-tree/src/style.tsindex b35ded0e6..61584ef89 100644--- a/ui/component/or-asset-tree/src/style.ts+++ b/ui/component/or-asset-tree/src/style.ts@@ -190,7 +190,6 @@ export const style = css`}#list-container {- height: 0px;flex: 1 1 auto;overflow: auto;font-size: 14px;diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.tsindex f6982043a..3fce466e5 100644--- a/ui/component/or-attribute-input/src/index.ts+++ b/ui/component/or-attribute-input/src/index.ts@@ -15,23 +15,13 @@ import manager, {AssetModelUtil, subscribe, Util} from "@openremote/core";import "@openremote/or-input";import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-input";-export function getAttributeLabel(attribute: Attribute | undefined, descriptor: AttributeDescriptor | undefined, fallback?: string): string {- if (!attribute && !descriptor) {- return fallback || "";- }-- const labelMetaValue = AssetModelUtil.getMetaValue(MetaItemType.LABEL, attribute, descriptor);- const name = attribute ? attribute.name : descriptor!.attributeName;- return i18next.t([name, fallback || labelMetaValue || name]);-}-export function getAttributeValueTemplate(assetType: string | undefined,attribute: Attribute,- readonly: boolean,- disabled: boolean,+ readonly: boolean | undefined,+ disabled: boolean | undefined,valueChangedCallback: (value: any) => void,- customProvider?: (assetType: string | undefined, attribute: Attribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean, disabled: boolean) => ((value: any) => TemplateResult) | undefined,+ customProvider?: (assetType: string | undefined, attribute: Attribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean | undefined, disabled: boolean | undefined) => ((value: any) => TemplateResult) | undefined,forceInputType?: InputType,labelOverride?: string) {@@ -125,11 +115,11 @@ export function getAttributeValueTemplate(if (inputType) {// TODO: Update to use 'effective' meta so not dependent on meta items being defined on the asset itself- min = AssetModelUtil.getMetaValue(MetaItemType.RANGE_MIN, attribute, attributeDescriptor) as number;- max = AssetModelUtil.getMetaValue(MetaItemType.RANGE_MAX, attribute, attributeDescriptor) as number;- label = labelOverride ? labelOverride : getAttributeLabel(attribute, attributeDescriptor);- ro = AssetModelUtil.getMetaValue(MetaItemType.READ_ONLY, attribute, attributeDescriptor);- options = AssetModelUtil.getMetaValue(MetaItemType.ALLOWED_VALUES, attribute, attributeDescriptor);+ min = Util.getMetaValue(MetaItemType.RANGE_MIN, attribute, attributeDescriptor) as number;+ max = Util.getMetaValue(MetaItemType.RANGE_MAX, attribute, attributeDescriptor) as number;+ label = labelOverride !== undefined ? labelOverride : Util.getAttributeLabel(attribute, attributeDescriptor);+ ro = readonly === undefined ? Util.getMetaValue(MetaItemType.READ_ONLY, attribute, attributeDescriptor) : readonly;+ options = Util.getMetaValue(MetaItemType.ALLOWED_VALUES, attribute, attributeDescriptor);if (inputType === InputType.TEXT && options && Array.isArray(options) && options.length > 0) {inputType = InputType.SELECT;@@ -190,7 +180,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEpublic label?: string;@property({type: Boolean})- public disabled: boolean = false;+ public disabled?: boolean;@property({type: Boolean})public disableSubscribe: boolean = false;@@ -199,9 +189,9 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEpublic disableWrite: boolean = false;@property({type: Boolean})- public readonly: boolean = false;+ public readonly?: boolean;- public customProvider?: (assetType: string | undefined, attribute: Attribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean, disabled: boolean) => ((value: any) => TemplateResult) | undefined;+ public customProvider?: (assetType: string | undefined, attribute: Attribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean | undefined, disabled: boolean | undefined) => ((value: any) => TemplateResult) | undefined;protected _loading: boolean = false;protected _invalid: boolean = false;@@ -292,25 +282,22 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEprotected onValueChange(newValue: any) {if (this.attribute || this.attributeRef) {- if (!this.disableWrite && !this.disabled && !this.readonly) {+ let attributeRef = this.attributeRef;- let attributeRef = this.attributeRef;+ if (!this.attributeRef) {+ attributeRef = {+ entityId: this.attribute!.assetId,+ attributeName: this.attribute!.name+ };+ }- if (!this.attributeRef) {- attributeRef = {- entityId: this.attribute!.assetId,- attributeName: this.attribute!.name- };+ super._sendEvent({+ eventType: "attribute",+ attributeState: {+ attributeRef: attributeRef,+ value: newValue}-- super._sendEvent({- eventType: "attribute",- attributeState: {- attributeRef: attributeRef,- value: newValue- }- } as AttributeEvent);- }+ } as AttributeEvent);}}}diff --git a/ui/component/or-header/src/index.ts b/ui/component/or-header/src/index.tsindex d55cad709..403f7d252 100644--- a/ui/component/or-header/src/index.ts+++ b/ui/component/or-header/src/index.ts@@ -1,6 +1,7 @@import {style} from "./style";import {customElement, html, LitElement, property, query} from "lit-element";import "@openremote/or-icon";+import "./or-language";@customElement("or-header")class OrHeader extends LitElement {diff --git a/ui/component/or-header/src/or-language.ts b/ui/component/or-header/src/or-language.tsnew file mode 100644index 000000000..3bb32255a--- /dev/null+++ b/ui/component/or-header/src/or-language.ts@@ -0,0 +1,78 @@+import {customElement, html, css, LitElement, property} from "lit-element";+import "@openremote/or-icon";+import manager from "@openremote/core";++// language=CSS+const style = css`+ :host {+ position: relative;+ }++ .dropdown-menu {+ position: absolute;+ top: 100%;+ box-shadow: rgba(0, 0, 0, 0.3) 0 5px 5px -2px;+ width: 120px;+ background-color: white;+ right: 0;+ }++ span {+ display: block;+ height: 40px;+ line-height: 40px;+ }++ .background-close {+ display: none;+ position: fixed;+ width: 100vw;+ height: 100vh;+ top: 0;+ left: 0;+ z-index: 0;+ }++ .background-close.active {+ display: block;+ }+`;++@customElement("or-language")+export class OrLanguage extends LitElement {+++ @property({type: Boolean})+ isVisible?: boolean = false;++ static styles = style;++ protected render() {+ return html`+ <or-icon icon="web" @click="${this.toggleMenu}"></or-icon>+ <div class="background-close ${this.isVisible ? "active" : ""}" @click="${this.closeMenu}"></div>+ ${this.isVisible ? html`+ <div class="dropdown-menu">+ <span @click="${() => this.changeLanguage("en")}"><or-translate value="english"></or-translate></span>+ <span @click="${() => this.changeLanguage("nl")}"><or-translate value="dutch"></or-translate></span>+ <span @click="${() => this.changeLanguage("fr")}"><or-translate value="french"></or-translate></span>+ <span @click="${() => this.changeLanguage("de")}"><or-translate value="german"></or-translate></span>+ <span @click="${() => this.changeLanguage("es")}"><or-translate value="spanish"></or-translate></span>+ </div>+ ` : ``}+ `;+ }++ changeLanguage(language: string) {+ manager.language = language;+ this.isVisible = false;+ }++ closeMenu() {+ this.isVisible = false;+ }++ toggleMenu() {+ this.isVisible = !this.isVisible;+ }+}diff --git a/ui/component/or-icon/src/index.ts b/ui/component/or-icon/src/index.tsindex 6ab6f5ad4..e9868e4de 100644--- a/ui/component/or-icon/src/index.ts+++ b/ui/component/or-icon/src/index.ts@@ -1,5 +1,13 @@-import {css, customElement, html, LitElement, property, PropertyValues} from "lit-element";+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";++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);+ const icon = overrideIcon ? overrideIcon : AssetModelUtil.getAssetDescriptorIcon(descriptor, fallbackIcon);+ return html`<or-icon style="--or-icon-fill: ${color ? "#" + color : "unset"}" icon="${icon ? icon : AssetType.THING.icon}"></or-icon>`;+}export interface IconSetSvg {size: number;diff --git a/ui/component/or-icon/tsconfig.json b/ui/component/or-icon/tsconfig.jsonindex 2a3b78ac3..2d31b45ae 100644--- a/ui/component/or-icon/tsconfig.json+++ b/ui/component/or-icon/tsconfig.json@@ -7,5 +7,8 @@},"include": ["./src"+ ],+ "references": [+ { "path": "../core" }]}\ No newline at end of filediff --git a/ui/component/or-input/package.json b/ui/component/or-input/package.jsonindex a76261dfa..6ce97af5f 100644--- a/ui/component/or-input/package.json+++ b/ui/component/or-input/package.json@@ -16,6 +16,7 @@"dependencies": {"@material/button": "^3.2.0","@material/checkbox": "^3.2.0",+ "@material/fab": "^4.0.0","@material/floating-label": "^3.2.0","@material/form-field": "^3.2.0","@material/icon-button": "^3.2.0",diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.tsindex b01a0d473..24be2a9a0 100644--- a/ui/component/or-input/src/index.ts+++ b/ui/component/or-input/src/index.ts@@ -9,10 +9,12 @@ import {MDCCheckbox} from "@material/checkbox";import {MDCSwitch} from "@material/switch";import {MDCSelect, MDCSelectEvent, } from "@material/select";import {MDCFormField, MDCFormFieldInput} from "@material/form-field";+import {MDCIconButtonToggle, MDCIconButtonToggleEventDetail} from "@material/icon-button";import moment from "moment";// TODO: Add webpack/rollup to build so consumers aren't forced to use the same toolingconst buttonStyle = require("!!raw-loader!@material/button/dist/mdc.button.css");+const buttonFabStyle = require("!!raw-loader!@material/fab/dist/mdc.fab.css");const iconButtonStyle = require("!!raw-loader!@material/icon-button/dist/mdc.icon-button.css");const textfieldStyle = require("!!raw-loader!@material/textfield/dist/mdc.textfield.css");const rippleStyle = require("!!raw-loader!@material/ripple/dist/mdc.ripple.css");@@ -55,6 +57,7 @@ declare global {export enum InputType {BUTTON = "button",+ BUTTON_TOGGLE = "button-toggle",BUTTON_MOMENTARY = "button-momentary",CHECKBOX = "checkbox",COLOUR = "color",@@ -84,6 +87,7 @@ export class OrInput extends LitElement {return [css`${unsafeCSS(iconButtonStyle)}`,css`${unsafeCSS(buttonStyle)}`,+ css`${unsafeCSS(buttonFabStyle)}`,css`${unsafeCSS(textfieldStyle)}`,css`${unsafeCSS(rippleStyle)}`,css`${unsafeCSS(lineRippleStyle)}`,@@ -158,6 +162,9 @@ export class OrInput extends LitElement {@property({type: String})public icon?: string;+ @property({type: String})+ public iconOn?: string;+@property({type: Boolean})public dense: boolean = false;@@ -169,6 +176,9 @@ export class OrInput extends LitElement {@property({type: Boolean})public raised: boolean = false;+ @property({type: Boolean})+ public action: boolean = false;+@property({type: Boolean})public unElevated: boolean = false;@@ -302,44 +312,41 @@ export class OrInput extends LitElement {${showValidationMessage ? this.validationMessage : this.helperText}</p>` : ``}`;+ case InputType.BUTTON_TOGGLE:+ return html`+ <button id="component" class="mdc-icon-button ${this.value ? "mdc-icon-button--on" : ""}"+ ?readonly="${this.readonly}"+ ?disabled="${this.disabled}"+ @MDCIconButtonToggle:change="${(evt: MDCIconButtonToggleEventDetail) => this.onValueChange(evt.isOn)}">+ ${this.icon ? html`<or-icon class="mdc-icon-button__icon" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}+ ${this.iconOn ? html`<or-icon class="mdc-icon-button__icon mdc-icon-button__icon--on" aria-hidden="true" icon="${this.iconOn}"></or-icon>` : ``}+ </button>+ `;case InputType.BUTTON:case InputType.BUTTON_MOMENTARY: {- const iconButton = this.isIconButton();+ const isMomentary = this.type === InputType.BUTTON_MOMENTARY;+ const isIconButton = !this.action && !this.label;const classes = {- "mdc-button--raised": this.raised,- "mdc-button--unelevated": this.unElevated,- "mdc-button--outlined": !iconButton && this.outlined,- "mdc-button--dense": !iconButton && this.dense,- "or-input--rounded": this.rounded,- "mdc-button": !iconButton,- "mdc-icon-button": iconButton- };- const iconClasses = {- "mdc-icon-button__icon": iconButton,- "mdc-button__icon": !iconButton,+ "mdc-icon-button": isIconButton,+ "mdc-fab": !isIconButton && this.action,+ "mdc-fab--extended": !isIconButton && this.action && !!this.label,+ "mdc-fab--mini": !isIconButton && this.action && this.dense,+ "mdc-button": !isIconButton && !this.action,+ "mdc-button--raised": !isIconButton && !this.action && this.raised,+ "mdc-button--unelevated": !isIconButton && !this.action && this.unElevated,+ "mdc-button--outlined": !isIconButton && !this.action && this.outlined,+ "mdc-button--dense": !isIconButton && !this.action && this.dense,+ "or-input--rounded": !isIconButton && !this.action && this.rounded};- if (this.type === InputType.BUTTON_MOMENTARY) {- return html`- <button id="component" class="${classMap(classes)}"- ?required="${this.required}"- ?readonly="${this.readonly}"- ?disabled="${this.disabled}"- @onmousedown="${() => this.onValueChange(true)}" @onmouseup="${() => this.onValueChange(false)}">- ${this.icon ? html`<or-icon class="${classMap(iconClasses)}" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}- ${this.label ? html`<span class="mdc-button__label">${this.label}</span>` : ``}- ${this.iconTrailing ? html`<or-icon class="${classMap(iconClasses)}" aria-hidden="true" icon="${this.iconTrailing}"></or-icon>` : ``}- </button>- `;- }return html`<button id="component" class="${classMap(classes)}"- ?required="${this.required}"?readonly="${this.readonly}"?disabled="${this.disabled}"- @onmouseup="${() => this.onValueChange(true)}">- ${this.icon ? html`<or-icon class="${classMap(iconClasses)}" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}- ${this.label ? html`<span class="mdc-button__label">${this.label}</span>` : ``}- ${this.iconTrailing ? html`<or-icon class="${classMap(iconClasses)}" aria-hidden="true" icon="${this.iconTrailing}"></or-icon>` : ``}+ @onmousedown="${() => {if (isMomentary) this.onValueChange(true)}}" @onmouseup="${() => isMomentary ? this.onValueChange(false) : this.onValueChange(true)}">+ ${!isIconButton ? html`<div class="mdc-button__ripple"></div>` : ``}+ ${this.icon ? html`<or-icon class="${isIconButton ? "" : this.action ? "mdc-fab__icon" : "mdc-button__icon"}" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}+ ${this.label ? html`<span class="${this.action ? "mdc-fab__label" : "mdc-button__label"}">${this.label}</span>` : ``}+ ${!isIconButton && this.iconTrailing ? html`<or-icon class="${this.action ? "mdc-fab__icon" : "mdc-button__icon"}" aria-hidden="true" icon="${this.iconTrailing}"></or-icon>` : ``}</button>`;}@@ -463,10 +470,6 @@ export class OrInput extends LitElement {return html`<span>INPUT TYPE NOT IMPLEMENTED</span>`;}- protected isIconButton() {- return !!(!this.value && this.rounded && this.icon);- }-protected updated(_changedProperties: PropertyValues): void {super.updated(_changedProperties);@@ -496,12 +499,17 @@ export class OrInput extends LitElement {case InputType.RADIO:break;case InputType.BUTTON:+ case InputType.BUTTON_MOMENTARY:+ const isIconButton = !this.action && !this.label;const ripple = new MDCRipple(component);- if (this.isIconButton()) {+ if (isIconButton) {ripple.unbounded = true;}this._mdcComponent = ripple;break;+ case InputType.BUTTON_TOGGLE:+ this._mdcComponent = new MDCIconButtonToggle(component);+ break;case InputType.CHECKBOX:this._mdcComponent = new MDCCheckbox(component);const field = this.shadowRoot!.getElementById("field");diff --git a/ui/component/or-input/src/style.ts b/ui/component/or-input/src/style.tsindex 5a6311201..7cfb73e9b 100644--- a/ui/component/or-input/src/style.ts+++ b/ui/component/or-input/src/style.ts@@ -56,6 +56,10 @@ export const orInputStyle = css`--or-icon-fill: var(--internal-or-input-color);}+ .mdc-icon-button {+ --or-icon-fill: var(--mdc-theme-primary);+ }+.mdc-icon-button {padding: 0;}diff --git a/ui/component/or-mwc-components/README.md b/ui/component/or-mwc-components/README.mdnew file mode 100644index 000000000..70db9a9a0--- /dev/null+++ b/ui/component/or-mwc-components/README.md@@ -0,0 +1,31 @@+# @openremote/or-input \<or-input\>+[![NPM Version][npm-image]][npm-url]+[![Linux Build][travis-image]][travis-url]+[![Test Coverage][coveralls-image]][coveralls-url]++Web Component for displaying an input control.++## Install+```bash+npm i @openremote/or-input+yarn add @openremote/or-input+```++## Usage+For a full list of properties, methods and options refer to the TypeDoc generated [documentation]().+++## Supported Browsers+The last 2 versions of all modern browsers are supported, including Chrome, Safari, Opera, Firefox, Edge. In addition,+Internet Explorer 11 is also supported.+++## License+[GNU AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html)++[npm-image]: https://img.shields.io/npm/v/live-xxx.svg+[npm-url]: https://npmjs.org/package/@openremote/or-input+[travis-image]: https://img.shields.io/travis/live-js/live-xxx/master.svg+[travis-url]: https://travis-ci.org/live-js/live-xxx+[coveralls-image]: https://img.shields.io/coveralls/live-js/live-xxx/master.svg+[coveralls-url]: https://coveralls.io/r/live-js/live-xxx?branch=masterdiff --git a/ui/component/or-mwc-components/build.gradle b/ui/component/or-mwc-components/build.gradlenew file mode 100644index 000000000..98cdcb8e2--- /dev/null+++ b/ui/component/or-mwc-components/build.gradle@@ -0,0 +1,15 @@+buildDir = "dist"++task clean() {+ doLast {+ delete "dist"+ }+}++task prepareUi() {+ dependsOn clean, npmPrepare+}++task publishUi() {+ dependsOn clean, npmPublish+}\ No newline at end of filediff --git a/ui/component/or-mwc-components/package.json b/ui/component/or-mwc-components/package.jsonnew file mode 100644index 000000000..e8fba6a50--- /dev/null+++ b/ui/component/or-mwc-components/package.json@@ -0,0 +1,22 @@+{+ "name": "@openremote/or-mwc-components",+ "version": "1.1.0",+ "description": "Material Design Components packaged as web components (The official components are hardcoded to use Material Design font which has limited icons)",+ "scripts": {+ "build": "npx tsc -b",+ "test": "echo \"No tests\" && exit 0",+ "prepublishOnly": "npx tsc -b && npx webpack"+ },+ "author": "OpenRemote",+ "license": "AGPL-3.0-or-later",+ "dependencies": {+ "@material/menu": "^3.2.0",+ "lit-element": "^2.2.1"+ },+ "devDependencies": {+ "tslint": ">=5.11.0",+ "typescript": ">=3.4.5",+ "webpack": "^4.41.2",+ "webpack-cli": "^3.3.9"+ }+}diff --git a/ui/component/or-mwc-components/src/or-mwc-menu.ts b/ui/component/or-mwc-components/src/or-mwc-menu.tsnew file mode 100644index 000000000..2bc00b74b--- /dev/null+++ b/ui/component/or-mwc-components/src/or-mwc-menu.ts@@ -0,0 +1,148 @@+import {css, customElement, html, LitElement, property, query, TemplateResult, unsafeCSS, PropertyValues} from "lit-element";++import {MDCMenu, MDCMenuItemComponentEventDetail} from "@material/menu";++const listStyle = require("!!raw-loader!@material/list/dist/mdc.list.css");+const menuSurfaceStyle = require("!!raw-loader!@material/menu-surface/dist/mdc.menu-surface.css");+const menuStyle = require("!!raw-loader!@material/menu/dist/mdc.menu.css");++export interface Menu {+ items: (MenuItem | MenuGroup | null)[];+}++export interface MenuGroup {+ icon?: string;+ items: (MenuItem | null)[];+}++export interface MenuItem {+ content: TemplateResult,+ value: any;+}++export class OrMwcMenuChangedEvent extends CustomEvent<string> {++ public static readonly NAME = "or-mwc-menu-changed";++ constructor(value: string) {+ super(OrMwcMenuChangedEvent.NAME, {+ detail: value,+ bubbles: true,+ composed: true+ });+ }+}++declare global {+ export interface HTMLElementEventMap {+ [OrMwcMenuChangedEvent.NAME]: OrMwcMenuChangedEvent;+ }+}+++@customElement("or-mwc-menu")+export class OrMwcMenu extends LitElement {++ static get styles() {+ return [+ css`${unsafeCSS(listStyle)}`,+ css`${unsafeCSS(menuStyle)}`,+ css`${unsafeCSS(menuSurfaceStyle)}`+ ];+ }++ @property({type: Object})+ public menu?: Menu;++ @property({type: String})+ public value?: string;++ @property({type: Boolean, attribute: true})+ public visible?: boolean;++ public anchorElem?: HTMLElement;++ @query("#wrapper")+ protected _wrapperElem!: HTMLElement;++ @query("#menu")+ protected _mdcElem!: HTMLElement;++ protected _mdcComponent?: MDCMenu;++ public open() {+ this._mdcComponent!.open = true;+ }++ disconnectedCallback(): void {+ super.disconnectedCallback();+ if (this._mdcComponent) {+ this._mdcComponent.destroy();+ this._mdcComponent = undefined;+ }+ }++ protected render() {++ if (!this.menu || !this.menu.items) {+ return html``;+ }++ return html`+ <div id="wrapper" class="mdc-menu-surface--anchor">+ <div class="mdc-menu mdc-menu-surface" id="menu">+ <ul class="mdc-list" role="menu" aria-hidden="true" aria-orientation="vertical" tabindex="-1">+ ${this.getItemsTemplate(this.menu.items)}+ </ul>+ </div>+ </div>+ `;+ }++ protected getItemsTemplate(items: (MenuItem | MenuGroup | null)[], icon?: string): TemplateResult {+ return html`+ ${items.map((item) => {+ if (item === null) {+ return html`<li class="mdc-list-divider" role="separator"></li>`;+ }+ if ((item as MenuGroup).items) {+ return html`+ <li>+ <ul class="mdc-menu__selection-group">+ ${this.getItemsTemplate((item as Menu).items, (item as MenuGroup).icon)}+ </ul>+ </li>+ `;+ }+ if ((item as MenuItem).content) {+ return html`+ <li @click="${() => this._onSelect((item as MenuItem).value)}" class="mdc-list-item ${(item as MenuItem).value === this.value}" role="menuitem">+ ${icon ? html`<or-icon icon="logout" class="mdc-list-item__graphic mdc-menu__selection-group-icon"></or-icon>` : ``}+ ${(item as MenuItem).content}+ </li>+ `;+ }+ })}+ `;+ }++ protected firstUpdated(_changedProperties: PropertyValues): void {+ super.firstUpdated(_changedProperties);+ this._mdcComponent = new MDCMenu(this._mdcElem);+ this._mdcComponent!.quickOpen = true;+ const elem = this.anchorElem || this._wrapperElem;+ // This doesn't work+ //this._mdcComponent.setAnchorElement(elem);+ }++ protected updated(_changedProperties: PropertyValues): void {+ if (_changedProperties.has("visible")) {+ this._mdcComponent!.open = this.visible || false;+ }+ }++ private _onSelect(value: string) {+ this.value = value;+ this.dispatchEvent(new OrMwcMenuChangedEvent(value));+ }+}diff --git a/ui/component/or-mwc-components/src/style.ts b/ui/component/or-mwc-components/src/style.tsnew file mode 100644index 000000000..5a6311201--- /dev/null+++ b/ui/component/or-mwc-components/src/style.ts@@ -0,0 +1,62 @@+import {css, unsafeCSS} from "lit-element";+import {DefaultColor1, DefaultColor4} from "@openremote/core";++// TODO this is temp work, should be replaced with material design components / styling+// language=CSS+export const orInputStyle = css`++ :host {+ display: inline-block;+ --internal-or-input-color: var(--or-input-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));+ --internal-or-input-text-color: var(--or-input-text-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));++ --mdc-theme-primary: var(--internal-or-input-color);+ --mdc-theme-on-primary: var(--internal-or-input-text-color);+ --mdc-theme-secondary: var(--internal-or-input-color);+ }++ .or-input--rounded {+ border-radius: 50% !important;+ }++ /* MDC TEXT FIELD AND SELECT DON'T USE THEME VARS */+ .mdc-text-field--focused:not(.mdc-text-field--disabled) .mdc-floating-label {+ color: var(--mdc-theme-primary);+ }+ .mdc-text-field--focused .mdc-text-field__input:required ~ .mdc-floating-label::after,+ .mdc-text-field--focused .mdc-text-field__input:required ~ .mdc-notched-outline .mdc-floating-label::after {+ color: var(--mdc-theme-primary);+ }++ .mdc-select:not(.mdc-select--disabled).mdc-select--focused .mdc-floating-label {+ color: var(--mdc-theme-primary);+ }++ .mdc-text-field, .mdc-text-field-helper-line {+ width: inherit;+ }++ .mdc-text-field--dense:not(.mdc-text-field--no-label):not(.mdc-text-field--outlined) {+ height: 52px;+ }++ .mdc-text-field--dense.mdc-text-field--no-label {+ height: 40px;+ }++ .mdc-switch {+ margin: 18px;+ }++ .mdc-select__dropdown-icon {+ background: none;+ }++ .mdc-select--focused .mdc-select__dropdown-icon {+ --or-icon-fill: var(--internal-or-input-color);+ }++ .mdc-icon-button {+ padding: 0;+ }+`;diff --git a/ui/component/or-mwc-components/tsconfig.json b/ui/component/or-mwc-components/tsconfig.jsonnew file mode 100644index 000000000..acb1a2837--- /dev/null+++ b/ui/component/or-mwc-components/tsconfig.json@@ -0,0 +1,15 @@+{+ "extends": "../../tsconfig",+ "compilerOptions": {+ "outDir": "./dist",+ "tsBuildInfoFile": "./dist/.tsbuildinfo",+ "rootDir": "src"+ },+ "include": [+ "./src"+ ],+ "references": [+ { "path": "../core" },+ { "path": "../or-select" }+ ]+}\ No newline at end of filediff --git a/ui/component/or-mwc-components/webpack.config.js b/ui/component/or-mwc-components/webpack.config.jsnew file mode 100644index 000000000..9fe13702d--- /dev/null+++ b/ui/component/or-mwc-components/webpack.config.js@@ -0,0 +1,7 @@+const util = require("../webpack.util");++bundles = {+ "index.bundle": undefined+};++module.exports = util.generateExports(__dirname);\ No newline at end of filediff --git a/ui/component/or-panel/package.json b/ui/component/or-panel/package.jsonindex 655455d2c..6732e997e 100644--- a/ui/component/or-panel/package.json+++ b/ui/component/or-panel/package.json@@ -1,7 +1,7 @@{"name": "@openremote/or-panel","version": "1.1.0",- "description": "OpenRemote scrollable panel with custom scrollbars based on simplebar",+ "description": "OpenRemote simple panel with heading","main": "dist/umd/index.bundle.js","module": "dist/index.js","types": "dist/index.d.ts",@@ -12,8 +12,9 @@"author": "OpenRemote","license": "AGPL-3.0-or-later","dependencies": {+ "@material/elevation": "^4.0.0","lit-element": "^2.2.1",- "simplebar": "^4.2.3"+ "simplebar": "^5.0.7"},"devDependencies": {"@types/simplebar": "^2.4.2",diff --git a/ui/component/or-panel/src/index.ts b/ui/component/or-panel/src/index.tsindex 034e38d00..0b04e66a0 100644--- a/ui/component/or-panel/src/index.ts+++ b/ui/component/or-panel/src/index.ts@@ -1,21 +1,38 @@import {css, customElement, html, LitElement, PropertyValues, query, unsafeCSS, property} from "lit-element";import SimpleBar from "simplebar";+import {DefaultColor2} from "@openremote/core";// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling-const scrollStyle = require("!!raw-loader!simplebar/dist/simplebar.css");+const simpleBarStyle = require("!!raw-loader!simplebar/dist/simplebar.css");+const elevationStyle = require("!!raw-loader!@material/elevation/dist/mdc.elevation.css");// language=CSSconst style = css`+:host {+ --internal-or-panel-background-color: var(--or-panel-background-color, var(--or-app-color2, ${unsafeCSS(DefaultColor2)}));+ --internal-or-panel-padding: var(--or-panel-padding, 10px);+ --internal-or-panel-heading-margin: var(--or-panel-heading-margin, 0 0 5px 0);+display: block;}:host([hidden]) {display: none;}++ #wrapper {+ height: 100%;+ flex: 1;+ }#panel {- height: 100%;+ padding: var(--internal-or-panel-padding);+ background-color: var(--internal-or-panel-background-color);+ }++ strong {+ margin: var(--internal-or-panel-heading-margin);}`;@@ -24,7 +41,8 @@ export class OrPanel extends LitElement {static get styles() {return [- css `${unsafeCSS(scrollStyle)}`,+ css `${unsafeCSS(elevationStyle)}`,+ css `${unsafeCSS(simpleBarStyle)}`,style];}@@ -35,24 +53,39 @@ export class OrPanel extends LitElement {@property({type: Boolean})forceVisible?: boolean;+ @property({type: Number})+ zLevel?: number;++ @property({type: String})+ public heading?: string;+@query("#panel")protected _panel!: HTMLDivElement;protected firstUpdated(_changedProperties: PropertyValues): void {super.firstUpdated(_changedProperties);- if (this._panel) {- new SimpleBar(this._panel, {- autoHide: this.autoHide,- // @ts-ignore- forceVisible: this.forceVisible- });- }+ // if (this._panel) {+ // new SimpleBar(this._panel, {+ // autoHide: this.autoHide,+ // // @ts-ignore+ // forceVisible: this.forceVisible+ // });+ // }}render() {++ let zLevel = this.zLevel || 1;+ zLevel = Math.min(24, Math.max(0, zLevel));+return html`- <div id="panel"><slot></slot></div>+ <div id="wrapper">+ <div id="panel" class="mdc-elevation--z${zLevel}">+ ${this.heading ? html`<strong>${this.heading}</strong>` : ``}+ <slot></slot>+ </div>+ </div>`;}}\ No newline at end of filediff --git a/ui/component/or-rules-editor/package.json b/ui/component/or-rules-editor/package.jsonindex 4d0f8a43e..94a2ee9c6 100644--- a/ui/component/or-rules-editor/package.json+++ b/ui/component/or-rules-editor/package.json@@ -16,13 +16,16 @@"@openremote/core": "^1.1.0","@openremote/or-input": "^1.1.0","@openremote/or-select": "^1.1.0",- "@openremote/or-attribute-input": "^1.1.0","@openremote/or-translate": "^1.1.0",+ "@openremote/or-icon": "^1.1.0",+ "@openremote/or-panel": "^1.1.0","@openremote/or-attribute-input": "^1.1.0",+ "@openremote/or-mwc-components": "^1.1.0","@openremote/rest": "^1.1.0","lit-element": "^2.2.1"},"devDependencies": {+ "@openremote/or-asset-viewer": "^1.1.0","@openremote/model": "^1.1.0","tslint": ">=5.11.0","typescript": ">=3.4.5",diff --git a/ui/component/or-rules-editor/src/index.ts b/ui/component/or-rules-editor/src/index.tsindex 24db030b0..38ea625b5 100644--- a/ui/component/or-rules-editor/src/index.ts+++ b/ui/component/or-rules-editor/src/index.ts@@ -1,4 +1,5 @@-import {customElement, html, LitElement, property, TemplateResult} from "lit-element";+import {customElement, html, css, unsafeCSS, LitElement, property, TemplateResult, query} from "lit-element";+import {DefaultColor1, DefaultColor2, DefaultColor5, DefaultColor3, DefaultBoxShadow, DefaultColor4, DefaultColor6, DefaultDisabledOpacity} from "@openremote/core";import i18next from "i18next";import "@openremote/or-select";import "@openremote/or-icon";@@ -28,10 +29,12 @@ import "@openremote/or-translate";import {translate} from "@openremote/or-translate";import "./or-rule-list";import "./or-rule-when";-import "./or-rule-actions";+import "./or-rule-then-otherwise";import "./or-rule-header";-import "./or-rule-section";-import {rulesEditorStyle} from "./style";+import "@openremote/or-panel";+import {OrRulesList} from "./or-rule-list";+import {Menu, OrMwcMenu, OrMwcMenuChangedEvent} from "@openremote/or-mwc-components/dist/or-mwc-menu";+import {InputType, OrInput} from "@openremote/or-input";export const enum ConditionType {ASSET_QUERY = "assetQuery",@@ -42,15 +45,7 @@ export const enum ConditionType {export const enum ActionType {WAIT = "wait",NOTIFICATION = "notification",- WRITE_ATTRIBUTE = "write-attribute",- UPDATE_ATTRIBUTE = "update-attribute"-}--export const enum ActionTargetType {- TRIGGER_ASSETS = "triggerAssets",- TAGGED_ASSETS = "taggedAssets",- USERS = "users",- OTHER_ASSETS = "otherAssets"+ ATTRIBUTE = "attribute"}export enum AssetQueryOperator {@@ -98,7 +93,6 @@ export interface RulesConfig {headerReadonly?: boolean;allowedConditionTypes?: ConditionType[];allowedActionTypes?: ActionType[];- allowedActionTargets?: ActionTargetType[];allowedAssetQueryOperators?: Map<AssetTypeAttributeName | AttributeDescriptor | AttributeValueDescriptor | ValueType, AssetQueryOperator[]>;hideActionTypeOptions?: boolean;hideActionTargetOptions?: boolean;@@ -108,9 +102,8 @@ export interface RulesConfig {hideWhenAddCondition?: boolean;hideWhenAddAttribute?: boolean;hideWhenAddGroup?: boolean;- hideWhenGroupOutline?: boolean;};- inputProvider?: (assetType: string | undefined, attribute: Attribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean, disabled: boolean) => ((value: any) => TemplateResult) | undefined;+ inputProvider?: (assetType: string | undefined, attribute: Attribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean | undefined, disabled: boolean | undefined) => ((value: any) => TemplateResult) | undefined;descriptors?: {all?: RulesDescriptorSection;when?: RulesDescriptorSection;@@ -123,6 +116,7 @@ export interface RulesConfig {whenCondition?: RuleCondition;whenAssetQuery?: AssetQuery;then?: RuleActionUnion;+ otherwise?: RuleActionUnion;};}@@ -156,6 +150,16 @@ export interface RulesConfigAttributeValue {valueType?: ValueType;}+export interface RulesetNode {+ ruleset: TenantRuleset;+ selected: boolean;+}++export interface RequestEventDetail<T> {+ allow: boolean,+ detail: T+}+function getAssetDescriptorFromSection(assetTpe: string, config: RulesConfig | undefined, useActionConfig: boolean) {if (!config || !config.descriptors) {return;@@ -184,6 +188,20 @@ export function getAssetTypeFromQuery(query?: AssetQuery) {return query && query.types && query.types.length > 0 && query.types[0] ? query.types[0].value : undefined;}+export function getAssetIdsFromQuery(query?: AssetQuery) {+ return query && query.ids ? [...query.ids] : undefined;+}++export function getAttributeNames(descriptor?: AssetDescriptor) {+ let attributes: string[] = [];++ if (descriptor && descriptor.attributeDescriptors) {+ attributes = descriptor.attributeDescriptors.map((ad) => ad.attributeName!);+ }++ return attributes;+}+export function getAssetDescriptors(config: RulesConfig | undefined, useActionConfig: boolean) {const assetDescriptors: AssetDescriptor[] = AssetModelUtil.getAssetDescriptors();let allowedAssetTypes: string[] = [];@@ -298,6 +316,24 @@ export function getAssetDescriptors(config: RulesConfig | undefined, useActionCo});}+export function getButtonWithMenuTemplate(menu: Menu, icon: string, value: string | undefined, valueChangedCallback: (v: string) => void): TemplateResult {++ const openMenu = (evt: Event) => {+ if (!menu) {+ return;+ }++ ((evt.currentTarget as OrInput).parentElement!.lastElementChild as OrMwcMenu).open();+ };++ return html`+ <div style="display: table-cell; vertical-align: middle;">+ <or-input type="${InputType.BUTTON}" .icon="${icon}" @click="${openMenu}"></or-input>+ ${menu ? html`<or-mwc-menu @or-mwc-menu-changed="${(evt: OrMwcMenuChangedEvent) => valueChangedCallback(evt.detail)}" .value="${value}" .menu="${menu}" id="menu"></or-mwc-menu>` : ``}+ </div>+ `;+}+function addOrReplaceMetaItemDescriptor(metaItemDescriptors: MetaItemDescriptor[], metaItemDescriptor: MetaItemDescriptor) {const index = metaItemDescriptors.findIndex((mid) => mid.urn === metaItemDescriptor.urn);if (index >= 0) {@@ -307,24 +343,220 @@ function addOrReplaceMetaItemDescriptor(metaItemDescriptors: MetaItemDescriptor[metaItemDescriptors.push(metaItemDescriptor);}-export class OrRuleChangedEvent extends CustomEvent<void> {+export class OrRulesEditorRuleChangedEvent extends CustomEvent<void> {++ public static readonly NAME = "or-rules-editor-rule-changed";++ constructor() {+ super(OrRulesEditorRuleChangedEvent.NAME, {+ bubbles: true,+ composed: true+ });+ }+}++export class OrRulesEditorRuleInvalidEvent extends CustomEvent<void> {++ public static readonly NAME = "or-rules-editor-rule-invalid";++ constructor() {+ super(OrRulesEditorRuleInvalidEvent.NAME, {+ bubbles: true,+ composed: true+ });+ }+}++export class OrRulesEditorRuleUnsupportedEvent extends CustomEvent<void> {- public static readonly NAME = "or-rule-changed";+ public static readonly NAME = "or-rules-editor-rule-unsupported";constructor() {- super(OrRuleChangedEvent.NAME, {+ super(OrRulesEditorRuleUnsupportedEvent.NAME, {bubbles: true,composed: true});}}+export class OrRulesEditorRequestSelectEvent extends CustomEvent<RequestEventDetail<TenantRuleset[]>> {++ public static readonly NAME = "or-rules-editor-request-select";++ constructor(request: TenantRuleset[]) {+ super(OrRulesEditorRequestSelectEvent.NAME, {+ bubbles: true,+ composed: true,+ detail: {+ allow: true,+ detail: request+ }+ });+ }+}++export class OrRulesEditorRequestAddEvent extends CustomEvent<void> {++ public static readonly NAME = "or-rules-editor-request-add";++ constructor() {+ super(OrRulesEditorRequestAddEvent.NAME, {+ bubbles: true,+ composed: true+ });+ }+}++export class OrRulesEditorRequestDeleteEvent extends CustomEvent<TenantRuleset[]> {++ public static readonly NAME = "or-rules-editor-request-delete";++ constructor(request: TenantRuleset[]) {+ super(OrRulesEditorRequestDeleteEvent.NAME, {+ bubbles: true,+ composed: true,+ detail: request+ });+ }+}++export class OrRulesEditorRequestCopyEvent extends CustomEvent<TenantRuleset> {++ public static readonly NAME = "or-rules-editor-request-copy";++ constructor(request: TenantRuleset) {+ super(OrRulesEditorRequestCopyEvent.NAME, {+ bubbles: true,+ composed: true,+ detail: request+ });+ }+}++export class OrRulesEditorRequestSaveEvent extends CustomEvent<TenantRuleset> {++ public static readonly NAME = "or-rules-editor-request-save";++ constructor(request: TenantRuleset) {+ super(OrRulesEditorRequestSaveEvent.NAME, {+ bubbles: true,+ composed: true,+ detail: request+ });+ }+}++export class OrRulesEditorSelectionChangedEvent extends CustomEvent<TenantRuleset[]> {++ public static readonly NAME = "or-rules-editor-selection-changed";++ constructor(nodes: TenantRuleset[]) {+ super(OrRulesEditorSelectionChangedEvent.NAME, {+ bubbles: true,+ composed: true,+ detail: nodes+ });+ }+}+declare global {export interface HTMLElementEventMap {- [OrRuleChangedEvent.NAME]: OrRuleChangedEvent;+ [OrRulesEditorRuleInvalidEvent.NAME]: OrRulesEditorRuleInvalidEvent;+ [OrRulesEditorRuleUnsupportedEvent.NAME]: OrRulesEditorRuleUnsupportedEvent;+ [OrRulesEditorRequestSelectEvent.NAME]: OrRulesEditorRequestSelectEvent;+ [OrRulesEditorRequestAddEvent.NAME]: OrRulesEditorRequestAddEvent;+ [OrRulesEditorRequestDeleteEvent.NAME]: OrRulesEditorRequestDeleteEvent;+ [OrRulesEditorRequestCopyEvent.NAME]: OrRulesEditorRequestCopyEvent;+ [OrRulesEditorRequestSaveEvent.NAME]: OrRulesEditorRequestSaveEvent;+ [OrRulesEditorRuleChangedEvent.NAME]: OrRulesEditorRuleChangedEvent;+ [OrRulesEditorSelectionChangedEvent.NAME]: OrRulesEditorSelectionChangedEvent;}}+// language=CSS+export const style = css`++ :host {+ display: flex;+ height: 100%;+ width: 100%;++ --internal-or-rules-editor-background-color: var(--or-rules-editor-background-color, var(--or-app-color2, ${unsafeCSS(DefaultColor2)}));+ --internal-or-rules-editor-text-color: var(--or-rules-editor-text-color, inherit);+ --internal-or-rules-editor-button-color: var(--or-rules-editor-button-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));+ --internal-or-rules-editor-invalid-color: var(--or-rules-editor-invalid-color, var(--or-app-color6, ${unsafeCSS(DefaultColor6)}));+ --internal-or-rules-editor-panel-color: var(--or-rules-editor-panel-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));+ --internal-or-rules-editor-line-color: var(--or-rules-editor-line-color, var(--or-app-color5, ${unsafeCSS(DefaultColor5)}));++ --internal-or-rules-editor-list-selected-color: var(--or-rules-editor-list-selected-color, var(--or-app-color2, ${unsafeCSS(DefaultColor2)}));+ --internal-or-rules-editor-list-text-color: var(--or-rules-editor-list-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));+ --internal-or-rules-editor-list-text-size: var(--or-rules-editor-list-text-size, 15px);++ --internal-or-rules-editor-list-button-size: var(--or-rules-editor-list-button-size, 24px);++ --internal-or-rules-editor-header-background-color: var(--or-rules-editor-header-background-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));+ --internal-or-rules-editor-header-height: var(--or-rules-editor-header-height, 80px);++ --or-panel-background-color: var(--internal-or-rules-editor-panel-color);+ }++ .shadow {+ -webkit-box-shadow: ${unsafeCSS(DefaultBoxShadow)};+ -moz-box-shadow: ${unsafeCSS(DefaultBoxShadow)};+ box-shadow: ${unsafeCSS(DefaultBoxShadow)};+ }++ #rule-list-container {+ min-width: 300px;+ width: 300px;+ z-index: 2;+ display: flex;+ flex-direction: column;+ background-color: var(--internal-or-rules-editor-panel-color);+ color: var(--internal-or-rules-editor-list-text-color);++ }++ .rule-container {+ display: flex;+ flex-direction: column;+ flex-grow: 1;+ }++ or-rule-header {+ min-height: var(--internal-or-rules-editor-header-height);+ height: var(--internal-or-rules-editor-header-height);+ }++ .rule-editor-panel {+ display: flex;+ flex-grow: 1;+ background-color: var(--internal-or-rules-editor-background-color);+ }++ .section-container {+ flex: 1 0 0px;+ }++ .msg {+ display: flex;+ justify-content: center;+ align-items: center;+ flex-direction: column;+ text-align: center;+ margin: auto;+ }++ @media only screen+ and (min-device-width : 768px)+ and (max-device-width : 1024px) {+ side-menu {+ min-width: 150px;+ width: 150px;+ }+ }+`;+@customElement("or-rules-editor")class OrRulesEditor extends translate(i18next)(LitElement) {@@ -332,20 +564,23 @@ class OrRulesEditor extends translate(i18next)(LitElement) {static get styles() {return [- rulesEditorStyle+ style];}public config?: RulesConfig;- @property({type: Number})- private value: number = 0;+ @property({type: String})+ public realm?: string;- @property({type: Array, attribute: false})- private _rulesets?: TenantRuleset[];+ @property({type: Array})+ public selectedIds?: number[];@property({type: Boolean, attribute: false})- private isValidRule?: boolean;+ private _isValidRule?: boolean;++ @query("#rules-list")+ private _rulesList!: OrRulesList;private _activeRuleset?: TenantRuleset;private _activeRules?: JsonRule[];@@ -357,7 +592,7 @@ class OrRulesEditor extends translate(i18next)(LitElement) {private set activeRuleset(ruleset: TenantRuleset | undefined) {this._activeRuleset = ruleset;this._activeRules = undefined;- this._activeModified = false;+ this._activeModified = !!(ruleset && !ruleset.id);if (ruleset && ruleset.rules) {const rules = JSON.parse(ruleset.rules) as JsonRulesetDefinition;@@ -377,33 +612,28 @@ class OrRulesEditor extends translate(i18next)(LitElement) {constructor() {super();- this.readRules();- this.addEventListener(OrRuleChangedEvent.NAME, this.onRuleChanged);- this.addEventListener("rules:set-active-rule", this.setActiveRuleset);- this.addEventListener("rules:create-rule", this.createRuleset);- this.addEventListener("rules:save-ruleset", this.saveRuleset);- this.addEventListener("rules:delete-rule", this.deleteRuleset);+ this.addEventListener(OrRulesEditorRuleChangedEvent.NAME, this._onRuleChanged);+ this.addEventListener(OrRulesEditorRequestSelectEvent.NAME, this._onRequestSelect);+ this.addEventListener(OrRulesEditorRequestAddEvent.NAME, this._onRequestAdd);+ this.addEventListener(OrRulesEditorRequestDeleteEvent.NAME, this._onRequestDelete);+ this.addEventListener(OrRulesEditorRequestCopyEvent.NAME, this._onRequestCopy);+ this.addEventListener(OrRulesEditorRequestSaveEvent.NAME, this._onRequestSave);+ this.addEventListener(OrRulesEditorSelectionChangedEvent.NAME, this._onRuleSelectionChanged);}protected ruleEditorPanelTemplate(rule: JsonRule) {- const thenTemplate = this.config && this.config.templates && this.config.templates.then ? this.config.templates.then : undefined;const targetTypeMap = this.getTargetTypeMap();const whenDescriptors = this.getAssetDescriptors(false);const actionDescriptors = this.getAssetDescriptors(true);- const thenAllowAdd = !this.config || !this.config.controls || this.config.controls.hideThenAddAction !== true;return html`- <div class="section-container">- <or-rule-section heading="${i18next.t("when")}...">- <or-rule-when .rule="${rule}" .config="${this.config}" .assetDescriptors="${whenDescriptors}" ?readonly="${this.isReadonly("when")}"></or-rule-when>- </or-rule-section>+ <div class="section-container">+ <or-rule-when .rule="${rule}" .config="${this.config}" .assetDescriptors="${whenDescriptors}" ?readonly="${this.isReadonly("when")}"></or-rule-when></div>- <div class="section-container">- <or-rule-section heading="${i18next.t("then")}...">- <or-rule-actions .rule="${rule}" .config="${this.config}" .newTemplate="${thenTemplate}" .allowAdd="${thenAllowAdd}" .targetTypeMap="${targetTypeMap}" .assetDescriptors="${actionDescriptors}" ?readonly="${this.isReadonly("then")}"></or-rule-actions>- </or-rule-section>+ <div class="section-container">+ <or-rule-then-otherwise .rule="${rule}" .config="${this.config}" .targetTypeMap="${targetTypeMap}" .assetDescriptors="${actionDescriptors}" ?readonly="${this.isReadonly("then")}"></or-rule-then-otherwise></div>`;}@@ -412,28 +642,17 @@ class OrRulesEditor extends translate(i18next)(LitElement) {return html`<div id="rule-list-container" class="shadow">- <or-rule-list .rulesets="${this._rulesets}" .ruleset="${this.activeRuleset}" ></or-rule-list>- <div id="bottom-toolbar">- ${manager.hasRole("write:rules") ? html`- <button @click="${this.deleteRuleset}"><or-icon icon="delete"></or-icon></button>- <button style="margin-left: auto;" @click="${this.createRuleset}"><or-icon icon="plus"></or-icon></button>- ` : ``}- </div>+ <or-rule-list id="rules-list" .realm="${this.realm}" .selectedIds="${this.selectedIds}"></or-rule-list></div>${this.activeRule ? html`<div class="rule-container">- <or-rule-header class="shadow" .readonly="${this.isReadonly("header")}" .ruleset="${this.activeRuleset}" .rule="${this.activeRule}" .saveEnabled="${!this._saveInProgress && this.isValidRule && this._activeModified}"></or-rule-header>+ <or-rule-header class="shadow" .readonly="${this.isReadonly("header")}" .ruleset="${this.activeRuleset}" .rule="${this.activeRule}" .saveEnabled="${!this._saveInProgress && this._isValidRule && this._activeModified}"></or-rule-header><div class="rule-editor-panel">${this.ruleEditorPanelTemplate(this.activeRule)}</div></div>` : html`- <div class="center-center">- <h3 style="font-weight: normal;">Kies links een profiel of maak een nieuw profiel aan.</h3>- ${manager.hasRole("write:rules") ? html`- <button style="margin: auto;" @click="${this.createRuleset}">profiel aanmaken</button>- ` : ``}- </div>+ <div class="msg"><or-translate value="noRuleSelected"></or-translate></div>`}`;}@@ -460,20 +679,20 @@ class OrRulesEditor extends translate(i18next)(LitElement) {}}- protected onRuleChanged() {+ protected _onRuleChanged() {this._activeModified = true;let isValid = false;const rule = this.activeRule;if (rule) {- isValid = this.validateRuleset();+ isValid = this._validateRuleset();}- this.isValidRule = isValid;+ this._isValidRule = isValid;this.requestUpdate();}- protected validateRuleset(): boolean {+ protected _validateRuleset(): boolean {const ruleset = this.activeRuleset;const rule = this.activeRule;@@ -490,7 +709,7 @@ class OrRulesEditor extends translate(i18next)(LitElement) {return false;}- if (!rule.then) {+ if (!rule.then || rule.then.length === 0) {return false;}@@ -507,25 +726,27 @@ class OrRulesEditor extends translate(i18next)(LitElement) {}protected validateConditionGroup(group: LogicGroup<RuleCondition>): boolean {- if (!group.items || group.items.length === 0) {+ if ((!group.items || group.items.length === 0) && (!group.groups || group.groups.length === 0)) {return false;}- for (const condition of group.items) {- if (!condition.assets && !condition.datetime && !condition.timer) {- return false;- }+ if (group.items) {+ for (const condition of group.items) {+ if (!condition.assets && !condition.datetime && !condition.timer) {+ return false;+ }- if (condition.assets && !this.validateAssetQuery(condition.assets)) {- return false;- }+ if (condition.assets && !this.validateAssetQuery(condition.assets, true, false)) {+ return false;+ }- if (condition.datetime && !this.validateValuePredicate(condition.datetime)) {- return false;- }+ if (condition.datetime && !this.validateValuePredicate(condition.datetime)) {+ return false;+ }- if (condition.timer && !Util.isTimeDuration(condition.timer)) {- return false;+ if (condition.timer && !Util.isTimeDuration(condition.timer)) {+ return false;+ }}}@@ -592,7 +813,11 @@ class OrRulesEditor extends translate(i18next)(LitElement) {}if (target.assets) {- return this.validateAssetQuery(target.assets);+ return this.validateAssetQuery(target.assets, false, false);+ }++ if (target.matchedAssets) {+ return this.validateAssetQuery(target.matchedAssets, false, true);}const typesAndTags = this.getTypeAndTagsFromGroup(rule.when!);@@ -603,22 +828,25 @@ class OrRulesEditor extends translate(i18next)(LitElement) {return true;}- protected validateAssetQuery(query?: AssetQuery): boolean {- if (!query) {- return true;- }+ protected validateAssetQuery(query: AssetQuery, isWhen: boolean, isMatchedAssets: boolean): boolean {if (!query.types || query.types.length === 0) {return false;}- if (!query.attributes || !query.attributes.items || query.attributes.items.length === 0) {- return false;+ if (isWhen) {+ if (!query.attributes || !query.attributes.items || query.attributes.items.length === 0) {+ return false;+ }+ } else {+ if (!query.ids || query.ids.length === 0 && !isMatchedAssets) {+ return false;+ }}if (query.types) {for (const type of query.types) {- if (!type.match || !type.value) {+ if (!type.value || !type.predicateType) {return false;}}@@ -665,62 +893,38 @@ class OrRulesEditor extends translate(i18next)(LitElement) {}}- protected readRules() {- manager.rest.api.RulesResource.getTenantRulesets(manager.config.realm, {- language: RulesetLang.JSON,- fullyPopulate: true- }).then((response: any) => {- if (response && response.data) {- this._rulesets = response.data;-- if (this._rulesets && this.activeRuleset) {- this.activeRuleset = this._rulesets.find((ruleset) => ruleset.id === this.activeRuleset!.id);- }- }- }).catch((reason: any) => {- console.error("Error: " + reason);- });- }+ protected _onRequestAdd() {+ const shouldContinue = this.okToLeaveActiveRule();- protected async createRuleset() {- const shouldContinue = await this.okToLeaveActiveRule();if (!shouldContinue) {return;}+ let rule = this.config && this.config.templates && this.config.templates.rule ? JSON.parse(JSON.stringify(this.config.templates.rule)) as JsonRule : undefined;- if (this._rulesets) {-- let rule = this.config && this.config.templates && this.config.templates.rule ? JSON.parse(JSON.stringify(this.config.templates.rule)) as JsonRule : undefined;-- if (!rule) {- rule = {+ if (!rule) {+ rule = {- };- }-- const name = this.config && this.config.templates && this.config.templates.rulesetName ? this.config.templates.rulesetName : OrRulesEditor.DEFAULT_RULESET_NAME;- rule.name = name;- const rules: JsonRulesetDefinition = {- rules: [rule]};+ }- const ruleset: TenantRuleset = {- id: 0,- type: "tenant",- name: name,- lang: RulesetLang.JSON,- realm: manager.getRealm(),- rules: JSON.stringify(rules)- };+ const name = this.config && this.config.templates && this.config.templates.rulesetName ? this.config.templates.rulesetName : OrRulesEditor.DEFAULT_RULESET_NAME;+ rule.name = name;+ const rules: JsonRulesetDefinition = {+ rules: [rule]+ };- this._rulesets = [...this._rulesets, ruleset];- this.activeRuleset = ruleset;- }+ const ruleset: TenantRuleset = {+ id: 0,+ type: "tenant",+ name: name,+ lang: RulesetLang.JSON,+ realm: manager.getRealm(),+ rules: JSON.stringify(rules)+ };+ this.activeRuleset = ruleset;}- protected saveRuleset(e: Event) {- e.preventDefault();-+ protected _onRequestSave(e: OrRulesEditorRequestSaveEvent) {if (!this.activeRuleset || !this.activeRule) {return;}@@ -740,72 +944,76 @@ class OrRulesEditor extends translate(i18next)(LitElement) {delete ruleset.status;delete ruleset.error;+ this._rulesList.disabled = true;+if (ruleset.id) {manager.rest.api.RulesResource.updateTenantRuleset(ruleset.id!, ruleset).then((response) => {this._saveInProgress = false;- this.readRules();+ this._rulesList.refresh();+ this._rulesList.disabled = false;});} else {manager.rest.api.RulesResource.createTenantRuleset(ruleset).then((response) => {ruleset.id = response.data;this._saveInProgress = false;- this.readRules();+ this._rulesList.refresh();+ this._rulesList.disabled = false;});}}- protected deleteRuleset() {+ protected _onRequestCopy(e: OrRulesEditorRequestCopyEvent) {+ const shouldContinue = this.okToLeaveActiveRule();- if (!this.activeRuleset) {+ if (!shouldContinue) {return;}- let confirmed = !this._activeModified || window.confirm(i18next.t("continueWithoutSaving"));+ let ruleset = JSON.parse(JSON.stringify(e.detail)) as TenantRuleset;+ delete ruleset.lastModified;+ delete ruleset.createdOn;+ delete ruleset.status;+ delete ruleset.error;+ this.activeRuleset = ruleset;+ }++ protected async _onRequestDelete(event: OrRulesEditorRequestDeleteEvent) {++ let confirmed = this.okToLeaveActiveRule();if (!confirmed) {return;}- confirmed = !this.activeRuleset.id || window.confirm(i18next.t("confirmDelete"));+ confirmed = !this.activeRuleset!.id || window.confirm(i18next.t("confirmDelete"));if (!confirmed) {return;}- const id = this.activeRuleset.id;- const index = this._rulesets!.findIndex((ruleset) => ruleset.id === this.activeRuleset!.id);- if (index >= 0) {- this._rulesets!.splice(index, 1);- }this.activeRuleset = undefined;- if (id) {- manager.rest.api.RulesResource.deleteTenantRuleset(id).then((response) => {- this.readRules();- });- }- }+ const rulesetsToDelete = event.detail;- protected async setActiveRuleset(e: any) {- if (this.okToLeaveActiveRule()) {- this.activeRuleset = e.detail.ruleset;+ // We need to call the backend so disable list until done+ this._rulesList.disabled = true;+ for (let ruleset of rulesetsToDelete) {+ await manager.rest.api.RulesResource.deleteTenantRuleset(ruleset.id!);}+ this._rulesList.refresh();+ this._rulesList.disabled = false;}- protected okToLeaveActiveRule() {+ protected _onRequestSelect(event: OrRulesEditorRequestSelectEvent) {+ event.detail.allow = this.okToLeaveActiveRule();+ }- const confirmed = !this._activeModified || window.confirm(i18next.t("continueWithoutSaving"));+ protected _onRuleSelectionChanged(event: OrRulesEditorSelectionChangedEvent) {+ this.activeRuleset = event.detail.length == 1 ? event.detail[0] : undefined;+ }- if (confirmed) {- if (this.activeRuleset && this.activeRuleset.id === 0) {- const index = this._rulesets!.findIndex((ruleset) => ruleset.id === this.activeRuleset!.id);- if (index >= 0) {- this._rulesets!.splice(index, 1);- this._rulesets = [...this._rulesets!];- }- }- }- return confirmed;+ protected okToLeaveActiveRule() {+ return !this._activeModified || window.confirm(i18next.t("continueWithoutSaving"));}protected getTypeAndTagsFromGroup(group: LogicGroup<RuleCondition>): [string, string?][] {diff --git a/ui/component/or-rules-editor/src/or-rule-action-attribute.ts b/ui/component/or-rules-editor/src/or-rule-action-attribute.tsnew file mode 100644index 000000000..eb34db51f--- /dev/null+++ b/ui/component/or-rules-editor/src/or-rule-action-attribute.ts@@ -0,0 +1,208 @@+import {customElement, html, LitElement, property, PropertyValues, css, TemplateResult} from "lit-element";+import {getAssetIdsFromQuery, getAssetTypeFromQuery, OrRulesEditorRuleChangedEvent, RulesConfig} from "./index";+import {+ Asset,+ AssetDescriptor,+ AssetQueryOrderBy$Property,+ Attribute,+ MetaItemType,+ RuleActionUpdateAttribute,+ RuleActionWriteAttribute+} from "@openremote/model";+import manager, {AssetModelUtil, Util} from "@openremote/core";+import {getAttributeValueTemplate} from "@openremote/or-attribute-input";+import {InputType, OrInputChangedEvent} from "@openremote/or-input";+import i18next from "i18next";++// language=CSS+const style = css`+ :host {+ display: flex;+ }++ :host > * {+ margin-right: 20px;+ }+`;++@customElement("or-rule-action-attribute")+export class OrRuleActionAttribute extends LitElement {++ static get styles() {+ return style;+ }++ @property({type: Object, attribute: false})+ public action!: RuleActionWriteAttribute | RuleActionUpdateAttribute;++ @property({type: Object, attribute: false})+ public targetTypeMap?: [string, string?][];++ public readonly?: boolean;++ public config?: RulesConfig;++ public assetDescriptors?: AssetDescriptor[];++ @property({type: Array, attribute: false})+ protected _assets?: Asset[];+++ protected shouldUpdate(_changedProperties: PropertyValues): boolean {+ if (_changedProperties.has("action")) {+ this._assets = undefined;+ }+ return super.shouldUpdate(_changedProperties);+ }++ protected _getAssetType() {+ if (!this.action.target) {+ return;+ }+ const query = this.action.target.assets ? this.action.target.assets : this.action.target.matchedAssets ? this.action.target.matchedAssets : undefined;+ return query ? getAssetTypeFromQuery(query) : undefined;+ }++ protected render() {++ if (!this.action.target) {+ return html``;+ }++ const assetType = this._getAssetType();++ if (!assetType) {+ return html``;+ }++ const query = this.action.target.assets ? this.action.target.assets : this.action.target.matchedAssets ? this.action.target.matchedAssets : undefined;+ const assetDescriptor = this.assetDescriptors ? this.assetDescriptors.find((ad) => ad.type === assetType) : undefined;++ if (!assetDescriptor) {+ return html``;+ }++ if (!this._assets) {+ this.loadAssets(assetType);+ return html``;+ }++ // TODO: Add multiselect support+ const ids = getAssetIdsFromQuery(query);+ const idValue = ids && ids.length > 0 ? ids[0] : "*";+ const idOptions: [string, string] [] = [+ ["*", i18next.t("matched")]+ ];++ idOptions.push(...this._assets!.map((asset) => [asset.id!, asset.name!] as [string, string]));++ const asset = idValue && idValue !== "*" ? this._assets.find(a => a.id === idValue) : undefined;+ const showUpdateOptions = !this.config || !this.config.controls || !this.config.controls.hideActionUpdateOptions;+ const attributeDescriptor = AssetModelUtil.getAssetAttributeDescriptor(assetDescriptor, this.action.attributeName);+ let attribute: Attribute | undefined = asset && this.action.attributeName ? Util.getAssetAttribute(asset, this.action.attributeName) : undefined;+ let inputTemplate: ((value: any) => TemplateResult) | undefined = undefined;++ // Only RW attributes can be used in actions+ let attributes: [string, string][];+ if (asset) {+ attributes = Util.getAssetAttributes(asset).filter((attr) => !Util.hasMetaItem(attr, MetaItemType.READ_ONLY.urn!))+ .map((attr) => {+ const attrDescriptor = AssetModelUtil.getAssetAttributeDescriptor(assetDescriptor, attr.name);+ return [attr.name!, Util.getAttributeLabel(attr, attrDescriptor)];+ });+ } else {+ attributes = !assetDescriptor || !assetDescriptor.attributeDescriptors ? []+ : assetDescriptor.attributeDescriptors.filter((ad) => !AssetModelUtil.hasMetaItem(ad, MetaItemType.READ_ONLY.urn!))+ .map((ad) => [ad.attributeName!, Util.getAttributeLabel(undefined, ad)]);+ }++ // A dummy attribute if we don't have a real one (to allow us to re-use the following function)+ if (this.action.attributeName) {+ if (!attribute) {+ attribute = {+ name: this.action.attributeName,+ type: attributeDescriptor ? attributeDescriptor.valueDescriptor : undefined+ };+ }++ inputTemplate = getAttributeValueTemplate(assetType, attribute, this.readonly || false, false, (v: any) => this.setActionAttributeValue(v), this.config ? this.config.inputProvider : undefined, undefined, "");+ }++ return html`+ <or-input id="matchSelect" type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" ?readonly="${this.readonly}" .options="${idOptions}" .value="${idValue}"></or-input>+ <or-input id="attributeSelect" .label="${i18next.t("attribute")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionAttributeName(e.detail.value)}" ?readonly="${this.readonly}" .options="${attributes}" .value="${this.action.attributeName}"></or-input>+ ${inputTemplate ? inputTemplate(this.action.value) : ``}+ `;+ }++ protected set _assetId(assetId: string) {+ const assetType = this._getAssetType();++ if (assetId === "*") {+ this.action.target!.assets = undefined;+ this.action.target = {+ matchedAssets: {+ types: [+ {+ predicateType: "string",+ value: assetType+ }+ ]+ }+ }+ } else {+ this.action.target!.matchedAssets = undefined;+ this.action.target = {+ assets: {+ ids: [+ assetId+ ],+ types: [+ {+ predicateType: "string",+ value: assetType+ }+ ]+ }+ }+ }++ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());+ this.requestUpdate();+ }++ protected setActionAttributeName(name: string | undefined) {+ this.action.attributeName = name;+ this.action.value = undefined;+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());+ this.requestUpdate();+ }++ protected setActionAttributeValue(value: any) {+ this.action.value = value;+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());+ this.requestUpdate();+ }++ protected loadAssets(type: string) {+ manager.rest.api.AssetResource.queryAssets({+ types: [+ {+ predicateType: "string",+ value: type+ }+ ],+ select: {+ excludeAttributeMeta: true,+ excludeAttributeTimestamp: true,+ excludeAttributeValue: true,+ excludeParentInfo: true,+ excludeRealm: true,+ excludePath: true+ },+ orderBy: {+ property: AssetQueryOrderBy$Property.NAME+ }+ }).then((response) => this._assets = response.data);+ }+}\ No newline at end of filediff --git a/ui/component/or-rules-editor/src/or-rule-actions.ts b/ui/component/or-rules-editor/src/or-rule-actions.tsdeleted file mode 100644index 0913a78b2..000000000--- a/ui/component/or-rules-editor/src/or-rule-actions.ts+++ /dev/null@@ -1,355 +0,0 @@-import {customElement, html, LitElement, property, TemplateResult} from "lit-element";-import {actionStyle} from "./style";-import "./or-rule-asset-query";-import {ActionTargetType, ActionType, getAssetTypeFromQuery, OrRuleChangedEvent, RulesConfig} from "./index";-import {- AssetDescriptor,- AttributeDescriptor,- JsonRule,- RuleActionUnion,- RuleActionWriteAttribute,- Attribute-} from "@openremote/model";-import i18next from "i18next";-import {InputType, OrInputChangedEvent} from "@openremote/or-input";-import {getAttributeValueTemplate} from "@openremote/or-attribute-input";--@customElement("or-rule-actions")-class OrRuleActions extends LitElement {-- static get styles() {- return actionStyle;- }-- @property({type: Object})- public rule?: JsonRule;-- @property({type: Object})- public targetTypeMap?: [string, string?][];-- public readonly?: boolean;-- public newTemplate?: RuleActionUnion;-- public config?: RulesConfig;-- public assetDescriptors?: AssetDescriptor[];-- public allowAdd: boolean = true;-- public static DEFAULT_ALLOWED_ACTION_TARGETS = [ActionTargetType.TRIGGER_ASSETS, ActionTargetType.TAGGED_ASSETS, ActionTargetType.OTHER_ASSETS, ActionTargetType.USERS];- public static DEFAULT_ALLOWED_ACTION_TYPES = [ActionType.WRITE_ATTRIBUTE, ActionType.UPDATE_ATTRIBUTE, ActionType.NOTIFICATION, ActionType.WAIT];-- protected ruleActionTemplate(action: RuleActionUnion) {-- if (!action) {- return ``;- }-- let targetTemplate: TemplateResult | string = ``;- let typeTemplate: TemplateResult | string = ``;- let currentTarget = ActionTargetType.TRIGGER_ASSETS;- const showTargetOptions = action.action !== "wait" && (!this.config || !this.config.controls || !this.config.controls.hideActionTargetOptions);- const showTypeOptions = !this.config || !this.config.controls || !this.config.controls.hideActionTypeOptions;- const showUpdateOptions = !this.config || !this.config.controls || !this.config.controls.hideActionUpdateOptions;- let allowedTargets = this.config && this.config.controls && this.config.controls.allowedActionTargets ? this.config.controls.allowedActionTargets : OrRuleActions.DEFAULT_ALLOWED_ACTION_TARGETS;- const allowedActions = this.config && this.config.controls && this.config.controls.allowedActionTypes ? this.config.controls.allowedActionTypes : OrRuleActions.DEFAULT_ALLOWED_ACTION_TYPES;- let targetRhsTemplate: TemplateResult | string = ``;-- if (action.target) {- if (action.target.ruleConditionTag !== undefined && action.target.ruleConditionTag !== null) {- currentTarget = ActionTargetType.TAGGED_ASSETS;- if (showTargetOptions) {- targetRhsTemplate = html`<or-input id="actionTagSelect" type="${InputType.SELECT}" .label="${i18next.t("tag")}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionTriggerTag(action, e.detail.value)}" ?readonly="${this.readonly}" .options="${this.getTriggerTags()}" .value="${action.target.ruleConditionTag}"></or-input>`;- }- } else if (action.target.users) {- currentTarget = ActionTargetType.USERS;- if (showTargetOptions) {- targetRhsTemplate = html`<span>USER QUERY NOT IMPLEMENTED</span>`;- }- } else if (action.target.assets) {- currentTarget = ActionTargetType.OTHER_ASSETS;- if (showTargetOptions) {- targetRhsTemplate = html`<or-rule-asset-query .config="${this.config}" .assetDescriptors="${this.assetDescriptors}" .readonly="${this.readonly}" .query="${action.target.assets}"></or-rule-asset-query>`;- }- }- }-- if (showTypeOptions) {- const translatedAllowedActions = allowedActions.map((actionType) => [actionType, i18next.t(actionType)] as [string, string]);- typeTemplate = html`- <or-input id="actionTypeSelect" .label="${i18next.t("action")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionType(action, e.detail.value as ActionType)}" ?readonly="${this.readonly}" .options="${translatedAllowedActions}" .value="${action.action}"></or-input>- `;- }-- if (showTargetOptions) {-- if (action.action !== "notification") {- allowedTargets = allowedTargets.filter((at) => at !== ActionTargetType.USERS);- }-- const translatedAllowedTargets = allowedTargets.map((at) => [at, i18next.t(at)] as [string, string]);- targetTemplate = html`- <or-input id="actionTargetSelect" .label="${i18next.t("target")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionTarget(action, e.detail.value as ActionTargetType)}" ?readonly="${this.readonly}" .options="${translatedAllowedTargets}" .value="${currentTarget}"></or-input>- ${targetRhsTemplate}- `;- }-- let actionTemplate: TemplateResult | string = ``;- switch (action.action) {- case "wait":- actionTemplate = html`<span>WAIT NOT IMPLEMENTED</span>`;- break;- case "notification":- actionTemplate = html`<span>NOTIFICATIONS NOT IMPLEMENTED</span>`;- break;- case "write-attribute":- case "update-attribute":- let assetTypes: [string, string][] = [];-- switch (currentTarget) {- case ActionTargetType.USERS:- return html`<span>INVALID RULE</span>`;- case ActionTargetType.TRIGGER_ASSETS:- // Get all asset types- assetTypes = this.getAssetTypes();- break;- case ActionTargetType.OTHER_ASSETS:- const type = getAssetTypeFromQuery(action.target!.assets);- if (type) {- if (this.assetDescriptors) {- const descriptor = this.assetDescriptors.find((ad) => ad.type === type);- if (descriptor) {- assetTypes.push([descriptor.type!, descriptor.name!]);- }- }- }- break;- case ActionTargetType.TAGGED_ASSETS:- // actionTemplate = html`- // <or-input type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionTriggerTag(action, e.detail.value)}" ?readonly="${this.readonly}" .options="${attributeNames}" .value="${action.attributeName}"></or-input>- // `;- assetTypes = this.getAssetTypes(action.target!.ruleConditionTag!);- break;- }-- const attributeDescriptors = this.getCommonAttributes(assetTypes);- const attributeNames = attributeDescriptors.map((ad) => [ad.attributeName, i18next.t(ad.attributeName!)]);- const assetType = assetTypes.length > 0 ? assetTypes[0][0] : undefined;-- // A dummy attribute to allow us to re-use the following function- let attribute: Attribute = {- name: action.attributeName- };- let inputTemplate = getAttributeValueTemplate(assetType, attribute, this.readonly || false, false, (v: any) => this.setActionAttributeValue(action, v), this.config ? this.config.inputProvider : undefined);-- actionTemplate = html`- <or-input id="actionAttributeSelect" .label="${i18next.t("attribute")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionAttributeName(action, e.detail.value)}" ?readonly="${this.readonly}" .options="${attributeNames}" .value="${action.attributeName}"></or-input>- ${action.attributeName && inputTemplate ? inputTemplate(action.value) : ``}- `;-- if (action.action === "update-attribute" && showUpdateOptions) {- actionTemplate = html`- ${actionTemplate}- <span>UPDATE NOT IMPLEMENTED</span>- `;- }- break;- }-- return html`- ${typeTemplate}- ${targetTemplate}- ${actionTemplate}- `;- }-- protected render() {-- if (!this.rule) {- return html``;- }-- if (!this.rule.then) {- this.rule.then = [];- }-- return html`- ${this.rule.then ? this.rule.then.map((action: RuleActionUnion) => {- return html`- <div class="rule-action">- ${this.ruleActionTemplate(action)}- ${!this.readonly && (this.allowAdd || this.rule!.then!.length > 1) ? html`- <button class="button-clear" @click="${() => this.removeAction(action)}"><or-icon icon="close-circle"></or-icon></input>- ` : ``}- </div>- `; }) : ``}- ${this.allowAdd ? html`- <div class="add-buttons-container">- <button class="button-clear add-button" @click="${this.addAction}"><or-icon icon="plus-circle"></or-icon><or-translate value="rulesEditorAddAction"></or-translate></button>- </div>- ` : ``}- `;- }-- protected getCommonAttributes(assetTypeAndNames: [string, string][]) {-- let isFirst = true;- let attributes: AttributeDescriptor[] = [];- for (const assetTypeAndName of assetTypeAndNames) {- const assetDescriptor = this.assetDescriptors ? this.assetDescriptors.find((ad) => ad.type === assetTypeAndName[0]) : undefined;- if (assetDescriptor && assetDescriptor.attributeDescriptors) {- if (isFirst) {- attributes = [...assetDescriptor.attributeDescriptors];- } else {- attributes = attributes.filter((attribute) => assetDescriptor.attributeDescriptors!.find((ad) => ad.attributeName === attribute.attributeName));- }- }- isFirst = false;- if (attributes.length === 0) {- break;- }- }-- return attributes;- }-- protected getTriggerTags(): string[] {- if (!this.targetTypeMap) {- return [];- }-- return this.targetTypeMap.map((typeAndTag, index) => typeAndTag[1] !== undefined ? typeAndTag[1] : index.toString()).sort();- }-- protected getAssetTypes(tagName?: string) {- if (!this.targetTypeMap || !this.assetDescriptors) {- return [];- }-- return this.targetTypeMap.filter((typeAndTag) => !tagName || typeAndTag[1] === tagName).map((typeAndTag) => {- const descriptor = this.assetDescriptors!.find((ad) => ad.type === typeAndTag[0]);- if (descriptor) {- return [descriptor.type, descriptor.name] as [string, string];- }- return null;- }).filter((type) => type !== null) as [string, string][];- }-- protected removeAction(action?: RuleActionUnion) {- if (!this.rule || !this.rule.then || !action) {- return;- }-- const index = this.rule.then.indexOf(action);- if (index >= 0) {- this.rule.then.splice(index, 1);- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();- }- }-- protected addAction() {-- if (!this.rule || !this.rule.then) {- return;- }-- let newAction: RuleActionUnion = {- action: "write-attribute"- };-- if (this.newTemplate) {- newAction = JSON.parse(JSON.stringify(this.newTemplate)) as RuleActionUnion;- }-- this.rule.then.push(newAction);- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();- }-- protected setActionTarget(action: RuleActionUnion, target: ActionTargetType | undefined) {- switch (target) {- case ActionTargetType.TRIGGER_ASSETS:- action.target = undefined;- break;- case ActionTargetType.TAGGED_ASSETS:- action.target = {- ruleConditionTag: ""- };- break;- case ActionTargetType.USERS:- action.target = {- users: {-- }- };- break;- case ActionTargetType.OTHER_ASSETS:- action.target = {- assets: {-- }- };- break;- }-- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();- }-- protected setActionType(action: RuleActionUnion, type: ActionType | undefined) {-- const actions = this.rule!.then!;- const index = actions.indexOf(action);- if (index < 0) {- return;- }-- switch (type) {- case ActionType.WAIT:- action = {- action: "wait"- };- break;- case ActionType.NOTIFICATION:- action = {- action: "notification"- };- break;- case ActionType.WRITE_ATTRIBUTE:- action = {- action: "write-attribute"- };- break;- case ActionType.UPDATE_ATTRIBUTE:- action = {- action: "update-attribute"- };- break;- }-- actions[index] = action;- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();- }-- protected setActionTriggerTag(action: RuleActionUnion, tag: string | undefined) {- action.target!.ruleConditionTag = tag;- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();- }-- protected setActionAttributeName(action: RuleActionUnion, name: string | undefined) {- (action as RuleActionWriteAttribute).attributeName = name;- (action as RuleActionWriteAttribute).value = undefined;- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();- }-- protected setActionAttributeValue(action: RuleActionUnion, value: any) {- (action as RuleActionWriteAttribute).value = value;- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();- }-}diff --git a/ui/component/or-rules-editor/src/or-rule-asset-query.ts b/ui/component/or-rules-editor/src/or-rule-asset-query.tsindex 8777e9057..a3022ceaa 100644--- a/ui/component/or-rules-editor/src/or-rule-asset-query.ts+++ b/ui/component/or-rules-editor/src/or-rule-asset-query.ts@@ -1,9 +1,10 @@-import {customElement, html, LitElement, property} from "lit-element";+import {css, customElement, html, LitElement, property, PropertyValues} from "lit-element";import {AssetDescriptor,AssetQuery,AssetQueryMatch,AssetQueryOperator as AQO,+ AssetQueryOrderBy$Property,AttributeDescriptor,AttributePredicate,AttributeValueDescriptor,@@ -11,29 +12,65 @@ import {LogicGroup,LogicGroupOperator,ValuePredicateUnion,- ValueType+ ValueType,+ Asset,+ MetaItemType} from "@openremote/model";import {AssetQueryOperator,AssetTypeAttributeName,getAssetTypeFromQuery,+ getAssetIdsFromQuery,getDescriptorValueType,- OrRuleChangedEvent,- RulesConfig+ OrRulesEditorRuleChangedEvent,+ RulesConfig, getAttributeNames} from "./index";import {OrSelectChangedEvent} from "@openremote/or-select";import "@openremote/or-input";import {InputType, OrInputChangedEvent} from "@openremote/or-input";import {getAttributeValueTemplate} from "@openremote/or-attribute-input";-import {Util} from "@openremote/core";-import {assetQueryEditorStyle} from "./style";+import manager, {Util, AssetModelUtil} from "@openremote/core";import i18next from "i18next";+import {buttonStyle} from "./style";++// language=CSS+const style = css`++ ${buttonStyle}++ :host {+ display: flex;+ }++ :host > * {+ margin-right: 20px;+ }++ .attribute-group {+ flex-grow: 1;+ display: flex;+ flex-direction: row;+ }++ .attribute, .attribute-editor {+ display: flex;+ flex-grow: 1;+ }++ .attribute > * {+ flex-grow: 0;+ }++ .attribute-editor > * {+ margin: 0 5px;+ }+`;@customElement("or-rule-asset-query")class OrRuleAssetQuery extends LitElement {- @property({type: Object})- public query?: AssetQuery;+ @property({type: Object, attribute: false})+ public query!: AssetQuery;public readonly?: boolean;@@ -41,6 +78,9 @@ class OrRuleAssetQuery extends LitElement {public assetDescriptors?: AssetDescriptor[];+ @property({type: Array, attribute: false})+ protected _assets?: Asset[];+// Value predicates for specific attribute value descriptorsprotected _queryOperatorsMap: Map<AssetTypeAttributeName | AttributeDescriptor | AttributeValueDescriptor | ValueType, AssetQueryOperator[]> = new Map<AssetTypeAttributeName | AttributeDescriptor | AttributeValueDescriptor | ValueType, AssetQueryOperator[]>([[AttributeValueType.GEO_JSON_POINT, [AssetQueryOperator.EQUALS, AssetQueryOperator.NOT_EQUALS, AssetQueryOperator.WITHIN_RADIUS, AssetQueryOperator.OUTSIDE_RADIUS, AssetQueryOperator.WITHIN_RECTANGLE, AssetQueryOperator.OUTSIDE_RECTANGLE]],@@ -51,11 +91,22 @@ class OrRuleAssetQuery extends LitElement {[ValueType.OBJECT, [AssetQueryOperator.CONTAINS_KEY, AssetQueryOperator.NOT_CONTAINS_KEY, AssetQueryOperator.VALUE_EMPTY, AssetQueryOperator.VALUE_NOT_EMPTY]]]);- protected attributePredicateEditorTemplate(assetDescriptor: AssetDescriptor, attributePredicate: AttributePredicate) {+ protected attributePredicateEditorTemplate(assetDescriptor: AssetDescriptor, asset: Asset | undefined, attributePredicate: AttributePredicate) {const operator = this.getOperator(attributePredicate);const attributeName = this.getAttributeName(attributePredicate);- const attributes = this.getAttributes(assetDescriptor).map((a) => [a, i18next.t(a)]);+ let attributes: [string, string][];+ if (asset) {+ attributes = Util.getAssetAttributes(asset).filter((attr) => !Util.hasMetaItem(attr, MetaItemType.READ_ONLY.urn!))+ .map((attr) => {+ const attrDescriptor = AssetModelUtil.getAssetAttributeDescriptor(assetDescriptor, attr.name);+ return [attr.name!, Util.getAttributeLabel(attr, attrDescriptor)];+ });+ } else {+ attributes = !assetDescriptor || !assetDescriptor.attributeDescriptors ? []+ : assetDescriptor.attributeDescriptors.filter((ad) => !AssetModelUtil.hasMetaItem(ad, MetaItemType.READ_ONLY.urn!))+ .map((ad) => [ad.attributeName!, Util.getAttributeLabel(undefined, ad)]);+ }return html`<div class="attribute-editor">@@ -83,22 +134,22 @@ class OrRuleAssetQuery extends LitElement {switch (valuePredicate.predicateType) {case "string":- return getAttributeValueTemplate(assetType, {name: attributeName!}, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined)(value);+ return getAttributeValueTemplate(assetType, {name: attributeName!}, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined, undefined, "")(value);case "boolean":return html `<span>NOT IMPLEMENTED</span>`;case "datetime":return html `<span>NOT IMPLEMENTED</span>`;case "number":if (valuePredicate.operator === AQO.BETWEEN) {- let inputTemplate1 = getAttributeValueTemplate(assetType, {name: attributeName!}, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined);- let inputTemplate2 = getAttributeValueTemplate(assetType, {name: attributeName!}, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "rangeValue", v), this.config ? this.config.inputProvider : undefined);+ let inputTemplate1 = getAttributeValueTemplate(assetType, {name: attributeName!}, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined, undefined, "");+ let inputTemplate2 = getAttributeValueTemplate(assetType, {name: attributeName!}, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "rangeValue", v), this.config ? this.config.inputProvider : undefined, undefined, "");return html`${inputTemplate1(value)}<span style="display: inline-flex; align-items: center;">&</span>${inputTemplate2(valuePredicate.rangeValue)}`;}- return getAttributeValueTemplate(assetType, {name: attributeName!}, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined)(value);+ return getAttributeValueTemplate(assetType, {name: attributeName!}, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined, undefined, "")(value);case "string-array":return html `<span>NOT IMPLEMENTED</span>`;case "radial":@@ -114,31 +165,42 @@ class OrRuleAssetQuery extends LitElement {case "array":// TODO: Update once we can determine inner type of array// Assume string array- return getAttributeValueTemplate(assetType, {name: attributeName!}, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined, InputType.TEXT)(value);+ return getAttributeValueTemplate(assetType, {name: attributeName!}, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined, InputType.TEXT, undefined)(value);default:return html `<span>NOT IMPLEMENTED</span>`;}}static get styles() {- return assetQueryEditorStyle;+ return style;}- protected render() {- if (!this.query) {- return;+ protected shouldUpdate(_changedProperties: PropertyValues): boolean {++ if (_changedProperties.has("query")) {+ this._assets = undefined;}+ return super.shouldUpdate(_changedProperties);+ }++ protected render() {+const assetType = getAssetTypeFromQuery(this.query);if (!assetType) {- return;+ return html``;}const assetDescriptor = this.assetDescriptors ? this.assetDescriptors.find((ad) => ad.type === assetType) : undefined;if (!assetDescriptor) {- return;+ return html``;+ }++ if (!this._assets) {+ this.loadAssets(assetType);+ return html``;}if (!this.query.attributes) {@@ -149,45 +211,41 @@ class OrRuleAssetQuery extends LitElement {this.query.attributes.items = [{}];}- const showAddAttribute = !this.readonly && (!this.config || !this.config.controls || this.config.controls.hideWhenAddAttribute !== true);const showRemoveAttribute = !this.readonly && this.query.attributes && this.query.attributes.items && this.query.attributes.items.length > 1;+ // TODO: Add multiselect support+ const ids = getAssetIdsFromQuery(this.query);+ const idValue = ids && ids.length > 0 ? ids[0] : "*";+ const idOptions: [string, string] [] = [+ ["*", i18next.t("anyOfThisType")]+ ];++ idOptions.push(...this._assets!.map((asset) => [asset.id!, asset.name!] as [string, string]));+return html`<div class="attribute-group">- <div class="attribute-items">- ${this.query.attributes && this.query.attributes.items ? this.query.attributes.items.map((attributePredicate) => {-- return html`- <div class="attribute-item">- <button @click="${() => this.toggleAttributeGroup(this.query!.attributes!)}" class="button-clear operator"><span>${i18next.t(!this.query!.attributes!.operator || this.query!.attributes!.operator === LogicGroupOperator.AND ? "and" : "or")}</span></button>- <div class="attribute">- ${this.attributePredicateEditorTemplate(assetDescriptor, attributePredicate)}- ${showRemoveAttribute ? html`- <button class="button-clear" @click="${() => this.removeAttributePredicate(this.query!.attributes!, attributePredicate)}"><or-icon icon="close-circle"></or-icon></input>- ` : ``}- </div>- </div>- `;- }) : ``}- </div>-- ${showAddAttribute ? html`- <div class="add-buttons-container">- ${showAddAttribute ? html`<button class="button-clear add-button" @click="${() => this.addAttributePredicate(this.query!.attributes!)}"><or-icon icon="plus-circle"></or-icon><or-translate value="rulesEditorAddCondition"></or-translate></button>` : ``}- </div>- ` : ``}++ <or-input type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" ?readonly="${this.readonly}" .options="${idOptions}" .value="${idValue}"></or-input>++ ${this.query.attributes && this.query.attributes.items ? this.query.attributes.items.map((attributePredicate) => {++ return html`+ <div class="attribute">+ ${this.attributePredicateEditorTemplate(assetDescriptor, idValue !== "*" ? this._assets!.find((asset) => asset.id === idValue) : undefined, attributePredicate)}+ ${showRemoveAttribute ? html`+ <button class="button-clear" @click="${() => this.removeAttributePredicate(this.query!.attributes!, attributePredicate)}"><or-icon icon="close-circle"></or-icon></input>+ ` : ``}+ </div>+ `;+ }) : ``}</div>`;}- protected getAttributes(descriptor?: AssetDescriptor) {- let attributes: string[] = [];-- if (descriptor && descriptor.attributeDescriptors) {- attributes = descriptor.attributeDescriptors.map((ad) => ad.attributeName!);- }-- return attributes;+ protected set _assetId(assetId: string | undefined) {+ !assetId || assetId === "*" ? this.query.ids = undefined : this.query.ids! = [assetId];+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());+ this.requestUpdate();}protected getAttributeName(attributePredicate: AttributePredicate): string | undefined {@@ -205,7 +263,7 @@ class OrRuleAssetQuery extends LitElement {attributePredicate!.name.match = AssetQueryMatch.EXACT;attributePredicate!.name.value = attributeName;attributePredicate!.value = undefined;- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();}@@ -349,7 +407,7 @@ class OrRuleAssetQuery extends LitElement {if (!operator) {attributePredicate.value = undefined;- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();return;}@@ -361,7 +419,7 @@ class OrRuleAssetQuery extends LitElement {if (!valueType || !value) {attributePredicate.value = undefined;- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();return;}@@ -544,7 +602,7 @@ class OrRuleAssetQuery extends LitElement {}attributePredicate.value = predicate;- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();}@@ -562,7 +620,7 @@ class OrRuleAssetQuery extends LitElement {}(valuePredicate as any)[propertyName] = value;- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();}@@ -571,7 +629,7 @@ class OrRuleAssetQuery extends LitElement {if (index >= 0) {group.items!.splice(index, 1);}- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();}@@ -580,7 +638,7 @@ class OrRuleAssetQuery extends LitElement {group.items = [];}group.items.push({});- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();}@@ -590,7 +648,29 @@ class OrRuleAssetQuery extends LitElement {} else {group.operator = LogicGroupOperator.OR;}- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();}++ protected loadAssets(type: string) {+ manager.rest.api.AssetResource.queryAssets({+ types: [+ {+ predicateType: "string",+ value: type+ }+ ],+ select: {+ excludeAttributeMeta: true,+ excludeAttributeTimestamp: true,+ excludeAttributeValue: true,+ excludeParentInfo: true,+ excludeRealm: true,+ excludePath: true+ },+ orderBy: {+ property: AssetQueryOrderBy$Property.NAME+ }+ }).then((response) => this._assets = response.data);+ }}diff --git a/ui/component/or-rules-editor/src/or-rule-condition.ts b/ui/component/or-rules-editor/src/or-rule-condition.tsindex 26d64bbc9..8887b7b2d 100644--- a/ui/component/or-rules-editor/src/or-rule-condition.ts+++ b/ui/component/or-rules-editor/src/or-rule-condition.ts@@ -1,25 +1,90 @@-import {customElement, html, LitElement, TemplateResult, property} from "lit-element";+import {customElement, html, css, LitElement, property, TemplateResult} from "lit-element";+import {AssetDescriptor, AssetQueryMatch, RuleCondition} from "@openremote/model";import {- AssetQueryMatch,- RuleCondition,- AssetDescriptor,-} from "@openremote/model";-import {- RulesConfig,ConditionType,- getAssetTypeFromQuery, OrRuleChangedEvent+ getAssetTypeFromQuery,+ getButtonWithMenuTemplate,+ OrRulesEditorRuleChangedEvent,+ RulesConfig} from "./index";import "./or-rule-asset-query";-import {OrSelectChangedEvent} from "@openremote/or-select";-import {conditionEditorStyle} from "./style";-import i18next from "i18next";-import {InputType} from "@openremote/or-input";+import "@openremote/or-mwc-components/dist/or-mwc-menu";+import {Menu, MenuItem} from "@openremote/or-mwc-components/dist/or-mwc-menu";+import "@openremote/or-icon";+import "@openremote/or-translate";+import {getAssetDescriptorIconTemplate} from "@openremote/or-icon";+import {AssetModelUtil} from "@openremote/core";+import {i18next} from "@openremote/or-translate";++const TIMER_COLOR = "4b87ea";+const DATE_TIME_COLOR = "6AEAA4";++function getWhenTypesMenu(config?: RulesConfig, assetDescriptors?: AssetDescriptor[]): Menu {++ let addAssetTypes = true;+ let addDatetime = true;+ let addTimer = true;++ if (config && config.controls && config.controls.allowedConditionTypes) {+ addAssetTypes = config.controls.allowedConditionTypes.indexOf(ConditionType.ASSET_QUERY) >= 0;+ addDatetime = config.controls.allowedConditionTypes.indexOf(ConditionType.DATE_TIME) >= 0;+ addTimer = config.controls.allowedConditionTypes.indexOf(ConditionType.TIMER) >= 0;+ }++ const menu: Menu = {+ items: []+ };++ if (addAssetTypes && assetDescriptors) {+ menu.items.push(...assetDescriptors.map((ad) => {+ const content = html`+ ${getAssetDescriptorIconTemplate(ad)}+ <span style="white-space: nowrap; text-transform: capitalize">${i18next.t(ad.name!, {defaultValue: ad.name!.replace(/_/g, " ").toLowerCase()})}</span>+ `;+ return {content: content, value: ad.type} as MenuItem+ }));+ }++ if (addDatetime) {+ const content = html`+ <or-icon style="--or-icon-fill: #${DATE_TIME_COLOR}" icon="clock"></or-icon>+ <span style="text-transform: capitalize"> <or-translate value="datetime"></or-translate></span>+ `;+ menu.items.push({content: content, value: ConditionType.DATE_TIME} as MenuItem);+ }++ if (addTimer) {+ const content = html`+ <or-icon style="--or-icon-fill: #${TIMER_COLOR}" icon="timer"></or-icon>+ <span style="text-transform: capitalize"> <or-translate value="timer"></or-translate></span>+ `;+ menu.items.push({content: content, value: ConditionType.TIMER} as MenuItem);+ }++ return menu;+}++// language=CSS+const style = css`+ :host {+ display: flex;+ flex-direction: row;+ }++ or-rule-asset-query {+ flex-grow: 1;+ }++ #type-selector {+ margin-top: 10px;+ }+`;@customElement("or-rule-condition")class OrRuleCondition extends LitElement {- @property({type: Object})- public ruleCondition?: RuleCondition;+ @property({type: Object, attribute: false})+ public ruleCondition!: RuleCondition;public readonly: boolean = false;@@ -28,15 +93,11 @@ class OrRuleCondition extends LitElement {public assetDescriptors?: AssetDescriptor[];static get styles() {- return conditionEditorStyle;+ return style;}protected render() {- if (!this.ruleCondition) {- return;- }-const showTypeSelect = !this.config || !this.config.controls || this.config.controls.hideConditionTypeOptions !== true;const type = this.type;@@ -44,8 +105,39 @@ class OrRuleCondition extends LitElement {return html`<span>INVALID CONFIG - NO TYPE SPECIFIED AND TYPE SELECTOR DISABLED</span>`;}+ let typeTemplate: TemplateResult | string = ``;let template: TemplateResult | string = ``;+ if (showTypeSelect) {++ let buttonIcon = undefined;+ let buttonColor = "inherit";++ if (type) {+ switch (type) {+ case ConditionType.DATE_TIME:+ buttonIcon = "clock";+ buttonColor = DATE_TIME_COLOR;+ break;+ case ConditionType.TIMER:+ buttonIcon = "timer";+ buttonColor = TIMER_COLOR;+ break;+ default:+ const ad = AssetModelUtil.getAssetDescriptor(type);+ buttonIcon = AssetModelUtil.getAssetDescriptorIcon(ad) || buttonIcon;+ buttonColor = AssetModelUtil.getAssetDescriptorColor(ad) || buttonColor;+ break;+ }+ }++ typeTemplate = html`+ <div style="display: table; height: 100%; --or-input-color: #${buttonColor}">+ ${getButtonWithMenuTemplate(getWhenTypesMenu(this.config, this.assetDescriptors), buttonIcon || "", type, (value: string) => this.type = value)}+ </div>+ `;+ }+if (type) {switch (type) {case ConditionType.DATE_TIME:@@ -61,47 +153,12 @@ class OrRuleCondition extends LitElement {}return html`- ${showTypeSelect ? html`<or-input id="type-selector" type="${InputType.SELECT}" @or-input-changed="${(e: OrSelectChangedEvent) => this.type = e.detail.value}" .options="${this.getTypes()}" .value="${type}" ?readonly="${this.readonly}"></or-input>` : ``}+ ${typeTemplate}${template}`;}- protected getTypes() {-- let addAssetTypes = true;- let addDatetime = true;- let addTimer = true;-- if (this.config && this.config.controls && this.config.controls.allowedConditionTypes) {- addAssetTypes = this.config.controls.allowedConditionTypes.indexOf(ConditionType.ASSET_QUERY) >= 0;- addDatetime = this.config.controls.allowedConditionTypes.indexOf(ConditionType.DATE_TIME) >= 0;- addTimer = this.config.controls.allowedConditionTypes.indexOf(ConditionType.TIMER) >= 0;- }-- const types: [string, string][] = [];-- if (addAssetTypes && this.assetDescriptors) {- this.assetDescriptors.forEach((ad) => types.push([ad.type!, ad.name!]));- }-- if (types.length > 0 && (addDatetime || addTimer)) {- types.push(["", "---"]); // Empty spacer- }-- if (addDatetime) {- types.push([ConditionType.DATE_TIME, i18next.t(ConditionType.DATE_TIME)]);- }- if (addTimer) {- types.push([ConditionType.TIMER, i18next.t(ConditionType.TIMER)]);- }-- return types;- }-protected get type(): string | undefined {- if (!this.ruleCondition) {- return;- }const assetType = getAssetTypeFromQuery(this.ruleCondition.assets);if (assetType) {@@ -118,15 +175,12 @@ class OrRuleCondition extends LitElement {}protected set type(value: string | undefined) {- if (!this.ruleCondition) {- return;- }if (!value || value === "") {this.ruleCondition.assets = undefined;this.ruleCondition.timer = undefined;this.ruleCondition.datetime = undefined;- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();return;}@@ -135,7 +189,7 @@ class OrRuleCondition extends LitElement {this.ruleCondition.assets = undefined;this.ruleCondition.datetime = undefined;this.ruleCondition.timer = "1h";- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();return;}@@ -146,7 +200,7 @@ class OrRuleCondition extends LitElement {this.ruleCondition.datetime = {predicateType: "datetime"};- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();return;}@@ -160,15 +214,15 @@ class OrRuleCondition extends LitElement {this.ruleCondition.assets = {};}- if (!this.ruleCondition!.assets!.types || this.ruleCondition!.assets!.types.length === 0) {- this.ruleCondition!.assets!.types = [{+ if (!this.ruleCondition.assets!.types || this.ruleCondition.assets!.types.length === 0) {+ this.ruleCondition.assets!.types = [{predicateType: "string",match: AssetQueryMatch.EXACT}];}- this.ruleCondition!.assets!.types[0].value = value;- this.dispatchEvent(new OrRuleChangedEvent());+ this.ruleCondition.assets!.types[0].value = value;+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();}}diff --git a/ui/component/or-rules-editor/src/or-rule-header.ts b/ui/component/or-rules-editor/src/or-rule-header.tsindex 5c7a5ed69..3d2847c2e 100644--- a/ui/component/or-rules-editor/src/or-rule-header.ts+++ b/ui/component/or-rules-editor/src/or-rule-header.ts@@ -6,7 +6,7 @@ import "@openremote/or-icon";import {TenantRuleset} from "@openremote/model";import {headerStyle} from "./style";-import {OrRuleChangedEvent} from "./index";+import {OrRulesEditorRuleChangedEvent, OrRulesEditorRequestSaveEvent} from "./index";@customElement("or-rule-header")class OrRuleHeader extends LitElement {@@ -15,10 +15,10 @@ class OrRuleHeader extends LitElement {return headerStyle;}- @property({type: Object})- public ruleset?: TenantRuleset;+ @property({type: Object, attribute: false})+ public ruleset!: TenantRuleset;- @property({type: Boolean})+ @property({type: Boolean, attribute: false})public saveEnabled: boolean = false;public readonly: boolean = false;@@ -27,22 +27,18 @@ class OrRuleHeader extends LitElement {const value = e.target.value;if (this.ruleset) {this.ruleset.name = value;- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());}}public saveRuleset() {- const event = new CustomEvent("rules:save-ruleset", {- bubbles: true,- composed: true- });- this.dispatchEvent(event);+ this.dispatchEvent(new OrRulesEditorRequestSaveEvent(this.ruleset));}public toggleEnabled() {if (this.ruleset) {this.ruleset.enabled = !this.ruleset.enabled;- this.dispatchEvent(new OrRuleChangedEvent());+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();}}diff --git a/ui/component/or-rules-editor/src/or-rule-list.ts b/ui/component/or-rules-editor/src/or-rule-list.tsindex 19f56d629..14ef8cc8e 100644--- a/ui/component/or-rules-editor/src/or-rule-list.ts+++ b/ui/component/or-rules-editor/src/or-rule-list.ts@@ -1,49 +1,267 @@-import {html, LitElement, property} from "lit-element";-import {TenantRuleset, JsonRule, RuleCondition} from "@openremote/model";-import {ruleListStyle} from "./style";+import {customElement, html, LitElement, property, PropertyValues, query, TemplateResult, css} from "lit-element";+import {JsonRule, RuleCondition, RulesetLang, Tenant, TenantRuleset} from "@openremote/model";+import "@openremote/or-translate";+import manager, {EventCallback, OREvent} from "@openremote/core";import moment from "moment";+import {InputType, OrInputChangedEvent} from "@openremote/or-input";+import {style as OrAssetTreeStyle} from "@openremote/or-asset-tree";+import {+ OrRulesEditorRequestAddEvent,+ OrRulesEditorRequestCopyEvent,+ OrRulesEditorRequestDeleteEvent,+ OrRulesEditorRequestSelectEvent,+ OrRulesEditorSelectionChangedEvent,+ RequestEventDetail,+ RulesetNode+} from "./index";++// language=CSS+const style = css`+ :host {+ overflow: auto;+ flex-grow: 1;+ font-size: var(--internal-or-rules-editor-list-text-size);+ }++ #wrapper[data-disabled] {+ opacity: 0.3;+ pointer-events: none;+ }++ .d-flex {+ display: -webkit-box;+ display: -moz-box;+ display: -ms-flexbox;+ display: -webkit-flex;+ display: flex;+ }++ .flex {+ -webkit-box-flex: 1;+ -moz-box-flex: 1;+ -webkit-flex: 1;+ -ms-flex: 1;+ flex: 1;+ }++ .list-title {+ display: block;+ padding: 30px 30px 5px 20px;+ text-transform: uppercase;+ /*color: var(, #808080);*/+ font-size:14px;+ font-weight: bold;+ text-align: left;+ }++ .list-item {+ text-decoration: none;+ padding: 13px 15px;+ border-left: 5px solid transparent;+ cursor: pointer;+ transition: all 200ms ease-in;+ opacity: 0.8;+ }++ .list-item:hover {+ border-left-color: var(--internal-or-rules-editor-list-selected-color);+ background-color: var(--internal-or-rules-editor-list-selected-color);+ }++ .list-item[selected] {+ border-left-color: var(--internal-or-rules-editor-button-color);+ background-color: var(--internal-or-rules-editor-list-selected-color);+ opacity: 1;+ }++ .list-item > span {+ width: 8px;+ height: 8px;+ border-radius: 8px;+ margin: 6px 10px 0 0;+ }++ .bg-green {+ background-color: #28b328;+ }++ .bg-red {+ background-color: red+ }++ .bg-blue {+ background-color: #3e92dc;+ }++ .bg-grey {+ background-color: #b7b7b7;+ }+`;++@customElement("or-rule-list")+export class OrRulesList extends LitElement {++ @property({type: String})+ public realm?: string;++ @property({type: Boolean})+ public disabled: boolean = false;++ @property({type: Boolean})+ public multiSelect: boolean = true;-class OrRulesList extends LitElement {@property({type: Array})- public rulesets: TenantRuleset[] = [];+ public selectedIds?: number[];++ @property({type: String})+ public sortBy?: string;++ @property({attribute: false})+ protected _realms?: Tenant[];++ @property({attribute: false})+ protected _nodes?: RulesetNode[];++ @property()+ protected _showLoading: boolean = true;++ @query("#sort-menu")+ protected _sortMenu!: HTMLDivElement;- @property({type: Object})- public ruleset?: TenantRuleset;+ protected _selectedNodes: RulesetNode[] = [];+ protected _initCallback?: EventCallback;+ protected _ready = false;static get styles() {- return ruleListStyle;+ return [+ OrAssetTreeStyle,+ style+ ];}- public setActiveRule(ruleset: TenantRuleset) {- const event = new CustomEvent("rules:set-active-rule", {- detail: {ruleset: JSON.parse(JSON.stringify(ruleset))},- bubbles: true,- composed: true+ public refresh() {+ this._nodes = undefined;+ }++ protected _onReady() {+ this._ready = true;+ this._loadRealms();+ this._loadRulesets();+ }++ protected firstUpdated(_changedProperties: PropertyValues): void {+ super.firstUpdated(_changedProperties);++ if (!manager.ready) {+ // Defer until openremote is initialised+ this._initCallback = (initEvent: OREvent) => {+ if (initEvent === OREvent.READY) {+ this._onReady();+ manager.removeListener(this._initCallback!);+ }+ };+ manager.addListener(this._initCallback);+ } else {+ this._onReady();+ }++ this.addEventListener("click", (evt) => {+ if (this._sortMenu.hasAttribute("data-visible") && !this._sortMenu.contains(evt.target as Node)) {+ this._sortMenu.toggleAttribute("data-visible");+ }});- this.dispatchEvent(event);+ }++ protected shouldUpdate(_changedProperties: PropertyValues): boolean {+ const result = super.shouldUpdate(_changedProperties);++ if (manager.ready) {+ if (_changedProperties.has("realm")) {+ this._nodes = undefined;+ }++ if (!this._nodes) {+ this._loadRulesets();+ return true;+ }++ if (_changedProperties.has("selectedIds")) {+ this._updateSelectedNodes();+ }++ if (_changedProperties.has("sortBy")) {+ OrRulesList._updateSort(this._nodes!, this._getSortFunction());+ }+ }++ return result;}protected render() {return html`- <div class="list-container">- <strong class="list-title">Profielen</strong>- ${this.rulesets && this.rulesets.map((ruleset: TenantRuleset, index: number) => {- return html`- <a ?selected="${this.ruleset && ruleset.id === this.ruleset.id}" class="d-flex list-item" @click="${() => this.setActiveRule(this.rulesets[index])}">- <span class="${this.checkRuleStatus(ruleset)}"></span>- <div class="flex">- <span>${ruleset.name}<span>${!ruleset.id ? " [concept]" : ""}</span></span>+ <div id="wrapper" ?data-disabled="${this.disabled}">+ <div id="header">+ <div id="title-container">+ <or-translate id="title" value="rule_plural"></or-translate>+ ${manager.isSuperUser() ? html `<or-input id="realm-picker" type="${InputType.SELECT}" .value="${this._getRealm()}" .options="${this._realms ? this._realms.map((tenant) => [tenant.realm, tenant.displayName]) : []}" @or-input-changed="${(evt: OrInputChangedEvent) => this._onRealmChanged(evt)}"></or-input>` : ``}+ </div>++ <div id="header-btns">++ <button style="display:none;" ?hidden="${!manager.hasRole("write:rules") || !this.selectedIds || this.selectedIds.length === 0}" @click="${() => this._onCopyClicked()}"><or-icon icon="content-copy"></or-icon></button>+ <button ?hidden="${!manager.hasRole("write:rules") || !this.selectedIds || this.selectedIds.length === 0}" @click="${() => this._onDeleteClicked()}"><or-icon icon="delete"></or-icon></button>+ <button ?hidden="${!manager.hasRole("write:rules")}" @click="${() => this._onAddClicked()}"><or-icon icon="plus"></or-icon></button>+ <button hidden @click="${() => this._onSearchClicked()}"><or-icon icon="magnify"></or-icon></button>+ <button @click="${() => this._onSortClicked()}"><or-icon icon="sort-variant"></or-icon></button>+ <div class="modal-container">+ <div class="modal" id="sort-menu">+ <div class="modal-content">+ <ul>+ <li @click="${() => this.sortBy = "name"}" ?data-selected="${!this.sortBy || this.sortBy === "name"}"><or-icon icon="check"></or-icon><or-translate value="name"></or-translate></li>+ <li @click="${() => this.sortBy = "created"}" ?data-selected="${this.sortBy === "created"}"><or-icon icon="check"></or-icon><or-translate value="creationDate"></or-translate></li>+ </ul>+ </div></div>- </a>- `;- })}+ </div>+ </div>+ </div>++ ${!this._nodes || this._showLoading+ ? html`+ <span id="loading">LOADING</span>`+ : html`+ <div id="list-container">+ <ol id="list">+ ${this._nodes.map((treeNode) => this._nodeTemplate(treeNode))}+ </ol>+ </div>+ `+ }++ <div id="footer">++ </div></div>`;}+ protected _nodeTemplate(node: RulesetNode): TemplateResult | string {+ return html`+ <li ?data-selected="${node.selected}" @click="${(evt: MouseEvent) => this._onNodeClicked(evt, node)}">+ <div class="node-container">+ <div class="node-name">+ <span class="${OrRulesList._getNodeStatusClasses(node.ruleset)}"></span>+ <div class="flex">+ <span>${node.ruleset.name}</span>+ </div>+ </div>+ </div>+ </li>+ `;+ }- checkRuleStatus(ruleset: TenantRuleset){+ protected static _getNodeStatusClasses(ruleset: TenantRuleset): string {let status = ruleset.enabled ? "bg-green" : "bg-red";if(ruleset.rules && ruleset.enabled) {@@ -70,9 +288,178 @@ class OrRulesList extends LitElement {}return status;+ }+ protected _loadRealms() {+ if (manager.isSuperUser()) {+ manager.rest.api.TenantResource.getAll().then((response) => {+ this._realms = response.data;+ });+ }}-}+ protected _updateSelectedNodes() {+ const actuallySelectedIds: number[] = [];+ const selectedNodes: RulesetNode[] = [];+ if (this._nodes) {+ this._nodes.forEach((node) => {+ if (this.selectedIds && this.selectedIds.indexOf(node.ruleset!.id!) >= 0) {+ actuallySelectedIds.push(node.ruleset!.id!);+ selectedNodes.push(node);+ node.selected = true;+ } else {+ node.selected = false;+ }+ });+ }-window.customElements.define("or-rule-list", OrRulesList);+ this.selectedIds = actuallySelectedIds;+ this._selectedNodes = selectedNodes;+ this.dispatchEvent(new OrRulesEditorSelectionChangedEvent(this._selectedNodes.map((node) => node.ruleset)));+ }++ protected static _updateSort(nodes: RulesetNode[], sortFunction: (a: RulesetNode, b: RulesetNode) => number) {+ if (!nodes) {+ return;+ }++ nodes.sort(sortFunction);+ }++ protected _onNodeClicked(evt: MouseEvent, node: RulesetNode) {+ if (evt.defaultPrevented) {+ return;+ }++ evt.preventDefault();++ let selectRulesets = this._selectedNodes.map((node) => node.ruleset);+ const index = selectRulesets.findIndex((ruleset) => ruleset.id === node.ruleset.id);+ let select = true;+ let deselectOthers = true;++ if (this.multiSelect) {+ if (evt.ctrlKey || evt.metaKey) {+ deselectOthers = false;+ if (index >= 0 && selectRulesets.length > 1) {+ select = false;+ }+ }+ }++ if (deselectOthers) {+ selectRulesets = [node.ruleset];+ } else if (select) {+ if (index < 0) {+ selectRulesets.push(node.ruleset);+ }+ } else {+ if (index >= 0) {+ selectRulesets.splice(index, 1);+ selectRulesets = [...selectRulesets];+ }+ }++ this._doRequest(new OrRulesEditorRequestSelectEvent(selectRulesets), (detail) => {+ this.selectedIds = detail.map((ruleset) => ruleset.id!);+ });+ }++ protected _onCopyClicked() {+ if (this._selectedNodes.length == 1) {+ this.dispatchEvent(new OrRulesEditorRequestCopyEvent(this._selectedNodes[0].ruleset));+ }+ }++ protected _onDeleteClicked() {+ if (this._selectedNodes.length > 0) {+ this.dispatchEvent(new OrRulesEditorRequestDeleteEvent(this._selectedNodes.map((node) => node.ruleset)));+ }+ }++ protected _onAddClicked() {+ this.dispatchEvent(new OrRulesEditorRequestAddEvent());+ }++ protected _onSearchClicked() {++ }++ protected _onSortClicked() {+ // Do open on next task to prevent click handler closing it immediately+ if (!this._sortMenu.hasAttribute("data-visible")) {+ window.setTimeout(() => {+ this._sortMenu.toggleAttribute("data-visible");+ });+ }+ }++ protected _getSortFunction(): (a: RulesetNode, b: RulesetNode) => number {++ const nameSort = (a: RulesetNode, b: RulesetNode) => { return a.ruleset!.name! < b.ruleset!.name! ? -1 : a.ruleset!.name! > b.ruleset!.name! ? 1 : 0 };++ if (this.sortBy === "created") {+ return (a, b) => { return a.ruleset!.createdOn! < b.ruleset!.createdOn! ? -1 : a.ruleset!.createdOn! > b.ruleset!.createdOn! ? 1 : nameSort(a, b) };+ }++ return nameSort;+ }++ protected _getRealm(): string | undefined {+ if (manager.isSuperUser() && this.realm) {+ return this.realm;+ }++ return manager.getRealm();+ }++ protected _onRealmChanged(evt: OrInputChangedEvent) {+ this.realm = evt.detail.value;+ }++ protected _doRequest<T>(event: CustomEvent<RequestEventDetail<T>>, handler: (detail: T) => void) {+ this.dispatchEvent(event);+ window.setTimeout(() => {+ if (event.detail.allow) {+ handler(event.detail.detail);+ }+ })+ }++ protected _loadRulesets() {++ const sortFunction = this._getSortFunction();++ manager.rest.api.RulesResource.getTenantRulesets(manager.config.realm, {+ language: RulesetLang.JSON,+ fullyPopulate: true+ }).then((response: any) => {+ if (response && response.data) {+ this._buildTreeNodes(response.data, sortFunction);+ }+ }).catch((reason: any) => {+ console.error("Error: " + reason);+ });+ }++ protected _buildTreeNodes(rulesets: TenantRuleset[], sortFunction: (a: RulesetNode, b: RulesetNode) => number) {+ if (!rulesets || rulesets.length === 0) {+ this._nodes = [];+ } else {++ let nodes = rulesets.map((ruleset) => {+ return {+ ruleset: ruleset+ } as RulesetNode;+ });++ nodes.sort(sortFunction);++ this._nodes = nodes;+ }+ if (this.selectedIds && this.selectedIds.length > 0) {+ this._updateSelectedNodes();+ }+ this._showLoading = false;+ }+}\ No newline at end of filediff --git a/ui/component/or-rules-editor/src/or-rule-section.ts b/ui/component/or-rules-editor/src/or-rule-section.tsdeleted file mode 100644index 8e470fff3..000000000--- a/ui/component/or-rules-editor/src/or-rule-section.ts+++ /dev/null@@ -1,22 +0,0 @@-import {html, property, LitElement, customElement} from "lit-element";-import {ruleSectionStyle} from "./style";--@customElement("or-rule-section")-class OrRuleSection extends LitElement {-- @property({type: String})- public heading?: string;-- static get styles() {- return ruleSectionStyle;- }-- public render() {- return html`- <div>- <strong>${this.heading}</strong>- <slot></slot>- </div>- `;- }-}\ No newline at end of filediff --git a/ui/component/or-rules-editor/src/or-rule-then-otherwise.ts b/ui/component/or-rules-editor/src/or-rule-then-otherwise.tsnew file mode 100644index 000000000..9eeebddd8--- /dev/null+++ b/ui/component/or-rules-editor/src/or-rule-then-otherwise.ts@@ -0,0 +1,325 @@+import {css, customElement, html, LitElement, property, TemplateResult} from "lit-element";+import {buttonStyle} from "./style";+import "./or-rule-asset-query";+import {+ ActionType,+ getAssetTypeFromQuery,+ getButtonWithMenuTemplate,+ OrRulesEditorRuleChangedEvent,+ RulesConfig+} from "./index";+import {AssetDescriptor, JsonRule, RuleActionUnion} from "@openremote/model";+import i18next from "i18next";+import {InputType} from "@openremote/or-input";+import {Menu, MenuItem} from "@openremote/or-mwc-components/dist/or-mwc-menu";+import {getAssetDescriptorIconTemplate} from "@openremote/or-icon";+import {AssetModelUtil} from "@openremote/core";+import "./or-rule-action-attribute";++const NOTIFICATION_COLOR = "4B87EA";+const WAIT_COLOR = "EACC54";++function getActionTypesMenu(config?: RulesConfig, assetDescriptors?: AssetDescriptor[]): Menu {++ let addAssetTypes = true;+ let addWait = true;+ let addNotification = true;++ if (config && config.controls && config.controls.allowedActionTypes) {+ addAssetTypes = config.controls.allowedActionTypes.indexOf(ActionType.ATTRIBUTE) >= 0;+ addWait = config.controls.allowedActionTypes.indexOf(ActionType.WAIT) >= 0;+ addNotification = config.controls.allowedActionTypes.indexOf(ActionType.NOTIFICATION) >= 0;+ }++ const menu: Menu = {+ items: []+ };++ if (addAssetTypes && assetDescriptors) {+ menu.items.push(...assetDescriptors.map((ad) => {+ const content = html`+ ${getAssetDescriptorIconTemplate(ad)}+ <span style="white-space: nowrap; text-transform: capitalize">${i18next.t(ad.name!, {defaultValue: ad.name!.replace(/_/g, " ").toLowerCase()})}</span>+ `;+ return {content: content, value: ad.type} as MenuItem+ }));+ }++ if (addNotification) {+ const content = html`+ <or-icon style="--or-icon-fill: #${NOTIFICATION_COLOR}" icon="email"></or-icon>+ <span style="text-transform: capitalize"> <or-translate value="notification"></or-translate></span>+ `;+ menu.items.push({content: content, value: ActionType.NOTIFICATION} as MenuItem);+ }++ if (addWait) {+ const content = html`+ <or-icon style="--or-icon-fill: #${WAIT_COLOR}" icon="timer"></or-icon>+ <span style="text-transform: capitalize"> <or-translate value="wait"></or-translate></span>+ `;+ menu.items.push({content: content, value: ActionType.WAIT} as MenuItem);+ }++ return menu;+}++// language=CSS+const style = css`++ :host {+ display: flex;+ width: 100%;+ flex-direction: column;+ }++ ${buttonStyle}++ .rule-action {+ display: flex;+ margin: 10px 0;+ }++ .rule-action-action {+ flex-grow: 1;+ }++ .rule-action-action > * {+ margin-right: 20px;+ }++ .rule-action > button {+ flex-grow: 0;+ }++ or-panel {+ margin: 20px;+ }++ #type-selector {+ margin-top: 10px;+ }+`;++@customElement("or-rule-then-otherwise")+class OrRuleThenOtherwise extends LitElement {++ static get styles() {+ return style;+ }++ @property({type: Object, attribute: false})+ public rule!: JsonRule;++ public readonly?: boolean;++ public config?: RulesConfig;++ public assetDescriptors?: AssetDescriptor[];++ protected get thenAllowAdd() {+ return !this.config || !this.config.controls || this.config.controls.hideThenAddAction !== true;+ }++ protected ruleActionTemplate(actions: RuleActionUnion[], action: RuleActionUnion) {++ const showTypeSelect = !this.config || !this.config.controls || this.config.controls.hideActionTypeOptions !== true;+ const type = this.getActionType(action);++ if (!type && !showTypeSelect) {+ return html`<span>INVALID CONFIG - NO TYPE SPECIFIED AND TYPE SELECTOR DISABLED</span>`;+ }++ let typeTemplate: TemplateResult | string = ``;+ let template: TemplateResult | string = ``;+ const thenAllowRemove = !this.readonly && (this.thenAllowAdd || this.rule.then!.length > 1);++ if (showTypeSelect) {++ let buttonIcon = undefined;+ let buttonColor = "inherit";++ if (action.action) {+ switch (action.action as ActionType) {+ case ActionType.WAIT:+ buttonIcon = "timer";+ buttonColor = WAIT_COLOR;+ break;+ case ActionType.NOTIFICATION:+ buttonIcon = "email";+ buttonColor = NOTIFICATION_COLOR;+ break;+ default:+ const ad = AssetModelUtil.getAssetDescriptor(type);+ buttonIcon = AssetModelUtil.getAssetDescriptorIcon(ad) || buttonIcon;+ buttonColor = AssetModelUtil.getAssetDescriptorColor(ad) || buttonColor;+ break;+ }+ }++ typeTemplate = html`+ <div style="display: table; height: 100%; --or-input-color: #${buttonColor}">+ ${getButtonWithMenuTemplate(getActionTypesMenu(this.config, this.assetDescriptors), buttonIcon || "", action.action, (value: string) => this.setActionType(actions, action, value))}+ </div>+ `;+ }++ if (type) {+ switch (type) {+ case ActionType.WAIT:+ template = html`<span>WAIT NOT IMPLEMENTED</span>`;+ break;+ case ActionType.NOTIFICATION:+ template = html`<span>NOTIFICATION NOT IMPLEMENTED</span>`;+ break;+ default:+ template = html`<or-rule-action-attribute .action="${action}" .config="${this.config}" .assetDescriptors="${this.assetDescriptors}" .readonly="${this.readonly}"></or-rule-action-attribute>`;+ break;+ }+ }++ return html`+ <div class="rule-action">+ ${typeTemplate}+ ${template}+ ${thenAllowRemove ? html`+ <button class="button-clear" @click="${() => this.removeAction(action)}"><or-icon icon="close-circle"></or-icon></input>+ ` : ``}+ </div>+ `;+ }++ protected render() {++ return html`+ <div>+ <or-panel .heading="${i18next.t("then")}...">+ ${!this.rule.then ? `` : this.rule.then.map((action: RuleActionUnion) => this.ruleActionTemplate(this.rule.then!, action))}++ ${this.thenAllowAdd ? html`+ <or-input type="${InputType.BUTTON}" .label="${i18next.t("rulesEditorAddAction")}" @click="${() => this.addAction()}"></or-input>+ ` : ``}+ </or-panel>+ </div>+ `;+ }++ protected getActionType(action: RuleActionUnion): string | undefined {++ switch (action.action) {+ case "wait":+ break;+ case "notification":+ break;+ case "write-attribute":+ case "update-attribute":+ if (!action.target) {+ return;+ }+ if (action.target.matchedAssets) {+ return getAssetTypeFromQuery(action.target.matchedAssets);+ }+ if (action.target.assets) {+ return getAssetTypeFromQuery(action.target.assets);+ }+ break;+ }+ }++ protected setActionType(actions: RuleActionUnion[], action: RuleActionUnion, value: string) {++ action.target = undefined;++ switch (action.action) {+ case "wait":+ action.millis = undefined;+ break;+ case "write-attribute":+ action.value = undefined;+ action.attributeName = undefined;+ break;+ case "notification":+ action.notification = undefined;+ break;+ case "update-attribute":+ action.value = undefined;+ action.attributeName = undefined;+ action.index = undefined;+ action.key = undefined;+ action.updateAction = undefined;+ break;+ }++ if (value === ActionType.WAIT) {+ action.action = "wait";+ } else if (value === ActionType.NOTIFICATION) {+ action.action = "notification";+ } else {+ action.action = "write-attribute";+ action.target = {+ matchedAssets: {+ types: [+ {+ predicateType: "string",+ value: value+ }+ ]+ }+ }+ }++ const index = actions.indexOf(action);+ actions[index] = {...action};++ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());+ this.requestUpdate();+ }++ protected removeAction(action?: RuleActionUnion) {+ if (!this.rule || !this.rule.then || !action) {+ return;+ }++ const index = this.rule.then.indexOf(action);+ if (index >= 0) {+ this.rule.then.splice(index, 1);+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());+ this.requestUpdate();+ }+ }++ protected addAction(otherwise?: boolean) {++ if (!this.rule) {+ return;+ }++ let actionArray: RuleActionUnion[];+ let newAction: RuleActionUnion = {+ action: "write-attribute"+ };+ let template: RuleActionUnion | undefined;++ if (!otherwise) {+ if (!this.rule.then) {+ this.rule.then = [];+ }+ actionArray = this.rule.then;+ template = this.config && this.config.templates && this.config.templates.then ? this.config.templates.then : undefined;+ } else {+ if (!this.rule.otherwise) {+ this.rule.otherwise = [];+ }+ actionArray = this.rule.otherwise;+ template = this.config && this.config.templates && this.config.templates.otherwise ? this.config.templates.otherwise : undefined;+ }++ if (template) {+ newAction = JSON.parse(JSON.stringify(template)) as RuleActionUnion;+ }++ actionArray.push(newAction);+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());+ this.requestUpdate();+ }+}diff --git a/ui/component/or-rules-editor/src/or-rule-when.ts b/ui/component/or-rules-editor/src/or-rule-when.tsindex c1943f80f..74a8520a2 100644--- a/ui/component/or-rules-editor/src/or-rule-when.ts+++ b/ui/component/or-rules-editor/src/or-rule-when.ts@@ -1,15 +1,75 @@-import {customElement, html, LitElement, TemplateResult, property} from "lit-element";-import {LogicGroup, JsonRule, RuleCondition, AssetDescriptor, LogicGroupOperator} from "@openremote/model";-import {OrRuleChangedEvent, RulesConfig} from "./index";-import {whenStyle} from "./style";+import {css, customElement, html, LitElement, property, PropertyValues, TemplateResult} from "lit-element";+import {AssetDescriptor, JsonRule, LogicGroup, LogicGroupOperator, RuleCondition, AssetType} from "@openremote/model";+import {OrRulesEditorRuleChangedEvent, RulesConfig} from "./index";+import {buttonStyle} from "./style";import "./or-rule-condition";import i18next from "i18next";+import {InputType} from "@openremote/or-input";++// language=CSS+const style = css`++ :host {+ display: block;+ }++ ${buttonStyle}++ .rule-group-items {+ display: flex;+ flex-direction: column;+ }++ .rule-group .rule-group-items > div {+ margin: 10px 0;+ }++ .rule-condition {+ display: flex;+ padding-right: 5px;+ }++ .rule-condition > * {+ flex-grow: 0;+ }++ .rule-condition > or-rule-condition {+ flex-grow: 1;+ }++ or-rule-condition {+ margin: 10px 0;+ }++ .rule-group-item > or-icon {+ padding-left: 17px;+ }++ or-icon.small {+ --or-icon-width: 14px;+ --or-icon-height: 14px;+ }++ or-panel {+ margin: 20px;+ position: relative;+ }++ or-panel > .remove-button {+ position: absolute;+ right: 0;+ top: 0;+ width: 24px;+ height: 24px;+ transform: translate(50%, -50%);+ }+`;@customElement("or-rule-when")class OrRuleWhen extends LitElement {static get styles() {- return whenStyle;+ return style;}@property({type: Object})@@ -22,58 +82,100 @@ class OrRuleWhen extends LitElement {public assetDescriptors?: AssetDescriptor[];protected ruleGroupTemplate(group: LogicGroup<RuleCondition>, parentGroup?: LogicGroup<RuleCondition>): TemplateResult | undefined {+if (!group) {return html``;}- const hasItems = (group.items && group.items.length > 0) || (group.groups && group.groups.length > 0);- const showGroupOutline = !this.config || !this.config.controls || this.config.controls.hideWhenGroupOutline !== true;+ const isTopLevel = !parentGroup;const showAddCondition = !this.readonly && (!this.config || !this.config.controls || this.config.controls.hideWhenAddCondition !== true);const showRemoveCondition = !this.readonly && group.items && group.items.length > 1;- const showAddGroup = !this.readonly && (!this.config || !this.config.controls || this.config.controls.hideWhenAddGroup !== true);const showRemoveGroup = !this.readonly;+ const showAddGroup = !this.readonly && (!this.config || !this.config.controls || this.config.controls.hideWhenAddGroup !== true);- return html`- <div class="rule-group ${showGroupOutline ? "visible" : "hidden"}">- ${showRemoveGroup ? html`- <button class="button-clear remove-button" @click="${() => this.removeGroup(group)}">- <div></div>- <or-icon icon="close-circle"></or-icon>- </button>- ` : ``}-- <div class="rule-group-items">- ${group.items && group.items.length > 0 ? group.items.map((condition: RuleCondition) => {- return html `- <div class="rule-group-item">- <button @click="${() => this.toggleGroup(group)}" class="button-clear operator"><span>${i18next.t(!group.operator || group.operator === LogicGroupOperator.AND ? "and" : "or")}</span></button>- <div class="rule-condition">- <or-rule-condition .config="${this.config}" .assetDescriptors="${this.assetDescriptors}" .ruleCondition="${condition}" .readonly="${this.readonly}" ></or-rule-condition>- ${showRemoveCondition ? html`- <button class="button-clear" @click="${() => this.removeCondition(condition)}"><or-icon icon="close-circle"></or-icon></input>- ` : ``}- </div>- </div>- `;- }) : ``}-- ${group.groups && group.groups.length > 0 ? html`- ${group.groups.map((childGroup: LogicGroup<RuleCondition>) => html`- <div class="rule-group-item">- <button @click="${() => this.toggleGroup(group)}" class="button-clear operator"><span>${i18next.t(!group.operator || group.operator === LogicGroupOperator.AND ? "and" : "or")}</span></button>- ${this.ruleGroupTemplate(childGroup, group)}- </div>- `)}+ let wrapper: (content: TemplateResult, item: LogicGroup<RuleCondition> | RuleCondition, parent: LogicGroup<RuleCondition>, isGroup: boolean, isFirst: boolean) => TemplateResult;++ if (isTopLevel) {+ wrapper = (content, item, parent, isGroup, isFirst) => {+ return html`+ <or-panel .heading="${i18next.t(isFirst ? "when": "orWhen")}...">+ ${showRemoveGroup ? html`+ <button class="button-clear remove-button" @click="${() => this.removeItem(item, parent, isGroup)}">+ <or-icon icon="close-circle"></or-icon>+ </button>+ ` : ``}+ ${content}+ </or-panel>`;+ };+ } else {+ wrapper = (content, item, parent, isGroup, isFirst) => {+ return html`+ ${!isFirst ? html`+ <or-icon class="small" icon="ampersand"></or-icon>` : ``}- </div>-- ${showAddCondition || showAddGroup ? html`- <div class="add-buttons-container ${hasItems ? "" : "hidden"}">- ${showAddCondition ? html`<button class="button-clear add-button" @click="${() => this.addCondition(group)}"><or-icon icon="plus-circle"></or-icon><or-translate value="rulesEditorAddCondition"></or-translate></button>` : ``}- ${showAddGroup ? html`<button class="button-clear add-button" @click="${() => this.addGroup(group)}"><or-icon icon="plus-circle"></or-icon><or-translate value="rulesEditorAddGroup"></or-translate></button>` : ``}- </div>- ` : ``}- </div>+ ${content}+ `;+ return content;+ }+ }++ let groupsTemplate: TemplateResult | string = ``;+ let itemsTemplate: TemplateResult | string = ``;+ let addTemplate: TemplateResult | string = ``;+ let isFirst = true;++ if (group.groups && group.groups.length > 0) {+ groupsTemplate = html`+ ${group.groups.map((childGroup: LogicGroup<RuleCondition>, index) => {+ const content = html`+ <div class="rule-group-item">+ ${this.ruleGroupTemplate(childGroup, group)}+ </div>+ `;+ return wrapper(content, childGroup, group, true, index == 0);+ })}+ `;+ isFirst = false;+ }++ if (group.items && group.items.length > 0) {+ itemsTemplate = html`+ ${group.items.map((condition: RuleCondition, index) => {+ const content = html`+ <div class="rule-group-item">+ <div class="rule-condition">+ <or-rule-condition .config="${this.config}" .assetDescriptors="${this.assetDescriptors}" .ruleCondition="${condition}" .readonly="${this.readonly}" ></or-rule-condition>+ ${showRemoveCondition ? html`+ <button class="button-clear" @click="${() => this.removeItem(condition, group, false)}"><or-icon icon="close-circle"></or-icon></input>+ ` : ``}+ </div>+ </div>+ `;+ return wrapper(content, condition, group, true, isFirst && index == 0);+ })}+ `;+ isFirst = false;+ }++ if (isTopLevel && showAddGroup) {+ addTemplate = html`+ <or-panel>+ <or-input type="${InputType.BUTTON}" icon="plus" @click="${() => this.addGroup(group)}"></or-input>+ <strong>${i18next.t(isFirst ? "when": "orWhen")}...</strong>+ </or-panel>+ `;+ }++ if (!isTopLevel && showAddCondition) {+ addTemplate = html`+ <or-input type="${InputType.BUTTON}" .label="${i18next.t("rulesEditorAddCondition")}" @click="${() => this.addCondition(group)}"></or-input>+ `;+ }++ return html`+ ${groupsTemplate}+ ${itemsTemplate}+ ${addTemplate}`;}@@ -81,157 +183,157 @@ class OrRuleWhen extends LitElement {return html`<span>DATE TIME PREDICATE NOT IMPLEMENTED</span>`;}- protected render() {- if (!this.rule) {- return html``;- }-- if (!this.rule.when) {- this.rule.when = {};+ protected shouldUpdate(_changedProperties: PropertyValues): boolean {+ if (_changedProperties.has("rule")) {+ if (this.rule) {+ if (!this.rule.when) {+ this.rule.when = {+ operator: LogicGroupOperator.OR+ };+ } else {+ // Check this is a rule compatible with this editor+ if (!OrRuleWhen._isRuleWhenCompatible(this.rule.when)) {+ this.rule = undefined;+ }+ }+ }}- return this.ruleGroupTemplate(this.rule.when);+ return super.shouldUpdate(_changedProperties);}- private toggleGroup(group: LogicGroup<RuleCondition>) {- if (group.operator === LogicGroupOperator.OR) {- group.operator = LogicGroupOperator.AND;- } else {- group.operator = LogicGroupOperator.OR;+ protected render() {+ if (!this.rule || !this.rule.when) {+ return html``;}- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();++ return html`+ <div>+ ${this.ruleGroupTemplate(this.rule.when!)}+ </div>+ `;}- private addGroup(parent: JsonRule | LogicGroup<RuleCondition>) {- if (!parent) {- return;+ /**+ * Currently only support a top level OR group and then N child AND groups with no more descendants+ */+ protected static _isRuleWhenCompatible(when: LogicGroup<RuleCondition>): boolean {+ if (when.operator !== LogicGroupOperator.OR) {+ console.warn("Incompatible rule: when operator not set to 'OR'");+ return false;}- let newGroup: LogicGroup<RuleCondition> = {};-- if (this.config && this.config.templates && this.config.templates.whenGroup) {- newGroup = JSON.parse(JSON.stringify(this.config.templates.whenGroup)) as LogicGroup<RuleCondition>;+ if (when.items && when.items.length > 0) {+ console.warn("Incompatible rule: when items not supported");+ return false;}- if ((parent as JsonRule).name !== undefined) {- const rule = parent as JsonRule;- rule.when = newGroup;- } else {- const condition = parent as LogicGroup<RuleCondition>;- if (!condition.groups) {- condition.groups = [];- }- condition.groups.push(newGroup);+ if (when.groups && when.groups.find((g) => !this._isWhenGroupCompatible(g))) {+ console.warn("Incompatible rule: when groups incompatible");+ return false;}- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();+ return true;}- private removeGroup(group: LogicGroup<RuleCondition>) {- if (!this.rule || !this.rule.when || !group) {- return;+ protected static _isWhenGroupCompatible(group: LogicGroup<RuleCondition>): boolean {+ if (group.operator === LogicGroupOperator.OR) {+ console.warn("Incompatible rule: when group operator not set to 'AND'");+ return false;}- if (this.rule.when === group) {- this.rule.when = undefined;- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();- return;+ if (group.groups && group.groups.length > 0) {+ console.warn("Incompatible rule: when group nested groups not supported");+ return false;}- const parent = this.getGroupParent(group, this.rule.when);- if (parent) {- const index = parent.groups!.indexOf(group);- parent.groups!.splice(index, 1);- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();- }+ return true;}- private addCondition(parent: LogicGroup<RuleCondition>) {- if (!parent) {+ private addGroup(parent: LogicGroup<RuleCondition>) {+ if (!this.rule || !this.rule.when || parent !== this.rule.when) {return;}- if (!parent.items) {- parent.items = [];+ let newGroup: LogicGroup<RuleCondition> = {};++ if (this.config && this.config.templates && this.config.templates.whenGroup) {+ newGroup = JSON.parse(JSON.stringify(this.config.templates.whenGroup)) as LogicGroup<RuleCondition>;}- let newTrigger: RuleCondition = {};+ // Force to AND as this is what the editor supports+ newGroup.operator = LogicGroupOperator.AND;- if (this.config && this.config.templates && this.config.templates.whenCondition) {- newTrigger = JSON.parse(JSON.stringify(this.config.templates.whenCondition)) as RuleCondition;+ // Clear any child groups+ newGroup.groups = undefined;++ // Add an item if none exist+ if (!newGroup.items || newGroup.items!.length === 0) {+ this.addCondition(newGroup, true);}- parent.items.push(newTrigger);- this.dispatchEvent(new OrRuleChangedEvent());+ const group = parent as LogicGroup<RuleCondition>;+ if (!group.groups) {+ group.groups = [];+ }+ group.groups.push(newGroup);++ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();}- private removeCondition(condition: RuleCondition) {- if (!this.rule || !this.rule.when || !condition) {- return;- }+ private removeItem(item: LogicGroup<RuleCondition> | RuleCondition, parent: LogicGroup<RuleCondition>, isGroup: boolean) {- const parent = this.getConditionParent(condition, this.rule.when);+ let removed = false;if (parent) {- const index = parent.items!.indexOf(condition);- parent.items!.splice(index, 1);- this.dispatchEvent(new OrRuleChangedEvent());- this.requestUpdate();- }- }-- private getConditionParent(condition: RuleCondition, start: LogicGroup<RuleCondition>) {- if (!condition || !start) {- return;- }-- if (start.items) {- const index = start.items.indexOf(condition);- if (index >= 0) {- return start;+ if (isGroup) {+ const index = parent.groups!.indexOf(item as LogicGroup<RuleCondition>);+ parent.groups!.splice(index, 1);+ removed = index >= 0;+ } else {+ const index = parent.items!.indexOf(item as RuleCondition);+ parent.items!.splice(index, 1);+ removed = index >= 0;}- }- if (start.groups) {- for (const group of start.groups) {- const result = this.getConditionParent(condition, group);- if (result) {- return group;- }+ if (removed) {+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());+ this.requestUpdate();}}}- private getGroupParent(group: LogicGroup<RuleCondition>, start: LogicGroup<RuleCondition>) {- if (!group || !start || !start.groups) {+ private addCondition(parent: LogicGroup<RuleCondition>, silent?: boolean) {+ if (!parent) {return;}- const index = start.groups.indexOf(group);- if (index >= 0) {- return start;+ if (!parent.items) {+ parent.items = [];}- for (const childGroup of start.groups) {- const result = this.getGroupParent(group, childGroup);- if (result) {- return childGroup;- }- }- }+ let newTrigger: RuleCondition = {};- private deleteWhenCondition(e: any) {+ if (this.config && this.config.templates && this.config.templates.whenCondition) {+ newTrigger = JSON.parse(JSON.stringify(this.config.templates.whenCondition)) as RuleCondition;+ }- const index = e.detail.index;+ // Populate the condition with something to help the UI+ if (!newTrigger.timer && !newTrigger.datetime && !newTrigger.assets) {+ newTrigger.assets = {+ types: [+ {+ predicateType: "string",+ value: AssetType.THING.type+ }+ ]+ };+ }- if (this.rule && this.rule.when && this.rule.when.items && this.rule.when.items.length > 0 && this.rule.when.items[0].assets && this.rule.when.items[0].assets.attributes && this.rule.when.items[0].assets.attributes.items) {- this.rule.when.items[0].assets.attributes.items.splice(index, 1);- this.dispatchEvent(new OrRuleChangedEvent());+ parent.items.push(newTrigger);+ if (!silent) {+ this.dispatchEvent(new OrRulesEditorRuleChangedEvent());this.requestUpdate();}}diff --git a/ui/component/or-rules-editor/src/style.ts b/ui/component/or-rules-editor/src/style.tsindex 627d4e683..e61e9580b 100644--- a/ui/component/or-rules-editor/src/style.ts+++ b/ui/component/or-rules-editor/src/style.ts@@ -1,113 +1,6 @@import {css, unsafeCSS} from "lit-element";import {DefaultColor1, DefaultColor2, DefaultColor5, DefaultColor3, DefaultBoxShadow, DefaultColor4, DefaultColor6, DefaultDisabledOpacity} from "@openremote/core";-// language=CSS-export const rulesEditorStyle = css`-- :host {- display: flex;- height: 100%;- width: 100%;-- --internal-or-rules-editor-background-color: var(--or-rules-editor-background-color, var(--or-app-color2, ${unsafeCSS(DefaultColor2)}));- --internal-or-rules-editor-text-color: var(--or-rules-editor-text-color, inherit);- --internal-or-rules-editor-button-color: var(--or-rules-editor-button-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));- --internal-or-rules-editor-invalid-color: var(--or-rules-editor-invalid-color, var(--or-app-color6, ${unsafeCSS(DefaultColor6)}));- --internal-or-rules-editor-panel-color: var(--or-rules-editor-panel-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));- --internal-or-rules-editor-line-color: var(--or-rules-editor-line-color, var(--or-app-color5, ${unsafeCSS(DefaultColor5)}));-- --internal-or-rules-editor-list-selected-color: var(--or-rules-editor-list-selected-color, var(--or-app-color2, ${unsafeCSS(DefaultColor2)}));- --internal-or-rules-editor-list-text-color: var(--or-rules-editor-list-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));- --internal-or-rules-editor-list-text-size: var(--or-rules-editor-list-text-size, 15px);-- --internal-or-rules-editor-list-button-size: var(--or-rules-editor-list-button-size, 24px);-- --internal-or-rules-editor-header-background-color: var(--or-rules-editor-header-background-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));- --internal-or-rules-editor-header-height: var(--or-rules-editor-header-height, 80px);- }-- .shadow {- -webkit-box-shadow: ${unsafeCSS(DefaultBoxShadow)};- -moz-box-shadow: ${unsafeCSS(DefaultBoxShadow)};- box-shadow: ${unsafeCSS(DefaultBoxShadow)};- }-- #rule-list-container {- min-width: 300px;- width: 300px;- z-index: 2;- display: flex;- flex-direction: column;- background-color: var(--internal-or-rules-editor-panel-color);- color: var(--internal-or-rules-editor-list-text-color);-- }-- #rule-list-container #bottom-toolbar {- display: flex;- border-top: 1px solid var(--internal-or-rules-editor-line-color);- --or-icon-fill: var(--internal-or-rules-editor-panel-color);- --or-icon-width: var(--internal-or-rules-editor-list-button-size);- --or-icon-height: var(--internal-or-rules-editor-list-button-size);- }-- #bottom-toolbar button {- padding: 5px;- margin: 10px;- cursor: pointer;- border: 1px solid var(--internal-or-rules-editor-line-color);- border-radius: 3px;- background-color: var(--internal-or-rules-editor-button-color);- }-- .rule-container {- display: flex;- flex-direction: column;- flex-grow: 1;- }-- or-rule-header {- min-height: var(--internal-or-rules-editor-header-height);- height: var(--internal-or-rules-editor-header-height);- }-- .rule-editor-panel {- display: flex;- flex-grow: 1;- background-color: var(--internal-or-rules-editor-background-color);- }-- .rule-editor-panel > * {- display: flex;- flex: 1 1 0;- }-- or-rule-section {- margin: 10px;- flex-grow: 1;- flex-shrink: 1;- }-- .center-center {- display: flex;- justify-content: center;- align-items: center;-- flex-direction: column;- text-align: center;- margin: auto;- }-- @media only screen- and (min-device-width : 768px)- and (max-device-width : 1024px) {- side-menu {- min-width: 150px;- width: 150px;- }- }-`;-// language=CSSexport const invalidStyle = css`*:invalid {@@ -164,100 +57,6 @@ export const buttonStyle = css`}`;-// language=CSS-export const ruleSectionStyle = css`- :host > div {- padding: 20px;- display: flex;- flex-direction: column;- background-color: var(--internal-or-rules-editor-panel-color);- box-shadow: rgba(0, 0, 0, 0.11) 0 1px 2px 0;- }-- strong {- text-transform: capitalize;- padding-bottom: 5px;- }-`;--// language=CSS-export const ruleListStyle = css`- :host {- overflow: auto;- flex-grow: 1;- font-size: var(--internal-or-rules-editor-list-text-size);- }-- .d-flex {- display: -webkit-box;- display: -moz-box;- display: -ms-flexbox;- display: -webkit-flex;- display: flex;- }-- .flex {- -webkit-box-flex: 1;- -moz-box-flex: 1;- -webkit-flex: 1;- -ms-flex: 1;- flex: 1;- }-- .list-title {- display: block;- padding: 30px 30px 5px 20px;- text-transform: uppercase;- color: var(, #808080);- font-size:14px;- font-weight: bold;- text-align: left;- }-- .list-item {- text-decoration: none;- padding: 13px 15px;- border-left: 5px solid transparent;- cursor: pointer;- transition: all 200ms ease-in;- opacity: 0.8;- }-- .list-item:hover {- border-left-color: var(--internal-or-rules-editor-list-selected-color);- background-color: var(--internal-or-rules-editor-list-selected-color);- }-- .list-item[selected] {- border-left-color: var(--internal-or-rules-editor-button-color);- background-color: var(--internal-or-rules-editor-list-selected-color);- opacity: 1;- }-- .list-item > span {- width: 8px;- height: 8px;- border-radius: 8px;- margin: 6px 10px 0 0;- }-- .bg-green {- background-color: #28b328;- }-- .bg-red {- background-color: red- }-- .bg-blue {- background-color: #3e92dc;- }-- .bg-grey {- background-color: #b7b7b7;- }-`;-// language=CSSexport const headerStyle = css`@@ -370,198 +169,3 @@ export const headerStyle = css`transform: translateX(20px);}`;--// language=CSS-export const whenStyle = css`-- ${buttonStyle}-- .rule-group {- display: flex;- flex-direction: column;- align-items: stretch;- position: relative;- }-- .rule-group.visible {- padding: 20px;- border-width: 2px;- border-style: solid;- border-color: var(--internal-or-rules-editor-line-color);- }-- .rule-group > .remove-button {- position: absolute;- right: 0;- top: 0;- width: 24px;- height: 24px;- transform: translate(50%, -50%);- }-- .rule-group > .remove-button > div {- position: absolute;- left: 2px;- right: 2px;- bottom: 2px;- top: 2px;- background-color: #FFF;- }-- .rule-group-items {- display: flex;- flex-direction: column;- }-- .rule-group .rule-group-items > div {- margin: 10px 0;- }-- .rule-group-item {- position: relative;- padding-left: 40px;- }-- .rule-condition {- display: flex;- }-- .operator {- text-transform: uppercase;- position: absolute;- left: 0;- top: 100%;- padding: 2px;- border: 2px solid var(--internal-or-rules-editor-button-color);- border-radius: 3px;- font-weight: bold;- font-size: small;- }-- .rule-condition > * {- flex-grow: 0;- }-- .rule-condition > or-rule-condition {- flex-grow: 1;- }-- .rule-group .rule-group-items div:last-child > .operator {- display: none;- }-`;--// language=CSS-export const actionStyle = css`-- ${buttonStyle}-- :host {- display: flex;- width: 100%;- flex-direction: column;- }-- .rule-action {- display: flex;- margin: 10px 0;- }-- .rule-action-action {- flex-grow: 1;- }-- .rule-action-action > * {- margin-right: 20px;- }-- .rule-action > button {- flex-grow: 0;- }-`;--// language=CSS-export const conditionEditorStyle = css`- :host {- display: flex;- flex-direction: row;- }-- :host > * {- margin-right: 20px;- }-- or-rule-asset-query {- flex-grow: 1;- }-- #type-selector {- margin-top: 10px;- }-`;--// language=CSS-export const assetQueryEditorStyle = css`-- ${buttonStyle}-- :host {- display: flex;- flex-direction: row;- }-- :host > * {- margin-right: 20px;- }-- .attribute-group {- flex-grow: 1;- display: flex;- flex-direction: column;- align-items: stretch;- position: relative;- }-- .attribute-items {- display: flex;- flex-direction: column;- }-- .attribute-items > div {- margin: 10px 0;- }-- .attribute-item {- position: relative;- padding-left: 40px;- }-- .attribute, .attribute-editor {- display: flex;- flex-grow: 1;- }-- .operator {- text-transform: uppercase;- position: absolute;- left: 0;- top: 100%;- padding: 2px;- border: 2px solid var(--internal-or-rules-editor-button-color);- border-radius: 3px;- font-weight: bold;- }-- .operator * {- font-size: small;- color: var(--internal-or-rules-editor-button-color);- }-- .attribute > * {- flex-grow: 0;- }-- .attribute-items div:last-child > .operator {- display: none;- }-`;diff --git a/ui/component/or-rules-editor/tsconfig.json b/ui/component/or-rules-editor/tsconfig.jsonindex c35978f28..72c588fcb 100644--- a/ui/component/or-rules-editor/tsconfig.json+++ b/ui/component/or-rules-editor/tsconfig.json@@ -13,6 +13,10 @@{ "path": "../or-translate" },{ "path": "../or-input" },{ "path": "../or-attribute-input" },+ { "path": "../or-icon" },+ { "path": "../or-panel" },+ { "path": "../or-asset-viewer" },+ { "path": "../or-mwc-components" },{ "path": "../rest" }]}\ No newline at end of filediff --git a/ui/component/rest/build.gradle b/ui/component/rest/build.gradleindex af0298f17..823447bc0 100644--- a/ui/component/rest/build.gradle+++ b/ui/component/rest/build.gradle@@ -94,7 +94,8 @@ clean {}}-build.dependsOn generateTypeScript+build.dependsOn generateTypeScript, npmBuild+npmBuild.dependsOn generateTypeScripttask prepareUi() {dependsOn clean, build, npmPreparediff --git a/ui/model-watch.js b/ui/model-watch.jsindex 85ca0d13b..a5d7cd94b 100644--- a/ui/model-watch.js+++ b/ui/model-watch.js@@ -37,5 +37,5 @@ child.stderr.pipe(process.stderr);child.on("exit", function() {console.log("gradlew modelWatch finished! Status = " + child.status);- process.exit(gradleModelWatch.status);+ process.exit(child.status);});\ No newline at end of filediff --git a/yarn.lock b/yarn.lockindex 5fa4f51fd..5ef0a40de 100644--- a/yarn.lock+++ b/yarn.lock@@ -1485,6 +1485,13 @@dependencies:tslib "^1.9.3"+"@material/animation@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/animation/-/animation-4.0.0.tgz#19eaf377809f20978f8452a4237d27867d3ffd1d"+ integrity sha512-IfzXzstWdtKQcsNWu+s2Hpz5dBwkTHtgtzoesr+FC7TqENH+SJdsF1ntnZI1XVi2C9ZlBf7f4BSmXpWHD0MIlw==+ dependencies:+ tslib "^1.9.3"+"@material/base@^3.1.0":version "3.1.0"resolved "https://registry.yarnpkg.com/@material/base/-/base-3.1.0.tgz#ab933896ab6390d4e1d2f9797b74a90f47db272a"@@ -1492,6 +1499,13 @@dependencies:tslib "^1.9.3"+"@material/base@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/base/-/base-4.0.0.tgz#535574d0b63c18892cfb70e88b27bc8f8090677a"+ integrity sha512-vHm7fkqXzjdfxifXvlmaZColoIfKuWmO+1rvdzDORTWP+A8Dq70cgKd2I1SBqxzDGjOasMzHbQI6f9MISQf2vQ==+ dependencies:+ tslib "^1.9.3"+"@material/button@^3.2.0":version "3.2.0"resolved "https://registry.yarnpkg.com/@material/button/-/button-3.2.0.tgz#859d9ce164d6ee5925ac0fb04af57ea7d9295c6e"@@ -1544,6 +1558,13 @@dependencies:tslib "^1.9.3"+"@material/dom@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/dom/-/dom-4.0.0.tgz#f0e68c4429e555040304c958bb3e11614276fdfa"+ integrity sha512-GRCJT9+PGWqygZwGf1XLTrbmzP35YWG7+T0hpfhoIJO8VDiMTeyfvhJXFuA2wh9pD0noEjte0lmbdBlykrbWZw==+ dependencies:+ tslib "^1.9.3"+"@material/elevation@^3.1.0":version "3.1.0"resolved "https://registry.yarnpkg.com/@material/elevation/-/elevation-3.1.0.tgz#2fcbde47653cc115519a39acc2d04b34e4cff12b"@@ -1553,11 +1574,39 @@"@material/feature-targeting" "^3.1.0""@material/theme" "^3.1.0"+"@material/elevation@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/elevation/-/elevation-4.0.0.tgz#58ba81c8c9efd0b5d3bfed7fa915d4930d814b97"+ integrity sha512-wKffoZcqkwAMWYbfGJJ95RDeOFz/IMvF7ye4VamjUwLb1iPiKxUZKUcd40XpuEvsn794HSIEWfGDsRq7BxJAMQ==+ dependencies:+ "@material/animation" "^4.0.0"+ "@material/feature-targeting" "^4.0.0"+ "@material/theme" "^4.0.0"++"@material/fab@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/fab/-/fab-4.0.0.tgz#634035a4ef087856fbc639de60efc32772d8dcb1"+ integrity sha512-YG5fubnZUEFLumBuc3Fw6Hcnek244OKJleSQhWVtFS6I2EgHqmr0gD8ZCKvXARmieyh4LRn7jKDK/WFJh74ayA==+ dependencies:+ "@material/animation" "^4.0.0"+ "@material/elevation" "^4.0.0"+ "@material/feature-targeting" "^4.0.0"+ "@material/ripple" "^4.0.0"+ "@material/rtl" "^4.0.0"+ "@material/shape" "^4.0.0"+ "@material/theme" "^4.0.0"+ "@material/typography" "^4.0.0"+"@material/feature-targeting@^3.1.0":version "3.1.0"resolved "https://registry.yarnpkg.com/@material/feature-targeting/-/feature-targeting-3.1.0.tgz#a6f6cacd1e0c9b60dc82f2f3bb2de8cfd472252b"integrity sha512-aXAa1Pv6w32URacE9LfMsl9zI6hFwx1K0Lp3Xpyf4rAkmaAB6z0gOkhicOrVFc0f64YheJgHjE7hJFieVenQdw==+"@material/feature-targeting@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/feature-targeting/-/feature-targeting-4.0.0.tgz#8d9d1470801a1fd166773731613d9fa89e0fd85e"+ integrity sha512-0gk+f151vqmEdWkrQ9ocPlQRU9aUtSGsVBhletqIbsthLUsZIz9qk25FHjV1wHd/bGHknd9NH+T8ENprv3KLFg==+"@material/floating-label@^3.2.0":version "3.2.0"resolved "https://registry.yarnpkg.com/@material/floating-label/-/floating-label-3.2.0.tgz#6de47528d1534b7d87f42286ed952fe63153c4d9"@@ -1672,11 +1721,28 @@"@material/theme" "^3.1.0"tslib "^1.9.3"+"@material/ripple@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/ripple/-/ripple-4.0.0.tgz#906ba421a3e6c68651d829d44c50a95060aa1e75"+ integrity sha512-9BLIOvyCP5sM+fQpLlcJZWyrHguusJq8E5A1pxg0wQwputOyaPBM7recHhYkJmVjzRpTcPgf1PkvkpN6DKGcNg==+ dependencies:+ "@material/animation" "^4.0.0"+ "@material/base" "^4.0.0"+ "@material/dom" "^4.0.0"+ "@material/feature-targeting" "^4.0.0"+ "@material/theme" "^4.0.0"+ tslib "^1.9.3"+"@material/rtl@^3.2.0":version "3.2.0"resolved "https://registry.yarnpkg.com/@material/rtl/-/rtl-3.2.0.tgz#0b2f7321463100674dfbf4507b54ccd052f05378"integrity sha512-L/w9m9Yx1ceOw/VjEfeJoqD4rW9QP3IBb9MamXAg3qUi/zsztoXD/FUw179pxkLn4huFFNlVYZ4Y1y6BpM0PMA==+"@material/rtl@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/rtl/-/rtl-4.0.0.tgz#bc07e0a7c47174b2542862c252b0e35b44329c47"+ integrity sha512-AP8zByVDEWAJVJoxByVccUbH+BX24IeG7ol+L6Qd8JjzPpz1fzPVJ4BeDNaF0a6sXtHsRmj2zN5dsx/BGC3IHg==+"@material/select@^3.2.0":version "3.2.0"resolved "https://registry.yarnpkg.com/@material/select/-/select-3.2.0.tgz#69961f6758eda5cce9ed8ab6a72db32661697fd6"@@ -1703,6 +1769,13 @@dependencies:"@material/feature-targeting" "^3.1.0"+"@material/shape@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/shape/-/shape-4.0.0.tgz#ddf4dcbfd290d367f80b26014fee0a1f490dc3cb"+ integrity sha512-wmr05YBrEL462QPiJ+t9xh5RqxzylXYo/8DVZnb/1WA9GZ6m38UK/8Awtip1cZAN34pzD/9p5AydyywlQVoI+g==+ dependencies:+ "@material/feature-targeting" "^4.0.0"+"@material/switch@^3.2.0":version "3.2.0"resolved "https://registry.yarnpkg.com/@material/switch/-/switch-3.2.0.tgz#003409a8eecfd2f9c9600bfb23e152bf12b7e518"@@ -1743,6 +1816,13 @@dependencies:"@material/feature-targeting" "^3.1.0"+"@material/theme@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/theme/-/theme-4.0.0.tgz#8de388fcdbae20fd09b02a3bdef3049bf2f623a8"+ integrity sha512-vS4G4rusJTatTH50kSYO1U3UGN8EY9kGRvPaFsEFKikJBOqcR6KWK9H9/wCLqqd6nDNifEj9H2sdWw1AV4NA6Q==+ dependencies:+ "@material/feature-targeting" "^4.0.0"+"@material/typography@^3.1.0":version "3.1.0"resolved "https://registry.yarnpkg.com/@material/typography/-/typography-3.1.0.tgz#5a3aee31f49f6b8c87ebc91b77c5b896b280c492"@@ -1750,6 +1830,13 @@dependencies:"@material/feature-targeting" "^3.1.0"+"@material/typography@^4.0.0":+ version "4.0.0"+ resolved "https://registry.yarnpkg.com/@material/typography/-/typography-4.0.0.tgz#57be7ac8b819f2ae29d48c9443b113d2f5585ecc"+ integrity sha512-lUG4yjG9fl1ryNX4OVnOmi+EjhiV4WsWcYt4yzffHrFg1RfKuCAV59j7TtmlMfZIkNDwqK5jvk3oOpTRDFpL8Q==+ dependencies:+ "@material/feature-targeting" "^4.0.0"+"@mdi/js@^4.5.95":version "4.5.95"resolved "https://registry.yarnpkg.com/@mdi/js/-/js-4.5.95.tgz#f9d12c03b9f848001c82fbdcd1aa445a6c9c8d67"@@ -4897,11 +4984,6 @@ grid-index@^1.0.0, grid-index@^1.1.0:resolved "https://registry.yarnpkg.com/grid-index/-/grid-index-1.1.0.tgz#97f8221edec1026c8377b86446a7c71e79522ea7"integrity sha512-HZRwumpOGUrHyxO5bqKZL0B0GlUpwtCAzZ42sgxUPniu33R1LSFH5yrIcBCHjkctCAh3mtWKcKd9J4vDDdeVHA==-growl@^1.10.5:- version "1.10.5"- resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e"- integrity sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==-handle-thing@^2.0.0:version "2.0.0"resolved "https://registry.yarnpkg.com/handle-thing/-/handle-thing-2.0.0.tgz#0e039695ff50c93fc288557d696f3c1dc6776754"@@ -4931,10 +5013,10 @@ har-validator@~5.1.0:ajv "^6.5.5"har-schema "^2.0.0"-has-flag@^1.0.0:- version "1.0.0"- resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"- integrity sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=+has-flag@^3.0.0:+ version "3.0.0"+ resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"+ integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=has-symbols@^1.0.0:version "1.0.0"@@ -5296,11 +5378,21 @@ inflight@^1.0.4:once "^1.3.0"wrappy "1"-inherits@2, [email protected], [email protected], [email protected], inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3:+inherits@2, [email protected], inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3:version "2.0.3"resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=+ version "2.0.1"+ resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1"+ integrity sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=++ version "2.0.4"+ resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"+ integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==+ini@^1.3.2, ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:version "1.3.5"resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"@@ -8230,11 +8322,6 @@ safe-regex@^1.1.0:resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==- version "1.1.3"- resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.3.tgz#9f5087419b4d091f232571e7fa52e90b0f552621"- integrity sha1-n1CHQZtNCR8jJXHn+lLpCw9VJiE=-version "0.1.4"resolved "https://registry.yarnpkg.com/sanitize-caja/-/sanitize-caja-0.1.4.tgz#7803e8e452b8e3bacb342dbd93adb885acd078af"@@ -8433,10 +8520,10 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=-simplebar@^4.2.3:- version "4.2.3"- resolved "https://registry.yarnpkg.com/simplebar/-/simplebar-4.2.3.tgz#dac40aced299c17928329eab3d5e6e795fafc10c"- integrity sha512-9no0pK7/1y+8/oTF3sy/+kx0PjQ3uk4cYwld5F1CJGk2gx+prRyUq8GRfvcVLq5niYWSozZdX73a2wIr1o9l/g==+simplebar@^5.0.6:+ version "5.0.6"+ resolved "https://registry.yarnpkg.com/simplebar/-/simplebar-5.0.6.tgz#2392bc27211bb3d4f9077e521d3c00d6311fbc69"+ integrity sha512-PAbvrH/eKon7NUTpD0ZxH+xnEeVGPaaQINJFWxJzTj6TtaN7KG80+US2HEU/xgaxaBGotqb1SmDhczaR5YuxYw==dependencies:can-use-dom "^0.1.0"core-js "^3.0.1"@@ -8918,12 +9005,19 @@ supercluster@^6.0.1:dependencies:kdbush "^3.0.0"[email protected], [email protected], supports-color@^5.3.0, supports-color@^6.1.0:- version "3.1.2"- resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.1.2.tgz#72a262894d9d408b956ca05ff37b2ed8a6e2a2d5"- integrity sha1-cqJiiU2dQIuVbKBf83su2KbiotU=[email protected], supports-color@^6.1.0:+ version "6.1.0"+ resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"+ integrity sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==+ dependencies:+ has-flag "^3.0.0"++supports-color@^5.3.0:+ version "5.5.0"+ resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"+ integrity sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==dependencies:- has-flag "^1.0.0"+ has-flag "^3.0.0"symbol-observable@^1.2.0:version "1.2.0"@@ -9206,11 +9300,6 @@ type-check@~0.3.2:dependencies:prelude-ls "~1.1.2"- version "1.0.0"- resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-1.0.0.tgz#762217cc06db258ec48908a1298e8b95121e8ea2"- integrity sha1-diIXzAbbJY7EiQihKY6LlRIejqI=-type-fest@^0.3.0:version "0.3.1"resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.3.1.tgz#63d00d204e059474fe5e1b7c011112bbd1dc29e1"