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
Updated rules editor to work with latest JSON rules model
Rich Turnera811f859f61a
diff --git a/ui/component/or-rules-editor/src/const/rule-config.ts b/ui/component/or-rules-editor/src/const/rule-config.tsindex 88b0a3db6..22c377541 100644--- a/ui/component/or-rules-editor/src/const/rule-config.ts+++ b/ui/component/or-rules-editor/src/const/rule-config.ts@@ -8,7 +8,8 @@ import {RuleActionUnion,RuleActionUpdateAttributeUpdateAction,RuleTrigger,- AttributePredicate+ AttributePredicate,+ RuleCondition} from "@openremote/model";import {airlines, airports, countries, languages, regions} from "./resources";@@ -49,7 +50,49 @@ export const rulesEditorConfig = {export const ruleTemplate: Rule = {name: "",when: undefined,- then: undefined+ then: undefined,+ otherwise: [+ {+ action: "update-attribute",+ updateAction: RuleActionUpdateAttributeUpdateAction.DELETE,+ attributeName: "flightProfiles",+ key: "%RULESET_ID%"+ }+ ],+ onStop: [+ {+ action: "update-attribute",+ updateAction: RuleActionUpdateAttributeUpdateAction.DELETE,+ attributeName: "flightProfiles",+ key: "%RULESET_ID%",+ target: {+ assets: {+ types: [+ {+ predicateType: "string",+ match: BaseAssetQueryMatch.EXACT,+ value: "urn:openremote:asset:kmar:flight"+ }+ ],+ attributes: {+ predicates: [+ {+ name: {+ predicateType: "string",+ match: BaseAssetQueryMatch.EXACT,+ value: "flightProfiles"+ },+ value: {+ predicateType: "object-value-key",+ key: "%RULESET_ID%"+ }+ }+ ]+ }+ }+ }+ }+ ]};export const rulesetTemplate: TenantRuleset = {@@ -61,7 +104,6 @@ export const rulesetTemplate: TenantRuleset = {rules: JSON.stringify({rules: [ruleTemplate]})};-export const defaultAssetType: NewAssetQuery = {types: [{predicateType: "string",@@ -78,24 +120,27 @@ export const defaultThenCondition: RuleActionUnion = {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 defaultWhenCondition: RuleCondition<RuleTrigger> = {+ predicates: [+ {+ assets: {+ types: [{+ predicateType: "string",+ match: BaseAssetQueryMatch.EXACT,+ value: "urn:openremote:asset:kmar:flight"+ }+ ],+ attributes: {+ predicates: []+ }+ }}- }+ ]};export const defaultPredicate: AttributePredicate = {@@ -109,4 +154,4 @@ export const defaultPredicate: AttributePredicate = {match: BaseAssetQueryMatch.EXACT}-};\ No newline at end of file+};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.tsindex 4c89154e9..3c2756675 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@@ -24,7 +24,6 @@ class OrRuleWhen extends LitElement {@property({type: Array})public predicates?: AttributePredicate[] = [];-constructor() {super();this.addEventListener("when-condition:delete", this.deleteWhenCondition);@@ -37,10 +36,10 @@ class OrRuleWhen extends LitElement {<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.types && this.rule.when.asset.attributes && this.rule.when.asset.attributes.predicates ? html`- ${this.rule.when.asset.attributes.predicates.map((predicate: AttributePredicate, index) => {+ ${this.rule && this.rule.when && this.rule.when.predicates && this.rule.when.predicates.length > 0 && this.rule.when.predicates[0].assets && this.rule.when.predicates[0].assets.types && this.rule.when.predicates[0].assets.attributes && this.rule.when.predicates[0].assets.attributes.predicates ? html`+ ${this.rule.when.predicates[0].assets.attributes.predicates.map((predicate: AttributePredicate, index) => {return html`- <or-rule-when-condition index="${index}" .assetType="${this.rule!.when!.asset!.types![0].value}" .predicate="${predicate}"></or-rule-when-condition>+ <or-rule-when-condition index="${index}" .assetType="${this.rule!.when!.predicates![0]!.assets!.types![0].value}" .predicate="${predicate}"></or-rule-when-condition>`; })}` : ``}@@ -59,7 +58,7 @@ class OrRuleWhen extends LitElement {super.updated(_changedProperties);if (this.rule && !this.rule.when) {this.rule.when = cloneDeep(defaultWhenCondition);- if (this.rule!.when!.asset!.attributes!.predicates!.length === 0) {+ if (this.rule.when.predicates![0].assets!.attributes!.predicates!.length === 0) {this.addPredicate();}this.requestUpdate();@@ -77,10 +76,10 @@ class OrRuleWhen extends LitElement {}private addPredicate() {- 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.predicates && this.rule.when.predicates.length > 0 && this.rule.when.predicates[0].assets && this.rule.when.predicates[0].assets.attributes && this.rule.when.predicates[0].assets.attributes.predicates) {const newPredicate = cloneDeep(defaultPredicate);- this.rule.when.asset.attributes.predicates.push(newPredicate);+ this.rule.when.predicates[0].assets.attributes.predicates.push(newPredicate);}}@@ -88,8 +87,8 @@ class OrRuleWhen extends LitElement {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) {- this.rule.when.asset.attributes.predicates.splice(index, 1);+ if (this.rule && this.rule.when && this.rule.when.predicates && this.rule.when.predicates.length > 0 && this.rule.when.predicates[0].assets && this.rule.when.predicates[0].assets.attributes && this.rule.when.predicates[0].assets.attributes.predicates) {+ this.rule.when.predicates[0].assets.attributes.predicates.splice(index, 1);this.requestUpdate();}}