Skip to content

armgit / core

Public Imported from GitHub
0

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

Add localstorage to chart and asset viewer

Robin Dekkers6fdf64bcd872
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index a1a2e6a9f..7d3af91e8 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -452,11 +452,20 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: { [
let availableAttributes: string[] = [];
let selectedAttributes: string[] = [];
+
if (groupConfig.childAssetTypes && groupConfig.childAssetTypes[childAssetType]) {
availableAttributes = groupConfig.childAssetTypes[childAssetType].availableAttributes ? groupConfig.childAssetTypes[childAssetType].availableAttributes! : [];
selectedAttributes = groupConfig.childAssetTypes[childAssetType].selectedAttributes ? groupConfig.childAssetTypes[childAssetType].selectedAttributes! : [];
}
-
+ const configStr = window.localStorage.getItem('OrAssetConfig')
+ const viewSelector = asset.id ? asset.id : window.location.hash;
+ if(configStr) {
+ const config = JSON.parse(configStr);
+ const view = config.views[viewSelector];
+ if(view) {
+ selectedAttributes = [...view]
+ }
+ }
// Get available and selected attributes from asset descriptor if not defined in config
if (availableAttributes.length === 0) {
const descriptor = AssetModelUtil.getAssetTypeInfo(childAssetType);
@@ -530,6 +539,22 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: { [
arr.unshift(childAsset.name!);
return arr;
});
+
+
+ let config = {
+ views: {
+ [asset.id!]: selectedAttributes
+ }
+ }
+
+ const message = {
+ provider: "STORAGE",
+ action: "STORE",
+ key: "OrAssetConfig",
+ value: JSON.stringify(config)
+
+ }
+ manager.console._doSendProviderMessage(message)
window.setTimeout(() => OrAssetViewer.generateGrid(hostElement.shadowRoot), 0);
};
diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.ts
index 6f238b652..f671d3121 100644
--- a/ui/component/or-attribute-card/src/index.ts
+++ b/ui/component/or-attribute-card/src/index.ts
@@ -362,7 +362,7 @@ export class OrAttributeCard extends LitElement {
];
this._dialog.dialogContent = html`
- <or-input id="delta-mode-picker" value="${this.deltaFormat}" @or-input-changed="${(evt: OrInputChangedEvent) => this.deltaFormat = evt.detail.value}" .type="${InputType.LIST}" .options="${options}"></or-input>
+ <or-input id="delta-mode-picker" value="${this.deltaFormat}" @or-input-changed="${(evt: OrInputChangedEvent) => {this.deltaFormat = evt.detail.value;this.saveSettings();}}" .type="${InputType.LIST}" .options="${options}"></or-input>
`;
}
else if (dialogContent === "editCurrentValue") {
@@ -390,6 +390,7 @@ export class OrAttributeCard extends LitElement {
else if (input > 10) {this.mainValueDecimals = 10;}
else {this.mainValueDecimals = input;}
this.formattedMainValue = this.getFormattedValue(this.mainValue!);
+ this.saveSettings();
}
}
}
@@ -539,6 +540,8 @@ export class OrAttributeCard extends LitElement {
if (this.assetAttributes && this.assetAttributes.length > 0) {
this.assetId = assets[0].id;
this.period = view.period;
+ if(view.deltaFormat) this.deltaFormat = view.deltaFormat;
+ if(view.decimals) this.mainValueDecimals = view.decimals;
this.attributeName = this.assetAttributes[0].name;
this.getData();
}
@@ -571,7 +574,9 @@ export class OrAttributeCard extends LitElement {
config.views[viewSelector][this.panelName] = {
assetIds: assetIds,
attributes: attributes,
- period: this.period
+ period: this.period,
+ deltaFormat: this.deltaFormat,
+ decimals: this.mainValueDecimals
};
const message = {
provider: "STORAGE",
@@ -772,12 +777,11 @@ export class OrAttributeCard extends LitElement {
const attr = this.asset.attributes![this.attributeName!];
const roundedVal = +value.toFixed(this.mainValueDecimals); // + operator prevents str return
- const attributeDescriptor = AssetModelUtil.getAttributeDescriptor(this.attributeName!);
+ const attributeDescriptor = AssetModelUtil.getAttributeDescriptor(this.attributeName!, this.asset!.type);
const units = Util.resolveUnits(Util.getAttributeUnits(attr, attributeDescriptor, this.asset!.type));
this.setMainValueSize(roundedVal.toString());
if (!units) { return {value: roundedVal, unit: "" }; }
-
return {
value: roundedVal,
unit: units
diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.ts
index 0fa377844..40888ad86 100644
--- a/ui/component/or-attribute-input/src/index.ts
+++ b/ui/component/or-attribute-input/src/index.ts
@@ -547,7 +547,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
if (!this.assetType || !this._templateProvider) {
return html``;
}
-
+
// Check if attribute hasn't been loaded yet or pending write
const loading = (this.attributeRefs && !this._attributeEvent) || !!this._writeTimeoutHandler;
let content: TemplateResult;
diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.ts
index 62b616a62..212ce8b3f 100644
--- a/ui/component/or-chart/src/index.ts
+++ b/ui/component/or-chart/src/index.ts
@@ -53,6 +53,9 @@ export interface ChartViewConfig {
timestamp?: Date;
compareTimestamp?: Date;
period?: moment.unitOfTime.Base;
+ deltaFormat?: string;
+ decimals?: number;
+ periodCompare?: boolean;
}
export interface OrChartEventDetail {
@@ -719,6 +722,8 @@ export class OrChart extends translate(i18next)(LitElement) {
this.assets = view.assetIds.map((assetId: string) => assets.find(x => x.id === assetId)!);
this.assetAttributes = view.attributes.map((attr: string, index: number) => assets[index] && assets[index].attributes ? assets[index].attributes![attr] : undefined).filter(attr => !!attr) as Attribute<any>[];
this.period = view.period;
+ if(typeof view.periodCompare != 'undefined') this.periodCompare = view.periodCompare;
+
});
}
@@ -748,7 +753,8 @@ export class OrChart extends translate(i18next)(LitElement) {
config.views[viewSelector][this.panelName] = {
assetIds: assetIds,
attributes: attributes,
- period: this.period
+ period: this.period,
+ periodCompare: this.periodCompare
};
const message = {
provider: "STORAGE",
@@ -870,6 +876,7 @@ export class OrChart extends translate(i18next)(LitElement) {
setPeriodCompare(periodCompare:boolean) {
this.periodCompare = periodCompare;
this._loadData();
+ this.saveSettings();
}
protected async _loadData() {
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 509786aa6..1fc7f138e 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
@@ -16,6 +16,7 @@ import i18next from "i18next";
import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";
import {translate} from "@openremote/or-translate";
import {OrAttributeInputChangedEvent} from "@openremote/or-attribute-input";
+import { ifDefined } from "lit-html/directives/if-defined";
// language=CSS
const style = css`
@@ -129,7 +130,9 @@ export class OrRuleActionAttribute extends translate(i18next)(LitElement) {
if (this.action.attributeName) {
const label = descriptors[1] && (descriptors[1].name === WellknownValueTypes.BOOLEAN) ? "" : i18next.t("value");
- attributeInput = html`<or-attribute-input @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setActionAttributeValue(ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="${label}" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${this.action.value}" .readonly="${this.readonly || false}"></or-attribute-input>`;
+ let inputType;
+ if(descriptors[0]?.format?.asSlider) inputType = InputType.NUMBER;
+ attributeInput = html`<or-attribute-input .inputType="${ifDefined(inputType)}" @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setActionAttributeValue(ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="${label}" .assetType="${assetType}" .attributeDescriptor="${descriptors[0]}" .attributeValueDescriptor="${descriptors[1]}" .value="${this.action.value}" .readonly="${this.readonly || false}"></or-attribute-input>`;
}
return html`