Fixes to devices listing

4.x.x
Rasika Perera 8 years ago
parent c6c555abc6
commit 4691bedbc5

@ -24,22 +24,22 @@ function onRequest(context) {
var groupName = request.getParameter("groupName"); var groupName = request.getParameter("groupName");
var groupOwner = request.getParameter("groupOwner"); var groupOwner = request.getParameter("groupOwner");
var page = {}; var viewModel = {};
var title = "Devices"; var title = "Devices";
if (groupName) { if (groupName) {
title = groupName + " " + title; title = groupName + " " + title;
page.groupName = groupName; viewModel.groupName = groupName;
} }
page.title = title; viewModel.title = title;
var currentUser = session.get(constants.USER_SESSION_KEY); var currentUser = session.get(constants.USER_SESSION_KEY);
if (currentUser) { if (currentUser) {
page.permissions = {}; viewModel.permissions = {};
var uiPermissions = userModule.getUIPermissions(); var uiPermissions = userModule.getUIPermissions();
page.permissions.list = stringify(uiPermissions); viewModel.permissions.list = stringify(uiPermissions);
if (uiPermissions.ADD_DEVICE) { if (uiPermissions.ADD_DEVICE) {
page.permissions.enroll = true; viewModel.permissions.enroll = true;
} }
page.currentUser = currentUser; viewModel.currentUser = currentUser;
var deviceCount = 0; var deviceCount = 0;
if (groupName && groupOwner) { if (groupName && groupOwner) {
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
@ -48,30 +48,30 @@ function onRequest(context) {
deviceCount = deviceModule.getDevicesCount(); deviceCount = deviceModule.getDevicesCount();
} }
if (deviceCount > 0) { if (deviceCount > 0) {
page.deviceCount = deviceCount; viewModel.deviceCount = deviceCount;
var utility = require("/app/modules/utility.js").utility; var utility = require("/app/modules/utility.js").utility;
var typesListResponse = deviceModule.getDeviceTypes(); var typesListResponse = deviceModule.getDeviceTypes();
var deviceTypes = []; var deviceTypes = [];
if (typesListResponse["status"] == "success") { if (typesListResponse["status"] == "success") {
var data = typesListResponse["content"]; var data = typesListResponse.content.deviceTypes;
if (data) { if (data) {
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
var config = utility.getDeviceTypeConfig(data[i].name); var config = utility.getDeviceTypeConfig(data[i]);
if (!config) { if (!config) {
continue; continue;
} }
var deviceType = config.deviceType; var deviceType = config.deviceType;
deviceTypes.push({ deviceTypes.push({
"type": data[i].name, "type": data[i],
"category": deviceType.category, "category": deviceType.category,
"label": deviceType.label, "label": deviceType.label,
"thumb": utility.getDeviceThumb(data[i].name) "thumb": utility.getDeviceThumb(data[i])
}); });
} }
} }
} }
page.deviceTypes = stringify(deviceTypes); viewModel.deviceTypes = stringify(deviceTypes);
} }
} }
return page; return viewModel;
} }

Loading…
Cancel
Save