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: overhaul of or-attribute-input to make the component usable from other components that don't actually have attributes (e.g. or-rules) without using the template function
Rich Turnerca63989784fc
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.javaindex 5e8aeb94a..8badacf63 100644--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java@@ -125,6 +125,11 @@ public class AssetViewActivitythis::onAttributeEvent));+ registrations.add(environment.getEventBus().register(+ AssetEvent.class,+ this::onAssetEvent+ ));+writeAssetToView();writeAttributesToView();loadParent();@@ -229,6 +234,17 @@ public class AssetViewActivity}}+ protected void onAssetEvent(AssetEvent assetEvent) {+ for (AttributeView attributeView : attributeViews) {+ attributeView.getAttribute().getReference().map(AttributeRef::getAttributeName)+ .flatMap(attributeName -> assetEvent.getAsset().getAttribute(attributeName))+ .ifPresent(assetAttribute ->+ attributeView.getAttribute().setValue(+ assetAttribute.getValue().orElse(null),+ assetAttribute.getValueTimestamp().orElse(0L)));+ }+ }+protected void onAgentStatusEvent(AgentStatusEvent event) {for (AttributeView attributeView : attributeViews) {AssetAttribute assetAttribute = attributeView.getAttribute();@@ -369,14 +385,14 @@ public class AssetViewActivityprotected void readAllAttributeValues() {environment.getEventService().dispatch(- new ReadAssetAttributesEvent(asset.getId())+ new ReadAssetEvent(asset.getId()));}protected void readAttributeValue(AssetAttribute attribute) {attribute.getReference().ifPresent(attributeRef ->environment.getEventService().dispatch(- new ReadAssetAttributesEvent(attributeRef.getEntityId(), attributeRef.getAttributeName())+ new ReadAssetAttributeEvent(attributeRef)));}diff --git a/ui/app/main/tsconfig.json b/ui/app/main/tsconfig.jsonindex 59092f4af..7da0c6ae9 100644--- a/ui/app/main/tsconfig.json+++ b/ui/app/main/tsconfig.json@@ -5,10 +5,9 @@"strict": true},"include": [- "./src",- "../../component/or-map/@types"+ "./src"],"references": [{ "path": "../or-app" }]-}\ No newline at end of file+}diff --git a/ui/app/or-app/src/pages/page-assets.ts b/ui/app/or-app/src/pages/page-assets.tsindex 7a646ec10..6957c5833 100644--- a/ui/app/or-app/src/pages/page-assets.ts+++ b/ui/app/or-app/src/pages/page-assets.ts@@ -496,8 +496,14 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {super(store);}- firstUpdated() {- this.shadowRoot.getElementById('pageAssetTree').addEventListener(OrAssetTreeSelectionChangedEvent.NAME, (evt) => this._onTreeSelectionChanged(evt));+ connectedCallback() {+ super.connectedCallback();+ this.addEventListener(OrAssetTreeSelectionChangedEvent.NAME, this._onTreeSelectionChanged);+ }++ disconnectedCallback() {+ super.disconnectedCallback();+ this.removeEventListener(OrAssetTreeSelectionChangedEvent.NAME, this._onTreeSelectionChanged);}protected render(): TemplateResult | void {@@ -514,8 +520,10 @@ class PageAssets<S extends AppStateKeyed> extends Page<S> {protected _onTreeSelectionChanged(event: OrAssetTreeSelectionChangedEvent) {const nodes = event.detail;- if(nodes[0]){- router.navigate('assets/'+nodes[0].asset.id);+ if (nodes[0]) {+ router.navigate("assets/" + nodes[0].asset.id);+ } else {+ router.navigate("assets/");}}}diff --git a/ui/app/or-app/src/pages/page-rules.ts b/ui/app/or-app/src/pages/page-rules.tsindex 24a6ffeea..567c80698 100644--- a/ui/app/or-app/src/pages/page-rules.ts+++ b/ui/app/or-app/src/pages/page-rules.ts@@ -37,11 +37,11 @@ export const PAGE_RULES_CONFIG_DEFAULT: PageRulesConfig = {descriptors: {all: {excludeAssets: [- AssetType.BUILDING.type,- AssetType.CITY.type,- AssetType.AREA.type,- AssetType.FLOOR.type,- AssetType.AGENT.type+ AssetType.BUILDING.type!,+ AssetType.CITY.type!,+ AssetType.AREA.type!,+ AssetType.FLOOR.type!,+ AssetType.AGENT.type!]}},diff --git a/ui/app/or-app/tsconfig.json b/ui/app/or-app/tsconfig.jsonindex fcba31fc8..2f146293f 100644--- a/ui/app/or-app/tsconfig.json+++ b/ui/app/or-app/tsconfig.json@@ -7,21 +7,20 @@"strict": false},"include": [- "./src",- "../../component/or-map/@types"+ "./src"],"references": [{ "path": "../../component/core" },{ "path": "../../component/or-icon" },- { "path": "../../component/or-input" },- { "path": "../../component/or-map" },+ { "path": "../../component/or-map" },+ { "path": "../../component/or-input" },+ { "path": "../../component/or-attribute-input" },{ "path": "../../component/or-asset-tree" },+ { "path": "../../component/or-asset-viewer" },{ "path": "../../component/or-data-viewer" },{ "path": "../../component/or-log-viewer" },- { "path": "../../component/or-attribute-input" },{ "path": "../../component/or-chart" },- { "path": "../../component/or-asset-viewer" },- { "path": "../../component/or-rules" },- { "path": "../../component/or-table" }+ { "path": "../../component/or-table" },+ { "path": "../../component/or-rules" }]-}\ No newline at end of file+}diff --git a/ui/component/core/src/asset-mixin.ts b/ui/component/core/src/asset-mixin.tsindex 7e4b17cae..77a76c7c9 100644--- a/ui/component/core/src/asset-mixin.ts+++ b/ui/component/core/src/asset-mixin.ts@@ -1,7 +1,7 @@/* tslint:disable:no-empty */import {EventProviderFactory, EventProviderStatus} from "./event";-import {arraysEqual} from "./util";-import {AttributeRef, SharedEvent, EventIdentifier} from "@openremote/model";+import {objectsEqual} from "./util";+import {AttributeRef, SharedEvent, EventRequestResponseWrapper} from "@openremote/model";declare type Constructor<T = {}> = new (...args: any[]) => T;@@ -132,7 +132,7 @@ export const subscribe = (eventProviderFactory: EventProviderFactory) => <T exte}public set assetIds(assetIds: string[] | undefined) {- if (arraysEqual(this._assetIds, assetIds)) {+ if (objectsEqual(this._assetIds, assetIds)) {return;}@@ -145,7 +145,7 @@ export const subscribe = (eventProviderFactory: EventProviderFactory) => <T exte}public set attributeRefs(attributes: AttributeRef[] | undefined) {- if (arraysEqual(this._attributeRefs, attributes)) {+ if (objectsEqual(this._attributeRefs, attributes)) {return;}@@ -157,7 +157,7 @@ export const subscribe = (eventProviderFactory: EventProviderFactory) => <T exteeventProviderFactory.getEventProvider()!.sendEvent(event);}- public _sendEventWithReply(event: SharedEvent & EventIdentifier): Promise<SharedEvent & EventIdentifier> {+ public _sendEventWithReply<U extends SharedEvent, V extends SharedEvent>(event: EventRequestResponseWrapper<U>): Promise<V> {return eventProviderFactory.getEventProvider()!.sendEventWithReply(event);}diff --git a/ui/component/core/src/event.ts b/ui/component/core/src/event.tsindex 240ed3f09..e0512f3d8 100644--- a/ui/component/core/src/event.ts+++ b/ui/component/core/src/event.ts@@ -6,12 +6,14 @@ import {EventSubscription,RenewEventSubscriptions,SharedEvent,- ReadAssetAttributesEvent,AssetEvent,- ReadAssetEvent,TriggeredEventSubscription,AttributeRef,- EventIdentifier+ EventRequestResponseWrapper,+ ReadAssetsEvent,+ AssetsEvent,+ AssetEventCause,+ Attribute} from "@openremote/model";export enum EventProviderStatus {@@ -41,7 +43,7 @@ export interface EventProvider {sendEvent<T extends SharedEvent>(event: T): void;- sendEventWithReply<T extends SharedEvent & EventIdentifier, U extends SharedEvent & EventIdentifier>(event: T): Promise<U>;+ sendEventWithReply<T extends SharedEvent, U extends SharedEvent>(event: EventRequestResponseWrapper<T>): Promise<U>;}// Interface to provide a singleton implementation of EventProvider@@ -62,6 +64,7 @@ const RENEW_MESSAGE_PREFIX = "RENEW:";const UNAUTHORIZED_MESSAGE_PREFIX = "UNAUTHORIZED:";const TRIGGERED_MESSAGE_PREFIX = "TRIGGERED:";const EVENT_MESSAGE_PREFIX = "EVENT:";+const EVENT_REQUEST_RESPONSE_MESSAGE_PREFIX = "REQUESTRESPONSE:";abstract class EventProviderImpl implements EventProvider {@@ -108,7 +111,7 @@ abstract class EventProviderImpl implements EventProvider {this._doConnect().then((connected: boolean) => {if (this._connectingDeferred) {- let deferred = this._connectingDeferred;+ const deferred = this._connectingDeferred;this._connectingDeferred = null;if (this._reconnectTimer) {@@ -156,7 +159,7 @@ abstract class EventProviderImpl implements EventProvider {public subscribe<T extends SharedEvent>(eventSubscription: EventSubscription<T>, callback: (event: T) => void): Promise<string> {- let subscriptionInfo = {+ const subscriptionInfo: EventSubscriptionInfo<SharedEvent> = {eventSubscription: eventSubscription,callback: callback as ((event: SharedEvent) => void),deferred: new Deferred<string>()@@ -164,7 +167,7 @@ abstract class EventProviderImpl implements EventProvider {if (this._pendingSubscription != null || this._status !== EventProviderStatus.CONNECTED) {this._queuedSubscriptions.push(subscriptionInfo);- return subscriptionInfo.deferred.promise;+ return subscriptionInfo.deferred!.promise;}this._pendingSubscription = subscriptionInfo;@@ -172,15 +175,15 @@ abstract class EventProviderImpl implements EventProvider {this._doSubscribe(eventSubscription).then(subscriptionId => {if (this._pendingSubscription) {- let subscriptionInfo = this._pendingSubscription;+ const subscription = this._pendingSubscription;this._pendingSubscription = null;// Store subscriptionId and callback- this._subscriptionMap[subscriptionId] = subscriptionInfo;+ this._subscriptionMap[subscriptionId] = subscription;this._processNextSubscription();- let deferred = subscriptionInfo.deferred;- subscriptionInfo.deferred = null;+ const deferred = subscription.deferred;+ subscription.deferred = null;if (deferred) {deferred.resolve(subscriptionId);@@ -189,11 +192,11 @@ abstract class EventProviderImpl implements EventProvider {},(reason) => {if (this._pendingSubscription) {- const subscriptionInfo = this._pendingSubscription;+ const subscription = this._pendingSubscription;this._pendingSubscription = null;this._processNextSubscription();- const deferred = subscriptionInfo.deferred;- subscriptionInfo.deferred = null;+ const deferred = subscription.deferred;+ subscription.deferred = null;if (deferred) {deferred.reject(reason);@@ -220,7 +223,7 @@ abstract class EventProviderImpl implements EventProvider {}}- public sendEventWithReply<T extends SharedEvent & EventIdentifier, U extends SharedEvent & EventIdentifier>(event: T): Promise<U> {+ public sendEventWithReply<T extends SharedEvent, U extends SharedEvent>(event: EventRequestResponseWrapper<T>): Promise<U> {if (this._status !== EventProviderStatus.CONNECTED) {return Promise.reject("Not connected");}@@ -229,7 +232,7 @@ abstract class EventProviderImpl implements EventProvider {public async subscribeAssetEvents(ids: string[] | AttributeRef[] | null, requestCurrentValues: boolean, callback: (event: AssetEvent) => void): Promise<string> {- let subscription: EventSubscription<AssetEvent> = {+ const subscription: EventSubscription<AssetEvent> = {eventType: "asset"};@@ -248,16 +251,32 @@ abstract class EventProviderImpl implements EventProvider {try {subscriptionId = await this.subscribe(subscription, callback);- // Get the current state of each asset+ // Get the current state of the assetsif (assetIds && requestCurrentValues) {- assetIds.forEach(assetId => {- let readEvent: ReadAssetEvent = {- assetId: assetId,- eventType: "read-asset",- subscriptionId: subscriptionId!- };- this.sendEvent(readEvent);- });+ const readRequest: EventRequestResponseWrapper<ReadAssetsEvent> = {+ messageId: "read-assets:" + assetIds.join(",") + ":" + subscriptionId,+ event: {+ eventType: "read-assets",+ assetQuery: {+ ids: assetIds,+ select: {+ excludeParentInfo: true,+ excludePath: true+ }+ }+ }+ }+ const response: AssetsEvent = await this.sendEventWithReply(readRequest);+ if (response.assets) {+ response.assets.forEach((asset) => {+ const assetEvent: AssetEvent = {+ eventType: "asset",+ asset: asset,+ cause: AssetEventCause.READ+ };+ callback(assetEvent);+ });+ }}} catch (e) {console.error("Failed to subscribe to asset events for assets: " + ids);@@ -277,10 +296,10 @@ abstract class EventProviderImpl implements EventProvider {}const isAttributeRef = typeof ids[0] !== "string";- const assetIds = isAttributeRef ? (ids as AttributeRef[]).map((id) => id.entityId!) : ids as string[];+ const assetIds = isAttributeRef ? [...new Set((ids as AttributeRef[]).map((id) => id.entityId!))] : [...new Set(ids as string[])];const attributes = isAttributeRef ? ids as AttributeRef[] : undefined;- let subscription: EventSubscription<AttributeEvent> = {+ const subscription: EventSubscription<AttributeEvent> = {eventType: "attribute",filter: {filterType: "asset",@@ -305,15 +324,40 @@ abstract class EventProviderImpl implements EventProvider {// Get the current value of each assets attributesif (requestCurrentValues) {- assetIds.forEach((assetId) => {- let readEvent: ReadAssetAttributesEvent = {- assetId: assetId,- eventType: "read-asset-attributes",- attributeNames: attributes ? attributes.filter((attr) => attr.entityId === assetId).map((attr) => attr.attributeName!) : undefined,- subscriptionId: subscriptionId!- };- this.sendEvent(readEvent);- });+ const readEvent: EventRequestResponseWrapper<ReadAssetsEvent> = {+ messageId: "read-assets:" + assetIds.join("") + ":" + subscriptionId,+ event: {+ eventType: "read-assets",+ assetQuery: {+ ids: assetIds,+ select: {+ excludeParentInfo: true,+ excludePath: true+ }+ }+ }+ };+ const response: AssetsEvent = await this.sendEventWithReply(readEvent);+ if (response.assets) {+ response.assets.forEach((asset) => {+ Object.entries(asset.attributes!).forEach(([attributeName, v]) => {+ const attr = v as Attribute;+ if (!attributes || attributes.find((attributeRef) => attributeRef.entityId === asset.id && attributeRef.attributeName === attributeName)) {+ callback({+ eventType: "attribute",+ timestamp: attr.valueTimestamp,+ attributeState: {+ value: attr.value,+ attributeRef: {+ entityId: asset.id,+ attributeName: attributeName+ }+ }+ });+ }+ });+ })+ }}} catch (e) {console.error("Failed to subscribe to attribute events for assets/attributes: " + assetIds.join(", "));@@ -332,19 +376,19 @@ abstract class EventProviderImpl implements EventProvider {}setTimeout(() => {- let subscriptionInfo = this._queuedSubscriptions.shift();+ const subscriptionInfo = this._queuedSubscriptions.shift();if (subscriptionInfo) {this.subscribe(subscriptionInfo.eventSubscription, subscriptionInfo.callback).then((id: string) => {- let deferred = subscriptionInfo!.deferred;+ const deferred = subscriptionInfo!.deferred;subscriptionInfo!.deferred = null;if (deferred) {deferred.resolve(id);}}, reason => {- let deferred = subscriptionInfo!.deferred;+ const deferred = subscriptionInfo!.deferred;subscriptionInfo!.deferred = null;if (deferred) {@@ -369,7 +413,7 @@ abstract class EventProviderImpl implements EventProvider {}protected _onMessageReceived(subscriptionId: string, event: SharedEvent) {- let subscriptionInfo = this._subscriptionMap[subscriptionId];+ const subscriptionInfo = this._subscriptionMap[subscriptionId];if (subscriptionInfo) {subscriptionInfo.callback(event);@@ -435,7 +479,7 @@ abstract class EventProviderImpl implements EventProvider {protected abstract _doSend<T extends SharedEvent>(event: T): void;- protected abstract _doSendWithReply<T extends SharedEvent & EventIdentifier, U extends SharedEvent & EventIdentifier>(event: T): Promise<U>;+ protected abstract _doSendWithReply<T extends SharedEvent, U extends SharedEvent>(event: EventRequestResponseWrapper<T>): Promise<U>;protected abstract _doConnect(): Promise<boolean>;@@ -455,7 +499,7 @@ export class WebSocketEventProvider extends EventProviderImpl {protected _webSocket: WebSocket | undefined = undefined;protected _connectDeferred: Deferred<boolean> | null = null;protected _subscribeDeferred: Deferred<string> | null = null;- protected _repliesDeferred: Map<string, Deferred<any>> = new Map<string, Deferred<any>>();+ protected _repliesDeferred: Map<string, Deferred<SharedEvent>> = new Map<string, Deferred<SharedEvent>>();protected _renewalTimer: number | null = null;get endpointUrl(): string {@@ -485,7 +529,7 @@ export class WebSocketEventProvider extends EventProviderImpl {this._webSocket!.onopen = () => {if (this._connectDeferred) {- let deferred = this._connectDeferred;+ const deferred = this._connectDeferred;this._connectDeferred = null;deferred.resolve(true);}@@ -493,7 +537,7 @@ export class WebSocketEventProvider extends EventProviderImpl {this._webSocket!.onerror = () => {if (this._connectDeferred) {- let deferred = this._connectDeferred;+ const deferred = this._connectDeferred;this._connectDeferred = null;deferred.resolve(false);} else {@@ -507,7 +551,7 @@ export class WebSocketEventProvider extends EventProviderImpl {this._webSocket = undefined;if (this._connectDeferred) {- let deferred = this._connectDeferred;+ const deferred = this._connectDeferred;this._connectDeferred = null;deferred.resolve(false);} else {@@ -551,14 +595,14 @@ export class WebSocketEventProvider extends EventProviderImpl {this._onMessageReceived(triggered.subscriptionId!, event);});}- } else if (msg.startsWith(EVENT_MESSAGE_PREFIX)) {- const str = msg.substring(EVENT_MESSAGE_PREFIX.length);- const event = JSON.parse(str) as SharedEvent;- if ((event as EventIdentifier).messageId) {- const deferred = this._repliesDeferred.get((event as EventIdentifier).messageId!);- this._repliesDeferred.delete((event as EventIdentifier).messageId!);+ } else if (msg.startsWith(EVENT_REQUEST_RESPONSE_MESSAGE_PREFIX)) {+ const str = msg.substring(EVENT_REQUEST_RESPONSE_MESSAGE_PREFIX.length);+ const event = JSON.parse(str) as EventRequestResponseWrapper<SharedEvent>;+ if (event.messageId && event.event) {+ const deferred = this._repliesDeferred.get(event.messageId!);+ this._repliesDeferred.delete(event.messageId!);if (deferred) {- deferred.resolve(event as (SharedEvent & EventIdentifier));+ deferred.resolve(event.event);}}}@@ -625,7 +669,7 @@ export class WebSocketEventProvider extends EventProviderImpl {this._webSocket!.send(message);}- protected _doSendWithReply<T extends SharedEvent & EventIdentifier, U extends SharedEvent & EventIdentifier>(event: T): Promise<U> {+ protected _doSendWithReply<T extends SharedEvent, U extends SharedEvent>(event: EventRequestResponseWrapper<T>): Promise<U> {if (!event.messageId) {event.messageId = new Date().getTime().toString(10);@@ -635,9 +679,9 @@ export class WebSocketEventProvider extends EventProviderImpl {return Promise.reject("There's already a pending send and reply with this ID");}- const deferred = new Deferred<U>();+ const deferred = new Deferred<SharedEvent>();this._repliesDeferred.set(event.messageId, deferred);- this._webSocket!.send(EVENT_MESSAGE_PREFIX + JSON.stringify(event));- return deferred.promise;+ this._webSocket!.send(EVENT_REQUEST_RESPONSE_MESSAGE_PREFIX + JSON.stringify(event));+ return (deferred as unknown as Deferred<U>).promise;}}diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.tsindex 4e7b99054..9450c5465 100644--- a/ui/component/core/src/index.ts+++ b/ui/component/core/src/index.ts@@ -17,7 +17,6 @@ import {} from "@openremote/model";import * as Util from "./util";import orIconSet from "./or-icon-set";-import { Deferred } from "./util";// Re-exportsexport {Util};@@ -99,6 +98,11 @@ export interface BasicLoginResult {closeCallback: undefined | ((authenticated: boolean) => void);}+export enum MapType {+ VECTOR = "VECTOR",+ RASTER = "RASTER"+}+export interface ManagerConfig {managerUrl: string;keycloakUrl?: string;@@ -113,6 +117,7 @@ export interface ManagerConfig {pollingIntervalMillis?: number;loadIcons?: boolean;loadDescriptors?: boolean;+ mapType?: MapType;loadTranslations?: string[];translationsLoadPath?: string;configureTranslationsOptions?: (i18next: i18next.InitOptions) => void;@@ -448,6 +453,10 @@ export class Manager implements EventProviderFactory {return this.events;}+ get mapType() {+ return this._config.mapType || MapType.VECTOR;+ }+protected static normaliseConfig(config: ManagerConfig): ManagerConfig {const normalisedConfig: ManagerConfig = Object.assign({}, config);diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.tsindex e0279cef1..4dd049d52 100644--- a/ui/component/core/src/util.ts+++ b/ui/component/core/src/util.ts@@ -13,10 +13,12 @@ import {AssetAttribute,AttributeDescriptor,MetaItemType,- MetaItemDescriptor+ MetaItemDescriptor,+ AttributeValueDescriptor} from "@openremote/model";import i18next from "i18next";import Qs from "qs";+import {AssetModelUtil} from "./index";export class Deferred<T> {@@ -173,23 +175,52 @@ export function isTimeDurationNegativeInfinity(time?: string): boolean {return "-*" === time;}-export function arraysEqual<T>(arr1?: T[], arr2?: T[]) {- if (arr1 === arr2) {- return true;+export function isObject(object: any): boolean {+ if (!!object) {+ return typeof object === "object";}- if (!arr1 || !arr2) {- return false;+ return false;+}++export function objectsEqual(obj1?: any, obj2?: any, deep: boolean = true): boolean {+ if (obj1 === obj2) {+ return true;}- if (arr1.length !== arr2.length) {++ if (!obj1 || !obj2) {return false;}- for (let i = arr1.length; i--;) {- if (arr1[i] !== arr2[i]) {++ if (deep) {+ let iterator1: [string, any][] | undefined;+ let iterator2: [string, any][] | undefined;++ if (Array.isArray(obj1) || typeof obj1 === "object") {+ if (typeof obj2 !== typeof obj1) {+ return false;+ }+ iterator1 = Object.entries(obj1).sort((a, b) => b[0].localeCompare(a[0]));+ iterator2 = Object.entries(obj2).sort((a, b) => b[0].localeCompare(a[0]));+ }++ if (!iterator1 || !iterator2) {+ return false;+ }++ if (iterator1.length !== iterator2.length) {return false;}++ for (let i = iterator1.length; i--;) {+ if (iterator1[i][0] !== iterator2[i][0] || !objectsEqual(iterator1[i][1], iterator2[i][1])) {+ return false;+ }+ }++ return true;}- return true;+ return false;}export function arrayRemove<T>(arr: T[], item: T) {@@ -243,7 +274,7 @@ export function hasMetaItem(attribute: Attribute, name: string): boolean {return !!getFirstMetaItem(attribute, name);}-export function getMetaValue(metaItemUrn: string | MetaItemDescriptor, attribute: Attribute | undefined, descriptor: AttributeDescriptor | undefined): any {+export function getMetaValue(metaItemUrn: string | MetaItemDescriptor, attribute: Attribute | undefined, descriptor: AttributeDescriptor | undefined, valueDescriptor?: AttributeValueDescriptor): any {const urn = typeof metaItemUrn === "string" ? metaItemUrn : (metaItemUrn as MetaItemDescriptor).urn;if (attribute && attribute.meta) {@@ -255,6 +286,11 @@ export function getMetaValue(metaItemUrn: string | MetaItemDescriptor, attributeconst metaItemDescriptor = descriptor.metaItemDescriptors.find((mid) => mid.urn === urn);return metaItemDescriptor ? metaItemDescriptor.initialValue : undefined;}++ if (valueDescriptor && valueDescriptor.metaItemDescriptors) {+ const metaItemDescriptor = valueDescriptor.metaItemDescriptors.find((mid) => mid.urn === urn);+ return metaItemDescriptor ? metaItemDescriptor.initialValue : undefined;+ }}export function getAttributeLabel(attribute: Attribute | undefined, descriptor: AttributeDescriptor | undefined, fallback?: string): string {@@ -267,19 +303,46 @@ export function getAttributeLabel(attribute: Attribute | undefined, descriptor:return i18next.t([name, fallback || labelMetaValue || name]);}-export function getAttributeValue(attribute: Attribute, descriptor: AttributeDescriptor | undefined, fallbackFormat?: string): any {- if (!attribute && !descriptor) {- return fallbackFormat || "";+export function getAttributeValueFormatter(attribute: Attribute | undefined, descriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined): ((value: any) => string) {++ let format = getMetaValue(MetaItemType.FORMAT, attribute, descriptor, valueDescriptor) as string;+ if (!format) {+ let valueType: string | undefined;+ if (attribute) {+ valueType = attribute.type! as string;+ } if (valueDescriptor) {+ valueType = valueDescriptor.valueType;+ } else if (descriptor) {+ valueDescriptor = descriptor.valueDescriptor as any;+ // noinspection SuspiciousTypeOfGuard+ if (typeof valueDescriptor === "string") {+ valueDescriptor = AssetModelUtil.getAttributeValueDescriptor(valueDescriptor);+ }+ if (valueDescriptor) {+ valueType = valueDescriptor.valueType;+ }+ }+ if (valueType) {+ format = i18next.t("attributeValueType." + valueType);+ }}- const format = getMetaValue(MetaItemType.FORMAT, attribute , undefined);- const valueType = attribute.type;- if (format) {- return i18next.t(format, { postProcess: "sprintf", sprintf: [attribute.value] });- } else if (attribute.value) {- return i18next.t(["attributeValueType." + valueType, fallbackFormat || "%s"], { postProcess: "sprintf", sprintf: [attribute.value] });- } else {- return attribute.value;++ return (value: any) => {+ return value === undefined || value === null ? "" : i18next.t((format ? [format, "%s"] : "%s"), { postProcess: "sprintf", sprintf: [value] });+ };+}++export function getAttributeValueFormatted(attribute: Attribute, descriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, fallback?: string): any {++ if (!attribute) {+ return fallback || "";+ }++ if (attribute.value === undefined || attribute.value === null) {+ return "";}++ return getAttributeValueFormatter(attribute, descriptor, valueDescriptor)(attribute.value);}/**@@ -306,7 +369,7 @@ export function updateAsset(asset: Asset, event: AttributeEvent): Asset {export function loadJs(url: string) {return new Promise((resolve, reject) => {- let script = document.createElement('script');+ const script = document.createElement('script');script.type = 'text/javascript';script.src = url;script.addEventListener('load', (e) => resolve(e), false);diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.tsindex 1329599eb..7dd4f9aa4 100644--- a/ui/component/or-asset-tree/src/index.ts+++ b/ui/component/or-asset-tree/src/index.ts@@ -1,7 +1,7 @@import {customElement, html, LitElement, property, PropertyValues, query, TemplateResult} from "lit-element";import "@openremote/or-input";import "@openremote/or-icon";-import {Asset, AssetQuery, AssetTreeNode, ClientRole, SharedEvent, EventIdentifier, AssetsEvent, AssetEvent, ReadAssetsEvent, AssetEventCause} from "@openremote/model";+import {Asset, AssetQuery, AssetTreeNode, ClientRole, SharedEvent, AssetsEvent, AssetEvent, AssetEventCause} from "@openremote/model";import "@openremote/or-translate";import {style} from "./style";import manager, {AssetModelUtil, OREvent, EventCallback, subscribe} from "@openremote/core";@@ -480,10 +480,12 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {}this._sendEventWithReply({- eventType: "read-assets",- assetQuery: query- } as ReadAssetsEvent)- .then((ev: SharedEvent & EventIdentifier) =>+ event: {+ eventType: "read-assets",+ assetQuery: query+ }+ })+ .then((ev) =>this._buildTreeNodes((ev as AssetsEvent).assets!, sortFunction));} else {this._buildTreeNodes(this.assets, sortFunction);diff --git a/ui/component/or-asset-viewer/package.json b/ui/component/or-asset-viewer/package.jsonindex 04e47796f..92bc56cac 100644--- a/ui/component/or-asset-viewer/package.json+++ b/ui/component/or-asset-viewer/package.json@@ -21,7 +21,6 @@"@openremote/or-translate": "^1.1.0","@openremote/or-panel": "^1.1.0","@openremote/or-table": "^1.1.0",- "@openremote/or-map": "^1.1.0","@openremote/or-chart": "^1.1.0","@openremote/rest": "^1.1.0","@openremote/or-mwc-components": "^1.1.0",diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.tsindex 099fe122d..19cd52633 100644--- a/ui/component/or-asset-viewer/src/index.ts+++ b/ui/component/or-asset-viewer/src/index.ts@@ -5,7 +5,6 @@ import "@openremote/or-attribute-input";import "@openremote/or-attribute-history";import "@openremote/or-chart";import "@openremote/or-table";-import "@openremote/or-map";import "@openremote/or-panel";import "@openremote/or-mwc-components/dist/or-mwc-dialog";import {OrTranslate, translate} from "@openremote/or-translate";@@ -14,7 +13,6 @@ import manager, {AssetModelUtil, subscribe, Util} from "@openremote/core";import {OrTable} from "@openremote/or-table";import {OrChartConfig, OrChartEvent} from "@openremote/or-chart";import {HistoryConfig, OrAttributeHistory, OrAttributeHistoryEvent} from "@openremote/or-attribute-history";-import {Type as MapType, Util as MapUtil} from "@openremote/or-map";import {Asset,AssetAttribute,@@ -23,7 +21,6 @@ import {Attribute,AttributeEvent,AttributeType,- MetaItem,MetaItemType,SharedEvent} from "@openremote/model";@@ -63,7 +60,6 @@ export interface AssetViewerConfig {propertyViewProvider?: (asset: Asset, property: string, value: any, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;attributeViewProvider?: (asset: Asset, attribute: Attribute, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;panelViewProvider?: (asset: Asset, attributes: Attribute[], panelName: string, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;- mapType?: MapType;historyConfig?: HistoryConfig;chartConfig?: OrChartConfig;}@@ -71,7 +67,6 @@ export interface AssetViewerConfig {export interface ViewerConfig {default?: AssetViewerConfig;assetTypes?: { [assetType: string]: AssetViewerConfig };- mapType?: MapType;historyConfig?: HistoryConfig;}@@ -180,7 +175,7 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Assconst options = historyAttrs.map((attr) => {const attributeDescriptor = AssetModelUtil.getAttributeDescriptorFromAsset(attr.name!);let label = Util.getAttributeLabel(attr, attributeDescriptor);- let unit = Util.getMetaValue(MetaItemType.UNIT_TYPE, attr, attributeDescriptor);+ const unit = Util.getMetaValue(MetaItemType.UNIT_TYPE, attr, attributeDescriptor);if(unit) {label = label + " ("+i18next.t(unit)+")";}@@ -257,60 +252,11 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Assconst 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 = viewerConfig.mapType || OrAssetViewer.DEFAULT_MAP_TYPE;- const lngLat = MapUtil.getLngLat(attribute);- const center = lngLat ? lngLat.toArray() : undefined;- const showOnMapMeta = Util.getFirstMetaItem(attribute, MetaItemType.SHOW_ON_DASHBOARD.urn!);- const attributeMetaChanged = async (value: string) => {- if (hostElement.shadowRoot) {-- if (attribute) {-- if(asset.id && asset.attributes && asset.attributes.location){-- const showOnMapMeta = Util.getFirstMetaItem(attribute, MetaItemType.SHOW_ON_DASHBOARD.urn!);- if(showOnMapMeta) {- showOnMapMeta.value = value;- } else {- const meta:MetaItem = {- name: MetaItemType.SHOW_ON_DASHBOARD.urn,- value: value- }-- if(attribute.meta){- attribute.meta.push(meta);- }- }- asset.attributes.location = {...attribute};- const response = await manager.rest.api.AssetResource.update(asset.id, asset);-- if (response.status !== 200) {- }- }--- }- }- };-content = html`- <style>- or-map {- border: #e5e5e5 1px solid;- }-- #location-map-input {- padding: 20px 0 0 0;- }- </style>- <or-map id="location-map" class="or-map" .center="${center}" type="${mapType}">- <or-map-marker-asset active .asset="${asset}"></or-map-marker-asset>- </or-map>- ${attribute.name === AttributeType.LOCATION.attributeName ? html`- <or-input id="location-map-input" type="${InputType.SWITCH}" @or-input-changed="${(evt: OrInputChangedEvent) => attributeMetaChanged(evt.detail.value)}" dense .value="${showOnMapMeta ? showOnMapMeta.value : undefined}" label="${i18next.t("showOnMap")}"></or-input>- ` : ``}- `;+ <div class="field">+ <or-attribute-input .assetType="${asset.type}" .attribute="${attribute}"></or-attribute-input>+ </div>+ `;}} else if (panelConfig && panelConfig.type === "group") {@@ -476,7 +422,7 @@ export function getAttributeTemplate(asset: Asset, attribute: AssetAttribute, ho}}return html`- <or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}" .label="${i18next.t(attribute.name!)}"></or-attribute-input>+ <or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}"}"></or-attribute-input>`;}@@ -521,7 +467,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_MAP_TYPE = MapType.VECTOR;public static DEFAULT_PANEL_TYPE: PanelType = "attribute";public static DEFAULT_VIEWER_CONFIG: AssetViewerConfig = {@@ -832,7 +777,6 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElemconfig.attributeViewProvider = assetConfig.attributeViewProvider || (this.config.default ? this.config.default.attributeViewProvider : undefined);config.panelViewProvider = assetConfig.panelViewProvider || (this.config.default ? this.config.default.panelViewProvider : undefined);config.propertyViewProvider = assetConfig.propertyViewProvider || (this.config.default ? this.config.default.propertyViewProvider : undefined);- config.mapType = assetConfig.mapType || this.config.mapType;config.historyConfig = assetConfig.historyConfig || this.config.historyConfig;}}diff --git a/ui/component/or-asset-viewer/tsconfig.json b/ui/component/or-asset-viewer/tsconfig.jsonindex 3f17c111f..c72451d02 100644--- a/ui/component/or-asset-viewer/tsconfig.json+++ b/ui/component/or-asset-viewer/tsconfig.json@@ -6,8 +6,7 @@"rootDir": "src"},"include": [- "./src",- "../or-map/@types"+ "./src"],"references": [{ "path": "../core" },@@ -18,9 +17,8 @@{ "path": "../or-table" },{ "path": "../or-translate" },{ "path": "../or-icon" },- { "path": "../or-map" },{ "path": "../or-attribute-input" },{ "path": "../or-attribute-history" },{ "path": "../or-mwc-components" }]-}\ No newline at end of file+}diff --git a/ui/component/or-attribute-input/package.json b/ui/component/or-attribute-input/package.jsonindex a5311f918..5b58f978b 100644--- a/ui/component/or-attribute-input/package.json+++ b/ui/component/or-attribute-input/package.json@@ -15,6 +15,7 @@"@openremote/core": "^1.1.0","@openremote/or-input": "^1.1.0","@openremote/or-translate": "^1.1.0",+ "@openremote/or-map": "^1.1.0","lit-element": "^2.2.1"},"devDependencies": {diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.tsindex 614aaaa2e..9bc4e686f 100644--- a/ui/component/or-attribute-input/src/index.ts+++ b/ui/component/or-attribute-input/src/index.ts@@ -2,7 +2,6 @@ import {css, customElement, html, LitElement, property, PropertyValues, query, Timport {i18next, translate} from "@openremote/or-translate";import {AssetAttribute,- Attribute,AttributeDescriptor,AttributeEvent,AttributeRef,@@ -15,150 +14,75 @@ import {import manager, {AssetModelUtil, subscribe, Util} from "@openremote/core";import "@openremote/or-input";import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-input";--export function getAttributeValueTemplate(- assetType: string | undefined,- attribute: Attribute,- readonly: boolean | undefined,- disabled: boolean | undefined,- valueChangedCallback: (value: any) => void,- customProvider?: (assetType: string | undefined, attribute: Attribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean | undefined, disabled: boolean | undefined) => ((value: any) => TemplateResult) | undefined,- forceInputType?: InputType,- labelOverride?: string) {-- let template: ((value: any) => TemplateResult) | undefined;-- if (!attribute) {- return () => html``;+import "@openremote/or-map";+import {Util as MapUtil, LngLat, getMarkerIconAndColorFromAssetType, OrMapClickedEvent, MapEventDetail} from "@openremote/or-map";++export class OrAttributeInputChangedEvent extends CustomEvent<OrAttributeInputChangedEventDetail> {++ public static readonly NAME = "or-attribute-input-changed";++ constructor(value?: any, previousValue?: any) {+ super(OrAttributeInputChangedEvent.NAME, {+ detail: {+ value: value,+ previousValue: previousValue+ },+ bubbles: true,+ composed: true+ });}+}- let attributeDescriptor: AttributeDescriptor | undefined;- let valueDescriptor: AttributeValueDescriptor | undefined;-- attributeDescriptor = AssetModelUtil.getAttributeDescriptorFromAsset(attribute.name!, assetType);- valueDescriptor = AssetModelUtil.getAttributeValueDescriptorFromAsset(attributeDescriptor && attributeDescriptor.valueDescriptor ? attributeDescriptor.valueDescriptor.name : attribute ? attribute.type as string : undefined, assetType, attribute.name);+export interface OrAttributeInputChangedEventDetail {+ value?: any;+ previousValue?: any;+}- if (customProvider) {- template = customProvider(assetType, attribute, attributeDescriptor, valueDescriptor, (newValue: any) => valueChangedCallback(newValue), readonly, disabled);+declare global {+ export interface HTMLElementEventMap {+ [OrAttributeInputChangedEvent.NAME]: OrAttributeInputChangedEvent;}+}- if (!template) {- let inputType: InputType | undefined;- let step: number | undefined;- let min: number | undefined;- let max: number | undefined;- let ro: boolean | undefined;- let label: string | undefined;- let unit: string | undefined;- let options: any | undefined;+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;- if (valueDescriptor) {+export const GeoJsonPointInputTemplateProvider: AttributeInputCustomProvider = (assetType, attribute, attributeDescriptor, valueDescriptor, valueChangeNotifier, readonly, disabled, label) => (value: any) => {+ let pos: LngLat | undefined;+ let center: number[] | undefined;+ if (value) {+ pos = MapUtil.getLngLat(value);+ center = pos ? pos.toArray() : undefined;+ }+ const iconAndColor = getMarkerIconAndColorFromAssetType(assetType);- switch (valueDescriptor.name) {- case AttributeValueType.GEO_JSON_POINT.name:- break;- case AttributeValueType.BOOLEAN.name:- case AttributeValueType.SWITCH_TOGGLE.name:- inputType = InputType.SWITCH;- break;- case AttributeValueType.NUMBER.name:- inputType = InputType.NUMBER;- break;- case AttributeValueType.STRING.name:- inputType = InputType.TEXT;- break;- case AttributeValueType.OBJECT.name:- case AttributeValueType.ARRAY.name:- inputType = InputType.JSON;- break;- case AttributeValueType.BRIGHTNESS.name:- inputType = InputType.NUMBER;- step = 1;- break;- default:- // Use value type- switch (valueDescriptor.valueType) {- case ValueType.STRING:- inputType = InputType.TEXT;- break;- case ValueType.NUMBER:- inputType = InputType.NUMBER;- break;- case ValueType.BOOLEAN:- inputType = InputType.SWITCH;- break;- default:- inputType = InputType.JSON;- break;- }- break;+ const clickHandler = (mapClickDetail: MapEventDetail) => {+ if (!readonly && !disabled) {+ const geoJsonPoint = MapUtil.getGeoJSONPoint(mapClickDetail.lngLat);+ if (valueChangeNotifier) {+ valueChangeNotifier(geoJsonPoint);}}+ };- if (forceInputType) {- inputType = forceInputType;- }-- if (!inputType) {- const currentValue = attribute.value;-- if (currentValue) {- if (typeof currentValue === "number") {- inputType = InputType.NUMBER;- } else if (typeof currentValue === "string") {- inputType = InputType.TEXT;- } else if (typeof currentValue === "boolean") {- inputType = InputType.SWITCH;- } else {- inputType = InputType.JSON;- }+ return html`+ <style>+ or-map {+ border: #e5e5e5 1px solid;}- }-- if (inputType) {- // TODO: Update to use 'effective' meta so not dependent on meta items being defined on the asset itself- min = Util.getMetaValue(MetaItemType.RANGE_MIN, attribute, attributeDescriptor) as number;- max = Util.getMetaValue(MetaItemType.RANGE_MAX, attribute, attributeDescriptor) as number;- label = labelOverride !== undefined ? labelOverride : Util.getAttributeLabel(attribute, attributeDescriptor);- ro = readonly === undefined ? Util.getMetaValue(MetaItemType.READ_ONLY, attribute, attributeDescriptor) : readonly;- unit = Util.getMetaValue(MetaItemType.UNIT_TYPE, attribute, attributeDescriptor);- options = Util.getMetaValue(MetaItemType.ALLOWED_VALUES, attribute, attributeDescriptor);- if(unit) {- label = label + " ("+i18next.t(unit)+")";- }- if (inputType === InputType.TEXT && options && Array.isArray(options) && options.length > 0) {- inputType = InputType.SELECT;- }-- const getValue = (value: any) => {- if (inputType === InputType.JSON && value !== null && typeof(value) !== "string") {- value = JSON.stringify(value, null, 2);- }- return Util.getAttributeValue(attribute, attributeDescriptor) ? Util.getAttributeValue(attribute, attributeDescriptor) : value;- };-- const setValue = (value: any) => {- if (inputType === InputType.JSON && value !== null && typeof(value) !== "string") {- if (typeof(value) === "string") {- value = JSON.parse(value);- }- }- valueChangedCallback(value);- };-- template = (value) => html`<or-input .type="${inputType}" .label="${label}" .value="${getValue(value)}" .allowedValues="${options}" .min="${min}" .max="${max}" .options="${options}" .readonly="${readonly || ro}" .disabled="${disabled}" @or-input-changed="${(e: OrInputChangedEvent) => setValue(e.detail.value)}"></or-input>`;- } else {- template = () => html``;- }- }-- return template;+ </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}" .color="${iconAndColor ? iconAndColor.color : undefined}"></or-map-marker>+ </or-map>+ `;}+const DEFAULT_TIMEOUT = 5000;+// TODO: Add support for attribute not found and attribute deletion/addition@customElement("or-attribute-input")export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitElement)) {+ // language=CSSstatic get styles() {return css`:host {@@ -168,7 +92,20 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEor-input {width: 100%;}-++ #wrapper {+ display: flex;+ position: relative;+ }++ #scrim {+ position: absolute;+ left: 0;+ top: 0;+ right: 0;+ bottom: 0;+ opacity: 0.5;+ }`;}@@ -178,6 +115,12 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE@property({type: Object})public attributeRef?: AttributeRef;+ @property({type: Object})+ public attributeDescriptor?: AttributeDescriptor;++ @property({type: Object})+ public attributeValueDescriptor?: AttributeValueDescriptor;+@property({type: String})public assetType?: string;@@ -188,116 +131,297 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEpublic disabled?: boolean;@property({type: Boolean})- public disableSubscribe: boolean = false;+ public readonly?: boolean;- @property({type: Boolean})- public disableWrite: boolean = false;+ @property()+ public value?: any;++ @property()+ public inputType?: InputType;@property({type: Boolean})- public readonly?: boolean;+ public disableSubscribe: boolean = false;- public customProvider?: (assetType: string | undefined, attribute: Attribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean | undefined, disabled: boolean | undefined) => ((value: any) => TemplateResult) | undefined;+ @query("#loading")+ protected _orInput!: OrInput;- protected _loading: boolean = false;- protected _invalid: boolean = false;- protected _template?: (value: any) => TemplateResult;+ @property()+ protected _attributeEvent?: AttributeEvent;- @query("#or-input")- protected _input!: OrInput;+ public customProvider?: AttributeInputCustomProvider;+ public writeTimeout?: number = DEFAULT_TIMEOUT;++ protected _template?: (value: any) => TemplateResult;+ protected _attributeDescriptor?: AttributeDescriptor;+ protected _attributeValueDescriptor?: AttributeValueDescriptor;+ protected _inputType?: InputType;+ protected _step?: number;+ protected _min?: any;+ protected _max?: any;+ protected _label?: string;+ protected _unit?: string;+ protected _options?: any;+ protected _readonly?: boolean;+ protected _disabled?: boolean;+ protected _valueFormatter?: (value: any) => any;+ protected _writeTimeoutHandler?: number;++ public disconnectedCallback() {+ super.disconnectedCallback();+ if (this._writeTimeoutHandler) {+ window.clearTimeout(this._writeTimeoutHandler);+ this._writeTimeoutHandler = undefined;+ }+ }public shouldUpdate(_changedProperties: PropertyValues): boolean {const shouldUpdate = super.shouldUpdate(_changedProperties);- if (_changedProperties.has("attribute")- || _changedProperties.has("attributeRef")+ let updateSubscribedRefs = false;+ let updateDescriptors = false;++ if (_changedProperties.has("disableSubscribe")) {+ updateSubscribedRefs = true;+ }++ if (_changedProperties.has("attributeDescriptor")+ || _changedProperties.has("attributeValueDescriptor")|| _changedProperties.has("assetType")) {+ updateDescriptors = true;+ }- if (!this.attribute) {- this._loading = true;- if (this.attributeRef) {- manager.rest.api.AssetResource.queryAssets({- ids: [this.attributeRef.entityId!],- select: {- attributes: [this.attributeRef.attributeName!],- excludePath: true,- excludeParentInfo: true- }- }).then((response) => {- if (response.data) {- this.assetType = response.data[0].type;- this.attribute = Util.getAssetAttribute(response.data[0], this.attributeRef!.attributeName!);- }- });- } else {- this._invalid = true;- }- } else {- this._invalid = false;- this._template = getAttributeValueTemplate(this.assetType, this.attribute, this.readonly, this.disabled, (value) => this.onValueChange(value), this.customProvider);- }+ if (_changedProperties.has("attribute") || _changedProperties.has("attributeRef")) {+ updateSubscribedRefs = true;+ updateDescriptors = true;+ }++ if (updateDescriptors) {+ this._updateDescriptors();+ }++ if (updateSubscribedRefs) {+ this._updateSubscribedRefs();+ }++ if (this._template+ && (_changedProperties.has("disabled")+ || _changedProperties.has("readonly")+ || _changedProperties.has("label"))) {+ this._updateTemplate();}return shouldUpdate;}- public updated(_changedProperties: PropertyValues): void {- super.updated(_changedProperties);+ protected _updateSubscribedRefs(): void {+ this._attributeEvent = undefined;- if (_changedProperties.has("attribute") || _changedProperties.has("disabledSubscribe")) {- if (this.attribute && !this.disableSubscribe) {- this._loading = true;- super.attributeRefs = [{entityId: this.attribute!.assetId!, attributeName: this.attribute!.name!}];- } else {- super.attributeRefs = undefined;- }+ if (this.disableSubscribe) {+ this.attributeRefs = undefined;+ } else {+ const attributeRef = this.attribute ? {entityId: this.attribute.assetId!, attributeName: this.attribute.name!} : this.attributeRef;+ this.attributeRefs = attributeRef ? [attributeRef] : undefined;}}- public render() {- if (this._invalid) {- return html`- <div>INVALID</div>- `;+ protected _updateDescriptors(): void {++ this._attributeValueDescriptor = undefined;+ this._attributeDescriptor = undefined;++ if (this.attributeDescriptor) {+ this._attributeDescriptor = this.attributeDescriptor;+ } else if (this.attribute || this.attributeRef) {+ const attrName = this.attribute ? this.attribute.name! : this.attributeRef!.attributeName!;+ this._attributeDescriptor = AssetModelUtil.getAttributeDescriptorFromAsset(attrName, this.assetType);+ }++ if (this.attributeValueDescriptor) {+ this._attributeValueDescriptor = this.attributeValueDescriptor;+ } else if (this._attributeDescriptor) {+ this._attributeValueDescriptor = this._attributeDescriptor.valueDescriptor;+ } else if (this.attribute) {+ this._attributeValueDescriptor = AssetModelUtil.getAttributeValueDescriptorFromAsset(this.attribute ? this.attribute.type as string : undefined, this.assetType, this._attributeDescriptor ? this._attributeDescriptor!.attributeName : undefined);}- if (this._loading) {- return html`- <div>LOADING</div>- `;+ this._updateTemplate();+ }++ protected _updateTemplate(): void {+ this._template = undefined;+ this._inputType = undefined;+ this._step = undefined;+ this._min = undefined;+ this._max = undefined;+ this._label = undefined;+ this._unit = undefined;+ this._options = undefined;+ this._disabled = undefined;+ this._readonly = undefined;+ this._inputType = undefined;+ this._valueFormatter = undefined;++ if (this.customProvider) {+ this._template = this.customProvider(this.assetType, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor, (v) => this._onValueChange(v), this.readonly, this.disabled, this.label);}if (this._template) {- return html`${this._template(this.attribute!.value)}`;+ return;}++ if (this.inputType) {+ this._inputType = this.inputType;+ } 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._onValueChange(v), this.readonly, this.disabled, this.label);+ return;+ case AttributeValueType.BOOLEAN.name:+ case AttributeValueType.SWITCH_TOGGLE.name:+ this._inputType = InputType.SWITCH;+ break;+ case AttributeValueType.NUMBER.name:+ this._inputType = InputType.NUMBER;+ break;+ case AttributeValueType.STRING.name:+ this._inputType = InputType.TEXT;+ break;+ case AttributeValueType.OBJECT.name:+ case AttributeValueType.ARRAY.name:+ this._inputType = InputType.JSON;+ break;+ case AttributeValueType.BRIGHTNESS.name:+ this._inputType = InputType.NUMBER;+ this._step = 1;+ break;+ default:+ // Use value type+ switch (this._attributeValueDescriptor.valueType) {+ case ValueType.STRING:+ this._inputType = InputType.TEXT;+ break;+ case ValueType.NUMBER:+ this._inputType = InputType.NUMBER;+ break;+ case ValueType.BOOLEAN:+ this._inputType = InputType.SWITCH;+ break;+ default:+ this._inputType = InputType.JSON;+ break;+ }+ break;+ }+ }++ if (!this._inputType && (this.attribute || this.value)) {+ const currentValue = this.attribute ? this.attribute.value : this.value;++ if (currentValue !== undefined && currentValue !== null) {+ if (typeof currentValue === "number") {+ this._inputType = InputType.NUMBER;+ } else if (typeof currentValue === "string") {+ this._inputType = InputType.TEXT;+ } else if (typeof currentValue === "boolean") {+ this._inputType = InputType.SWITCH;+ } else {+ this._inputType = InputType.JSON;+ }+ }+ }++ if (this._inputType) {+ this._min = Util.getMetaValue(MetaItemType.RANGE_MIN, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor) as number;+ 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);+ this._label = this.label !== undefined ? this.label : Util.getAttributeLabel(this.attribute, this._attributeDescriptor) + (this._unit ? " (" + i18next.t(this._unit) + ")" : "");+ 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) {+ this._inputType = InputType.SELECT;+ }++ switch (this._inputType) {+ case InputType.NUMBER:+ case InputType.TEXT:+ case InputType.COLOUR:+ case InputType.TELEPHONE:+ this._valueFormatter = Util.getAttributeValueFormatter(this.attribute, this._attributeDescriptor, this._attributeValueDescriptor);+ }+ }+ }++ public render() {++ // Check if attribute hasn't been loaded yet or pending write+ const loading = this.attributeRefs && !this._attributeEvent;+ let content: TemplateResult | string | undefined = "";++ if (!loading) {+ let value = this.getValue();++ if (this._template) {+ content = this._template(value);+ } else {++ if (!this._inputType) {+ content = html`<div>INVALID</div>`;+ }++ if (this._valueFormatter) {+ value = this._valueFormatter(value);+ }++ content = html`<or-input id="input" .type="${this._inputType}" .label="${this._label}" .value="${value}" .allowedValues="${this._options}" .min="${this._min}" .max="${this._max}" .options="${this._options}" .readonly="${this._readonly}" .disabled="${this._disabled}" @or-input-changed="${(e: OrInputChangedEvent) => {+ this._onValueChange(e.detail.value);+ e.stopPropagation()+ }}"></or-input>`;+ }+ }++ return html`+ <div id="wrapper">+ ${content}+ ${loading || this._writeTimeoutHandler+ ? html`<div id="scrim"><progress class="pure-material-progress-circular"></progress></div>`+ : ``}+ </div>+ `;+ }++ protected getValue(): any {+ return this._attributeEvent ? this._attributeEvent.attributeState!.value : this.value;}public _onEvent(event: SharedEvent) {if (event.eventType !== "attribute") {return;}- const attributeEvent = event as AttributeEvent;++ this._attributeEvent = event as AttributeEvent;const oldValue = this.attribute ? this.attribute.value : undefined;if (this.attribute) {- this.attribute.value = attributeEvent.attributeState!.value;+ this.attribute.value = this._attributeEvent.attributeState!.value;this.attribute.valueTimestamp = event.timestamp;- this._loading = false;super.requestUpdate();}- this.dispatchEvent(new OrInputChangedEvent(attributeEvent.attributeState!.value, oldValue));+ this.dispatchEvent(new OrAttributeInputChangedEvent(this._attributeEvent.attributeState!.value, oldValue));}- protected onValueChange(newValue: any) {- if (this.attribute || this.attributeRef) {+ protected _onValueChange(newValue: any) {+ const oldValue = this.getValue();- let attributeRef = this.attributeRef;+ if (this.readonly || this._readonly) {+ return;+ }- if (!this.attributeRef) {- attributeRef = {- entityId: this.attribute!.assetId,- attributeName: this.attribute!.name- };- }+ // Check if this control is linked to the backend via asset-mixin; if so send an update and wait for the+ // updated attribute event to come back through the system or timeout and reset the value+ if (this.attributeRefs) {+ const attributeRef = this.attributeRefs[0];super._sendEvent({eventType: "attribute",@@ -306,6 +430,15 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEvalue: newValue}} as AttributeEvent);++ // Clear the last attribute event which will cause loading state on render+ this._writeTimeoutHandler = window.setTimeout(() => this._onWriteTimeout(), this.writeTimeout);+ } else {+ this.dispatchEvent(new OrAttributeInputChangedEvent(newValue, oldValue));}}++ protected _onWriteTimeout() {+ this._writeTimeoutHandler = undefined;+ }}diff --git a/ui/component/or-attribute-input/tsconfig.json b/ui/component/or-attribute-input/tsconfig.jsonindex 405ac3761..0bc413e36 100644--- a/ui/component/or-attribute-input/tsconfig.json+++ b/ui/component/or-attribute-input/tsconfig.json@@ -6,11 +6,13 @@"rootDir": "src"},"include": [- "./src"+ "./src",+ "../or-map/@types"],"references": [{ "path": "../core" },{ "path": "../or-translate" },+ { "path": "../or-map" },{ "path": "../or-input" }]-}\ No newline at end of file+}diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.tsindex a2fa6296d..5d8b6229b 100644--- a/ui/component/or-input/src/index.ts+++ b/ui/component/or-input/src/index.ts@@ -1,4 +1,4 @@-import {css, customElement, html, LitElement, property, PropertyValues, TemplateResult, unsafeCSS, query} from "lit-element";+import {css, customElement, html, LitElement, property, PropertyValues, TemplateResult, unsafeCSS} from "lit-element";import {classMap} from "lit-html/directives/class-map";import {ifDefined} from "lit-html/directives/if-defined";import {MDCTextField} from "@material/textfield";@@ -242,7 +242,7 @@ export class OrInput extends LitElement {public max?: any;@property()- public min?: HTMLInputElement;+ public min?: any;@property({type: Number})public step?: number;@@ -547,45 +547,48 @@ export class OrInput extends LitElement {case InputType.TEXT:case InputType.TEXTAREA:case InputType.JSON: {- let val = this.value;+ const valMinMax: [any, any, any] = [this.value, this.min, this.max];++ if (valMinMax.find((v) => v !== undefined && v !== null && typeof(v) !== "string") !== undefined) {++ let format: string | undefined;- if (typeof(val) !== "string") {switch (this.type) {case InputType.TIME:- if (val instanceof Date) {- val = moment(val).format("HH:mm");- }+ format = "HH:mm";break;case InputType.DATE:- if (val instanceof Date) {- val = moment(val).format("YYYY-MM-DD");- }+ format = "YYYY-MM-DD";break;case InputType.WEEK:- if (val instanceof Date) {- val = moment(val).format("YYYY-")+"W"+moment(val).format("WW");- }- break;+ format = "YYYY-Www";+ break;case InputType.MONTH:- if (val instanceof Date) {- val = moment(val).format("YYYY-MM");- }+ format = "YYYY-MM";break;case InputType.DATETIME:- if (val instanceof Date) {- val = moment(val).format("YYYY-MM-DDTHH:mm");- } else if (typeof(val) === "number") {- const offset = (new Date()).getTimezoneOffset() * 60000;- val = moment(new Date(val - offset)).format("YYYY-MM-DDTHH:mm");- }+ format = "YYYY-MM-DDTHH:mm";break;case InputType.JSON:- val = val !== undefined && val !== null ? JSON.stringify(val, null, 2) : "";+ valMinMax[0] = valMinMax[0] !== undefined && valMinMax[0] !== null ? (typeof valMinMax[0] === "string" ? valMinMax[0] : JSON.stringify(valMinMax[0], null, 2)) : "";break;default:- val = val !== undefined && val !== null ? val : "";+ valMinMax[0] = valMinMax[0] !== undefined && valMinMax[0] !== null ? valMinMax[0] : "";break;}++ if (format) {+ valMinMax.forEach((val, i) => {+ if (typeof(val) === "number") {+ const offset = (new Date()).getTimezoneOffset() * 60000;+ val = new Date(val - offset);+ }+ if (val instanceof Date) {+ val = moment(val).format(format);+ }+ valMinMax[i] = val;+ });+ }}const classes = {@@ -616,7 +619,7 @@ export class OrInput extends LitElement {maxlength="${ifDefined(this.maxLength)}"rows="${this.rows ? this.rows : 5}"cols="${ifDefined(this.cols)}"- aria-label="${ifDefined(this.label)}">${val ? val : ""}</textarea>+ aria-label="${ifDefined(this.label)}">${valMinMax[0] ? valMinMax[0] : ""}</textarea>${this.renderOutlined(labelTemplate)}` :html`<input type="${this.type}" id="elem" class="mdc-text-field__input"@@ -624,9 +627,9 @@ export class OrInput extends LitElement {?readonly="${this.readonly}"?disabled="${this.disabled}"@change="${(e: Event) => this.onValueChange((e.target as HTMLInputElement), (e.target as HTMLInputElement).value)}"- .value="${val !== null && val !== undefined ? val : ""}"- min="${ifDefined(this.min)}"- max="${ifDefined(this.max)}"+ .value="${valMinMax[0] !== null && valMinMax[0] !== undefined ? valMinMax[0] : ""}"+ min="${ifDefined(valMinMax[1])}"+ max="${ifDefined(valMinMax[2])}"step="${this.step ? this.step : "any"}"aria-label="${ifDefined(this.label)}"minlength="${ifDefined(this.minLength)}"diff --git a/ui/component/or-map/@types/mapbox.js.d.ts b/ui/component/or-map/@types/mapbox.js/index.d.tssimilarity index 100%rename from ui/component/or-map/@types/mapbox.js.d.tsrename to ui/component/or-map/@types/mapbox.js/index.d.tsdiff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.tsindex 16d92b704..52ab38332 100644--- a/ui/component/or-map/src/index.ts+++ b/ui/component/or-map/src/index.ts@@ -1,4 +1,4 @@-import manager, {EventCallback, OREvent} from "@openremote/core";+import manager, {EventCallback, OREvent, MapType} from "@openremote/core";import {FlattenedNodesObserver} from "@polymer/polymer/lib/utils/flattened-nodes-observer.js";import {CSSResult, customElement, html, LitElement, property, PropertyValues, query} from "lit-element";import {LngLat, LngLatBoundsLike, LngLatLike} from "mapbox-gl";@@ -8,15 +8,10 @@ import {OrMapMarker, OrMapMarkerChangedEvent} from "./markers/or-map-marker";import * as Util from "./util";// Re-exports-export {Util};+export {Util, LngLat};export * from "./markers/or-map-marker";export * from "./markers/or-map-marker-asset";-export enum Type {- VECTOR = "VECTOR",- RASTER = "RASTER"-}-export interface ViewSettings {"center": LngLatLike;"bounds": LngLatBoundsLike;@@ -26,21 +21,16 @@ export interface ViewSettings {"boxZoom": boolean;}-export interface MapLoadedEventDetail {--}-export interface MapEventDetail {- lngLat: LngLatLike;+ lngLat: LngLat;}-export class OrMapLoadedEvent extends CustomEvent<MapLoadedEventDetail> {+export class OrMapLoadedEvent extends CustomEvent<void> {public static readonly NAME = "or-map-loaded";constructor() {super(OrMapLoadedEvent.NAME, {- detail: {},bubbles: true,composed: true});@@ -51,7 +41,7 @@ export class OrMapClickedEvent extends CustomEvent<MapEventDetail> {public static readonly NAME = "or-map-clicked";- constructor(lngLat: LngLatLike) {+ constructor(lngLat: LngLat) {super(OrMapClickedEvent.NAME, {detail: {lngLat: lngLat@@ -75,7 +65,7 @@ export class OrMap extends LitElement {public static styles = style;@property({type: String})- public type: Type = Type.VECTOR;+ public type: MapType = manager.mapType;protected _markerStyles: string[] = [];@@ -165,6 +155,26 @@ export class OrMap extends LitElement {manager.removeListener(this.onManagerEvent);}+ protected render() {+ return html`+ <div id="container">+ <div id="map"></div>+ <slot></slot>+ <a id="openremote" href="https://openremote.io/" target="_blank">+ <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAAABGdBTUEAAYagMeiWXwAAAAJiS0dEAP+Hj8y/AAAESUlEQVRIx5XVbWzdZRnH8c//f07POe36sK7SrYXZjYGzbBokOqd4QtKATdnMDFFSkoFzmWGRQOAFSoYnsBSzxBdmGsN4Y7LEFwZkUdHpDoja/AnJjBvp1sm2upW5PtAV+zBS+7Tz//tiLe0emPF+d9/39fvmunJf9+8K3HBF1drFzurVn5+5XkTwPwBNOt1s0pCjDnnT+Xzy/wOa5jaXnLLfLwzlF0WENwaYckyvUTHS1tnjl+6JFqk+JoMOqqy2JqjPVpXP1k7U1+Ty8paBPk97NX/pYwEdgZUetNkdlirDrHGnyv6y5r3lm4M2WVzwpJfz8XUBHTntnrJO6qqLWE9u/125zBNq0WebN/PXAjqq/cBOVWDasCEsd5MsmEzt/3xP+S6fwNsezPdfBejI6fCEDMa95oAT/t31pVxDQ6p6oy2WYSb18w0D2V3Klez2w3y8CNAR2G6vShxXUCxMkXLvS7Y6E/5+3emaJ92JqezzG+8M2nHW/flTi59xladU4phtfluYgnsDWUt8Nv7+8UfO73UUuenvDLxuCKu0RQt90BFo14wxzzpamD8uExtHSsu5HSP7XMCtZ5uTPyO0SdVCBlXahHjNG4WFrGY9Y4tXzODL7zb7NYJS64eHzWK92xYAa9yBKa8Wphf0xaQ4XOz0qF9JhMnXh//mIm4dnDSMOusWALepwQUnrm2t4pi9hrGyP+ccloxV6kOZFemoWi2mOpclaQycqGlt9R8XHS/GixinnVWvbDpjDEEpNpdnWrtd+HvZWzMQT9xjj1iXzUau6MPS9X9NKOeTmqzPpZWwfMkEKnza2ivimqxCKZjQa9BMmFI2D+gxibql4z7EiobYOSy1o7V6Xt1aYacGvD/7lse1+GZ9t0Zc8kHaGcOa1K6o+FePL1iy7K7wYHy70FZa9+qVWOm7tgslfpecKcy46GS0xXKM6g6d14VU+RfTnRJ8Y223w8j4tkMOOeR1j6nAMT8tzkCUcvlbn3ImbJn0RyWC+1af1Iv6ukcbf+aIRKDR3b5ipVCiy+PenaupWRsSfzCWim0ftUmdiqrJwWLpbmk3196UfXG0X6NKIWKDXva0I0UQZT2nRaDfc/mhgCj0PS9ImZzefbg5fliIvuTA++/0ZaYDTDqqpzhn6lHoW36iSuLHnslfCiBqdMBGDI6/0LUhfkgGiWFbC29c+epRaJMX3YJuD+R75l15wG4DaKh5dsPJsj0GXLaawavkWY/MyUcU/JOPHCkK7fAjNZiIf/PeX/vWx1814muF0Y/EKWs95mFVuKhgX352EYAoY5vnNSDRF/9p/MgHfQ2dldNIqbPeJm2aBBix20vzg26RpUUpLfb43FxZU4YMmEJGoxXKQeIfCg4uzMkrTDVitZ0ecst1B05i0Cv26Vk8H68JjFKabXa/Zkul5w5Lxp120EHdlyu/AQCiQI1P+YxaGcwY1+20kasnM/wXCa5/Ik1hKTEAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTktMDgtMjBUMTU6MTc6NTUrMDA6MDCwJSdSAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE5LTA4LTIwVDE1OjE3OjU1KzAwOjAwwXif7gAAAABJRU5ErkJggg==" />+ </a>+ </div>+ `;+ }++ protected updated(changedProperties: PropertyValues) {+ super.updated(changedProperties);++ if (changedProperties.has("center") || changedProperties.has("zoom")) {+ this.flyTo(this.center, this.zoom);+ }+ }+public reloadMap() {this._loaded = false;this.loadMap();@@ -261,21 +271,7 @@ export class OrMap extends LitElement {}});}---- protected render() {- return html`- <div id="container">- <div id="map"></div>- <slot></slot>- <a id="openremote" href="https://openremote.io/" target="_blank">- <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J/AAAABGdBTUEAAYagMeiWXwAAAAJiS0dEAP+Hj8y/AAAESUlEQVRIx5XVbWzdZRnH8c//f07POe36sK7SrYXZjYGzbBokOqd4QtKATdnMDFFSkoFzmWGRQOAFSoYnsBSzxBdmGsN4Y7LEFwZkUdHpDoja/AnJjBvp1sm2upW5PtAV+zBS+7Tz//tiLe0emPF+d9/39fvmunJf9+8K3HBF1drFzurVn5+5XkTwPwBNOt1s0pCjDnnT+Xzy/wOa5jaXnLLfLwzlF0WENwaYckyvUTHS1tnjl+6JFqk+JoMOqqy2JqjPVpXP1k7U1+Ty8paBPk97NX/pYwEdgZUetNkdlirDrHGnyv6y5r3lm4M2WVzwpJfz8XUBHTntnrJO6qqLWE9u/125zBNq0WebN/PXAjqq/cBOVWDasCEsd5MsmEzt/3xP+S6fwNsezPdfBejI6fCEDMa95oAT/t31pVxDQ6p6oy2WYSb18w0D2V3Klez2w3y8CNAR2G6vShxXUCxMkXLvS7Y6E/5+3emaJ92JqezzG+8M2nHW/flTi59xladU4phtfluYgnsDWUt8Nv7+8UfO73UUuenvDLxuCKu0RQt90BFo14wxzzpamD8uExtHSsu5HSP7XMCtZ5uTPyO0SdVCBlXahHjNG4WFrGY9Y4tXzODL7zb7NYJS64eHzWK92xYAa9yBKa8Wphf0xaQ4XOz0qF9JhMnXh//mIm4dnDSMOusWALepwQUnrm2t4pi9hrGyP+ccloxV6kOZFemoWi2mOpclaQycqGlt9R8XHS/GixinnVWvbDpjDEEpNpdnWrtd+HvZWzMQT9xjj1iXzUau6MPS9X9NKOeTmqzPpZWwfMkEKnza2ivimqxCKZjQa9BMmFI2D+gxibql4z7EiobYOSy1o7V6Xt1aYacGvD/7lse1+GZ9t0Zc8kHaGcOa1K6o+FePL1iy7K7wYHy70FZa9+qVWOm7tgslfpecKcy46GS0xXKM6g6d14VU+RfTnRJ8Y223w8j4tkMOOeR1j6nAMT8tzkCUcvlbn3ImbJn0RyWC+1af1Iv6ukcbf+aIRKDR3b5ipVCiy+PenaupWRsSfzCWim0ftUmdiqrJwWLpbmk3196UfXG0X6NKIWKDXva0I0UQZT2nRaDfc/mhgCj0PS9ImZzefbg5fliIvuTA++/0ZaYDTDqqpzhn6lHoW36iSuLHnslfCiBqdMBGDI6/0LUhfkgGiWFbC29c+epRaJMX3YJuD+R75l15wG4DaKh5dsPJsj0GXLaawavkWY/MyUcU/JOPHCkK7fAjNZiIf/PeX/vWx1814muF0Y/EKWs95mFVuKhgX352EYAoY5vnNSDRF/9p/MgHfQ2dldNIqbPeJm2aBBix20vzg26RpUUpLfb43FxZU4YMmEJGoxXKQeIfCg4uzMkrTDVitZ0ecst1B05i0Cv26Vk8H68JjFKabXa/Zkul5w5Lxp120EHdlyu/AQCiQI1P+YxaGcwY1+20kasnM/wXCa5/Ik1hKTEAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTktMDgtMjBUMTU6MTc6NTUrMDA6MDCwJSdSAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE5LTA4LTIwVDE1OjE3OjU1KzAwOjAwwXif7gAAAABJRU5ErkJggg==" />- </a>- </div>- `;- }}export * from "./markers/or-map-marker";-export * from "./markers/or-map-marker-asset";\ No newline at end of file+export * from "./markers/or-map-marker-asset";diff --git a/ui/component/or-map/src/mapwidget.ts b/ui/component/or-map/src/mapwidget.tsindex 6c7228311..4caacad69 100644--- a/ui/component/or-map/src/mapwidget.ts+++ b/ui/component/or-map/src/mapwidget.ts@@ -1,8 +1,10 @@-import manager from "@openremote/core";+// tslint:disable-next-line:no-reference+///<reference path="../@types/mapbox.js/index.d.ts" />+import manager, {MapType} from "@openremote/core";import {LngLatLike, Map as MapGL, MapboxOptions as OptionsGL, Marker as MarkerGL, Style as StyleGL, LngLat,MapMouseEvent} from "mapbox-gl";import L, {Map as MapJS, MapOptions as OptionsJS, Marker as MarkerJS} from "mapbox.js";-import {OrMapClickedEvent, OrMapLoadedEvent, Type, ViewSettings} from "./index";+import {OrMapClickedEvent, OrMapLoadedEvent, ViewSettings} from "./index";import {OrMapMarker} from "./markers/or-map-marker";@@ -18,7 +20,7 @@ const metersToPixelsAtMaxZoom = (meters:number, latitude:number) =>export class MapWidget {protected _mapJs?: MapJS;protected _mapGl?: MapGL;- protected _type: Type;+ protected _type: MapType;protected _styleParent: Node;protected _mapContainer: HTMLElement;protected _loaded: boolean = false;@@ -29,7 +31,7 @@ export class MapWidget {protected _zoom?: number;protected _clickHandlers: Map<OrMapMarker, (ev: MouseEvent) => void> = new Map();- constructor(type: Type, styleParent: Node, mapContainer: HTMLElement) {+ constructor(type: MapType, styleParent: Node, mapContainer: HTMLElement) {this._type = type;this._styleParent = styleParent;this._mapContainer = mapContainer;@@ -40,7 +42,7 @@ export class MapWidget {this._center = getLngLat(center);switch (this._type) {- case Type.RASTER:+ case MapType.RASTER:if (this._mapJs) {const latLng = getLatLng(this._center) || (this._viewSettings ? getLatLng(this._viewSettings.center) : undefined);if (latLng) {@@ -48,7 +50,7 @@ export class MapWidget {}}break;- case Type.VECTOR:+ case MapType.VECTOR:if (this._mapGl && this._center) {this._mapGl.setCenter(this._center);}@@ -60,23 +62,21 @@ export class MapWidget {public flyTo(coordinates?:LngLatLike, zoom?: number): this {switch (this._type) {- case Type.RASTER:+ case MapType.RASTER:if (this._mapJs) {- //TODO implement fylTo+ // TODO implement fylTo}break;- case Type.VECTOR:- if (this._mapGl) {- if(this._viewSettings) {- if (!coordinates) {- coordinates = this._center ? this._center : this._viewSettings.center;- }+ case MapType.VECTOR:+ if (!coordinates) {+ coordinates = this._center ? this._center : this._viewSettings ? this._viewSettings.center : undefined;+ }- if (!zoom) {- zoom = this._zoom ? this._zoom : this._viewSettings.zoom ? this._viewSettings.zoom : 18;- }- }+ if (!zoom) {+ zoom = this._zoom ? this._zoom : this._viewSettings && this._viewSettings.zoom ? this._viewSettings.zoom : undefined;+ }+ if (this._mapGl) {// Only do flyTo if it has valid LngLat valueif(coordinates) {this._mapGl.flyTo({@@ -84,7 +84,9 @@ export class MapWidget {zoom: zoom});}-+ } else {+ this._center = coordinates;+ this._zoom = zoom;}break;}@@ -97,12 +99,12 @@ export class MapWidget {this._zoom = zoom;switch (this._type) {- case Type.RASTER:+ case MapType.RASTER:if (this._mapJs && this._zoom) {this._mapJs.setZoom(this._zoom, {animate: false});}break;- case Type.VECTOR:+ case MapType.VECTOR:if (this._mapGl && this._zoom) {this._mapGl.setZoom(this._zoom);}@@ -114,7 +116,7 @@ export class MapWidget {public async loadViewSettings() {let settingsResponse;- if (this._type === Type.RASTER) {+ if (this._type === MapType.RASTER) {settingsResponse = await manager.rest.api.MapResource.getSettingsJs();} else {settingsResponse = await manager.rest.api.MapResource.getSettings();@@ -133,7 +135,7 @@ export class MapWidget {return;}- if (this._type === Type.RASTER) {+ if (this._type === MapType.RASTER) {// Add style to shadow rootconst style = document.createElement("style");@@ -247,7 +249,7 @@ export class MapWidget {});}- protected _onMapClick(lngLat: LngLatLike) {+ protected _onMapClick(lngLat: LngLat) {this._mapContainer.dispatchEvent(new OrMapClickedEvent(lngLat));}@@ -287,13 +289,13 @@ export class MapWidget {protected _updateMarkerPosition(marker: OrMapMarker) {switch (this._type) {- case Type.RASTER:+ case MapType.RASTER:const m: MarkerJS | undefined = this._markersJs.get(marker);if (m) {m.setLatLng([marker.lat!, marker.lng!]);}break;- case Type.VECTOR:+ case MapType.VECTOR:const mGl: MarkerGL | undefined = this._markersGl.get(marker);if (mGl) {mGl.setLngLat([marker.lng!, marker.lat!]);@@ -306,7 +308,7 @@ export class MapWidget {protected _updateMarkerElement(marker: OrMapMarker, doAdd: boolean) {switch (this._type) {- case Type.RASTER:+ case MapType.RASTER:let m = this._markersJs.get(marker);if (m) {this._removeMarkerClickHandler(marker, marker.markerContainer as HTMLElement);@@ -334,7 +336,7 @@ export class MapWidget {}break;- case Type.VECTOR:+ case MapType.VECTOR:let mGl = this._markersGl.get(marker);if (mGl) {marker._actualMarkerElement = undefined;diff --git a/ui/component/or-map/src/markers/or-map-marker-asset.ts b/ui/component/or-map/src/markers/or-map-marker-asset.tsindex e2ce691e4..055056377 100644--- a/ui/component/or-map/src/markers/or-map-marker-asset.ts+++ b/ui/component/or-map/src/markers/or-map-marker-asset.ts@@ -5,6 +5,25 @@ import {subscribe} from "@openremote/core";import manager, {AssetModelUtil} from "@openremote/core";import {Util} from "@openremote/core";+export function getMarkerIconAndColorFromAssetType(type: string | undefined): {icon: string, color: string | undefined} | undefined {+ if (!type) {+ return;+ }++ const descriptor = AssetModelUtil.getAssetDescriptor(type);+ const icon = descriptor && descriptor.icon ? descriptor.icon : AssetType.THING.icon!;+ let color: string | undefined;++ if (descriptor && descriptor.color) {+ color = descriptor.color;+ }++ return {+ color: color,+ icon: icon+ };+}+@customElement("or-map-marker-asset")export class OrMapMarkerAsset extends subscribe(manager)(OrMapMarker) {@@ -24,22 +43,19 @@ export class OrMapMarkerAsset extends subscribe(manager)(OrMapMarker) {protected markerColor?: string;protected set type(type: string | undefined) {- if (!type) {+ const iconAndColor = getMarkerIconAndColorFromAssetType(type);++ if (!iconAndColor) {this.visible = false;return;}- const descriptor = AssetModelUtil.getAssetDescriptor(type);-if (this.assetTypeAsIcon) {- const icon = descriptor ? descriptor.icon : AssetType.THING.icon;- this.icon = icon;+ this.icon = iconAndColor.icon;}- if (descriptor && descriptor.color) {- this.markerColor = descriptor.color;- this.updateColor(this.markerContainer);- }+ this.markerColor = iconAndColor.color;+ this.updateColor(this.markerContainer);this.visible = true;}diff --git a/ui/component/or-map/src/or-map-asset-card.ts b/ui/component/or-map/src/or-map-asset-card.tsindex 24d687e8a..1ab86e073 100644--- a/ui/component/or-map/src/or-map-asset-card.ts+++ b/ui/component/or-map/src/or-map-asset-card.ts@@ -29,7 +29,7 @@ import {mapAssetCardStyle} from "./style";orAttributeTemplateProvider.setTemplate((attribute:Attribute) => {let template;- const value = Util.getAttributeValue(attribute, undefined)+ const value = Util.getAttributeValueFormatted(attribute, undefined, undefined);switch (attribute.type) {case AttributeValueType.SWITCH_TOGGLE.name:template = html`<or-translate value="${value ? "On" : "Off"}"></or-translate>`;diff --git a/ui/component/or-map/src/util.ts b/ui/component/or-map/src/util.tsindex 55e309e36..1a15894e4 100644--- a/ui/component/or-map/src/util.ts+++ b/ui/component/or-map/src/util.ts@@ -1,6 +1,6 @@import {LngLat, LngLatBounds, LngLatBoundsLike, LngLatLike} from "mapbox-gl";import L, {LatLng, LatLngBounds} from "mapbox.js";-import {Asset, AttributeType, AssetAttribute, GeoJSONPoint, AttributeValueType} from "@openremote/model";+import {Asset, AttributeType, AssetAttribute, GeoJSONPoint, Position, AttributeValueType} from "@openremote/model";import {Util} from "@openremote/core";export function getLngLat(lngLatLike?: LngLatLike | Asset | AssetAttribute | GeoJSONPoint): LngLat | undefined {@@ -47,6 +47,16 @@ export function getLngLat(lngLatLike?: LngLatLike | Asset | AssetAttribute | Geo}}+export function getGeoJSONPoint(lngLat: LngLat | undefined): GeoJSONPoint | null {+ if (!lngLat) {+ return null;+ }++ return {+ coordinates: ([lngLat.lng, lngLat.lat] as unknown) as Position+ }+}+export function getLngLatBounds(lngLatBoundsLike?: LngLatBoundsLike): LngLatBounds | undefined {if (lngLatBoundsLike) {diff --git a/ui/component/or-map/tsconfig.json b/ui/component/or-map/tsconfig.jsonindex 45f8e6848..a164c30ba 100644--- a/ui/component/or-map/tsconfig.json+++ b/ui/component/or-map/tsconfig.json@@ -6,8 +6,7 @@"rootDir": "src"},"include": [- "./src",- "./@types"+ "./src"],"references": [{ "path": "../core" },@@ -17,4 +16,4 @@{ "path": "../or-icon" },{ "path": "../or-input" }]-}\ No newline at end of file+}diff --git a/ui/component/or-rules/package.json b/ui/component/or-rules/package.jsonindex d5ff551cd..ce508f268 100644--- a/ui/component/or-rules/package.json+++ b/ui/component/or-rules/package.json@@ -14,13 +14,11 @@"dependencies": {"@openremote/core": "^1.1.0","@openremote/model": "^1.1.0",- "@openremote/or-asset-viewer": "^1.1.0","@openremote/or-attribute-input": "^1.1.0","@openremote/or-icon": "^1.1.0","@openremote/or-input": "^1.1.0","@openremote/or-mwc-components": "^1.1.0","@openremote/or-panel": "^1.1.0",- "@openremote/or-map": "^1.1.0","@openremote/or-select": "^1.1.0","@openremote/or-translate": "^1.1.0","@openremote/rest": "^1.1.0",diff --git a/ui/component/or-rules/src/flow-viewer/components/internal-picker.ts b/ui/component/or-rules/src/flow-viewer/components/internal-picker.tsindex d1e46a902..1dede1e4c 100644--- a/ui/component/or-rules/src/flow-viewer/components/internal-picker.ts+++ b/ui/component/or-rules/src/flow-viewer/components/internal-picker.ts@@ -3,6 +3,7 @@ import { Node, PickerType, AssetAttributeInternalValue, AssetState, MetaItemTypeimport { nodeConverter } from "../converters/node-converter";import { OrInputChangedEvent } from "@openremote/or-input";import rest from "@openremote/rest";+import "@openremote/or-asset-tree";import { OrAssetTreeRequestSelectEvent } from "@openremote/or-asset-tree";import { ResizeObserver } from "resize-observer";import { project, modal } from "./flow-editor";diff --git a/ui/component/or-rules/src/index.ts b/ui/component/or-rules/src/index.tsindex 42eaa3c4d..95954d2e1 100644--- a/ui/component/or-rules/src/index.ts+++ b/ui/component/or-rules/src/index.ts@@ -41,6 +41,7 @@ import "./flow-viewer/flow-viewer";import {OrRuleList} from "./or-rule-list";import {OrRuleViewer} from "./or-rule-viewer";import {RecurrenceOption} from "./json-viewer/or-rule-then-otherwise";+import { AttributeInputCustomProvider } from "@openremote/or-attribute-input";export const enum ConditionType {ASSET_QUERY = "assetQuery",@@ -113,7 +114,7 @@ export interface RulesConfig {hideWhenAddAttribute?: boolean;hideWhenAddGroup?: boolean;};- inputProvider?: (assetType: string | undefined, attribute: Attribute | undefined, attributeDescriptor: AttributeDescriptor | undefined, valueDescriptor: AttributeValueDescriptor | undefined, valueChangeNotifier: (value: any | undefined) => void, readonly: boolean | undefined, disabled: boolean | undefined) => ((value: any) => TemplateResult) | undefined;+ inputProvider?: AttributeInputCustomProvider;descriptors?: {all?: RulesDescriptorSection;when?: RulesDescriptorSection;diff --git a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-message.ts b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-message.tsindex 9404b07aa..85069b643 100644--- a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-message.ts+++ b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-message.ts@@ -3,7 +3,8 @@ import "@openremote/or-input";import i18next from "i18next";import {translate} from "@openremote/or-translate";import "@openremote/or-input";-import {InputType, OrInputChangedEvent} from "@openremote/or-input";import {+import {InputType, OrInputChangedEvent} from "@openremote/or-input";+import {RuleActionNotification,EmailNotificationMessage} from "@openremote/model";@@ -47,4 +48,4 @@ export class OrRuleFormMessage extends translate(i18next)(LitElement) {this.dispatchEvent(new OrRulesJsonRuleChangedEvent());this.requestUpdate();}-}\ No newline at end of file+}diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-attribute.tsindex 21ef06aea..aa988d777 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@@ -12,11 +12,12 @@ import {ValueType} from "@openremote/model";import manager, {AssetModelUtil, Util} from "@openremote/core";-import {getAttributeValueTemplate} from "@openremote/or-attribute-input";+import "@openremote/or-attribute-input";import {InputType, OrInputChangedEvent} from "@openremote/or-input";import i18next from "i18next";import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";import { translate } from "@openremote/or-translate";+import { OrAttributeInputChangedEvent } from "@openremote/or-attribute-input";// language=CSSconst style = css`@@ -108,7 +109,7 @@ export class OrRuleActionAttribute extends translate(i18next)(LitElement) {const showUpdateOptions = !this.config || !this.config.controls || !this.config.controls.hideActionUpdateOptions;const attributeDescriptor = AssetModelUtil.getAssetAttributeDescriptor(assetDescriptor, this.action.attributeName);let attribute: Attribute | undefined = asset && this.action.attributeName ? Util.getAssetAttribute(asset, this.action.attributeName) : undefined;- let inputTemplate: ((value: any) => TemplateResult) | undefined = undefined;+ const attributeValueDescriptor = attributeDescriptor && attributeDescriptor.valueDescriptor ? typeof attributeDescriptor.valueDescriptor === "string" ? AssetModelUtil.getAttributeValueDescriptor(attributeDescriptor.valueDescriptor as string) : attributeDescriptor.valueDescriptor : attribute ? AssetModelUtil.getAttributeValueDescriptor(attribute.type as string) : undefined;// Only RW attributes can be used in actionslet attributes: [string, string][];@@ -124,24 +125,18 @@ export class OrRuleActionAttribute extends translate(i18next)(LitElement) {.map((ad) => [ad.attributeName!, Util.getAttributeLabel(undefined, ad)]);}- // A dummy attribute if we don't have a real one (to allow us to re-use the following function)- if (this.action.attributeName) {- if (!attribute) {- attribute = {- name: this.action.attributeName,- type: attributeDescriptor ? attributeDescriptor.valueDescriptor : undefined- };- }+ let attributeInput: TemplateResult | undefined;- inputTemplate = getAttributeValueTemplate(assetType, attribute, this.readonly || false, false, (v: any) => this.setActionAttributeValue(v), this.config ? this.config.inputProvider : undefined, undefined,- (attribute.type && (attribute.type.valueType === ValueType.BOOLEAN || attribute.type === AttributeValueType.BOOLEAN.name || attribute.type === AttributeValueType.SWITCH_TOGGLE.name)) ? "" : i18next.t("value"));+ if (this.action.attributeName) {+ const label = (attributeValueDescriptor && (attributeValueDescriptor.valueType === ValueType.BOOLEAN || attributeValueDescriptor.name === AttributeValueType.BOOLEAN.name || attributeValueDescriptor.name === AttributeValueType.SWITCH_TOGGLE.name)) ? "" : i18next.t("value");+ attributeInput = html`<or-attribute-input @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setActionAttributeValue(ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="${label}" .assetType="${assetType}" .attributeDescriptor="${attributeDescriptor}" .attributeValueDescriptor="${attributeValueDescriptor}" .value="${this.action.value}" .readonly="${this.readonly || false}"></or-attribute-input>`;}return html`- <or-input id="matchSelect" .label="${i18next.t("asset")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" ?readonly="${this.readonly}" .options="${idOptions}" .value="${idValue}"></or-input>+ <or-input id="matchSelect" .label="${i18next.t("asset")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" .readonly="${this.readonly || false}" .options="${idOptions}" .value="${idValue}"></or-input>${attributes.length > 0 ? html`- <or-input id="attributeSelect" .label="${i18next.t("attribute")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionAttributeName(e.detail.value)}" ?readonly="${this.readonly}" .options="${attributes}" .value="${this.action.attributeName}"></or-input>- ${inputTemplate ? inputTemplate(this.action.value) : ``}+ <or-input id="attributeSelect" .label="${i18next.t("attribute")}" .type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this.setActionAttributeName(e.detail.value)}" .readonly="${this.readonly || false}" .options="${attributes}" .value="${this.action.attributeName}"></or-input>+ ${attributeInput}` : html`<or-translate value="No attributes with write permission"></or-translate>`}@@ -216,4 +211,4 @@ export class OrRuleActionAttribute extends translate(i18next)(LitElement) {}}).then((response) => this._assets = response.data);}-}\ No newline at end of file+}diff --git a/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts b/ui/component/or-rules/src/json-viewer/or-rule-asset-query.tsindex 85e8a0f58..472211433 100644--- a/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts+++ b/ui/component/or-rules/src/json-viewer/or-rule-asset-query.ts@@ -27,12 +27,13 @@ import {import {OrSelectChangedEvent} from "@openremote/or-select";import "@openremote/or-input";import {InputType, OrInputChangedEvent} from "@openremote/or-input";-import {getAttributeValueTemplate} from "@openremote/or-attribute-input";+import "@openremote/or-attribute-input";import manager, {AssetModelUtil, Util} from "@openremote/core";import i18next from "i18next";import {buttonStyle} from "../style";import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";import {translate} from "@openremote/or-translate";+import { OrAttributeInputChangedEvent } from "@openremote/or-attribute-input";// language=CSSconst style = css`@@ -163,9 +164,9 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {const operators = this.getOperators(assetDescriptor, attribute, attributeName);return html`- <or-input type="${InputType.SELECT}" @or-input-changed="${(e: OrSelectChangedEvent) => this.setAttributeName(attributePredicate, e.detail.value)}" ?readonly="${this.readonly}" .options="${attributes}" .value="${attributeName}" .label="${i18next.t("attribute")}"></or-input>+ <or-input type="${InputType.SELECT}" @or-input-changed="${(e: OrSelectChangedEvent) => this.setAttributeName(attributePredicate, e.detail.value)}" .readonly="${this.readonly || false}" .options="${attributes}" .value="${attributeName}" .label="${i18next.t("attribute")}"></or-input>- ${attributeName ? html`<or-input type="${InputType.SELECT}" @or-input-changed="${(e: OrSelectChangedEvent) => this.setOperator(assetDescriptor, attribute, attributeName, attributePredicate, e.detail.value)}" ?readonly="${this.readonly}" .options="${operators}" .value="${operator}" .label="${i18next.t("operator")}"></or-input>` : ``}+ ${attributeName ? html`<or-input type="${InputType.SELECT}" @or-input-changed="${(e: OrSelectChangedEvent) => this.setOperator(assetDescriptor, attribute, attributeName, attributePredicate, e.detail.value)}" .readonly="${this.readonly || false}" .options="${operators}" .value="${operator}" .label="${i18next.t("operator")}"></or-input>` : ``}${attributePredicate ? this.attributePredicateValueEditorTemplate(assetDescriptor, attributePredicate) : ``}`;@@ -181,27 +182,28 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {const attributeName = this.getAttributeName(attributePredicate);const assetType = getAssetTypeFromQuery(this.query);+ const attributeDescriptor = AssetModelUtil.getAssetAttributeDescriptor(assetDescriptor, attributeName);+ const attributeValueDescriptor = attributeDescriptor && attributeDescriptor.valueDescriptor ? typeof attributeDescriptor.valueDescriptor === "string" ? AssetModelUtil.getAttributeValueDescriptor(attributeDescriptor.valueDescriptor as string) : attributeDescriptor.valueDescriptor : undefined;+// @ts-ignoreconst value = valuePredicate ? valuePredicate.value : undefined;switch (valuePredicate.predicateType) {case "string":- return getAttributeValueTemplate(assetType, { name: attributeName!, type: AttributeValueType.STRING }, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined, undefined, i18next.t("string"))(value);+ return html`<or-attribute-input @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="${i18next.t("string")}" .assetType="${assetType}" .attributeDescriptor="${attributeDescriptor}" .attributeValueDescriptor="${attributeValueDescriptor}" .value="${value}" .readonly="${this.readonly || false}"></or-attribute-input>`;case "boolean":return html ``; // Handled by the operator IS_TRUE or IS_FALSEcase "datetime":return html `<span>NOT IMPLEMENTED</span>`;case "number":if (valuePredicate.operator === AQO.BETWEEN) {- const inputTemplate1 = getAttributeValueTemplate(assetType, { name: attributeName!, type: AttributeValueType.NUMBER }, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined, undefined, i18next.t("between"));- const inputTemplate2 = getAttributeValueTemplate(assetType, { name: attributeName!, type: AttributeValueType.NUMBER }, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "rangeValue", v), this.config ? this.config.inputProvider : undefined, undefined, i18next.t("and"));return html`- ${inputTemplate1(value)}+ <or-attribute-input .inputType="${InputType.NUMBER}" @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="${i18next.t("between")}" .assetType="${assetType}" .attributeDescriptor="${attributeDescriptor}" .attributeValueDescriptor="${attributeValueDescriptor}" .value="${value}" .readonly="${this.readonly || false}"></or-attribute-input><span style="display: inline-flex; align-items: center;">&</span>- ${inputTemplate2(valuePredicate.rangeValue)}+ <or-attribute-input .inputType="${InputType.NUMBER}" @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setValuePredicateProperty(valuePredicate, "rangeValue", ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="${i18next.t("and")}" .assetType="${assetType}" .attributeDescriptor="${attributeDescriptor}" .attributeValueDescriptor="${attributeValueDescriptor}" .value="${valuePredicate.rangeValue}" .readonly="${this.readonly || false}"></or-attribute-input>`;}- return getAttributeValueTemplate(assetType, { name: attributeName!, type: AttributeValueType.NUMBER }, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined, undefined, i18next.t("number"))(value);+ return html`<or-attribute-input @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="${i18next.t("number")}" .assetType="${assetType}" .attributeDescriptor="${attributeDescriptor}" .attributeValueDescriptor="${attributeValueDescriptor}" .value="${value}" .readonly="${this.readonly || false}"></or-attribute-input>`;case "string-array":return html `<span>NOT IMPLEMENTED</span>`;case "radial":@@ -217,7 +219,7 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {case "array":// TODO: Update once we can determine inner type of array// Assume string array- return getAttributeValueTemplate(assetType, {name: attributeName!, type: AttributeValueType.ARRAY }, this.readonly || false, false, (v: any) => this.setValuePredicateProperty(valuePredicate, "value", v), this.config ? this.config.inputProvider : undefined, InputType.TEXT, undefined)(value);+ return html`<or-attribute-input @or-attribute-input-changed="${(ev: OrAttributeInputChangedEvent) => this.setValuePredicateProperty(valuePredicate, "value", ev.detail.value)}" .customProvider="${this.config?.inputProvider}" .label="${i18next.t("array")}" .assetType="${assetType}" .attributeDescriptor="${attributeDescriptor}" .attributeValueDescriptor="${attributeValueDescriptor}" .value="${value}" .readonly="${this.readonly || false}"></or-attribute-input>`;default:return html `<span>NOT IMPLEMENTED</span>`;}@@ -280,7 +282,7 @@ export class OrRuleAssetQuery extends translate(i18next)(LitElement) {return html`<div class="attribute-group">- <or-input id="idSelect" type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" ?readonly="${this.readonly}" .options="${idOptions}" .value="${idValue}" .label="${i18next.t("asset")}"></or-input>+ <or-input id="idSelect" type="${InputType.SELECT}" @or-input-changed="${(e: OrInputChangedEvent) => this._assetId = (e.detail.value)}" .readonly="${this.readonly || false}" .options="${idOptions}" .value="${idValue}" .label="${i18next.t("asset")}"></or-input>${this.query.attributes && this.query.attributes.items ? this.query.attributes.items.map((attributePredicate) => {diff --git a/ui/component/or-rules/tsconfig.json b/ui/component/or-rules/tsconfig.jsonindex 71d03ee96..aa85e573c 100644--- a/ui/component/or-rules/tsconfig.json+++ b/ui/component/or-rules/tsconfig.json@@ -11,13 +11,11 @@"references": [{ "path": "../core" },{ "path": "../or-translate" },- { "path": "../or-input" },- { "path": "../or-map" },- { "path": "../or-attribute-input" },{ "path": "../or-icon" },{ "path": "../or-panel" },- { "path": "../or-asset-viewer" },- { "path": "../or-asset-tree" },- { "path": "../or-mwc-components" }+ { "path": "../or-mwc-components" },+ { "path": "../or-input" },+ { "path": "../or-attribute-input" },+ { "path": "../or-asset-tree" }]-}\ No newline at end of file+}diff --git a/ui/demo/demo-or-map/tsconfig.json b/ui/demo/demo-or-map/tsconfig.jsonindex b37ec3da1..737d6bee3 100644--- a/ui/demo/demo-or-map/tsconfig.json+++ b/ui/demo/demo-or-map/tsconfig.json@@ -4,8 +4,7 @@"tsBuildInfoFile": "./.tsbuildinfo"},"include": [- "./src",- "../../component/or-map/@types"+ "./src"],"references": [{ "path": "../../demo/demo-core" },@@ -13,4 +12,4 @@{ "path": "../../component/rest" },{ "path": "../../component/or-map" }]-}\ No newline at end of file+}diff --git a/ui/tsconfig.json b/ui/tsconfig.jsonindex 21f23f1e0..8fdfaf765 100644--- a/ui/tsconfig.json+++ b/ui/tsconfig.json@@ -16,4 +16,4 @@"allowSyntheticDefaultImports": true,"composite": true}-}\ No newline at end of file+}