Added geo-fencing to the devicemgt app

revert-70aa11f8
Rasika Perera 8 years ago
parent ea3ed9c444
commit 7b0295ff01

@ -176,7 +176,8 @@
"perm:ios:get-restrictions", "perm:ios:get-restrictions",
"perm:ios:wipe-data", "perm:ios:wipe-data",
"perm:admin", "perm:admin",
"perm:devicetype:deployment" "perm:devicetype:deployment",
"perm:geo-service:analytics"
], ],
"isOAuthEnabled": true, "isOAuthEnabled": true,
"backendRestEndpoints": { "backendRestEndpoints": {

@ -69,35 +69,22 @@ deviceModule = function () {
throw constants["ERRORS"]["USER_NOT_FOUND"]; throw constants["ERRORS"]["USER_NOT_FOUND"];
} }
var userName = carbonUser.username + "@" + carbonUser.domain; var userName = carbonUser.username + "@" + carbonUser.domain;
var locationHistory = [];
var locationDataSet = []; try {
switch (deviceType) { var fromDate = new Date();
case 'android': fromDate.setHours(fromDate.getHours() - 2);
locationDataSet = batchProvider.getData(userName, deviceId, deviceType); var toDate = new Date();
break; var serviceUrl = devicemgtProps["httpsURL"] + '/api/device-mgt/v1.0/geo-services/stats/' + deviceType + '/' + deviceId;
case 'android_sense': serviceInvokers.XMLHttp.get(serviceUrl,
locationDataSet = batchProvider.getData(userName, deviceId, deviceType); function (backendResponse) {
break; if (backendResponse.status === 200 && backendResponse.responseText) {
locationHistory = JSON.parse(backendResponse.responseText);
}
var locationData = [];
var locationTimeData = [];
if (locationDataSet != null) {
for (var i = 0; i < locationDataSet.length; i++) {
var gpsReading = {};
var gpsReadingTimes = {};
gpsReading.lat = locationDataSet[i].latitude;
gpsReading.lng = locationDataSet[i].longitude;
if (deviceType == "android") {
gpsReadingTimes.time = locationDataSet[i].timeStamp;
} else {
gpsReadingTimes.time = locationDataSet[i].meta_timestamp;
}
locationData.push(gpsReading);
locationTimeData.push(gpsReadingTimes);
} }
});
} catch (e) {
log.error(e.message, e);
} }
var locationInfo = {}; var locationInfo = {};
try { try {
var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/location"; var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/location";
@ -110,14 +97,12 @@ deviceModule = function () {
locationInfo.latitude = device.latitude; locationInfo.latitude = device.latitude;
locationInfo.longitude = device.longitude; locationInfo.longitude = device.longitude;
locationInfo.updatedOn = device.updatedTime; locationInfo.updatedOn = device.updatedTime;
} }
}); });
} catch (e) { } catch (e) {
log.error(e.message, e); log.error(e.message, e);
} }
var utility = require('/app/modules/utility.js')["utility"]; var utility = require('/app/modules/utility.js')["utility"];
try { try {
utility.startTenantFlow(carbonUser); utility.startTenantFlow(carbonUser);
@ -192,16 +177,35 @@ deviceModule = function () {
} }
} }
} }
if (device["deviceInfo"]) { if (device["deviceInfo"]) {
filteredDeviceData["latestDeviceInfo"] = device["deviceInfo"]; filteredDeviceData["latestDeviceInfo"] = device["deviceInfo"];
} else {
filteredDeviceData["latestDeviceInfo"] = {};
filteredDeviceData["latestDeviceInfo"]["location"] = {};
}
//location related verification and modifications //location related verification and modifications
// adding the location histry for the movement path. // adding the location histry for the movement path.
var locationHistory = {};
locationHistory.locations = locationData;
locationHistory.times = locationTimeData;
filteredDeviceData["locationHistory"] = locationHistory; filteredDeviceData["locationHistory"] = locationHistory;
//checking for the latest location information based on historical data.
if (locationHistory) {
var infoDate;
var locationDate;
var historicalLatestLoc = locationHistory[locationHistory.length - 1];
if (historicalLatestLoc && filteredDeviceData.latestDeviceInfo && filteredDeviceData.latestDeviceInfo.location) {
infoDate = new Date(filteredDeviceData.latestDeviceInfo.location.updatedTime);
locationDate = new Date(historicalLatestLoc.values.timeStamp);
}
if (infoDate < locationDate || filteredDeviceData.latestDeviceInfo.length === 0) {
filteredDeviceData.latestDeviceInfo.location = {};
filteredDeviceData.latestDeviceInfo.location.longitude = historicalLatestLoc.values.longitude;
filteredDeviceData.latestDeviceInfo.location.latitude = historicalLatestLoc.values.latitude;
filteredDeviceData.latestDeviceInfo.location.updatedTime = historicalLatestLoc.values.timeStamp;
}
}
//checking for the latest location information. //checking for the latest location information.
if (filteredDeviceData.latestDeviceInfo.location && locationInfo) { if (filteredDeviceData.latestDeviceInfo.location && locationInfo) {
var infoDate = new Date(filteredDeviceData.latestDeviceInfo.location.updatedTime); var infoDate = new Date(filteredDeviceData.latestDeviceInfo.location.updatedTime);
@ -209,11 +213,10 @@ deviceModule = function () {
if (infoDate < locationDate) { if (infoDate < locationDate) {
filteredDeviceData.latestDeviceInfo.location.longitude = locationInfo.longitude; filteredDeviceData.latestDeviceInfo.location.longitude = locationInfo.longitude;
filteredDeviceData.latestDeviceInfo.location.latitude = locationInfo.latitude; filteredDeviceData.latestDeviceInfo.location.latitude = locationInfo.latitude;
} filteredDeviceData.latestDeviceInfo.location.updatedTime = locationInfo.updatedOn;
} }
} }
response["content"] = filteredDeviceData; response["content"] = filteredDeviceData;
response["status"] = "success"; response["status"] = "success";
return response; return response;
@ -277,28 +280,6 @@ deviceModule = function () {
return response; return response;
}; };
/*
@Updated
*/
// publicMethods.getLicense = function (deviceType) {
// var url;
// var license;
// if (deviceType == "windows") {
// url = mdmProps["httpURL"] + "/mdm-windows-agent/services/device/license";
// } else if (deviceType == "ios") {
// url = mdmProps["httpsURL"] + "/ios-enrollment/license/";
// }
// if (url != null && url != undefined) {
// serviceInvokers.XMLHttp.get(url, function (responsePayload) {
// license = responsePayload.text;
// }, function (responsePayload) {
// return null;
// });
// }
// return license;
// };
publicMethods.getDevices = function (userName) { publicMethods.getDevices = function (userName) {
var url = devicemgtProps["httpsURL"] + var url = devicemgtProps["httpsURL"] +
devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices"; devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/devices";

@ -19,6 +19,8 @@
{{#zone "content"}} {{#zone "content"}}
{{#if deviceFound}} {{#if deviceFound}}
{{#if isAuthorized}} {{#if isAuthorized}}
<span id="logged-in-user" class="hidden" data-username="{{@user.username}}" data-domain="{{@user.domain}}"
data-tenant-id="{{@user.tenantId}}" data-iscloud="{{isCloud}}"></span>
{{#defineZone "device-details-header"}} {{#defineZone "device-details-header"}}
<h1 class="page-sub-title device-id device-select" data-deviceid="{{device.deviceIdentifier}}" <h1 class="page-sub-title device-id device-select" data-deviceid="{{device.deviceIdentifier}}"
data-type="{{device.type}}"> data-type="{{device.type}}">

@ -34,6 +34,7 @@ function onRequest(context) {
var viewModel = {}; var viewModel = {};
if (filteredDeviceData["type"]) { if (filteredDeviceData["type"]) {
viewModel["deviceType"] = filteredDeviceData["type"]; viewModel["deviceType"] = filteredDeviceData["type"];
viewModel["type"] = filteredDeviceData["type"];
viewModel.isNotWindows = true; viewModel.isNotWindows = true;
if (viewModel["deviceType"] == "windows") { if (viewModel["deviceType"] == "windows") {
viewModel.isNotWindows = false; viewModel.isNotWindows = false;

@ -37,6 +37,11 @@ var invokerUtil = function () {
acceptTypeValue = acceptType; acceptTypeValue = acceptType;
} }
var synchronous = false;
if (isSynchronous) {
synchronous = true;
}
if(contentTypeValue == "application/json"){ if(contentTypeValue == "application/json"){
restAPIRequestDetails["requestPayload"] = JSON.stringify(requestPayload); restAPIRequestDetails["requestPayload"] = JSON.stringify(requestPayload);
} }
@ -46,6 +51,7 @@ var invokerUtil = function () {
contentType: contentTypeValue, contentType: contentTypeValue,
data: JSON.stringify(restAPIRequestDetails), data: JSON.stringify(restAPIRequestDetails),
accept: acceptTypeValue, accept: acceptTypeValue,
async : synchronous,
success: successCallback, success: successCallback,
error: function (jqXHR) { error: function (jqXHR) {
if (jqXHR.status == 401) { if (jqXHR.status == 401) {
@ -61,22 +67,22 @@ var invokerUtil = function () {
$.ajax(request); $.ajax(request);
}; };
publicMethods.get = function (requestURL, successCallback, errorCallback, contentType, acceptType) { publicMethods.get = function (requestURL, successCallback, errorCallback, contentType, acceptType, isSynchronous) {
var requestPayload = null; var requestPayload = null;
privateMethods.execute("GET", requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType); privateMethods.execute("GET", requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType, isSynchronous);
}; };
publicMethods.post = function (requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType) { publicMethods.post = function (requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType, isSynchronous) {
privateMethods.execute("POST", requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType); privateMethods.execute("POST", requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType, isSynchronous);
}; };
publicMethods.put = function (requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType) { publicMethods.put = function (requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType, isSynchronous) {
privateMethods.execute("PUT", requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType); privateMethods.execute("PUT", requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType, isSynchronous);
}; };
publicMethods.delete = function (requestURL, successCallback, errorCallback, contentType, acceptType) { publicMethods.delete = function (requestURL, successCallback, errorCallback, contentType, acceptType, isSynchronous) {
var requestPayload = null; var requestPayload = null;
privateMethods.execute("DELETE", requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType); privateMethods.execute("DELETE", requestURL, requestPayload, successCallback, errorCallback, contentType, acceptType, isSynchronous);
}; };
return publicMethods; return publicMethods;

@ -266,3 +266,7 @@ header .username {
.add-padding-top-3x { .add-padding-top-3x {
padding-top: 15px !important; padding-top: 15px !important;
} }
ul#noty_topRight_layout_container li{
margin-bottom: 10px;
}

@ -429,11 +429,11 @@ a.ctrl-filter-category:hover {
.btn { .btn {
display: inline-block; display: inline-block;
padding: 8px 20px; /*padding: 8px 20px;*/
margin-bottom: 0; margin-bottom: 0;
font-size: 16px; /*font-size: 16px;*/
font-weight: normal; font-weight: normal;
line-height: 1.42857143; /*line-height: 1.42857143;*/
text-align: center; text-align: center;
white-space: nowrap; white-space: nowrap;
vertical-align: middle; vertical-align: middle;
@ -446,7 +446,7 @@ a.ctrl-filter-category:hover {
user-select: none; user-select: none;
background-image: none; background-image: none;
border: 1px solid transparent; border: 1px solid transparent;
border-radius: 0; /*border-radius: 0;*/
transition: background 0.2s; transition: background 0.2s;
} }

@ -26,4 +26,42 @@
{{#zone "bottomJs" override=false}} {{#zone "bottomJs" override=false}}
{{!-- Responsive JS Library--}} {{!-- Responsive JS Library--}}
{{js "js/responsive-text.js"}} {{js "js/responsive-text.js"}}
<script type="text/javascript">
$.noty.defaults = {
layout: 'topRight',
theme: 'metroui', // or relax
type: 'alert', // success, error, warning, information, notification
text: '', // [string|html] can be HTML or STRING
dismissQueue: true, // [boolean] If you want to use queue feature set this true
force: false, // [boolean] adds notification to the beginning of queue when set to true
maxVisible: 5, // [integer] you can set max visible notification count for dismissQueue true option,
template: '<div class="noty_message"><span class="noty_text"></span><div class="noty_close"></div></div>',
timeout: 3000, // [integer|boolean] delay for closing event in milliseconds. Set false for sticky notifications
progressBar: false, // [boolean] - displays a progress bar
animation: {
open: {height: 'toggle'}, // or Animate.css class names like: 'animated bounceInLeft'
close: {height: 'toggle'}, // or Animate.css class names like: 'animated bounceOutLeft'
easing: 'swing',
speed: 500 // opening & closing animation speed
},
closeWith: ['click'], // ['click', 'button', 'hover', 'backdrop'] // backdrop click will close all notifications
modal: false, // [boolean] if true adds an overlay
killer: false, // [boolean] if true closes all notifications and shows itself
callback: {
onShow: function() {},
afterShow: function() {},
onClose: function() {},
afterClose: function() {},
onCloseClick: function() {},
},
buttons: false // [boolean|array] an array of buttons, for creating confirmation dialogs.
};
</script>
{{/zone}} {{/zone}}

@ -7837,7 +7837,7 @@ ul.sidebar-messages > li {
* noty styles * noty styles
* ======================================================================== */ * ======================================================================== */
#noty_topRight_layout_container { #noty_topRight_layout_container {
position: absolute !important; position: fixed !important;
} }
#noty_topRight_layout_container, #noty_topLeft_layout_container { #noty_topRight_layout_container, #noty_topLeft_layout_container {

@ -8,7 +8,7 @@ $.noty.layouts.topRight = {
selector: 'ul#noty_topRight_layout_container', selector: 'ul#noty_topRight_layout_container',
style : function() { style : function() {
$(this).css({ $(this).css({
top : 20, top : 0,
right : 20, right : 20,
position : 'fixed', position : 'fixed',
width : '310px', width : '310px',

Loading…
Cancel
Save