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 c7de8aac7eb..b225f9c9834 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
@@ -18,6 +18,7 @@
{{unit "cdmf.unit.ui.title" pageTitle="Device Management"}}
{{unit "cdmf.unit.data-tables-extended"}}
+{{unit "cdmf.unit.lib.ui-permissions-utility"}}
{{#zone "breadcrumbs"}}
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 0e384c7016c..778b467ea47 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
@@ -29,7 +29,6 @@ function InitiateViewOption(url) {
(function () {
var cache = {};
- var permissionSet = {};
var validateAndReturn = function (value) {
return (value == undefined || value == null) ? "Unspecified" : value;
};
@@ -44,15 +43,6 @@ function InitiateViewOption(url) {
}, {});
}
});
-
- //This method is used to setup permission for device listing
- $.setPermission = function (permission) {
- permissionSet[permission] = true;
- };
-
- $.hasPermission = function (permission) {
- return permissionSet[permission];
- };
})();
/*
@@ -78,13 +68,6 @@ $(document).ready(function () {
addDeviceSelectedClass(this);
});
- var permissionList = $("#permission").data("permission");
- for (var key in permissionList) {
- if (permissionList.hasOwnProperty(key)) {
- $.setPermission(key);
- }
- }
-
/* for device list sorting drop down */
$(".ctrl-filter-type-switcher").popover({
html: true,
@@ -168,11 +151,11 @@ function toTitleCase(str) {
function loadDevices(searchType, searchParam) {
var serviceURL;
- if (groupName && groupOwner && $.hasPermission("LIST_OWN_DEVICES")) {
+ if (groupName && groupOwner && permissionsUtil.hasPermission("LIST_OWN_DEVICES")) {
serviceURL = "/api/device-mgt/v1.0/groups/owner/" + groupOwner + "/name/" + groupName + "/devices";
- } else if ($.hasPermission("LIST_DEVICES")) {
+ } else if (permissionsUtil.hasPermission("LIST_DEVICES")) {
serviceURL = "/api/device-mgt/v1.0/devices";
- } else if ($.hasPermission("LIST_OWN_DEVICES")) {
+ } else if (permissionsUtil.hasPermission("LIST_OWN_DEVICES")) {
//Get authenticated users devices
serviceURL = "/api/device-mgt/v1.0/users/devices?username=" + currentUser;
} else {
@@ -227,6 +210,38 @@ function loadDevices(searchType, searchParam) {
return type;
}
+ function analyticsEnabled(type) {
+ var deviceTypes = deviceListing.data("deviceTypes");
+ for (var i = 0; i < deviceTypes.length; i++) {
+ if (deviceTypes[i].type == type) {
+ var analyticsEnabled = deviceTypes[i].analyticsEnabled;
+ if (analyticsEnabled == undefined) {
+ // By default it should be enabled
+ return true;
+ }
+ // In JS Boolean("false") returns TRUE => http://stackoverflow.com/a/264037/1560536
+ return (analyticsEnabled == "true");
+ }
+ }
+ return true;
+ }
+
+ function groupingEnabled(type) {
+ var deviceTypes = deviceListing.data("deviceTypes");
+ for (var i = 0; i < deviceTypes.length; i++) {
+ if (deviceTypes[i].type == type) {
+ var groupingEnabled = deviceTypes[i].groupingEnabled;
+ if (groupingEnabled == undefined) {
+ // By default it should be enabled
+ return true;
+ }
+ // In JS Boolean("false") returns TRUE => http://stackoverflow.com/a/264037/1560536
+ return (analyticsEnabled == "true");
+ }
+ }
+ return true;
+ }
+
var columns = [
{
targets: 0,
@@ -251,7 +266,8 @@ function loadDevices(searchType, searchParam) {
return html;
}
},
- {targets: 2,
+ {
+ targets: 2,
data: 'user',
class: 'fade-edge remove-padding-top',
},
@@ -292,7 +308,7 @@ function loadDevices(searchType, searchParam) {
class: 'fade-edge remove-padding-top',
render: function (status, type, row, meta) {
if (getDeviceTypeCategory(row.deviceType) == 'mobile') {
- return row.enrolmentInfo.ownership;
+ return row.ownership;
} else {
return null;
}
@@ -313,15 +329,19 @@ function loadDevices(searchType, searchParam) {
' class="btn padding-reduce-on-grid-view">'
+
'View';
- html += ''
+
''
+
'Analytics';
+ }
- if (!groupName || !groupOwner) {
+ if (groupingEnabled(deviceType) && (!groupName || !groupOwner)) {
html +=
'
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js
index bec491c0178..26d7387a7fe 100644
--- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js
@@ -82,26 +82,13 @@ function toTitleCase(str) {
});
}
-(function () {
- var permissionSet = {};
-
- //This method is used to setup permission for device listing
- $.setPermission = function (permission) {
- permissionSet[permission] = true;
- };
-
- $.hasPermission = function (permission) {
- return permissionSet[permission];
- };
-})();
-
function loadGroups() {
var groupListing = $("#group-listing");
var currentUser = groupListing.data("currentUser");
var serviceURL;
- if ($.hasPermission("LIST_ALL_GROUPS")) {
+ if (permissionsUtil.hasPermission("LIST_ALL_GROUPS")) {
serviceURL = "/devicemgt_admin/groups";
- } else if ($.hasPermission("LIST_GROUPS")) {
+ } else if (permissionsUtil.hasPermission("LIST_GROUPS")) {
//Get authenticated users groups
serviceURL = "/devicemgt_admin/groups/user/" + currentUser;
} else {