From b1683c1ccbf8b56192d884fbe77246495951ba5e Mon Sep 17 00:00:00 2001 From: charithag Date: Thu, 28 Apr 2016 08:01:46 +0530 Subject: [PATCH] Add capability to assign device in to a group and bug fixes --- .../carbon/device/mgt/jaxrs/api/Group.java | 51 ++++--- .../src/main/webapp/META-INF/permissions.xml | 15 +- .../mgt/core/group/mgt/dao/GroupDAOImpl.java | 4 +- .../jaggeryapps/devicemgt/api/group-api.jag | 83 +++++++++++ .../jaggeryapps/devicemgt/api/stats-api.jag | 124 ---------------- .../devicemgt/app/modules/group.js | 2 +- .../app/pages/cdmf.page.devices/devices.hbs | 2 +- .../app/pages/cdmf.page.devices/devices.js | 1 - .../cdmf.page.devices/public/js/listing.js | 132 ++++++++---------- .../jaggeryapps/devicemgt/jaggery.conf | 4 - 10 files changed, 189 insertions(+), 229 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag 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 4e1b9b68b7..acd9e98714 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 @@ -21,15 +21,15 @@ package org.wso2.carbon.device.mgt.jaxrs.api; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; -import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyEixistException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupUser; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; +import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -141,6 +141,26 @@ public class Group { } } + @Path("/all") + @GET + @Produces("application/json") + public Response getAllGroups() { + try { + GroupManagementProviderService groupManagementProviderService = DeviceMgtAPIUtils + .getGroupManagementProviderService(); + PaginationResult paginationResult = groupManagementProviderService + .getGroups(0, groupManagementProviderService.getGroupCount()); + if (paginationResult.getRecordsTotal() > 0) { + return Response.status(Response.Status.OK).entity(paginationResult.getData()).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("/user/{user}") @GET @Produces("application/json") @@ -364,16 +384,18 @@ public class Group { } @GET - @Path("/owner/{owner}/name/{groupName}/devices/all") + @Path("/owner/{owner}/name/{groupName}/devices") @Produces("application/json") - public Response getDevices(@PathParam("groupName") String groupName, - @PathParam("owner") String owner) { + public Response getDevices(@PathParam("groupName") String groupName, @PathParam("owner") String owner, + @QueryParam("start") int startIdx, @QueryParam("length") int length) { try { - List devices = DeviceMgtAPIUtils.getGroupManagementProviderService().getDevices( - groupName, owner); - Device[] deviceArray = new Device[devices.size()]; - devices.toArray(deviceArray); - return Response.status(Response.Status.OK).entity(deviceArray).build(); + PaginationResult paginationResult = DeviceMgtAPIUtils + .getGroupManagementProviderService().getDevices(groupName, owner, startIdx, length); + if (paginationResult.getRecordsTotal() > 0) { + return Response.status(Response.Status.OK).entity(paginationResult).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(); @@ -394,15 +416,12 @@ public class Group { } } - @PUT - @Path("/owner/{owner}/name/{groupName}/devices/{deviceType}/{deviceId}") + @POST + @Path("/owner/{owner}/name/{groupName}/devices") @Produces("application/json") public Response addDevice(@PathParam("groupName") String groupName, - @PathParam("owner") String owner, @PathParam("deviceId") String deviceId, - @PathParam("deviceType") String deviceType, - @FormParam("userName") String userName) { + @PathParam("owner") String owner, DeviceIdentifier deviceIdentifier) { try { - DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType); boolean isAdded = DeviceMgtAPIUtils.getGroupManagementProviderService().addDevice( deviceIdentifier, groupName, owner); if (isAdded) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml index 1768fa9160..e00d1a93ac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml @@ -959,12 +959,19 @@ - List All Groups + List All Groups with Pagination /device-mgt/admin/groups/list /groups GET + + List All Groups + /device-mgt/admin/groups/list + /groups/all + GET + + List Groups /device-mgt/user/groups/list @@ -1080,7 +1087,7 @@ List Group Devices /device-mgt/user/groups/devices/list - /groups/owner/*/name/*/devices/all + /groups/owner/*/name/*/devices GET @@ -1094,8 +1101,8 @@ Add Device to Group /device-mgt/user/groups/devices/add - /groups/owner/*/name/*/devices/*/* - PUT + /groups/owner/*/name/*/devices + POST diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java index 819d676dc7..afb8cca055 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupDAOImpl.java @@ -356,9 +356,9 @@ public class GroupDAOImpl implements GroupDAO { ResultSet resultSet = null; try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT COUNT(gm.ID) AS DEVICE_COUNT FROM DM_DEVICE_GROUP_MAP gm, (SELECT ID as GROUP_ID " + + String sql = "SELECT COUNT(gm.ID) AS DEVICE_COUNT FROM DM_DEVICE_GROUP_MAP gm, (SELECT ID " + "FROM DM_GROUP WHERE GROUP_NAME = ? AND OWNER = ? AND TENANT_ID = ?) dg " + - "WHERE dm.GROUP_ID = dg.GROUP_ID AND dm.TENANT_ID = ?"; + "WHERE gm.GROUP_ID = dg.ID AND dm.TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, groupName); stmt.setString(2, owner); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag new file mode 100644 index 0000000000..e64ad14d16 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag @@ -0,0 +1,83 @@ +<% +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +var uri = request.getRequestURI(); +var uriMatcher = new URIMatcher(String(uri)); + +var log = new Log("api/device-api.jag"); +var constants = require("/app/modules/constants.js"); +var utility = require("/app/modules/utility.js").utility; +var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); +var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; + +var user = session.get(constants.USER_SESSION_KEY); +var result; + +response.contentType = 'application/json'; + +if (!user) { + response.sendRedirect("/devicemgt/login?#login-required"); + exit(); +} else { + if (uriMatcher.match("/{context}/api/groups")) { + var url = request.getParameter("url"); + var draw = request.getParameter("draw"); + var length = request.getParameter("length"); + var start = request.getParameter("start"); + var search = request.getParameter("search[value]"); + var groupName = request.getParameter("columns[1][search][value]"); + var owner = request.getParameter("columns[2][search][value]"); + var targetURL; + + function appendQueryParam(url, queryParam, value) { + if (url.indexOf("?") > 0) { + return url + "&" + queryParam + "=" + value; + } + return url + "?" + queryParam + "=" + value; + } + + targetURL = devicemgtProps.httpsURL + request.getParameter("url"); + targetURL = appendQueryParam(targetURL, "start", start); + targetURL = appendQueryParam(targetURL, "length", length); + + if (search && search !== "") { + targetURL = appendQueryParam(targetURL, "search", search); + } + + if (groupName && groupName !== "") { + targetURL = appendQueryParam(targetURL, "group-name", groupName); + } + + if (owner && owner !== "") { + targetURL = appendQueryParam(targetURL, "user", owner); + } + + serviceInvokers.XMLHttp.get( + targetURL, function (responsePayload) { + response.status = 200; + result = responsePayload; + }, + function (responsePayload) { + response.status = responsePayload.status; + result = responsePayload.responseText; + }); + } +} + +%> \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag deleted file mode 100644 index 5c8fd94355..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/stats-api.jag +++ /dev/null @@ -1,124 +0,0 @@ -<% -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -var uri = request.getRequestURI(); -var uriMatcher = new URIMatcher(String(uri)); - -var log = new Log("api/stats-api.jag"); - -var from = request.getParameter("from"); -var to = request.getParameter("to"); - -var constants = require("/app/modules/constants.js"); -var utility = require("/app/modules/utility.js").utility; -var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); - -var deviceCloudGroupService = devicemgtProps["httpsURL"] + "/common/group_manager"; -var deviceCloudDeviceService = devicemgtProps["httpsURL"] + "/common/device_manager"; -var deviceCloudStatsService = devicemgtProps["httpsURL"] + "/common/stats_manager"; - -var stats = {}; -var deviceId; -var deviceType; - -var responseProcessor = require('utils').response; -response.contentType = 'application/json'; - -var user = session.get(constants.USER_SESSION_KEY); - -if (!user) { - response = responseProcessor.buildErrorResponse(response, 401, "Unauthorized"); -} else { - if (uriMatcher.match("/{context}/api/stats")) { - deviceId = request.getParameter("deviceId"); - deviceType = request.getParameter("deviceType"); - - getDeviceData(deviceType, deviceId); - - } else if (uriMatcher.match("/{context}/api/stats/group")) { - var groupId = request.getParameter("groupId"); - - //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/all - var endPoint = deviceCloudGroupService + "/group/id/" + groupId + "/device/all"; - var data = {"username": user}; - var devices = get(endPoint, data, "json").data; - - for (var device in devices) { - deviceId = devices[device].deviceIdentifier; - deviceType = devices[device].type; - getDeviceData(deviceType, deviceId); - } - } - log.info(stats); - // returning the result. - if (stats) { - print(stats); - } -} - -function getDeviceData(deviceType, deviceId) { - //URL: GET https://localhost:9443/devicecloud/device_manager/device/type/{type}/identifier/{identifier} - var endPoint = deviceCloudDeviceService + "/device/type/" + deviceType + "/identifier/" + deviceId; - var data = {"username": user}; - var device = get(endPoint, data, "json").data; - log.info(device); - if (!device) { - return; - } - var uname = device.enrolmentInfo.owner; - - var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; - - if (analyticStreams) { - var streamTableName; - for (var stream in analyticStreams) { - streamTableName = analyticStreams[stream]["table"]; - if (stats[streamTableName] == null) { - stats[streamTableName] = []; - } - stats[streamTableName].push({ - "device": device.name, - "stats": getSensorData(streamTableName, analyticStreams[stream]["ui_unit"]["data"][1]["column"]["name"], uname, device.type, device.deviceIdentifier, from, to), - "stream": analyticStreams[stream] - }); - } - } -} - -function getSensorData(table, column, user, type, deviceIdentifier, from, to) { - - var fetchedData = []; - - try { - ///stats/device/type/{type}/identifier/{identifier} - var endPoint = deviceCloudStatsService + "/stats/device/type/" + type + "/identifier/" + deviceIdentifier; - var query = "?table=" + encodeURIComponent(table) - + "&column=" + encodeURIComponent(column) - + "&username=" + encodeURIComponent(user) - + "&from=" + from - + "&to=" + to; - endPoint = endPoint + query; - fetchedData = get(endPoint, {}, "json").data; - return fetchedData; - } catch (error) { - log.error(error); - } -} - -%> diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js index 3d050b38a1..31fac7176d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/group.js @@ -54,7 +54,7 @@ var groupModule = {}; }; groupModule.getGroupDeviceCount = function (groupName, owner) { - endPoint = groupServiceEndpoint + "/" + owner + "/" + groupName + "/devices/count"; + endPoint = groupServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices/count"; return serviceInvokers.XMLHttp.get( endPoint, function (responsePayload) { return responsePayload; 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 2966fa09a2..1122acfc29 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 @@ -1,4 +1,4 @@ -{{unit "cdmf.unit.ui.title" pageTitle="Device Management"}} +{{unit "cdmf.unit.ui.title" pageTitle=title}} {{unit "cdmf.unit.data-tables-extended"}} 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 851fec3688..e56c529cc9 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 @@ -44,7 +44,6 @@ function onRequest(context) { if (groupName && groupOwner) { var groupModule = require("/app/modules/group.js").groupModule; deviceCount = groupModule.getGroupDeviceCount(groupName, groupOwner); - page.groupOwner = groupOwner; } else { deviceCount = deviceModule.getDevicesCount(); } 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 ae7a5fcaa5..e8b20bd5c8 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 @@ -61,10 +61,18 @@ function InitiateViewOption(url) { var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; var assetContainer = "#ast-container"; +var deviceListing, currentUser, groupName, groupOwner; + /* * DOM ready functions. */ $(document).ready(function () { + deviceListing = $("#device-listing"); + deviceListing.data("current-user"); + + groupName = getParameterByName("groupName"); + groupOwner = getParameterByName("groupOwner"); + /* Adding selected class for selected devices */ $(deviceCheckbox).each(function () { addDeviceSelectedClass(this); @@ -88,8 +96,6 @@ $(document).ready(function () { $(".ast-container").on("click", ".claim-btn", function(e){ e.stopPropagation(); var deviceId = $(this).data("deviceid"); - var deviceListing = $("#device-listing"); - var currentUser = deviceListing.data("current-user"); var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser; var deviceIdentifier = {id: deviceId, type: "TemperatureController"}; invokerUtil.put(serviceURL, deviceIdentifier, function(message){ @@ -161,10 +167,6 @@ function toTitleCase(str) { } function loadDevices(searchType, searchParam){ - var deviceListing = $("#device-listing"); - var imageResource = deviceListing.data("image-resource"); - var currentUser = deviceListing.data("currentUser"); - var serviceURL; if ($.hasPermission("LIST_DEVICES")) { serviceURL = "/devicemgt_admin/devices"; @@ -304,6 +306,15 @@ function loadDevices(searchType, searchParam){ 'data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' + '' + ''; + + if (!groupName || !groupOwner) { + html += '' + + '' + + ''; + } + html += '' + '' + @@ -370,12 +381,6 @@ function loadDevices(searchType, searchParam){ }); } -/* - * Setting-up global variables. - */ -var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; -var assetContainer = "#ast-container"; - function openCollapsedNav() { $('.wr-hidden-nav-toggle-btn').addClass('active'); $('#hiddenNav').slideToggle('slideDown', function () { @@ -386,14 +391,12 @@ function openCollapsedNav() { } function initPage() { - var deviceListing = $("#device-listing"); - var currentUser = deviceListing.data("currentUser"); 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"; + serviceURL = "/devicemgt_admin/devices/user/" + currentUser + "/count"; } invokerUtil.get(serviceURL, function (data) { @@ -442,8 +445,6 @@ $(document).ready(function () { $(".ast-container").on("click", ".claim-btn", function(e) { e.stopPropagation(); var deviceId = $(this).data("deviceid"); - var deviceListing = $("#device-listing"); - var currentUser = deviceListing.data("current-user"); var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser; var deviceIdentifier = {id: deviceId, type: "TemperatureController"}; invokerUtil.put(serviceURL, deviceIdentifier, function(message) { @@ -516,72 +517,51 @@ function attachDeviceEvents() { $("a.group-device-link").click(function () { var deviceId = $(this).data("deviceid"); var deviceType = $(this).data("devicetype"); - var endPoint = "api/group/all"; - $(modalPopupContent).html($('#group-device-modal-content').html()); $('#user-groups').html('
'); $("a#group-device-yes-link").hide(); showPopup(); - var getGroupsRequest = $.ajax({ - url: endPoint, - method: "GET", - contentType: "application/json", - accept: "application/json" - }); - - getGroupsRequest.done(function (data, txtStatus, jqxhr) { - var groups = JSON.parse(data); - var status = jqxhr.status; - if (status == 200) { - groups = groups.data; - if (groups.length <= 0) { - $('#user-groups').html("There is no any groups available"); - return; - } - var str = '
'; - $('#user-groups').html(str); - $("a#group-device-yes-link").show(); - $("a#group-device-yes-link").click(function () { - var selectedGroupId = $('#assign-group-selector').val(); - endPoint = "api/group/id/" + selectedGroupId + "/assign"; - var device = {"deviceId": deviceId, "deviceType": deviceType}; - - var assignRequest = $.ajax({ - url: endPoint, - method: "POST", - contentType: "application/json", - accept: "application/json", - data: JSON.stringify(device) - }); - - assignRequest.done(function (data, txtStatus, jqxhr) { - var status = jqxhr.status; - if (status == 200) { - $(modalPopupContent).html($('#group-associate-device-200-content').html()); - setTimeout(function () { - hidePopup(); - location.reload(false); - }, 2000); - } else { - displayDeviceErrors(jqXHR); - } - } - ); - assignRequest.fail(function (jqXHR) { - displayDeviceErrors(jqXHR); - }); - }); - } - } - ); - getGroupsRequest.fail(function (jqXHR) { + var serviceURL; + if ($.hasPermission("LIST_ALL_GROUPS")) { + serviceURL = "/devicemgt_admin/groups/all"; + } else if ($.hasPermission("LIST_GROUPS")) { + //Get authenticated users groups + serviceURL = "/devicemgt_admin/groups/user/" + currentUser; + } + + invokerUtil.get(serviceURL, function (data) { + var groups = JSON.parse(data); + if (groups.length <= 0) { + $('#user-groups').html("There is no any groups available"); + return; + } + var str = '
'; + $('#user-groups').html(str); + $("a#group-device-yes-link").show(); + $("a#group-device-yes-link").click(function () { + var selectedGroup = $('#assign-group-selector').val(); + serviceURL = "/devicemgt_admin/groups/owner/" + selectedGroup + "/devices"; + var device = {"id": deviceId, "type": deviceType}; + invokerUtil.post(serviceURL, device, function (data) { + $(modalPopupContent).html($('#group-associate-device-200-content').html()); + setTimeout(function () { + hidePopup(); + location.reload(false); + }, 2000); + }, function (message) { + displayDeviceErrors(jqXHR); + }); + }); + }, function (message) { displayDeviceErrors(jqXHR); }); + $("a#group-device-cancel-link").click(function () { hidePopup(); }); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf index 1ee17c2028..d18daaa172 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/jaggery.conf @@ -11,10 +11,6 @@ "url": "/api/group/*", "path": "/api/group-api.jag" }, - { - "url": "/api/stats/*", - "path": "/api/stats-api.jag" - }, { "url": "/api/operations/*", "path": "/api/operation-api.jag"