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: core utils and styling constants
Rich Turner6afa568fcb5c
diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.tsindex 947f7474c..b052dcb7e 100644--- a/ui/component/core/src/index.ts+++ b/ui/component/core/src/index.ts@@ -7,6 +7,17 @@ import {EventProvider, EventProviderFactory, EventProviderStatus, WebSocketEventimport i18next from "i18next";import i18nextXhr from "i18next-xhr-backend";import {AssetDescriptor, AttributeDescriptor, AttributeValueDescriptor, MetaItemDescriptor} from "@openremote/model";+import * as Util from "./util";++export {Util}++export const DefaultColor1: string = "#FFF"; // Header and panels+export const DefaultColor2: string = "#F9F9F9"; // Background+export const DefaultColor3: string = "#202020"; // Text+export const DefaultColor4: string = "#1B5630"; // Buttons+export const DefaultColor5: string = "#CCC"; // Borders and lines+export const DefaultBoxShadow: string = "0 5px 5px -5px rgba(0,0,0,0.57)";+export const DefaultHeaderHeight: string = "60px";export enum ORError {NONE = "NONE",diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.tsindex f853fec01..aa0f07db5 100644--- a/ui/component/core/src/util.ts+++ b/ui/component/core/src/util.ts@@ -5,8 +5,13 @@ import {PushNotificationMessage,RuleActionUnion,RuleCondition,- LogicGroup+ LogicGroup,+ Asset,+ AssetAttribute,+ AttributeEvent,+ MetaItem} from "@openremote/model";+import {Util} from "./index";export class Deferred<T> {@@ -191,3 +196,51 @@ export function getEnumKeyAsString(enm: object, val: string): string {const key = Object.keys(enm).find((k) => enm[k] === val);return key!;}++export function getQueryParameter(name: string): string {+ name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");+ const regex = new RegExp("[\\?&]" + name + "=([^&#]*)");+ const results = regex.exec(location.search);+ return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));+}++export function getAssetAttribute(asset: Asset, attributeName: string): AssetAttribute | undefined {+ if (asset.attributes && asset.attributes.hasOwnProperty(attributeName)) {+ const attr = asset.attributes[attributeName] as AssetAttribute;+ attr.name = attributeName;+ return attr;+ }+}++export function getAssetAttributes(asset: Asset): AssetAttribute[] {+ if (asset.attributes) {+ return Object.entries(asset.attributes as {[s: string]: AssetAttribute}).map(([name, attr]) => {+ attr.name = name;+ return attr;+ });+ }++ return [];+}++/**+ * Immutable update of an asset using the supplied attribute event+ */+export function updateAsset(asset: Asset, event: AttributeEvent): Asset {++ const attributeName = event.attributeState!.attributeRef!.attributeName!;++ if (asset.attributes) {+ if (event.attributeState!.deleted) {+ delete asset.attributes![attributeName];+ } else {+ const attribute = getAssetAttribute(asset, attributeName);+ if (attribute) {+ attribute.value = event.attributeState!.value;+ attribute.valueTimestamp = event.timestamp;+ }+ }+ }++ return Object.assign({}, asset);+}