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
Added function to get RadialPredicates from json rules
Michael Rademaker6fddb9a79e85
diff --git a/ui/component/core/src/util.ts b/ui/component/core/src/util.tsindex 78e2d99b8..9bc1c93b6 100644--- a/ui/component/core/src/util.ts+++ b/ui/component/core/src/util.ts@@ -1,3 +1,4 @@+import {JsonRulesetDefinition, PushNotificationMessage, RadialGeofencePredicate} from "@openremote/model";export class Deferred<T> {@@ -24,4 +25,43 @@ export class Deferred<T> {});Object.freeze(this);}-}\ No newline at end of file+}++export interface GeoNotification {+ predicate: RadialGeofencePredicate+ notification: PushNotificationMessage+}++export function getGeoNotificationsFromRulesSet(json: string): GeoNotification[] {++ let rulesetDefinition: JsonRulesetDefinition = JSON.parse(json) as JsonRulesetDefinition;++ let geoPredicates: GeoNotification[] = [];+ let geoNotification: GeoNotification;++ rulesetDefinition.rules!.forEach((rule) => {+ geoNotification = {} as GeoNotification;+ if (rule.when && rule.when.asset) {+ rule.when.asset.attributes!.predicates!.forEach((predicate) => {+ if (predicate.value!.predicateType == "radial" || predicate.value!.predicateType == "rect") {+ geoNotification.predicate = predicate.value as RadialGeofencePredicate+ }+ });+ }++ if (rule.then) {+ rule.then.forEach((action) => {+ if (action.action == "notification") {+ if (action.notification && action.notification.message) {+ geoNotification.notification = action.notification.message as PushNotificationMessage;+ }+ }+ });+ }+ if (geoNotification.predicate && geoNotification.notification) {+ geoPredicates.push(geoNotification)+ }+ });++ return geoPredicates;+}