Merge pull request #214 from charithag/master

Fix issues in device listing page and device details page
revert-70aa11f8
Milan Perera 9 years ago
commit 37b6161bc6

@ -25,6 +25,8 @@ var constants = require("/app/modules/constants.js");
var deviceModule = require("/app/modules/device.js").deviceModule; var deviceModule = require("/app/modules/device.js").deviceModule;
var utility = require("/app/modules/utility.js").utility; var utility = require("/app/modules/utility.js").utility;
var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
var userModule = require("/app/modules/user.js").userModule;
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils; var CarbonUtils = Packages.org.wso2.carbon.utils.CarbonUtils;
var user = session.get(constants.USER_SESSION_KEY); var user = session.get(constants.USER_SESSION_KEY);
@ -159,6 +161,88 @@ if (!user) {
var deviceType = elements.deviceType; var deviceType = elements.deviceType;
var deviceName = request.getParameter("name"); var deviceName = request.getParameter("name");
result = deviceModule.updateDevice(deviceType, deviceId, deviceName); result = deviceModule.updateDevice(deviceType, deviceId, deviceName);
} else if (uriMatcher.match("/{context}/api/devices")) {
var url = request.getParameter("url");
var draw = request.getParameter("draw");
var length = request.getParameter("length");
var start = request.getParameter("start");
var search = request.getParameter("search[value]");
var deviceName = request.getParameter("columns[1][search][value]");
var owner = request.getParameter("columns[2][search][value]");
var status = request.getParameter("columns[3][search][value]");
var platform = request.getParameter("columns[4][search][value]");
var ownership = request.getParameter("columns[5][search][value]");
var targetURL;
function appendQueryParam (url, queryParam , value) {
if (url.indexOf("?") > 0) {
return url + "&" + queryParam + "=" + value;
}
return url + "?" + queryParam + "=" + value;
}
targetURL = devicemgtProps.httpsURL + request.getParameter("url");
targetURL = appendQueryParam(targetURL, "draw", draw);
targetURL = appendQueryParam(targetURL, "start", start);
targetURL = appendQueryParam(targetURL, "length", length);
if (search && search !== "") {
targetURL = appendQueryParam(targetURL, "search", search);
}
if (deviceName && deviceName !== "") {
targetURL = appendQueryParam(targetURL, "device-name", deviceName);
}
if (owner && owner !== "") {
targetURL = appendQueryParam(targetURL, "user", owner);
}
if (status && status !== "") {
targetURL = appendQueryParam(targetURL, "status", status);
}
if (platform && platform !== "") {
targetURL = appendQueryParam(targetURL, "type", platform);
}
if (ownership && ownership !== "") {
targetURL = appendQueryParam(targetURL, "ownership", ownership);
}
serviceInvokers.XMLHttp.get(
targetURL, function (responsePayload) {
response.status = 200;
result = responsePayload;
},
function (responsePayload) {
response.status = responsePayload.status;
result = responsePayload.responseText;
});
} else if (uriMatcher.match("/{context}/api/devices/")) {
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) {
result = deviceModule.listDevices();
} else {
response.sendError(403);
}
} else if (uriMatcher.match("/{context}/api/devices/{type}/{deviceId}")) {
elements = uriMatcher.elements();
deviceId = elements.deviceId;
type = elements.type;
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) {
result = deviceModule.viewDevice(type, deviceId);
}else {
response.sendError(403);
}
} else if (uriMatcher.match("{context}/api/devices/{type}/{deviceId}/{operation}")) {
elements = uriMatcher.elements();
deviceId = elements.deviceId;
type = elements.type;
operation = elements.operation;
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/operation")) {
result = deviceModule.performOperation(deviceId, operation, [], type);
} else {
response.sendError(403);
}
} }
} }

@ -278,9 +278,10 @@ deviceModule = function () {
if (device) { if (device) {
var propertiesList = device["properties"]; var propertiesList = device["properties"];
var properties = {}; var properties = {};
if (propertiesList){
for (var i = 0; i < propertiesList.length; i++) { for (var i = 0; i < propertiesList.length; i++) {
properties[propertiesList[i]["name"]] = properties[propertiesList[i]["name"]] = propertiesList[i]["value"];
propertiesList[i]["value"]; }
} }
var deviceObject = {}; var deviceObject = {};
deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"]; deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"];

@ -21,6 +21,7 @@ var operationModule = function () {
var utility = require('/app/modules/utility.js').utility; var utility = require('/app/modules/utility.js').utility;
var constants = require('/app/modules/constants.js'); var constants = require('/app/modules/constants.js');
var devicemgtProps = require('/app/conf/devicemgt-props.js').config(); var devicemgtProps = require('/app/conf/devicemgt-props.js').config();
var serviceInvokers = require("/app/modules/backend-service-invoker.js").backendServiceInvoker;
var publicMethods = {}; var publicMethods = {};
var privateMethods = {}; var privateMethods = {};
@ -39,51 +40,45 @@ var operationModule = function () {
privateMethods.getOperationsFromFeatures = function (deviceType, operationType) { privateMethods.getOperationsFromFeatures = function (deviceType, operationType) {
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType; var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/features/" + deviceType;
var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) { var featuresList = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
var features = responsePayload.responseContent; var features = responsePayload;
var featureList = []; var featureList = [];
var feature; var feature;
for (var i = 0; i < features.size(); i++) { for (var i = 0; i < features.length; i++) {
feature = {}; feature = {};
if (features.get(i).getType() != operationType) { if (features[i].type != operationType) {
continue; continue;
} else if (features.get(i).getType() == 'monitor') { } else if (features[i].type == 'monitor') {
var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"]; var analyticStreams = utility.getDeviceTypeConfig(deviceType)["analyticStreams"];
if (analyticStreams) { if (analyticStreams) {
for (var stream in analyticStreams) { for (var stream in analyticStreams) {
if (analyticStreams[stream].name == features.get(i).getName()) { if (analyticStreams[stream].name == features[i].name) {
feature.ui_unit = analyticStreams[stream].ui_unit; feature.ui_unit = analyticStreams[stream].ui_unit;
break; break;
} }
} }
} }
} }
feature["operation"] = new String(features.get(i).getCode()); feature["operation"] = features[i].code;
feature["name"] = new String(features.get(i).getName()); feature["name"] = features[i].name;
feature["description"] = new String(features.get(i).getDescription()); feature["description"] = features[i].description;
feature["deviceType"] = new String(features.get(i).getDeviceType()); feature["deviceType"] = deviceType;
feature["params"] = []; feature["params"] = [];
var metaData = features.get(i).getMetadataEntries(); var metaData = features[i].metadataEntries;
if (metaData && metaData != null) { if (metaData) {
for (var j = 0; j < metaData.size(); j++) { for (var j = 0; j < metaData.length; j++) {
feature["params"].push(new String(metaData.get(j).getValue())); feature["params"].push(metaData[j].value);
} }
featureList.push(feature); featureList.push(feature);
} }
} }
return featureList; return featureList;
} }, function (responsePayload) {
,
function (responsePayload) {
var response = {}; var response = {};
response["status"] = "error"; response["status"] = "error";
return response; return response;
} }
); );
return featuresList; return featuresList;
return featureList;
} catch (e) {
throw e;
}
}; };
publicMethods.getControlOperations = function (deviceType) { publicMethods.getControlOperations = function (deviceType) {
@ -108,7 +103,6 @@ var operationModule = function () {
'","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' + '","protocol":"mqtt", "sessionId":"' + session.getId() + '", "' +
constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX + constants.AUTHORIZATION_HEADER + '":"' + constants.BEARER_PREFIX +
getAccessToken(deviceType, user.username, deviceId) + '"}'; getAccessToken(deviceType, user.username, deviceId) + '"}';
log.warn("header: " + header);
return post(endPoint, params, JSON.parse(header), "json"); return post(endPoint, params, JSON.parse(header), "json");
}; };

@ -61,7 +61,7 @@
<div> <div>
{{unit "cdmf.unit.device.operation-mod"}} {{unit "cdmf.unit.device.operation-mod"}}
{{#if deviceCount}} {{#if deviceCount}}
<span id="permission" data-permission="{{{permissions}}}"></span> <span id="permission" data-permission="{{permissions.list}}"></span>
<div id="loading-content" class="col-centered"> <div id="loading-content" class="col-centered">
<i class="fw fw-settings fw-spin fw-2x"></i> <i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
@ -324,7 +324,7 @@
{{/zone}} {{/zone}}
{{#zone "bottomJs"}} {{#zone "bottomJs"}}
<script id="device-listing" data-current-user="{{currentUser.username}}" <script id="device-listing" data-current-user="{{currentUser.username}}" data-device-types="{{deviceTypes}}"
data-image-resource="{{@app.context}}/public/cdmf.unit.device.type." data-image-resource="{{@app.context}}/public/cdmf.unit.device.type."
src="{{@page.publicUri}}/templates/listing.hbs" src="{{@page.publicUri}}/templates/listing.hbs"
type="text/x-handlebars-template"></script> type="text/x-handlebars-template"></script>

@ -31,25 +31,13 @@ function onRequest(context) {
page.groupName = groupName; page.groupName = groupName;
} }
page.title = title; page.title = title;
page.permissions = {};
var currentUser = session.get(constants.USER_SESSION_KEY); var currentUser = session.get(constants.USER_SESSION_KEY);
var permissions = [];
if (currentUser) { if (currentUser) {
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/list")) { page.permissions = {};
permissions.push("LIST_DEVICES"); page.permissions.list = stringify(userModule.getUIPermissions());
} 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")) { if (userModule.isAuthorized("/permission/admin/device-mgt/admin/devices/add")) {
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; page.currentUser = currentUser;
var deviceCount = 0; var deviceCount = 0;
if (groupName && groupOwner) { if (groupName && groupOwner) {
@ -64,15 +52,17 @@ function onRequest(context) {
var utility = require("/app/modules/utility.js").utility; var utility = require("/app/modules/utility.js").utility;
var data = deviceModule.getDeviceTypes(); var data = deviceModule.getDeviceTypes();
var deviceTypes = []; var deviceTypes = [];
if (data.data) { if (data) {
for (var i = 0; i < data.data.length; i++) { for (var i = 0; i < data.length; i++) {
var deviceType = utility.getDeviceTypeConfig(data[i].name).deviceType;
deviceTypes.push({ deviceTypes.push({
"type": data.data[i].name, "type": data[i].name,
"category": utility.getDeviceTypeConfig(data.data[i].name).deviceType.category "category": deviceType.category,
"label": deviceType.label
}); });
} }
} }
page.deviceTypes = deviceTypes; page.deviceTypes = stringify(deviceTypes);
} }
} }
return page; return page;

@ -72,8 +72,10 @@ $(document).ready(function () {
var i; var i;
var permissionList = $("#permission").data("permission"); var permissionList = $("#permission").data("permission");
for (i = 0; i < permissionList.length; i++) { for (var key in permissionList) {
$.setPermission(permissionList[i]); if (permissionList.hasOwnProperty(key)) {
$.setPermission(key);
}
} }
/* for device list sorting drop down */ /* for device list sorting drop down */
@ -181,6 +183,9 @@ function loadDevices(searchType, searchParam){
} }
function getPropertyValue(deviceProperties, propertyName) { function getPropertyValue(deviceProperties, propertyName) {
if (!deviceProperties) {
return;
}
var property; var property;
for (var i = 0; i < deviceProperties.length; i++) { for (var i = 0; i < deviceProperties.length; i++) {
property = deviceProperties[i]; property = deviceProperties[i];
@ -191,6 +196,16 @@ function loadDevices(searchType, searchParam){
return {}; return {};
} }
function getDeviceTypeLabel(type){
var deviceTypes = deviceListing.data("deviceTypes");
for (var i = 0; i < deviceTypes.length; i++){
if (deviceTypes[i].type == type){
return deviceTypes[i].label;
}
}
return type;
}
$('#device-grid').datatables_extended ({ $('#device-grid').datatables_extended ({
serverSide: true, serverSide: true,
processing: false, processing: false,
@ -242,7 +257,10 @@ function loadDevices(searchType, searchParam){
} }
return html; return html;
}}, }},
{ targets: 4, data: 'type' , className: 'fade-edge remove-padding-top' }, { targets: 4, data: 'type' , className: 'fade-edge remove-padding-top' ,
render: function ( status, type, row, meta ) {
return getDeviceTypeLabel(row.type);
}},
{ targets: 5, data: 'enrolmentInfo.ownership' , className: 'fade-edge remove-padding-top' }, { targets: 5, data: 'enrolmentInfo.ownership' , className: 'fade-edge remove-padding-top' },
{ targets: 6, data: 'enrolmentInfo.status' , className: 'text-right content-fill text-left-on-grid-view no-wrap' , { targets: 6, data: 'enrolmentInfo.status' , className: 'text-right content-fill text-left-on-grid-view no-wrap' ,
render: function ( status, type, row, meta ) { render: function ( status, type, row, meta ) {

Loading…
Cancel
Save