From ca62c2ef73f8dfe875485e4c7381d08cae76a68a Mon Sep 17 00:00:00 2001 From: Charitha Goonetilleke Date: Wed, 4 May 2016 02:47:45 +0530 Subject: [PATCH] Fix grouped device listing --- .../carbon/device/mgt/jaxrs/api/Group.java | 18 ++++++++++ .../cdmf.page.devices/public/js/listing.js | 36 ++++--------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java index a4dffc4fee..ab350b6b07 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Group.java @@ -168,6 +168,24 @@ public class Group { } } + @Path("/user/{user}/all") + @GET + @Produces("application/json") + public Response getGroups(@PathParam("user") String userName) { + try { + List deviceGroups = DeviceMgtAPIUtils.getGroupManagementProviderService() + .getGroups(userName); + if (deviceGroups.size() > 0) { + return Response.status(Response.Status.OK).entity(deviceGroups).build(); + } else { + return Response.status(Response.Status.NOT_FOUND).build(); + } + } catch (GroupManagementException e) { + log.error(e.getMessage(), e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); + } + } + @Path("/owner/{owner}/name/{groupName}") @GET @Produces("application/json") 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 49d0707be5..09453f8041 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 @@ -68,7 +68,7 @@ var deviceListing, currentUser, groupName, groupOwner; */ $(document).ready(function () { deviceListing = $("#device-listing"); - deviceListing.data("current-user"); + currentUser = deviceListing.data("current-user"); groupName = getParameterByName("groupName"); groupOwner = getParameterByName("groupOwner"); @@ -168,7 +168,9 @@ function toTitleCase(str) { function loadDevices(searchType, searchParam){ var serviceURL; - if ($.hasPermission("LIST_DEVICES")) { + if (groupName && groupOwner && $.hasPermission("LIST_OWN_DEVICES")) { + serviceURL = "/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName + "/devices"; + } else if ($.hasPermission("LIST_DEVICES")) { serviceURL = "/devicemgt_admin/devices"; } else if ($.hasPermission("LIST_OWN_DEVICES")) { //Get authenticated users devices @@ -390,32 +392,6 @@ function openCollapsedNav() { }); } -function initPage() { - var serviceURL; - if ($.hasPermission("LIST_DEVICES")) { - serviceURL = "/devicemgt_admin/devices/count"; - } else if ($.hasPermission("LIST_OWN_DEVICES")) { - //Get authenticated users devices - serviceURL = "/devicemgt_admin/devices/user/" + currentUser + "/count"; - } - invokerUtil.get(serviceURL, - function (data) { - if (data) { - data = JSON.parse(data); - if (Number(data) > 0) { - loadDevices(); - } else { - $("#loading-content").remove(); - $("#device-listing-status-msg").text("No enrolled devices found."); - $("#device-listing-status").removeClass(' hidden'); - } - } - }, function (message) { - initPage(); - } - ); -} - /* * DOM ready functions. */ @@ -432,7 +408,7 @@ $(document).ready(function () { } } - initPage(); + loadDevices(); /* for device list sorting drop down */ $(".ctrl-filter-type-switcher").popover({ @@ -515,7 +491,7 @@ function attachDeviceEvents() { serviceURL = "/devicemgt_admin/groups/all"; } else if ($.hasPermission("LIST_GROUPS")) { //Get authenticated users groups - serviceURL = "/devicemgt_admin/groups/user/" + currentUser; + serviceURL = "/devicemgt_admin/groups/user/" + currentUser + "/all"; } invokerUtil.get(serviceURL, function (data) {