From e205fd97cd14631576bc6712af76267746243af0 Mon Sep 17 00:00:00 2001 From: kamidu Date: Wed, 22 Mar 2017 20:14:50 +0530 Subject: [PATCH] fix the user view related issues and device location out dated issue --- .../modules/business-controllers/device.js | 34 +++ .../app/pages/cdmf.page.user.view/view.hbs | 206 ++++++++++-------- .../app/pages/cdmf.page.user.view/view.js | 5 +- 3 files changed, 150 insertions(+), 95 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index 68fa4630d7..1da093d61d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -98,6 +98,26 @@ deviceModule = function () { locationTimeData.push(gpsReadingTimes); } } + var locationInfo = {}; + try { + var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/location"; + serviceInvokers.XMLHttp.get( + url, + function (backendResponse) { + + if (backendResponse.status == 200 && backendResponse.responseText) { + var device = parse(backendResponse.responseText); + locationInfo.latitude = device.latitude; + locationInfo.longitude = device.longitude; + locationInfo.updatedOn = device.updatedTime; + + } + }); + } catch (e) { + log.error(e.message, e); + } + + var utility = require('/app/modules/utility.js')["utility"]; try { utility.startTenantFlow(carbonUser); @@ -175,10 +195,24 @@ deviceModule = function () { if (device["deviceInfo"]) { filteredDeviceData["latestDeviceInfo"] = device["deviceInfo"]; } + + //location related verification and modifications + // adding the location histry for the movement path. var locationHistory = {}; locationHistory.locations = locationData; locationHistory.times = locationTimeData; filteredDeviceData["locationHistory"] = locationHistory; + + //checking for the latest location information. + if (filteredDeviceData.latestDeviceInfo.location && locationInfo) { + var infoDate = new Date(filteredDeviceData.latestDeviceInfo.location.updatedTime); + var locationDate = new Date(locationInfo.updatedOn); + if (infoDate < locationDate) { + filteredDeviceData.latestDeviceInfo.location.longitude = locationInfo.longitude; + filteredDeviceData.latestDeviceInfo.location.latitude = locationInfo.latitude; + } + } + response["content"] = filteredDeviceData; response["status"] = "success"; return response; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.hbs index 6230be73b7..dd86421cc7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.hbs @@ -37,99 +37,100 @@ {{#zone "content"}} {{#if canView}} - {{#zone "contentTitle"}} -
-
- + {{#if exists}} + {{#zone "contentTitle"}} +
+
+ +
-
- {{/zone}} + {{/zone}} -
-
-
-
-
-
+
+
+
+
+
+
- {{#unless isCloud}} - {{#if editPermitted}} - - {{/if}} - {{/unless}} + {{#unless isCloud}} + {{#if editPermitted}} + + {{/if}} + {{/unless}} +
-
-
-
Profile Overview +
+
Profile Overview +
+ {{#defineZone "user-detail-properties"}} + + + + + + + + + + + + + + + + + + + + + + + +
Username{{user.username}}
First Name{{user.firstname}}
Last Name{{user.lastname}}
Email{{user.emailAddress}}
Roles + {{#each userRoles}} + + {{/each}} +
+ {{/defineZone}}
- {{#defineZone "user-detail-properties"}} - - - - - - - - - - - - - - - - - - - - - - - -
Username{{user.username}}
First Name{{user.firstname}}
Last Name{{user.lastname}}
Email{{user.emailAddress}}
Roles - {{#each userRoles}} - - {{/each}} -
- {{/defineZone}} -
-
-
- - {{#defineZone "user-enrolled-devices"}} -
-
-
-
Enrolled Devices by - {{#if user.firstname}} - {{user.firstname}} {{user.lastname}} - {{else}} - {{user.username}} - {{/if}} -
-
-
-
- {{#each devices}} -
+
+
+ +
+ {{#defineZone "user-enrolled-devices"}} +
+
+
+
Enrolled Devices by + {{#if user.firstname}} + {{user.firstname}} {{user.lastname}} + {{else}} + {{user.username}} + {{/if}} +
+
+
+
+ {{#each devices}} +
@@ -160,18 +161,37 @@
-
- {{/each}} +
+ {{/each}} +
+
-
-
- {{/defineZone}} + {{/defineZone}} +
+
+ {{else}} +
+
+

User not found.

+
Please click "Add A New User", if you wish to add user or click + "View User List" to navigate to the user list. +
+ + + + + + + Add Another User + +
-
+ {{/if}} {{else}}

Permission Denied diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.js index 2d544949b0..0be5dd28df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.user.view/view.js @@ -21,7 +21,7 @@ function onRequest(context) { var username = request.getParameter("username"); var user = userModule.getUser(username)["content"]; var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"]; - + var isExsistingUser = false; var userName = request.getParameter("username"); var user, userRoles, devices; @@ -32,6 +32,7 @@ function onRequest(context) { if (response["status"] == "success") { user = response["content"]; user.domain = response["userDomain"]; + isExsistingUser = true; } response = userModule.getRolesByUsername(userName); @@ -49,5 +50,5 @@ function onRequest(context) { var isCloud = deviceMgtProps.isCloud; - return {"user": user, "userRoles": userRoles, "devices": devices, "canView": canView, "isCloud" : isCloud}; + return {"exists": isExsistingUser, "user": user, "userRoles": userRoles, "devices": devices, "canView": canView, "isCloud" : isCloud}; }