Skip to content

armgit / core

Public Imported from GitHub
0

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

Fix ui bugs #334, #314, #324, #317, #323

Robin Dekkers6933157d8570
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index e67add78c..93a8e89dd 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -548,12 +548,21 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: { [
return arr;
});
-
- let config = {
- views: {
- [asset.id!]: selectedAttributes
+ let config;
+ const configStr = window.localStorage.getItem('OrAssetConfig')
+ if(configStr) {
+ config = JSON.parse(configStr);
+ if(asset.id) {
+ config.views[asset.id] = selectedAttributes;
+ }
+ } else {
+ config = {
+ views: {
+ [asset.id!]: selectedAttributes
+ }
}
}
+
const message = {
provider: "STORAGE",
diff --git a/ui/component/or-attribute-history/src/index.ts b/ui/component/or-attribute-history/src/index.ts
index f9f972bc6..c43f97b71 100644
--- a/ui/component/or-attribute-history/src/index.ts
+++ b/ui/component/or-attribute-history/src/index.ts
@@ -260,6 +260,7 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
protected _type?: ValueDescriptor;
protected _style!: CSSStyleDeclaration;
+ protected _updateTimestampTimer: number | null = null;
connectedCallback() {
super.connectedCallback();
this._style = window.getComputedStyle(this);
@@ -314,10 +315,10 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
<div id="controls">
<or-input .type="${InputType.SELECT}" ?disabled="${disabled}" .label="${i18next.t("timeframe")}" @or-input-changed="${(evt: OrInputChangedEvent) => this.period = evt.detail.value}" .value="${this.period}" .options="${this._getPeriodOptions()}"></or-input>
<div id="ending-controls">
- <or-input id="ending-date" .type="${InputType.DATETIME}" ?disabled="${disabled}" label="${i18next.t("ending")}" .value="${this.fromTimestamp}" @or-input-changed="${(evt: OrInputChangedEvent) => this.fromTimestamp = this._updateTimestamp(moment(evt.detail.value as string).toDate())}"></or-input>
- <or-icon class="button button-icon" ?disabled="${disabled}" icon="chevron-left" @click="${() => this.fromTimestamp = this._updateTimestamp(this.fromTimestamp!, false)}"></or-icon>
- <or-icon class="button button-icon" ?disabled="${disabled}" icon="chevron-right" @click="${() => this.fromTimestamp = this._updateTimestamp(this.fromTimestamp!, true)}"></or-icon>
- <or-icon class="button button-icon" ?disabled="${disabled}" icon="chevron-double-right" @click="${() => this.fromTimestamp = this._updateTimestamp(new Date())}"></or-icon>
+ <or-input id="ending-date" .type="${InputType.DATETIME}" ?disabled="${disabled}" label="${i18next.t("ending")}" .value="${this.fromTimestamp}" @or-input-changed="${(evt: OrInputChangedEvent) => this._updateTimestamp(moment(evt.detail.value as string).toDate())}"></or-input>
+ <or-icon class="button button-icon" ?disabled="${disabled}" icon="chevron-left" @click="${() => this._updateTimestamp(this.fromTimestamp!, false)}"></or-icon>
+ <or-icon class="button button-icon" ?disabled="${disabled}" icon="chevron-right" @click="${() => this._updateTimestamp(this.fromTimestamp!, true)}"></or-icon>
+ <or-icon class="button button-icon" ?disabled="${disabled}" icon="chevron-double-right" @click="${() => this._updateTimestamp(new Date())}"></or-icon>
</div>
</div>
@@ -712,13 +713,20 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
}
}
protected _updateTimestamp(timestamp: Date, forward?: boolean) {
- const newMoment = moment(timestamp);
- if (forward !== undefined) {
- newMoment.add(forward ? 1 : -1, this.period);
+ if (this._updateTimestampTimer) {
+ window.clearTimeout(this._updateTimestampTimer);
+ this._updateTimestampTimer = null;
}
+ this._updateTimestampTimer = window.setTimeout(() => {
+ const newMoment = moment(timestamp);
- return newMoment.toDate();
+ if (forward !== undefined) {
+ newMoment.add(forward ? 1 : -1, this.period);
+ }
+ this.fromTimestamp = newMoment.toDate()
+ }, 1000);
}
+
}
diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.ts
index 40888ad86..47a06daab 100644
--- a/ui/component/or-attribute-input/src/index.ts
+++ b/ui/component/or-attribute-input/src/index.ts
@@ -511,7 +511,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
// Fallback to simple input provider
const valueChangeHandler = (detail: OrInputChangedEventDetail) => {
- if (detail.enterPressed || !this._templateProvider || !this._templateProvider.supportsSendButton) {
+ if (detail.enterPressed || !this._templateProvider || !this.showButton || !this._templateProvider.supportsSendButton) {
this._onInputValueChanged(detail.value);
} else {
this._newValue = detail.value;
@@ -576,7 +576,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
}
protected get showButton(): boolean {
- if (this.isReadonly() || this.disabled || this.disableButton || !this._getAttributeRef()) {
+ if (this.isReadonly() || this.disabled || !this.disableButton || !this._getAttributeRef()) {
return false;
}
diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.ts
index 212ce8b3f..8199d17fe 100644
--- a/ui/component/or-chart/src/index.ts
+++ b/ui/component/or-chart/src/index.ts
@@ -383,6 +383,8 @@ export class OrChart extends translate(i18next)(LitElement) {
protected _style!: CSSStyleDeclaration;
+ protected _updateTimestampTimer: number | null = null;
+
firstUpdated() {
if (this._dialogElem) {
this._dialog = new MDCDialog(this._dialogElem);
@@ -462,9 +464,9 @@ export class OrChart extends translate(i18next)(LitElement) {
.type="${endDateInputType}"
?disabled="${disabled}"
.value="${this.timestamp}"
- @or-input-changed="${(evt: OrInputChangedEvent) => this.timestamp = this._updateTimestamp(moment(evt.detail.value as string).toDate())}"></or-input>
- <or-icon class="button-icon" icon="chevron-left" @click="${() => this.timestamp = this._updateTimestamp(this.timestamp!, false)}"></or-icon>
- <or-icon class="button-icon" icon="chevron-right" @click="${() => this.timestamp = this._updateTimestamp(this.timestamp!, true)}"></or-icon>
+ @or-input-changed="${(evt: OrInputChangedEvent) => this._updateTimestamp(moment(evt.detail.value as string).toDate())}"></or-input>
+ <or-icon class="button-icon" icon="chevron-left" @click="${() => this._updateTimestamp(this.timestamp!, false)}"></or-icon>
+ <or-icon class="button-icon" icon="chevron-right" @click="${() =>this._updateTimestamp(this.timestamp!, true)}"></or-icon>
</div>
${this.periodCompare ? html `
<div class="period-controls">
@@ -474,9 +476,9 @@ export class OrChart extends translate(i18next)(LitElement) {
.type="${endDateInputType}"
?disabled="${disabled}"
.value="${this.compareTimestamp}"
- @or-input-changed="${(evt: OrInputChangedEvent) => this.compareTimestamp = this._updateTimestamp(moment(evt.detail.value as string).toDate())}"></or-input>
- <or-icon class="button-icon" icon="chevron-left" @click="${() => this.compareTimestamp = this._updateTimestamp(this.compareTimestamp!, false)}"></or-icon>
- <or-icon class="button-icon" icon="chevron-right" @click="${() => this.compareTimestamp = this._updateTimestamp(this.compareTimestamp!, true)}"></or-icon>
+ @or-input-changed="${(evt: OrInputChangedEvent) => this._updateTimestamp(moment(evt.detail.value as string).toDate(), undefined, true)}"></or-input>
+ <or-icon class="button-icon" icon="chevron-left" @click="${() => this._updateTimestamp(this.compareTimestamp!, false, true)}"></or-icon>
+ <or-icon class="button-icon" icon="chevron-right" @click="${() => this._updateTimestamp(this.compareTimestamp!, true, true)}"></or-icon>
</div>
` : html``}
@@ -1120,13 +1122,24 @@ export class OrChart extends translate(i18next)(LitElement) {
return interval;
}
- protected _updateTimestamp(timestamp: Date, forward?: boolean) {
- const newMoment = moment(timestamp);
+ protected _updateTimestamp(timestamp: Date, forward?: boolean, compare=false) {
- if (forward !== undefined) {
- newMoment.add(forward ? 1 : -1, this.period);
+ if (this._updateTimestampTimer) {
+ window.clearTimeout(this._updateTimestampTimer);
+ this._updateTimestampTimer = null;
}
+ this._updateTimestampTimer = window.setTimeout(() => {
+ const newMoment = moment(timestamp);
- return newMoment.toDate();
+ if (forward !== undefined) {
+ newMoment.add(forward ? 1 : -1, this.period);
+ }
+ if(compare) {
+ this.compareTimestamp = newMoment.toDate()
+ } else {
+ this.timestamp = newMoment.toDate()
+ }
+ }, 1000);
}
+
}
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index b9f3076f8..b08fb03a6 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -447,6 +447,10 @@ const style = css`
.or-input--rounded {
border-radius: 50% !important;
}
+
+ .mdc-text-field__input::-webkit-calendar-picker-indicator {
+ display: block;
+ }
::-webkit-clear-button {display: none;}
::-webkit-inner-spin-button { display: none; }
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 1fc7f138e..fbc21704c 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
@@ -121,7 +121,7 @@ export class OrRuleActionAttribute extends translate(i18next)(LitElement) {
attributes = !assetTypeInfo || !assetTypeInfo.attributeDescriptors ? [] : assetTypeInfo.attributeDescriptors.filter((ad) => !Util.hasMetaItem(WellknownMetaItems.READONLY, ad))
.map((ad) => {
- const label = Util.getAttributeLabel(undefined, descriptors[0], assetType, false);
+ const label = Util.getAttributeLabel(ad, descriptors[0], assetType, false);
return [ad.name!, label];
});
}
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 d5875ed74..132502e02 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
@@ -343,11 +343,7 @@ export class OrRuleJsonViewer extends translate(i18next)(LitElement) implements
if (!target) {
return true;
}
-
- if (!target.assets && !target.conditionAssets) {
- return false;
- }
-
+
if (target.assets) {
return this._validateAssetQuery(target.assets, false, false);
}
@@ -355,9 +351,8 @@ export class OrRuleJsonViewer extends translate(i18next)(LitElement) implements
if (target.matchedAssets) {
return this._validateAssetQuery(target.matchedAssets, false, true);
}
-
- const typesAndTags = getTypeAndTagsFromGroup(rule.when!);
- if (typesAndTags.findIndex((typeAndTag) => target.conditionAssets === typeAndTag[1]) < 0) {
+
+ if (target.conditionAssets && getTypeAndTagsFromGroup(rule.when!).findIndex((typeAndTag) => target.conditionAssets === typeAndTag[1]) < 0) {
return false;
}
@@ -374,8 +369,8 @@ export class OrRuleJsonViewer extends translate(i18next)(LitElement) implements
if (!query.attributes || !query.attributes.items || query.attributes.items.length === 0) {
return false;
}
- } else {
- if (!query.ids || query.ids.length === 0 && !isMatchedAssets) {
+ } else if (!isMatchedAssets) {
+ if (!query.ids || query.ids.length === 0) {
return false;
}
}
diff --git a/ui/component/or-rules/src/or-rule-validity.ts b/ui/component/or-rules/src/or-rule-validity.ts
index 47e8b0805..8b2dbcfde 100644
--- a/ui/component/or-rules/src/or-rule-validity.ts
+++ b/ui/component/or-rules/src/or-rule-validity.ts
@@ -86,14 +86,20 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {
}
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);
+ const newStartDate = moment(value);
+ if(newStartDate.isValid()) {
+ validity.start = newStartDate.set({hour:0,minute:0,second:0,millisecond:0}).toDate().getTime();
+ if (this.getValidityType() === "validityRecurrence") {
+ origOptions!.dtstart = newStartDate.toDate();
+ this._rrule = new RRule(origOptions);
+ }
}
break;
case "end":
- validity.end = moment(value).set({hour:23,minute:59,second:0,millisecond:0}).toDate().getTime();
+ const newEndDate = moment(value);
+ if(newEndDate.isValid()) {
+ validity.end = newEndDate.set({hour:23,minute:59,second:0,millisecond:0}).toDate().getTime();
+ }
break;
case "never-ends":
if (value) {
@@ -136,6 +142,7 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {
if(this.getValidityType() === "validityRecurrence") this._rrule = new RRule(origOptions);
break;
}
+ this._validity = {...validity}
this.refreshDialogContent();
}
@@ -177,11 +184,13 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {
start: moment().startOf("day").toDate().getTime(),
end: moment().endOf("day").toDate().getTime()
};
+ this._rrule = undefined;
break;
case "validityRecurrence":
if (!this._validity) {
this._validity = {
-
+ start: moment().startOf("day").toDate().getTime(),
+ end: moment().endOf("day").toDate().getTime()
};
}
this._rrule = new RRule({