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
UI updates: bug fixes and improvements
Rich Turneree4fbfa1f1e9
diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.tsindex 24624d424..8bc51055d 100644--- a/ui/component/core/src/util.ts+++ b/ui/component/core/src/util.ts@@ -469,7 +469,7 @@ export function getMetaValueAsString(metaItem: NameValueHolder<any> | undefined,function getValueHolderValueAsString(nameValueHolder: NameValueHolder<any> | undefined, descriptor: AbstractNameValueDescriptorHolder | string | undefined, assetType: string | undefined, showUnits: boolean, isAttribute: boolean, fallback?: string): string {- let valueStr = getValueAsString(nameValueHolder ? nameValueHolder.value : undefined, () => getValueFormatConstraintOrUnits(WellknownMetaItems.FORMAT, nameValueHolder, descriptor, assetType, isAttribute), fallback);+ let valueStr = getValueAsString(nameValueHolder ? nameValueHolder.value : undefined, () => getValueFormatConstraintOrUnits(WellknownMetaItems.FORMAT, nameValueHolder, descriptor, assetType, isAttribute), undefined, fallback);if (showUnits) {const units: string[] | undefined = getValueFormatConstraintOrUnits(WellknownMetaItems.UNITS, nameValueHolder, descriptor, assetType, isAttribute);diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.tsindex a5f11e0e6..f9bedf102 100644--- a/ui/component/or-asset-tree/src/index.ts+++ b/ui/component/or-asset-tree/src/index.ts@@ -511,8 +511,10 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {protected _onAddClicked() {const types = this._getAllowedChildTypes(this._selectedNodes[0]);- let dialog: OrMwcDialog;+ const agentTypes = types.filter((t) => t.descriptorType === "agent");+ const assetTypes = types.filter((t) => t.descriptorType === "asset");const parent = this._selectedNodes && this._selectedNodes.length === 1 ? this._selectedNodes[0].asset : undefined;+ let dialog: OrMwcDialog;const onAddChanged = (ev: OrAddChangedEvent) => {const nameValid = !!ev.detail.name && ev.detail.name.trim().length > 0 && ev.detail.name.trim().length < 1024;@@ -524,7 +526,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {{title: i18next.t("addAsset"),content: html`- <or-add-asset-dialog id="add-panel" .config="${this.config}" .agentTypes="${types[0]}" .assetTypes="${types[1]}" .parent="${parent}" @or-add-asset-changed="${onAddChanged}"></or-add-asset-dialog>+ <or-add-asset-dialog id="add-panel" .config="${this.config}" .agentTypes="${agentTypes}" .assetTypes="${assetTypes}" .parent="${parent}" @or-add-asset-changed="${onAddChanged}"></or-add-asset-dialog>`,actions: [{@@ -547,7 +549,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {const asset: Asset = {name: name,type: descriptor.name,- realm: manager.getRealm()+ realm: manager.displayRealm};if (this.selectedIds) {diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.tsindex 16c412b0b..077890e25 100644--- a/ui/component/or-asset-viewer/src/index.ts+++ b/ui/component/or-asset-viewer/src/index.ts@@ -28,6 +28,7 @@ import {ClientRole,SharedEvent,WellknownAssets,+ WellknownAttributes,WellknownMetaItems} from "@openremote/model";import {panelStyles, style} from "./style";@@ -440,12 +441,12 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: { [if (panelConfig && panelConfig.type === "group") {- if (asset.type !== "urn:openremote:asset:group") {+ if (asset.type !== "GroupAsset") {return;}// Get child asset type attribute value- const childAssetTypeAttribute = asset.attributes && asset.attributes["childAssetType"];+ const childAssetTypeAttribute = asset.attributes && asset.attributes[WellknownAttributes.CHILDASSETTYPE];const groupConfig = panelConfig as GroupPanelConfig;if (!childAssetTypeAttribute || typeof childAssetTypeAttribute.value !== "string") {diff --git a/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts b/ui/component/or-asset-viewer/src/or-edit-asset-panel.tsindex c72b305b7..19cc13855 100644--- a/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts+++ b/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts@@ -352,7 +352,7 @@ export class OrEditAssetPanel extends LitElement {const meta = attribute.meta || {};const metaItemList: (ListItem | null)[] = assetTypeInfo.metaItemDescriptors.map((metaName) => AssetModelUtil.getMetaItemDescriptor(metaName)!)- .filter((descriptor) => meta.hasOwnProperty(descriptor.name!))+ .filter((descriptor) => !meta.hasOwnProperty(descriptor.name!)).map((descriptor) => {return {text: Util.getMetaLabel(undefined, descriptor, this.asset!.type!, true),diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.tsindex cfa45e55f..4922f85ea 100644--- a/ui/component/or-attribute-input/src/index.ts+++ b/ui/component/or-attribute-input/src/index.ts@@ -509,7 +509,14 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE}// Fallback to simple input provider- this._templateProvider = getValueHolderInputTemplateProvider(this.assetType, this.attribute, this._attributeDescriptor, valueDescriptor, (v: any) => this._onInputValueChanged(v), options);+ const valueChangeHandler = (e: OrInputChangedEvent) => {+ if (e.detail.enterPressed || !this._templateProvider || !this._templateProvider.supportsSendButton) {+ this._onInputValueChanged(e.detail.value);+ } else {+ this._newValue = e.detail.value;+ }+ };+ this._templateProvider = getValueHolderInputTemplateProvider(this.assetType, this.attribute, this._attributeDescriptor, valueDescriptor, (e: any) => valueChangeHandler(e), options);}public getLabel(): string | undefined {diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.tsindex 2cfdf6ff7..3c045f2c0 100644--- a/ui/component/or-input/src/index.ts+++ b/ui/component/or-input/src/index.ts@@ -37,11 +37,12 @@ export class OrInputChangedEvent extends CustomEvent<OrInputChangedEventDetail>public static readonly NAME = "or-input-changed";- constructor(value?: any, previousValue?: any) {+ constructor(value?: any, previousValue?: any, enterPressed?: boolean) {super(OrInputChangedEvent.NAME, {detail: {value: value,- previousValue: previousValue+ previousValue: previousValue,+ enterPressed: enterPressed},bubbles: true,composed: true@@ -52,6 +53,7 @@ export class OrInputChangedEvent extends CustomEvent<OrInputChangedEventDetail>export interface OrInputChangedEventDetail {value?: any;previousValue?: any;+ enterPressed?: boolean;}declare global {@@ -342,7 +344,8 @@ export const getValueHolderInputTemplateProvider: ValueInputProviderGenerator =.helperText="${helperText}" .helperPersistent="${true}"}}" @or-input-changed="${(e: OrInputChangedEvent) => {e.stopPropagation();- valueChangeNotifier(valueConverter ? valueConverter(e.detail.value) : e.detail.value);+ e.detail.value = valueConverter ? valueConverter(e.detail.value) : e.detail.value;+ valueChangeNotifier(e);}}"></or-input>`};@@ -785,9 +788,15 @@ export class OrInput extends LitElement {<div id="component"class="mdc-select ${classMap(classes)}"@MDCSelect:change="${(e: MDCSelectEvent) => this.onValueChange(undefined, e.detail.index === -1 ? undefined : Array.isArray(this.options![e.detail.index]) ? this.options![e.detail.index][0] : this.options![e.detail.index])}">- <div id="menu-anchor" class="mdc-select__anchor select-class">+ <div id="menu-anchor" class="mdc-select__anchor" role="button"+ aria-haspopup="listbox"+ aria-expanded="false"+ aria-labelledby="label selected-text"><span class="mdc-select__ripple"></span>- <span class="mdc-select__selected-text">${valueLabel ? i18next.t(valueLabel) : ""}</span>+ ${outlined ? this.renderOutlined(labelTemplate) : labelTemplate}+ <span class="mdc-select__selected-text-container">+ <span id="selected-text" class="mdc-select__selected-text">${valueLabel ? i18next.t(valueLabel) : ""}<</span>+ </span><span class="mdc-select__dropdown-icon"><svgclass="mdc-select__dropdown-icon-graphic"@@ -806,12 +815,11 @@ export class OrInput extends LitElement {</polygon></svg></span>- ${outlined ? this.renderOutlined(labelTemplate) : labelTemplate}${!outlined ? html`<div class="mdc-line-ripple"></div>` : ``}</div>- <div class="mdc-select__menu mdc-menu mdc-menu-surface select-class" role="listbox">- <ul class="mdc-list">+ <div class="mdc-select__menu mdc-menu mdc-menu-surface">+ <ul class="mdc-list" role="listbox">${opts ? opts.map(([optValue, optDisplay], index) => {if (this.value === optValue) {this._selectedIndex = index;@@ -1018,9 +1026,9 @@ export class OrInput extends LitElement {step="${this.step ? this.step : "any"}" minlength="${ifDefined(this.minLength)}" pattern="${ifDefined(this.pattern)}"maxlength="${ifDefined(this.maxLength)}" placeholder="${ifDefined(this.placeHolder)}".value="${valMinMax[0] !== null && valMinMax[0] !== undefined ? valMinMax[0] : ""}"- @keyup="${(e: KeyboardEvent) => {+ @keydown="${(e: KeyboardEvent) => {if ((e.code === "Enter" || e.code === "NumpadEnter")) {- this.onValueChange((e.target as HTMLInputElement), (e.target as HTMLInputElement).value);+ this.onValueChange((e.target as HTMLInputElement), (e.target as HTMLInputElement).value, true);}}}"@input="${(e: Event) => this.clearValidation(e)}"@change="${(e: Event) => this.onValueChange((e.target as HTMLInputElement), (e.target as HTMLInputElement).value)}" />`;@@ -1188,7 +1196,7 @@ export class OrInput extends LitElement {if(input) input.setCustomValidity("");}- protected onValueChange(elem: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | undefined, newValue: any | undefined) {+ protected onValueChange(elem: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | undefined, newValue: any | undefined, enterPressed?: boolean) {let valid = true;if (elem && this._mdcComponent) {@@ -1242,7 +1250,7 @@ export class OrInput extends LitElement {(this._mdcComponent2 as MDCTextField).value = newValue;}}- this.dispatchEvent(new OrInputChangedEvent(this.value, previousValue));+ this.dispatchEvent(new OrInputChangedEvent(this.value, previousValue, enterPressed));}}diff --git a/ui/component/or-mwc-components/src/or-mwc-list.ts b/ui/component/or-mwc-components/src/or-mwc-list.tsindex 9a27feebd..2f0d4fbb1 100644--- a/ui/component/or-mwc-components/src/or-mwc-list.ts+++ b/ui/component/or-mwc-components/src/or-mwc-list.ts@@ -327,7 +327,7 @@ export class OrMwcList extends LitElement {return indexes;}, [] as number[]);- this._mdcComponent.selectedIndex = indexes.length === 1 ? indexes[0] : indexes.length > 1 ? indexes : -1;+ this._mdcComponent.selectedIndex = this.type === ListType.CHECKBOX ? indexes : indexes.length >= 1 ? indexes[0] : -1;}protected _onSelected(ev: MDCListActionEvent) {diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-notification.tsindex b1ec69f6b..6dea74402 100644--- a/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts+++ b/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts@@ -315,7 +315,7 @@ export class OrRuleActionNotification extends LitElement {case ActionTargetType.ASSET:if (!value || value === "allMatched") {delete this.action.target;- } else if (value.startsWith("urn:")) {+ } else if (value.endsWith("Asset")) {// This is an asset typethis.action.target = {matchedAssets: {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.tsindex 2313a9721..87a64d5f3 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@@ -28,7 +28,7 @@ export function getWhenTypesMenu(config?: RulesConfig, assetInfos?: AssetTypeInfconst menu: MenuItem[] = [];if (addAssetTypes && assetInfos) {- menu.push(...assetInfos.map((assetTypeInfo) => {+ menu.push(...assetInfos.filter((assetInfo) => assetInfo.assetDescriptor!.descriptorType !== "agent").map((assetTypeInfo) => {const color = AssetModelUtil.getAssetDescriptorColour(assetTypeInfo);const icon = AssetModelUtil.getAssetDescriptorIcon(assetTypeInfo);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 00f624790..3083b5a20 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@@ -40,7 +40,7 @@ function getActionTypesMenu(config?: RulesConfig, assetInfos?: AssetTypeInfo[]):const menu: MenuItem[] = [];if (addAssetTypes && assetInfos) {- menu.push(...assetInfos.map((assetTypeInfo) => {+ menu.push(...assetInfos.filter((assetInfo) => assetInfo.assetDescriptor!.descriptorType !== "agent").map((assetTypeInfo) => {const color = AssetModelUtil.getAssetDescriptorColour(assetTypeInfo);const icon = AssetModelUtil.getAssetDescriptorIcon(assetTypeInfo);diff --git a/ui/component/or-rules/src/or-rule-list.ts b/ui/component/or-rules/src/or-rule-list.tsindex a0e282749..8e55a6b6f 100644--- a/ui/component/or-rules/src/or-rule-list.ts+++ b/ui/component/or-rules/src/or-rule-list.ts@@ -1,5 +1,5 @@import {css, customElement, html, LitElement, property, PropertyValues, TemplateResult} from "lit-element";-import {CalendarEvent, ClientRole, RulesetLang, RulesetUnion, TenantRuleset} from "@openremote/model";+import {CalendarEvent, ClientRole, RulesetLang, RulesetUnion, TenantRuleset, WellknownMetaItems, WellknownRulesetMetaItems} from "@openremote/model";import "@openremote/or-translate";import manager, {OREvent, Util} from "@openremote/core";import "@openremote/or-input";@@ -333,8 +333,8 @@ export class OrRuleList extends translate(i18next)(LitElement) {if (ruleset.enabled) {// Look at validity meta- if (ruleset.meta && ruleset.meta.hasOwnProperty("urn:openremote:rule:meta:validity")) {- const calendarEvent = ruleset.meta["urn:openremote:rule:meta:validity"] as CalendarEvent;+ if (ruleset.meta && ruleset.meta[WellknownRulesetMetaItems.VALIDITY]) {+ const calendarEvent = ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent;const now = new Date().getTime();if (calendarEvent.start) {diff --git a/ui/component/or-rules/src/or-rule-validity.ts b/ui/component/or-rules/src/or-rule-validity.tsindex 5d59f8803..47e8b0805 100644--- a/ui/component/or-rules/src/or-rule-validity.ts+++ b/ui/component/or-rules/src/or-rule-validity.ts@@ -1,4 +1,4 @@-import {css, customElement, html, LitElement, property, PropertyValues, query} from "lit-element";+import {css, customElement, html, LitElement, property, PropertyValues, query, TemplateResult} from "lit-element";import {CalendarEvent, RulesetUnion, WellknownRulesetMetaItems} from "@openremote/model";import {OrRulesRuleChangedEvent} from "./index";import "@openremote/or-input";@@ -6,27 +6,24 @@ import {InputType, OrInputChangedEvent} from "@openremote/or-input";import i18next from "i18next";import {translate} from "@openremote/or-translate";-import {DialogAction, OrMwcDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";+import {OrMwcDialog, showDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";import {ByWeekday, RRule, Weekday} from 'rrule'import moment from "moment";@customElement("or-rule-validity")export class OrRuleValidity extends translate(i18next)(LitElement) {- @property({type: Number})- public rulesetId?: number | undefined;-@property({type: Object})public ruleset?: RulesetUnion;@query("#radial-modal")protected dialog?: OrMwcDialog;- @property({type: Object})- public rrule: RRule = new RRule({- freq: RRule.DAILY,- dtstart: new Date()- });+ @property()+ protected _validity?: CalendarEvent;+ @property()+ protected _rrule?: RRule;+ protected _dialog?: OrMwcDialog;constructor() {super();@@ -40,17 +37,12 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {protected updated(changedProps: PropertyValues) {super.updated(changedProps);- if(changedProps.has("ruleset") && this.ruleset) {- if(this.ruleset.id && this.ruleset.id != this.rulesetId) {- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("radial-modal") as OrMwcDialog;- if (dialog) dialog.close();- this.rulesetId = this.ruleset.id- }- const validity = this.ruleset.meta ? this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent : undefined;- if (validity && validity.recurrence) {- this.rrule = RRule.fromString(validity.recurrence)- } else {- this.rrule = new RRule();++ if (changedProps.has("ruleset") && this.ruleset) {+ this._validity = this.ruleset.meta ? this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent : undefined;++ if (this._validity && this._validity.recurrence) {+ this._rrule = RRule.fromString(this._validity.recurrence);}}}@@ -75,142 +67,135 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {}isAllDay() {- if(this.ruleset && this.ruleset.meta) {- const validity = this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent;- return validity && moment(validity.start).hours() === 0 && moment(validity.start).minutes() === 0- && moment(validity.end).hours() === 23 && moment(validity.end).minutes() === 59;- }+ return this._validity && moment(this._validity.start).hours() === 0 && moment(this._validity.start).minutes() === 0+ && moment(this._validity.end).hours() === 23 && moment(this._validity.end).minutes() === 59;}- protected setRRuleValue(value: any, key?: string) {- if (key && this.rrule && this.ruleset) {- const origOptions = this.rrule.origOptions;- if (!this.ruleset.meta) {- this.ruleset.meta = {};- }- if (!this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY]) {- this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] = {};- }- const validity = this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent;- switch (key) {- case "all-day":- if (value) {- validity.start = moment(validity.start).startOf("day").toDate().getTime();- validity.end = moment(validity.end).endOf("day").toDate().getTime();- } else {- validity.start = moment().toDate().getTime();- validity.end = moment().add(1, 'hour').toDate().getTime();- }- break;- case "start":- validity.start = moment(value).set({hour:0,minute:0,second:0,millisecond:0}).toDate().getTime();- if (this.getValidityType() === "validityRecurrence") {- origOptions.dtstart = moment(value).toDate();- this.rrule = new RRule(origOptions);- }- break;- case "end":- validity.end = moment(value).set({hour:23,minute:59,second:0,millisecond:0}).toDate().getTime();- break;- case "never-ends":- if (value) {- delete origOptions.until- } else {- origOptions.until = moment().add(1, 'year').toDate();- }- if (this.getValidityType() === "validityRecurrence") this.rrule = new RRule(origOptions);- break;- case "byweekday":- if (!origOptions.byweekday) origOptions.byweekday = [];- if (!Array.isArray(origOptions.byweekday)) origOptions.byweekday = [origOptions.byweekday as ByWeekday];- if (value.checked) {- const weekDay = this.getWeekDay(value.name);- if (weekDay) origOptions.byweekday.push(weekDay);- } else {- origOptions.byweekday = origOptions.byweekday.filter((day) => day !== this.getWeekDay(value.name));- }- if (this.getValidityType() === "validityRecurrence") this.rrule = new RRule(origOptions);- break;- case "until":- if (this.rrule.options.until) {- const newDate = moment(value)- origOptions["until"] = new Date(moment(origOptions.until).set({year: newDate.year(), month: newDate.month(), date: newDate.date()}).format())- }- if (this.getValidityType() === "validityRecurrence") this.rrule = new RRule(origOptions);- break;- case "dtstart-time":- const timeParts = value.split(':');- origOptions.dtstart = moment(origOptions.dtstart).set({hour:timeParts[0],minute:timeParts[1],second:0,millisecond:0}).toDate();- validity.start = moment(origOptions.dtstart).toDate().getTime();- if (this.getValidityType() === "validityRecurrence") this.rrule = new RRule(origOptions);- break;- case "until-time":- const untilParts = value.split(':');- if (this.rrule.options.until) {- origOptions.until = moment(origOptions.until).set({hour:untilParts[0],minute:untilParts[1],second:0,millisecond:0}).toDate()- }- validity.end = moment(validity.end).set({hour:untilParts[0],minute:untilParts[1],second:0,millisecond:0}).toDate().getTime();- if(this.getValidityType() === "validityRecurrence") this.rrule = new RRule(origOptions);- break;- }+ protected setRRuleValue(value: any, key: string) {+ const origOptions = this._rrule ? this._rrule.origOptions : undefined;+ const validity = this._validity!;++ switch (key) {+ case "all-day":+ if (value) {+ validity.start = moment(validity.start).startOf("day").toDate().getTime();+ validity.end = moment(validity.end).endOf("day").toDate().getTime();+ } else {+ validity.start = moment().toDate().getTime();+ validity.end = moment().add(1, 'hour').toDate().getTime();+ }+ break;+ case "start":+ validity.start = moment(value).set({hour:0,minute:0,second:0,millisecond:0}).toDate().getTime();+ if (this.getValidityType() === "validityRecurrence") {+ origOptions!.dtstart = moment(value).toDate();+ this._rrule = new RRule(origOptions);+ }+ break;+ case "end":+ validity.end = moment(value).set({hour:23,minute:59,second:0,millisecond:0}).toDate().getTime();+ break;+ case "never-ends":+ if (value) {+ delete origOptions!.until+ } else {+ origOptions!.until = moment().add(1, 'year').toDate();+ }+ if (this.getValidityType() === "validityRecurrence") this._rrule = new RRule(origOptions);+ break;+ case "byweekday":+ if (!origOptions!.byweekday) origOptions!.byweekday = [];+ if (!Array.isArray(origOptions!.byweekday)) origOptions!.byweekday = [origOptions!.byweekday as ByWeekday];+ if (value.checked) {+ const weekDay = this.getWeekDay(value.name);+ if (weekDay) origOptions!.byweekday.push(weekDay);+ } else {+ origOptions!.byweekday = origOptions!.byweekday.filter((day) => day !== this.getWeekDay(value.name));+ }+ if (this.getValidityType() === "validityRecurrence") this._rrule = new RRule(origOptions);+ break;+ case "until":+ if (this._rrule!.options.until) {+ const newDate = moment(value)+ origOptions!.until = new Date(moment(origOptions!.until).set({year: newDate.year(), month: newDate.month(), date: newDate.date()}).format())+ }+ if (this.getValidityType() === "validityRecurrence") this._rrule = new RRule(origOptions);+ break;+ case "dtstart-time":+ const timeParts = value.split(':');+ origOptions!.dtstart = moment(origOptions!.dtstart).set({hour:timeParts[0],minute:timeParts[1],second:0,millisecond:0}).toDate();+ validity.start = moment(origOptions!.dtstart).toDate().getTime();+ if (this.getValidityType() === "validityRecurrence") this._rrule = new RRule(origOptions);+ break;+ case "until-time":+ const untilParts = value.split(':');+ if (this._rrule!.options.until) {+ origOptions!.until = moment(origOptions!.until).set({hour:untilParts[0],minute:untilParts[1],second:0,millisecond:0}).toDate()+ }+ validity.end = moment(validity.end).set({hour:untilParts[0],minute:untilParts[1],second:0,millisecond:0}).toDate().getTime();+ if(this.getValidityType() === "validityRecurrence") this._rrule = new RRule(origOptions);+ break;}- this.requestUpdate();+ this.refreshDialogContent();}timeLabel() {if (this.getValidityType() === "validityAlways") {return i18next.t("validityAlways");- } else if (this.ruleset && this.ruleset.meta && this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] && (this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent).recurrence) {- const validity = this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent;+ } else if (this._validity && this._rrule) {+ const validity = this._validity;const diff = moment(validity.end).diff(validity.start, "days");let diffString = "";if (this.isAllDay()) {if(diff > 0) diffString = " "+i18next.t('forDays', {days: diff});- return this.rrule.toText() + diffString;+ return this._rrule.toText() + diffString;} else {if(diff > 0) diffString = i18next.t("fromToDays", {start: moment(validity.start).format("HH:mm"), end: moment(validity.end).format("HH:mm"), days: diff })if(diff === 0) diffString = i18next.t("fromTo", {start: moment(validity.start).format("HH:mm"), end: moment(validity.end).format("HH:mm") })- return this.rrule.toText() + " " + diffString;+ return this._rrule.toText() + " " + diffString;}- } else if (this.ruleset && this.ruleset.meta && this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY]) {- const validity = this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent;+ } else if (this._validity) {let format = "DD-MM-YYYY";if(!this.isAllDay()) format = "DD-MM-YYYY HH:mm";- return i18next.t("activeFromTo", {start: moment(validity.start).format(format), end: moment(validity.end).format(format) })+ return i18next.t("activeFromTo", {start: moment(this._validity.start).format(format), end: moment(this._validity.end).format(format) })}}setValidityType(value: any) {- if(!this.ruleset) return;+ if (!this.ruleset) return;if (!this.ruleset.meta) this.ruleset.meta = {};switch (value) {case "validityAlways":delete this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY];+ this._validity = undefined;+ this._rrule = undefined;break;case "validityPeriod":- this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] = {- start: moment().startOf('day').toDate().getTime(),- end: moment().endOf('day').toDate().getTime()- } as CalendarEvent;+ this._validity = {+ start: moment().startOf("day").toDate().getTime(),+ end: moment().endOf("day").toDate().getTime()+ };break;case "validityRecurrence":- this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] = {- start: moment().startOf("day").toDate().getTime(),- end: moment().endOf("day").toDate().getTime(),- recurrence: {}- } as CalendarEvent;+ if (!this._validity) {+ this._validity = {++ };+ }+ this._rrule = new RRule({+ freq: RRule.DAILY,+ dtstart: new Date()+ });break;}- this.requestUpdate("ruleset");+ this.refreshDialogContent();}getValidityType () {- if(this.ruleset && this.ruleset.meta && this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY]) {- const validity = this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent;-- if (validity.recurrence) {+ if(this._validity) {+ if (this._rrule) {return "validityRecurrence";} else {return "validityPeriod";@@ -219,23 +204,66 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {return "validityAlways";}- renderDialogHTML() {+ protected render() {+ if(!this.ruleset) return html``;- if (!this.ruleset) {- return;- }+ return html`+ <or-input .type="${InputType.BUTTON}" .label="${this.timeLabel()}" @click="${() => this.showDialog()}"></or-input>+ `;+ }- if (!this.dialog) {+ protected showDialog() {++ this._dialog = showDialog({+ title: i18next.t("scheduleRuleActivity"),+ actions: [+ {+ actionName: "cancel",+ content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-input>`,+ action: () => {+ this._dialog = undefined;+ }+ },+ {+ actionName: "ok",+ default: true,+ content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("apply")}"></or-input>`,+ action: () => {+ if (this.ruleset && this.ruleset.meta) {+ if (this.getValidityType() === "validityAlways") {+ delete this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY];+ } else {+ if (this.getValidityType() === "validityRecurrence") {+ this._validity!.recurrence = this._rrule!.toString().split("RRULE:")[1];+ }+ this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] = this._validity;+ }+ this.dispatchEvent(new OrRulesRuleChangedEvent(true));+ this._dialog = undefined;+ }+ }+ },+ ],+ content: this.getDialogContent()+ });+ }++ protected refreshDialogContent() {+ if (!this._dialog) {return;}+ this._dialog.dialogContent = this.getDialogContent();+ }++ protected getDialogContent(): TemplateResult {const options = [RRule.MO.toString(), RRule.TU.toString(), RRule.WE.toString(), RRule.TH.toString(), RRule.FR.toString(), RRule.SA.toString(), RRule.SU.toString()];const validityTypes = ["validityAlways", "validityPeriod", "validityRecurrence"];const validityType = this.getValidityType();- const selectedOptions = this.rrule.options && this.rrule.options.byweekday ? this.rrule.options.byweekday.map(day => new Weekday(day).toString()) : [];- const validity = this.ruleset.meta ? this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent : undefined;+ const selectedOptions = this._rrule && this._rrule.options && this._rrule.options.byweekday ? this._rrule.options.byweekday.map(day => new Weekday(day).toString()) : [];+ const validity = this._validity;- this.dialog.dialogContent = html`+ return html`<div style="min-height: 200px; min-width: 635px; display:grid; flex-direction: row;"><div class="layout horizontal"><or-input .value="${validityType}" .type="${InputType.SELECT}" .options="${validityTypes}" @or-input-changed="${(e: OrInputChangedEvent) => this.setValidityType(e.detail.value)}" ></or-input>@@ -260,72 +288,19 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {` : ``}${validityType === "validityRecurrence" ? html`- <label style="display:block; margin-top: 20px;"><or-translate value="repeatOccurrenceEvery"></or-translate></label>+ <label style="display: block; margin-top: 20px;"><or-translate value="repeatOccurrenceEvery"></or-translate></label><div class="layout horizontal"><or-input .value="${selectedOptions}" .type="${InputType.CHECKBOX_LIST}" .options="${options}" .label="${i18next.t("daysOfTheWeek")}" @or-input-changed="${(e: OrInputChangedEvent) => this.setRRuleValue(e.detail.value, "byweekday")}" ></or-input></div><label style="display:block; margin-top: 20px;"><or-translate value="repetitionEnds"></or-translate></label><div class="layout horizontal">- <or-input .value="${!this.rrule.options.until}" @or-input-changed="${(e: OrInputChangedEvent) => this.setRRuleValue(e.detail.value, "never-ends")}" .type="${InputType.CHECKBOX}" .label="${i18next.t("never")}"></or-input>+ <or-input .value="${!this._rrule!.options.until}" @or-input-changed="${(e: OrInputChangedEvent) => this.setRRuleValue(e.detail.value, "never-ends")}" .type="${InputType.CHECKBOX}" .label="${i18next.t("never")}"></or-input></div><div class="layout horizontal">- <or-input ?disabled="${!this.rrule.options.until}" .value="${this.rrule.options.until ? moment(this.rrule.options.until).format("YYYY-MM-DD") : moment().add(1, 'year').format('YYYY-MM-DD')}" .type="${InputType.DATE}" @or-input-changed="${(e: OrInputChangedEvent) => this.setRRuleValue(e.detail.value, "until")}" .label="${i18next.t("to")}"></or-input>+ <or-input ?disabled="${!this._rrule!.options.until}" .value="${this._rrule!.options.until ? moment(this._rrule!.options.until).format("YYYY-MM-DD") : moment().add(1, 'year').format('YYYY-MM-DD')}" .type="${InputType.DATE}" @or-input-changed="${(e: OrInputChangedEvent) => this.setRRuleValue(e.detail.value, "until")}" .label="${i18next.t("to")}"></or-input></div>- ` : ``}-+ ` : ``}</div>`;}-- protected render() {- if(!this.ruleset) return html``;--- // @ts-ignore-- const validityModalActions: DialogAction[] = [- {- actionName: "cancel",- content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-input>`,- action: () => {- // Nothing to do here- }- },- {- actionName: "ok",- default: true,- content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("apply")}"></or-input>`,- action: () => {- if(this.ruleset && this.ruleset.meta) {- const validity = this.ruleset.meta[WellknownRulesetMetaItems.VALIDITY] as CalendarEvent;- if(this.getValidityType() === "validityRecurrence") {- validity.recurrence = this.rrule.toString().split("RRULE:")[1]- }- if(this.getValidityType() === "validityPeriod" || this.getValidityType() === "validityRecurrence") {- validity.start = moment(validity.start).toDate().getTime();- validity.end = moment(validity.end).toDate().getTime();- }- this.dispatchEvent(new OrRulesRuleChangedEvent(true));- this.requestUpdate('ruleset')- }- }- },- ];--- const validityModalOpen = () => {- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("radial-modal") as OrMwcDialog;- if (dialog) {- dialog.open();- this.renderDialogHTML();- }- };-- this.renderDialogHTML();-- return html`- <or-input .type="${InputType.BUTTON}" .label="${this.timeLabel()}" @click="${validityModalOpen}"></or-input>- <or-mwc-dialog id="radial-modal" dialogTitle="${i18next.t("scheduleRuleActivity")}" .dialogActions="${validityModalActions}"></or-mwc-dialog>- `- }}diff --git a/ui/demo/demo-or-thermostat/src/index.ts b/ui/demo/demo-or-thermostat/src/index.tsindex 67ffc9c7e..bab40aecc 100644--- a/ui/demo/demo-or-thermostat/src/index.ts+++ b/ui/demo/demo-or-thermostat/src/index.ts@@ -25,7 +25,7 @@ async function initApartment1Asset(): Promise<string|undefined> {type: {predicateType: "string",match: AssetQueryMatch.EXACT,- value: "urn:openremote:asset:room"+ value: "RoomAsset"},select: {include: AssetQueryInclude.ONLY_ID_AND_NAME