From 389173f505802c12ac3f5bb377deb033893e1077 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Sat, 8 Jul 2017 19:17:52 +0530 Subject: [PATCH 1/2] Fixes https://github.com/wso2/product-iots/issues/1084 --- .../cdmf.unit.geo-dashboard/geo-dashboard.hbs | 12 ++- .../cdmf.unit.geo-dashboard/geo-dashboard.js | 2 +- .../cdmf.unit.geo-dashboard/public/js/app.js | 99 +++++++------------ .../public/js/geo_remote.js | 11 --- .../public/js/websocket.js | 88 +++++++---------- 5 files changed, 77 insertions(+), 135 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.hbs index 4fe6e70fd3..0c94083014 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/geo-dashboard.hbs @@ -64,6 +64,12 @@
+ {{#if geoServicesEnabled}} +
+ Alerts Stream  + Spatial Stream +
+ {{/if}}
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/app.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/app.js index 181829e390..dcc9a8c95a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/app.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/app.js @@ -273,16 +273,20 @@ var getProviderData = function (timeFrom, timeTo) { deviceId = deviceDetails.data("deviceid"); deviceType = deviceDetails.data("type"); - var serviceUrl = '/api/device-mgt/v1.0/geo-services/stats/' + deviceType + '/' + deviceId + '?from=' + timeFrom + '&to=' + timeTo; - invokerUtil.get(serviceUrl, - function (data) { - tableData = JSON.parse(data); - if (tableData.length === 0) { - showCurrentLocation(tableData); - } - }, function (message) { - showCurrentLocation(tableData); - }); + if (geoFencingEnabled) { + var serviceUrl = '/api/device-mgt/v1.0/geo-services/stats/' + deviceType + '/' + deviceId + '?from=' + timeFrom + '&to=' + timeTo; + invokerUtil.get(serviceUrl, + function (data) { + tableData = JSON.parse(data); + if (tableData.length === 0) { + showCurrentLocation(tableData); + } + }, function (message) { + showCurrentLocation(tableData); + }); + } else { + showCurrentLocation(tableData); + } return tableData; }; @@ -368,7 +372,9 @@ function enableRealTime() { isBatchModeOn = false; } -function InitSpatialObject() { +var geoFencingEnabled = true; +function InitSpatialObject(geoFencingIsEnabled) { + geoFencingEnabled = geoFencingIsEnabled; var spatialObject = drawSpatialObject(); map.addControl(L.control.focus({position: 'bottomright', marker: spatialObject.marker, zoomLevel: zoomLevel})); } @@ -420,9 +426,11 @@ function drawSpatialObject() { return true; } - var alertsFromDate = new Date(); - alertsFromDate.setHours(alertsFromDate.getHours() - 24); //last 24 hours - getAlertsHistory(deviceType, deviceId, alertsFromDate.valueOf(), toDate.valueOf()); + if (geoFencingEnabled) { + var alertsFromDate = new Date(); + alertsFromDate.setHours(alertsFromDate.getHours() - 24); //last 24 hours + getAlertsHistory(deviceType, deviceId, alertsFromDate.valueOf(), toDate.valueOf()); + } setTimeout(function () { map.invalidateSize(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js index 26438fbe45..3ef846e148 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.geo-dashboard/public/js/websocket.js @@ -631,7 +631,7 @@ function initializeGeoLocation(geoFencingEnabled) { $("#proximity_alert").hide(); initialLoad(); - InitSpatialObject(); + InitSpatialObject(geoFencingEnabled); if (geoFencingEnabled) { initializeSpatialStreamWebSocket();