diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index d154e8ae91..462f403693 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 @@ -11,15 +11,18 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.wso2.carbon.device.mgt.core.dao; -import org.wso2.carbon.device.mgt.common.*; +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.EnrolmentInfo.Status; +import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.util.HashMap; @@ -211,6 +214,16 @@ public interface DeviceDAO { */ List getDevicesOfUser(PaginationRequest request, int tenantId) throws DeviceManagementDAOException; + /** + * This method is used to retrieve the device count of a given tenant. + * + * @param username user name. + * @param tenantId tenant id. + * @return returns the device count. + * @throws DeviceManagementDAOException + */ + int getDeviceCount(String username, int tenantId) throws DeviceManagementDAOException; + /** * This method is used to retrieve the device count of a given tenant. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 5b9fe78f4b..868d070d24 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 @@ -11,7 +11,7 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -29,11 +29,15 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.DeviceType; -import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.Date; -import java.util.Iterator; import java.util.HashMap; +import java.util.Iterator; import java.util.List; public abstract class AbstractDeviceDAOImpl implements DeviceDAO { @@ -331,6 +335,39 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { return DeviceManagementDAOFactory.getConnection(); } + /** + * Get device count of user. + * + * @return device count + * @throws DeviceManagementDAOException + */ + @Override + public int getDeviceCount(String username, int tenantId) throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + int deviceCount = 0; + try { + conn = this.getConnection(); + String sql = "SELECT COUNT(d1.DEVICE_ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID FROM " + + "DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE " + + "d1.DEVICE_ID = e.DEVICE_ID AND e.OWNER = ? AND TENANT_ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, tenantId); + stmt.setString(2, username); + stmt.setInt(3, tenantId); + rs = stmt.executeQuery(); + if (rs.next()) { + deviceCount = rs.getInt("DEVICE_COUNT"); + } + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while getting the device count", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, rs); + } + return deviceCount; + } + /** * Get device count of all devices. * 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 00b3a8bbad..819d676dc7 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 @@ -237,7 +237,7 @@ public class GroupDAOImpl implements GroupDAO { List deviceGroups = new ArrayList<>(); try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT DESCRIPTION, GROUP_NAME, DATE_OF_CREATE, DATE_OF_LAST_UPDATE, OWNER " + String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, DATE_OF_CREATE, DATE_OF_LAST_UPDATE, OWNER " + "FROM DM_GROUP WHERE GROUP_NAME LIKE ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, "%" + groupName + "%"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupManagementDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupManagementDAOUtil.java index 775ee264d6..9a206c7b71 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupManagementDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/group/mgt/dao/GroupManagementDAOUtil.java @@ -82,6 +82,7 @@ public final class GroupManagementDAOUtil { public static DeviceGroupBuilder loadGroup(ResultSet resultSet) throws SQLException { DeviceGroupBuilder group = new DeviceGroupBuilder(new DeviceGroup()); + group.setGroupId(resultSet.getInt("ID")); group.setDescription(resultSet.getString("DESCRIPTION")); group.setName(resultSet.getString("GROUP_NAME")); group.setDateOfCreation(resultSet.getLong("DATE_OF_CREATE")); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 0c307f6e0e..1a6cd8b7e8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 @@ -11,13 +11,19 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.wso2.carbon.device.mgt.core.service; -import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.FeatureManager; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; @@ -112,6 +118,15 @@ public interface DeviceManagementProviderService extends OperationManager { */ List getAllDevicesOfRole(String roleName) throws DeviceManagementException; + /** + * Method to get the device count of user. + * + * @return device count + * @throws DeviceManagementException If some unusual behaviour is observed while counting + * the devices + */ + int getDeviceCount(String username) throws DeviceManagementException; + /** * Method to get the count of all types of devices. * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 91dd6de9dc..73487be49c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 @@ -11,7 +11,7 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -20,7 +20,16 @@ package org.wso2.carbon.device.mgt.core.service; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; -import org.wso2.carbon.device.mgt.common.*; +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.DeviceManager; +import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier; +import org.wso2.carbon.device.mgt.common.EnrolmentInfo; +import org.wso2.carbon.device.mgt.common.FeatureManager; +import org.wso2.carbon.device.mgt.common.PaginationRequest; +import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.TransactionManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration; import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; @@ -28,7 +37,11 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService; import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; -import org.wso2.carbon.device.mgt.core.dao.*; +import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; +import org.wso2.carbon.device.mgt.core.dao.EnrollmentDAO; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent; @@ -38,18 +51,23 @@ import org.wso2.carbon.email.sender.core.TypedValue; import org.wso2.carbon.user.api.UserStoreException; import java.sql.SQLException; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, PluginInitializationListener { + private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class); private DeviceDAO deviceDAO; private DeviceTypeDAO deviceTypeDAO; private EnrollmentDAO enrollmentDAO; private DeviceManagementPluginRepository pluginRepository; - private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class); - public DeviceManagementProviderServiceImpl() { this.pluginRepository = new DeviceManagementPluginRepository(); initDataAccessObjects(); @@ -1012,6 +1030,21 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return devices; } + @Override + public int getDeviceCount(String username) throws DeviceManagementException { + try { + DeviceManagementDAOFactory.openConnection(); + return deviceDAO.getDeviceCount(username, this.getTenantId()); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while retrieving the device count of user '" + + username + "'", e); + } catch (SQLException e) { + throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + } + @Override public int getDeviceCount() throws DeviceManagementException { try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java index dcc9e4e134..6c64b7cf03 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderService.java @@ -93,6 +93,17 @@ public interface GroupManagementProviderService { */ PaginationResult getGroups(int startIndex, int rowCount) throws GroupManagementException; + /** + * Get paginated device groups in tenant + * + * @param username of user. + * @param startIndex for pagination. + * @param rowCount for pagination. + * @return paginated list of groups + * @throws GroupManagementException + */ + PaginationResult getGroups(String username, int startIndex, int rowCount) throws GroupManagementException; + /** * Get all device group count in tenant * diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 38a4b85212..fabbaceb96 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -263,6 +263,34 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid return paginationResult; } + @Override + public PaginationResult getGroups(String username, int startIndex, int rowCount) throws GroupManagementException { + Map groups = new HashMap<>(); + UserStoreManager userStoreManager; + try { + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId) + .getUserStoreManager(); + String[] roleList = userStoreManager.getRoleListOfUser(username); + int index = 0; + for (String role : roleList) { + if (role != null && role.contains("Internal/group-")) { + DeviceGroupBuilder deviceGroupBuilder = extractNewGroupFromRole(groups, role); + if (deviceGroupBuilder != null && startIndex <= index++ && index <= rowCount) { + groups.put(deviceGroupBuilder.getGroupId(), deviceGroupBuilder.getGroup()); + } + } + } + } catch (UserStoreException e) { + throw new GroupManagementException("Error occurred while getting user store manager.", e); + } + PaginationResult paginationResult = new PaginationResult(); + paginationResult.setRecordsTotal(getGroupCount()); + paginationResult.setData(new ArrayList<>(groups.values())); + paginationResult.setRecordsFiltered(groups.size()); + return paginationResult; + } + @Override public int getGroupCount() throws GroupManagementException { try { @@ -563,7 +591,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid public List getDevices(String groupName, String owner) throws GroupManagementException { try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); - GroupManagementDAOFactory.getConnection(); + GroupManagementDAOFactory.openConnection(); return this.groupDAO.getDevices(groupName, owner, tenantId); } catch (GroupManagementDAOException e) { throw new GroupManagementException("Error occurred while getting devices in group.", e); @@ -583,7 +611,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); List devices; try { - GroupManagementDAOFactory.getConnection(); + GroupManagementDAOFactory.openConnection(); devices = this.groupDAO.getDevices(groupName, owner, startIndex, rowCount, tenantId); } catch (GroupManagementDAOException e) { throw new GroupManagementException("Error occurred while getting devices in group.", e); @@ -606,7 +634,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid public int getDeviceCount(String groupName, String owner) throws GroupManagementException { try { int count; - GroupManagementDAOFactory.getConnection(); + GroupManagementDAOFactory.openConnection(); count = groupDAO.getDeviceCount(groupName, owner, CarbonContext.getThreadLocalCarbonContext().getTenantId()); return count; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js index 316887d68a..9aeb2e84de 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/backend-service-invoker.js @@ -77,7 +77,7 @@ var backendServiceInvoker = function () { if (xmlHttpRequest.responseText != null) { return successCallback(parse(xmlHttpRequest.responseText)); } else { - return successCallback({"statusCode": 200, "messageFromServer": "Operation Completed"}); + return successCallback({"status": xmlHttpRequest.status, "messageFromServer": "Operation Completed"}); } } else if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED || xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js index be709b11a3..bd7ca11999 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/device.js @@ -348,6 +348,22 @@ deviceModule = function () { return result; }; + publicMethods.getOwnDevicesCount = function () { + var carbonUser = session.get(constants.USER_SESSION_KEY); + var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/user/" + carbonUser.username + + "/count"; + return serviceInvokers.XMLHttp.get( + url, function (responsePayload) { + return responsePayload; + } + , + function (responsePayload) { + log.error(responsePayload); + return -1; + } + ); + }; + publicMethods.getAllDevicesCount = function () { var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/count"; return serviceInvokers.XMLHttp.get( 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 0632d2a998..37894ac2a3 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 @@ -25,14 +25,28 @@ var groupModule = {}; var utility = require("/app/modules/utility.js").utility; var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker; - var deviceCloudService = devicemgtProps["httpsURL"] + "/common/group_manager"; + var groupServiceEndpoint = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/groups"; var user = session.get(constants.USER_SESSION_KEY); var endPoint; groupModule.getGroupCount = function () { - endPoint = deviceCloudService + "/groups/count?userName=" + user.username; + endPoint = groupServiceEndpoint + "/user/" + user.username + "/count"; + return serviceInvokers.XMLHttp.get( + endPoint, function (responsePayload) { + return responsePayload; + } + , + function (responsePayload) { + log.error(responsePayload); + return -1; + } + ); + }; + + groupModule.getGroupDeviceCount = function (groupName, owner) { + endPoint = groupServiceEndpoint + "/" + owner + "/" + 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 195e010166..a15a5a84b1 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 @@ -60,8 +60,273 @@
{{unit "cdmf.unit.device.operation-mod"}} - {{unit "cdmf.unit.device.listing"}} + {{#if deviceCount}} + +
+ +     + Loading devices . . . +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ + {{else}} +
+ +
+ {{/if}} + +
+ +
+ +
+ +
+ +
+ +
+ +
+
+
+
+

Do you really want to remove this device from your Devices List?

+ + +
+
+
+
+ +
+
+
+
+

Device was successfully removed.

+
+
+
+
+ +
+
+
+
+

Please enter new name for the device?

+
+ +
+ +
+ +
+
+
+
+ +
+
+
+
+

Device was successfully updated.

+
+
+
+
+ +
+ +
+ +
+ +
+ +
+ +
+{{/zone}} + +{{#zone "bottomJs"}} + + {{js "js/listing.js"}} {{/zone}} \ No newline at end of file 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 50480ab828..88cb32d704 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 @@ -18,19 +18,61 @@ function onRequest(context) { var constants = require("/app/modules/constants.js"); - var page = {}; + var userModule = require("/app/modules/user.js").userModule; + var deviceModule = require("/app/modules/device.js").deviceModule; + var groupName = request.getParameter("groupName"); + var groupOwner = request.getParameter("groupOwner"); + + var page = {}; var title = "Devices"; if (groupName) { title = groupName + " " + title; page.groupName = groupName; } - page.title =title; + page.title = title; page.permissions = {}; var currentUser = session.get(constants.USER_SESSION_KEY); + var permissions = []; if (currentUser) { + if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) { + permissions.push("LIST_DEVICES"); + } else if (userModule.isAuthorized("/permission/admin/device-mgt/user/devices/list")) { + permissions.push("LIST_OWN_DEVICES"); + } else if (userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/list")) { + permissions.push("LIST_POLICIES"); + } if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/add")) { - page.permissions.enroll = true; + permissions.enroll = true; + } + if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/remove")) { + permissions.push("REMOVE_DEVICE"); + } + + page.permissions.list = permissions; + page.currentUser = currentUser; + var deviceCount = 0; + if (groupName && groupOwner) { + var groupModule = require("/app/modules/group.js").groupModule; + deviceCount = groupModule.getGroupDeviceCount(groupName, groupOwner); + page.groupOwner = groupOwner; + } else { + deviceCount = deviceModule.getOwnDevicesCount(); + } + if (deviceCount > 0) { + page.deviceCount = deviceCount; + var utility = require("/app/modules/utility.js").utility; + var data = deviceModule.getDeviceTypes(); + var deviceTypes = []; + if (data.data) { + for (var i = 0; i < data.data.length; i++) { + deviceTypes.push({ + "type": data.data[i].name, + "category": utility.getDeviceTypeConfig(data.data[i].name).deviceType.category + }); + } + } + page.deviceTypes = deviceTypes; } } return page; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.listing/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 similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.listing/public/js/listing.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.listing/public/templates/listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/templates/listing.hbs similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.listing/public/templates/listing.hbs rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/templates/listing.hbs diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs index b42f90ceea..8852bbd67e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs @@ -54,59 +54,11 @@ -
+
-
- -
- -
- -
- -
- -
-