From 6e748ae799ecb43584525277bafee1919cd1f36b Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Sat, 8 Jul 2017 21:10:04 +0530 Subject: [PATCH] Hiding geo-fencing related buttons when geoservices disabled --- .../cdmf.unit.geo-dashboard/geo-dashboard.hbs | 2 ++ .../cdmf.unit.geo-dashboard/public/js/app.js | 36 +++++++++++-------- .../public/js/websocket.js | 2 +- 3 files changed, 25 insertions(+), 15 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 0c94083014..0c22014c8e 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 @@ -485,11 +485,13 @@
Information

+ {{#if geoServicesEnabled}}
Speed km/h
Heading
+ {{/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();