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
Add reset input to or-rules, improve responsiveness or-attribute-history
robindekkers4dd598ac9fc5
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.jsonindex f57a3d6d6..0b4958988 100644--- a/deployment/manager/shared/locales/en/or.json+++ b/deployment/manager/shared/locales/en/or.json@@ -115,5 +115,12 @@"string": "Text","operator": "Operator","area": "Area",- "timestamp": "Timestamp"+ "timestamp": "Timestamp",+ "frequency": "Frequency",+ "everyTime": "Every time",+ "onlyOnce": "Only once",+ "oncePerHour": "Once per hour",+ "oncePerDay": "Once per day",+ "oncePerWeek": "Once per week",+ "oncePerMonth": "Once per month"}diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.tsindex 0331e78ce..dc239f84a 100644--- a/ui/component/or-asset-viewer/src/index.ts+++ b/ui/component/or-asset-viewer/src/index.ts@@ -391,7 +391,19 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem--or-attribute-history-controls-margin: 0 0 0 204px;}- @media screen and (max-width: 769px) {+ @media screen and (max-width: 2028px) {+ #history-controls {+ position: unset;+ margin: 0 0 10px 0;+ }++ or-attribute-history {+ --or-attribute-history-controls-margin: 10px 0 0 0;+ --or-attribute-history-controls-margin-children: 0 20px 20px 0;+ }+ }++ @media screen and (max-width: 1700px) {#history-controls {position: unset;margin: 0 auto 10px auto;@@ -399,6 +411,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElemor-attribute-history {--or-attribute-history-controls-margin: 10px 0 0 0;+ --or-attribute-history-controls-margin-children: 0 auto 20px auto;}}</style>diff --git a/ui/component/or-attribute-history/src/index.ts b/ui/component/or-attribute-history/src/index.tsindex d01f18986..5fd2e49c6 100644--- a/ui/component/or-attribute-history/src/index.ts+++ b/ui/component/or-attribute-history/src/index.ts@@ -110,7 +110,8 @@ const style = css`:host {--internal-or-attribute-history-background-color: var(--or-attribute-history-background-color, var(--or-app-color2, ${unsafeCSS(DefaultColor2)}));--internal-or-attribute-history-text-color: var(--or-attribute-history-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));- --internal-or-attribute-history-controls-margin: var(--or-attribute-history-controls-margin, 0);+ --internal-or-attribute-history-controls-margin: var(--or-attribute-history-controls-margin, 0);+ --internal-or-attribute-history-controls-margin-children: var(--or-attribute-history-controls-margin-children, 0 auto 20px auto);--internal-or-attribute-history-graph-fill-color: var(--or-attribute-history-graph-fill-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));--internal-or-attribute-history-graph-fill-opacity: var(--or-attribute-history-graph-fill-opacity, 1);--internal-or-attribute-history-graph-line-color: var(--or-attribute-history-graph-line-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));@@ -160,7 +161,7 @@ const style = css`}#controls > * {- margin: 0 auto 20px auto;+ margin: var(--internal-or-attribute-history-controls-margin-children);}#ending-controls {diff --git a/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts b/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.tsindex 0b985d9ee..4c1e52933 100644--- a/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts+++ b/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts@@ -9,7 +9,7 @@ import {import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";-import {AssetDescriptor, JsonRule, RuleActionUnion, RuleActionNotification} from "@openremote/model";+import {AssetDescriptor, JsonRule, RuleActionUnion, RuleConditionReset} from "@openremote/model";import i18next from "i18next";import {InputType} from "@openremote/or-input";import {MenuItem} from "@openremote/or-mwc-components/dist/or-mwc-menu";@@ -66,6 +66,32 @@ function getActionTypesMenu(config?: RulesConfig, assetDescriptors?: AssetDescrireturn menu;}+type resetOptions = {+ [key: string]: string+}++const resetOptions:resetOptions = {+ "everyTime": "everyTime",+ "onlyOnce": "onlyOnce",+ "1h": "oncePerHour",+ "1d": "oncePerDay",+ "1w": "oncePerWeek",+ "1mn": "oncePerMonth"+};++function getResetMenu(config?: RulesConfig): MenuItem[] {++ const menu: MenuItem[] = [];++ menu.push(...Object.entries(resetOptions).map(([key, value]) => {+ const content = html`+ <span style="white-space: nowrap;">${i18next.t(value)}</span>+ `;+ return {content: content, value: key} as MenuItem+ }));++ return menu;+}// language=CSSconst style = css`@@ -102,6 +128,7 @@ const style = css`}or-panel {+ position: relative;margin: 10px 10px 20px 10px;}@@ -117,6 +144,13 @@ const style = css`.add-button-wrapper > * {margin-right: 6px;}++ .rule-reset {+ position: absolute;+ top: 5px;+ right: 0;+ }+`;@customElement("or-rule-then-otherwise")@@ -139,6 +173,38 @@ class OrRuleThenOtherwise extends translate(i18next)(LitElement) {return !this.config || !this.config.controls || this.config.controls.hideThenAddAction !== true;}+ protected ruleResetTemplate(reset: RuleConditionReset) {+ let resetTemplate: TemplateResult | string = ``;++ let buttonIcon = undefined;+ let buttonColor = "inherit";++ let value;++ if (!reset) value = "onlyOnce";+ else if (reset.valueChanges && reset.timestampChanges) value = "everyTime";+ else if (reset.timer) value = reset.timer;+ else if (this.config && this.config.json && this.config.json.rule && this.config.json.rule.reset) value = this.config.json.rule.reset.timer;+++ resetTemplate = html`+ <div style="color: #${buttonColor}; margin-right: 6px;">+ ${getContentWithMenuTemplate(+ html`<or-input type="${InputType.BUTTON}" label="${value ? i18next.t(resetOptions[value]) : i18next.t('frequency') }"></or-input>`,+ getResetMenu(this.config),+ value,+ (value: string) => this.setResetOption(value))}+ </div>+ `;++ return html`+ <div class="rule-reset">+ ${resetTemplate}+ </div>+ `;++ }+protected ruleActionTemplate(actions: RuleActionUnion[], action: RuleActionUnion) {const showTypeSelect = !this.config || !this.config.controls || this.config.controls.hideActionTypeOptions !== true;@@ -218,8 +284,9 @@ class OrRuleThenOtherwise extends translate(i18next)(LitElement) {return html`<div><or-panel .heading="${i18next.t("then")}...">+ ${this.ruleResetTemplate(this.rule.reset!)}+${!this.rule.then ? `` : this.rule.then.map((action: RuleActionUnion) => this.ruleActionTemplate(this.rule.then!, action))}-${this.thenAllowAdd ? html`<span class="add-button-wrapper">${getContentWithMenuTemplate(@@ -258,6 +325,33 @@ class OrRuleThenOtherwise extends translate(i18next)(LitElement) {}}+ protected setResetOption(value: string) {++ switch (value) {+ case "onlyOnce":+ delete this.rule.reset;+ break;+ case "everyTime":+ if (this.rule.reset) delete this.rule.reset.timer;+ this.rule.reset = {+ valueChanges: true,+ timestampChanges: true+ };+ break;+ default:+ if (this.rule.reset) {+ if (this.rule.reset.valueChanges) delete this.rule.reset.valueChanges;+ if (this.rule.reset.timestampChanges) delete this.rule.reset.timestampChanges;+ this.rule.reset.timer = value;+ } else {+ this.rule.reset = {timer: value};+ }+ break;+ }+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());+ this.requestUpdate();+ }+protected setActionType(actions: RuleActionUnion[], action: RuleActionUnion, value: string) {action.target = undefined;