Skip to content
Permalink
Browse files

UI updates: fixed or-rules-editor to work with latest or components

  • Loading branch information...
richturner committed Oct 9, 2019
1 parent d5320c4 commit 636aafca1094f28e8cba068cadb2f9687071ad5f
@@ -61,13 +61,14 @@ export const subscribe = (eventProviderFactory: EventProviderFactory) => <T exte
return;
}

const isAttributes = !!this._attributeRefs;
const ids: string[] | AttributeRef[] | undefined = this._attributeRefs ? this._attributeRefs : this._assetIds;

if (ids && ids.length > 0) {
this._assetSubscriptionId = await eventProviderFactory.getEventProvider()!.subscribeAssetEvents(ids, true, (event) => this._onAssetEvent(event));
this._attributeSubscriptionId = await eventProviderFactory.getEventProvider()!.subscribeAttributeEvents(ids, false, (event) => this._onAttributeEvent(event));
} else if (this._attributeRefs && this._attributeRefs.length > 0) {

if (!isAttributes) {
this._assetSubscriptionId = await eventProviderFactory.getEventProvider()!.subscribeAssetEvents(ids, true, (event) => this._onAssetEvent(event));
}
this._attributeSubscriptionId = await eventProviderFactory.getEventProvider()!.subscribeAttributeEvents(ids, isAttributes, (event) => this._onAttributeEvent(event));
}
this.onStatusChange(EventProviderStatus.CONNECTED);
}
@@ -219,16 +219,16 @@ abstract class EventProviderImpl implements EventProvider {
eventType: "asset"
};

if (ids && ids.length > 0) {
const isAttributeRef = ids && typeof ids[0] !== "string";
const assetIds = isAttributeRef ? (ids as AttributeRef[]).map((id) => id.entityId!) : ids as string[] | null;

if (assetIds && assetIds.length > 0) {
subscription.filter = {
filterType: "asset-id",
assetIds: ids
};
}

const isAttributeRef = ids && typeof ids[0] !== "string";
const assetIds = isAttributeRef ? (ids as AttributeRef[]).map((id) => id.entityId!) : ids as string[] | null;

let subscriptionId: string | null = null;

try {
@@ -278,7 +278,7 @@ abstract class EventProviderImpl implements EventProvider {

try {
subscriptionId = await this.subscribe(subscription, (evt) => {
if(attributes) {
if (attributes) {
// Filter events for these attributes
const eventRef = evt.attributeState!.attributeRef!;
if (attributes.findIndex((attrRef) => eventRef.entityId === attrRef.entityId && eventRef.attributeName === attrRef.attributeName) >= 0) {
@@ -7,7 +7,8 @@ import {EventProvider, EventProviderFactory, EventProviderStatus, WebSocketEvent
import i18next from "i18next";
import i18nextXhr from "i18next-xhr-backend";
import {AssetDescriptor, AttributeDescriptor, AttributeValueDescriptor, MetaItemDescriptor, Asset, AssetAttribute,
MetaItem} from "@openremote/model";
MetaItem,
Attribute} from "@openremote/model";
import * as Util from "./util";

export declare type KeycloakPromise<T> = {
@@ -185,7 +186,11 @@ export class AssetModelUtil {
});
}

public static getAttributeValueDescriptorFromAsset(name: string, assetType?: string, attributeName?: string) : AttributeValueDescriptor | undefined {
public static getAttributeValueDescriptorFromAsset(name: string | undefined, assetType?: string, attributeName?: string): AttributeValueDescriptor | undefined {
if (!name) {
return;
}

if (attributeName) {
const attributeDescriptor = this.getAttributeDescriptorFromAsset(attributeName, assetType);
if (attributeDescriptor) {
@@ -216,15 +221,18 @@ export class AssetModelUtil {
return attributeValueDescriptor1.name === attributeValueDescriptor2.name && attributeValueDescriptor1.valueType === attributeValueDescriptor2.valueType;
}

public static getMetaValue(metaItemUrn: string | MetaItemDescriptor, metaItems: MetaItem[] | undefined): any {
if (!metaItems) {
return;
}

public static getMetaValue(metaItemUrn: string | MetaItemDescriptor, attribute: Attribute | undefined, descriptor: AttributeDescriptor | undefined): any {
const urn = typeof metaItemUrn === "string" ? metaItemUrn : (metaItemUrn as MetaItemDescriptor).urn;

const mi = metaItems.find((mi) => mi.name === urn);
return mi ? mi.value : undefined;
if (attribute && attribute.meta) {
const metaItem = attribute.meta.find((mi) => mi.name === urn);
return metaItem ? metaItem.value : undefined;
}

if (descriptor && descriptor.metaItemDescriptors) {
const metaItemDescriptor = descriptor.metaItemDescriptors.find((mid) => mid.urn === urn);
return metaItemDescriptor ? metaItemDescriptor.initialValue : undefined;
}
}

public static getMetaInitialValueFromMetaDescriptors(metaItemUrn: MetaItemDescriptor | string, metaItemDescriptors: MetaItemDescriptor[] | undefined): any | undefined {

0 comments on commit 636aafc

Please sign in to comment.
You can’t perform that action at this time.