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: various bug fixes and enhancements (closes #216)

Rich Turnere5d9353de9d5
diff --git a/ui/app/or-app/src/app.ts b/ui/app/or-app/src/app.ts
index f29dea90e..3a5c2c346 100644
--- a/ui/app/or-app/src/app.ts
+++ b/ui/app/or-app/src/app.ts
@@ -22,20 +22,20 @@ const INITIAL_STATE: AppState = {
scrollTop: 0,
};
+export interface PageAndParams {
+ page: string;
+ params?: {[k in string]: any};
+}
+
const appSlice = createSlice({
name: "app",
initialState: INITIAL_STATE,
reducers: {
- updatePage(state, action: PayloadAction<string>) {
- return {
- ...state,
- page: action.payload
- };
- },
- updateParams(state, action: PayloadAction<{[k in string]: any}>) {
+ updatePage(state, action: PayloadAction<PageAndParams | string>) {
return {
...state,
- params: action.payload
+ page: typeof action.payload === "string" ? action.payload : action.payload.page,
+ params: typeof action.payload === "string" ? undefined : action.payload.params
};
},
updateDrawer(state, action: PayloadAction<boolean>) {
@@ -53,5 +53,5 @@ const appSlice = createSlice({
}
});
-export const {updatePage, updateParams, updateDrawer, scrollToTop} = appSlice.actions;
+export const {updatePage, updateDrawer, scrollToTop} = appSlice.actions;
export const appReducer = appSlice.reducer;
diff --git a/ui/app/or-app/src/index.ts b/ui/app/or-app/src/index.ts
index 614aac478..55a073b9e 100644
--- a/ui/app/or-app/src/index.ts
+++ b/ui/app/or-app/src/index.ts
@@ -17,11 +17,11 @@ import "@openremote/or-icon";
import {updateMetadata} from "pwa-helpers/metadata";
import i18next from "i18next";
import Navigo from "navigo";
-import manager, {Auth, DefaultColor2, DefaultColor3, DefaultHeaderHeight, ManagerConfig, Util, BasicLoginResult} from "@openremote/core";
+import manager, {Auth, DefaultColor2, DefaultColor3, ManagerConfig, Util, BasicLoginResult} from "@openremote/core";
import {DEFAULT_LANGUAGES, HeaderConfig, HeaderItem, Languages} from "./or-header";
import {DialogConfig, OrMwcDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
-import {AnyAction, EnhancedStore, Unsubscribe, Action} from "@reduxjs/toolkit";
-import {AppStateKeyed, updatePage, updateParams} from "./app";
+import {AnyAction, EnhancedStore, Unsubscribe} from "@reduxjs/toolkit";
+import {AppStateKeyed, updatePage} from "./app";
import {ThunkMiddleware} from "redux-thunk";
import { translate } from "@openremote/or-translate";
import { InputType, OrInputChangedEvent } from "@openremote/or-input";
@@ -71,6 +71,8 @@ export interface PageProvider<S extends AppStateKeyed> {
export abstract class Page<S extends AppStateKeyed> extends translate(i18next)(LitElement) {
+ abstract get name(): string;
+
protected _store: EnhancedStore<S, AnyAction, ReadonlyArray<ThunkMiddleware<S>>>;
protected _storeUnsubscribe!: Unsubscribe;
@@ -339,8 +341,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
provider.routes.forEach((route) => {
router.on(
route, (params, query) => {
- this._store.dispatch(updatePage(pageName));
- this._store.dispatch(updateParams(params));
+ this._store.dispatch(updatePage({page: pageName, params: params}));
}
)
});
@@ -426,7 +427,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
if (this._page && this.appConfig.pages[this._page]) {
const pageElem = this.appConfig.pages[this._page].pageCreator();
this._mainElem.appendChild(pageElem);
- pageTitle += (i18next.isInitialized ? " - " + i18next.t(this._page) : " - " + this._page);
+ pageTitle += (i18next.isInitialized ? " - " + i18next.t(pageElem.name) : " - " + pageElem.name);
}
}
diff --git a/ui/app/or-app/src/pages/page-account.ts b/ui/app/or-app/src/pages/page-account.ts
index 8feb71ab5..08fe69830 100644
--- a/ui/app/or-app/src/pages/page-account.ts
+++ b/ui/app/or-app/src/pages/page-account.ts
@@ -29,6 +29,10 @@ class PageAccount<S extends AppStateKeyed> extends Page<S> {
`;
}
+ get name(): string {
+ return "account";
+ }
+
constructor(store: EnhancedStore<S>) {
super(store);
}
diff --git a/ui/app/or-app/src/pages/page-assets.ts b/ui/app/or-app/src/pages/page-assets.ts
index 72606d8ff..8b48528d5 100644
--- a/ui/app/or-app/src/pages/page-assets.ts
+++ b/ui/app/or-app/src/pages/page-assets.ts
@@ -2,7 +2,7 @@ import {css, customElement, html, property, TemplateResult, unsafeCSS} from "lit
import "@openremote/or-asset-tree";
import "@openremote/or-asset-viewer";
import {ViewerConfig} from "@openremote/or-asset-viewer";
-import {OrAssetTreeSelectionChangedEvent, AssetTreeConfig} from "@openremote/or-asset-tree";
+import {AssetTreeConfig, OrAssetTreeSelectionChangedEvent, OrAssetTreeRequestSelectEvent} from "@openremote/or-asset-tree";
import {DefaultBoxShadow} from "@openremote/core";
import {AppStateKeyed, Page, router} from "../index";
import {EnhancedStore} from "@reduxjs/toolkit";
@@ -490,9 +490,16 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
@property()
public config?: PageAssetsConfig;
+ @property()
+ protected _selectedId;
+
@property()
protected _assetId;
+ get name(): string {
+ return "assets";
+ }
+
constructor(store: EnhancedStore<S>) {
super(store);
}
@@ -500,15 +507,17 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
connectedCallback() {
super.connectedCallback();
this.addEventListener(OrAssetTreeSelectionChangedEvent.NAME, this._onTreeSelectionChanged);
+ this.addEventListener(OrAssetTreeRequestSelectEvent.NAME, this._onTreeSelectionRequested);
}
disconnectedCallback() {
super.disconnectedCallback();
this.removeEventListener(OrAssetTreeSelectionChangedEvent.NAME, this._onTreeSelectionChanged);
+ this.removeEventListener(OrAssetTreeRequestSelectEvent.NAME, this._onTreeSelectionRequested);
}
protected render(): TemplateResult | void {
- const selectedIds = [this._assetId];
+ const selectedIds = [this._selectedId];
return html`
<or-asset-tree .config="${this.config && this.config.tree ? this.config.tree : null}" id="pageAssetTree" class="${this._assetId ? "hideMobile" : ""}" .selectedIds="${selectedIds}"></or-asset-tree>
<or-asset-viewer class="${!this._assetId ? "hideMobile" : ""}" .config="${this.config && this.config.viewer ? this.config.viewer : PAGE_ASSETS_DEFAULT_CONFIG}" .assetId="${this._assetId}"></or-asset-viewer>
@@ -516,15 +525,31 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {
}
stateChanged(state: S) {
- this._assetId = state.app.params && state.app.params.id ? state.app.params.id : undefined;
+ this._selectedId = state.app.params && state.app.params.id ? state.app.params.id : undefined;
+ }
+
+ protected _onTreeSelectionRequested(event: OrAssetTreeRequestSelectEvent) {
+ // Block the selection change but update the route which will cause the change
+ event.detail.allow = false;
+ const assetId = event.detail.detail.node.asset.id;
+ if (assetId) {
+ router.navigate("assets/" + assetId);
+ } else {
+ router.navigate("assets/");
+ }
}
protected _onTreeSelectionChanged(event: OrAssetTreeSelectionChangedEvent) {
const nodes = event.detail;
- if (nodes[0]) {
- router.navigate("assets/" + nodes[0].asset.id);
- } else {
+ const assetId = nodes[0] ? nodes[0].asset.id : undefined;
+
+ if (this._selectedId !== assetId) {
+ // Asset requested in route couldn't be selected so navigate to no asset
router.navigate("assets/");
+ this._assetId = undefined;
+ } else {
+ // Requested asset has been selected in the asset tree
+ this._assetId = assetId;
}
}
}
diff --git a/ui/app/or-app/src/pages/page-gateway.ts b/ui/app/or-app/src/pages/page-gateway.ts
index d9be39be4..9529a6f5b 100644
--- a/ui/app/or-app/src/pages/page-gateway.ts
+++ b/ui/app/or-app/src/pages/page-gateway.ts
@@ -135,6 +135,10 @@ class PageGateway<S extends AppStateKeyed> extends Page<S> {
}
};
+ get name(): string {
+ return "gateway";
+ }
+
constructor(store: EnhancedStore<S>) {
super(store);
}
diff --git a/ui/app/or-app/src/pages/page-insights.ts b/ui/app/or-app/src/pages/page-insights.ts
index c91692267..c4de5c1f4 100644
--- a/ui/app/or-app/src/pages/page-insights.ts
+++ b/ui/app/or-app/src/pages/page-insights.ts
@@ -1,7 +1,6 @@
-import {css, customElement, html, property, TemplateResult, unsafeCSS} from "lit-element";
+import {css, customElement, html, property, TemplateResult} from "lit-element";
import "@openremote/or-data-viewer";
import {DataViewerConfig} from "@openremote/or-data-viewer";
-import {DefaultBoxShadow} from "@openremote/core";
import {AppStateKeyed, Page} from "../index";
import {EnhancedStore} from "@reduxjs/toolkit";
import i18next from "i18next";
@@ -76,6 +75,10 @@ class PageInsights<S extends AppStateKeyed> extends Page<S> {
@property()
protected _assetId;
+ get name(): string {
+ return "insights";
+ }
+
constructor(store: EnhancedStore<S>) {
super(store);
}
diff --git a/ui/app/or-app/src/pages/page-logs.ts b/ui/app/or-app/src/pages/page-logs.ts
index eb0b19233..15d0cf725 100644
--- a/ui/app/or-app/src/pages/page-logs.ts
+++ b/ui/app/or-app/src/pages/page-logs.ts
@@ -6,6 +6,7 @@ import {EnhancedStore} from "@reduxjs/toolkit";
export function pageLogsProvider<S extends AppStateKeyed>(store: EnhancedStore<S>, config?: ViewerConfig) {
return {
+ name: "logs",
routes: [
"logs"
],
@@ -34,6 +35,13 @@ class PageLogs<S extends AppStateKeyed> extends Page<S> {
`;
}
+ @property()
+ public config?: ViewerConfig;
+
+ get name(): string {
+ return "account";
+ }
+
constructor(store: EnhancedStore<S>) {
super(store);
}
@@ -41,10 +49,6 @@ class PageLogs<S extends AppStateKeyed> extends Page<S> {
public stateChanged(state: S) {
}
-
- @property()
- public config?: ViewerConfig;
-
protected render() {
return html`
<or-log-viewer .config="${this.config}"></or-log-viewer>
diff --git a/ui/app/or-app/src/pages/page-map.ts b/ui/app/or-app/src/pages/page-map.ts
index aeea7e184..c19fd8c3e 100644
--- a/ui/app/or-app/src/pages/page-map.ts
+++ b/ui/app/or-app/src/pages/page-map.ts
@@ -220,6 +220,10 @@ export class PageMap<S extends MapStateKeyed> extends Page<S> {
return assets.find((asset) => asset.id === currentId);
});
+ get name(): string {
+ return "map";
+ }
+
constructor(store: EnhancedStore<S>) {
super(store);
}
diff --git a/ui/app/or-app/src/pages/page-mobile-geofences.ts b/ui/app/or-app/src/pages/page-mobile-geofences.ts
index 95ff59d04..14467f3ba 100644
--- a/ui/app/or-app/src/pages/page-mobile-geofences.ts
+++ b/ui/app/or-app/src/pages/page-mobile-geofences.ts
@@ -24,17 +24,7 @@ export function pageMobileGeofencesProvider<S extends AppStateKeyed>(store: Enha
const QUERY_VIEW = new URLSearchParams(window.location.search).get("view");
@customElement("page-mobile-geofences")
class PageMobileGeofences<S extends AppStateKeyed> extends Page<S> {
- @property({type: String})
- view = QUERY_VIEW ? QUERY_VIEW : "map";
-
- @property({type: Array})
- mapItems = [];
-
- @property({type: Array})
- listItems = [];
- @property({type: Object})
- activeItem;
static get styles() {
// language=CSS
@@ -125,6 +115,22 @@ class PageMobileGeofences<S extends AppStateKeyed> extends Page<S> {
`;
}
+ @property({type: String})
+ view = QUERY_VIEW ? QUERY_VIEW : "map";
+
+ @property({type: Array})
+ mapItems = [];
+
+ @property({type: Array})
+ listItems = [];
+
+ @property({type: Object})
+ activeItem;
+
+ get name(): string {
+ return "mobile-geofences";
+ }
+
constructor(store: EnhancedStore<S>) {
super(store);
this.getGeoNotifications();
diff --git a/ui/app/or-app/src/pages/page-mobile-onboarding.ts b/ui/app/or-app/src/pages/page-mobile-onboarding.ts
index 2d2fc0d1e..c3fccc3ea 100644
--- a/ui/app/or-app/src/pages/page-mobile-onboarding.ts
+++ b/ui/app/or-app/src/pages/page-mobile-onboarding.ts
@@ -81,11 +81,12 @@ class PageMobileOnboarding<S extends AppStateKeyed> extends Page<S> {
`;
}
+ get name(): string {
+ return "mobile-onboarding";
+ }
+
constructor(store: EnhancedStore<S>) {
super(store);
-
-
-
}
public connectedCallback() {
diff --git a/ui/app/or-app/src/pages/page-mobile-splash.ts b/ui/app/or-app/src/pages/page-mobile-splash.ts
index 0157c6085..d84b222e0 100644
--- a/ui/app/or-app/src/pages/page-mobile-splash.ts
+++ b/ui/app/or-app/src/pages/page-mobile-splash.ts
@@ -36,9 +36,14 @@ class PageMobileSplash<S extends AppStateKeyed> extends Page<S> {
`;
}
+ get name(): string {
+ return "mobile-splash";
+ }
+
constructor(store: EnhancedStore<S>) {
super(store);
}
+
public connectedCallback() {
super.connectedCallback();
setTimeout(() => {
diff --git a/ui/app/or-app/src/pages/page-rules.ts b/ui/app/or-app/src/pages/page-rules.ts
index 567c80698..06fb0716c 100644
--- a/ui/app/or-app/src/pages/page-rules.ts
+++ b/ui/app/or-app/src/pages/page-rules.ts
@@ -52,9 +52,6 @@ export const PAGE_RULES_CONFIG_DEFAULT: PageRulesConfig = {
@customElement("page-rules")
class PageRules<S extends AppStateKeyed> extends Page<S> {
- @property()
- public config?: PageRulesConfig;
-
static get styles() {
// language=CSS
return css`
@@ -69,6 +66,13 @@ class PageRules<S extends AppStateKeyed> extends Page<S> {
`;
}
+ @property()
+ public config?: PageRulesConfig;
+
+ get name(): string {
+ return "rules";
+ }
+
constructor(store: EnhancedStore<S>) {
super(store);
}
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index 033751eb0..7fa0e687f 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -10,7 +10,7 @@ import "@openremote/or-table";
import "@openremote/or-panel";
import "@openremote/or-mwc-components/dist/or-mwc-dialog";
import {OrTranslate, translate} from "@openremote/or-translate";
-import {InputType, OrInputChangedEvent} from "@openremote/or-input";
+import {InputType, OrInputChangedEvent, OrInput} from "@openremote/or-input";
import manager, {AssetModelUtil, subscribe, Util} from "@openremote/core";
import {OrTable} from "@openremote/or-table";
import {OrChartConfig, OrChartEvent} from "@openremote/or-chart";
@@ -34,7 +34,7 @@ import {DialogAction, OrMwcDialog} from "@openremote/or-mwc-components/dist/or-m
import { GenericAxiosResponse } from "axios";
import { OrIcon } from "@openremote/or-icon";
-export type PanelType = "property" | "location" | "attribute" | "history" | "chart" | "group" | "survey" | "survey-results";
+export type PanelType = "property" | "attribute" | "history" | "group" | "survey" | "survey-results";
export interface PanelConfig {
type?: PanelType;
@@ -47,6 +47,14 @@ export interface PanelConfig {
readonly?: string[];
panelStyles?: { [style: string]: string };
fieldStyles?: { [field: string]: { [style: string]: string } };
+ itemConfig?: {[name: string]: {
+ readonly?: boolean;
+ disabled?: boolean;
+ label?: string;
+ disableButton?: boolean;
+ disableHelperText?: boolean;
+ inputTypeOverride?: InputType;
+ }};
}
export interface GroupPanelConfig extends PanelConfig {
@@ -94,10 +102,7 @@ class EventHandler {
}
}
-export interface OrComputeGridEventDetail {
-}
-
-export class OrComputeGridEvent extends CustomEvent<OrComputeGridEventDetail> {
+export class OrComputeGridEvent extends CustomEvent<void> {
public static readonly NAME = "or-compute-grid-event";
@@ -118,17 +123,17 @@ function getPanel(name: string, panelConfig: PanelConfig, content: TemplateResul
}
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">
- <div class="panel-title">
- <or-translate value="${panelConfig.title ? panelConfig.title : name}"></or-translate>
- </div>
- <div class="panel-content">
- ${content}
- </div>
+ <div class=${classMap({panel: true, mobileHidden: panelConfig.hideOnMobile === true})} id="${name}-panel" style="${panelConfig && panelConfig.panelStyles ? styleMap(panelConfig.panelStyles) : ""}">
+ <div class="panel-content-wrapper">
+ <div class="panel-title">
+ <or-translate value="${panelConfig.title ? panelConfig.title : name}"></or-translate>
+ </div>
+ <div class="panel-content">
+ ${content}
</div>
</div>
- `;
+ </div>
+ `;
}
export function getPanelContent(panelName: string, asset: Asset, attributes: AssetAttribute[], hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig): TemplateResult | undefined {
@@ -153,22 +158,21 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass
let content: TemplateResult | undefined;
- // if (panelConfig && panelConfig.type === "property") {
- // // Special handling for info panel which only shows properties
- // let properties = OrAssetViewer.getInfoProperties(panelConfig);
-
- // if (properties.length === 0) {
- // return;
- // }
-
- // content = html`
- // ${properties.map((prop) => {
- // let style = styles ? styles[prop!] : undefined;
- // return prop === "attributes" ? `` : OrAssetViewer.getField(prop, true, style, OrAssetViewer.getPropertyTemplate(prop, (asset as { [index: string]: any })[prop], viewerConfig, panelConfig, shadowRoot));
- // })}
- // `;
- // } else
- if (panelConfig && panelConfig.type === "survey") {
+ if (panelConfig && panelConfig.type === "property") {
+ // Special handling for info panel which only shows properties
+ const properties = OrAssetViewer.getInfoProperties(panelConfig);
+
+ if (properties.length === 0) {
+ return;
+ }
+
+ content = html`
+ ${properties.map((prop) => {
+ const style = styles ? styles[prop!] : undefined;
+ return prop === "attributes" ? `` : getField(prop, true, style, getPropertyTemplate(asset, prop, hostElement, viewerConfig, panelConfig));
+ })}
+ `;
+ } else if (panelConfig && panelConfig.type === "survey") {
content = html`
<or-survey id="survey" .surveyId="${asset.id}"></or-survey>
`;
@@ -248,41 +252,8 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass
`;
}
- }
- // DEPRECATED
- // else if (panelConfig && panelConfig.type === "chart") {
-
- // let storeDataPointAttrs = attrs.filter((attr) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!))
-
- // let assetAttributes;
- // // let defaultAttrs = storeDataPointAttrs.filter((attr) => (defaultAttributes && defaultAttributes.indexOf(attr.name!) >= 0));
- // // 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" panelName="${panelName}" .config="${viewerConfig.chartConfig}" .activeAsset="${asset}" activeAssetId="${asset.id}" .assets="${assetList ? assetList : [asset]}" .assetAttributes="${assetAttributes}"></or-chart>
- // `;
-
- // }
- else if (panelConfig && panelConfig.type === "location") {
-
- const attribute = attrs.find((attr) => attr.name === AttributeType.LOCATION.attributeName);
- if (attribute) {
- content = html`
- <div class="field">
- <or-attribute-input .assetType="${asset.type}" .attribute="${attribute}" readonly disableButton></or-attribute-input>
- </div>
- `;
- }
} else if (panelConfig && panelConfig.type === "group") {
+
if (asset.type !== "urn:openremote:asset:group") {
return;
}
@@ -382,7 +353,10 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass
loadingMsg.hidden = true;
attributeTable.hidden = false;
const headers = [...selectedAttributes].sort();
- attributeTable.headers = headers.map((header) => i18next.t(header));
+ attributeTable.headers = headers.map((attrName) => {
+ const attributeDescriptor = AssetModelUtil.getAttributeDescriptorFromAsset(attrName, childAssetType);
+ return Util.getAttributeLabel(undefined, attributeDescriptor, undefined, false);
+ });
attributeTable.headers.unshift(i18next.t("groupAssetName"));
attributeTable.rows = childAssets.map((childAsset) => {
// todo: it's only processing including selected headers here...
@@ -443,11 +417,78 @@ export function getAttributeTemplate(asset: Asset, attribute: AssetAttribute, ho
return result;
}
}
+
+ let attrLabel: string | undefined;
+ let attrDisabled: boolean | undefined;
+ let attrReadonly: boolean | undefined;
+ let attrDisableButton: boolean | undefined;
+ let attrInputType: InputType | undefined;
+ let attrDisableHelper: boolean | undefined;
+
+
+ if (panelConfig.itemConfig && panelConfig.itemConfig[attribute.name!]) {
+ const attrConfig = panelConfig.itemConfig[attribute.name!];
+ attrLabel = attrConfig.label;
+ attrDisabled = attrConfig.disabled;
+ attrReadonly = attrConfig.readonly;
+ attrDisableButton = attrConfig.disableButton;
+ attrDisableHelper = attrConfig.disableHelperText;
+ attrInputType = attrConfig.inputTypeOverride;
+ }
+
return html`
- <or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}" hasHelperText></or-attribute-input>
+ <or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}" .disabled="${attrDisabled}" .label="${attrLabel}" .readonly="${attrReadonly}" .disableButton="${attrDisableButton}" .inputType="${attrInputType}" .hasHelperText="${!attrDisableHelper}"></or-attribute-input>
`;
}
+export function getPropertyTemplate(asset: Asset, property: string, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) {
+ let value = (asset as { [index: string]: any })[property];
+
+ if (viewerConfig.propertyViewProvider) {
+ const result = viewerConfig.propertyViewProvider(asset, property, value, hostElement, viewerConfig, panelConfig);
+ if (result) {
+ return result;
+ }
+ }
+
+ let type = InputType.TEXT;
+ let minLength: number | undefined;
+ let maxLength: number | undefined;
+
+ switch (property) {
+ case "path":
+ if (!value || !(Array.isArray(value))) {
+ return;
+ }
+
+ // Populate value when we get the response
+ getAssetNames(value as string[]).then(
+ (names) => {
+ if (hostElement && hostElement.shadowRoot) {
+ const pathField = hostElement.shadowRoot.getElementById("property-path") as OrInput;
+ if (pathField) {
+ pathField.value = names.reverse().join(" > ");
+ }
+ }
+ }
+ );
+ value = i18next.t("loading");
+ break;
+ case "createdOn":
+ type = InputType.DATETIME;
+ break;
+ case "accessPublicRead":
+ type = InputType.CHECKBOX;
+ break;
+ case "name":
+ minLength = 1;
+ maxLength = 1023;
+ break;
+ }
+
+ return html`<or-input id="property-${property}" type="${type}" .minLength="${minLength}" .maxLength="${maxLength}" dense .value="${value}" readonly label="${i18next.t(property)}"></or-input>`;
+}
+
export function getField(name: string, isProperty: boolean, styles: { [style: string]: string } | undefined, content: TemplateResult | undefined): TemplateResult {
if (!content) {
return html``;
@@ -459,6 +500,23 @@ export function getField(name: string, isProperty: boolean, styles: { [style: st
`;
}
+async function getAssetNames(ids: string[]): Promise<string[]> {
+ const response = await manager.rest.api.AssetResource.queryAssets({
+ select: {
+ excludePath: true,
+ excludeParentInfo: true,
+ excludeAttributes: true
+ },
+ ids: ids
+ });
+
+ if (response.status !== 200 || !response.data || response.data.length !== ids.length) {
+ return ids;
+ }
+
+ return ids.map((id) => response.data.find((asset) => asset.id === id)!.name!);
+}
+
async function getAssetChildren(id: string, childAssetType: string): Promise<Asset[]> {
let response: GenericAxiosResponse<Asset[]>;
@@ -489,8 +547,6 @@ async function getAssetChildren(id: string, childAssetType: string): Promise<Ass
@customElement("or-asset-viewer")
export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElement)) {
- public static DEFAULT_PANEL_TYPE: PanelType = "attribute";
-
public static DEFAULT_VIEWER_CONFIG: AssetViewerConfig = {
viewerStyles: {
@@ -524,13 +580,19 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
}
},
location: {
- type: "location",
+ type: "attribute",
include: ["location"],
panelStyles: {
},
fieldStyles: {
location: {
}
+ },
+ itemConfig: {
+ location: {
+ label: "",
+ readonly: true
+ }
}
},
attributes: {
@@ -655,6 +717,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
this._loading = true;
super.assetIds = [this.assetId];
} else {
+ this._loading = false;
super.assetIds = undefined;
}
}
@@ -701,52 +764,6 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
return properties;
}
- // public static getPropertyTemplate(property: string, value: any, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig, shadowRoot: ShadowRoot | null) {
- // let type = InputType.TEXT;
- // let minLength: number | undefined;
- // let maxLength: number | undefined;
-
- // if (viewerConfig.propertyViewProvider) {
- // const result = viewerConfig.propertyViewProvider(property, value, viewerConfig, panelConfig);
- // if (result) {
- // return result;
- // }
- // }
-
- // switch (property) {
- // case "path":
- // if (!value || !(Array.isArray(value))) {
- // return;
- // }
-
- // // Populate value when we get the response
- // OrAssetViewer.getAssetNames(value as string[]).then(
- // (names) => {
- // if (shadowRoot) {
- // const pathField = shadowRoot.getElementById("property-path") as OrInput;
- // if (pathField) {
- // pathField.value = names.reverse().join(" > ");
- // }
- // }
- // }
- // );
- // value = i18next.t("loading");
- // break;
- // case "createdOn":
- // type = InputType.DATETIME;
- // break;
- // case "accessPublicRead":
- // type = InputType.CHECKBOX;
- // break;
- // case "name":
- // minLength = 1;
- // maxLength = 1023;
- // break;
- // }
-
- // return html`<or-input id="property-${property}" type="${type}" .minLength="${minLength}" .maxLength="${maxLength}" dense .value="${value}" readonly label="${i18next.t(property)}"></or-input>`;
- // }
-
// TODO: Add debounce in here to minimise render calls
_onEvent(event: SharedEvent) {
if (event.eventType === "asset") {
diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.ts
index 71f40647e..a029e28c5 100644
--- a/ui/component/or-attribute-input/src/index.ts
+++ b/ui/component/or-attribute-input/src/index.ts
@@ -45,9 +45,11 @@ declare global {
}
}
-export type AttributeInputCustomProvider = (assetType: string | undefined, attribute: AssetAttribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean | undefined, disabled: boolean | undefined, label: string | undefined) => ((value: any) => TemplateResult) | undefined;
+export type AttributeInputCustomProviderResult = ((value: any, timestamp: number | undefined, loading: boolean, sending: boolean, error: boolean) => TemplateResult) | undefined;
-export const GeoJsonPointInputTemplateProvider: AttributeInputCustomProvider = (assetType, attribute, attributeDescriptor, valueDescriptor, valueChangeNotifier, readonly, disabled, label) => (value: any) => {
+export type AttributeInputCustomProvider = (assetType: string | undefined, attribute: AssetAttribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean | undefined, disabled: boolean | undefined, label: string | undefined) => AttributeInputCustomProviderResult;
+
+export const GeoJsonPointInputTemplateProvider: AttributeInputCustomProvider = (assetType, attribute, attributeDescriptor, valueDescriptor, valueChangeNotifier, readonly, disabled, label) => (value, timestamp, loading, sending, error) => {
let pos: LngLat | undefined;
let center: number[] | undefined;
if (value) {
@@ -57,7 +59,7 @@ export const GeoJsonPointInputTemplateProvider: AttributeInputCustomProvider = (
const iconAndColor = getMarkerIconAndColorFromAssetType(assetType);
const clickHandler = (mapClickDetail: MapEventDetail) => {
- if (!readonly && !disabled) {
+ if (!readonly && !disabled && mapClickDetail.doubleClick) {
const geoJsonPoint = MapUtil.getGeoJSONPoint(mapClickDetail.lngLat);
if (valueChangeNotifier) {
valueChangeNotifier(geoJsonPoint);
@@ -65,16 +67,67 @@ export const GeoJsonPointInputTemplateProvider: AttributeInputCustomProvider = (
}
};
- return html`
+ const content = html`
<style>
or-map {
border: #e5e5e5 1px solid;
+ margin: 3px 0;
}
- </style>
+ </style>
<or-map class="or-map" @or-map-clicked="${(ev: OrMapClickedEvent) => clickHandler(ev.detail)}" .center="${center}">
<or-map-marker active .lng="${pos ? pos.lng : undefined}" .lat="${pos ? pos.lat : undefined}" .icon="${iconAndColor ? iconAndColor.icon : undefined}" .activeColor="${iconAndColor ? "#" + iconAndColor.color : undefined}" .color="${iconAndColor ? "#" + iconAndColor.color : undefined}"></or-map-marker>
</or-map>
`;
+
+ return getAttributeInputWrapper(content, loading, !!disabled, getHelperText(sending, false, timestamp), label, undefined);
+}
+
+export function getAttributeInputWrapper(content: TemplateResult, loading: boolean, disabled: boolean, helperText: string | undefined, label: string | undefined, buttonIcon?: string, valueProvider?: () => any, valueChangeConsumer?: (value: any) => void): TemplateResult {
+
+ if (helperText) {
+ content = html`
+ <div id="wrapper-helper">
+ ${label ? html`<div>${label}</div>` : ``}
+ <div id="wrapper-input">${content}</div>
+ <div id="helper-text">${helperText}</div>
+ </div>
+ `;
+ }
+
+ if (buttonIcon) {
+ content = html`
+ ${content}
+ <or-input id="send-btn" icon="${buttonIcon}" type="button" .disabled="${disabled || loading}" @or-input-changed="${(e: OrInputChangedEvent) => {
+ e.stopPropagation();
+ if (valueProvider && valueChangeConsumer) {
+ valueChangeConsumer(valueProvider())
+ }
+ }}"></or-input>
+ `;
+ }
+
+ return html`
+ <div id="wrapper" class="${buttonIcon === undefined || buttonIcon ? "no-padding" : "right-padding"}">
+ ${content}
+ <div id="scrim" class="${ifDefined(loading ? undefined : "hidden")}"><progress class="pure-material-progress-circular"></progress></div>
+ </div>
+ `;
+}
+
+export function getHelperText(sending: boolean, error: boolean, timestamp: number | undefined): string | undefined {
+ if (sending) {
+ return i18next.t("sending");
+ }
+
+ if (error) {
+ return i18next.t("sendFailed");
+ }
+
+ if (!timestamp) {
+ return;
+ }
+
+ return i18next.t("updatedWithDate", { date: new Date(timestamp) });
}
const DEFAULT_TIMEOUT = 5000;
@@ -90,7 +143,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
display: inline-block;
}
- #wrapper > or-input {
+ #wrapper or-input, #wrapper or-map {
width: 100%;
}
@@ -111,13 +164,13 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
#wrapper-input {
flex: 1;
- margin-left: 16px;
+ display: flex;
}
#wrapper-input > or-input {
- width: 100%;
+ margin-left: 16px;
}
-
+
/* Copy of mdc text field helper text styles */
#helper-text {
margin-left: 16px;
@@ -326,7 +379,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
public customProvider?: AttributeInputCustomProvider;
public writeTimeout?: number = DEFAULT_TIMEOUT;
- protected _template?: (value: any) => TemplateResult;
+ protected _template?: AttributeInputCustomProviderResult;
protected _attributeDescriptor?: AttributeDescriptor;
protected _attributeValueDescriptor?: AttributeValueDescriptor;
protected _inputType?: InputType;
@@ -474,8 +527,17 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
this._inputType = undefined;
this._valueFormat = undefined;
+ if (this.label) {
+ this._label = this.label;
+ } else if (this.label !== "" && this.label !== null) {
+ const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(this.assetType, this.attribute || this._attributeDescriptor);
+ this._label = Util.getAttributeLabel(this.attribute, descriptors[0], descriptors[1], true);
+ }
+ this._readonly = this.readonly !== undefined ? this.readonly : Util.getMetaValue(MetaItemType.READ_ONLY, this.attribute, this._attributeDescriptor);
+ this._disabled = this.disabled;
+
if (this.customProvider) {
- this._template = this.customProvider(this.assetType, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor, (v) => this._updateValue(v), this.readonly, this.disabled, this.label);
+ this._template = this.customProvider(this.assetType, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor, (v) => this._updateValue(v), this._readonly, this._disabled, this._label);
}
if (this._template) {
@@ -487,7 +549,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
} else if (this._attributeValueDescriptor) {
switch (this._attributeValueDescriptor.name) {
case AttributeValueType.GEO_JSON_POINT.name:
- this._template = GeoJsonPointInputTemplateProvider(this.assetType, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor, (v) => this._updateValue(v), this.readonly, this.disabled, this.label);
+ this._template = GeoJsonPointInputTemplateProvider(this.assetType, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor, (v) => this._updateValue(v), this._readonly, this._disabled, this._label);
return;
case AttributeValueType.SWITCH_MOMENTARY.name:
this._inputType = InputType.BUTTON_MOMENTARY;
@@ -533,14 +595,6 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
this._max = Util.getMetaValue(MetaItemType.RANGE_MAX, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor) as number;
this._unit = Util.getMetaValue(MetaItemType.UNIT_TYPE, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor) as string;
this._step = Util.getMetaValue(MetaItemType.STEP, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor) as number;
- if (this.label) {
- this._label = this.label;
- } else {
- const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(this.assetType, this.attribute || this._attributeDescriptor);
- this._label = Util.getAttributeLabel(this.attribute, descriptors[0], descriptors[1], true);
- }
- this._readonly = this.readonly !== undefined ? this.readonly : Util.getMetaValue(MetaItemType.READ_ONLY, this.attribute, this._attributeDescriptor);
- this._disabled = this.disabled;
this._options = Util.getMetaValue(MetaItemType.ALLOWED_VALUES, this.attribute, this._attributeDescriptor);
if (!this.inputType && this._inputType === InputType.TEXT && this._options && Array.isArray(this._options) && this._options.length > 0) {
@@ -569,14 +623,14 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
const value = this.getValue();
if (this._template) {
- content = this._template(value);
+ content = this._template(value, this.getTimestamp(), loading, !!this._writeTimeoutHandler, this._sendError);
} else {
if (!this._inputType) {
content = html`<div><or-translate .value="attributeUnsupported"></or-translate></div>`;
}
- const helperText = this.getHelperText();
+ const helperText = this.hasHelperText ? getHelperText(!!this._writeTimeoutHandler, this._sendError, this.getTimestamp()) : undefined;
const buttonIcon = this._writeTimeoutHandler ? "send-clock" : "send";
const supportsHelperText = this.inputTypeSupportsHelperText();
let label = this._label;
@@ -600,34 +654,10 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
}
}}"></or-input>`;
- if (helperText && !supportsHelperText) {
- // Manually provide helper text outside of or-input
- content = html`
- <div id="wrapper-helper">
- <div>${this._label}</div>
- <div id="wrapper-input">${content}</div>
- <div id="helper-text">${helperText}</div>
- </div>
- `;
- }
-
- if (this._showButton) {
- content = html`
- ${content}
- <or-input id="send-btn" icon="${buttonIcon}" type="button" .disabled="${this._disabled || loading}" @or-input-changed="${(e: OrInputChangedEvent) => {
- e.stopPropagation();
- this._updateValue(this._attrInput.value);
- }}"></or-input>
- `;
- }
+ content = getAttributeInputWrapper(content, loading, !!this._disabled, !supportsHelperText ? helperText : undefined, this._label, this._showButton ? buttonIcon : this.disableButton ? undefined : "", () => this._attrInput.value, (v) => this._updateValue(v));
}
- return html`
- <div id="wrapper" class="${this._showButton || this.disableButton ? "no-padding" : "right-padding"}">
- ${content}
- <div id="scrim" class="${ifDefined(loading ? undefined : "hidden")}"><progress class="pure-material-progress-circular"></progress></div>
- </div>
- `;
+ return content;
}
protected updated(_changedProperties: PropertyValues): void {
@@ -646,28 +676,6 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
return this._attributeEvent ? this._attributeEvent.timestamp : this.attribute ? this.attribute.valueTimestamp : undefined;
}
- protected getHelperText(): string | undefined {
- if (!this.hasHelperText) {
- return;
- }
-
- if (this._writeTimeoutHandler) {
- return i18next.t("sending");
- }
-
- if (this._sendError) {
- return i18next.t("sendFailed");
- }
-
- const timestamp = this.getTimestamp();
-
- if (!timestamp) {
- return;
- }
-
- return i18next.t("updatedWithDate", { date: new Date(timestamp) });
- }
-
protected inputTypeSupportsButton() {
return this._inputType === InputType.NUMBER
|| this._inputType === InputType.TELEPHONE
diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.ts
index 52ab38332..ad7c1d3e2 100644
--- a/ui/component/or-map/src/index.ts
+++ b/ui/component/or-map/src/index.ts
@@ -23,6 +23,7 @@ export interface ViewSettings {
export interface MapEventDetail {
lngLat: LngLat;
+ doubleClick: boolean;
}
export class OrMapLoadedEvent extends CustomEvent<void> {
@@ -41,9 +42,10 @@ export class OrMapClickedEvent extends CustomEvent<MapEventDetail> {
public static readonly NAME = "or-map-clicked";
- constructor(lngLat: LngLat) {
+ constructor(lngLat: LngLat, doubleClick: boolean = false) {
super(OrMapClickedEvent.NAME, {
detail: {
+ doubleClick: doubleClick,
lngLat: lngLat
},
bubbles: true,
diff --git a/ui/component/or-map/src/mapwidget.ts b/ui/component/or-map/src/mapwidget.ts
index 4caacad69..6a472ebf7 100644
--- a/ui/component/or-map/src/mapwidget.ts
+++ b/ui/component/or-map/src/mapwidget.ts
@@ -227,11 +227,13 @@ export class MapWidget {
await this.styleLoaded();
- this._mapGl.on("click", (e: MapMouseEvent)=> {
+ this._mapGl.on("click", (e: MapMouseEvent) => {
this._onMapClick(e.lngLat);
});
-
+ this._mapGl.on("dblclick", (e: MapMouseEvent) => {
+ this._onMapClick(e.lngLat, true);
+ });
}
this._mapContainer.dispatchEvent(new OrMapLoadedEvent());
@@ -249,8 +251,8 @@ export class MapWidget {
});
}
- protected _onMapClick(lngLat: LngLat) {
- this._mapContainer.dispatchEvent(new OrMapClickedEvent(lngLat));
+ protected _onMapClick(lngLat: LngLat, doubleClicked: boolean = false) {
+ this._mapContainer.dispatchEvent(new OrMapClickedEvent(lngLat, doubleClicked));
}
public addMarker(marker: OrMapMarker) {
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 e3af1f252..6832216ff 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
@@ -117,7 +117,7 @@ export class OrRuleActionAttribute extends translate(i18next)(LitElement) {
attributes = Util.getAssetAttributes(asset).filter((attr) => !Util.hasMetaItem(attr, MetaItemType.READ_ONLY.urn!))
.map((attr) => {
const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(asset.type, attr);
- const label = Util.getAttributeLabel(attribute, descriptors[0], descriptors[1], false);
+ const label = Util.getAttributeLabel(attr, descriptors[0], descriptors[1], false);
return [attr.name!, label];
});
} else {