Merge pull request #209 from charithag/master

Fixing UI and implementation issues occurred after restructuring.
merge-requests/7/head
Ruwan 9 years ago
commit de8967c5a7

@ -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
@ -18,8 +18,11 @@
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<Device> 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.
*

@ -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
@ -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.
*

@ -237,7 +237,7 @@ public class GroupDAOImpl implements GroupDAO {
List<DeviceGroupBuilder> 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 + "%");

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 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
@ -14,7 +14,6 @@
* 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.group.mgt.dao;
@ -39,7 +38,7 @@ public class GroupManagementDAOFactory {
private static final Log log = LogFactory.getLog(GroupManagementDAOFactory.class);
private static DataSource dataSource;
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<>();
/**
* Get instance of GroupDAO
@ -162,7 +161,8 @@ public class GroupManagementDAOFactory {
Connection conn = currentConnection.get();
if (conn == null) {
throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
"This might have ideally been caused by not properly initiating the transaction via " +
"This might have ideally been caused by not properly " +
"initiating the transaction via " +
"'beginTransaction'/'openConnection' methods");
}
try {

@ -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"));

@ -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
@ -43,6 +43,7 @@ import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.tenant.TenantConfigurationManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.group.mgt.dao.GroupManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl;
@ -53,7 +54,6 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceIm
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
import org.wso2.carbon.email.sender.core.service.EmailSenderService;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
@ -103,14 +103,32 @@ import java.util.List;
*/
public class DeviceManagementServiceComponent {
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
private static final Object LOCK = new Object();
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
private static List<PluginInitializationListener> listeners = new ArrayList<>();
private static List<DeviceManagementService> deviceManagers = new ArrayList<>();
private static List<DeviceManagerStartupListener> startupListeners = new ArrayList<>();
private DeviceManagementPluginRepository pluginRepository = new DeviceManagementPluginRepository();
public static void registerPluginInitializationListener(PluginInitializationListener listener) {
synchronized (LOCK) {
listeners.add(listener);
for (DeviceManagementService deviceManagementService : deviceManagers) {
listener.registerDeviceManagementService(deviceManagementService);
}
}
}
public static void registerStartupListener(DeviceManagerStartupListener startupListener) {
startupListeners.add(startupListener);
}
public static void notifyStartupListeners() {
for (DeviceManagerStartupListener startupListener : startupListeners) {
startupListener.notifyObserver();
}
}
@SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) {
try {
@ -124,6 +142,7 @@ public class DeviceManagementServiceComponent {
DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig();
DeviceManagementDAOFactory.init(dsConfig);
GroupManagementDAOFactory.init(dsConfig);
NotificationManagementDAOFactory.init(dsConfig);
OperationManagementDAOFactory.init(dsConfig);
@ -159,15 +178,6 @@ public class DeviceManagementServiceComponent {
//do nothing
}
public static void registerPluginInitializationListener(PluginInitializationListener listener) {
synchronized (LOCK) {
listeners.add(listener);
for (DeviceManagementService deviceManagementService : deviceManagers) {
listener.registerDeviceManagementService(deviceManagementService);
}
}
}
private void initOperationsManager() throws OperationManagementException {
OperationManager operationManager = new OperationManagerImpl();
DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
@ -349,14 +359,4 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setConfigurationContextService(null);
}
public static void registerStartupListener(DeviceManagerStartupListener startupListener) {
startupListeners.add(startupListener);
}
public static void notifyStartupListeners() {
for (DeviceManagerStartupListener startupListener : startupListeners) {
startupListener.notifyObserver();
}
}
}

@ -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
@ -17,7 +17,13 @@
*/
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<Device> 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.
*

@ -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
@ -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 {

@ -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
*

@ -263,6 +263,34 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
return paginationResult;
}
@Override
public PaginationResult getGroups(String username, int startIndex, int rowCount) throws GroupManagementException {
Map<Integer, DeviceGroup> 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<Device> 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<Device> 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;

@ -20,7 +20,7 @@
* This backendServiceInvoker contains the wrappers for back end jaggary calls.
*/
var backendServiceInvoker = function () {
var log = new Log("/app/modules/backend-service-invoker.js")
var log = new Log("/app/modules/backend-service-invoker.js");
var publicXMLHTTPInvokers = {};
var privateMethods = {};
var publicWSInvokers = {};
@ -72,14 +72,12 @@ var backendServiceInvoker = function () {
} else {
xmlHttpRequest.send();
}
log.debug("Service Invoker-URL: " + url);
log.debug("Service Invoker-Method: " + method);
if ((xmlHttpRequest.status >= 200 && xmlHttpRequest.status < 300) || xmlHttpRequest.status == 302) {
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) {
@ -188,7 +186,7 @@ var backendServiceInvoker = function () {
privateMethods.initiateWSRequest = function (action, endpoint, successCallback, errorCallback, soapVersion, payload) {
var ws = require('ws');
var wsRequest = new ws.WSRequest();
var options = new Array();
var options = [];
if (IS_OAUTH_ENABLED) {
var accessToken = privateMethods.getAccessToken();
if (accessToken) {

@ -274,7 +274,7 @@ deviceModule = function () {
utility.startTenantFlow(carbonUser);
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/view?type=" + deviceType + "&id=" + deviceId;
var dataNew = serviceInvokers.XMLHttp.get(
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
var device = responsePayload.responseContent;
if (device) {
@ -307,7 +307,6 @@ deviceModule = function () {
return response;
}
);
return dataNew;
} catch (e) {
throw e;
} finally {
@ -351,25 +350,32 @@ deviceModule = function () {
publicMethods.getOwnDevicesCount = function () {
var carbonUser = session.get(constants.USER_SESSION_KEY);
var listAllDevicesEndPoint = deviceCloudService + "/device/user/" + carbonUser.username + "/all/count";
return get(listAllDevicesEndPoint, {}, "json").data;
};
publicMethods.getUnGroupedDevices = function () {
var carbonUser = session.get(constants.USER_SESSION_KEY);
var listAllDevicesEndPoint = deviceCloudService + "/device/user/" + carbonUser.username + "/ungrouped";
return get(listAllDevicesEndPoint, {}, "json").data;
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.getUnGroupedDevicesCount = function () {
var result = publicMethods.getUnGroupedDevices();
var devices = result.data;
var count = 0;
if (devices) {
count = devices.length;
publicMethods.getAllDevicesCount = function () {
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/count";
return serviceInvokers.XMLHttp.get(
url, function (responsePayload) {
return responsePayload;
}
result.data = count;
return result;
,
function (responsePayload) {
log.error(responsePayload);
return -1;
}
);
};
publicMethods.getAllPermittedDevices = function () {

@ -23,169 +23,40 @@ var groupModule = {};
var constants = require('/app/modules/constants.js');
var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
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 deviceModule = require("/app/modules/device.js").deviceModule;
var endPoint, data, response;
groupModule.addGroup = function (group) {
var name = group["name"];
var description = group["description"];
//URL: POST https://localhost:9443/devicecloud/group_manager/group
endPoint = deviceCloudService + "/group";
data = {"name": name, "username": user.username, "description": description};
return post(endPoint, data, "json");
};
groupModule.updateGroup = function (groupId, group) {
var name = group["name"];
var description = group["description"];
//URL: PUT https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
endPoint = deviceCloudService + "/group/id/" + groupId;
data = {"name": name, "username": user.username, "description": description};
return put(endPoint, data, "json");
};
groupModule.removeGroup = function (groupId) {
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
endPoint = deviceCloudService + "/group/id/" + groupId + "?username=" + user.username;
return del(endPoint, {}, "json");
};
groupModule.getGroup = function (groupId) {
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}
endPoint = deviceCloudService + "/group/id/" + groupId;
data = {"username": user.username};
return get(endPoint, data, "json");
};
groupModule.findGroups = function (name) {
//URL: GET https://localhost:9443/devicecloud/group_manager/group/name/{name}
endPoint = deviceCloudService + "/group/name/" + name;
data = {"username": user.username};
return get(endPoint, data, "json");
};
groupModule.getGroups = function () {
//URL: GET https://localhost:9443/devicecloud/group_manager/group/all
endPoint = deviceCloudService + "/group/user/" + user.username + "/all";
data = {"username": user.username};
return get(endPoint, data, "json");
};
var endPoint;
groupModule.getGroupCount = function () {
//URL: GET https://localhost:9443/devicecloud/group_manager/group/all/count
endPoint = deviceCloudService + "/group/user/" + user.username + "/all/count";
data = {"username": user.username};
response = get(endPoint, data, "json");
if (response) {
return response.data;
} else {
return -1;
}
};
groupModule.shareGroup = function (groupId, shareUser, role) {
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share
endPoint = deviceCloudService + "/group/id/" + groupId + "/share";
data = {"username": user.username, "shareUser": shareUser, "role": role};
return post(endPoint, data, "json");
};
groupModule.unshareGroup = function (groupId, shareUser, role) {
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/unshare
endPoint = deviceCloudService + "/group/id/" + groupId + "/unshare";
data = {"username": user.username, "unShareUser": unShareUser, "role": role};
return post(endPoint, data, "json");
};
groupModule.addRole = function (groupId, role, permissions) {
//URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role
endPoint = deviceCloudService + "/group/id/" + groupId + "/role";
data = {"username": user.username, "permissions": permissions, "role": role};
return post(endPoint, data, "json");
};
groupModule.deleteRole = function (groupId, role) {
//URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role
endPoint = deviceCloudService + "/group/id/" + groupId + "/role/" + role;
return del(endPoint, {}, "json");
};
groupModule.getGroupRoles = function (groupId) {
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role/all
endPoint = deviceCloudService + "/group/id/" + groupId + "/role/all";
data = {"username": user.username};
return get(endPoint, data, "json");
};
groupModule.getUserRoles = function (groupId, userId) {
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/{user}/role/all
endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId + "/role/all";
data = {"username": user.username};
return get(endPoint, data, "json");
};
groupModule.getRoleMapping = function (groupId, userId) {
var allRoles = groupModule.getGroupRoles(groupId).data;
var userRolesObj = groupModule.getUserRoles(groupId, userId);
var userRoles = userRolesObj.data;
var roleMap = [];
for (var role in allRoles) {
var objRole = {"role": allRoles[role], "assigned": false};
for (var usrRole in userRoles) {
if (allRoles[role] == userRoles[usrRole]) {
objRole.assigned = true;
break;
}
endPoint = groupServiceEndpoint + "/user/" + user.username + "/count";
return serviceInvokers.XMLHttp.get(
endPoint, function (responsePayload) {
return responsePayload;
}
roleMap.push(objRole);
,
function (responsePayload) {
log.error(responsePayload);
return -1;
}
var result = {};
result.data = roleMap;
result.xhr = userRolesObj.xhr;
return result;
);
};
groupModule.setRoleMapping = function (groupId, userId, roleMap) {
var result;
for (var role in roleMap) {
if (roleMap[role].assigned == true) {
result = groupModule.shareGroup(groupId,userId,roleMap[role].role);
} else {
result = groupModule.unshareGroup(groupId,userId,roleMap[role].role);
}
groupModule.getGroupDeviceCount = function (groupName, owner) {
endPoint = groupServiceEndpoint + "/" + owner + "/" + groupName + "/devices/count";
return serviceInvokers.XMLHttp.get(
endPoint, function (responsePayload) {
return responsePayload;
}
return result;
};
groupModule.getUsers = function (groupId) {
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/user/all
endPoint = deviceCloudService + "/group/id/" + groupId + "/user/all";
data = {"username": user.username};
return get(endPoint, data, "json");
};
groupModule.getDevices = function (groupId) {
var result = groupModule.getGroup(groupId);
var group = result.data;
if (group) {
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/all
endPoint = deviceCloudService + "/group/id/" + groupId + "/device/all";
data = {"username": user.username};
result = get(endPoint, data, "json");
,
function (responsePayload) {
log.error(responsePayload);
return -1;
}
return result;
};
groupModule.assignDevice = function (groupId, deviceId, deviceType) {
//URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/assign
endPoint = deviceCloudService + "/group/id/" + groupId + "/device/assign";
data = {"username": user.username, "deviceId": deviceId, "deviceType": deviceType};
return put(endPoint, data, "json");
);
};
}(groupModule));

@ -53,7 +53,7 @@ var userModule = function () {
throw constants.ERRORS.USER_NOT_FOUND;
}
return carbonUser;
}
};
/**
* Only GET method is implemented for now since there are no other type of methods used this method.
@ -436,7 +436,7 @@ var userModule = function () {
} finally {
utility.endTenantFlow();
}
}
};
/*
@NewlyAdded
@ -629,44 +629,44 @@ var userModule = function () {
publicMethods.getUIPermissions = function () {
var permissions = {};
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/devices/list") ||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/devices/list") ||
publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
permissions["LIST_DEVICES"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/list")) {
permissions["LIST_GROUPS"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/list")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/users/list")) {
permissions["LIST_USERS"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/list")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/roles/list")) {
permissions["LIST_ROLES"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/list")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/list")) {
permissions["LIST_POLICIES"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/groups/add")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/groups/add")) {
permissions["ADD_GROUP"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/add")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/users/add")) {
permissions["ADD_USER"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/users/remove")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/users/remove")) {
permissions["REMOVE_USER"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/add")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/roles/add")) {
permissions["ADD_ROLE"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/add")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/add")) {
permissions["ADD_POLICY"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/priority")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/priority")) {
permissions["CHANGE_POLICY_PRIORITY"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/dashboard/view")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/dashboard/view")) {
permissions["VIEW_DASHBOARD"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/platform-configs/view")) {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/emm-admin/platform-configs/view")) {
permissions["TENANT_CONFIGURATION"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {

@ -10,5 +10,177 @@
{{/zone}}
{{#zone "content"}}
{{unit "cdmf.unit.dashboard"}}
<div class="wr-content">
{{#if permissions.VIEW_DASHBOARD}}
<div class="row wr-stats-board">
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Devices</div>
<div>
<div class="tile-icon"><i class="fw fw-mobile"></i></div>
<div class="tile-stats">
<span id="device-count">{{device_count}}</span>
<span class="tile-stats-free">
<a href="{{@app.context}}/devices">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
<a href="{{@app.context}}/device/enroll">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="row wr-stats-board">
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Groups</div>
<div>
<div class="tile-icon"><i class="fw fw-grouping"></i></div>
<div class="tile-stats">
<span id="group-count">{{group_count}}</span>
<span class="tile-stats-free">
<a href="{{@app.context}}/groups">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
<a href="{{@app.context}}/group/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="row wr-stats-board">
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Users</div>
<div>
<div class="tile-icon"><i class="fw fw-user"></i></div>
<div class="tile-stats">
<span id="user-count">{{user_count}}</span>
<span class="tile-stats-free">
<a href="{{@app.context}}/users">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
<a href="{{@app.context}}/user/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="row wr-stats-board">
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Policies</div>
<div>
<div class="tile-icon"><i class="fw fw-policy"></i></div>
<div class="tile-stats">
<span id="policy-count">{{policy_count}}</span>
<span class="tile-stats-free">
<a href="{{@app.context}}/policies">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
<a href="{{@app.context}}/policy/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="row wr-stats-board">
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Roles</div>
<div>
<div class="tile-icon"><i class="fw fw-bookmark"></i></div>
<div class="tile-stats">
<span id="role-count">{{role_count}}</span>
<span class="tile-stats-free">
<a id="device-count-view-btn" href="{{@app.context}}/roles">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
<a href="{{@app.context}}/roles/add-role">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span>
</div>
</div>
</div>
</div>
</div>
{{else}}
Permission denied
{{/if}}
</div>
<div id="qr-code-modal" data-enrollment-url="{{enrollmentURL}}" class="hidden">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
Scan QR code to start enrollment
</h3>
<h4>
Please scan the QR code using your mobile device to retrieve enrollment URL.
</h4>
<div class="panel panel-default">
<div class="panel-body col-centered ">
<div class="qr-code"></div>
</div>
</div>
</div>
</div>
</div>
</div>
{{/zone}}

@ -35,7 +35,7 @@ function onRequest(context) {
var groupModule = require("/app/modules/group.js").groupModule;
var policyModule = require("/app/modules/policy.js").policyModule;
page.device_count = deviceModule.getOwnDevicesCount();
page.device_count = deviceModule.getAllDevicesCount();
page.group_count = groupModule.getGroupCount();
page.user_count = userModule.getUsers()["content"].length;
page.policy_count = policyModule.getAllPolicies()["content"].length;

@ -60,8 +60,273 @@
<div class="col-md-12 wr-page-content">
<div>
{{unit "cdmf.unit.device.operation-mod"}}
{{unit "cdmf.unit.device.listing"}}
{{#if deviceCount}}
<span id="permission" data-permission="{{{permissions}}}"></span>
<div id="loading-content" class="col-centered">
<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading devices . . .
<br>
</div>
<div id="device-listing-status" class="raw hidden">
<ul style="list-style-type: none;">
<li class="message message-info">
<h4>
<i class="icon fw fw-info"></i>
<a id="device-listing-status-msg"></a>
</h4>
</li>
</ul>
</div>
<div id="device-table">
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
id="device-grid">
<thead>
<tr class="sort-row">
<th class="no-sort"></th>
<th>By Device Name</th>
<th>By Owner</th>
<th>By Status</th>
<th>By Platform</th>
<th>By Ownership</th>
<th class="no-sort"></th>
</tr>
<tr class="filter-row filter-box">
<th class="no-sort"></th>
<th data-for="By Device name" class="text-filter"></th>
<th data-for="By Owner" class="text-filter"></th>
<th data-for="By Status" class="select-filter"></th>
<th data-for="By Platform" class="select-filter data-platform"></th>
<th data-for="By Ownership" class="select-filter"></th>
<th class="no-sort"></th>
</tr>
<tr class="bulk-action-row">
<th colspan="7">
<div id="operation-bar" class="hidden">
{{unit "mdm.unit.device.operation-bar"}}
</div>
<div id="operation-guide" class="bs-callout bs-callout-info">
<h4>Enabling Device Operations</h4>
<p>To enable device operations, select the desired platform from above
filter.</p>
</div>
</th>
</tr>
</thead>
<tbody id="ast-container">
<br class="c-both"/>
</tbody>
</table>
</div>
<br class="c-both"/>
<div id="content-filter-types" style="display: none">
<div class="sort-title">Sort By</div>
<div class="sort-options">
<a href="#">By Device Name<span class="ico-sort-asc"></span></a>
<a href="#">By Owner</a>
<a href="#">By Status</a>
<a href="#">By Platform</a>
<a href="#">By Ownership</a>
</div>
</div>
{{else}}
<div id="ast-container" class="ast-container list-view">
<div class="ctrl-info-panel col-centered text-center wr-login">
<h2>You don't have any device
{{#if groupName}}
assigned to this group
{{else}}
registered
{{/if}}
at the moment.</h2>
<br/>
<p class="text-center">
{{#if groupName}}
<a href="{{@app.context}}/devices" class="wr-btn">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Assign from My Devices
</a>
{{else}}
<a href="{{@app.context}}/device/enroll" class="wr-btn">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Enroll New Device
</a>
{{/if}}
</p>
</div>
</div>
{{/if}}
<div id="group-device-modal-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-3 col-centered">
<h3>Please select group</h3>
<div id="user-groups">Loading...</div>
<div class="buttons">
<a href="#" id="group-device-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Assign&nbsp;&nbsp;&nbsp;&nbsp;
</a>
&nbsp;&nbsp;
<a href="#" id="group-device-cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="group-associate-device-200-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-3 col-centered">
<h3>Device was successfully associated with group.</h3>
</div>
</div>
</div>
</div>
<div id="group-deassociate-device-200-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-3 col-centered">
<h3>Device was successfully removed from group.</h3>
</div>
</div>
</div>
</div>
<div id="remove-device-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to remove this device from your Devices List?</h3>
<div class="buttons">
<a href="#" id="remove-device-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Yes&nbsp;&nbsp;&nbsp;&nbsp;
</a>
&nbsp;&nbsp;
<a href="#" id="remove-device-cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-device-200-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Device was successfully removed.</h3>
</div>
</div>
</div>
</div>
<div id="edit-device-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Please enter new name for the device?</h3>
<br/>
<div>
<input id="edit-device-name" style="color:#3f3f3f;padding:5px" type="text"
value=""
placeholder="Type here" size="60">
</div>
<div class="buttons">
<a href="#" id="edit-device-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Rename&nbsp;&nbsp;&nbsp;&nbsp;
</a>
&nbsp;&nbsp;
<a href="#" id="edit-device-cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="edit-device-200-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Device was successfully updated.</h3>
</div>
</div>
</div>
</div>
<div id="device-400-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>Exception at backend. Try Later.</h3>
<br/>
<div class="buttons">
<a href="#" id="device-400-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="device-403-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>Operation not permitted.</h3>
<br/>
<div class="buttons">
<a href="#" id="device-403-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="device-409-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>Device does not exist.</h3>
<br/>
<div class="buttons">
<a href="#" id="remove-device-409-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
<script id="device-listing" data-current-user="{{currentUser.username}}"
data-image-resource="{{@app.context}}/public/cdmf.unit.device.type."
src="{{@page.publicUri}}/templates/listing.hbs"
type="text/x-handlebars-template"></script>
{{js "js/listing.js"}}
{{/zone}}

@ -18,8 +18,13 @@
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;
@ -28,9 +33,46 @@ function onRequest(context) {
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;

@ -54,59 +54,11 @@
</div>
</div>
<div id="group-400-content" class="hide">
<div id="group-error-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h4>Exception at backend. Try Later.</h4>
<br/>
<div class="buttons">
<a href="#" id="group-400-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="group-403-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h4>Operation not permitted.</h4>
<br/>
<div class="buttons">
<a href="#" id="group-403-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="group-409-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h4>Group Name already exists.</h4>
<br/>
<div class="buttons">
<a href="#" id="group-409-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="group-unexpected-error-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h4>Unexpected error occurred!</h4>
<h4 id="error-msg">Unexpected error occurred!</h4>
<br/>
<div class="buttons">
<a href="#" id="group-unexpected-error-link" class="btn-operations">

@ -29,7 +29,8 @@ $(function () {
} else {
var group = {"name": name, "description": description};
var successCallback = function (data) {
var successCallback = function (jqXHR) {
var data = JSON.parse(jqXHR);
if (data.status == 201) {
$('.wr-validation-summary strong').text("Group created. You will be redirected to groups");
$('.wr-validation-summary').removeClass("hidden");
@ -39,13 +40,13 @@ $(function () {
window.location = "../groups";
}, 1500);
} else {
displayErrors(status);
displayErrors(data.status);
}
};
invokerUtil.post("/common/group_manager/groups", group,
invokerUtil.post("/devicemgt_admin/groups", group,
successCallback, function (message) {
displayErrors(message.content);
displayErrors(message);
});
return false;
@ -53,28 +54,11 @@ $(function () {
});
});
function displayErrors(status) {
function displayErrors(message) {
showPopup();
if (status == 400) {
$(modalPopupContent).html($('#group-400-content').html());
$("a#group-400-link").click(function () {
hidePopup();
});
} else if (status == 403) {
$(modalPopupContent).html($('#group-403-content').html());
$("a#group-403-link").click(function () {
hidePopup();
});
} else if (status == 409) {
$(modalPopupContent).html($('#group-409-content').html());
$("a#group-409-link").click(function () {
hidePopup();
});
} else {
$(modalPopupContent).html($('#group-unexpected-error-content').html());
$('#error-msg').html(message.responseText);
$(modalPopupContent).html($('#group-error-content').html());
$("a#group-unexpected-error-link").click(function () {
hidePopup();
});
console.log("Error code: " + status);
}
}

@ -268,7 +268,7 @@
{{#zone "bottomJs"}}
<script id="group-listing" data-current-user="{{currentUser.username}}"
src="{{@unit.publicUri}}/templates/listing.hbs"
src="{{@page.publicUri}}/templates/listing.hbs"
type="text/x-handlebars-template"></script>
{{#if groupCount}}
{{js "js/listing.js"}}

@ -108,7 +108,7 @@ function loadGroups() {
$(".icon .text").res_text(0.2);
};
invokerUtil.get("/common/group_manager/groups?start=0&rowCount=1000",
invokerUtil.get("/devicemgt_admin/groups/user/" + currentUser + "?start=0&rowCount=1000",
successCallback, function (message) {
displayErrors(message.content);
});
@ -282,7 +282,7 @@ function attachEvents() {
}
};
invokerUtil.delete("/common/group_manager/groups/" + groupOwner + "/" + groupName,
invokerUtil.delete("/devicemgt_admin/groups/" + groupOwner + "/" + groupName,
successCallback, function (message) {
displayErrors(message.content);
});
@ -326,7 +326,7 @@ function attachEvents() {
}
};
invokerUtil.put("/common/group_manager/groups/" + groupOwner + "/" + groupName,
invokerUtil.put("/devicemgt_admin/groups/" + groupOwner + "/" + groupName,
successCallback, function (message) {
displayErrors(message.content);
});
@ -354,7 +354,7 @@ function getAllRoles(groupName, groupOwner, selectedUser) {
}
};
invokerUtil.get("/common/group_manager/groups/" + groupOwner + "/" + groupName + "/share/roles",
invokerUtil.get("/devicemgt_admin/groups/" + groupOwner + "/" + groupName + "/share/roles",
successCallback, function (message) {
displayErrors(message.content);
});
@ -407,7 +407,7 @@ function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) {
}
};
invokerUtil.get("/common/group_manager/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser,
invokerUtil.get("/devicemgt_admin/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser,
successCallback, function (message) {
displayErrors(message.content);
});
@ -431,7 +431,7 @@ function updateGroupShare(groupName, groupOwner, selectedUser, role) {
}
};
invokerUtil.put("/common/group_manager/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser,
invokerUtil.put("/devicemgt_admin/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser,
role, successCallback, function (message) {
displayErrors(message.content);
});

@ -164,7 +164,6 @@ function getDateTime(from, to) {
startDate = new Date(from);
endDate = new Date(to);
DateRange = convertDate(startDate) + " " + configObject.separator + " " + convertDate(endDate);
console.log(DateRange);
$('#date-range').html(DateRange);
getStats(from / 1000, to / 1000);
}

@ -1,173 +0,0 @@
<div class="wr-content">
{{#if permissions.VIEW_DASHBOARD}}
<div class="row wr-stats-board">
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Devices</div>
<div>
<div class="tile-icon"><i class="fw fw-mobile"></i></div>
<div class="tile-stats">
<span id="device-count">{{device_count}}</span>
<span class="tile-stats-free">
<a href="{{@app.context}}/devices">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
<a href="{{@app.context}}/device/enroll">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="row wr-stats-board">
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Groups</div>
<div>
<div class="tile-icon"><i class="fw fw-grouping"></i></div>
<div class="tile-stats">
<span id="group-count">{{group_count}}</span>
<span class="tile-stats-free">
<a href="{{@app.context}}/groups">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
<a href="{{@app.context}}/group/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="row wr-stats-board">
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Users</div>
<div>
<div class="tile-icon"><i class="fw fw-user"></i></div>
<div class="tile-stats">
<span id="user-count">{{user_count}}</span>
<span class="tile-stats-free">
<a href="{{@app.context}}/users">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
<a href="{{@app.context}}/user/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="row wr-stats-board">
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Policies</div>
<div>
<div class="tile-icon"><i class="fw fw-policy"></i></div>
<div class="tile-stats">
<span id="policy-count">{{policy_count}}</span>
<span class="tile-stats-free">
<a href="{{@app.context}}/policies">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
<a href="{{@app.context}}/policy/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span>
</div>
</div>
</div>
</div>
</div>
<div class="row wr-stats-board">
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Roles</div>
<div>
<div class="tile-icon"><i class="fw fw-bookmark"></i></div>
<div class="tile-stats">
<span id="role-count">{{role_count}}</span>
<span class="tile-stats-free">
<a id="device-count-view-btn" href="{{@app.context}}/roles">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
<a href="{{@app.context}}/roles/add-role">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span>
</div>
</div>
</div>
</div>
</div>
{{else}}
Permission denied
{{/if}}
</div>
<div id="qr-code-modal" data-enrollment-url="{{enrollmentURL}}" class="hidden">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
Scan QR code to start enrollment
</h3>
<h4>
Please scan the QR code using your mobile device to retrieve enrollment URL.
</h4>
<div class="panel panel-default">
<div class="panel-body col-centered ">
<div class="qr-code"></div>
</div>
</div>
</div>
</div>
</div>
</div>

@ -1,264 +0,0 @@
{{#if deviceCount}}
<span id="permission" data-permission="{{permissions}}"></span>
<div id="loading-content" class="col-centered">
<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading devices . . .
<br>
</div>
<div id="device-listing-status" class="raw hidden">
<ul style="list-style-type: none;">
<li class="message message-info" >
<h4>
<i class="icon fw fw-info"></i>
<a id="device-listing-status-msg"></a>
</h4>
</li>
</ul>
</div>
<div id="device-table">
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden" id="device-grid">
<thead>
<tr class="sort-row">
<th class="no-sort"></th>
<th>By Device Name</th>
<th>By Owner</th>
<th>By Status</th>
<th>By Platform</th>
<th>By Ownership</th>
<th class="no-sort"></th>
</tr>
<tr class="filter-row filter-box">
<th class="no-sort"></th>
<th data-for="By Device name" class="text-filter"></th>
<th data-for="By Owner" class="text-filter"></th>
<th data-for="By Status" class="select-filter"></th>
<th data-for="By Platform" class="select-filter data-platform"></th>
<th data-for="By Ownership" class="select-filter"></th>
<th class="no-sort"></th>
</tr>
<tr class="bulk-action-row">
<th colspan="7">
<div id = "operation-bar" class="hidden">
{{unit "mdm.unit.device.operation-bar"}}
</div>
<div id="operation-guide" class="bs-callout bs-callout-info">
<h4>Enabling Device Operations</h4>
<p>To enable device operations, select the desired platform from above filter.</p>
</div>
</th>
</tr>
</thead>
<tbody id="ast-container">
<br class="c-both" />
</tbody>
</table>
</div>
<br class="c-both"/>
<div id="content-filter-types" style="display: none">
<div class="sort-title">Sort By</div>
<div class="sort-options">
<a href="#">By Device Name<span class="ico-sort-asc"></span></a>
<a href="#">By Owner</a>
<a href="#">By Status</a>
<a href="#">By Platform</a>
<a href="#">By Ownership</a>
</div>
</div>
{{else}}
<div id="ast-container" class="ast-container list-view">
<div class="ctrl-info-panel col-centered text-center wr-login">
<h2>You don't have any device
{{#if groupId}}
assigned to this group
{{else}}
registered
{{/if}}
at the moment.</h2>
<br/>
<p class="text-center">
{{#if groupId}}
<a href="{{@app.context}}/devices" class="wr-btn">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Assign from My Devices
</a>
{{else}}
<a href="{{@app.context}}/device/enroll" class="wr-btn">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Enroll New Device
</a>
{{/if}}
</p>
</div>
</div>
{{/if}}
<div id="group-device-modal-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-3 col-centered">
<h3>Please select group</h3>
<div id="user-groups">Loading...</div>
<div class="buttons">
<a href="#" id="group-device-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Assign&nbsp;&nbsp;&nbsp;&nbsp;
</a>
&nbsp;&nbsp;
<a href="#" id="group-device-cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="group-associate-device-200-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-3 col-centered">
<h3>Device was successfully associated with group.</h3>
</div>
</div>
</div>
</div>
<div id="group-deassociate-device-200-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-3 col-centered">
<h3>Device was successfully removed from group.</h3>
</div>
</div>
</div>
</div>
<div id="remove-device-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to remove this device from your Devices List?</h3>
<div class="buttons">
<a href="#" id="remove-device-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Yes&nbsp;&nbsp;&nbsp;&nbsp;
</a>
&nbsp;&nbsp;
<a href="#" id="remove-device-cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-device-200-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Device was successfully removed.</h3>
</div>
</div>
</div>
</div>
<div id="edit-device-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Please enter new name for the device?</h3>
<br/>
<div>
<input id="edit-device-name" style="color:#3f3f3f;padding:5px" type="text"
value=""
placeholder="Type here" size="60">
</div>
<div class="buttons">
<a href="#" id="edit-device-yes-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Rename&nbsp;&nbsp;&nbsp;&nbsp;
</a>
&nbsp;&nbsp;
<a href="#" id="edit-device-cancel-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Cancel&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="edit-device-200-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Device was successfully updated.</h3>
</div>
</div>
</div>
</div>
<div id="device-400-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>Exception at backend. Try Later.</h3>
<br/>
<div class="buttons">
<a href="#" id="device-400-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="device-403-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>Operation not permitted.</h3>
<br/>
<div class="buttons">
<a href="#" id="device-403-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
<div id="device-409-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>Device does not exist.</h3>
<br/>
<div class="buttons">
<a href="#" id="remove-device-409-link" class="btn-operations">
&nbsp;&nbsp;&nbsp;&nbsp;Ok&nbsp;&nbsp;&nbsp;&nbsp;
</a>
</div>
</div>
</div>
</div>
</div>
{{#zone "bottomJs"}}
<script id="device-listing" data-current-user="{{currentUser.username}}"
data-image-resource="{{@app.context}}/public/cdmf.unit.device.type."
src="{{@unit.publicUri}}/templates/listing.hbs"
type="text/x-handlebars-template"></script>
{{js "js/listing.js"}}
{{/zone}}

@ -1,68 +0,0 @@
/*
* 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.
*/
function onRequest(context) {
var page_data = {};
var groupId = request.getParameter("groupId");
var userModule = require("/app/modules/user.js").userModule;
var constants = require("/app/modules/constants.js");
var deviceModule = require("/app/modules/device.js").deviceModule;
var permissions = [];
var currentUser = session.get(constants.USER_SESSION_KEY);
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/remove")) {
permissions.push("REMOVE_DEVICE");
}
page_data.permissions = stringify(permissions);
page_data.currentUser = currentUser;
var deviceCount;
if (groupId) {
var groupModule = require("/app/modules/group.js").groupModule;
deviceCount = groupModule.getDevices(groupId).data.length;
page_data.groupId = groupId;
} else {
deviceCount = deviceModule.getOwnDevicesCount();
}
if (deviceCount > 0){
page_data.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_data.deviceTypes = deviceTypes;
}
}
return page_data;
}
Loading…
Cancel
Save