Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

UI updates: rules styling, enhancements and bug fixes

Rich Turner0de7659030d5
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.json
index bc980faed..95ac0a8b2 100644
--- a/deployment/manager/shared/locales/en/or.json
+++ b/deployment/manager/shared/locales/en/or.json
@@ -55,6 +55,7 @@
"notLengthEquals": "Array length does not equal",
"lengthGreaterThan": "Array length greater than",
"lengthLessThan": "Array length less than",
+ "valueChanges": "Value changes",
"save": "Save",
"active": "Active",
"continueWithoutSaving": "If you continue, your changes will not be saved. Continue without saving?",
diff --git a/ui/component/or-asset-tree/src/style.ts b/ui/component/or-asset-tree/src/style.ts
index 9c3094ec9..536f77496 100644
--- a/ui/component/or-asset-tree/src/style.ts
+++ b/ui/component/or-asset-tree/src/style.ts
@@ -128,7 +128,6 @@ export const style = css`
.node-container {
display: flex;
- flex-direction: row;
border-left: 4px solid transparent;
user-select: none;
cursor: pointer;
diff --git a/ui/component/or-rules/src/index.ts b/ui/component/or-rules/src/index.ts
index 2b009f533..7f0528e66 100644
--- a/ui/component/or-rules/src/index.ts
+++ b/ui/component/or-rules/src/index.ts
@@ -1,4 +1,4 @@
-import {css, customElement, html, LitElement, property, query, TemplateResult, unsafeCSS} from "lit-element";
+import {css, customElement, html, LitElement, property, query, TemplateResult, unsafeCSS, PropertyValues} from "lit-element";
import manager, {
AssetModelUtil,
DefaultBoxShadow,
@@ -78,7 +78,8 @@ export enum AssetQueryOperator {
WITHIN_RADIUS = "withinRadius",
OUTSIDE_RADIUS = "outsideRadius",
WITHIN_RECTANGLE = "withinRectangle",
- OUTSIDE_RECTANGLE = "outsideRectangle"
+ OUTSIDE_RECTANGLE = "outsideRectangle",
+ VALUE_CHANGES = "valueChanges"
}
export interface AssetTypeAttributeName {
@@ -557,6 +558,17 @@ export class OrRules extends translate(i18next)(LitElement) {
this.addEventListener(OrRulesSaveStartEvent.NAME, this._onRuleSaveStart);
}
+ public shouldUpdate(_changedProperties: PropertyValues): boolean {
+ if (this._rulesList && _changedProperties.has("selectedIds")) {
+ this._rulesList.selectedIds = this.selectedIds;
+ if (_changedProperties.size === 1) {
+ return false;
+ }
+ }
+
+ return super.shouldUpdate(_changedProperties);
+ }
+
protected render() {
return html`
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
index 353bed2bf..6fb12da43 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
@@ -14,6 +14,7 @@ import {getAttributeValueTemplate} from "@openremote/or-attribute-input";
import {InputType, OrInputChangedEvent} from "@openremote/or-input";
import i18next from "i18next";
import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";
+import { translate } from "@openremote/or-translate";
// language=CSS
const style = css`
@@ -28,7 +29,7 @@ const style = css`
`;
@customElement("or-rule-action-attribute")
-export class OrRuleActionAttribute extends LitElement {
+export class OrRuleActionAttribute extends translate(i18next)(LitElement) {
static get styles() {
return style;
@@ -49,8 +50,7 @@ export class OrRuleActionAttribute extends LitElement {
@property({type: Array, attribute: false})
protected _assets?: Asset[];
-
- protected shouldUpdate(_changedProperties: PropertyValues): boolean {
+ public shouldUpdate(_changedProperties: PropertyValues): boolean {
if (_changedProperties.has("action")) {
this._assets = undefined;
}
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts b/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
index 625d55b67..0e28b57fc 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
@@ -33,6 +33,7 @@ import manager, {AssetModelUtil, Util} from "@openremote/core";
import i18next from "i18next";
import {buttonStyle} from "../style";
import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";
+import { translate } from "@openremote/or-translate";
// language=CSS
const style = css`
@@ -68,7 +69,7 @@ const style = css`
`;
@customElement("or-rule-asset-query")
-class OrRuleAssetQuery extends LitElement {
+class OrRuleAssetQuery extends translate(i18next)(LitElement) {
@property({type: Object, attribute: false})
public condition!: RuleCondition;
@@ -92,7 +93,8 @@ class OrRuleAssetQuery extends LitElement {
AssetQueryOperator.WITHIN_RECTANGLE,
AssetQueryOperator.OUTSIDE_RECTANGLE,
AssetQueryOperator.VALUE_EMPTY,
- AssetQueryOperator.VALUE_NOT_EMPTY]
+ AssetQueryOperator.VALUE_NOT_EMPTY,
+ AssetQueryOperator.VALUE_CHANGES]
],
[ValueType.STRING, [
AssetQueryOperator.EQUALS,
@@ -116,13 +118,15 @@ class OrRuleAssetQuery extends LitElement {
AssetQueryOperator.BETWEEN,
AssetQueryOperator.NOT_BETWEEN,
AssetQueryOperator.VALUE_EMPTY,
- AssetQueryOperator.VALUE_NOT_EMPTY]
+ AssetQueryOperator.VALUE_NOT_EMPTY,
+ AssetQueryOperator.VALUE_CHANGES]
],
[ValueType.BOOLEAN, [
AssetQueryOperator.IS_TRUE,
AssetQueryOperator.IS_FALSE,
AssetQueryOperator.VALUE_EMPTY,
- AssetQueryOperator.VALUE_NOT_EMPTY]
+ AssetQueryOperator.VALUE_NOT_EMPTY,
+ AssetQueryOperator.VALUE_CHANGES]
],
[ValueType.ARRAY, [
AssetQueryOperator.CONTAINS,
@@ -134,13 +138,15 @@ class OrRuleAssetQuery extends LitElement {
AssetQueryOperator.LENGTH_LESS_THAN,
AssetQueryOperator.LENGTH_GREATER_THAN,
AssetQueryOperator.VALUE_EMPTY,
- AssetQueryOperator.VALUE_NOT_EMPTY]
+ AssetQueryOperator.VALUE_NOT_EMPTY,
+ AssetQueryOperator.VALUE_CHANGES]
],
[ValueType.OBJECT, [
AssetQueryOperator.CONTAINS_KEY,
AssetQueryOperator.NOT_CONTAINS_KEY,
AssetQueryOperator.VALUE_EMPTY,
- AssetQueryOperator.VALUE_NOT_EMPTY]
+ AssetQueryOperator.VALUE_NOT_EMPTY,
+ AssetQueryOperator.VALUE_CHANGES]
]
]);
@@ -170,7 +176,7 @@ class OrRuleAssetQuery extends LitElement {
<div class="attribute-editor">
<or-input type="${InputType.SELECT}" @or-input-changed="${(e: OrSelectChangedEvent) => this.setAttributeName(attributePredicate, e.detail.value)}" ?readonly="${this.readonly}" .options="${attributes}" .value="${attributeName}"></or-input>
- ${attributeName ? html`<or-input type="${InputType.SELECT}" @or-input-changed="${(e: OrSelectChangedEvent) => this.setOperator(assetDescriptor, attributePredicate, e.detail.value)}" ?readonly="${this.readonly}" .options="${operators}" .value="${operator}"></or-input>` : ``}
+ ${attributeName ? html`<or-input type="${InputType.SELECT}" @or-input-changed="${(e: OrSelectChangedEvent) => this.setOperator(assetDescriptor, attribute, attributeName, attributePredicate, e.detail.value)}" ?readonly="${this.readonly}" .options="${operators}" .value="${operator}"></or-input>` : ``}
${attributePredicate ? this.attributePredicateValueEditorTemplate(assetDescriptor, attributePredicate) : ``}
</div>
@@ -233,7 +239,7 @@ class OrRuleAssetQuery extends LitElement {
return style;
}
- protected shouldUpdate(_changedProperties: PropertyValues): boolean {
+ public shouldUpdate(_changedProperties: PropertyValues): boolean {
if (_changedProperties.has("condition")) {
this._assets = undefined;
@@ -459,7 +465,7 @@ class OrRuleAssetQuery extends LitElement {
}
}
- protected setOperator(assetDescriptor: AssetDescriptor, attributePredicate: AttributePredicate, operator: string | undefined) {
+ protected setOperator(assetDescriptor: AssetDescriptor, attribute: Attribute | undefined, attributeName: string, attributePredicate: AttributePredicate, operator: string | undefined) {
if (!this.query
|| !this.query.attributes
@@ -468,6 +474,8 @@ class OrRuleAssetQuery extends LitElement {
return;
}
+ this.condition.reset = undefined;
+
if (!operator) {
attributePredicate.value = undefined;
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
@@ -475,9 +483,9 @@ class OrRuleAssetQuery extends LitElement {
return;
}
- const attributeName = this.getAttributeName(attributePredicate);
- const attributeDescriptor = assetDescriptor.attributeDescriptors ? assetDescriptor.attributeDescriptors.find((ad) => ad.attributeName === attributeName) : undefined;
- const valueType = getDescriptorValueType(attributeDescriptor);
+ const descriptor = assetDescriptor.attributeDescriptors ? assetDescriptor.attributeDescriptors.find((ad) => ad.attributeName === attributeName) : undefined;
+ const valueDescriptor = attribute ? AssetModelUtil.getAttributeValueDescriptor(attribute.type as string) : descriptor ? descriptor.valueDescriptor : undefined;
+ const valueType = valueDescriptor ? valueDescriptor.valueType : undefined;
const value = operator as AssetQueryOperator;
if (!valueType || !value) {
@@ -618,7 +626,7 @@ class OrRuleAssetQuery extends LitElement {
// multiple
case AssetQueryOperator.EQUALS:
case AssetQueryOperator.NOT_EQUALS:
- if (attributeDescriptor && attributeDescriptor.valueDescriptor && attributeDescriptor.valueDescriptor.name === AttributeValueType.DATETIME.name) {
+ if (descriptor && descriptor.valueDescriptor && descriptor.valueDescriptor.name === AttributeValueType.DATETIME.name) {
predicate = {
predicateType: "datetime",
negate: value === AssetQueryOperator.NOT_EQUALS,
@@ -644,9 +652,15 @@ class OrRuleAssetQuery extends LitElement {
};
break;
case AssetQueryOperator.VALUE_NOT_EMPTY:
+ case AssetQueryOperator.VALUE_CHANGES:
predicate = {
predicateType: "value-not-empty"
};
+ if (value === AssetQueryOperator.VALUE_CHANGES) {
+ this.condition.reset = {
+ valueChanges: true
+ };
+ }
break;
case AssetQueryOperator.CONTAINS:
case AssetQueryOperator.NOT_CONTAINS:
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-condition.ts b/ui/component/or-rules/src/json-viewer/or-rule-condition.ts
index e8810157c..c5c6210de 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-condition.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-condition.ts
@@ -13,7 +13,7 @@ import "@openremote/or-translate";
import {getAssetDescriptorIconTemplate} from "@openremote/or-icon";
import {InputType} from "@openremote/or-input";
import {AssetModelUtil} from "@openremote/core";
-import {i18next} from "@openremote/or-translate";
+import {i18next, translate} from "@openremote/or-translate";
import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";
import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/dist/or-mwc-menu";
@@ -121,7 +121,7 @@ const style = css`
`;
@customElement("or-rule-condition")
-class OrRuleCondition extends LitElement {
+class OrRuleCondition extends translate(i18next)(LitElement) {
@property({type: Object, attribute: false})
public ruleCondition!: RuleCondition;
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts b/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts
index 0514fad25..b7f44aaa7 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts
@@ -17,6 +17,7 @@ import {getAssetDescriptorIconTemplate} from "@openremote/or-icon";
import {AssetModelUtil} from "@openremote/core";
import "./or-rule-action-attribute";
import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/dist/or-mwc-menu";
+import { translate } from "@openremote/or-translate";
const NOTIFICATION_COLOR = "4B87EA";
const WAIT_COLOR = "EACC54";
@@ -112,7 +113,7 @@ const style = css`
`;
@customElement("or-rule-then-otherwise")
-class OrRuleThenOtherwise extends LitElement {
+class OrRuleThenOtherwise extends translate(i18next)(LitElement) {
static get styles() {
return style;
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-when.ts b/ui/component/or-rules/src/json-viewer/or-rule-when.ts
index a29c325dd..cafe8d9d3 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-when.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-when.ts
@@ -8,6 +8,7 @@ import {InputType} from "@openremote/or-input";
import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";
import {getWhenTypesMenu, updateRuleConditionType} from "./or-rule-condition";
import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/dist/or-mwc-menu";
+import { translate } from "@openremote/or-translate";
// language=CSS
const style = css`
@@ -78,7 +79,7 @@ const style = css`
`;
@customElement("or-rule-when")
-class OrRuleWhen extends LitElement {
+class OrRuleWhen extends translate(i18next)(LitElement) {
static get styles() {
return style;
@@ -190,7 +191,7 @@ class OrRuleWhen extends LitElement {
return html`<span>DATE TIME PREDICATE NOT IMPLEMENTED</span>`;
}
- protected shouldUpdate(_changedProperties: PropertyValues): boolean {
+ public shouldUpdate(_changedProperties: PropertyValues): boolean {
if (_changedProperties.has("rule")) {
if (this.rule) {
if (!this.rule.when) {
diff --git a/ui/component/or-rules/src/or-rule-list.ts b/ui/component/or-rules/src/or-rule-list.ts
index dffb738d8..ff67271b4 100644
--- a/ui/component/or-rules/src/or-rule-list.ts
+++ b/ui/component/or-rules/src/or-rule-list.ts
@@ -36,31 +36,17 @@ const style = css`
pointer-events: none;
}
- .list-item {
- text-decoration: none;
- padding: 13px 15px;
- border-left: 5px solid transparent;
- cursor: pointer;
- transition: all 200ms ease-in;
- opacity: 0.8;
+ .node-container {
+ align-items: center;
+ padding-left: 10px;
}
-
- .list-item:hover {
- border-left-color: var(--internal-or-rules-list-selected-color);
- background-color: var(--internal-or-rules-list-selected-color);
- }
-
- .list-item[selected] {
- border-left-color: var(--internal-or-rules-button-color);
- background-color: var(--internal-or-rules-list-selected-color);
- opacity: 1;
- }
-
- .list-item > span {
- width: 8px;
- height: 8px;
- border-radius: 8px;
- margin: 6px 10px 0 0;
+
+ .node-status {
+ width: 10px;
+ height: 10px;
+ border-radius: 5px;
+ margin-right: 10px;
+ display: none;
}
.bg-green {
@@ -187,7 +173,14 @@ export class OrRuleList extends translate(i18next)(LitElement) {
}
if (_changedProperties.has("selectedIds")) {
- this._updateSelectedNodes();
+ let changed = true;
+ const oldValue = _changedProperties.get("selectedIds") as number[];
+ if (this.selectedIds && oldValue && this.selectedIds.length === oldValue.length) {
+ changed = !!this.selectedIds.find((oldSelected) => oldValue.indexOf(oldSelected) < 0);
+ }
+ if (changed) {
+ this._updateSelectedNodes();
+ }
}
if (_changedProperties.has("sortBy")) {
@@ -276,12 +269,8 @@ export class OrRuleList extends translate(i18next)(LitElement) {
return html`
<li ?data-selected="${node.selected}" @click="${(evt: MouseEvent) => this._onNodeClicked(evt, node)}">
<div class="node-container">
- <div class="node-name">
- <span class="${OrRuleList._getNodeStatusClasses(node.ruleset)}"></span>
- <div class="flex">
- <span>${node.ruleset.name}</span>
- </div>
- </div>
+ <span class="node-status ${OrRuleList._getNodeStatusClasses(node.ruleset)}"></span>
+ <span class="node-name">${node.ruleset.name}</span>
</div>
</li>
`;
diff --git a/ui/component/or-rules/src/or-rule-viewer.ts b/ui/component/or-rules/src/or-rule-viewer.ts
index 6dba7bff2..602701fb8 100644
--- a/ui/component/or-rules/src/or-rule-viewer.ts
+++ b/ui/component/or-rules/src/or-rule-viewer.ts
@@ -124,11 +124,10 @@ export class OrRuleViewer extends translate(i18next)(LitElement) {
public shouldUpdate(_changedProperties: PropertyValues): boolean {
if (_changedProperties.has("ruleset")) {
this._supported = true;
+ this.modified = false;
+ this._ruleValid = false;
- if (!this.ruleset) {
- this.modified = false;
- this._ruleValid = false;
- } else {
+ if (this.ruleset) {
this._focusName = true;
}
}