From 85d07dc9cbd1ab67d9387533bd99d0ded1a8a959 Mon Sep 17 00:00:00 2001 From: GDLMadushanka Date: Mon, 5 Jun 2017 09:35:46 +0530 Subject: [PATCH] Redirecting to respective analytics pages depending on the device type --- .../app/pages/cdmf.page.devices/devices.hbs | 4 ++-- .../app/pages/cdmf.page.devices/devices.js | 19 +++++++++++---- .../cdmf.page.devices/public/js/listing.js | 24 ++++++++++++++++++- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs index 059aa68899d..e03ea2f90dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs @@ -519,8 +519,8 @@ {{/zone}} {{#zone "bottomJs"}} - + {{js "js/listing.js"}} {{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js index 5727b6f06d5..c513053eddc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.js @@ -21,7 +21,7 @@ function onRequest(context) { var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"]; var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; - + var groupId = request.getParameter("groupId"); var viewModel = {}; @@ -60,6 +60,8 @@ function onRequest(context) { if (data) { for (var i = 0; i < data.length; i++) { var config = utility.getDeviceTypeConfig(data[i]); + var log = new Log("devices.js"); + if (!config) { continue; } @@ -70,7 +72,8 @@ function onRequest(context) { "label": deviceType.label, "thumb": utility.getDeviceThumb(data[i]), "analyticsEnabled": deviceType.analyticsEnabled, - "groupingEnabled": deviceType.groupingEnabled + "groupingEnabled": deviceType.groupingEnabled, + "analyticsView" : deviceType.analyticsView }); } } @@ -80,9 +83,15 @@ function onRequest(context) { } var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; - var analyticsServer = mdmProps["dashboardServerURL"]; - var analyticsURL = analyticsServer + "/portal/t/" + context.user.userDomain + "/dashboards/android-iot/battery?owner=" + context.user.username + "&deviceId="; - viewModel.analyticsURL = analyticsURL; + var serverUrl = mdmProps["httpsURL"]; + var portalUrl = mdmProps["portalURL"]; + var userDomain = context.user.domain; + //var userName = context.user.username; + + viewModel.serverUrl = serverUrl; + viewModel.portalUrl = portalUrl; + viewModel.userDomain = userDomain; + //viewModel.userName = userName; return viewModel; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index 8876c069281..54fd4d7698b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -224,6 +224,21 @@ function loadDevices(searchType, searchParam) { return true; } + function getAnalyticsView(type) { + var deviceTypes = deviceListing.data("deviceTypes"); + for (var i = 0; i < deviceTypes.length; i++) { + if (deviceTypes[i].type == type) { + var analyticsView = deviceTypes[i].analyticsView; + if (analyticsEnabled == undefined) { + // if undefined go to default analytics view + return "none"; + } + return analyticsView; + } + } + return "none"; + } + function groupingEnabled(type) { var deviceTypes = deviceListing.data("deviceTypes"); for (var i = 0; i < deviceTypes.length; i++) { @@ -323,12 +338,19 @@ function loadDevices(searchType, searchParam) { var deviceType = row.deviceType; var deviceIdentifier = row.deviceIdentifier; var html = ''; - var statURL = $("#device-listing").data("analitics-url"); + var portalUrl = $("#device-listing").data("portal-url"); + var serverUrl = $("#device-listing").data("server-url"); + var userDomain = $("#device-listing").data("userDomain"); + var statURL; if (status != 'REMOVED') { html = ''; if (analyticsEnabled(row.deviceType)) { + switch (getAnalyticsView(deviceType)) { + case "DAS" : { statURL =portalUrl + "/portal/t/"+ userDomain+ "/dashboards/android-iot/battery?owner=" +currentUser+"&deviceId=";break;} + default : {statURL=context+ "/device/" + row.deviceType +"/analytics?deviceId="} + } html += '