Skip to content

armgit / core

Public Imported from GitHub
0

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

UI updates: Added time controls to or-attribute-history closes #9

Rich Turner3b3a53ba843f
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.json
index 4fbd1dcf4..8679517b2 100644
--- a/deployment/manager/shared/locales/en/or.json
+++ b/deployment/manager/shared/locales/en/or.json
@@ -1,6 +1,7 @@
{
- "asset": "asset",
- "asset_plural": "assets",
+ "asset": "Asset",
+ "asset_plural": "Assets",
+ "attribute": "Attribute",
"scenes": "Scenes",
"settings": "Settings",
"selectLanguage": "Select Language",
@@ -72,12 +73,19 @@
"confirmDeleteAssets": "Remove assets?",
"ok": "OK",
"cancel": "Cancel",
- "createdOn": "Created on",
+ "createdOn": "Created on: {{-date, LLLL}}",
"accessPublicRead": "Public read",
"type": "Type",
"path": "Path",
"showOnMap": "Show on map",
"noAssetSelected": "Please select an asset on the left",
"loading": "Loading...",
- "location": "Location"
+ "location": "Location",
+ "hour": "Hour",
+ "day": "Day",
+ "week": "Week",
+ "month": "Month",
+ "year": "Year",
+ "period": "Period",
+ "ending": "Ending"
}
\ No newline at end of file
diff --git a/deployment/manager/shared/locales/nl/or.json b/deployment/manager/shared/locales/nl/or.json
index 89fd0fabd..cfb825998 100644
--- a/deployment/manager/shared/locales/nl/or.json
+++ b/deployment/manager/shared/locales/nl/or.json
@@ -1,6 +1,7 @@
{
- "asset": "asset",
- "asset_plural": "assets",
+ "asset": "Asset",
+ "asset_plural": "Assets",
+ "attribute": "Attribute",
"scenes": "Scenes",
"settings": "Instellingen",
"selectLanguage": "Taal kiezen",
@@ -72,12 +73,19 @@
"confirmDeleteAssets": "Asset verwijderen?",
"ok": "OK",
"cancel": "Annuleren",
- "createdOn": "Aangemaakt op",
+ "createdOn": "Aangemaakt op: {{-date, LLLL}}",
"accessPublicRead": "Publiek",
"type": "Type",
"path": "Pad",
"showOnMap": "Tonen op kaart",
"noAssetSelected": "Kies aan de linkerkant een asset uit de lijst",
"loading": "Aan het laden...",
- "location": "Locatie"
+ "location": "Locatie",
+ "hour": "Hour",
+ "day": "Day",
+ "week": "Week",
+ "month": "Month",
+ "year": "Year",
+ "period": "Period",
+ "ending": "Ending"
}
\ No newline at end of file
diff --git a/ui/component/core/package.json b/ui/component/core/package.json
index 2c02e6da1..e9bc601da 100644
--- a/ui/component/core/package.json
+++ b/ui/component/core/package.json
@@ -20,6 +20,7 @@
"@openremote/rest": "^1.1.0",
"i18next": "^15.0.9",
"i18next-xhr-backend": "^2.0.1",
+ "moment": "^2.24.0",
"platform": "^1.3.5",
"url-search-params-polyfill": "^5.0.0"
},
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index c7ff05eab..4ddb836e3 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -80,7 +80,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
public static DEFAULT_CONFIG: AssetViewerConfig = {
viewerStyles: {
gridTemplateColumns: "repeat(12, 1fr)",
- gridTemplateRows: "30px max-content"
+ gridTemplateRows: "auto minmax(0, 1fr) minmax(0, 50%)"
},
panels: {
"info": {
@@ -88,8 +88,8 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
panelStyles: {
gridColumnStart: "1",
gridColumnEnd: "7",
- gridRowStart: "2",
- gridRowEnd: "3",
+ gridRowStart: "1",
+ gridRowEnd: "2",
},
fieldStyles: {
name: {
@@ -109,8 +109,8 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
panelStyles: {
gridColumnStart: "7",
gridColumnEnd: "13",
- gridRowStart: "2",
- gridRowEnd: "4",
+ gridRowStart: "1",
+ gridRowEnd: "3",
minHeight: "400px"
},
fieldStyles: {
@@ -125,8 +125,8 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
panelStyles: {
gridColumnStart: "1",
gridColumnEnd: "7",
- gridRowStart: "3",
- gridRowEnd: "5"
+ gridRowStart: "2",
+ gridRowEnd: "4"
}
},
"history": {
@@ -134,8 +134,8 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
panelStyles: {
gridColumnStart: "7",
gridColumnEnd: "13",
- gridRowStart: "4",
- gridRowEnd: "5",
+ gridRowStart: "3",
+ gridRowEnd: "4"
},
scrollable: false
}
@@ -211,22 +211,24 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
}
const descriptor = AssetModelUtil.getAssetDescriptor(this.asset!.type!);
- var assetDate = new Date(this.asset!.createdOn!);
- var formattedDate = assetDate.toLocaleString('nl-NL');
return html`
- <div id="container" style="${this._viewerConfig.viewerStyles ? styleMap(this._viewerConfig.viewerStyles) : ""}">
+ <div id="wrapper">
<div id="asset-header">
- <div class="title">
+ <div id="title">
<or-icon title="${descriptor && descriptor.type ? descriptor.type : "unset"}" style="--or-icon-fill: ${descriptor && descriptor.color ? "#" + descriptor.color : "unset"}" icon="${descriptor && descriptor.icon ? descriptor.icon : AssetType.THING.icon}"></or-icon>${this.asset.name}
</div>
- <div class="created mobileHidden">Aangemaakt op: ${formattedDate}</div>
+ <div id="created"><or-translate value="createdOn" .options="${{date: new Date(this.asset!.createdOn!)} as i18next.TOptions<i18next.InitOptions>}"></or-translate></div>
+ </div>
+ <div id="container" style="${this._viewerConfig.viewerStyles ? styleMap(this._viewerConfig.viewerStyles) : ""}">
+ ${html`${Object.entries(this._viewerConfig.panels).map(([name, panelConfig]) => {
+ const panelTemplate = OrAssetViewer.getPanel(name, this.asset!, this._attributes!, this._viewerConfig!, panelConfig, this.shadowRoot);
+ return panelTemplate || ``;
+ })}`
+ }
</div>
- ${html`${Object.entries(this._viewerConfig.panels).map(([name, panelConfig]) => {
- const panelTemplate = OrAssetViewer.getPanel(name, this.asset!, this._attributes!, this._viewerConfig!, panelConfig, this.shadowRoot);
- return panelTemplate || ``;
- })}`
- }`;
+ </div>
+ `;
}
protected updated(_changedProperties: PropertyValues) {
@@ -347,23 +349,29 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
width: 100%;
display: flex;
flex-direction: column;
+ position: relative;
}
#history-controls {
+ flex: 0;
margin-bottom: 10px;
+ position: absolute;
}
#history-attribute-picker {
flex: 0;
+ width: 200px;
}
or-attribute-history {
height: 100%;
+ flex: 1 1 auto;
+ --or-attribute-history-controls-margin: 0 0 0 204px;
}
</style>
<div id="history-container">
<div id="history-controls">
- <or-input id="history-attribute-picker" @or-input-changed="${(evt: OrInputChangedEvent) => attributeChanged(evt.detail.value)}" .type="${InputType.SELECT}" .options="${historyAttrs.map((attr) => [attr.name, getAttributeLabel(attr, undefined)])}"></or-input>
+ <or-input id="history-attribute-picker" .label="${i18next.t("attribute")}" @or-input-changed="${(evt: OrInputChangedEvent) => attributeChanged(evt.detail.value)}" .type="${InputType.SELECT}" .options="${historyAttrs.map((attr) => [attr.name, getAttributeLabel(attr, undefined)])}"></or-input>
</div>
<or-attribute-history id="attribute-history" .config="${viewerConfig.historyConfig}" .assetType="${asset.type}"></or-attribute-history>
</div>
diff --git a/ui/component/or-asset-viewer/src/style.ts b/ui/component/or-asset-viewer/src/style.ts
index f87e0f334..fb9ecf5f3 100644
--- a/ui/component/or-asset-viewer/src/style.ts
+++ b/ui/component/or-asset-viewer/src/style.ts
@@ -22,14 +22,21 @@ export const style = css`
display: none;
}
+ #wrapper {
+ height: 100%;
+ width: 100%;
+ display: flex;
+ flex-direction: column;
+ }
+
#container {
box-sizing: border-box;
padding: 20px 30px;
column-gap: var(--internal-or-asset-viewer-panel-margin);
row-gap: var(--internal-or-asset-viewer-panel-margin);
- height: 100%;
+ flex: 1 1 auto;
display: grid;
- overflow-y: auto;
+ width: 100%;
-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 */
@@ -67,26 +74,23 @@ export const style = css`
}
#asset-header {
+ padding: 20px 30px 0 30px;
display: flex;
align-items: center;
justify-content: space-between;
- grid-column-start: 1;
- grid-column-end: 13;
- grid-row-start: 1;
- grid-row-end: 2;
}
- #asset-header > .title {
+ #title {
flex: 1 0 auto;
font-size: 18px;
font-weight: bold;
}
- #asset-header .title > or-icon {
+ #title > or-icon {
margin-right: 10px;
}
- #asset-header > .created {
+ #created {
text-align: right;
flex: 1 0 auto;
font-size: 12px;
diff --git a/ui/component/or-attribute-history/src/index.ts b/ui/component/or-attribute-history/src/index.ts
index fcecab871..4590b3e80 100644
--- a/ui/component/or-attribute-history/src/index.ts
+++ b/ui/component/or-attribute-history/src/index.ts
@@ -12,13 +12,19 @@ import {
import i18next from "i18next";
import {translate} from "@openremote/or-translate";
import {AssetAttribute, AttributeRef, DatapointInterval, ValueDatapoint, ValueType} from "@openremote/model";
-import manager, {AssetModelUtil, DefaultColor2, DefaultColor3, DefaultColor4, DefaultColor5} from "@openremote/core";
+import manager, {
+ AssetModelUtil,
+ DefaultColor2,
+ DefaultColor3,
+ DefaultColor4,
+ DefaultColor5,
+ Util
+} from "@openremote/core";
import "@openremote/or-input";
import "@openremote/or-panel";
import "@openremote/or-translate";
-import {Util} from "@openremote/core";
import Chart, {ChartTooltipCallback} from "chart.js";
-import {InputType} from "@openremote/or-input";
+import {InputType, OrInputChangedEvent} from "@openremote/or-input";
import {MDCDataTable} from "@material/data-table";
import {JSONPath} from "jsonpath-plus";
import moment from "moment";
@@ -57,8 +63,14 @@ export interface TableConfig {
attributeValueTypes?: {[attributeValueType: string]: AssetTableConfig};
}
+export interface ChartConfig {
+ xLabel?: string;
+ yLabel?: string;
+}
+
export interface HistoryConfig {
- table: TableConfig;
+ table?: TableConfig;
+ chart?: ChartConfig;
}
// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling
@@ -68,7 +80,8 @@ const tableStyle = require("!!raw-loader!@material/data-table/dist/mdc.data-tabl
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-text-color: var(--or-attribute-history-text-color, var(--or-app-color3, ${unsafeCSS(DefaultColor3)}));
+ --internal-or-attribute-history-controls-margin: var(--or-attribute-history-controls-margin, 0);
--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)}));
@@ -95,10 +108,6 @@ const style = css`
height: 100%;
flex-direction: column;
}
-
- #container > * {
- width: 100%;
- }
#msg {
height: 100%;
@@ -111,29 +120,25 @@ const style = css`
#msg:not([hidden]) {
display: flex;
}
-
- #history-wrapper:not([hidden]) {
- height: 100%;
- display: flex;
- flex-direction: column;
- }
-
- #history-wrapper > * {
- width: 100%;
- }
- #chart-controls {
+ #controls {
flex: 0;
- display: none;
justify-content: space-between;
- margin-bottom: 10px;
+ padding-bottom: 10px;
+ margin: var(--internal-or-attribute-history-controls-margin);
+ }
+
+ #ending-controls {
+ float: right;
+ padding-right: 10px;
}
#chart-container {
- position: relative;
height: 100%;
+ flex: 1 1 auto;
+ position: relative;
}
-
+
#table-container {
height: 100%;
}
@@ -177,19 +182,7 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
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;
+ public interval?: DatapointInterval;
@property({type: Number})
public timestamp?: Date;
@@ -212,60 +205,85 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
protected _tableElem!: HTMLDivElement;
protected _table?: MDCDataTable;
protected _chart?: Chart;
- protected _type?: ValueType;
+ protected _type?: ValueType | null;
protected _style!: CSSStyleDeclaration;
+ connectedCallback() {
+ super.connectedCallback();
+ this._style = window.getComputedStyle(this);
+ }
+
+ disconnectedCallback(): void {
+ super.disconnectedCallback();
+ this._cleanup();
+ }
+
+
shouldUpdate(_changedProperties: PropertyValues): boolean {
- let reloadData = _changedProperties.has("interval");
+ let returnFalse = false;
+
+ if (!this.timestamp) {
+ this.timestamp = new Date();
+ returnFalse = true;
+ }
+
+ if (!this.interval) {
+ this.interval = DatapointInterval.DAY;
+ returnFalse = true;
+ }
+
+ if (returnFalse) {
+ // Will update on next pass
+ return false;
+ }
+
+ let reloadData = _changedProperties.has("interval") || _changedProperties.has("timestamp");
if (_changedProperties.has("attributeRef") || _changedProperties.has("attribute")) {
this._type = undefined;
+ this._cleanup();
reloadData = true;
}
if (reloadData) {
this._data = undefined;
- if (this.attribute || this.attributeRef) {
- this._loadData();
- }
+ 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;
+ const disabled = this._loading || !this._type;
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 id="controls">
+ <or-input .type="${InputType.SELECT}" ?disabled="${disabled}" .label="${i18next.t("period")}" @or-input-changed="${(evt: OrInputChangedEvent) => this.interval = evt.detail.value}" .value="${this.interval}" .options="${this._getIntervalOptions()}"></or-input>
+ <div id="ending-controls">
+ <or-input .type="${InputType.BUTTON}" ?disabled="${disabled}" icon="chevron-left-circle" rounded @click="${() => this._updateTimestamp(this.timestamp!, false)}"></or-input>
+ <or-input .type="${InputType.DATETIME}" ?disabled="${disabled}" label="${i18next.t("ending")}" .value="${this.timestamp}" @or-input-changed="${(evt: OrInputChangedEvent) => this._updateTimestamp(moment(evt.detail.value as string).toDate())}"></or-input>
+ <or-input .type="${InputType.BUTTON}" ?disabled="${disabled}" icon="chevron-right-circle" rounded @click="${() => this._updateTimestamp(this.timestamp!, true)}"></or-input>
</div>
- <or-panel ?hidden="${isChart}" id="table-container">
- ${this._tableTemplate || ``}
- </or-panel>
</div>
+ ${!this._type ? html`
+ <div id="msg">
+ <or-translate value="invalidAttribute"></or-translate>
+ </div>
+ ` : isChart
+ ? html`
+ <div id="chart-container">
+ <canvas id="chart"></canvas>
+ </div>
+ ` : html`
+ <or-panel id="table-container">
+ ${this._tableTemplate || ``}
+ </or-panel>
+ `}
</div>
`;
}
@@ -273,112 +291,104 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
updated(changedProperties: PropertyValues) {
super.updated(changedProperties);
- if (changedProperties.has("_data")) {
- if (!this._data) {
- this._cleanup();
- }
+ if (!this._type) {
+ return;
+ }
- if (this._data && this._data.length > 0) {
+ const isChart = this._type === ValueType.NUMBER || this._type === ValueType.BOOLEAN;
- 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;
+ }
+ }
- 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"))
}
- }
-
- 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,
+ // REMOVED AS DOESN'T SIZE CORRECTLY 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"
}
- ]
- },
- 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
+ ticks: {
+ autoSkip: true,
+ maxTicksLimit: 30,
+ fontColor: "#000",
+ fontFamily: "'Open Sans', Helvetica, Arial, Lucida, sans-serif",
+ fontSize: 9,
+ fontStyle: "normal"
},
- 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"
- }
- }]
+ gridLines: {
+ color: "#cccccc"
}
- }
- });
- } else {
- this._chart.data.datasets![0].data = this._data;
- this._chart.update();
+ }]
+ }
}
- } else {
- this._tableTemplate = this._getTableTemplate();
+ });
+ } else {
+ if (changedProperties.has("_data")) {
+ this._chart.data.datasets![0].data = this._data;
+ this._chart.update();
}
}
- }
-
- if (changedProperties.has("_tableTemplate") && this._tableElem) {
- // Don't think we need to instantiate
- //this._table = new MDCDataTable(this._tableElem);
+ } else {
+ this._tableTemplate = this._getTableTemplate();
}
}
@@ -535,12 +545,12 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
DatapointInterval.MONTH,
DatapointInterval.YEAR
].map((interval) => {
- return [interval, i18next.t(interval)];
+ return [interval, i18next.t(interval.toLowerCase())];
});
}
protected async _loadData() {
- if (!this.assetType || (!this.attribute && !this.attributeRef)) {
+ if (this._loading || this._type === null || !this.assetType || (!this.attribute && !this.attributeRef)) {
return;
}
@@ -548,7 +558,7 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
const assetId = this.attribute ? this.attribute.assetId! : this.attributeRef!.entityId!;
const attributeName = this.attribute ? this.attribute.name! : this.attributeRef!.attributeName!;
- if (!this._type) {
+ if (this._type === undefined) {
let attr = this.attribute;
if (!attr) {
@@ -575,7 +585,11 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
if (attrDescriptor && attrDescriptor.valueType) {
this._type = attrDescriptor.valueType;
+ } else {
+ this._type = null;
}
+ } else {
+ this._type = null;
}
}
@@ -584,12 +598,17 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
return;
}
+ if (!this.interval || !this.timestamp) {
+ this._loading = false;
+ return;
+ }
+
const response = await manager.rest.api.AssetDatapointResource.getDatapoints(
assetId,
attributeName,
{
- interval: this.interval,
- timestamp: this.timestamp ? this.timestamp.getTime() : new Date().valueOf()
+ interval: this.interval || DatapointInterval.DAY,
+ timestamp: this.timestamp.getTime()
}
);
@@ -599,4 +618,34 @@ export class OrAttributeHistory extends translate(i18next)(LitElement) {
this._data = response.data;
}
}
+
+ protected _updateTimestamp(timestamp: Date, forward?: boolean) {
+ if (!this.interval) {
+ return;
+ }
+
+ const newMoment = moment(timestamp);
+
+ if (forward !== undefined) {
+ switch (this.interval) {
+ case DatapointInterval.HOUR:
+ newMoment.add(forward ? 1 : -1, "hour");
+ break;
+ case DatapointInterval.DAY:
+ newMoment.add(forward ? 1 : -1, "day");
+ break;
+ case DatapointInterval.WEEK:
+ newMoment.add(forward ? 1 : -1, "week");
+ break;
+ case DatapointInterval.MONTH:
+ newMoment.add(forward ? 1 : -1, "month");
+ break;
+ case DatapointInterval.YEAR:
+ newMoment.add(forward ? 1 : -1, "year");
+ break;
+ }
+ }
+
+ this.timestamp = newMoment.toDate();
+ }
}
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index 132c98eb9..b01a0d473 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -9,6 +9,7 @@ import {MDCCheckbox} from "@material/checkbox";
import {MDCSwitch} from "@material/switch";
import {MDCSelect, MDCSelectEvent, } from "@material/select";
import {MDCFormField, MDCFormFieldInput} from "@material/form-field";
+import moment from "moment";
// 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");
@@ -303,19 +304,19 @@ export class OrInput extends LitElement {
`;
case InputType.BUTTON:
case InputType.BUTTON_MOMENTARY: {
- const rounded = !!(!this.value && this.rounded && this.icon);
+ const iconButton = this.isIconButton();
const classes = {
"mdc-button--raised": this.raised,
"mdc-button--unelevated": this.unElevated,
- "mdc-button--outlined": !rounded && this.outlined,
- "mdc-button--dense": !rounded && this.dense,
+ "mdc-button--outlined": !iconButton && this.outlined,
+ "mdc-button--dense": !iconButton && this.dense,
"or-input--rounded": this.rounded,
- "mdc-button": !rounded,
- "mdc-icon-button": rounded
+ "mdc-button": !iconButton,
+ "mdc-icon-button": iconButton
};
const iconClasses = {
- "mdc-icon-button__icon": rounded,
- "mdc-button__icon": !rounded,
+ "mdc-icon-button__icon": iconButton,
+ "mdc-button__icon": !iconButton,
};
if (this.type === InputType.BUTTON_MOMENTARY) {
return html`
@@ -383,10 +384,11 @@ export class OrInput extends LitElement {
switch (this.type) {
case InputType.DATETIME:
// Date time conversion for UNIX timestamps in millis
- if (typeof(val) === "number") {
+ if (val instanceof Date) {
+ val = moment(val).format("YYYY-MM-DDTHH:mm");
+ } else if (typeof(val) === "number") {
const offset = (new Date()).getTimezoneOffset() * 60000;
- const str = (new Date(val - offset)).toISOString();
- val = str.slice(0, str.lastIndexOf(":"));
+ val = moment(new Date(val - offset)).format("YYYY-MM-DDTHH:mm");
}
break;
case InputType.JSON:
@@ -434,7 +436,7 @@ export class OrInput extends LitElement {
?readonly="${this.readonly}"
?disabled="${this.disabled}"
@change="${(e: Event) => this.onValueChange((e.target as HTMLInputElement).value)}"
- value="${val}"
+ .value="${val}"
min="${ifDefined(this.min)}"
max="${ifDefined(this.max)}"
step="${ifDefined(this.step)}"
@@ -461,6 +463,10 @@ export class OrInput extends LitElement {
return html`<span>INPUT TYPE NOT IMPLEMENTED</span>`;
}
+ protected isIconButton() {
+ return !!(!this.value && this.rounded && this.icon);
+ }
+
protected updated(_changedProperties: PropertyValues): void {
super.updated(_changedProperties);
@@ -490,7 +496,11 @@ export class OrInput extends LitElement {
case InputType.RADIO:
break;
case InputType.BUTTON:
- this._mdcComponent = new MDCRipple(component);
+ const ripple = new MDCRipple(component);
+ if (this.isIconButton()) {
+ ripple.unbounded = true;
+ }
+ this._mdcComponent = ripple;
break;
case InputType.CHECKBOX:
this._mdcComponent = new MDCCheckbox(component);
diff --git a/ui/component/or-input/src/style.ts b/ui/component/or-input/src/style.ts
index eb22749df..5a6311201 100644
--- a/ui/component/or-input/src/style.ts
+++ b/ui/component/or-input/src/style.ts
@@ -6,6 +6,7 @@ import {DefaultColor1, DefaultColor4} from "@openremote/core";
export const orInputStyle = css`
:host {
+ display: inline-block;
--internal-or-input-color: var(--or-input-color, var(--or-app-color4, ${unsafeCSS(DefaultColor4)}));
--internal-or-input-text-color: var(--or-input-text-color, var(--or-app-color1, ${unsafeCSS(DefaultColor1)}));
@@ -54,4 +55,8 @@ export const orInputStyle = css`
.mdc-select--focused .mdc-select__dropdown-icon {
--or-icon-fill: var(--internal-or-input-color);
}
+
+ .mdc-icon-button {
+ padding: 0;
+ }
`;