Skip to content

armgit / core

Public Imported from GitHub
0

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

Add or-map-asset-card, improve rules ui & header

Robin Dekkers3f94f1b52201
diff --git a/deployment/manager/shared/locales/de/or.json b/deployment/manager/shared/locales/de/or.json
index 16fc5ba1f..21f8c4fa6 100644
--- a/deployment/manager/shared/locales/de/or.json
+++ b/deployment/manager/shared/locales/de/or.json
@@ -106,5 +106,7 @@
"wait": "Warte",
"history": "Historie",
"attributes": "Attribute",
- "info": "Info"
+ "info": "Info",
+ "logs":"Logs",
+ "choose_lang":"Choose language"
}
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.json
index c0fb693bb..4382f0f38 100644
--- a/deployment/manager/shared/locales/en/or.json
+++ b/deployment/manager/shared/locales/en/or.json
@@ -167,5 +167,7 @@
"oncePerDay": "Once per day",
"oncePerWeek": "Once per week",
"reset": "Reset",
- "noLongerMatches": "No longer matches"
+ "noLongerMatches": "No longer matches",
+ "logs":"Logs",
+ "choose_lang":"Choose language"
}
diff --git a/deployment/manager/shared/locales/es/or.json b/deployment/manager/shared/locales/es/or.json
index 53daf521c..19fcb2ac4 100644
--- a/deployment/manager/shared/locales/es/or.json
+++ b/deployment/manager/shared/locales/es/or.json
@@ -106,5 +106,7 @@
"wait": "Espere",
"history": "Historia",
"attributes": "Atributos",
- "info": "Informacion"
+ "info": "Informacion",
+ "logs":"Logs",
+ "choose_lang":"Choose language"
}
diff --git a/deployment/manager/shared/locales/fr/or.json b/deployment/manager/shared/locales/fr/or.json
index 24840f366..e879b15dc 100644
--- a/deployment/manager/shared/locales/fr/or.json
+++ b/deployment/manager/shared/locales/fr/or.json
@@ -106,5 +106,7 @@
"wait": "Attendre",
"history": "Historique",
"attributes": "Attributs",
- "info": "Info"
+ "info": "Info",
+ "logs":"Logs",
+ "choose_lang":"Choose language"
}
diff --git a/deployment/manager/shared/locales/nl/or.json b/deployment/manager/shared/locales/nl/or.json
index 93da5f23f..69bab9cfd 100644
--- a/deployment/manager/shared/locales/nl/or.json
+++ b/deployment/manager/shared/locales/nl/or.json
@@ -6,7 +6,7 @@
"asset": "Asset",
"asset_plural": "Assets",
"attribute": "Attribuut",
- "insights": "Insights",
+ "insights": "Inzicht",
"scenes": "Scenes",
"settings": "Instellingen",
"selectLanguage": "Taal kiezen",
@@ -167,5 +167,7 @@
"oncePerDay": "Max. 1x per dag",
"oncePerWeek": "Max. 1x per week",
"reset": "Reset",
- "noLongerMatches": "Niet meer geldig"
+ "noLongerMatches": "Niet meer geldig",
+ "logs":"Logs",
+ "choose_lang":"Kies een taal"
}
diff --git a/ui/app/main/src/components/pages/page-map.ts b/ui/app/main/src/components/pages/page-map.ts
index 1f981d01a..0f386cf08 100644
--- a/ui/app/main/src/components/pages/page-map.ts
+++ b/ui/app/main/src/components/pages/page-map.ts
@@ -1,19 +1,33 @@
import {css, customElement, html, LitElement, property, query} from "lit-element";
import {connect} from "pwa-helpers/connect-mixin";
import "@openremote/or-map";
+import "@openremote/or-map/dist/or-map-asset-card";
+import {ViewerConfig} from "@openremote/or-map/dist/or-map-asset-card";
+
+import {Util} from "@openremote/core";
import {OrMap, OrMapClickedEvent, OrMapMarkerAsset, OrMapMarkerClickedEvent} from "@openremote/or-map";
import {RootState, store} from "../../store";
import {setCurrentAssetId, subscribeAssets, unsubscribeAssets} from "../../actions/map";
import map from "../../reducers/map";
import {createSelector} from "reselect";
-import {Asset} from "@openremote/model";
-import "../or-asset-summary-card";
+import {Asset, AttributeType, MetaItemType} from "@openremote/model";
import {MapStyle} from "./style";
import {router} from "../../index";
store.addReducers({
map
});
+const mapCardConfig: ViewerConfig = {
+ default: {
+ exclude: ["userNotes"]
+ },
+ assetTypes: {
+ "urn:openremote:asset:iems:weather": {
+ exclude: ["location"]
+ }
+ }
+};
+
@customElement("page-map")
class PageMap extends connect(store)(LitElement) {
@@ -52,11 +66,14 @@ class PageMap extends connect(store)(LitElement) {
return html`
- ${this._currentAsset ? html `<or-asset-summary-card .asset="${this._currentAsset}"> </or-asset-summary-card>` : ``}
+ ${this._currentAsset ? html `<or-map-asset-card .config="${mapCardConfig}" .asset="${this._currentAsset}"></or-map-asset-card>` : ``}
<or-map id="map" class="or-map">
${
this._assets.map((asset) => {
+ const attr = Util.getAssetAttribute(asset, AttributeType.LOCATION.attributeName!);
+ const showOnMapMeta = Util.getFirstMetaItem(attr, MetaItemType.SHOW_ON_DASHBOARD.urn!);
+ if(!showOnMapMeta || !showOnMapMeta.value) return html``;
return html`
<or-map-marker-asset ?active="${this._currentAsset && this._currentAsset.id === asset.id}" .asset="${asset}"></or-map-marker-asset>
`;
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index e297732f0..5d7c99267 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -101,7 +101,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
"info": {
type: "attribute",
hideOnMobile: true,
- include: ["userNotes", "brand"],
+ include: ["userNotes", "manufacturer", "model"],
panelStyles: {
},
fieldStyles: {
@@ -304,12 +304,10 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
public static getPanel(name: string, asset: Asset, attributes: AssetAttribute[], viewerConfig: AssetViewerConfig, panelConfig: PanelConfig, shadowRoot: ShadowRoot | null) {
const content = OrAssetViewer.getPanelContent(name, asset, attributes, viewerConfig, panelConfig, shadowRoot);
-
if (!content) {
return;
}
-
return html`
<div class=${classMap({"panel": true, mobileHidden: panelConfig.hideOnMobile === true})} id="${name}-panel" style="${panelConfig && panelConfig.panelStyles ? styleMap(panelConfig.panelStyles) : ""}">
<div class="panel-content-wrapper">
@@ -438,22 +436,8 @@ 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}" .activeAsset="${asset}" .assets="${assetList ? assetList : [asset]}" .assetAttributes="${assetAttributes}"></or-chart>
+ <or-chart id="chart" .config="${viewerConfig.chartConfig}" activeAssetId="${asset.id}" .activeAsset="${asset}" ></or-chart>
`;
} else if (panelConfig && panelConfig.type === "location") {
@@ -516,11 +500,13 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
`;
}
} else {
+ if(attrs.length === 0) return undefined;
+
content = html`
${attrs.sort((attr1, attr2) => attr1.name! < attr2.name! ? -1 : attr1.name! > attr2.name! ? 1 : 0).map((attr) => {
- let style = styles ? styles[attr.name!] : undefined;
- return this.getField(attr.name!, false, style, OrAssetViewer.getAttributeTemplate(asset, attr, viewerConfig, panelConfig));
- })}
+ let style = styles ? styles[attr.name!] : undefined;
+ return this.getField(attr.name!, false, style, OrAssetViewer.getAttributeTemplate(asset, attr, viewerConfig, panelConfig));
+ })}
`;
}
@@ -580,7 +566,6 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
return result;
}
}
-
return html`
<or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}" .label="${i18next.t(attribute.name!)}"></or-attribute-input>
`;
@@ -590,7 +575,6 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
if (!content) {
return ``;
}
-
return html`
<div id="field-${name}" style="${styles ? styleMap(styles) : ""}" class="field ${isProperty ? "field-property" : "field-attribute"}">
${content}
diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.ts
index 682ef56ca..6c9653a13 100644
--- a/ui/component/or-chart/src/index.ts
+++ b/ui/component/or-chart/src/index.ts
@@ -47,6 +47,13 @@ export class OrChartEvent extends CustomEvent<OrChartEventDetail> {
});
}
}
+export interface ChartViewConfig {
+ assetIds?: (string|undefined)[];
+ attributes?: (string|undefined)[];
+ timestamp?: Date;
+ compareTimestamp?: Date;
+ period?: moment.unitOfTime.Base;
+}
export interface OrChartEventDetail {
value?: any;
@@ -67,6 +74,7 @@ export interface ChartConfig {
export interface OrChartConfig {
chart?: ChartConfig;
+ views: {[name: string]: ChartViewConfig};
}
// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling
const dialogStyle = require("!!raw-loader!@material/dialog/dist/mdc.dialog.css");
@@ -332,6 +340,9 @@ export class OrChart extends translate(i18next)(LitElement) {
@property({type: Object})
public assets: Asset[] = [];
+ @property({type: String})
+ public activeAssetId?:string;
+
@property({type: Object})
private activeAsset?: Asset;
@@ -526,6 +537,7 @@ export class OrChart extends translate(i18next)(LitElement) {
<or-asset-tree id="chart-asset-tree" .selectedIds="${this.activeAsset ? [this.activeAsset.id] : null}]"></or-asset-tree>
${this.activeAsset && this.activeAsset.attributes ? html`
<or-input id="chart-attribute-picker"
+ style="display:flex;"
.label="${i18next.t("attribute")}"
.type="${InputType.LIST}"
.options="${this._getAttributeOptions()}"></or-input>
@@ -603,7 +615,11 @@ export class OrChart extends translate(i18next)(LitElement) {
updated(changedProperties: PropertyValues) {
super.updated(changedProperties);
-
+ if (changedProperties.has("activeAsset") && this.activeAsset && changedProperties.get("activeAsset") !== this.activeAsset) {
+ this.getSettings();
+ } else {
+ this.saveSettings();
+ }
if (!this._data) {
return;
}
@@ -681,13 +697,67 @@ export class OrChart extends translate(i18next)(LitElement) {
this._chart.update();
}
}
-
this.onCompleted().then(() => {
this.dispatchEvent(new OrChartEvent('rendered'));
});
}
+ getSettings() {
+ if(!this.activeAssetId) return
+ const configStr = window.localStorage.getItem('OrChartConfig')
+ if(!configStr) return
+
+ const assetId = this.activeAssetId;
+ const config = JSON.parse(configStr);
+ const view = config.views[assetId]
+
+ 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 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]: {}
+ }
+ }
+ }
+ config.views[assetId] = {
+ assetIds: assetIds,
+ attributes:attributes,
+ timestamp: this.timestamp,
+ compareTimestamp: this.compareTimestamp,
+ period: this.period
+ };
+ window.localStorage.setItem('OrChartConfig', JSON.stringify(config))
+ }
+
_openDialog() {
const component = this.shadowRoot!.getElementById("mdc-dialog");
if(component){
@@ -789,7 +859,7 @@ 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);
diff --git a/ui/component/or-header/src/index.ts b/ui/component/or-header/src/index.ts
index 60ea0b9eb..26686a04c 100644
--- a/ui/component/or-header/src/index.ts
+++ b/ui/component/or-header/src/index.ts
@@ -58,13 +58,13 @@ const secondaryItems: menuOption[] = [
{
icon: "web",
value: "language",
- text: "Language"
+ text: "lang"
},
{
icon: "file-document-box-search-outline",
value: "logs",
href: "#!logs",
- text: "Logs"
+ text: "logs"
},
// {
// icon: "account-cog",
@@ -80,7 +80,7 @@ const secondaryItems: menuOption[] = [
{
icon: "logout",
value: "logout",
- text: "Log out"
+ text: "logout"
}
];
@@ -114,7 +114,7 @@ class OrHeader extends LitElement {
private secondaryItems: menuOption[] = secondaryItems;
@property({ type: String })
- private activeMenu: string | undefined = window.location.hash;
+ private activeMenu: string | undefined = window.location.hash ? window.location.hash : "#!map";
@query("slot[name=mobile-bottom]")
protected _mobileBottomSlot?: HTMLSlotElement;
@@ -157,9 +157,9 @@ class OrHeader extends LitElement {
getHeaderMenu(this.secondaryItems),
this.activeMenu,
(values: string | string[]) => this.setActiveMenu(values as string))}
- <span id="menu-btn-mobile" >
+ <div id="menu-btn-mobile" >
<button id="menu-btn" class="menu-btn" title="Menu" @click="${this._menuButtonClicked}">${this._drawerOpened ? html`<or-icon icon="close"></or-icon>` : html`<or-icon icon="menu"></or-icon>`}</button>
- </span>
+ </div>
</div>
</div>
<or-language-modal id="language-modal"></or-language-modal>
diff --git a/ui/component/or-header/src/or-language-modal.ts b/ui/component/or-header/src/or-language-modal.ts
index a75989bc1..bbb2e2e0a 100644
--- a/ui/component/or-header/src/or-language-modal.ts
+++ b/ui/component/or-header/src/or-language-modal.ts
@@ -76,7 +76,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">Choice language</h2>
+ <h2 class="mdc-dialog__title" id="my-dialog-title">${i18next.t("choose_lang")}</h2>
<div class="dialog-container mdc-dialog__content" id="language-dialog-content">
<or-input id="language-picker"
.label="${i18next.t("language")}"
diff --git a/ui/component/or-header/src/style.ts b/ui/component/or-header/src/style.ts
index 0472170cb..bc40e1551 100644
--- a/ui/component/or-header/src/style.ts
+++ b/ui/component/or-header/src/style.ts
@@ -115,13 +115,11 @@ export const style = css`
}
#mobile-bottom {
+ border-top: 1px solid var(--internal-or-header-drawer-separator-color);
margin-top: 20px;
+ padding-top: 10px;
}
-
- #mobile-bottom.has-children {
- border-top: 2px solid var(--internal-or-header-drawer-separator-color);
- }
-
+
.menu-item {
opacity: 0.7;
cursor: pointer;
@@ -133,6 +131,7 @@ export const style = css`
+ .menu-item:hover,
.menu-item[selected] {
opacity: 1;
}
@@ -157,7 +156,11 @@ export const style = css`
display: inline-block;
line-height: var(--internal-or-header-height);
}
-
+
+ or-mwc-menu {
+ margin-right: 10px;
+ display: block;
+ }
/* Wide layout: when the viewport width is bigger than 780px, layout
changes to a wide layout. */
@@ -168,15 +171,7 @@ export const style = css`
display: block;
}
- #logo {
- margin: var(--internal-or-header-logo-margin);
- height: var(--internal-or-header-logo-height);
- display: block;
- }
-
- #logo-mobile {
- display: none;
- }
+
#menu-btn-mobile {
display: none;
@@ -205,6 +200,16 @@ export const style = css`
}
@media (min-width: 1024px) {
+ #logo {
+ margin: var(--internal-or-header-logo-margin);
+ height: var(--internal-or-header-logo-height);
+ display: block;
+ }
+
+ #logo-mobile {
+ display: none;
+ }
+
#desktop-left .menu-item or-icon{
display: inline-block;
}
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index c5644d83e..fdf530f61 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -14,6 +14,8 @@ import {MDCIconButtonToggle, MDCIconButtonToggleEventDetail} from "@material/ico
import moment from "moment";
import {DefaultColor1, DefaultColor4, DefaultColor8} from "@openremote/core";
+import i18next from "i18next";
+
// 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");
const buttonFabStyle = require("!!raw-loader!@material/fab/dist/mdc.fab.css");
@@ -122,6 +124,11 @@ const style = css`
flex: 1 1 0;
}
+ .mdc-list {
+ flex: 1 1 0;
+ overflow: auto;
+ }
+
#menu-anchor {
max-width: 100%;
}
@@ -400,13 +407,13 @@ export class OrInput extends LitElement {
this._selectedIndex = -1;
return html`
- <div id="component" class="mdc-select ${classMap(classesList)}" @MDCList:action="${(e: MDCListActionEvent) => 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="component" class="mdc-list mdc-select ${classMap(classesList)}" @MDCList:action="${(e: MDCListActionEvent) => 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])}">
<ul class="mdc-list">
${optsList ? optsList.map(([optValue, optDisplay], index) => {
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}">${optDisplay}</li>`;
+ return html`<li class="mdc-list-item${this.value === optValue ? " mdc-list-item--selected" : ""}" role="option" data-value="${optValue}">${i18next.t(optDisplay)}</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
new file mode 100644
index 000000000..1daa1c274
--- /dev/null
+++ b/ui/component/or-map/src/or-map-asset-card.ts
@@ -0,0 +1,199 @@
+import {
+ css,
+ CSSResult,
+ CSSResultArray,
+ customElement,
+ html,
+ LitElement,
+ property,
+ PropertyValues,
+ TemplateResult,
+ unsafeCSS
+} from "lit-element";
+import {Asset,Attribute, AssetEvent, AssetEventCause, AttributeEvent, AttributeType, AttributeValueType, MetaItemType, AttributeDescriptor} from "@openremote/model";
+import manager, {
+ AssetModelUtil,
+ DefaultColor1,
+ DefaultColor3,
+ DefaultColor4,
+ DefaultColor5,
+ DefaultHeaderHeight,
+ subscribe,
+ Util
+} from "@openremote/core";
+import "@openremote/or-icon";
+import "./or-map-attribute-field";
+import {orAttributeTemplateProvider} from "./or-map-attribute-field";
+import { i18next } from "@openremote/or-translate";
+import {mapAssetCardStyle} from "./style";
+
+orAttributeTemplateProvider.setTemplate((attribute:Attribute) => {
+ let template;
+ switch (attribute.type) {
+
+ case AttributeValueType.BOOLEAN.name:
+ template = html`<or-translate value="${attribute.value}"></or-translate>`;
+ break;
+ case AttributeValueType.SWITCH_TOGGLE.name:
+ template = html`<or-translate value="${attribute.value ? "On" : "Off"}"></or-translate>`;
+ break;
+ case AttributeValueType.NUMBER.name:
+ case AttributeValueType.SOUND.name:
+ template = attribute.value ? new Intl.NumberFormat().format(attribute.value) : "-";
+ break;
+ case AttributeValueType.STRING.name:
+ template = html`<or-translate value="${attribute.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>`;
+ }
+ else if(attribute.value && attribute.value.content.time) {
+ template = new Intl.DateTimeFormat('default', {
+ year: 'numeric',
+ month: 'numeric',
+ day: 'numeric',
+ hour: 'numeric',
+ minute: 'numeric'
+ }).format(new Date(attribute.value.content.time));
+ }
+ break;
+ default:
+ template = attribute.value ? attribute.value : "-";
+ break;
+ }
+ return template;
+});
+
+export interface MapAssetCardConfig {
+ include?: string[];
+ exclude?: string[];
+}
+
+
+export interface ViewerConfig {
+ default?: MapAssetCardConfig;
+ assetTypes?: { [assetType: string]: MapAssetCardConfig };
+}
+
+@customElement("or-map-asset-card")
+export class OrMapAssetCard extends subscribe(manager)(LitElement) {
+
+ @property({type: String, reflect: true, attribute: true})
+ public assetId?: string;
+
+ @property({type: Object, attribute: true})
+ public asset?: Asset;
+
+ @property({type: Object})
+ public config?: ViewerConfig;
+
+ @property({type: Boolean, attribute: true})
+ public useAssetColor: boolean = true;
+
+ static get styles(): CSSResultArray | CSSResult {
+ return mapAssetCardStyle;
+ }
+
+ protected shouldUpdate(_changedProperties: PropertyValues): boolean {
+
+ if (_changedProperties.has("assetId")) {
+ this.title = "";
+ this.assetIds = this.assetId && this.assetId.length > 0 ? [this.assetId] : undefined;
+
+ if (Object.keys(_changedProperties).length === 1) {
+ return false;
+ }
+ }
+
+ return super.shouldUpdate(_changedProperties);
+ }
+
+ public onAttributeEvent(event: AttributeEvent) {
+
+ if (this.asset) {
+ this.asset = Util.updateAsset(this.asset, event);
+ this.requestUpdate();
+ }
+ }
+
+ public onAssetEvent(event: AssetEvent) {
+ switch (event.cause) {
+ case AssetEventCause.READ:
+ case AssetEventCause.CREATE:
+ case AssetEventCause.UPDATE:
+ this.asset = event.asset;
+ break;
+ case AssetEventCause.DELETE:
+ this.asset = undefined;
+ break;
+ }
+ }
+
+ getCardConfig() {
+ if(!this.config) return;
+ if(!this.asset) return this.config.default;
+
+ const config = this.config.assetTypes && this.config.assetTypes.hasOwnProperty(this.asset.type!) ? this.config.assetTypes[this.asset.type!] : this.config.default;
+
+ return config;
+ }
+
+ protected render(): TemplateResult | undefined {
+
+ if (!this.asset) {
+ return html``;
+ }
+
+ const icon = this.getIcon();
+ const color = this.getColor();
+ const styleStr = color ? "--internal-or-asset-summary-card-header-color: #" + color + ";" : "";
+ const cardConfig = this.getCardConfig();
+ const attributes = Util.getAssetAttributes(this.asset).filter((attr) => attr.name !== AttributeType.LOCATION.attributeName);
+ const includedAttributes = cardConfig && cardConfig.include ? cardConfig.include : undefined;
+ const excludedAttributes = cardConfig && cardConfig.exclude ? cardConfig.exclude : [];
+ const attrs = attributes.filter((attr) =>
+ (!includedAttributes || includedAttributes.indexOf(attr.name!) >= 0)
+ && (!excludedAttributes || excludedAttributes.indexOf(attr.name!) < 0));
+
+ return html`
+ <div id="card-container" style="${styleStr}">
+ <div id="header">
+ ${icon ? html`<or-icon icon="${icon}"></or-icon>` : ``}
+ <span id="title">${this.asset.name}</span>
+ </div>
+ <div id="attribute-list">
+ <ul>
+ ${attrs.map((attr) => {
+ let attributeDescriptor: AttributeDescriptor | undefined = AssetModelUtil.getAttributeDescriptorFromAsset(attr.name!);
+ let label = Util.getAttributeLabel(attr, attributeDescriptor);
+ const unit = Util.getMetaValue(MetaItemType.UNIT_TYPE, attr, attributeDescriptor);
+
+ if(unit)
+ label = label + " ("+i18next.t(unit)+")";
+ return html`<li><span class="attribute-name">${label}</span><span class="attribute-value"><or-attribute-field .attribute="${attr}"></or-attribute-field></span></li>`;
+ })}
+ </ul>
+ </div>
+ <div id="footer">
+ <a data-navigo href="#!assets/${this.asset.id}">Asset details</a>
+ </div>
+ </div>
+ `;
+ }
+
+ protected getIcon(): string | undefined {
+ if (this.asset) {
+ const descriptor = AssetModelUtil.getAssetDescriptor(this.asset.type);
+ return descriptor ? descriptor.icon : undefined;
+ }
+ }
+
+ protected getColor(): string | undefined {
+ if (this.asset) {
+ const descriptor = AssetModelUtil.getAssetDescriptor(this.asset.type);
+ return descriptor ? descriptor.color : undefined;
+ }
+ }
+}
diff --git a/ui/app/main/src/components/or-attribute-field/src/index.ts b/ui/component/or-map/src/or-map-attribute-field.ts
similarity index 86%
rename from ui/app/main/src/components/or-attribute-field/src/index.ts
rename to ui/component/or-map/src/or-map-attribute-field.ts
index 312547aaf..52eec8c5b 100644
--- a/ui/app/main/src/components/or-attribute-field/src/index.ts
+++ b/ui/component/or-map/src/or-map-attribute-field.ts
@@ -10,9 +10,9 @@ import manager, {subscribe} from "@openremote/core";
import "@openremote/or-input";
class ORAttributeTemplateProvider {
- _template = null;
+ _template: Function | null = null;
- getTemplate(object) {
+ getTemplate(object:AssetAttribute | undefined) {
if(this._template){
const template = this._template(object);
if (template) {
@@ -21,14 +21,14 @@ class ORAttributeTemplateProvider {
}
}
- setTemplate(callback) {
+ setTemplate(callback: Function) {
this._template = callback;
}
}
export let orAttributeTemplateProvider = new ORAttributeTemplateProvider();
-orAttributeTemplateProvider.setTemplate((attribute) => {
+orAttributeTemplateProvider.setTemplate((attribute: AssetAttribute) => {
let template;
switch (attribute.type) {
default:
diff --git a/ui/component/or-map/src/style.ts b/ui/component/or-map/src/style.ts
index 59650a91c..ed4c4c2ae 100644
--- a/ui/component/or-map/src/style.ts
+++ b/ui/component/or-map/src/style.ts
@@ -1,5 +1,5 @@
import {css, unsafeCSS} from "lit-element";
-import { DefaultColor1, DefaultColor4, DefaultBoxShadow} from "@openremote/core";
+import { DefaultColor1, DefaultColor3, DefaultColor4, DefaultColor5, DefaultHeaderHeight, DefaultBoxShadow} from "@openremote/core";
export const markerColorVar = "--internal-or-map-marker-color";
export const markerActiveColorVar = "--internal-or-map-marker-active-color";
@@ -137,4 +137,104 @@ export const style = css`
right: 12px;
}
}
-`;
\ No newline at end of file
+`;
+
+export const mapAssetCardStyle = css`
+ :host {
+ --internal-or-asset-summary-card-header-color: var(--or-asset-summary-card-header-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));
+ --internal-or-asset-summary-card-header-text-color: var(--or-asset-summary-card-header-text-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));
+ --internal-or-asset-summary-card-header-height: var(--or-asset-summary-card-header-height, calc(${unsafeCSS(DefaultHeaderHeight)} - 10px));
+ --internal-or-asset-summary-card-background-color: var(--or-asset-summary-card-background-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));
+ --internal-or-asset-summary-card-background-text-color: var(--or-asset-summary-card-background-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));
+ --internal-or-asset-summary-card-separator-color: var(--or-asset-summary-card-separator-color, var(--or-app-color5, ${unsafeCSS(DefaultColor5)}));
+
+ display: block;
+ }
+
+ #card-container {
+ display: flex;
+ flex-direction: column;
+ height: 100%;
+ background-color: var(--internal-or-asset-summary-card-background-color);
+ -webkit-box-shadow: 1px 1px 2px 0px rgba(0,0,0,0.28);
+ -moz-box-shadow: 1px 1px 2px 0px rgba(0,0,0,0.28);
+ box-shadow: 1px 1px 2px 0px rgba(0,0,0,0.28);
+ }
+
+ #header {
+ height: var(--internal-or-asset-summary-card-header-height);
+ background-color: var(--internal-or-asset-summary-card-header-color);
+ line-height: var(--internal-or-asset-summary-card-header-height);
+ border-bottom: 1px solid ${unsafeCSS(DefaultColor5)};
+ text-align: center;
+ color: var(--internal-or-asset-summary-card-header-text-color);
+ --or-icon-fill: var(--internal-or-asset-summary-card-header-text-color);
+ --or-icon-width: 20px;
+ --or-icon-height: 20px;
+ z-index: 99999;
+ }
+
+ #header > or-icon {
+ margin-right: 5px;
+ }
+
+ #title {
+ font-weight: 500;
+ }
+
+ #attribute-list {
+ flex: 1;
+ color: var(--internal-or-asset-summary-card-background-text-color);
+ padding: 10px 20px;
+ overflow: auto;
+ font-size: 14px;
+ }
+
+ ul {
+ list-style-type: none;
+ margin: 0;
+ padding: 0;
+ }
+
+ li {
+ display: flex;
+ line-height: 30px;
+ }
+
+ .attribute-name {
+ flex: 1;
+ }
+
+ .attribute-value {
+ overflow: hidden;
+ padding-left: 20px;
+ text-align: right;
+ }
+
+ #footer {
+ justify-content: end;
+ display: flex;
+ height: var(--internal-or-asset-summary-card-header-height);
+ border-top: 1px solid var(--internal-or-asset-summary-card-separator-color);
+ text-align: right;
+ }
+
+ #footer > a {
+ line-height: var(--internal-or-asset-summary-card-header-height);
+ font-weight: 500;
+ font-size: 14px;
+ margin-left: auto;
+ margin-right: 20px;
+ text-decoration: none;
+ color: var(--internal-or-asset-summary-card-background-text-color);
+ }
+
+ @media only screen and (min-width: 415px){
+ #card-container {
+ height: 400px; /* fallback for IE */
+ height: max-content;
+ max-height: calc(100vh - 150px);
+ min-height: 134px;
+ }
+ }
+`
\ No newline at end of file
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 8c45b53d9..21ef06aea 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
@@ -47,8 +47,10 @@ export class OrRuleActionAttribute extends translate(i18next)(LitElement) {
public readonly?: boolean;
+ @property({type: Object})
public config?: RulesConfig;
+ @property({type: Object})
public assetDescriptors?: AssetDescriptor[];
@property({type: Array, attribute: false})
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.ts
index eed20beab..c0c0e2674 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
@@ -32,6 +32,7 @@ export class OrRuleActionNotification extends LitElement {
public readonly?: boolean;
+ @property({type: Object})
public config?: RulesConfig;
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts b/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
index d15ae25f7..85e8a0f58 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts
@@ -63,8 +63,10 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {
public readonly?: boolean;
+ @property({type: Object})
public config?: RulesConfig;
+ @property({type: Object})
public assetDescriptors?: AssetDescriptor[];
@property({type: Array, attribute: false})
@@ -275,7 +277,6 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {
];
idOptions.push(...this._assets!.map((asset) => [asset.id!, asset.name!] as [string, string]));
-
return html`
<div class="attribute-group">
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 c42ac0f42..c8412f793 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
@@ -1,4 +1,4 @@
-import {customElement, html, css, LitElement, property, TemplateResult, query} from "lit-element";
+import {customElement, html, css, LitElement, property, TemplateResult, query, PropertyValues} from "lit-element";
import {AssetDescriptor, AssetQueryMatch, RuleCondition, AssetType} from "@openremote/model";
import {
ActionType,
@@ -115,8 +115,10 @@ class OrRuleCondition extends translate(i18next)(LitElement) {
public readonly: boolean = false;
+ @property({type: Object})
public config?: RulesConfig;
+ @property({type: Object})
public assetDescriptors?: AssetDescriptor[];
@query("#asset-query")
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-when.ts b/ui/component/or-rules/src/json-viewer/or-rule-when.ts
index 004e3608b..40db993cc 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-when.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-when.ts
@@ -198,7 +198,6 @@ class OrRuleWhen extends translate(i18next)(LitElement) {
</span>
`;
}
-
return html`
${groupsTemplate}
${itemsTemplate}