Skip to content

armgit / core

Public Imported from GitHub
0

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

Various minor UI updates

Rich Turnercc1a3b570445
diff --git a/model/src/main/java/org/openremote/model/query/NewAssetQuery.java b/model/src/main/java/org/openremote/model/query/NewAssetQuery.java
index 9b3790a90..2f6d38144 100644
--- a/model/src/main/java/org/openremote/model/query/NewAssetQuery.java
+++ b/model/src/main/java/org/openremote/model/query/NewAssetQuery.java
@@ -36,6 +36,7 @@ import org.openremote.model.rules.json.RuleCondition;
* There is an implicit AND between properties and an implicit OR between each value of a property.
*/
// TODO: Merge with existing AssetQuery
+// TODO: types and attributes are linked and shouldn't be independently specified
public class NewAssetQuery {
public String[] ids;
diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.ts
index a4cf4d5ed..67ab8a9bf 100644
--- a/ui/component/core/src/index.ts
+++ b/ui/component/core/src/index.ts
@@ -101,6 +101,14 @@ export class AssetModelUtil {
});
}
+ public static getAssetAttributeDescriptor(assetDescriptor?: AssetDescriptor, attributeName?: string): AttributeDescriptor | undefined {
+ if (!attributeName || !assetDescriptor || !assetDescriptor.attributeDescriptors) {
+ return;
+ }
+
+ return assetDescriptor.attributeDescriptors.find((attributeDescriptor) => attributeDescriptor.attributeName === attributeName);
+ }
+
public static getAttributeDescriptor(attributeName?: string): AttributeDescriptor | undefined {
if (!attributeName) {
return;
@@ -130,6 +138,16 @@ export class AssetModelUtil {
return metaItemDescriptor.urn === urn;
});
}
+
+ public static attributeValueDescriptorsMatch(attributeValueDescriptor1: AttributeValueDescriptor, attributeValueDescriptor2: AttributeValueDescriptor) {
+ if (attributeValueDescriptor1 === attributeValueDescriptor2) {
+ return true;
+ }
+ if (!attributeValueDescriptor1 || !attributeValueDescriptor2) {
+ return false;
+ }
+ return attributeValueDescriptor1.name === attributeValueDescriptor2.name && attributeValueDescriptor1.valueType === attributeValueDescriptor2.valueType;
+ }
}
export type EventCallback = (event: OREvent) => any;
@@ -376,7 +394,8 @@ export class Manager {
const initOptions: i18next.InitOptions = {
lng: "en",
fallbackLng: "en",
- defaultNS: "or",
+ defaultNS: "app",
+ fallbackNS: "or",
ns: this.config.loadTranslations,
backend: {
loadPath: (langs: string[], namespaces: string[]) => {
diff --git a/ui/component/or-rules-editor/package.json b/ui/component/or-rules-editor/package.json
index 4488a1e6e..1570d2941 100644
--- a/ui/component/or-rules-editor/package.json
+++ b/ui/component/or-rules-editor/package.json
@@ -15,6 +15,7 @@
"@openremote/model": "^1.0.1",
"@openremote/or-input": "^1.0.0",
"@openremote/or-select": "^1.0.0",
+ "@openremote/or-translate": "^1.0.0",
"@openremote/rest": "^1.0.0",
"@types/lodash-es": "^4.17.3",
"lit-element": "^2.1.0",
diff --git a/ui/component/or-rules-editor/src/index.ts b/ui/component/or-rules-editor/src/index.ts
index 5e22e6c3d..c8c4bb2a7 100644
--- a/ui/component/or-rules-editor/src/index.ts
+++ b/ui/component/or-rules-editor/src/index.ts
@@ -21,6 +21,9 @@ import findIndex from "lodash-es/findIndex";
import {attributeDescriptors} from "./const/attribute-descriptors";
import {ruleTemplate, rulesetTemplate} from "./const/rule-config";
+import "@openremote/or-translate";
+import {translate} from "@openremote/or-translate/dist/translate-mixin";
+import i18next from "i18next";
class InputHandlers {
public handlers: Array<(condition: RuleActionWriteAttribute) => TemplateResult | undefined> = [];
@@ -48,7 +51,7 @@ function confirmDialog(msg: string) {
}
@customElement("or-rules-editor")
-class OrRulesEditor extends LitElement {
+class OrRulesEditor extends translate(i18next)(LitElement) {
static get styles() {
return [
diff --git a/ui/component/or-rules-editor/src/or-rule-then-condition/index.ts b/ui/component/or-rules-editor/src/or-rule-then-condition/index.ts
index 58f9bfff0..efd249ee2 100644
--- a/ui/component/or-rules-editor/src/or-rule-then-condition/index.ts
+++ b/ui/component/or-rules-editor/src/or-rule-then-condition/index.ts
@@ -50,7 +50,7 @@ class OrRuleThenCondition extends LitElement {
<or-icon icon="numeric-1-circle"></or-icon>
</or-select-asset-action>
<or-select-asset-attribute disabled type="${this.condition}" value="${this.condition.attributeName}"></or-select-asset-attribute>
- <or-select-operator disabled type="${this.condition}" value="EQUAL"></or-select-operator>
+ <or-select-operator disabled value="EQUAL"></or-select-operator>
${this.createInputControl(this.condition!)}
` : ``}
</div>
diff --git a/ui/component/or-rules-editor/src/or-rule-when-condition/index.ts b/ui/component/or-rules-editor/src/or-rule-when-condition/index.ts
index ebceba6a5..070e31584 100644
--- a/ui/component/or-rules-editor/src/or-rule-when-condition/index.ts
+++ b/ui/component/or-rules-editor/src/or-rule-when-condition/index.ts
@@ -1,4 +1,4 @@
-import {html, LitElement, property, customElement, PropertyValues} from "lit-element";
+import {customElement, html, LitElement, property, PropertyValues} from "lit-element";
import "../selects/or-select-asset-attribute";
import "../selects/or-select-operator";
@@ -8,8 +8,7 @@ import "@openremote/or-icon";
import {AssetModelUtil} from "@openremote/core";
import {style} from "./style";
-import {AttributePredicate, AttributeDescriptor, ValueType} from "@openremote/model";
-import find from "lodash/find";
+import {AttributeDescriptor, AttributePredicate, AssetDescriptor} from "@openremote/model";
import {attributeDescriptors} from "../const/attribute-descriptors";
import {rulesEditorConfig} from "../const/rule-config";
@@ -23,12 +22,17 @@ class OrRuleWhenCondition extends LitElement {
];
}
+ protected assetDescriptor?: AssetDescriptor;
+
@property({type: Object})
public predicate?: AttributePredicate;
@property({type: Number})
public index?: number;
+ @property({type: String})
+ public assetType?: string;
+
@property({type: Array})
public attributeDescriptors?: AttributeDescriptor[] = attributeDescriptors;
@@ -41,7 +45,13 @@ class OrRuleWhenCondition extends LitElement {
this.addEventListener("asset-attribute:changed", this.setAssetAttribute);
this.addEventListener("operator:changed", this.setOperator);
this.addEventListener("or-input:changed", this.setValue);
+ }
+ protected shouldUpdate(_changedProperties: Map<PropertyKey, unknown>): boolean {
+ if (_changedProperties.has("assetType")) {
+ this.assetDescriptor = AssetModelUtil.getAssetDescriptor(this.assetType) || {attributeDescriptors: []};
+ }
+ return super.shouldUpdate(_changedProperties);
}
protected render() {
@@ -59,7 +69,7 @@ class OrRuleWhenCondition extends LitElement {
${this.predicate.value && this.predicate.value.predicateType === "string" ? html`
${this.predicate.name.value ? html`
- <or-select-operator type="${this.getAttributeDescriptors(this.predicate.name.value)!.valueDescriptor!.valueType}" .value="${this.predicate.value.match}"></or-select-operator>
+ <or-select-operator .type="${this.getAttributeDescriptor(this.predicate.name.value)!.valueDescriptor}" .value="${this.predicate.value.match}"></or-select-operator>
` : ``}
${this.predicate.name.value && this.predicate.value.match ? html`
@@ -122,9 +132,12 @@ class OrRuleWhenCondition extends LitElement {
// }
// }
- private getAttributeDescriptors(attributeName: string) {
- console.log(AssetModelUtil.getAttributeDescriptor(attributeName));
- return AssetModelUtil.getAttributeDescriptor(attributeName);
+ private getAttributeDescriptor(attributeName: string) {
+ if (!this.assetDescriptor) {
+ return;
+ }
+
+ return AssetModelUtil.getAssetAttributeDescriptor(this.assetDescriptor, attributeName);
}
private getAttributeConfig(name: string) {
diff --git a/ui/component/or-rules-editor/src/or-rule-when/index.ts b/ui/component/or-rules-editor/src/or-rule-when/index.ts
index 2268520ae..31b70478d 100644
--- a/ui/component/or-rules-editor/src/or-rule-when/index.ts
+++ b/ui/component/or-rules-editor/src/or-rule-when/index.ts
@@ -28,16 +28,16 @@ class OrRuleWhen extends LitElement {
}
+ // TODO: cleanup hacked asset type pass through
protected render() {
-
return html`
<div class="rule-content-section">
<div class="rule-when-container bg-white shadow">
<strong>Als..</strong>
- ${this.rule && this.rule.when && this.rule.when.asset && this.rule.when.asset.attributes && this.rule.when.asset.attributes.predicates ? html`
+ ${this.rule && this.rule.when && this.rule.when.asset && this.rule.when.asset.types && this.rule.when.asset.attributes && this.rule.when.asset.attributes.predicates ? html`
${this.rule.when.asset.attributes.predicates.map((predicate: AttributePredicate, index) => {
return html`
- <or-rule-when-condition index="${index}" .predicate="${predicate}"></or-rule-when-condition>
+ <or-rule-when-condition index="${index}" .assetType="${this.rule!.when!.asset!.types![0].value}" .predicate="${predicate}"></or-rule-when-condition>
`; })}
` : ``}
diff --git a/ui/component/or-rules-editor/src/selects/or-select-asset-attribute/index.ts b/ui/component/or-rules-editor/src/selects/or-select-asset-attribute/index.ts
index 6e3909511..c0385bed8 100644
--- a/ui/component/or-rules-editor/src/selects/or-select-asset-attribute/index.ts
+++ b/ui/component/or-rules-editor/src/selects/or-select-asset-attribute/index.ts
@@ -1,7 +1,7 @@
import {html, LitElement, customElement, property, PropertyValues} from "lit-element";
import {AttributeDescriptor, AttributeValueType, AttributeValueDescriptor, ValueType} from "@openremote/model";
-
import {selectStyle} from "@openremote/or-select/dist/style";
+import i18next from "i18next";
import {attributeDescriptors} from "../../const/attribute-descriptors";
import {rulesEditorConfig} from "../../const/rule-config";
@@ -58,7 +58,7 @@ class OrSelectAssetAttribute extends LitElement {
<select ?disabled="${this.disabled}" id="or-select-asset-attribute" @change="${this.onChange}">
${this.options ? this.options.map((attribute: AttributeDescriptor) => {
return html`
- <option ?selected="${attribute.attributeName === this.value}" value="${attribute.attributeName}">${attribute.attributeName}</option>
+ <option ?selected="${attribute.attributeName === this.value}" value="${attribute.attributeName}">${i18next.t(attribute.attributeName || "")}</option>
`;
}) : ``}
</select>
@@ -71,8 +71,8 @@ class OrSelectAssetAttribute extends LitElement {
return;
}
- this.options = this.attributeDescriptors.filter((obj) => {
- return obj.attributeName && rulesEditorConfig.options.attributeValueDescriptors.hasOwnProperty(obj.attributeName);
+ this.options = this.attributeDescriptors.filter((attributeDescriptor) => {
+ return attributeDescriptor.attributeName && rulesEditorConfig.options.attributeValueDescriptors.hasOwnProperty(attributeDescriptor.attributeName);
});
}
diff --git a/ui/component/or-rules-editor/src/selects/or-select-operator/index.ts b/ui/component/or-rules-editor/src/selects/or-select-operator/index.ts
index f544f621c..e042b8eb0 100644
--- a/ui/component/or-rules-editor/src/selects/or-select-operator/index.ts
+++ b/ui/component/or-rules-editor/src/selects/or-select-operator/index.ts
@@ -1,12 +1,13 @@
-import {html, LitElement, property, customElement} from 'lit-element';
+import {html, LitElement, property, customElement} from "lit-element";
import {AttributeValueType, BaseAssetQueryMatch, BaseAssetQueryOperator, AttributeValueDescriptor} from "@openremote/model";
import {selectStyle} from "@openremote/or-select/dist/style";
+import {AssetModelUtil} from "@openremote/core/dist";
@customElement('or-select-operator')
class OrRuleWhen extends LitElement {
- @property({type: String})
+ @property({type: Object})
type?: AttributeValueDescriptor;
@property({type: String})
@@ -28,7 +29,7 @@ class OrRuleWhen extends LitElement {
<select ?disabled="${this.disabled}" id="or-select-operator" @change="${this.onChange}">
<option ?selected="${this.value === BaseAssetQueryOperator.EQUALS}" value="${BaseAssetQueryOperator.EQUALS}">=</option>
<option ?selected="${this.value === BaseAssetQueryOperator.NOT_EQUALS}" value="${BaseAssetQueryOperator.NOT_EQUALS}">!=</option>
- ${this.type === AttributeValueType.NUMBER ? html`
+ ${AssetModelUtil.attributeValueDescriptorsMatch(this.type, AttributeValueType.NUMBER) ? html`
<option ?selected="${this.value === BaseAssetQueryOperator.LESS_THAN}" value="${BaseAssetQueryOperator.LESS_THAN}" value="LESS_THAN"><</option>
<option ?selected="${this.value === BaseAssetQueryOperator.GREATER_THAN}" value="${BaseAssetQueryOperator.GREATER_THAN}" value="GREATER_THAN">></option>
<option ?selected="${this.value === BaseAssetQueryOperator.LESS_EQUALS}" value="${BaseAssetQueryOperator.LESS_EQUALS}" value="LESS_EQUALS">=<</option>
diff --git a/ui/component/or-rules-editor/tsconfig.json b/ui/component/or-rules-editor/tsconfig.json
index c2df6cda0..4610819e8 100644
--- a/ui/component/or-rules-editor/tsconfig.json
+++ b/ui/component/or-rules-editor/tsconfig.json
@@ -10,6 +10,7 @@
"references": [
{ "path": "../core" },
{ "path": "../or-select" },
+ { "path": "../or-translate" },
{ "path": "../or-input" },
{ "path": "../rest" }
]
diff --git a/ui/demo/demo-core/package.json b/ui/demo/demo-core/package.json
index 6d02c0e89..a8a8a6cc3 100644
--- a/ui/demo/demo-core/package.json
+++ b/ui/demo/demo-core/package.json
@@ -8,7 +8,7 @@
"modelBuild": "node ../../model-build.js",
"modelWatch": "node ../../model-watch.js",
"build": "npx tsc -b && npx cross-env NODE_ENV=production webpack",
- "serve": "npx tsc -b && npx webpack-dev-server",
+ "serve": "npx webpack-dev-server",
"watch": "npx tsc -b -w",
"test": "echo \"Error: no test specified\" && exit 1"
},
diff --git a/ui/demo/demo-or-header/package.json b/ui/demo/demo-or-header/package.json
index f75045fe2..8a8816f8a 100644
--- a/ui/demo/demo-or-header/package.json
+++ b/ui/demo/demo-or-header/package.json
@@ -7,7 +7,7 @@
"modelBuild": "node ../../model-build.js",
"modelWatch": "node ../../model-watch.js",
"build": "npx tsc -b && npx cross-env NODE_ENV=production webpack",
- "serve": "npx tsc -b && npx webpack-dev-server",
+ "serve": "npx webpack-dev-server",
"watch": "npx tsc -b -w",
"test": "echo \"Error: no test specified\" && exit 1"
},
diff --git a/ui/demo/demo-or-map/package.json b/ui/demo/demo-or-map/package.json
index d289a38d7..b3af7a8f9 100644
--- a/ui/demo/demo-or-map/package.json
+++ b/ui/demo/demo-or-map/package.json
@@ -7,7 +7,7 @@
"modelBuild": "node ../../model-build.js",
"modelWatch": "node ../../model-watch.js",
"build": "npx tsc -b && npx cross-env NODE_ENV=production webpack",
- "serve": "npx tsc -b && npx webpack-dev-server",
+ "serve": "npx webpack-dev-server",
"watch": "node ../../model-build.js && npx tsc -b -w",
"test": "echo \"Error: no test specified\" && exit 1"
},
diff --git a/ui/demo/demo-or-thermostat/package.json b/ui/demo/demo-or-thermostat/package.json
index 8e7c68a09..d8b59d6b1 100644
--- a/ui/demo/demo-or-thermostat/package.json
+++ b/ui/demo/demo-or-thermostat/package.json
@@ -7,7 +7,7 @@
"modelBuild": "node ../../model-build.js",
"modelWatch": "node ../../model-watch.js",
"build": "npx tsc -b && npx cross-env NODE_ENV=production webpack",
- "serve": "npx tsc -b && npx webpack-dev-server",
+ "serve": "npx webpack-dev-server",
"watch": "npx tsc -b -w",
"test": "echo \"Error: no test specified\" && exit 1"
},
diff --git a/ui/demo/demo-rest/package.json b/ui/demo/demo-rest/package.json
index 47e097d39..27452cab1 100644
--- a/ui/demo/demo-rest/package.json
+++ b/ui/demo/demo-rest/package.json
@@ -8,7 +8,7 @@
"modelBuild": "node ../../model-build.js",
"modelWatch": "node ../../model-watch.js",
"build": "npx tsc -b && npx cross-env NODE_ENV=production webpack",
- "serve": "npx tsc -b && npx webpack-dev-server",
+ "serve": "npx webpack-dev-server",
"watch": "npx tsc -b -w",
"test": "echo \"Error: no test specified\" && exit 1"
},