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: Added or-attribute-history
Rich Turnera5fa7113d8f4
diff --git a/ui/app/smart-building/package.json b/ui/app/smart-building/package.jsonindex 3c3e4d897..7fc5f00da 100644--- a/ui/app/smart-building/package.json+++ b/ui/app/smart-building/package.json@@ -30,7 +30,7 @@"i18next-xhr-backend": "^2.0.1","lit-element": "^2.0.1","mapbox-gl": "^0.50.0",- "moment": "^2.22.2",+ "moment": "^2.24.0","moment-es6": "^1.0.0","pwa-helpers": "^0.9.0","redux": "^4.0.0",diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.tsindex 4dae94341..cf2afb9f6 100644--- a/ui/component/core/src/util.ts+++ b/ui/component/core/src/util.ts@@ -204,10 +204,11 @@ export function getQueryParameter(name: string): string {return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));}-export function getAssetAttribute(asset: Asset, attributeName: string): Attribute | undefined {+export function getAssetAttribute(asset: Asset, attributeName: string): AssetAttribute | undefined {if (asset.attributes && asset.attributes.hasOwnProperty(attributeName)) {- const attr = asset.attributes[attributeName] as Attribute;+ const attr = asset.attributes[attributeName] as AssetAttribute;attr.name = attributeName;+ attr.assetId = asset.id;return attr;}}diff --git a/ui/component/or-asset-viewer/package.json b/ui/component/or-asset-viewer/package.jsonindex 23b2c0009..fed3aefe5 100644--- a/ui/component/or-asset-viewer/package.json+++ b/ui/component/or-asset-viewer/package.json@@ -14,12 +14,12 @@"@openremote/core": "^1.0.2","@openremote/model": "^1.0.2","@openremote/or-icon": "^1.0.0",- "@openremote/or-select": "^1.0.0",+ "@openremote/or-attribute-input": "^1.0.0",+ "@openremote/or-attribute-history": "^1.0.0","@openremote/or-translate": "^1.0.0",+ "@openremote/or-panel": "^1.0.0","@openremote/rest": "^1.0.2",- "@types/simplebar": "^2.4.2",- "lit-element": "^2.2.1",- "simplebar": "^4.2.3"+ "lit-element": "^2.2.1"},"devDependencies": {"tslint": "^5.11.0",diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.tsindex 3ada708fd..4cdcfc6b8 100644--- a/ui/component/or-asset-viewer/src/index.ts+++ b/ui/component/or-asset-viewer/src/index.ts@@ -1,25 +1,40 @@-import {customElement, html, LitElement, property, PropertyValues, TemplateResult, query} from "lit-element";+import {customElement, html, LitElement, property, PropertyValues, query, TemplateResult} from "lit-element";import "@openremote/or-select";import "@openremote/or-icon";import "@openremote/or-input";import "@openremote/or-attribute-input";+import "@openremote/or-attribute-history";+import {getAttributeLabel} from "@openremote/or-attribute-input";import "@openremote/or-translate";import {translate} from "@openremote/or-translate/dist/translate-mixin";-import {InputType, OrInput} from "@openremote/or-input";-import {Asset, AttributeEvent, AssetEvent, Attribute, AssetAttribute, AttributeType, MetaItemType} from "@openremote/model";+import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-input";+import {+ Asset,+ AssetAttribute,+ AssetEvent,+ Attribute,+ AttributeEvent,+ AttributeType,+ MetaItemType,+ AttributeValueType+} from "@openremote/model";import {style} from "./style";-import "./components/or-panel";+import "@openremote/or-panel";import openremote from "@openremote/core";import rest from "@openremote/rest";import {subscribe} from "@openremote/core/dist/asset-mixin";-import {getAssetAttributes, getFirstMetaItem} from "@openremote/core/dist/util";+import {getAssetAttribute, getAssetAttributes, getFirstMetaItem} from "@openremote/core/dist/util";import i18next from "i18next";import {styleMap} from "lit-html/directives/style-map";import "@openremote/or-map";import {Type as MapType} from "@openremote/or-map";import {getLngLat} from "@openremote/or-map/dist/util";+import {OrAttributeHistory, HistoryConfig} from "@openremote/or-attribute-history";++export type PanelType = "property" | "location" | "attribute" | "history";export interface PanelConfig {+ type?: PanelType;scrollable?: boolean;hide?: boolean;include?: string[];@@ -29,46 +44,88 @@ export interface PanelConfig {fieldStyles?: { [field: string]: { [style: string]: string } };}+export interface AssetViewerConfig {+ panels: {[name: string] : PanelConfig};+ viewerStyles?: { [style: string]: string };+}+export interface ViewerConfig {- default?: {[name: string]: PanelConfig};- assetTypes?: { [assetType: string]: {[name: string]: PanelConfig} };- propertyViewProvider?: (property: string, value: any) => TemplateResult | undefined;- attributeViewProvider?: (attribute: Attribute) => TemplateResult | undefined;- assetNameProvider?: (id: string) => string;+ default?: AssetViewerConfig;+ assetTypes?: { [assetType: string]: AssetViewerConfig };+ propertyViewProvider?: (property: string, value: any, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;+ attributeViewProvider?: (attribute: Attribute, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;+ panelViewProvider?: (attributes: AssetAttribute[], panelName: string, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;mapType?: MapType;+ historyConfig?: HistoryConfig;}@customElement("or-asset-viewer")export class OrAssetViewer extends subscribe(openremote)(translate(i18next)(LitElement)) {- public static DEFAULT_CONFIG: {[name: string]: PanelConfig} = {- "info": {- fieldStyles: {- name: {- width: "60%"+ public static DEFAULT_MAP_TYPE = MapType.VECTOR;+ public static DEFAULT_PANEL_TYPE: PanelType = "attribute";++ public static DEFAULT_CONFIG: AssetViewerConfig = {+ viewerStyles: {+ gridTemplateColumns: "repeat(12, 1fr)",+ gridTemplateRows: "auto minmax(0, 1fr) minmax(0, 50%)"+ },+ panels: {+ "info": {+ type: "property",+ panelStyles: {+ gridColumnStart: "1",+ gridColumnEnd: "7",+ gridRowStart: "1",+ gridRowEnd: "2",},- createdOn: {- width: "40%",- paddingLeft: "20px",- boxSizing: "border-box"+ fieldStyles: {+ name: {+ width: "60%"+ },+ createdOn: {+ width: "40%",+ paddingLeft: "20px",+ boxSizing: "border-box"+ }}- }- },- "location": {- scrollable: false,- include: ["location"],- fieldStyles: {- location: {- height: "100%",- margin: "0"+ },+ "location": {+ type: "location",+ scrollable: false,+ include: ["location"],+ panelStyles: {+ gridColumnStart: "7",+ gridColumnEnd: "13",+ gridRowStart: "1",+ gridRowEnd: "3",+ },+ fieldStyles: {+ location: {+ height: "100%",+ margin: "0"+ }+ }+ },+ "attributes": {+ type: "attribute",+ panelStyles: {+ gridColumnStart: "1",+ gridColumnEnd: "7",+ gridRowStart: "2",+ gridRowEnd: "4"}+ },+ "history": {+ type: "history",+ panelStyles: {+ gridColumnStart: "7",+ gridColumnEnd: "13",+ gridRowStart: "3",+ gridRowEnd: "4",+ },+ scrollable: false,}- },- "attributes": {-- },- "history": {- scrollable: false,}};@@ -101,6 +158,11 @@ export class OrAssetViewer extends subscribe(openremote)(translate(i18next)(LitE@property()protected _loading: boolean = false;+ @query("#history-attribute-picker")+ protected _historyAttributePicker?: OrInput;+ @query("#attribute-history")+ protected _attributeHistory?: OrAttributeHistory;+protected render() {if (this._loading) {@@ -121,18 +183,32 @@ export class OrAssetViewer extends subscribe(openremote)(translate(i18next)(LitE`;}- const panelConfigs = this._getPanelConfig(this.asset!);+ const viewerConfig = this._getPanelConfig(this.asset!);const attributes = getAssetAttributes(this.asset);return html`- <div id="container">- ${html`${Object.entries(panelConfigs).map(([name, config]) => {- const panelTemplate = this._getPanel(name, config, this._getPanelContent(name, attributes, config));+ <div id="container" style="${viewerConfig.viewerStyles ? styleMap(viewerConfig.viewerStyles) : ""}">+ ${html`${Object.entries(viewerConfig.panels).map(([name, panelConfig]) => {+ const panelTemplate = this._getPanel(name, panelConfig, this._getPanelContent(attributes, name, viewerConfig, panelConfig));return panelTemplate || ``;})}`}`;}+ protected updated(_changedProperties: PropertyValues) {+ super.updated(_changedProperties);++ if (_changedProperties.has("assetId")) {+ this.asset = undefined;+ if (this.assetId) {+ this._loading = true;+ super.assetIds = [this.assetId];+ } else {+ super.assetIds = undefined;+ }+ }+ }+protected _getInfoProperties(config?: PanelConfig): string[] {let properties = config && config.include ? config.include : OrAssetViewer.DEFAULT_INFO_PROPERTIES;@@ -150,74 +226,169 @@ export class OrAssetViewer extends subscribe(openremote)(translate(i18next)(LitEreturn html`<div class="panel" id="${name}-panel" style="${config && config.panelStyles ? styleMap(config.panelStyles) : ""}">-- <div class="panel-title">- <or-translate value="${name}"></or-translate>- </div>- ${!config || config.scrollable === undefined || config.scrollable ? html`- <or-panel class="panel-content-wrapper">- <div class="panel-content">- ${content}- </div>- </or-panel>- `: html`- <div class="panel-content">- ${content}- </div>- `}+ ${content}</div>`;}- protected _getPanelContent(panelName: string, attributes: AssetAttribute[], config: PanelConfig): TemplateResult | undefined {- if (config.hide || attributes.length === 0) {+ protected _getPanelContent(attributes: AssetAttribute[], panelName: string, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig): TemplateResult | undefined {+ if (panelConfig.hide || attributes.length === 0) {return;}- let styles = config ? config.fieldStyles : undefined;+ if (this.config && this.config.panelViewProvider) {+ const template = this.config.panelViewProvider(attributes, panelName, viewerConfig, panelConfig);+ if (template) {+ return template;+ }+ }- // Special handling for info panel which only shows properties- if (panelName === "info") {- let properties = this._getInfoProperties(config);+ let styles = panelConfig ? panelConfig.fieldStyles : undefined;++ const includedAttributes = panelConfig && panelConfig.include ? panelConfig.include : undefined;+ const excludedAttributes = panelConfig && panelConfig.exclude ? panelConfig.exclude : [];+ const attrs = attributes.filter((attr) =>+ (!includedAttributes || includedAttributes.indexOf(attr.name!) >= 0)+ && (!excludedAttributes || excludedAttributes.indexOf(attr.name!) < 0));++ let innerContent: TemplateResult | undefined;++ if (panelConfig && panelConfig.type === "property") {+ // Special handling for info panel which only shows properties+ let properties = this._getInfoProperties(panelConfig);if (properties.length === 0) {return;}- return html`+ innerContent = html`${properties.map((prop) => {let style = styles ? styles[prop!] : undefined;- return prop === "attributes" ? `` : this._getField(prop, true, style, this._getPropertyTemplate(prop, (this.asset! as {[index: string]:any})[prop]));+ return prop === "attributes" ? `` : this._getField(prop, true, style, this._getPropertyTemplate(prop, (this.asset! as {[index: string]:any})[prop], viewerConfig, panelConfig));})}`;+ } else if (panelConfig && panelConfig.type === "history") {+ // Special handling for history panel which shows an attribute selector and a graph/data table of historical values+ const historyAttrs = attrs.filter((attr) => getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!));+ if (historyAttrs.length > 0) {+ innerContent = html`+ <style>+ #history-container {+ height: 100%;+ width: 100%;+ display: flex;+ flex-direction: column;+ }++ #history-controls {+ margin-bottom: 10px;+ }++ #history-attribute-picker {+ flex: 0;+ }++ or-attribute-history {+ height: 100%;+ }+ </style>+ <div id="history-container">+ <div id="history-controls">+ <or-input id="history-attribute-picker" @or-input-changed="${(evt: OrInputChangedEvent) => this._historyAttributeChanged(evt.detail.value)}" .type="${InputType.SELECT}" .options="${historyAttrs.map((attr) => [attr.name, getAttributeLabel(attr)])}"></or-input>+ </div>+ <or-attribute-history id="attribute-history" .config="${this.config ? this.config.historyConfig : undefined}" .assetType="${this.asset!.type}"></or-attribute-history>+ </div>+ `;+ }+ } else if (panelConfig && panelConfig.type === "location") {+ const attribute = attrs.find((attr) => attr.name === AttributeType.LOCATION.attributeName);+ if (attribute) {+ // Special handling for location panel which shows an attribute selector and a map showing the location of the attribute+ const mapType = this.config && this.config.mapType ? this.config.mapType : OrAssetViewer.DEFAULT_MAP_TYPE;+ const lngLat = getLngLat(attribute);+ const center = lngLat ? lngLat.toArray() : undefined;+ const showOnMapMeta = getFirstMetaItem(attribute, MetaItemType.SHOW_ON_DASHBOARD.urn!);++ return html`+ <style>+ #location-container {+ height: 100%;+ width: 100%;+ display: flex;+ flex-direction: column;+ }+ #location-container > or-map {+ flex: 1;+ border: #dbdbdb 1px solid;+ }+ #location-map-input {+ flex: 0 0 auto;+ padding: 20px 0 0 0;+ }+ </style>+ <div id="location-container">+ <or-map id="location-map" class="or-map" .center="${center}" type="${mapType}">+ <or-map-marker-asset active .asset="${this.asset}"></or-map-marker-asset>+ </or-map>+ ${attribute.name === AttributeType.LOCATION.attributeName ? html`+ <or-input id="location-map-input" type="${InputType.SWITCH}" readonly dense .value="${showOnMapMeta ? showOnMapMeta.value : undefined}" label="${i18next.t("showOnMap")}"></or-input>+ ` : ``}+ </div>+ `;+ }+ } else {+ innerContent = 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, this._getAttributeTemplate(attr, viewerConfig, panelConfig));+ })}+ `;}- // Special handling for history panel- if (panelName === "history") {- return html``;+ if (!innerContent) {+ return;}- const includedAttributes = config && config.include ? config.include : undefined;- const excludedAttributes = config && config.exclude ? config.exclude : [];- const attrs = attributes.filter((attr) =>- (!includedAttributes || includedAttributes.indexOf(attr.name!) >= 0)- && (!excludedAttributes || excludedAttributes.indexOf(attr.name!) < 0));-return 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, this._getAttributeTemplate(panelName, attr));- })}+ <div class="panel-title">+ <or-translate value="${name}"></or-translate>+ </div>+ ${!panelConfig || panelConfig.scrollable === undefined || panelConfig.scrollable ? html`+ <or-panel class="panel-content-wrapper">+ <div class="panel-content">+ ${innerContent}+ </div>+ </or-panel>+ `: html`+ <div class="panel-content-wrapper">+ <div class="panel-content">+ ${innerContent}+ </div>+ </div>+ `}`;}- protected _getPropertyTemplate(property: string, value: any) {+ protected _historyAttributeChanged(attributeName: string | undefined) {+ if (this._historyAttributePicker && this._attributeHistory) {++ let attribute: AssetAttribute | undefined;++ if (attributeName) {+ attribute = getAssetAttribute(this.asset!, attributeName);+ }++ this._attributeHistory.attribute = attribute;+ }+ }++ protected _getPropertyTemplate(property: string, value: any, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) {let type = InputType.TEXT;let minLength: number | undefined;let maxLength: number | undefined;if (this.config && this.config.propertyViewProvider) {- const result = this.config.propertyViewProvider(property, value);+ const result = this.config.propertyViewProvider(property, value, viewerConfig, panelConfig);if (result) {return result;}@@ -254,47 +425,16 @@ export class OrAssetViewer extends subscribe(openremote)(translate(i18next)(LitEreturn html`<or-input id="property-${property}" type="${type}" .minLength="${minLength}" .maxLength="${maxLength}" dense .value="${value}" readonly label="${i18next.t(property)}"></or-input>`;}- protected _getAttributeTemplate(panel: string, attribute: AssetAttribute) {+ protected _getAttributeTemplate(attribute: AssetAttribute, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) {if (this.config && this.config.attributeViewProvider) {- const result = this.config.attributeViewProvider(attribute);+ const result = this.config.attributeViewProvider(attribute, viewerConfig, panelConfig);if (result) {return result;}}- // Special control for main asset location attribute when shown in the location panel- if (panel === "location" && attribute.name === AttributeType.LOCATION.attributeName) {-- const mapType = this.config && this.config.mapType ? this.config.mapType : MapType.VECTOR;- const lngLat = getLngLat(attribute);- const center = lngLat ? lngLat.toArray() : undefined;- const showOnMapMeta = getFirstMetaItem(attribute, MetaItemType.SHOW_ON_DASHBOARD.urn!);-- return html`- <style>- #location-map-container {- height: 100%;- width: 100%;- display: flex;- flex-direction: column;- }- #location-map-container > or-map {- flex: 1;- border: #dbdbdb 1px solid;- }- #location-map-input {- flex: 0 0 auto;- padding: 20px 0 0 0;- }- </style>- <div id="location-map-container">- <or-map id="location-map" class="or-map" .center="${center}" type="${mapType}">- <or-map-marker-asset active .asset="${this.asset}"></or-map-marker-asset>- </or-map>- <or-input id="location-map-input" type="${InputType.SWITCH}" readonly dense .value="${showOnMapMeta ? showOnMapMeta.value : undefined}" label="${i18next.t("showOnMap")}"></or-input>- </div>- `;- }+ // Default panel type+ const panelType = panelConfig ? panelConfig.type : OrAssetViewer.DEFAULT_PANEL_TYPE;return html`<or-attribute-input dense .assetType="${this.asset!.type}" .attribute="${attribute}" .label="${i18next.t(attribute.name!)}"></or-attribute-input>@@ -313,20 +453,7 @@ export class OrAssetViewer extends subscribe(openremote)(translate(i18next)(LitE`;}- protected updated(_changedProperties: PropertyValues) {- super.updated(_changedProperties);-- if (_changedProperties.has("assetId")) {- this.asset = undefined;- if (this.assetId) {- this._loading = true;- super.assetIds = [this.assetId];- } else {- super.assetIds = undefined;- }- }- }-+ // TODO: Add debounce in here to minimise render callspublic onAttributeEvent(event: AttributeEvent) {const attrName = event.attributeState!.attributeRef!.attributeName!;@@ -348,12 +475,33 @@ export class OrAssetViewer extends subscribe(openremote)(translate(i18next)(LitEthis._loading = false;}- protected _getPanelConfig(asset: Asset) {- let config = this.config && this.config.default ? Object.assign({...OrAssetViewer.DEFAULT_CONFIG}, this.config.default) : {...OrAssetViewer.DEFAULT_CONFIG};-+ protected _getPanelConfig(asset: Asset): AssetViewerConfig {+ let config = {...OrAssetViewer.DEFAULT_CONFIG};if (this.config) {+ if (!config.viewerStyles) {+ config.viewerStyles = {};+ }+ if (!config.panels) {+ config.panels = {};+ }if (this.config.assetTypes && this.config.assetTypes.hasOwnProperty(asset.type!)) {- config = Object.assign(config, this.config.assetTypes[asset.type!]);+ const assetConfig = this.config.assetTypes[asset.type!];+ if (assetConfig.viewerStyles) {+ Object.assign(config.viewerStyles, assetConfig.viewerStyles);+ }+ if (assetConfig.panels) {+ Object.entries(assetConfig.panels).forEach(([name, assetPanelConfig]) => {+ if (config.panels.hasOwnProperty(name)) {+ const panelStyles = {...config.panels[name].panelStyles};+ const fieldStyles = {...config.panels[name].fieldStyles};+ Object.assign(config.panels[name], {...assetPanelConfig});+ config.panels[name].panelStyles = Object.assign(panelStyles, assetPanelConfig.panelStyles);+ config.panels[name].fieldStyles = Object.assign(fieldStyles, assetPanelConfig.fieldStyles);+ } else {+ config.panels[name] = {...assetPanelConfig};+ }+ });+ }}}@@ -361,10 +509,6 @@ export class OrAssetViewer extends subscribe(openremote)(translate(i18next)(LitE}protected async _getAssetNames(ids: string[]): Promise<string[]> {- if (this.config && this.config.assetNameProvider) {- return ids.map((id) => this.config!.assetNameProvider!(id));- }-const response = await rest.api.AssetResource.queryAssets({select: {excludePath: true,diff --git a/ui/component/or-asset-viewer/src/style.ts b/ui/component/or-asset-viewer/src/style.tsindex 727dc74a7..31486f448 100644--- a/ui/component/or-asset-viewer/src/style.ts+++ b/ui/component/or-asset-viewer/src/style.ts@@ -8,43 +8,18 @@ export const style = css`:host {--internal-or-asset-viewer-background-color: var(--or-asset-viewer-background-color, var(--or-app-color2, ${unsafeCSS(DefaultColor2)}));- --internal-or-asset-viewer-grid-template-columns: var(--or-asset-viewer-grid-template-columns, repeat(12, 1fr));- --internal-or-asset-viewer-grid-template-rows: var(--or-asset-viewer-grid-template-rows, repeat(auto-fill, 1fr));- --internal-or-asset-viewer-grid-template-auto-rows: var(--or-asset-viewer-grid-template-auto-rows, minmax(min-content, 1fr));- --internal-or-asset-viewer-panel-margin: var(--or-asset-viewer-panel-margin, 15px);+ --internal-or-asset-viewer-panel-margin: var(--or-asset-viewer-panel-margin, 30px);--internal-or-asset-viewer-panel-padding: var(--or-asset-viewer-panel-padding, 24px);- --internal-or-asset-viewer-text-color: var(--or-asset-viewer-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));+ --internal-or-asset-viewer-text-color: var(--or-asset-viewer-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));--internal-or-asset-viewer-title-text-color: var(--or-asset-viewer-title-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));--internal-or-asset-viewer-panel-color: var(--or-asset-viewer-panel-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));--internal-or-asset-viewer-line-color: var(--or-asset-viewer-line-color, var(--or-app-color5, ${unsafeCSS(DefaultColor5)}));- --internal-or-asset-viewer-info-columm-start: var(--or-asset-viewer-info-columm-start, 1);- --internal-or-asset-viewer-info-columm-end: var(--or-asset-viewer-info-columm-end, 7);- --internal-or-asset-viewer-info-row-start: var(--or-asset-viewer-info-row-start, 1);- --internal-or-asset-viewer-info-row-end: var(--or-asset-viewer-info-row-end, 2);- --internal-or-asset-viewer-info-height: var(--or-asset-viewer-info-height, unset);- --internal-or-asset-viewer-info-min-height: var(--or-asset-viewer-info-min-height, unset);- --internal-or-asset-viewer-location-columm-start: var(--or-asset-viewer-location-columm-start, 7);- --internal-or-asset-viewer-location-columm-end: var(--or-asset-viewer-location-columm-end, 13);- --internal-or-asset-viewer-location-row-start: var(--or-asset-viewer-location-row-start, 1);- --internal-or-asset-viewer-location-row-end: var(--or-asset-viewer-location-row-end, 3);- --internal-or-asset-viewer-location-height: var(--or-asset-viewer-location-height, unset);- --internal-or-asset-viewer-location-min-height: var(--or-asset-viewer-location-min-height, unset);- --internal-or-asset-viewer-attributes-columm-start: var(--or-asset-viewer-attributes-columm-start, 1);- --internal-or-asset-viewer-attributes-columm-end: var(--or-asset-viewer-attributes-columm-end, 7);- --internal-or-asset-viewer-attributes-row-start: var(--or-asset-viewer-attributes-row-start, 2);- --internal-or-asset-viewer-attributes-row-end: var(--or-asset-viewer-attributes-row-end, 4);- --internal-or-asset-viewer-attributes-height: var(--or-asset-viewer-attributes-height, unset);- --internal-or-asset-viewer-attributes-min-height: var(--or-asset-viewer-attributes-min-height, unset);- --internal-or-asset-viewer-history-columm-start: var(--or-asset-viewer-history-columm-start, 7);- --internal-or-asset-viewer-history-columm-end: var(--or-asset-viewer-history-columm-end, 13);- --internal-or-asset-viewer-history-row-start: var(--or-asset-viewer-history-row-start, 3);- --internal-or-asset-viewer-history-row-end: var(--or-asset-viewer-history-row-end, 4);- --internal-or-asset-viewer-history-height: var(--or-asset-viewer-history-height, unset);- --internal-or-asset-viewer-history-min-height: var(--or-asset-viewer-history-min-height, unset);height: 100%;width: 100%;+ box-sizing: border-box;background-color: var(--internal-or-asset-viewer-background-color);+ padding: var(--internal-or-asset-viewer-panel-margin);}*[hidden] {@@ -53,12 +28,12 @@ export const style = css`#container {box-sizing: border-box;- padding: var(--internal-or-asset-viewer-panel-margin);height: 100%;display: grid;grid-template-columns: var(--internal-or-asset-viewer-grid-template-columns);grid-template-rows: var(--internal-or-asset-viewer-grid-template-rows);- grid-auto-rows: var(--internal-or-asset-viewer-grid-template-auto-rows);+ column-gap: var(--internal-or-asset-viewer-panel-margin);+ row-gap: var(--internal-or-asset-viewer-panel-margin);-webkit-animation: fadein 0.3s; /* Safari, Chrome and Opera > 12.1 */-moz-animation: fadein 0.3s; /* Firefox < 16 */-ms-animation: fadein 0.3s; /* Internet Explorer */@@ -98,15 +73,15 @@ export const style = css`.panel {display: flex;flex-direction: column;- background-color: var(--internal-or-asset-viewer-panel-color);+ background-color: var(--internal-or-asset-viewer-panel-color);+ margin: 0;padding: var(--internal-or-asset-viewer-panel-padding);- margin: var(--internal-or-asset-viewer-panel-margin);box-shadow: ${unsafeCSS(DefaultBoxShadow)};}.panel-content-wrapper {+ flex: 1;height: 100%;- min-height: 0;}.panel-content {@@ -134,282 +109,6 @@ export const style = css`width: 100%;box-sizing: border-box;}-- #info-panel {- grid-column-start: var(--internal-or-asset-viewer-info-columm-start);- grid-column-end: var(--internal-or-asset-viewer-info-columm-end);- grid-row-start: var(--internal-or-asset-viewer-info-row-start);- grid-row-end: var(--internal-or-asset-viewer-info-row-end);- height: var(--internal-or-asset-viewer-info-height);- min-height: var(--internal-or-asset-viewer-info-min-height);- }-- #location-panel {- grid-column-start: var(--internal-or-asset-viewer-location-columm-start);- grid-column-end: var(--internal-or-asset-viewer-location-columm-end);- grid-row-start: var(--internal-or-asset-viewer-location-row-start);- grid-row-end: var(--internal-or-asset-viewer-location-row-end);- height: var(--internal-or-asset-viewer-location-height);- min-height: var(--internal-or-asset-viewer-location-min-height);- }-- #attributes-panel {- grid-column-start: var(--internal-or-asset-viewer-attributes-columm-start);- grid-column-end: var(--internal-or-asset-viewer-attributes-columm-end);- grid-row-start: var(--internal-or-asset-viewer-attributes-row-start);- grid-row-end: var(--internal-or-asset-viewer-attributes-row-end);- height: var(--internal-or-asset-viewer-attributes-height);- min-height: var(--internal-or-asset-viewer-attributes-min-height);- }-- #history-panel {- grid-column-start: var(--internal-or-asset-viewer-history-columm-start);- grid-column-end: var(--internal-or-asset-viewer-history-columm-end);- grid-row-start: var(--internal-or-asset-viewer-history-row-start);- grid-row-end: var(--internal-or-asset-viewer-history-row-end);- height: var(--internal-or-asset-viewer-history-height);- min-height: var(--internal-or-asset-viewer-history-min-height);- }----- button {- background-color: var(--internal-or-asset-tree-button-color);- color: var(--internal-or-asset-tree-background-color);- --or-icon-width: 26px;- --or-icon-height: 26px;- --or-icon-fill: var(--internal-or-asset-tree-background-color);- margin: 0 8px;- border: none;- padding: 0;- display: inline-block;- cursor: pointer;- }-- button:focus {- outline: 0;- }-- #header {- background-color: var(--internal-or-asset-tree-header-color);- display: flex;- width: 100%;- height: var(--internal-or-asset-tree-header-height);- border-bottom: 1px solid ${unsafeCSS(DefaultColor5)};- -webkit-box-shadow: ${unsafeCSS(DefaultBoxShadowBottom)};- -moz-box-shadow: ${unsafeCSS(DefaultBoxShadowBottom)};- box-shadow: ${unsafeCSS(DefaultBoxShadowBottom)};- z-index: 1000;- }-- #header > * {- line-height: var(--internal-or-asset-tree-header-height);- }-- #title-container {- flex: 1 0 auto;- flex-direction: row;- text-transform: capitalize;- padding-left: 30px;-- --or-select-text-color: var(--internal-or-asset-tree-header-text-color);- --or-select-option-text-color: var(--internal-or-asset-tree-header-menu-text-color);- --or-select-option-background-color: var(--internal-or-asset-tree-header-menu-background-color);- --or-select-background-color: none;- --or-select-border-color: none;- --or-select-padding: 5px 20px 5px 5px;- }-- #title {- font-weight: bold;- font-size: 20px;- color: var(--internal-or-asset-tree-header-text-color);- }-- #realm-picker {- outline: none;- margin-left: 5px;- text-transform: none;- font-size: 14px;- }-- #header-btns {- display: flex;- flex-direction: row;- padding-right: 10px;- }-- .modal-container {- position: relative;- line-height: normal;- }-- .modal {- position: absolute;- height: 0;- overflow: hidden;- }-- .modal[data-visible] {- transition: all 0.5s ease-in;- height: auto;- overflow: visible;- }-- .modal-content {- border: 1px solid var(--internal-or-asset-tree-line-color);- box-shadow: ${unsafeCSS(DefaultBoxShadow)};- -moz-box-shadow: ${unsafeCSS(DefaultBoxShadow)};- -webkit-box-shadow: ${unsafeCSS(DefaultBoxShadow)};- color: var(--internal-or-asset-tree-header-menu-text-color);- background-color: var(--internal-or-asset-tree-header-menu-background-color);- padding: 20px 25px 10px 25px;- }-- .modal-content > ul {- list-style-type: none;- padding: 0;- margin-bottom: 0;- white-space: nowrap;- }-- .modal-content > ul > li {- font-weight: bolder;- line-height: 40px;- cursor: pointer;- }-- .modal-content > ul > li > or-icon {- visibility: hidden;- width: 18px;- height: 18px;- margin-right: 10px;- --or-icon-fill: var(--internal-or-asset-tree-header-color);- --or-icon-stroke: var(--internal-or-asset-tree-header-color);- --or-icon-stroke-width: 2px;- }-- .modal-content > ul > li[data-selected] > or-icon {- visibility: visible;- }-- .modal-content > h2 {- opacity: 0.6;- font-size: 0.9em;- margin: 0;- }-- .modal-btns {- text-align: right;- }-- .modal-btns .btn {- font-weight: bolder;- cursor: pointer;- text-transform: uppercase;- }-- .modal-btns .btn + .btn {- margin-left: 15px;- }-- #sort-menu {- left: -173px;- top: var(--internal-or-asset-tree-header-height);- }-- #delete-not-allowed-modal {- left: -400px;- top: var(--internal-or-asset-tree-header-height);- }-- #delete-confirm-modal {- left: -300px;- top: var(--internal-or-asset-tree-header-height);- }-- #list-container {- flex: 1 0 auto;- overflow: auto;- }-- #list {- margin: 0;- color: var(--internal-or-asset-tree-text-color);- padding: 15px 0;- font-weight: bolder;- }-- #list, ol {- list-style-type: none;- }-- li ol {- padding: 0;- }-- #list li:not([data-expanded]) > ol {- display: none;- }-- #list li[data-selected] > .node-container, #list li > .node-container:hover {- background-color: var(--internal-or-asset-tree-selected-background-color);- }-- #list li[data-selected] > .node-container {- border-left-color: var(--internal-or-asset-tree-selected-color);- }-- .node-container {- display: flex;- flex-direction: row;- border-left: 6px solid transparent;- user-select: none;- cursor: pointer;- height: var(--internal-or-asset-tree-item-height);- line-height: var(--internal-or-asset-tree-item-height);- padding-top: var(--internal-or-asset-tree-item-padding);- padding-bottom: var(--internal-or-asset-tree-item-padding);- }-- .node-container > * {- flex: 0 0 auto;- }-- .expander {- width: 26px;- height: 100%;- display: inline-block;- background-repeat: no-repeat;- background-size: 100%;- background-position: center;- }-- .expander[data-expandable] {- background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='${unsafeCSS(mdi.icons["chevron-right"])}'/%3E%3C/svg%3E");- }-- li[data-expanded] > .node-container .expander {- background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='${unsafeCSS(mdi.icons["chevron-down"])}'/%3E%3C/svg%3E") !important;- }-- .node-name {- margin: -4px 0;- flex: 1 0 auto;- display: flex;- align-items: center;- }-- .node-name > span {- vertical-align: middle;- }-- .node-name > or-icon {- --or-icon-width: var(--internal-or-asset-tree-item-height);- --or-icon-height: var(--internal-or-asset-tree-item-height);- margin-right: 10px;- }#loading, #noneselected {display: flex;diff --git a/ui/component/or-asset-viewer/tsconfig.json b/ui/component/or-asset-viewer/tsconfig.jsonindex 227b51dc4..e685ed805 100644--- a/ui/component/or-asset-viewer/tsconfig.json+++ b/ui/component/or-asset-viewer/tsconfig.json@@ -13,10 +13,11 @@{ "path": "../core" },{ "path": "../rest" },{ "path": "../or-select" },+ { "path": "../or-panel" },{ "path": "../or-translate" },{ "path": "../or-icon" },{ "path": "../or-map" },- { "path": "../or-input" },- { "path": "../or-attribute-input" }+ { "path": "../or-attribute-input" },+ { "path": "../or-attribute-history" }]}\ No newline at end of filediff --git a/ui/component/or-attribute-history/.npmignore b/ui/component/or-attribute-history/.npmignorenew file mode 100644index 000000000..ca658009d--- /dev/null+++ b/ui/component/or-attribute-history/.npmignore@@ -0,0 +1,3 @@+build/+build.gradle+test/\ No newline at end of filediff --git a/ui/component/or-attribute-history/README.md b/ui/component/or-attribute-history/README.mdnew file mode 100644index 000000000..e383fd8fe--- /dev/null+++ b/ui/component/or-attribute-history/README.md@@ -0,0 +1,31 @@+# @openremote/or-attribute-history \<or-attribute-history\>+[![NPM Version][npm-image]][npm-url]+[![Linux Build][travis-image]][travis-url]+[![Test Coverage][coveralls-image]][coveralls-url]++Web Component for displaying historical values of an attribute.++## Install+```bash+npm i @openremote/or-attribute-history+yarn add @openremote/or-attribute-history+```++## Usage+For a full list of properties, methods and options refer to the TypeDoc generated [documentation]().+++## Supported Browsers+The last 2 versions of all modern browsers are supported, including Chrome, Safari, Opera, Firefox, Edge. In addition,+Internet Explorer 11 is also supported.+++## License+[GNU AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html)++[npm-image]: https://img.shields.io/npm/v/live-xxx.svg+[npm-url]: https://npmjs.org/package/@openremote/or-input+[travis-image]: https://img.shields.io/travis/live-js/live-xxx/master.svg+[travis-url]: https://travis-ci.org/live-js/live-xxx+[coveralls-image]: https://img.shields.io/coveralls/live-js/live-xxx/master.svg+[coveralls-url]: https://coveralls.io/r/live-js/live-xxx?branch=masterdiff --git a/ui/component/or-attribute-history/build.gradle b/ui/component/or-attribute-history/build.gradlenew file mode 100644index 000000000..c08de8a80--- /dev/null+++ b/ui/component/or-attribute-history/build.gradle@@ -0,0 +1,11 @@+buildDir = "dist"++task clean() {+ doLast {+ delete "dist"+ }+}++task build() {+ dependsOn npmBuild+}\ No newline at end of filediff --git a/ui/component/or-attribute-history/package.json b/ui/component/or-attribute-history/package.jsonnew file mode 100644index 000000000..0086f90db--- /dev/null+++ b/ui/component/or-attribute-history/package.json@@ -0,0 +1,27 @@+{+ "name": "@openremote/or-attribute-history",+ "version": "1.0.0",+ "description": "OpenRemote attribute history",+ "main": "dist/index.js",+ "types": "src/index.ts",+ "scripts": {+ "build": "npx tsc",+ "test": "echo \"No tests\" && exit 0"+ },+ "author": "OpenRemote",+ "license": "AGPL-3.0-or-later",+ "dependencies": {+ "@material/data-table": "^3.2.0",+ "@openremote/core": "^1.0.0",+ "@openremote/or-translate": "^1.0.0",+ "@types/chart.js": "^2.8.5",+ "chart.js": "^2.8.0",+ "jsonpath-plus": "^1.1.0",+ "lit-element": "^2.2.1",+ "moment": "^2.24.0"+ },+ "devDependencies": {+ "tslint": "^5.11.0",+ "typescript": "^3.4.5"+ }+}diff --git a/ui/component/or-attribute-history/src/index.ts b/ui/component/or-attribute-history/src/index.tsnew file mode 100644index 000000000..d8e459a4c--- /dev/null+++ b/ui/component/or-attribute-history/src/index.ts@@ -0,0 +1,592 @@+import {+ css,+ customElement,+ html,+ LitElement,+ property,+ PropertyValues,+ query,+ TemplateResult,+ unsafeCSS+} from "lit-element";+import i18next from "i18next";+import {translate} from "@openremote/or-translate/dist/translate-mixin";+import {AssetAttribute, AttributeRef, DatapointInterval, ValueDatapoint, ValueType} from "@openremote/model";+import {AssetModelUtil, DefaultColor2, DefaultColor3, DefaultColor4, DefaultColor5} from "@openremote/core";+import rest from "@openremote/rest";+import "@openremote/or-input";+import "@openremote/or-panel";+import "@openremote/or-translate";+import {getAssetAttribute} from "@openremote/core/dist/util";+import Chart, {ChartTooltipCallback} from "chart.js";+import {InputType} from "@openremote/or-input";+import {MDCDataTable} from "@material/data-table";+import {JSONPath} from "jsonpath-plus";+import moment from "moment";+import {styleMap} from "lit-html/directives/style-map";++export type TableColumnType = "timestamp" | "prop";++export interface TableColumnConfig {+ type?: TableColumnType;+ header?: string;+ numeric?: boolean;+ path?: string;+ stringify?: boolean;+ styles?: { [style: string]: string };+ contentProvider?: (datapoint: ValueDatapoint<any>, value: any, config: TableColumnConfig) => TemplateResult | any | undefined;+}++export interface AssetTableConfig {+ timestampFormat?: string;+ /* Supports extracting columns automatically from the keys of object data, for strings */+ autoColumns?: boolean;+ columns?: TableColumnConfig[];+ styles?: { [style: string]: string };+}++export interface TableConfig {+ default?: AssetTableConfig;+ assetTypes?: {+ [assetType: string]: {+ attributeNames?: {[attributeName: string]: AssetTableConfig};+ attributeValueTypes?: {[attributeValueType: string]: AssetTableConfig};+ };+ },+ attributeNames?: {[attributeName: string]: AssetTableConfig};+ attributeValueTypes?: {[attributeValueType: string]: AssetTableConfig};+}++export interface HistoryConfig {+ table: TableConfig;+}++// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling+const tableStyle = require("!!raw-loader!@material/data-table/dist/mdc.data-table.css");++// language=CSS+const style = css`+ :host {+ --internal-or-attribute-history-background-color: var(--or-attribute-history-background-color, var(--or-app-color2, ${unsafeCSS(DefaultColor2)}));+ --internal-or-attribute-history-text-color: var(--or-attribute-history-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));+ --internal-or-attribute-history-graph-fill-color: var(--or-attribute-history-graph-fill-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));+ --internal-or-attribute-history-graph-fill-opacity: var(--or-attribute-history-graph-fill-opacity, 1);+ --internal-or-attribute-history-graph-line-color: var(--or-attribute-history-graph-line-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));+ --internal-or-attribute-history-graph-point-color: var(--or-attribute-history-graph-point-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));+ --internal-or-attribute-history-graph-point-border-color: var(--or-attribute-history-graph-point-border-color, var(--or-app-color5, ${unsafeCSS(DefaultColor5)}));+ --internal-or-attribute-history-graph-point-radius: var(--or-attribute-history-graph-point-radius, 4);+ --internal-or-attribute-history-graph-point-hit-radius: var(--or-attribute-history-graph-point-hit-radius, 20);+ --internal-or-attribute-history-graph-point-border-width: var(--or-attribute-history-graph-point-border-width, 2);+ --internal-or-attribute-history-graph-point-hover-color: var(--or-attribute-history-graph-point-hover-color, var(--or-app-color5, ${unsafeCSS(DefaultColor5)}));+ --internal-or-attribute-history-graph-point-hover-border-color: var(--or-attribute-history-graph-point-hover-border-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));+ --internal-or-attribute-history-graph-point-hover-radius: var(--or-attribute-history-graph-point-hover-radius, 4);+ --internal-or-attribute-history-graph-point-hover-border-width: var(--or-attribute-history-graph-point-hover-border-width, 2);++ display: block;+ }++ :host[hidden] {+ display: none;+ }++ #container {+ display: flex;+ width: 100%;+ height: 100%;+ }++ #container > * {+ width: 100%;+ }++ #msg {+ height: 100%;+ width: 100%;+ }++ #history-wrapper:not([hidden]) {+ height: 100%;+ display: flex;+ flex-direction: column;+ }++ #history-wrapper > * {+ width: 100%;+ }++ #chart-controls {+ flex: 0;+ display: none;+ justify-content: space-between;+ margin-bottom: 10px;+ }++ #chart-container {+ position: relative;+ height: 100%;+ }++ #table-container {+ height: 100%;+ }++ #table {+ width: 100%;+ margin-bottom: 10px;+ }++ #table > table {+ width: 100%;+ table-layout: fixed;+ }++ #table th, #table td {+ overflow: hidden;+ white-space: nowrap;+ text-overflow: ellipsis;+ }+`;++@customElement("or-attribute-history")+export class OrAttributeHistory extends translate(i18next)(LitElement) {++ public static DEFAULT_TIMESTAMP_FORMAT = "L HH:mm:ss";++ static get styles() {+ return [+ css`${unsafeCSS(tableStyle)}`,+ style+ ];+ }++ @property({type: String})+ public assetType?: string;++ @property({type: Object})+ public attribute?: AssetAttribute;++ @property({type: Object})+ public attributeRef?: AttributeRef;++ @property({type: String})+ public xLabel?: string;++ @property({type: String})+ public yLabel?: string;++ @property({type: Number})+ public from?: number;++ @property({type: Number})+ public to?: number;++ @property({type: String})+ public interval: DatapointInterval = DatapointInterval.WEEK;++ @property({type: Number})+ public timestamp?: Date;++ @property({type: Object})+ public config?: HistoryConfig;++ @property()+ protected _loading: boolean = false;++ @property()+ protected _data?: ValueDatapoint<any>[];++ @property()+ protected _tableTemplate?: TemplateResult;++ @query("#chart")+ protected _chartElem!: HTMLCanvasElement;+ @query("#table")+ protected _tableElem!: HTMLDivElement;+ protected _table?: MDCDataTable;+ protected _chart?: Chart;+ protected _type?: ValueType;+ protected _style!: CSSStyleDeclaration;++ shouldUpdate(_changedProperties: PropertyValues): boolean {++ let reloadData = _changedProperties.has("interval");++ if (_changedProperties.has("attributeRef") || _changedProperties.has("attribute")) {+ this._type = undefined;+ reloadData = true;+ }++ if (reloadData) {+ this._data = undefined;+ if (this.attribute || this.attributeRef) {+ this._loadData();+ }+ }++ return super.shouldUpdate(_changedProperties);+ }++ connectedCallback() {+ super.connectedCallback();+ this._style = window.getComputedStyle(this);+ }++ disconnectedCallback(): void {+ super.disconnectedCallback();+ this._cleanup();+ }++ render() {++ const hasData = this._data && this._data.length > 0;+ const isChart = this._type === ValueType.NUMBER || this._type === ValueType.BOOLEAN;++ return html`+ <div id="container">+ <div id="msg" ?hidden="${!this._loading && hasData}"><or-translate value="${this._loading ? "loading" : "noData"}"></or-translate></div>+ <div id="history-wrapper" ?hidden="${this._loading || !hasData}">+ <div id="chart-controls">+ <or-input .type="${InputType.SELECT}" .options="${this._getIntervalOptions()}"></or-input>+ </div>+ <div ?hidden="${!isChart}" id="chart-container">+ <canvas id="chart"></canvas>+ </div>+ <or-panel ?hidden="${isChart}" id="table-container">+ ${this._tableTemplate || ``}+ </or-panel>+ </div>++ </div>+ `;+ }++ updated(changedProperties: PropertyValues) {+ super.updated(changedProperties);++ if (changedProperties.has("_data")) {+ if (!this._data) {+ this._cleanup();+ }++ if (this._data && this._data.length > 0) {++ const isChart = this._type === ValueType.NUMBER || this._type === ValueType.BOOLEAN;++ if (isChart) {+ if (!this._chart) {+ let bgColor = this._style.getPropertyValue("--internal-or-attribute-history-graph-fill-color").trim();+ const opacity = Number(this._style.getPropertyValue("--internal-or-attribute-history-graph-fill-opacity").trim());+ if (!isNaN(opacity)) {+ if (bgColor.startsWith("#") && (bgColor.length === 4 || bgColor.length === 7)) {+ bgColor += (bgColor.length === 4 ? Math.round(opacity * 255).toString(16).substr(0, 1) : Math.round(opacity * 255).toString(16));+ } else if (bgColor.startsWith("rgb(")) {+ bgColor = bgColor.substring(0, bgColor.length - 1) + opacity;+ }+ }++ this._chart = new Chart(this._chartElem, {+ type: "bar",+ data: {+ datasets: [+ {+ data: this._data,+ backgroundColor: bgColor,+ borderColor: this._style.getPropertyValue("--internal-or-attribute-history-graph-line-color"),+ pointBorderColor: this._style.getPropertyValue("--internal-or-attribute-history-graph-point-border-color"),+ pointBackgroundColor: this._style.getPropertyValue("--internal-or-attribute-history-graph-point-color"),+ pointRadius: Number(this._style.getPropertyValue("--internal-or-attribute-history-graph-point-radius")),+ pointBorderWidth: Number(this._style.getPropertyValue("--internal-or-attribute-history-graph-point-border-width")),+ pointHoverBackgroundColor: this._style.getPropertyValue("--internal-or-attribute-history-graph-point-hover-color"),+ pointHoverBorderColor: this._style.getPropertyValue("--internal-or-attribute-history-graph-point-hover-border-color"),+ pointHoverRadius: Number(this._style.getPropertyValue("--internal-or-attribute-history-graph-point-hover-radius")),+ pointHoverBorderWidth: Number(this._style.getPropertyValue("--internal-or-attribute-history-graph-point-hover-border-width")),+ pointHitRadius: Number(this._style.getPropertyValue("--internal-or-attribute-history-graph-point-hit-radius"))+ }+ ]+ },+ options: {+ maintainAspectRatio: false,+ responsive: true,+ legend: {+ display: false+ },+ tooltips: {+ displayColors: false,+ callbacks: {+ label: (tooltipItem, data) => {+ return tooltipItem.yLabel; // Removes the colon before the label+ },+ footer: () => {+ return " "; // Hack the broken vertical alignment of body with footerFontSize: 0+ }+ } as ChartTooltipCallback+ },+ scales: {+ yAxes: [{+ ticks: {+ beginAtZero: true+ },+ gridLines: {+ color: "#cccccc"+ }+ }],+ xAxes: [{+ type: "time",+ time: {+ displayFormats: {+ millisecond: 'HH:mm:ss.SSS',+ second: 'HH:mm:ss',+ minute: "HH:mm",+ hour: "HH:mm",+ week: "w"+ }+ },+ ticks: {+ autoSkip: true,+ maxTicksLimit: 30,+ fontColor: "#000",+ fontFamily: "'Open Sans', Helvetica, Arial, Lucida, sans-serif",+ fontSize: 9,+ fontStyle: "normal"+ },+ gridLines: {+ color: "#cccccc"+ }+ }]+ }+ }+ });+ } else {+ this._chart.data.datasets![0].data = this._data;+ this._chart.update();+ }+ } else {+ this._tableTemplate = this._getTableTemplate();+ }+ }+ }++ if (changedProperties.has("_tableTemplate") && this._tableElem) {+ // Don't think we need to instantiate+ //this._table = new MDCDataTable(this._tableElem);+ }+ }++ protected _cleanup() {+ if (this._chart) {+ this._chart.destroy();+ this._chart = undefined;+ }+ if (this._table) {+ this._table.destroy();+ this._table = undefined;+ }+ }++ protected _getTableTemplate(): TemplateResult {++ const assetType = this.assetType!;+ const attributeName = this.attribute ? this.attribute.name! : this.attributeRef!.attributeName!;+ const attributeType = this.attribute ? this.attribute.type as string : undefined;++ let config: AssetTableConfig = {+ autoColumns: true+ };++ if (this.config && this.config.table) {+ if (this.config.table.assetTypes+ && this.config.table.assetTypes[assetType]+ && ((this.config.table.assetTypes[assetType].attributeNames && this.config.table.assetTypes[assetType].attributeNames![attributeName])+ || (attributeType && this.config.table.assetTypes[assetType].attributeValueTypes && this.config.table.assetTypes[assetType].attributeValueTypes![attributeType]))) {+ config = this.config.table.assetTypes[assetType].attributeNames && this.config.table.assetTypes[assetType].attributeNames![attributeName] || this.config.table.assetTypes[assetType].attributeValueTypes![attributeType!];+ } else if (this.config.table.attributeNames && this.config.table.attributeNames[attributeName]) {+ config = this.config.table.attributeNames[attributeName];+ } else if (attributeType && this.config.table.attributeValueTypes && this.config.table.attributeValueTypes[attributeType]) {+ config = this.config.table.attributeValueTypes[attributeType];+ } else if (this.config.table.default) {+ config = this.config.table.default;+ }++ if (!config) {+ config = {+ autoColumns: true+ };+ }+ }++ if (config.autoColumns) {+ config = {...config};++ config.columns = [];++ const dp = this._data!.find((dp) => dp.y !== undefined || dp.y !== null);+ if (dp) {+ if (typeof(dp.y) === "object" && !Array.isArray(dp.y)) {+ config.columns = Object.entries(dp.y as {}).map(([prop, value]) => {+ return {+ type: "prop",+ header: prop,+ path: "$." + prop,+ stringify: typeof(value) === "object",+ numeric: !isNaN(Number(value))+ } as TableColumnConfig+ });+ } else {+ config.columns.push({+ type: "prop",+ stringify: true,+ numeric: typeof(dp.y) === "number"+ });+ }+ }++ if (config.columns.length > 0) {+ config.columns.push({+ header: "timestamp",+ type: "timestamp"+ })+ }+ }++ if (config.columns && config.columns.length > 0) {+ return html`+ <div id="table" class="mdc-data-table">+ <table style="${config.styles ? styleMap(config.styles) : ""}" class="mdc-data-table__table" aria-label="${attributeName + " history"}">+ <thead>+ <tr class="mdc-data-table__header-row">+ ${config.columns.map((c) => html`<th style="${c.styles ? styleMap(c.styles) : ""}" class="mdc-data-table__header-cell ${c.numeric ? "mdc-data-table__header-cell--numeric" : ""}" role="columnheader" scope="col"><or-translate value="${c.header}"></or-translate></th>`)}+ </tr>+ </thead>+ <tbody class="mdc-data-table__content">+ ${this._data!.map((dp) => {+ return html`+ <tr class="mdc-data-table__row">+ ${config.columns!.map((c) => html`<td style="${c.styles ? styleMap(c.styles) : ""}" class="mdc-data-table__cell ${c.numeric ? "mdc-data-table__cell--numeric" : ""}">${this._getCellValue(dp, c, config.timestampFormat)}</td>`)}+ </tr>+ `;+ })}+ </tbody>+ </table>+ </div>+ `;+ }++ console.warn("OrAttributeHistory: No columns configured so nothing to show");+ return html``;+ }++ protected _getCellValue(datapoint: ValueDatapoint<any>, config: TableColumnConfig, timestampFormat: string | undefined): TemplateResult | string | undefined {++ switch (config.type) {+ case "timestamp":+ const value = moment(datapoint.x).format(timestampFormat || OrAttributeHistory.DEFAULT_TIMESTAMP_FORMAT);+ if (config && config.contentProvider) {+ const template = config.contentProvider(datapoint, value, config);+ if (template) {+ return template;+ }+ }+ return value;+ case "prop":+ let data = datapoint.y;++ if (config.path) {+ data = JSONPath({+ path: config.path,+ json: datapoint.y,+ wrap: false+ });+ // TODO: Remove once JSONPath updated https://github.com/s3u/JSONPath/issues/86)+ if (Array.isArray(data) && data.length === 1) {+ data = data[0];+ }+ }++ if (config && config.contentProvider) {+ const template = config.contentProvider(datapoint, data, config);+ if (template) {+ return template;+ }+ }++ if (config.stringify) {+ return JSON.stringify(data);+ }++ return data;+ }+ }++ protected _getIntervalOptions(): [string, string][] {+ return [+ DatapointInterval.HOUR,+ DatapointInterval.DAY,+ DatapointInterval.WEEK,+ DatapointInterval.MONTH,+ DatapointInterval.YEAR+ ].map((interval) => {+ return [interval, i18next.t(interval)];+ });+ }++ protected async _loadData() {+ if (!this.assetType || (!this.attribute && !this.attributeRef)) {+ return;+ }++ this._loading = true;+ const assetId = this.attribute ? this.attribute.assetId! : this.attributeRef!.entityId!;+ const attributeName = this.attribute ? this.attribute.name! : this.attributeRef!.attributeName!;++ if (!this._type) {+ let attr = this.attribute;++ if (!attr) {+ const response = await rest.api.AssetResource.queryAssets({+ ids: [assetId],+ select: {+ excludeParentInfo: true,+ excludeRealm: true,+ excludePath: true,+ excludeAttributeMeta: true,+ attributes: [+ attributeName+ ]+ }+ });+ if (response.status === 200 && response.data.length > 0) {+ attr = getAssetAttribute(response.data[0], attributeName);+ }+ }++ if (attr) {+ const attributeType = attr.type as string;+ const attrDescriptor = AssetModelUtil.getAttributeValueDescriptorFromAsset(attributeType, this.assetType, attributeName);++ if (attrDescriptor && attrDescriptor.valueType) {+ this._type = attrDescriptor.valueType;+ }+ }+ }++ if (!this._type) {+ this._loading = false;+ return;+ }++ const response = await rest.api.AssetDatapointResource.getDatapoints(+ assetId,+ attributeName,+ {+ interval: this.interval,+ timestamp: this.timestamp ? this.timestamp.getTime() : new Date().valueOf()+ }+ );++ this._loading = false;++ if (response.status === 200) {+ this._data = response.data;+ }+ }+}diff --git a/ui/component/or-attribute-history/tsconfig.json b/ui/component/or-attribute-history/tsconfig.jsonnew file mode 100644index 000000000..5e97588c3--- /dev/null+++ b/ui/component/or-attribute-history/tsconfig.json@@ -0,0 +1,18 @@+{+ "extends": "../../tsconfig",+ "compilerOptions": {+ "outDir": "./dist",+ "tsBuildInfoFile": "./dist/.tsbuildinfo",+ "rootDir": "src"+ },+ "include": [+ "./src"+ ],+ "references": [+ { "path": "../core" },+ { "path": "../or-panel" },+ { "path": "../or-input" },+ { "path": "../or-translate" }++ ]+}\ No newline at end of filediff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.tsindex f0f53463a..c2f0bf466 100644--- a/ui/component/or-attribute-input/src/index.ts+++ b/ui/component/or-attribute-input/src/index.ts@@ -9,7 +9,8 @@ import {AttributeValueDescriptor,AttributeValueType,MetaItemType,- ValueType+ ValueType,+ Attribute} from "@openremote/model";import openremote, {AssetModelUtil} from "@openremote/core";import {subscribe} from "@openremote/core/dist/asset-mixin";@@ -17,6 +18,11 @@ import "@openremote/or-select";import "@openremote/or-input";import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-input";+export function getAttributeLabel(attribute: Attribute, fallback?: string): string {+ const labelMetaValue = AssetModelUtil.getMetaValue(MetaItemType.LABEL, attribute.meta);+ return i18next.t([attribute!.name!, fallback || labelMetaValue || attribute!.name!]);+}+// Allows consuming applications to provide custom UI for certain attributes; if the value is changed the custom control// must call the valueChangeNotifier.class AttributeInputProviders {@@ -184,7 +190,7 @@ export class OrAttributeInput extends subscribe(openremote)(translate(i18next)(L// TODO: Update to use 'effective' meta so not dependent on meta items being defined on the asset itselfthis._min = AssetModelUtil.getMetaValue(MetaItemType.RANGE_MIN, this.attribute.meta);this._max = AssetModelUtil.getMetaValue(MetaItemType.RANGE_MAX, this.attribute.meta);- this._label = AssetModelUtil.getMetaValue(MetaItemType.LABEL, this.attribute.meta);+ this._label = getAttributeLabel(this.attribute);this._readonly = AssetModelUtil.getMetaValue(MetaItemType.READ_ONLY, this.attribute.meta);this._allowedValues = AssetModelUtil.getMetaValue(MetaItemType.ALLOWED_VALUES, this.attribute.meta);@@ -267,7 +273,7 @@ export class OrAttributeInput extends subscribe(openremote)(translate(i18next)(Lvalue = this._valueOutboundConverter(this.attribute.value);}- return html`<or-input .type="${this._inputType}" .label="${i18next.t([this.attribute!.name!, this._label || this.attribute!.name!])}" .value="${value}" .allowedValues="${this._allowedValues}" .min="${this._min}" .max="${this._max}" .readonly="${this.readonly || this._readonly}" .disabled="${this.disabled}" .dense="${this.dense}" @or-input-changed="${(e: OrInputChangedEvent) => this.onValueChange(e.detail.value)}"></or-input>`;+ return html`<or-input .type="${this._inputType}" .label="${this._label}" .value="${value}" .allowedValues="${this._allowedValues}" .min="${this._min}" .max="${this._max}" .readonly="${this.readonly || this._readonly}" .disabled="${this.disabled}" .dense="${this.dense}" @or-input-changed="${(e: OrInputChangedEvent) => this.onValueChange(e.detail.value)}"></or-input>`;}return html`<span>INPUT TYPE NOT IMPLEMENTED</span>`;diff --git a/yarn.lock b/yarn.lockindex 416bc93b0..a2aa7b52a 100644--- a/yarn.lock+++ b/yarn.lock@@ -795,6 +795,24 @@"@material/theme" "^3.1.0"tslib "^1.9.3"+"@material/data-table@^3.2.0":+ version "3.2.0"+ resolved "https://registry.yarnpkg.com/@material/data-table/-/data-table-3.2.0.tgz#4751a83bc4f01252ba7aa908e78dd389f452ed83"+ integrity sha512-67Bjo4B3kiB2zPEhd1OyHGWCNyQtoFTLNmOAPDFAxbmfaBquvjzAEYos2/cJpvzP8yUCIMJlOYaP0uvv94n2og==+ dependencies:+ "@material/animation" "^3.1.0"+ "@material/base" "^3.1.0"+ "@material/checkbox" "^3.2.0"+ "@material/dom" "^3.1.0"+ "@material/elevation" "^3.1.0"+ "@material/feature-targeting" "^3.1.0"+ "@material/ripple" "^3.2.0"+ "@material/rtl" "^3.2.0"+ "@material/shape" "^3.1.0"+ "@material/theme" "^3.1.0"+ "@material/typography" "^3.1.0"+ tslib "^1.10.0"+"@material/dom@^1.1.0":version "1.1.0"resolved "https://registry.yarnpkg.com/@material/dom/-/dom-1.1.0.tgz#3bd3d1a3415b4181118fecb182d93beda56a6f8c"@@ -1243,6 +1261,11 @@dependencies:"@polymer/polymer" preview+"@types/chart.js@^2.8.5":+ version "2.8.5"+ resolved "https://registry.yarnpkg.com/@types/chart.js/-/chart.js-2.8.5.tgz#7d47cfd36f0a1c2c4ad6a585749bc68e8659492a"+ integrity sha512-CohUDPD3f5e/sGI8SUs1zaUnS38MMA+4WDDxBoudQIKVqNj4LJG2P+Z0WXB+vT4jkDpc7itXYoNIZq1f1MpulA==+"@types/events@*":version "3.0.0"resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"@@ -2031,7 +2054,7 @@ [email protected], chalk@^2.0.0, chalk@^2.3.0, chalk@^2.4.2:escape-string-regexp "^1.0.5"supports-color "^5.3.0"-chart.js@^2.7.0:+chart.js@^2.7.0, chart.js@^2.8.0:version "2.8.0"resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-2.8.0.tgz#b703b10d0f4ec5079eaefdcd6ca32dc8f826e0e9"integrity sha512-Di3wUL4BFvqI5FB5K26aQ+hvWh8wnP9A3DWGvXHVkO13D3DSnaSsdZx29cXlEsYKVkn1E2az+ZYFS4t0zi8x0w==@@ -4058,6 +4081,11 @@ json5@^2.1.0:dependencies:minimist "^1.2.0"+jsonpath-plus@^1.1.0:+ version "1.1.0"+ resolved "https://registry.yarnpkg.com/jsonpath-plus/-/jsonpath-plus-1.1.0.tgz#7caaea4db88b761a0a3b55d715cb01eaa469dfa5"+ integrity sha512-ydqTBOuLcFCUr9e7AxJlKCFgxzEQ03HjnIim0hJSdk2NxD8MOsaMOrRgP6XWEm5q3VuDY5+cRT1DM9vLlGo/qA==+kdbush@^2.0.1:version "2.0.1"resolved "https://registry.yarnpkg.com/kdbush/-/kdbush-2.0.1.tgz#90c6128e3001ac68c550d7c9e2f222c0269666f1"@@ -4545,7 +4573,7 @@ moment-es6@^1.0.0:dependencies:moment "*"-moment@*, moment@^2.10.2, moment@^2.20.1, moment@^2.22.2, moment@^2.24.0:+moment@*, moment@^2.10.2, moment@^2.24.0:version "2.24.0"resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==@@ -6382,7 +6410,7 @@ trim-right@^1.0.1:resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"integrity sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=-tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:+tslib@^1.10.0, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:version "1.10.0"resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==