Skip to content

armgit / core

Public Imported from GitHub
0

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

UI updates: minor or-rules, or-icon and or-input

Rich Turner9969cda51f12
diff --git a/ui/component/or-icon/src/index.ts b/ui/component/or-icon/src/index.ts
index 93d7e008c..512144cad 100644
--- a/ui/component/or-icon/src/index.ts
+++ b/ui/component/or-icon/src/index.ts
@@ -12,32 +12,37 @@ const _iconSets = new ORIconSets();
export const IconSets = _iconSets;
+// language=CSS
+const style = css`
+
+ :host {
+ --internal-or-icon-width: var(--or-icon-width, 24px);
+ --internal-or-icon-height: var(--or-icon-height, 24px);
+ --internal-or-icon-fill: var(--or-icon-fill, currentColor);
+ --internal-or-icon-stroke: var(--or-icon-fill, none);
+ --internal-or-icon-stroke-width: var(--or-icon-stroke-width, 0);
+
+ display: inline-block;
+ position: relative;
+ vertical-align: text-bottom;
+ fill: var(--internal-or-icon-fill);
+ stroke: var(--internal-or-icon-stroke);
+ stroke-width: var(--internal-or-icon-stroke-width);
+ width: var(--internal-or-icon-width);
+ height: var(--internal-or-icon-height);
+ }
+
+ :host([hidden]) {
+ display: none;
+ }
+`;
+
@customElement("or-icon")
export class OrIcon extends LitElement {
- static styles = css`
- :host {
-
- --internal-or-icon-width: var(--or-icon-width, 24px);
- --internal-or-icon-height: var(--or-icon-height, 24px);
- --internal-or-icon-fill: var(--or-icon-fill, currentColor);
- --internal-or-icon-stroke: var(--or-icon-fill, none);
- --internal-or-icon-stroke-width: var(--or-icon-stroke-width, 0);
-
- display: inline-block;
- position: relative;
- vertical-align: text-bottom;
- fill: var(--internal-or-icon-fill);
- stroke: var(--internal-or-icon-stroke);
- stroke-width: var(--internal-or-icon-stroke-width);
- width: var(--internal-or-icon-width);
- height: var(--internal-or-icon-height);
- }
-
- :host([hidden]) {
- display: none;
- }
- `;
+ static get styles() {
+ return style;
+ }
@property({type: String, reflect: true})
icon?: string;
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index 553b4d400..5590dfee3 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -10,7 +10,7 @@ import {MDCSelect, MDCSelectEvent, } from "@material/select";
import {MDCFormField, MDCFormFieldInput} from "@material/form-field";
import {MDCIconButtonToggle, MDCIconButtonToggleEventDetail} from "@material/icon-button";
import moment from "moment";
-import {DefaultColor1, DefaultColor4} from "@openremote/core";
+import {DefaultColor1, DefaultColor4, DefaultColor8} from "@openremote/core";
// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling
const buttonStyle = require("!!raw-loader!@material/button/dist/mdc.button.css");
@@ -86,7 +86,7 @@ const style = css`
:host {
display: inline-block;
--internal-or-input-color: var(--or-input-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));
- --internal-or-input-text-color: var(--or-input-text-color, var(--or-app-color1, inherit));
+ --internal-or-input-text-color: var(--or-input-text-color, var(--or-app-color1, ${unsafeCSS(DefaultColor8)}));
--mdc-theme-primary: var(--internal-or-input-color);
--mdc-theme-on-primary: var(--internal-or-input-text-color);
@@ -143,10 +143,6 @@ const style = css`
--or-icon-fill: var(--internal-or-input-color);
}
- .mdc-icon-button {
- --or-icon-fill: var(--internal-or-input-text-color);
- }
-
.mdc-icon-button {
padding: 0;
}
@@ -179,6 +175,9 @@ export class OrInput extends LitElement {
];
}
+ @property({type: Boolean})
+ public focused?: boolean;
+
@property()
public value?: any;
@@ -622,6 +621,10 @@ export class OrInput extends LitElement {
this.type = InputType.JSON;
}
}
+
+ if (this.focused && this._mdcComponent && typeof((this._mdcComponent as any).focus) === "function") {
+ (this._mdcComponent as any).focus();
+ }
}
protected renderOutlined(labelTemplate: TemplateResult | "") {
diff --git a/ui/component/or-rules/src/index.ts b/ui/component/or-rules/src/index.ts
index cca0a5bfe..2b009f533 100644
--- a/ui/component/or-rules/src/index.ts
+++ b/ui/component/or-rules/src/index.ts
@@ -643,7 +643,7 @@ export class OrRules extends translate(i18next)(LitElement) {
}
protected _onRuleSelectionChanged(event: OrRulesSelectionChangedEvent) {
- this._activeRuleset = event.detail.length == 1 ? event.detail[0] : undefined;
+ this._activeRuleset = event.detail.length === 1 ? {...event.detail[0]} : undefined;
}
protected _onRuleSaveStart(event: OrRulesSaveStartEvent) {
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
index 603954f5e..353bed2bf 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts
@@ -19,6 +19,7 @@ import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";
const style = css`
:host {
display: flex;
+ align-items: center;
}
:host > * {
@@ -130,7 +131,7 @@ export class OrRuleActionAttribute extends LitElement {
}
return html`
- <or-input id="matchSelect" type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" ?readonly="${this.readonly}" .options="${idOptions}" .value="${idValue}"></or-input>
+ <or-input id="matchSelect" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" ?readonly="${this.readonly}" .options="${idOptions}" .value="${idValue}"></or-input>
<or-input id="attributeSelect" .label="${i18next.t("attribute")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionAttributeName(e.detail.value)}" ?readonly="${this.readonly}" .options="${attributes}" .value="${this.action.attributeName}"></or-input>
${inputTemplate ? inputTemplate(this.action.value) : ``}
`;
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-condition.ts b/ui/component/or-rules/src/json-viewer/or-rule-condition.ts
index f623e2537..dea87287f 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-condition.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-condition.ts
@@ -172,7 +172,7 @@ class OrRuleCondition extends LitElement {
}
typeTemplate = html`
- <div id="type" style="--or-input-text-color: #${buttonColor}">
+ <div id="type" style="color: #${buttonColor}">
${getContentWithMenuTemplate(
html`<or-input class="menu-button" type="${InputType.BUTTON}" .icon="${buttonIcon || ""}"></or-input>`,
getWhenTypesMenu(this.config, this.assetDescriptors),
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-json-viewer.ts b/ui/component/or-rules/src/json-viewer/or-rule-json-viewer.ts
index 18788bb68..ac385fc96 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-json-viewer.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-json-viewer.ts
@@ -83,6 +83,10 @@ export class OrRuleJsonViewer extends translate(i18next)(LitElement) implements
}
public set ruleset(ruleset: RulesetUnion) {
+ if (this._ruleset === ruleset) {
+ return;
+ }
+
this._ruleset = ruleset;
if (!ruleset.rules) {
@@ -180,13 +184,13 @@ export class OrRuleJsonViewer extends translate(i18next)(LitElement) implements
return;
}
- this._rule.name = this.ruleset.name;
+ this._rule.name = this._ruleset.name;
const jsonRules: JsonRulesetDefinition = {
rules: [this._rule]
};
- this.ruleset.rules = JSON.stringify(jsonRules);
+ this._ruleset.rules = JSON.stringify(jsonRules);
}
public validate(): boolean {
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.ts
index 05f91c554..0514fad25 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
@@ -168,7 +168,7 @@ class OrRuleThenOtherwise extends LitElement {
}
typeTemplate = html`
- <div style="--or-input-text-color: #${buttonColor}">
+ <div style="color: #${buttonColor}">
${getContentWithMenuTemplate(
html`<or-input class="menu-button" type="${InputType.BUTTON}" .icon="${buttonIcon || ""}"></or-input>`,
getActionTypesMenu(this.config, this.assetDescriptors),
diff --git a/ui/component/or-rules/src/or-rule-viewer.ts b/ui/component/or-rules/src/or-rule-viewer.ts
index c409d6832..6dba7bff2 100644
--- a/ui/component/or-rules/src/or-rule-viewer.ts
+++ b/ui/component/or-rules/src/or-rule-viewer.ts
@@ -12,7 +12,7 @@ import manager, {DefaultBoxShadow} from "@openremote/core";
import "./json-viewer/or-rule-json-viewer";
import "@openremote/or-input";
import {translate} from "@openremote/or-translate";
-import {InputType, OrInputChangedEvent} from "@openremote/or-input";
+import {InputType, OrInputChangedEvent, OrInput} from "@openremote/or-input";
import i18next from "i18next";
// language=CSS
@@ -78,13 +78,6 @@ export const style = css`
@customElement("or-rule-viewer")
export class OrRuleViewer extends translate(i18next)(LitElement) {
- constructor() {
- super();
-
- this.addEventListener(OrRulesRuleChangedEvent.NAME, this._onRuleChanged);
- this.addEventListener(OrRulesRuleUnsupportedEvent.NAME, this._onRuleUnsupported);
- }
-
static get styles() {
return [
style
@@ -115,8 +108,17 @@ export class OrRuleViewer extends translate(i18next)(LitElement) {
@query("#rule-viewer")
public view?: RuleView;
+ protected _focusName = false;
+
+ constructor() {
+ super();
+
+ this.addEventListener(OrRulesRuleChangedEvent.NAME, this._onRuleChanged);
+ this.addEventListener(OrRulesRuleUnsupportedEvent.NAME, this._onRuleUnsupported);
+ }
+
public get valid() {
- return this.ruleset && this.view && this._ruleValid && this.ruleset.name && this.ruleset.name.length >= 3 && this.ruleset.name.length > 255;
+ return this.ruleset && this.view && this._ruleValid && this.ruleset.name && this.ruleset.name.length >= 3 && this.ruleset.name.length < 255;
}
public shouldUpdate(_changedProperties: PropertyValues): boolean {
@@ -126,6 +128,8 @@ export class OrRuleViewer extends translate(i18next)(LitElement) {
if (!this.ruleset) {
this.modified = false;
this._ruleValid = false;
+ } else {
+ this._focusName = true;
}
}
return super.shouldUpdate(_changedProperties);
@@ -159,16 +163,16 @@ export class OrRuleViewer extends translate(i18next)(LitElement) {
return html`
<div class="wrapper">
<div id="rule-header">
- <or-input id="rule-name" .type="${InputType.TEXT}" .value="${this.ruleset ? this.ruleset.name : null}" ?disabled="${this._isReadonly()}" fullwidth required minlength="3" maxlength="255" @or-input-changed="${(e: OrInputChangedEvent) => this._changeName(e.detail.value)}"></or-input>
+ <or-input id="rule-name" .type="${InputType.TEXT}" ?focused="${this._focusName}" .value="${this.ruleset ? this.ruleset.name : null}" ?disabled="${this._isReadonly()}" fullwidth required minlength="3" maxlength="255" @or-input-changed="${(e: OrInputChangedEvent) => this._changeName(e.detail.value)}"></or-input>
<div id="rule-header-controls">
<span id="active-wrapper">
<or-translate value="active"></or-translate>
- <or-input .type="${InputType.SWITCH}" .value="${this.ruleset && this.ruleset.enabled}" ?disabled="${this._cannotSave()}" @or-input-changed="${this._toggleEnabled}"></or-input>
+ <or-input .type="${InputType.SWITCH}" .value="${this.ruleset && this.ruleset.enabled}" ?disabled="${!this.ruleset.id}" @or-input-changed="${this._toggleEnabled}"></or-input>
</span>
- <or-input .type="${InputType.BUTTON}" id="save-btn" .label="${i18next.t("save")}" raised ?disabled="${this._cannotSave()}" @or-input-changed="${this._doSave}"></or-input>
+ <or-input .type="${InputType.BUTTON}" id="save-btn" .label="${i18next.t("save")}" raised ?disabled="${this._cannotSave()}" @click="${this._doSave}" @or-input-changed="${this._doSave}"></or-input>
</div>
</div>
@@ -196,6 +200,7 @@ export class OrRuleViewer extends translate(i18next)(LitElement) {
protected _changeName(name: string) {
if (this.ruleset && this.ruleset.name !== name) {
this.ruleset.name = name;
+ this.modified = true;
this.requestUpdate();
}
}
@@ -249,6 +254,7 @@ export class OrRuleViewer extends translate(i18next)(LitElement) {
protected _toggleEnabled() {
if (this.ruleset) {
this.ruleset.enabled = !this.ruleset.enabled;
+ this.modified = true;
this.requestUpdate();
}
}