Skip to content

armgit / core

Public Imported from GitHub
0

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

Rules Editor Visual Fixes

robindekkers96fb46cca7d4
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index 800a94a3c..7cec842af 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -5,10 +5,13 @@ import {orInputStyle} from './style';
class OrInput extends LitElement {
@property({type: String})
- type: string = 'text';
+ public type: string = "text";
@property({type: String})
- name: string = '';
+ public name: string = "";
+
+ @property({type: Boolean})
+ public required: boolean = false;
@property({type: String})
public value: string = "";
@@ -23,7 +26,7 @@ class OrInput extends LitElement {
protected render() {
return html`
- <input class="or-input" type="${this.type}" name="${this.name}" @change="${this.onChange}" .value="${this.value}" />
+ <input class="or-input" ?required="${this.required}" type="${this.type}" name="${this.name}" @change="${this.onChange}" .value="${this.value}" />
`;
}
diff --git a/ui/component/or-input/src/style.ts b/ui/component/or-input/src/style.ts
index 1f206e261..d0c1084b2 100644
--- a/ui/component/or-input/src/style.ts
+++ b/ui/component/or-input/src/style.ts
@@ -14,4 +14,6 @@ export const orInputStyle = css`
border-bottom: 2px solid #d5d5d5;
background-color: #f2f2f2;
}
+
+ input:focus:required:invalid { border-bottom: 2px solid red;}
`;
\ No newline at end of file
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 1f7cf1a49..88b0a3db6 100644
--- a/ui/component/or-rules-editor/src/const/rule-config.ts
+++ b/ui/component/or-rules-editor/src/const/rule-config.ts
@@ -18,23 +18,29 @@ export const rulesEditorConfig = {
addThenCondition: false,
},
options: {
- attributeValueDescriptors: {
- flightProfiles: {},
- airportIata: {
- options: airports
- },
- airlineIata: {
- options: airlines
- },
- originRegion: {
- options: regions
- },
- pax: {},
- languageCodes: {
- options: languages
- },
- countryCode: {
- options: countries
+ when: {
+ attributeValueDescriptors: {
+ airportIata: {
+ options: airports
+ },
+ airlineIata: {
+ options: airlines
+ },
+ originRegion: {
+ options: regions
+ },
+ passengerCapacity: {},
+ languageCodes: {
+ options: languages
+ },
+ countryCode: {
+ options: countries
+ }
+ }
+ },
+ then: {
+ attributeValueDescriptors: {
+ flightProfiles: {}
}
}
}
@@ -47,7 +53,7 @@ export const ruleTemplate: Rule = {
};
export const rulesetTemplate: TenantRuleset = {
- name: "New Rule",
+ name: "Nieuw Profiel",
type: "tenant",
lang: RulesetLang.JSON,
realm: openremote.getRealm(),
diff --git a/ui/component/or-rules-editor/src/index.ts b/ui/component/or-rules-editor/src/index.ts
index fb94974ad..672ef38d2 100644
--- a/ui/component/or-rules-editor/src/index.ts
+++ b/ui/component/or-rules-editor/src/index.ts
@@ -18,6 +18,7 @@ import "./or-rule-header";
import {style} from "./style";
import findIndex from "lodash-es/findIndex";
+import cloneDeep from "lodash-es/cloneDeep";
import {attributeDescriptors} from "./const/attribute-descriptors";
import {ruleTemplate, rulesetTemplate} from "./const/rule-config";
@@ -98,7 +99,7 @@ class OrRulesEditor extends translate(i18next)(LitElement) {
<or-rule-list .rulesets="${this.rulesets}" .ruleset="${this.ruleset}" ></or-rule-list>
<div class="bottom-toolbar">
<icon class="small-icon" @click="${this.deleteRule}"><or-icon icon="delete"></or-icon></icon>
- <icon class="small-icon" @click="${this.createRule}"><or-icon icon="plus"></or-icon></icon>
+ <icon style="margin-left: auto;" class="small-icon" @click="${this.createRule}"><or-icon icon="plus"></or-icon></icon>
</div>
</side-menu>
${this.ruleset ? html`
@@ -116,7 +117,7 @@ class OrRulesEditor extends translate(i18next)(LitElement) {
</or-body>
` : html`
<div class="center-center">
- <h3>Kies links een profiel of maakt een nieuw profiel aan.</h3>
+ <h3 style="font-weight: normal;">Kies links een profiel of maak een nieuw profiel aan.</h3>
<button style="margin: auto;" @click="${this.createRule}">profiel aanmaken</button>
</div>
`}
@@ -137,15 +138,16 @@ class OrRulesEditor extends translate(i18next)(LitElement) {
this.rulesets = response.data;
if (this.ruleset && this.rulesets) {
const index = findIndex(this.rulesets, ["id", this.ruleset.id]);
+ console.log(index, this.ruleset.id);
let updatedRuleset;
// ID is not found when a new ruleset is added
- if (index > 0) {
+ if (index > -1) {
updatedRuleset = this.rulesets[index];
+ console.log(updatedRuleset, this.rulesets[index]);
} else {
updatedRuleset = this.rulesets[this.rulesets.length - 1];
}
-
this.ruleset = updatedRuleset;
this.computeRuleset();
}
@@ -156,17 +158,18 @@ class OrRulesEditor extends translate(i18next)(LitElement) {
});
}
- private createRule() {
- const shouldContinue = this.shouldShowModal();
+ private async createRule() {
+ const shouldContinue = await this.shouldShowModal();
if (!shouldContinue) {
return;
}
if (this.rulesets) {
- const newRule = {...rulesetTemplate};
+ const newRule = cloneDeep(rulesetTemplate);
this.rulesets = [...this.rulesets, rulesetTemplate];
this.ruleset = newRule;
- this.computeRuleset();
+ this.computeRuleset()
+ // this.readRules();
}
}
@@ -207,7 +210,7 @@ class OrRulesEditor extends translate(i18next)(LitElement) {
}
const id = this.ruleset.id;
- confirmDialog("Weet je zeker dat je deze regel wilt verwijderen?")
+ confirmDialog("Als je doorgaat worden je veranderingen niet opgeslagen. Doorgaan zonder opslaan?")
.then(() => {
rest.api.RulesResource.deleteTenantRuleset(id).then(() => {
this.cleanRule();
@@ -239,31 +242,24 @@ class OrRulesEditor extends translate(i18next)(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 = {...ruleTemplate};
+ this.rule = cloneDeep(ruleTemplate);
this.rule.name = this.ruleset.name;
}
this.requestUpdate();
}
- private setActiveRule(e: any) {
- const shouldContinue = this.shouldShowModal();
- if (!shouldContinue) {
- return;
- }
- this.ruleset = e.detail.ruleset;
- this.computeRuleset();
+ private async setActiveRule(e: any) {
+ const shouldContinue = await this.shouldShowModal();
+ if (!shouldContinue) {
+ return;
+ }
+ this.ruleset = e.detail.ruleset;
+ this.readRules();
}
private shouldShowModal() {
if (this.ruleset && this.ruleset.rules !== JSON.stringify({rules: [this.rule]})) {
- confirmDialog("Weet je zeker dat je deze regel niet wilt opslaan?")
- .then(() => {
- this.readRules();
- return true;
- })
- .catch(() => {
- return false;
- });
+ return confirmDialog("Als je doorgaat worden je veranderingen niet opgeslagen. Doorgaan zonder opslaan?");
} else {
return true;
}
diff --git a/ui/component/or-rules-editor/src/or-rule-header/index.ts b/ui/component/or-rules-editor/src/or-rule-header/index.ts
index 794b70004..138bad4ab 100644
--- a/ui/component/or-rules-editor/src/or-rule-header/index.ts
+++ b/ui/component/or-rules-editor/src/or-rule-header/index.ts
@@ -35,7 +35,7 @@ class OrRuleHeader extends LitElement {
<input @change="${this.changeName}" type="text" .value="${this.ruleset ? this.ruleset.name : null}" />
<div class="layout horizontal" style="margin-left: auto;">
- <span style="margin: 9px 0;">Actief</span>
+ <span style="margin: 9px 0;" class="toggle-label" ?data-disabled="${!this.ruleset!.id}">Actief</span>
<label class="switch" ?data-disabled="${!this.ruleset!.id}">
<input @change="${this.toggleEnabled}" ?disabled="${!this.ruleset!.id}" ?checked="${this.ruleset!.enabled}" type="checkbox">
<span class="slider round"></span>
diff --git a/ui/component/or-rules-editor/src/or-rule-header/style.ts b/ui/component/or-rules-editor/src/or-rule-header/style.ts
index f39597681..fdbc94851 100644
--- a/ui/component/or-rules-editor/src/or-rule-header/style.ts
+++ b/ui/component/or-rules-editor/src/or-rule-header/style.ts
@@ -38,6 +38,7 @@ export const style = css`
height: 40px;
border-radius: 5px;
+ border: none;
background-color: var(--app-primary-color);
margin-left: auto;
color: var(--app-white-color, #FFF);
@@ -66,7 +67,7 @@ export const style = css`
display: inline-block;
width: 36px;
height: 14px;
- margin: 13px 20px
+ margin: 13px 30px 13px 10px;
}
/* Hide default HTML checkbox */
@@ -88,7 +89,15 @@ export const style = css`
-webkit-transition: .4s;
transition: .4s;
}
-
+
+ .switch[data-disabled] {
+ cursor: auto;
+ }
+
+ .toggle-label[data-disabled] {
+ color: #e4e4e4;
+ }
+
.switch[data-disabled] .slider::before {
background-color: #e4e4e4;
}
diff --git a/ui/component/or-rules-editor/src/or-rule-list/index.ts b/ui/component/or-rules-editor/src/or-rule-list/index.ts
index 0090ddde6..aeb2545a8 100644
--- a/ui/component/or-rules-editor/src/or-rule-list/index.ts
+++ b/ui/component/or-rules-editor/src/or-rule-list/index.ts
@@ -31,6 +31,14 @@ class OrRulesList extends LitElement {
.list-container {
}
+ .list-title {
+ display: block;
+ padding: 17px 33px 10px 33px;
+ text-transform: uppercase;
+ color: var(--app-grey-color);
+ opacity: 0.87;
+ }
+
.list-item {
text-decoration: none;
height: 24px;
@@ -74,6 +82,7 @@ class OrRulesList extends LitElement {
}
</style>
<div class="list-container">
+ <strong class="list-title">Profielen</strong>
${this.rulesets && this.rulesets.map((ruleset: TenantRuleset, index:number) => {
return html`
<a ?selected="${this.ruleset && ruleset.id === this.ruleset.id}" class="d-flex list-item" @click="${() => this.setActiveRule(this.rulesets[index])}">
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 efd249ee2..1c232bcce 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
@@ -49,8 +49,8 @@ class OrRuleThenCondition extends LitElement {
<or-select-asset-action>
<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 value="EQUAL"></or-select-operator>
+ <or-select-asset-attribute type="then" disabled value="${this.condition.attributeName}"></or-select-asset-attribute>
+ <or-select-operator hidden disabled value="EQUAL"></or-select-operator>
${this.createInputControl(this.condition!)}
` : ``}
</div>
diff --git a/ui/component/or-rules-editor/src/or-rule-then-condition/style.ts b/ui/component/or-rules-editor/src/or-rule-then-condition/style.ts
index 0803373ec..6a644256a 100644
--- a/ui/component/or-rules-editor/src/or-rule-then-condition/style.ts
+++ b/ui/component/or-rules-editor/src/or-rule-then-condition/style.ts
@@ -1,6 +1,6 @@
import {css} from 'lit-element';
-
+// language=CSS
export const style = css`
:host {
display: block;
@@ -20,7 +20,20 @@ export const style = css`
margin-right: 20px;
}
- .rule-container > *:last-child {
+ .rule-container > [hidden] {
+ display: none;
+ }
+
+ .rule-container > or-select-asset-action {
+ margin-right: 10px;
+ }
+
+ .rule-container > or-select-asset-action or-icon {
+ margin-top: 7px;
+ }
+
+ .rule-container > *:last-child {
margin-right: 0;
- }
+ }
+
`;
\ No newline at end of file
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 db52e9420..866e8fa3a 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
@@ -7,6 +7,8 @@ import {Rule, RuleActionUnion,
import "../or-rule-then-condition";
import {rulesEditorConfig, defaultThen, defaultThenCondition} from "../const/rule-config";
+import cloneDeep from "lodash-es/cloneDeep";
+
@customElement("or-rule-then")
class OrRuleThen extends LitElement {
@@ -54,19 +56,19 @@ class OrRuleThen extends LitElement {
protected updated(_changedProperties: PropertyValues): void {
super.updated(_changedProperties);
if (this.rule && !this.rule.then) {
- this.rule.then = [...defaultThen];
+ this.rule.then = cloneDeep(defaultThen);
this.requestUpdate();
}
}
private addThenCondition() {
if (this.rule && !this.rule.then) {
- this.rule.then = [...defaultThen];
+ this.rule.then = cloneDeep(defaultThen);
}
if (this.rule && this.rule.then) {
- this.rule.then.push({...defaultThenCondition});
+ this.rule.then.push(cloneDeep(defaultThenCondition));
this.requestUpdate();
}
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 5ad48429e..b578affd7 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
@@ -65,18 +65,18 @@ class OrRuleWhenCondition extends LitElement {
</or-select-asset-type>
${this.predicate.name ? html`
- <or-select-asset-attribute value="${this.predicate.name.value}"></or-select-asset-attribute>
+ <or-select-asset-attribute type="when" value="${this.predicate.name.value}"></or-select-asset-attribute>
${this.predicate.value && this.predicate.value.predicateType === "string" ? html`
${this.predicate.name.value ? html`
- <or-select-operator .type="${this.getAttributeDescriptor(this.predicate.name.value)!.valueDescriptor}" .value="${this.predicate.value.match}"></or-select-operator>
+ <or-select-operator .type="${this.getAttributeDescriptor(this.predicate.name.value)!.valueDescriptor!.valueType}" .value="${this.predicate.value.match}"></or-select-operator>
` : ``}
${this.predicate.name.value && this.predicate.value.match ? html`
${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 : null}"></or-input>
+ <or-input required type="${this.getAttributeDescriptor(this.predicate.name.value)!.valueDescriptor!.valueType}" .value="${this.predicate.value.value ? this.predicate.value.value : null}"></or-input>
`}
` : ``}
@@ -140,7 +140,7 @@ class OrRuleWhenCondition extends LitElement {
}
private getAttributeConfig(name: string) {
- const attributeValueDescriptors: any = rulesEditorConfig.options.attributeValueDescriptors;
+ const attributeValueDescriptors: any = rulesEditorConfig.options.when.attributeValueDescriptors;
if (attributeValueDescriptors) {
const attributeConfig = attributeValueDescriptors[name];
diff --git a/ui/component/or-rules-editor/src/or-rule-when-condition/style.ts b/ui/component/or-rules-editor/src/or-rule-when-condition/style.ts
index 3820743b6..7db4ff230 100644
--- a/ui/component/or-rules-editor/src/or-rule-when-condition/style.ts
+++ b/ui/component/or-rules-editor/src/or-rule-when-condition/style.ts
@@ -20,6 +20,14 @@ export const style = css`
margin-right: 20px;
}
+ .rule-container > or-select-asset-type {
+ margin-right: 10px;
+ }
+
+ .rule-container > or-select-asset-type or-icon {
+ margin-top: 7px;
+ }
+
.rule-container > *:last-child {
margin-right: 0;
}
@@ -30,6 +38,11 @@ export const style = css`
.small-icon {
cursor: pointer;
- fill: var(--app-grey-color, #F5F5F5);
+ fill: rgb(213, 213, 213);
}
+
+ .small-icon:hover {
+ fill: var(--app-primary-color);
+ }
+
`;
\ 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.ts
index 31b70478d..291b1a327 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
@@ -6,6 +6,8 @@ import {Rule, AttributePredicate} from "@openremote/model";
import "../or-rule-when-condition";
import {defaultPredicate, defaultWhenCondition, rulesEditorConfig} from "../const/rule-config";
+import cloneDeep from "lodash-es/cloneDeep";
+
@customElement("or-rule-when")
class OrRuleWhen extends LitElement {
@@ -52,7 +54,7 @@ class OrRuleWhen extends LitElement {
protected updated(_changedProperties: PropertyValues): void {
super.updated(_changedProperties);
if (this.rule && !this.rule.when) {
- this.rule.when = {...defaultWhenCondition};
+ this.rule.when = cloneDeep(defaultWhenCondition);
if (this.rule!.when!.asset!.attributes!.predicates!.length === 0) {
this.addPredicate();
}
@@ -62,7 +64,7 @@ class OrRuleWhen extends LitElement {
private addWhenCondition() {
if (this.rule && !this.rule.when) {
- this.rule.when = {...defaultWhenCondition};
+ this.rule.when = cloneDeep(defaultWhenCondition);
}
this.addPredicate();
@@ -72,7 +74,9 @@ 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) {
- this.rule.when.asset.attributes.predicates.push({...defaultPredicate});
+ const newPredicate = cloneDeep(defaultPredicate);
+
+ this.rule.when.asset.attributes.predicates.push(newPredicate);
}
}
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 c0385bed8..0a44d37ec 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
@@ -12,6 +12,9 @@ class OrSelectAssetAttribute extends LitElement {
@property({type: String})
public assetType: string = "";
+ @property({type: String})
+ public type: "when" | "then" = "when";
+
@property({type: Array})
public attributeDescriptors?: AttributeDescriptor[] = attributeDescriptors;
@@ -72,7 +75,13 @@ class OrSelectAssetAttribute extends LitElement {
}
this.options = this.attributeDescriptors.filter((attributeDescriptor) => {
- return attributeDescriptor.attributeName && rulesEditorConfig.options.attributeValueDescriptors.hasOwnProperty(attributeDescriptor.attributeName);
+ if (this.type === "when") {
+ return attributeDescriptor.attributeName && rulesEditorConfig.options.when.attributeValueDescriptors.hasOwnProperty(attributeDescriptor.attributeName);
+ }
+
+ if (this.type === "then") {
+ return attributeDescriptor.attributeName && rulesEditorConfig.options.then.attributeValueDescriptors.hasOwnProperty(attributeDescriptor.attributeName);
+ }
});
}