Skip to content
Permalink
Browse files

WIP Rules editor

  • Loading branch information...
robin-dekkers committed Apr 9, 2019
1 parent 5c78a8b commit 1a454726300508d6f0db951d734a83df392350c7
@@ -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"
}
} ];
@@ -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
}

};
@@ -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();
Oops, something went wrong.

0 comments on commit 1a45472

Please sign in to comment.
You can’t perform that action at this time.