Skip to content

armgit / core

Public Imported from GitHub
0

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

Use or-translate in header & input, fix or-chart

Robin Dekkers3dd6d34e4648
diff --git a/deployment/manager/shared/locales/de/or.json b/deployment/manager/shared/locales/de/or.json
index 21f8c4fa6..472fc9ae5 100644
--- a/deployment/manager/shared/locales/de/or.json
+++ b/deployment/manager/shared/locales/de/or.json
@@ -107,6 +107,6 @@
"history": "Historie",
"attributes": "Attribute",
"info": "Info",
- "logs":"Logs",
- "choose_lang":"Choose language"
+ "logs":"Protokolle",
+ "choose_lang":"Sprache wählen"
}
diff --git a/deployment/manager/shared/locales/es/or.json b/deployment/manager/shared/locales/es/or.json
index 19fcb2ac4..f28043f4c 100644
--- a/deployment/manager/shared/locales/es/or.json
+++ b/deployment/manager/shared/locales/es/or.json
@@ -107,6 +107,6 @@
"history": "Historia",
"attributes": "Atributos",
"info": "Informacion",
- "logs":"Logs",
- "choose_lang":"Choose language"
+ "logs":"Registros",
+ "choose_lang":"Elige lengua"
}
diff --git a/deployment/manager/shared/locales/fr/or.json b/deployment/manager/shared/locales/fr/or.json
index e879b15dc..01af70372 100644
--- a/deployment/manager/shared/locales/fr/or.json
+++ b/deployment/manager/shared/locales/fr/or.json
@@ -107,6 +107,6 @@
"history": "Historique",
"attributes": "Attributs",
"info": "Info",
- "logs":"Logs",
- "choose_lang":"Choose language"
+ "logs":"Journaux",
+ "choose_lang":"Choisissez la langue"
}
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index 5d7c99267..c06e930e6 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -436,8 +436,23 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
}
} else if (panelConfig && panelConfig.type === "chart") {
+
+ let storeDataPointAttrs = attrs.filter((attr) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!))
+ let defaultAttrs = storeDataPointAttrs.filter((attr) => (defaultAttributes && defaultAttributes.indexOf(attr.name!) >= 0));
+ let assetAttributes;
+
+ if(defaultAttrs.length > 0){
+ assetAttributes = defaultAttrs;
+ } else if(storeDataPointAttrs.length > 0) {
+ assetAttributes = storeDataPointAttrs;
+ assetAttributes.length = 1;
+ }
+ const assetList:Asset[] = [];
+ if(assetAttributes) {
+ assetAttributes.forEach(attr => assetList.push(asset));
+ }
content = html`
- <or-chart id="chart" .config="${viewerConfig.chartConfig}" activeAssetId="${asset.id}" .activeAsset="${asset}" ></or-chart>
+ <or-chart id="chart" .config="${viewerConfig.chartConfig}" .activeAsset="${asset}" activeAssetId="${asset.id}" .assets="${assetList ? assetList : [asset]}" .assetAttributes="${assetAttributes}"></or-chart>
`;
} else if (panelConfig && panelConfig.type === "location") {
diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.ts
index 6c9653a13..b3cd62308 100644
--- a/ui/component/or-chart/src/index.ts
+++ b/ui/component/or-chart/src/index.ts
@@ -11,7 +11,7 @@ import {
} from "lit-element";
import i18next from "i18next";
import {translate} from "@openremote/or-translate";
-import {Asset, AssetAttribute, AttributeRef, DatapointInterval, MetaItemType} from "@openremote/model";
+import {Asset, AssetAttribute, AttributeRef, DatapointInterval, MetaItemType, Attribute} from "@openremote/model";
import manager, {
AssetModelUtil,
DefaultColor2,
@@ -355,9 +355,6 @@ export class OrChart extends translate(i18next)(LitElement) {
@property({type: Array})
public colors: string[] = ["#3869B1", "#DA7E30", "#3F9852", "#CC2428", "#6B4C9A", "#922427", "#958C3D", "#535055"];
- @property({type: Array})
- public usedColors: string[] = [];
-
@property({type: String})
public period: moment.unitOfTime.Base = "day";
@@ -406,13 +403,7 @@ export class OrChart extends translate(i18next)(LitElement) {
this._dialog = new MDCDialog(this._dialogElem);
- this.assetAttributes.map((attr, index) => {
- const meta = {name: "color", value: this.colors[index]};
- if(attr.meta){
- attr.meta.push(meta);
- }
- this.usedColors = [...this.usedColors, this.colors[index]];
- });
+ this.getSettings();
}
}
@@ -435,15 +426,7 @@ export class OrChart extends translate(i18next)(LitElement) {
}
shouldUpdate(_changedProperties: PropertyValues): boolean {
-
- let reloadData = _changedProperties.has("period") || _changedProperties.has("compareTimestamp") || _changedProperties.has("timestamp") || _changedProperties.has("assetAttributes");
-
- if (reloadData) {
- this._data = [];
- this._loadData();
- }
-
- return super.shouldUpdate(_changedProperties);
+ return super.shouldUpdate(_changedProperties);
}
render() {
@@ -499,7 +482,7 @@ export class OrChart extends translate(i18next)(LitElement) {
` : html``}
<div id="attribute-list">
- ${this.assetAttributes.map((attr, index) => {
+ ${this.assetAttributes && this.assetAttributes.map((attr, index) => {
const attributeDescriptor = AssetModelUtil.getAttributeDescriptorFromAsset(attr.name!);
let label = Util.getAttributeLabel(attr, attributeDescriptor);
@@ -569,6 +552,8 @@ export class OrChart extends translate(i18next)(LitElement) {
setPeriodOption(value:any) {
this.period = value;
+
+ this.saveSettings();
this.requestUpdate();
}
@@ -617,9 +602,22 @@ export class OrChart extends translate(i18next)(LitElement) {
super.updated(changedProperties);
if (changedProperties.has("activeAsset") && this.activeAsset && changedProperties.get("activeAsset") !== this.activeAsset) {
this.getSettings();
- } else {
- this.saveSettings();
}
+
+ if(changedProperties.has("assetAttributes") ) {
+ this.assetAttributes.forEach((attr, index) => {
+ if(this.getAttrColor(attr)) return;
+ this.setAttrColor(attr)
+ });
+ }
+
+ let reloadData = changedProperties.has("period") || changedProperties.has("compareTimestamp") || changedProperties.has("timestamp") || changedProperties.has("assetAttributes");
+
+ if (reloadData) {
+ this._data = [];
+ this._loadData();
+ }
+
if (!this._data) {
return;
}
@@ -704,55 +702,47 @@ export class OrChart extends translate(i18next)(LitElement) {
}
getSettings() {
- if(!this.activeAssetId) return
const configStr = window.localStorage.getItem('OrChartConfig')
if(!configStr) return
- const assetId = this.activeAssetId;
+ const viewSelector = this.activeAssetId ? this.activeAssetId : window.location.hash;
const config = JSON.parse(configStr);
- const view = config.views[assetId]
+ const view = config.views[viewSelector]
if(!view) return
const query = {
ids: view.assetIds
}
+
manager.rest.api.AssetResource.queryAssets(query).then((response) => {
const assets = response.data;
- console.log(view.attributes);
this.assets = view.assetIds.map((assetId: string) => assets.find(x => x.id === assetId));
this.assetAttributes = view.attributes.map((attr: string, index: number) => Util.getAssetAttribute(this.assets[index], attr));
- this.timestamp = this._updateTimestamp(view.timestamp)
- this.compareTimestamp = this._updateTimestamp(view.compareTimestamp);
this.period = view.period;
});
}
saveSettings() {
- if(!this.activeAssetId) return
-
- const assetId = this.activeAssetId;
+ const viewSelector = this.activeAssetId ? this.activeAssetId : window.location.hash;
const assets: Asset[] = this.assets.filter(asset => 'id' in asset && typeof asset.id === "string");
const assetIds = assets.map(asset => asset.id);
- console.log(this.assetAttributes)
const attributes = this.assetAttributes.map(attr => attr.name);
const configStr = window.localStorage.getItem('OrChartConfig')
let config:OrChartConfig;
-
if(configStr) {
config = JSON.parse(configStr);
} else {
config = {
views: {
- [assetId]: {}
+ [viewSelector]: {}
}
}
- }
- config.views[assetId] = {
+ }
+
+ config.views[viewSelector] = {
assetIds: assetIds,
- attributes:attributes,
- timestamp: this.timestamp,
- compareTimestamp: this.compareTimestamp,
+ attributes: attributes,
period: this.period
};
window.localStorage.setItem('OrChartConfig', JSON.stringify(config))
@@ -774,20 +764,28 @@ export class OrChart extends translate(i18next)(LitElement) {
if(this.activeAsset){
const attr = Util.getAssetAttribute(this.activeAsset, elm.value);
if(attr){
- const color = this.colors.filter(color => this.usedColors.indexOf(color) < 0)[0];
- const meta = {name: "color", value: color};
- if(attr.meta){
- attr.meta.push(meta);
- }
- this.usedColors = [...this.usedColors, color];
- this.assets = [...this.assets, this.activeAsset];
+ this.setAttrColor(attr);
this.assetAttributes = [...this.assetAttributes, attr];
}
+ this.assets = [...this.assets, this.activeAsset];
}
+ this.saveSettings();
+ }
+ }
+
+ setAttrColor(attr: Attribute) {
+ const usedColors = this.assetAttributes.map(attr => this.getAttrColor(attr));
+ const color = this.colors.filter(color => usedColors.indexOf(color) < 0)[0];
+ const meta = {name: "color", value: color};
+ if(attr.meta){
+ attr.meta.push(meta);
}
}
-
+ getAttrColor(attr: Attribute) {
+ return Util.getMetaValue('color', attr, undefined);
+ }
+
async onCompleted() {
await this.updateComplete;
}
@@ -802,7 +800,8 @@ export class OrChart extends translate(i18next)(LitElement) {
protected _deleteAttribute (index:number) {
this.assets = [...this.assets.slice(0, index).concat(this.assets.slice(index + 1, this.assets.length))];
this.assetAttributes = [...this.assetAttributes.slice(0, index).concat(this.assetAttributes.slice(index + 1, this.assetAttributes.length))];
- this.usedColors = [...this.usedColors.slice(0, index).concat(this.usedColors.slice(index + 1, this.usedColors.length))];
+
+ this.saveSettings();
}
protected _getAttributeOptions() {
@@ -859,13 +858,10 @@ export class OrChart extends translate(i18next)(LitElement) {
if(!this.assetAttributes || !this.assets || this.assets.length === 0) {
return;
}
- console.log(this.assetAttributes, this.assets);
- let data = this.assetAttributes.map(async (attribute, index) => {
- const valuepoints = await this._loadAttributeData(attribute, this.timestamp);
- const bgColor = Util.getMetaValue('color', attribute, undefined);
+
+ const datasetBases = this.assetAttributes.map(attribute => {
+ const bgColor = this.getAttrColor(attribute);
const dataset: ChartDataSets = {
- data: valuepoints,
- label: this.assets[index]!.name +" "+ Util.getAttributeLabel(attribute, undefined),
borderColor: bgColor,
pointRadius: 2,
backgroundColor: bgColor,
@@ -874,6 +870,17 @@ export class OrChart extends translate(i18next)(LitElement) {
return dataset;
});
+ let data = this.assetAttributes.map(async (attribute, index) => {
+ const valuepoints = await this._loadAttributeData(attribute, this.timestamp);
+ const dataset = {...datasetBases[index],
+ data: valuepoints
+ };
+ if(this.assets[index])
+ dataset['label'] = this.assets[index]!.name +" "+ Util.getAttributeLabel(attribute, undefined);
+
+ return dataset;
+ });
+
Promise.all(data).then((completed => {
this._baseData = [...completed];
@@ -881,16 +888,13 @@ export class OrChart extends translate(i18next)(LitElement) {
let predictedData = this.assetAttributes.map(async (attribute, index) => {
const valuepoints = await this._loadPredictedAttributeData(attribute, this.timestamp);
- const bgColor = Util.getMetaValue('color', attribute, undefined);
- const dataset: ChartDataSets = {
+ const dataset = {...datasetBases[index],
data: valuepoints,
- label: this.assets[index]!.name +" "+ Util.getAttributeLabel(attribute, undefined)+" "+i18next.t("predicted"),
- borderColor: bgColor,
- borderDash: [2, 4],
- pointRadius: 2,
- backgroundColor: bgColor,
- fill: false
+ borderDash: [2, 4]
};
+
+ if(this.assets[index])
+ dataset['label'] = this.assets[index]!.name +" "+ Util.getAttributeLabel(attribute, undefined)+" "+i18next.t("predicted");
return dataset;
});
@@ -899,31 +903,25 @@ export class OrChart extends translate(i18next)(LitElement) {
if(this.periodCompare) {
const cData = this.assetAttributes.map(async (attribute, index) => {
const valuepoints = await this._loadAttributeData(attribute, this.compareTimestamp);
- const bgColor = Util.getMetaValue('color', attribute, undefined);
- const dataset: ChartDataSets = {
+ const dataset = {...datasetBases[index],
data: valuepoints,
- label: this.assets[index]!.name +" "+ Util.getAttributeLabel(attribute, undefined)+" "+i18next.t("compare"),
- borderColor: Util.getMetaValue('color', attribute, undefined),
- borderDash: [10, 10],
- pointRadius: 2,
- backgroundColor: bgColor,
- fill: false
+ borderDash: [10, 10]
};
+
+ if(this.assets[index])
+ dataset['label'] = this.assets[index]!.name +" "+ Util.getAttributeLabel(attribute, undefined)+" "+i18next.t("compare");
+
return dataset;
});
let cPredictedData = this.assetAttributes.map(async (attribute, index) => {
const valuepoints = await this._loadPredictedAttributeData(attribute, this.compareTimestamp);
- const bgColor = Util.getMetaValue('color', attribute, undefined);
- const dataset: ChartDataSets = {
+ const dataset = {...datasetBases[index],
data: valuepoints,
- label: this.assets[index]!.name +" "+ Util.getAttributeLabel(attribute, undefined)+" "+i18next.t("compare")+" "+i18next.t("predicted"),
- borderColor: bgColor,
- borderDash: [2, 4],
- pointRadius: 2,
- backgroundColor: bgColor,
- fill: false
+ borderDash: [2, 4]
};
+ if(this.assets[index])
+ dataset['label'] = this.assets[index]!.name +" "+ Util.getAttributeLabel(attribute, undefined)+" "+i18next.t("compare")+" "+i18next.t("predicted")
return dataset;
});
diff --git a/ui/component/or-data-viewer/src/index.ts b/ui/component/or-data-viewer/src/index.ts
index 384765d5d..96447fbf7 100644
--- a/ui/component/or-data-viewer/src/index.ts
+++ b/ui/component/or-data-viewer/src/index.ts
@@ -116,10 +116,6 @@ export class OrDataViewer extends subscribe(manager)(translate(i18next)(LitEleme
this.addEventListener(OrChartEvent.NAME,() => OrDataViewer.generateGrid(this.shadowRoot));
}
- firstUpdated() {
- this.loadAssets();
- }
-
protected render() {
if (this._loading) {
@@ -203,33 +199,11 @@ export class OrDataViewer extends subscribe(manager)(translate(i18next)(LitEleme
return;
}
- const defaults = panelConfig && panelConfig.defaults ? panelConfig.defaults : undefined;
- let assetList: Asset[] = [];;
- let assetAttributes: Attribute[] = [];
- if(defaults && this._assets){
- const assetIds = defaults.map(obj => obj.assetId);
- const attributeName = defaults.map(obj => obj.attributes);
-
- this._assets.map(asset => {
- const index = assetIds.indexOf(asset.id);
- if(index >= 0) {
- assetList.push(asset);
- let attrs:Attribute[] = Util.getAssetAttributes(asset);
- if(attrs) {
- attrs = attrs.filter(attr => {
- const name = attributeName[index];
- return attr.name && name && name.includes(attr.name);
- });
- }
- assetAttributes = assetAttributes.concat(attrs)
- }
- });
- }
let content: TemplateResult | undefined;
if (panelConfig && panelConfig.type === "chart") {
content = html`
- <or-chart id="chart" .config="${this.config.chartConfig}" .assets="${assetList ? assetList : []}" .assetAttributes="${assetAttributes}">></or-chart>
+ <or-chart id="chart" .config="${this.config.chartConfig}"></or-chart>
`;
}
@@ -237,19 +211,4 @@ export class OrDataViewer extends subscribe(manager)(translate(i18next)(LitEleme
return content;
}
-
- protected async loadAssets() {
- const query = {
- select: {
- excludeAttributeMeta: true,
- excludeAttributeTimestamp: true,
- excludeAttributeValue: true,
- excludeParentInfo: true,
- excludeRealm: true,
- excludePath: true
- }
- };
- const response = await manager.rest.api.AssetResource.queryAssets(query);
- this._assets = response.data;
- }
}
diff --git a/ui/component/or-header/src/index.ts b/ui/component/or-header/src/index.ts
index 26686a04c..e761dfaca 100644
--- a/ui/component/or-header/src/index.ts
+++ b/ui/component/or-header/src/index.ts
@@ -87,7 +87,7 @@ const secondaryItems: menuOption[] = [
function getHeaderMenu(items: menuOption[]): MenuItem[] {
return items.map(option => {
return {
- text: i18next.t(option.text),
+ text: option.text,
value: option.value ? option.value : "",
icon: option.icon,
href: option.href
diff --git a/ui/component/or-header/src/or-language-modal.ts b/ui/component/or-header/src/or-language-modal.ts
index bbb2e2e0a..9e8651ca8 100644
--- a/ui/component/or-header/src/or-language-modal.ts
+++ b/ui/component/or-header/src/or-language-modal.ts
@@ -34,7 +34,9 @@ export const languageOptions: languageOptions = {
};
const getLanguageOptions = () => {
- return Object.entries(languageOptions);
+ return Object.entries(languageOptions).map(([key, value]) => {
+ return [key, i18next.t(value)]
+ });
}
@customElement("or-language-modal")
@@ -60,7 +62,6 @@ export class OrLanguageModal extends LitElement {
];
}
-
firstUpdated() {
this.language = manager.language ? manager.language : "en";
this._dialog = new MDCDialog(this._dialogElem);
@@ -76,7 +77,7 @@ export class OrLanguageModal extends LitElement {
aria-describedby="my-dialog-content">
<div class="mdc-dialog__container">
<div class="mdc-dialog__surface">
- <h2 class="mdc-dialog__title" id="my-dialog-title">${i18next.t("choose_lang")}</h2>
+ <h2 class="mdc-dialog__title" id="my-dialog-title"><or-translate value="choose_lang"></or-translate></h2>
<div class="dialog-container mdc-dialog__content" id="language-dialog-content">
<or-input id="language-picker"
.label="${i18next.t("language")}"
@@ -111,6 +112,8 @@ export class OrLanguageModal extends LitElement {
if(this.shadowRoot && this.shadowRoot.getElementById('language-picker')){
const elm = this.shadowRoot.getElementById('language-picker') as HTMLInputElement;
manager.language = elm.value;
+ this.language = manager.language;
+ this.requestUpdate();
}
}
}
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index fdf530f61..31413df9f 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -413,7 +413,7 @@ export class OrInput extends LitElement {
if (this.value === optValue) {
this._selectedIndex = index;
}
- return html`<li class="mdc-list-item${this.value === optValue ? " mdc-list-item--selected" : ""}" role="option" data-value="${optValue}">${i18next.t(optDisplay)}</li>`;
+ return html`<li class="mdc-list-item${this.value === optValue ? " mdc-list-item--selected" : ""}" role="option" data-value="${optValue}"><or-translate value="${optDisplay}"></or-translate></li>`;
}) : ``}
</ul>
</div>
diff --git a/ui/component/or-map/src/or-map-asset-card.ts b/ui/component/or-map/src/or-map-asset-card.ts
index 1daa1c274..9bfea4831 100644
--- a/ui/component/or-map/src/or-map-asset-card.ts
+++ b/ui/component/or-map/src/or-map-asset-card.ts
@@ -29,27 +29,28 @@ import {mapAssetCardStyle} from "./style";
orAttributeTemplateProvider.setTemplate((attribute:Attribute) => {
let template;
+ const value = attribute.value ? attribute.value : "-";
switch (attribute.type) {
case AttributeValueType.BOOLEAN.name:
- template = html`<or-translate value="${attribute.value}"></or-translate>`;
+ template = html`<or-translate value="${value}"></or-translate>`;
break;
case AttributeValueType.SWITCH_TOGGLE.name:
- template = html`<or-translate value="${attribute.value ? "On" : "Off"}"></or-translate>`;
+ template = html`<or-translate value="${value ? "On" : "Off"}"></or-translate>`;
break;
case AttributeValueType.NUMBER.name:
case AttributeValueType.SOUND.name:
- template = attribute.value ? new Intl.NumberFormat().format(attribute.value) : "-";
+ template = attribute.value ? new Intl.NumberFormat().format(value) : "-";
break;
case AttributeValueType.STRING.name:
- template = html`<or-translate value="${attribute.value}"></or-translate>`;
+ template = html`<or-translate value="${value}"></or-translate>`;
break;
case AttributeValueType.OBJECT.name:
case AttributeValueType.ARRAY.name:
if(attribute.name === "status") {
- template = html`<or-translate value="${attribute.value.result}"></or-translate>`;
+ template = html`<or-translate value="${value.result}"></or-translate>`;
}
- else if(attribute.value && attribute.value.content.time) {
+ else if(value && value.content.time) {
template = new Intl.DateTimeFormat('default', {
year: 'numeric',
month: 'numeric',
@@ -60,7 +61,7 @@ orAttributeTemplateProvider.setTemplate((attribute:Attribute) => {
}
break;
default:
- template = attribute.value ? attribute.value : "-";
+ template = value;
break;
}
return template;
diff --git a/ui/component/or-mwc-components/src/or-mwc-menu.ts b/ui/component/or-mwc-components/src/or-mwc-menu.ts
index 550fc2a6c..a01aafb8d 100644
--- a/ui/component/or-mwc-components/src/or-mwc-menu.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-menu.ts
@@ -214,8 +214,8 @@ export class OrMwcMenu extends LitElement {
${leftTemplate}
${!text ? html`` : html`
<span class="mdc-list-item__text">
- <span class="${this.twoLine ? "mdc-list-item__primary-text" : ""}">${item.text}</span>
- ${this.twoLine ? html`<span class="mdc-list-item__secondary-text">${item.secondaryText || ""}</span>` : ``}
+ <span class="${this.twoLine ? "mdc-list-item__primary-text" : ""}"><or-translate value="${item.text}"></or-translate></span>
+ ${this.twoLine ? html`<span class="mdc-list-item__secondary-text"><or-translate value="${item.secondaryText}"></or-translate></span>` : ``}
</span>
`}
${rightTemplate}