Skip to content

armgit / core

Public Imported from GitHub
0

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

WIP Rules editor

robindekkers1a4547263005
diff --git a/ui/component/or-rules-editor/src/const/attribute-descriptors.ts b/ui/component/or-rules-editor/src/const/attribute-descriptors.ts
index cf9b34f1a..b4270c898 100644
--- a/ui/component/or-rules-editor/src/const/attribute-descriptors.ts
+++ b/ui/component/or-rules-editor/src/const/attribute-descriptors.ts
@@ -3,12 +3,218 @@ import {
ValueType
} from "@openremote/model";
-export const attributeDescriptors: AttributeDescriptor[] = [
- {name: "flightProfiles", valueDescriptor: {name: "STRING", valueType: ValueType.STRING}},
- {name: "airportIata", valueDescriptor: {name: "STRING", valueType: ValueType.STRING}},
- {name: "airlineIata", valueDescriptor: {name: "STRING", valueType: ValueType.STRING}},
- {name: "originRegion", valueDescriptor: {name: "STRING", valueType: ValueType.STRING}},
- {name: "languageCodes", valueDescriptor: {name: "STRING", valueType: ValueType.STRING}},
- {name: "passengerCapacity", valueDescriptor: {name: "NUMBER", valueType: ValueType.NUMBER}},
- {name: "countryCode", valueDescriptor: {name: "STRING", valueType: ValueType.STRING}}
-];
+export const attributeDescriptors: any[] = [ {
+ name: "flightProfiles",
+ attributeValueDescriptor : {
+ icon : "cubes",
+ valueType : "OBJECT",
+ name: "OBJECT"
+ }
+ }, {
+ name: "languageCodes",
+ attributeValueDescriptor : {
+ icon : "ellipsis-h",
+ valueType : "ARRAY",
+ name: "ARRAY"
+ }
+ }, {
+ name: "flightName",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "flightDirection",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "airlineIata",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "scheduleDate",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "scheduleTime",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "scheduledInBlockTime",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "estimatedLandingTime",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "actualLandingTime",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "estimatedPierTime",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "estimatedCheckPointTime",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "estimatedSchengenCheckPointTime",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "terminal",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "gate",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "gateNumber",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "hashtag",
+ valueType : "NUMBER",
+ name: "NUMBER"
+ }
+ }, {
+ name: "pier",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "checkPoint",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "pierDisplayName",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "passengerCapacity",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "hashtag",
+ valueType : "NUMBER",
+ name: "NUMBER"
+ }
+ }, {
+ name: "passengerArrivalCheckPoint",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "hashtag",
+ valueType : "NUMBER",
+ name: "NUMBER"
+ }
+ }, {
+ name: "passengerSchengenCheckPoint",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "hashtag",
+ valueType : "NUMBER",
+ name: "NUMBER"
+ }
+ }, {
+ name: "airportName",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "airportIata",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "city",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "countryCode",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ }, {
+ name: "originRegion",
+ metaItemDescriptors : [ ],
+ valueDescriptor : {
+ icon : "file-text-o",
+ valueType : "STRING",
+ name: "STRING"
+ }
+ } ];
diff --git a/ui/component/or-rules-editor/src/const/rule-config.ts b/ui/component/or-rules-editor/src/const/rule-config.ts
index 9148f9e21..17ffceab9 100644
--- a/ui/component/or-rules-editor/src/const/rule-config.ts
+++ b/ui/component/or-rules-editor/src/const/rule-config.ts
@@ -2,25 +2,20 @@ import openremote from "@openremote/core";
import {
Rule,
RulesetLang,
- TenantRuleset
+ TenantRuleset,
+ NewAssetQuery,
+ BaseAssetQueryMatch,
+ RuleActionUnion,
+ RuleActionUpdateAttributeUpdateAction,
+ RuleTrigger,
+ AttributePredicate
} from "@openremote/model";
-export const ruleModel: Rule = {
- name: "",
- when: undefined,
- then: undefined
-};
-
-export const rulesetModel: TenantRuleset = {
- name: "New Rule",
- type: "tenant",
- lang: RulesetLang.JSON,
- realm: openremote.getRealm(),
- accessPublicRead: true,
- rules: JSON.stringify({rules: [ruleModel]})
-};
-
export const rulesEditorConfig = {
+ controls: {
+ addWhenCondition: true,
+ addThenCondition: false,
+ },
options: {
attributeValueDescriptors: {
flightProfiles: {},
@@ -43,3 +38,68 @@ export const rulesEditorConfig = {
}
}
};
+
+export const ruleTemplate: Rule = {
+ name: "",
+ when: undefined,
+ then: undefined
+};
+
+export const rulesetTemplate: TenantRuleset = {
+ name: "New Rule",
+ type: "tenant",
+ lang: RulesetLang.JSON,
+ realm: openremote.getRealm(),
+ accessPublicRead: true,
+ rules: JSON.stringify({rules: [ruleTemplate]})
+};
+
+
+export const defaultAssetType: NewAssetQuery = {
+ types: [{
+ predicateType: "string",
+ match: BaseAssetQueryMatch.EXACT,
+ value: "urn:openremote:asset:kmar:flight"
+ }]
+};
+
+export const defaultThenCondition: RuleActionUnion = {
+ action: "update-attribute",
+ updateAction: RuleActionUpdateAttributeUpdateAction.ADD_OR_REPLACE,
+ attributeName: "flightProfiles",
+ key: "%RULESET_ID%",
+ value: {
+ profileName: "%RULESET_NAME%",
+ profileColor: "orange"
+ },
+ target: { useAssetsFromWhen: true}
+};
+
+export const defaultThen: RuleActionUnion[] = [defaultThenCondition];
+
+export const defaultWhenCondition: RuleTrigger = {
+ asset: {
+ types: [{
+ predicateType: "string",
+ match: BaseAssetQueryMatch.EXACT,
+ value: "urn:openremote:asset:kmar:flight"
+ }
+ ],
+ attributes: {
+ predicates: []
+ }
+ }
+};
+
+export const defaultPredicate: AttributePredicate = {
+ name: {
+ predicateType: "string",
+ match: BaseAssetQueryMatch.EXACT,
+ value: "airlineIata"
+ },
+ value: {
+ predicateType: "string",
+ match: BaseAssetQueryMatch.EXACT
+ }
+
+};
\ No newline at end of file
diff --git a/ui/component/or-rules-editor/src/index.ts b/ui/component/or-rules-editor/src/index.ts
index 14fdff2fc..96c579325 100644
--- a/ui/component/or-rules-editor/src/index.ts
+++ b/ui/component/or-rules-editor/src/index.ts
@@ -20,7 +20,7 @@ import {style} from "./style";
import findIndex from "lodash-es/findIndex";
import {attributeDescriptors} from "./const/attribute-descriptors";
-import {ruleModel, rulesetModel, rulesEditorConfig} from "./const/rule-config";
+import {ruleTemplate, rulesetTemplate} from "./const/rule-config";
class InputHandlers {
public handlers: Array<(condition: RuleActionWriteAttribute) => TemplateResult | undefined> = [];
@@ -146,8 +146,8 @@ class OrRulesEditor extends LitElement {
}
if (this.rulesets) {
- const newRule = rulesetModel;
- this.rulesets = [...this.rulesets, rulesetModel];
+ const newRule = rulesetTemplate;
+ this.rulesets = [...this.rulesets, rulesetTemplate];
this.ruleset = newRule;
this.computeRuleset();
}
@@ -217,7 +217,7 @@ class OrRulesEditor extends LitElement {
if (this.ruleset && this.ruleset.rules) {
this.rule = JSON.parse(this.ruleset.rules).rules[0];
} else if (this.ruleset && !this.ruleset.rules) {
- this.rule = ruleModel;
+ this.rule = ruleTemplate;
this.rule.name = this.ruleset.name;
}
this.requestUpdate();
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 448a7272a..6ccb020af 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
@@ -7,11 +7,10 @@ import "@openremote/or-select";
import "@openremote/or-icon";
import handler from "../index";
import {style} from "./style";
-import set from 'lodash/set';
+import set from "lodash/set";
-import {RuleActionUnion, RuleActionWriteAttribute, AttributeDescriptor} from "@openremote/model";
+import {RuleActionWriteAttribute} from "@openremote/model";
-// TODO use create select option to
@customElement("or-rule-then-condition")
class OrRuleThenCondition extends LitElement {
@@ -27,9 +26,6 @@ class OrRuleThenCondition extends LitElement {
@property({type: Number})
private value: number = 0;
- @property({type: Array})
- public attributeDescriptors?: AttributeDescriptor[];
-
constructor() {
super();
@@ -50,7 +46,7 @@ class OrRuleThenCondition extends LitElement {
return html`
<div class="rule-container">
${this.condition ? html`
- <or-select-asset-attribute disabled type="${this.condition}" value="${this.condition.attributeName}" .attributeDescriptors="${this.attributeDescriptors}"></or-select-asset-attribute>
+ <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>
${this.createInputControl(this.condition!)}
` : ``}
@@ -63,7 +59,7 @@ class OrRuleThenCondition extends LitElement {
const result = h(this.condition!);
if (result) {
- let response = html`${result}`;
+ const response = html`${result}`;
return response;
}
}
diff --git a/ui/component/or-rules-editor/src/or-rule-then/index.ts b/ui/component/or-rules-editor/src/or-rule-then/index.ts
index 622152506..d0d69cce1 100644
--- a/ui/component/or-rules-editor/src/or-rule-then/index.ts
+++ b/ui/component/or-rules-editor/src/or-rule-then/index.ts
@@ -1,35 +1,13 @@
-import {html, LitElement, property, customElement, PropertyValues} from 'lit-element';
+import {html, LitElement, property, customElement, PropertyValues} from "lit-element";
-import {style} from './style';
-import {Rule, RuleTrigger, RuleActionUnion, NewAssetQuery, BaseAssetQueryMatch, RuleActionUpdateAttributeUpdateAction,
+import {style} from "./style";
+import {Rule, RuleActionUnion,
AttributeDescriptor} from "@openremote/model";
-import '../or-rule-then-condition';
+import "../or-rule-then-condition";
+import {rulesEditorConfig, defaultThen, defaultThenCondition} from "../const/rule-config";
-
-const defaultAssetType:NewAssetQuery = {
- "types": [{
- "predicateType": "string",
- "match": BaseAssetQueryMatch.EXACT,
- "value": "urn:openremote:asset:kmar:flight"
- }]
-};
-
-let defaultThenCondition:RuleActionUnion = {
- action: "update-attribute",
- updateAction: RuleActionUpdateAttributeUpdateAction.ADD_OR_REPLACE,
- attributeName: "profiles",
- key: "%RULESET_ID%",
- value: {
- profileName: "%RULESET_NAME%",
- profileColor: "orange"
- },
- target: { "useAssetsFromWhen": true}
-};
-
-let defaultThen:RuleActionUnion[] = [defaultThenCondition];
-
-@customElement('or-rule-then')
+@customElement("or-rule-then")
class OrRuleThen extends LitElement {
static get styles() {
@@ -38,50 +16,55 @@ class OrRuleThen extends LitElement {
]
}
+ @property({type: Object})
+ public rule?: Rule;
+
+ @property({type: Array})
+ public attributeDescriptors?: AttributeDescriptor[];
+
+ constructor() {
+ super();
+ }
+
protected render() {
return html`
<div class="rule-content-section">
<h3>Dan..</h3>
<div class="rule-then-container bg-white shadow">
- ${this.rule && this.rule.then ? this.rule.then.map((then:RuleActionUnion) => {
- return html`
+ ${this.rule && this.rule.then ? this.rule.then.map((then: RuleActionUnion) => {
+ return html`
<or-rule-then-condition .condition="${then}" .attributeDescriptors="${this.attributeDescriptors}"></or-rule-then-condition>
- <span class="rule-additional">&</span>
- `
- }) : ``}
- <a class="button-add" @click="${this.addThenCondition}">+</a>
+
+ ${rulesEditorConfig.controls.addThenCondition ? html`
+ <span class="rule-additional">&</span>
+ ` : ``}
+
+ `; }) : ``}
+
+ ${rulesEditorConfig.controls.addThenCondition ? html`
+ <a class="button-add" @click="${this.addThenCondition}">+</a>
+ ` : ``}
</div>
</div>
`;
}
- @property({type: Object})
- rule?: Rule;
-
- @property({type: Array})
- public attributeDescriptors?: AttributeDescriptor[];
-
-
- constructor() {
- super();
- }
-
protected updated(_changedProperties: PropertyValues): void {
super.updated(_changedProperties);
- if(this.rule && !this.rule.then) {
+ if (this.rule && !this.rule.then) {
this.rule.then = defaultThen;
this.requestUpdate();
}
}
- addThenCondition () {
- if(this.rule && !this.rule.then) {
+ private addThenCondition () {
+ if (this.rule && !this.rule.then) {
this.rule.then = defaultThen;
}
- if(this.rule && this.rule.then) {
+ if (this.rule && this.rule.then) {
this.rule.then.push(defaultThenCondition);
this.requestUpdate();
}
@@ -89,4 +72,3 @@ class OrRuleThen extends LitElement {
}
}
-
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 494e82ab9..bf114cda8 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,22 +1,43 @@
-import {html, LitElement, property, customElement} from 'lit-element';
-import '../selects/or-select-asset-attribute';
-import '../selects/or-select-operator';
+import {html, LitElement, property, customElement} from "lit-element";
+import "../selects/or-select-asset-attribute";
+import "../selects/or-select-operator";
-import '@openremote/or-input';
-import '@openremote/or-select';
-import '@openremote/or-icon';
+import "@openremote/or-input";
+import "@openremote/or-select";
+import "@openremote/or-icon";
-import {style} from './style';
+import {style} from "./style";
import {AttributePredicate, AttributeDescriptor, ValueType} from "@openremote/model";
-import find from 'lodash/find';
+import find from "lodash/find";
-@customElement('or-rule-when-condition')
+import {attributeDescriptors} from "../const/attribute-descriptors";
+import {rulesEditorConfig} from "../const/rule-config";
+
+@customElement("or-rule-when-condition")
class OrRuleWhenCondition extends LitElement {
static get styles() {
return [
style
- ]
+ ];
+ }
+
+ @property({type: Object})
+ public predicate?: AttributePredicate;
+
+ @property({type: Number})
+ public index?: number;
+
+ @property({type: Array})
+ public attributeDescriptors?: AttributeDescriptor[] = attributeDescriptors;
+
+ constructor() {
+ super();
+
+ this.addEventListener("asset-attribute:changed", this.setAssetAttribute);
+ this.addEventListener("operator:changed", this.setOperator);
+ this.addEventListener("or-input:changed", this.setValue);
+
}
protected render() {
@@ -25,23 +46,23 @@ class OrRuleWhenCondition extends LitElement {
<div class="rule-container">
${this.predicate ? html`
<or-select-asset-type>
- <or-icon icon="${this.predicate.name ? 'airplane' : 'airplane'}">
+ <or-icon icon="${this.predicate.name ? "airplane" : "airplane"}">
</or-icon>
</or-select-asset-type>
${this.predicate.name ? html`
- <or-select-asset-attribute icon="${this.predicate}" value="${this.predicate.name.value}" .attributeDescriptors="${this.attributeDescriptors}"></or-select-asset-attribute>
+ <or-select-asset-attribute icon="${this.predicate}" value="${this.predicate.name.value}"></or-select-asset-attribute>
- ${this.predicate.value && this.predicate.value.predicateType === 'string' ? html`
+ ${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>
` : ``}
${this.predicate.name.value && this.predicate.value.match ? html`
- ${this.getAttributeDescriptors(this.predicate.name.value)!.valueDescriptor!.valueType === ValueType.ARRAY ? html`
- <or-select .options="${this.getAttributeDescriptors(this.predicate.name.value)!.initialValue}" value="${this.predicate.value.value ? this.predicate.value.value : ''}"></or-select>
- `: html`
- <or-input type="text" value="${this.predicate.value.value ? this.predicate.value.value : ''}"></or-input>
+ ${this.getAttributeConfig(this.predicate.name.value)!.options ? html`
+ <or-select .options="${this.getAttributeConfig(this.predicate.name.value).options}" value="${this.predicate.value.value ? this.predicate.value.value : ""}"></or-select>
+ ` : html`
+ <or-input type="text" value="${this.predicate.value.value ? this.predicate.value.value : ""}"></or-input>
`}
` : ``}
@@ -60,15 +81,6 @@ class OrRuleWhenCondition extends LitElement {
`;
}
- @property({type: Object})
- predicate?: AttributePredicate;
-
- @property({type: Number})
- index?: number;
-
- @property({type: Array})
- public attributeDescriptors?: AttributeDescriptor[];
-
// setAssetType(value:string) {
// const assetType = {
// "predicateType": "string",
@@ -82,11 +94,21 @@ class OrRuleWhenCondition extends LitElement {
// }
// }
- getAttributeDescriptors(name: string) {
- return find(this.attributeDescriptors, ['name', name]);
+ private getAttributeDescriptors(name: string) {
+ return find(this.attributeDescriptors, ["name", name]);
+ }
+
+ private getAttributeConfig(name: string) {
+ const attributeValueDescriptors: any = rulesEditorConfig.options.attributeValueDescriptors;
+
+ if (attributeValueDescriptors) {
+ const attributeConfig = attributeValueDescriptors[name];
+ return attributeConfig;
+ }
+
}
- setAssetAttribute(e:any) {
+ private setAssetAttribute(e: any) {
const value = e.detail.value;
if(this.predicate && this.predicate.name) {
@@ -97,26 +119,26 @@ class OrRuleWhenCondition extends LitElement {
}
}
- setOperator(e:any){
+ private setOperator(e: any){
const value = e.detail.value;
- if(this.predicate && this.predicate.value && this.predicate.value.predicateType === 'string') {
+ if(this.predicate && this.predicate.value && this.predicate.value.predicateType === "string") {
this.predicate.value.match = value;
this.requestUpdate();
}
}
- setValue(e:any) {
+ private setValue(e: any) {
const value = e.detail.value;
- if(this.predicate && this.predicate.value && this.predicate.value.predicateType === 'string') {
+ if(this.predicate && this.predicate.value && this.predicate.value.predicateType === "string") {
this.predicate.value.value = value;
this.requestUpdate();
}
}
- deleteCondition (){
+ private deleteCondition() {
- let event = new CustomEvent('when-condition:delete', {
+ const event = new CustomEvent("when-condition:delete", {
detail: { index: this.index },
bubbles: true,
composed: true });
@@ -126,15 +148,4 @@ class OrRuleWhenCondition extends LitElement {
this.requestUpdate();
}
- constructor() {
- super();
-
- this.addEventListener('asset-attribute:changed', this.setAssetAttribute);
- this.addEventListener('operator:changed', this.setOperator);
- this.addEventListener('or-input:changed', this.setValue);
-
- }
-
-
}
-
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 6a6020a46..d0849a279 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
@@ -1,46 +1,30 @@
-import {html, LitElement, property, customElement, PropertyValues} from 'lit-element';
+import {html, LitElement, property, customElement, PropertyValues} from "lit-element";
-import {style} from './style';
-import {Rule, RuleTrigger, AttributePredicate, BaseAssetQueryMatch, NewAssetQuery, AttributeDescriptor,
- BaseAssetQueryOperator} from "@openremote/model";
+import {style} from "./style";
+import {Rule, AttributePredicate} from "@openremote/model";
-import '../or-rule-when-condition';
+import "../or-rule-when-condition";
+import {defaultPredicate, defaultWhenCondition, rulesEditorConfig} from "../const/rule-config";
-
-const defaultWhenCondition:RuleTrigger = {
- "asset": {
- "types": [{
- "predicateType": "string",
- "match": BaseAssetQueryMatch.EXACT,
- "value": "urn:openremote:asset:kmar:flight"
- }
- ],
- "attributes": {
- "predicates": []
- }
- }
-};
-
-const defaultPredicate:AttributePredicate = {
- name: {
- predicateType: "string",
- match: BaseAssetQueryMatch.EXACT,
- value: "airlineIata"
- },
- value: {
- predicateType: "string",
- match: BaseAssetQueryMatch.EXACT
- }
-
-};
-
-@customElement('or-rule-when')
+@customElement("or-rule-when")
class OrRuleWhen extends LitElement {
static get styles() {
return [
style
- ]
+ ];
+ }
+
+ @property({type: Object})
+ public rule?: Rule;
+
+ @property({type: Array})
+ public predicates?: AttributePredicate[] = [];
+
+ constructor() {
+ super();
+ this.addEventListener("when-condition:delete", this.deleteWhenCondition);
+
}
protected render() {
@@ -50,48 +34,34 @@ class OrRuleWhen extends LitElement {
<h3>Als..</h3>
<div class="rule-when-container bg-white shadow">
${this.rule && this.rule.when && this.rule.when.asset && this.rule.when.asset.attributes && this.rule.when.asset.attributes.predicates ? html`
- ${this.rule.when.asset.attributes.predicates.map((predicate:AttributePredicate, index) => {
+ ${this.rule.when.asset.attributes.predicates.map((predicate: AttributePredicate, index) => {
return html`
- <or-rule-when-condition index="${index}" .predicate="${predicate}" .attributeDescriptors="${this.attributeDescriptors}"></or-rule-when-condition>
+ <or-rule-when-condition index="${index}" .predicate="${predicate}"></or-rule-when-condition>
<span class="rule-additional">&</span>
- `
- })}
- `: ``}
- <a class="button-add" @click="${this.addWhenCondition}">+</a>
+ `; })}
+ ` : ``}
+
+ ${rulesEditorConfig.controls.addWhenCondition ? html`
+ <a class="button-add" @click="${this.addWhenCondition}">+</a>
+ ` : ``}
</div>
</div>
`;
}
- @property({type: Object})
- rule?: Rule;
-
- @property({type: Array})
- predicates?: AttributePredicate[] = [];
-
- @property({type: Array})
- public attributeDescriptors?: AttributeDescriptor[];
-
-
- constructor() {
- super();
- this.addEventListener('when-condition:delete', this.deleteWhenCondition);
-
- }
-
protected updated(_changedProperties: PropertyValues): void {
super.updated(_changedProperties);
- if(this.rule && !this.rule.when) {
+ if (this.rule && !this.rule.when) {
this.rule.when = defaultWhenCondition;
- if(this.rule!.when!.asset!.attributes!.predicates!.length === 0) {
+ if (this.rule!.when!.asset!.attributes!.predicates!.length === 0) {
this.addPredicate();
}
this.requestUpdate();
}
}
- addWhenCondition () {
- if(this.rule && !this.rule.when) {
+ private addWhenCondition() {
+ if (this.rule && !this.rule.when) {
this.rule.when = defaultWhenCondition;
}
@@ -100,20 +70,19 @@ class OrRuleWhen extends LitElement {
}
- addPredicate() {
- if(this.rule && this.rule.when && this.rule.when.asset && this.rule.when.asset.attributes && this.rule.when.asset.attributes.predicates) {
+ private addPredicate() {
+ if (this.rule && this.rule.when && this.rule.when.asset && this.rule.when.asset.attributes && this.rule.when.asset.attributes.predicates) {
this.rule.when.asset.attributes.predicates.push(defaultPredicate);
}
}
- deleteWhenCondition (e:any) {
+ private deleteWhenCondition(e: any) {
const index = e.detail.index;
- if(this.rule && this.rule.when && this.rule.when.asset && this.rule.when.asset.attributes && this.rule.when.asset.attributes.predicates) {
+ if (this.rule && this.rule.when && this.rule.when.asset && this.rule.when.asset.attributes && this.rule.when.asset.attributes.predicates) {
this.rule.when.asset.attributes.predicates.splice(index, 1);
this.requestUpdate();
}
}
}
-
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 6254628db..191d0b8bd 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,12 +1,11 @@
-import {html, LitElement, customElement, property} from "lit-element";
+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";
-const Test = {
- STRING: {name: "flightProfile", icon: "file-text-o", valueType: ValueType.STRING},
- NUMBER: {name: ""}
-};
+import {attributeDescriptors} from "../../const/attribute-descriptors";
+import {rulesEditorConfig} from "../../const/rule-config";
+
@customElement("or-select-asset-attribute")
class OrSelectAssetAttribute extends LitElement {
@@ -17,7 +16,11 @@ class OrSelectAssetAttribute extends LitElement {
public assetType: string = "";
@property({type: Array})
- public attributeDescriptors?: AttributeDescriptor[];
+ public attributeDescriptors?: AttributeDescriptor[] = attributeDescriptors;
+
+ // TODO replace with type from rulesEditor config?
+ @property({type: Array})
+ public options?: any[];
@property({type: String})
public value: any;
@@ -56,7 +59,7 @@ class OrSelectAssetAttribute extends LitElement {
// TODO types should be based on rules-config
return html`
<select ?disabled="${this.disabled}" id="or-select-asset-attribute" @change="${this.onChange}">
- ${this.attributeDescriptors ? this.attributeDescriptors.map((attribute: AttributeDescriptor) => {
+ ${this.options ? this.options.map((attribute: AttributeDescriptor) => {
return html`
<option ?selected="${attribute.name === this.value}" value="${attribute.name}">${attribute.name}</option>
`;
@@ -64,4 +67,17 @@ class OrSelectAssetAttribute extends LitElement {
</select>
`;
}
+
+ protected firstUpdated(_changedProperties: PropertyValues): void {
+ super.firstUpdated(_changedProperties);
+ if (!this.attributeDescriptors) {
+ return;
+ }
+
+ this.options = this.attributeDescriptors.filter((obj) => {
+ return obj.name && rulesEditorConfig.options.attributeValueDescriptors.hasOwnProperty(obj.name);
+ });
+
+ }
+
}