From 176738b14bc239aaaeba54fcb59ac8338bf5595c Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Sat, 29 Jul 2017 16:46:00 +0530 Subject: [PATCH] Geo Fencing improvements --- .../cdmf.unit.geo-dashboard/geo-dashboard.hbs | 29 ++++++++++++----- .../cdmf.unit.geo-dashboard/public/js/app.js | 31 +++++++++++++------ .../public/js/websocket.js | 2 +- 3 files changed, 43 insertions(+), 19 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 48970a6fa3..eb788c4a81 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 @@ -745,24 +745,37 @@ geoPublicUri = $("#geo-charts").data("geo-public-uri"); {{#if geoServicesEnabled}} var geoToolsMenu = $('#location-action-bar'); - var realtTime = createGeoToolListItem('javascript:enableRealTime()', - 'Return to Real Time View', 'fw fw-undo', geoToolsMenu); + + var refreshMap = createGeoToolListItem('javascript:void(0);', 'Refresh', 'fw fw-refresh', geoToolsMenu, true); + refreshMap.addClass("geo-alert"); + refreshMap.on("click", function(){enableRealTime();}); + + var realtTime = createGeoToolListItem('javascript:void(0);', 'Return to Real Time View', 'fw fw-undo', geoToolsMenu, true); + realtTime.on("click", function(){enableRealTime();}); realtTime.css("display", "none"); realtTime.attr("id", "realTimeShow"); - createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/speed_alert.html', + + var speedAlert = createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/speed_alert.html', 'Set Speed Alert', 'glyphicon glyphicon-dashboard', geoToolsMenu); - createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/stationery_alert.html', + speedAlert.addClass("geo-alert"); + + var stationaryAlert = createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/stationery_alert.html', 'Add Stationary Alert', 'glyphicon glyphicon-link', geoToolsMenu); - createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/within_alert.html', + stationaryAlert.addClass("geo-alert"); + + var withinAlert = createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/within_alert.html', 'Add Geofence Alert', 'glyphicon glyphicon-log-in', geoToolsMenu); - createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/exit_alert.html', + withinAlert.addClass("geo-alert"); + + var exitAlert = createGeoToolListItem(geoPublicUri + '/assets/html_templates/modal/exit_alert.html', 'Add Geofence Exit Alert', 'glyphicon glyphicon-log-out', geoToolsMenu); + exitAlert.addClass("geo-alert"); {{/if}} } $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { - $('#dateRangePopup').dialog('close'); - }) + $('#dateRangePopup.ui-dialog-content').dialog('close'); + }); }); {{/zone}} 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 a87c01a49d..1d93c73a2f 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 @@ -35,12 +35,12 @@ var zoomLevel = 15; var tileSet = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"; var attribution = "© OpenStreetMap contributors"; -function initialLoad() { +function initialLoad(geoFencingEnabled) { if (document.getElementById('map') == null) { setTimeout(initialLoad, 500); // give everything some time to render } else { initializeMap(); - processAfterInitializationMap(); + processAfterInitializationMap(geoFencingEnabled); $("#loading").hide(); } } @@ -111,7 +111,7 @@ var geoAlertsBar; var groupedOverlays; var layerControl; -function processAfterInitializationMap() { +function processAfterInitializationMap(geoFencingEnabled) { attributionControl = L.control({ position: "bottomright" }); @@ -123,7 +123,9 @@ function processAfterInitializationMap() { map.addControl(L.control.fullscreen({position: 'bottomright'})); geoAlertsBar = L.control.geoAlerts({position: 'topright'}); - map.addControl(geoAlertsBar); + if (geoFencingEnabled) { + map.addControl(geoAlertsBar); + } groupedOverlays = { "Web Map Service layers": {} @@ -277,6 +279,7 @@ var getProviderData = function (timeFrom, timeTo) { var serviceUrl = '/api/device-mgt/v1.0/geo-services/stats/' + deviceType + '/' + deviceId + '?from=' + timeFrom + '&to=' + timeTo; invokerUtil.get(serviceUrl, function (data) { + if(data === ""){showCurrentLocation(tableData);} tableData = JSON.parse(data); if (tableData.length === 0) { showCurrentLocation(tableData); @@ -359,7 +362,8 @@ function notifyError(message) { } function enableRealTime() { - document.getElementById('realTimeShow').style.display = 'none'; + $("#realTimeShow").hide(); + $(".geo-alert").show(); spatialObject = currentSpatialObjects[selectedSpatialObject]; if (spatialObject) { spatialObject.removePath(); @@ -368,8 +372,13 @@ function enableRealTime() { selectedSpatialObject = null; clearFocus(); clearMap(); - document.getElementById('objectInfo').style.display = 'none'; isBatchModeOn = false; + initializeGeoLocation(geoFencingEnabled); +} + +function disableRealTime(){ + $(".geo-alert").hide(); + $("#realTimeShow").show(); } var geoFencingEnabled = true; @@ -456,7 +465,7 @@ function focusOnHistorySpatialObject(objectId, timeFrom, timeTo) { notifyError('No end time provided to show history. Please provide a suitable value' + timeTo); } else { $('#dateRangePopup').dialog('close'); - document.getElementById('realTimeShow').style.display = 'block'; + disableRealTime(); isBatchModeOn = true; clearFocus(); // Clear current focus if any clearMap(); @@ -524,11 +533,13 @@ function clearFocus() { } } -function createGeoToolListItem(link, text, icon, menuRoot) { +function createGeoToolListItem(link, text, icon, menuRoot, noModal) { var listItem = $("
", { class: 'action-btn filter'}).appendTo(menuRoot); var anchor = $("", {href: link, text: ' ' + text}).appendTo(listItem); - anchor.attr('data-toggle', 'modal'); - anchor.attr('data-target', '#commonModal'); + if(!noModal){ + anchor.attr('data-toggle', 'modal'); + anchor.attr('data-target', '#commonModal'); + } $("", {class: icon}).prependTo(anchor); return listItem; } 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 3ef846e148..ffa49ac0e2 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 @@ -630,7 +630,7 @@ function initializeGeoLocation(geoFencingEnabled) { + "deviceId=" + deviceId + "&deviceType=" + deviceType + "&websocketToken=" + wsToken; $("#proximity_alert").hide(); - initialLoad(); + initialLoad(geoFencingEnabled); InitSpatialObject(geoFencingEnabled); if (geoFencingEnabled) {