mharindu 8 years ago
commit 3d432707b2

@ -19,7 +19,6 @@
{{unit "cdmf.unit.lib.qrcode"}} {{unit "cdmf.unit.lib.qrcode"}}
{{unit "mdm.unit.device.qr-modal"}} {{unit "mdm.unit.device.qr-modal"}}
{{#zone "content"}} {{#zone "content"}}
{{#if permissions.VIEW_DASHBOARD}}
{{#if permissions.LIST_DEVICES}} {{#if permissions.LIST_DEVICES}}
<div class="row "> <div class="row ">
<div class="col-md-3 wr-stats-board"> <div class="col-md-3 wr-stats-board">
@ -151,9 +150,6 @@
</div> </div>
</div> </div>
{{/if}} {{/if}}
{{else}}
Permission denied
{{/if}}
{{/zone}} {{/zone}}
{{#zone "bottomJs"}} {{#zone "bottomJs"}}
{{js "js/dashboard.js"}} {{js "js/dashboard.js"}}

@ -20,10 +20,16 @@ function onRequest(context) {
var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var generalConfig = context.app.conf["generalConfig"]; var generalConfig = context.app.conf["generalConfig"];
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
var viewModel = {}; var viewModel = {};
viewModel.permissions = userModule.getUIPermissions(); var permissions = {};
new Log().debug("## Permissions : " + stringify(userModule.getUIPermissions())); permissions.LIST_DEVICES = userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/view");
permissions.LIST_POLICIES = userModule.isAuthorized("/permission/admin/device-mgt/policies/view");
permissions.LIST_ROLES = userModule.isAuthorized("/permission/admin/device-mgt/roles/view");
permissions.LIST_USERS = userModule.isAuthorized("/permission/admin/device-mgt/users/view");
permissions.ADD_POLICY = userModule.isAuthorized("/permission/admin/device-mgt/policies/manage");
permissions.ADD_ROLE = userModule.isAuthorized("/permission/admin/device-mgt/roles/manage");
permissions.ADD_USER = userModule.isAuthorized("/permission/admin/device-mgt/users/manage");
viewModel.permissions = permissions;
//TODO: Move enrollment URL into app-conf.json //TODO: Move enrollment URL into app-conf.json
viewModel.enrollmentURL = mdmProps.generalConfig.host + mdmProps.enrollmentDir; viewModel.enrollmentURL = mdmProps.generalConfig.host + mdmProps.enrollmentDir;
return viewModel; return viewModel;

@ -28,6 +28,7 @@
</a> </a>
</li> </li>
<li> <li>
<!--suppress HtmlUnknownTarget -->
<a href="{{@app.context}}/devices"> <a href="{{@app.context}}/devices">
Devices Devices
</a> </a>
@ -35,132 +36,131 @@
{{/zone}} {{/zone}}
{{#zone "navbarActions"}} {{#zone "navbarActions"}}
{{!-- #if permissions.enroll --}} {{#if permissions.ENROLL_DEVICE}}
<li id = "enroll-btn"> <li id = "enroll-btn">
<a href="javascript:toggleEnrollment()"> <a href="javascript:toggleEnrollment()">
<span class="fw-stack"> <span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-mobile fw-stack-1x"></i> <i class="fw fw-mobile fw-stack-1x"></i>
<span class="fw-stack fw-move-right fw-move-bottom"> <span class="fw-stack fw-move-right fw-move-top">
<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i> <i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i>
<i class="fw fw-circle fw-stack-2x"></i> <i class="fw fw-circle fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i> <i class="fw fw-add fw-stack-1x"></i>
</span> </span>
</span> </span>
Enroll Device &nbsp;&nbsp;Enroll Device
</a> </a>
</li> </li>
{{!-- /if --}} {{/if}}
<li id = "advanced-search-btn"> {{#if permissions.ADVANCED_SEARCH}}
<a href="{{appContext}}devices/search"> <li id = "advanced-search-btn">
<span class="fw-stack"> <a href="{{appContext}}devices/search">
<i class="fw fw-ring fw-stack-2x"></i> <span class="fw-stack">
<i class="fw fw-mobile fw-stack-1x"></i> <i class="fw fw-ring fw-stack-2x"></i>
<span class="fw-stack fw-move-right fw-move-bottom"> <i class="fw fw-mobile fw-stack-1x"></i>
<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i> <span class="fw-stack fw-move-right fw-move-top">
<i class="fw fw-circle fw-stack-2x"></i> <i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i>
<i class="fw fw-search fw-stack-1x"></i> <i class="fw fw-circle fw-stack-2x"></i>
</span> <i class="fw fw-search fw-stack-1x"></i>
</span> </span>
Advanced Search </span>
</a> &nbsp;&nbsp;Advanced Search
</li> </a>
</li>
{{/if}}
{{/zone}} {{/zone}}
{{#zone "content"}} {{#zone "content"}}
<span id="permission" data-permission="{{permissions}}"></span> {{#if permissions.VIEW_DEVICES}}
<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;
Loading devices . . . Loading devices . . .
<br> <br>
</div> </div>
<div id="device-listing-status" class="raw hidden"> <div id="device-listing-status" class="raw hidden">
<ul style="list-style-type: none;"> <ul style="list-style-type: none;">
<li class="message message-info"> <li class="message message-info">
<h4> <h4>
<i class="icon fw fw-info"></i> <i class="icon fw fw-info"></i>
<a id="device-listing-status-msg"></a> <a id="device-listing-status-msg"></a>
</h4> </h4>
</li> </li>
</ul> </ul>
</div> </div>
<div id="device-table"> <div id="device-table">
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view" <table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view"
id="device-grid"> id="device-grid">
<thead> <thead>
<tr class="sort-row"> <tr class="sort-row">
<th class="no-sort"></th> <th class="no-sort"></th>
<th>By Device Name</th> <th>By Device Name</th>
<th>By Owner</th> <th>By Owner</th>
<th>By Status</th> <th>By Status</th>
<th>By Platform</th> <th>By Platform</th>
<th>By Ownership</th> <th>By Ownership</th>
<th class="no-sort"></th> <th class="no-sort"></th>
</tr> </tr>
<tr class="filter-row filter-box"> <tr class="filter-row filter-box">
<th class="no-sort"></th> <th class="no-sort"></th>
<th data-for="By Device Name"></th> <th data-for="By Device Name"></th>
<th data-for="By Owner" 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 Status" class="select-filter"></th>
<th data-for="By Platform" class="select-filter data-platform"></th> <th data-for="By Platform" class="select-filter data-platform"></th>
<th data-for="By Ownership" class="select-filter"></th> <th data-for="By Ownership" class="select-filter"></th>
<th class="no-sort"></th> <th class="no-sort"></th>
</tr> </tr>
<tr class="bulk-action-row hidden"> <tr class="bulk-action-row hidden">
<th colspan="7"> <th colspan="7">
<div id="operation-bar"> <div id="operation-bar">
{{unit "mdm.unit.device.operation-bar"}} {{unit "mdm.unit.device.operation-bar"}}
</div> </div>
<div id="operation-guide" class="bs-callout bs-callout-info"> <div id="operation-guide" class="bs-callout bs-callout-info">
<h4>Enabling Device Operations</h4> <h4>Enabling Device Operations</h4>
<p>To enable device operations, select the desired platform from above filter.</p> <p>To enable device operations, select the desired platform from above filter.</p>
</div> </div>
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody id="ast-container"> <tbody id="ast-container"></tbody>
</table>
<br class="c-both"/> </div>
</tbody> <br class="c-both"/>
</table> <div id="content-filter-types" style="display: none">
</div> <div class="sort-title">Sort By</div>
<br class="c-both"/> <div class="sort-options">
<div id="content-filter-types" style="display: none"> <a href="#">By Device Name<span class="ico-sort-asc"></span></a>
<div class="sort-title">Sort By</div> <a href="#">By Owner</a>
<div class="sort-options"> <a href="#">By Status</a>
<a href="#">By Device Name<span class="ico-sort-asc"></span></a> <a href="#">By Platform</a>
<a href="#">By Owner</a> <a href="#">By Ownership</a>
<a href="#">By Status</a> </div>
<a href="#">By Platform</a>
<a href="#">By Ownership</a>
</div> </div>
</div> <div id="no-device-view" class="ast-container list-view hidden">
<div id="no-device-view" class="ast-container list-view hidden"> <div class="ctrl-info-panel col-centered text-center wr-login">
<div class="ctrl-info-panel col-centered text-center wr-login"> <h2>You don't have any device registered at the moment.</h2>
<h2>You don't have any device registered at the moment.</h2> <br/>
<br/> <p class="text-center">
<p class="text-center"> <a href="javascript:toggleEnrollment()" class="wr-btn">
<a href="javascript:toggleEnrollment()" class="wr-btn"> <span class="fw-stack">
<span class="fw-stack"> <i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-mobile fw-stack-1x"></i>
<i class="fw fw-mobile fw-stack-1x"></i> <span class="fw-stack fw-move-right fw-move-bottom">
<span class="fw-stack fw-move-right fw-move-bottom"> <i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i>
<i class="fw fw-circle fw-stack-2x fw-stroke fw-inverse"></i> <i class="fw fw-circle fw-stack-2x"></i>
<i class="fw fw-circle fw-stack-2x"></i> <i class="fw fw-add fw-stack-1x"></i>
<i class="fw fw-add fw-stack-1x"></i> </span>
</span> </span>
</span> Enroll New Device
Enroll New Device </a>
</a> </p>
</p> </div>
</div> </div>
</div> {{/if}}
{{/zone}} {{/zone}}
{{#zone "bottomJs"}} {{#zone "bottomJs"}}
<script id="device-listing" data-current-user="{{currentUser.username}}" {{#if permissions.VIEW_DEVICES}}
data-image-resource="{{self.publicURL}}/images/" {{js "js/device-listing.js"}}
src="{{self.publicURL}}/templates/device-listing.hbs" type="text/x-handlebars-template"></script> {{/if}}
{{js "js/device-listing.js"}}
{{/zone}} {{/zone}}

@ -15,26 +15,29 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
function onRequest(context){
var userModule = require("/app/modules/business-controllers/user.js").userModule; function onRequest() {
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var constants = require("/app/modules/constants.js"); var constants = require("/app/modules/constants.js");
var viewModel = {}; var viewModel = {};
var permissions = []; var permissions = {};
if(userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/devices/list")){
permissions.push("LIST_DEVICES"); // permission checks
if (userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/devices/view")) { // [1] checking enrollment permissions
permissions.push("VIEW_DEVICES"); permissions["ENROLL_DEVICE"] = userModule.isAuthorized("/permission/admin/device-mgt/devices/enroll/android") ||
} userModule.isAuthorized("/permission/admin/device-mgt/devices/enroll/ios") ||
}else if(userModule.isAuthorized("/permission/admin/device-mgt/user/devices/list")){ userModule.isAuthorized("/permission/admin/device-mgt/devices/enroll/windows");
permissions.push("LIST_OWN_DEVICES");
if (userModule.isAuthorized("/permission/admin/device-mgt/user/devices/view")) { // [2] checking advanced device search permissions
permissions.push("VIEW_OWN_DEVICES"); permissions["ADVANCED_SEARCH"] = userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/view");
}
}else if(userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/policies/list")){ // [3] checking device viewing permission
permissions.push("LIST_POLICIES"); permissions["VIEW_DEVICES"] = userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/view");
}
var currentUser = session.get(constants.USER_SESSION_KEY); var currentUser = session.get(constants["USER_SESSION_KEY"]);
viewModel.permissions = stringify(permissions);
viewModel.currentUser = currentUser; viewModel["permissions"] = permissions;
viewModel["currentUser"] = currentUser;
return viewModel; return viewModel;
} }

@ -28,8 +28,6 @@ function InitiateViewOption(url) {
} }
(function () { (function () {
var cache = {};
var permissionSet = {};
var validateAndReturn = function (value) { var validateAndReturn = function (value) {
return (value == undefined || value == null) ? "Unspecified" : value; return (value == undefined || value == null) ? "Unspecified" : value;
}; };
@ -44,105 +42,15 @@ function InitiateViewOption(url) {
}, {}); }, {});
} }
}); });
//This method is used to setup permission for device listing
$.setPermission = function (permission) {
permissionSet[permission] = true;
};
$.hasPermission = function (permission) {
return permissionSet[permission];
};
})(); })();
/* /*
* Setting-up global variables. * Setting-up global variables.
*/ */
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
var assetContainer = "#ast-container";
/*
* DOM ready functions.
*/
$(document).ready(function () {
/* Adding selected class for selected devices */
$(deviceCheckbox).each(function () {
addDeviceSelectedClass(this);
});
var i;
var permissionList = $("#permission").data("permission");
for (i = 0; i < permissionList.length; i++) {
$.setPermission(permissionList[i]);
}
/* for device list sorting drop down */
$(".ctrl-filter-type-switcher").popover({
html : true,
content : function () {
return $("#content-filter-types").html();
}
});
$(".ast-container").on("click", ".claim-btn", function(e){
e.stopPropagation();
var deviceId = $(this).data("deviceid");
var deviceListing = $("#device-listing");
var currentUser = deviceListing.data("current-user");
var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser;
var deviceIdentifier = {id: deviceId, type: "TemperatureController"};
invokerUtil.put(serviceURL, deviceIdentifier, function(message){
console.log(message);
}, function(message){
console.log(message.content);
});
});
});
/*
* On Select All Device button click function.
*
* @param button: Select All Device button
*/
function selectAllDevices(button) {
if(!$(button).data('select')){
$(deviceCheckbox).each(function(index){
$(this).prop('checked', true);
addDeviceSelectedClass(this);
});
$(button).data('select', true);
$(button).html('Deselect All Devices');
}else{
$(deviceCheckbox).each(function(index){
$(this).prop('checked', false);
addDeviceSelectedClass(this);
});
$(button).data('select', false);
$(button).html('Select All Devices');
}
}
/*
* On listing layout toggle buttons click function.
*
* @param view: Selected view type
* @param selection: Selection button
*/
function changeDeviceView(view, selection) {
$(".view-toggle").each(function() {
$(this).removeClass("selected");
});
$(selection).addClass("selected");
if (view == "list") {
$(assetContainer).addClass("list-view");
} else {
$(assetContainer).removeClass("list-view");
}
}
/* /*
* Add selected style class to the parent element function. * Add selected style class to the parent element function.
*
* @param checkbox: Selected checkbox * @param checkbox: Selected checkbox
*/ */
function addDeviceSelectedClass(checkbox) { function addDeviceSelectedClass(checkbox) {
@ -153,30 +61,10 @@ function addDeviceSelectedClass(checkbox) {
} }
} }
function toTitleCase(str) { function loadDevices() {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
function loadDevices(searchType, searchParam){
var deviceListing = $("#device-listing"); var deviceListing = $("#device-listing");
var currentUser = deviceListing.data("currentUser"); var currentUser = deviceListing.data("currentUser");
var serviceURL;
if ($.hasPermission("LIST_DEVICES")) {
//serviceURL = "/mdm-admin/devices";
serviceURL = "/api/device-mgt/v1.0/devices";
} else if ($.hasPermission("LIST_OWN_DEVICES")) {
//Get authenticated users devices
serviceURL = "/api/device-mgt/v1.0/devices?user="+currentUser;
//serviceURL = "/mdm-admin/users/devices?username="+currentUser;
} else {
$("#loading-content").remove();
$('#device-table').addClass('hidden');
$('#device-listing-status-msg').text('Permission denied.');
$("#device-listing-status").removeClass(' hidden');
return;
}
function getPropertyValue(deviceProperties, propertyName) { function getPropertyValue(deviceProperties, propertyName) {
var property; var property;
for (var i =0; i < deviceProperties.length; i++) { for (var i =0; i < deviceProperties.length; i++) {
@ -188,30 +76,30 @@ function loadDevices(searchType, searchParam){
return {}; return {};
} }
var fnCreatedRow = function( nRow, aData, iDataIndex ) { var fnCreatedRow = function (nRow) {
$(nRow).attr('data-type', 'selectable'); $(nRow).attr('data-type', 'selectable');
$(nRow).attr('data-deviceid', aData.deviceIdentifier); };
$(nRow).attr('data-devicetype', aData.deviceType);
}
var columns = [ var columns = [
{ {
class : 'remove-padding icon-only content-fill viewEnabledIcon', class : 'remove-padding icon-only content-fill viewEnabledIcon',
data : 'icon', data : 'icon',
render: function (data, type, row, meta) { render: function (data, type, row) {
var deviceType = row.deviceType; var deviceType = row.deviceType;
var deviceIdentifier = row.deviceIdentifier; var deviceIdentifier = row.deviceIdentifier;
var url = "#"; var url = "#";
if (status != 'REMOVED') { if (status != 'REMOVED') {
url = "device/" + deviceType + "?id=" + deviceIdentifier; url = "device/" + deviceType + "?id=" + deviceIdentifier;
} }
return '<div onclick="javascript:InitiateViewOption(\'' + url + '\')" class="thumbnail icon"><i class="square-element text fw fw-mobile"></i></div>' return '<div onclick="javascript:InitiateViewOption(\'' + url + '\')" class="thumbnail icon">' +
'<i class="square-element text fw fw-mobile"></i></div>'
} }
},{ },
{
class: 'fade-edge', class: 'fade-edge',
data: 'name', data: 'name',
render: function ( name, type, row, meta ) { render: function (name, type, row) {
var model = row.model; var model = row.model;
var vendor = row.vendor; var vendor = row.vendor;
var html = '<h4>Device ' + name + '</h4>'; var html = '<h4>Device ' + name + '</h4>';
@ -220,16 +108,18 @@ function loadDevices(searchType, searchParam){
} }
return html; return html;
} }
},{ },
{
class: 'fade-edge remove-padding-top', class: 'fade-edge remove-padding-top',
data: 'owner', data: 'user',
render: function ( owner, type, row, meta ) { render: function (user) {
return '<div><label class="label-bold">Owner&nbsp;:&nbsp;</label>' + owner + '</div>'; return '<div><label class="label-bold">Owner&nbsp;:&nbsp;</label>' + user + '</div>';
} }
},{ },
{
class: 'fade-edge remove-padding-top', class: 'fade-edge remove-padding-top',
data: 'status', data: 'status',
render: function ( status, type, row, meta ) { render: function (status) {
var html; var html;
switch (status) { switch (status) {
case 'ACTIVE' : case 'ACTIVE' :
@ -245,35 +135,37 @@ function loadDevices(searchType, searchParam){
html = '<span><i class="fw fw-delete icon-danger"></i> Removed</span>'; html = '<span><i class="fw fw-delete icon-danger"></i> Removed</span>';
break; break;
} }
return '<div><label class="label-bold">Status&nbsp;:&nbsp;</label>'+html+'</div>'; return '<div><label class="label-bold">Status&nbsp;:&nbsp;</label>' + html + '</div>';
} }
},{ },
{
className: 'fade-edge remove-padding-top', className: 'fade-edge remove-padding-top',
data: 'deviceType', data: 'deviceType',
render: function ( deviceType, type, row, meta ) { render: function (deviceType) {
return '<div><label class="label-bold">Type&nbsp;:&nbsp;</label>' + deviceType + '</div>'; return '<div><label class="label-bold">Type&nbsp;:&nbsp;</label>' + deviceType + '</div>';
} }
},{ },
{
className: 'fade-edge remove-padding-top', className: 'fade-edge remove-padding-top',
data: 'ownership', data: 'ownership',
render: function ( ownership, type, row, meta ) { render: function (ownership) {
return '<div><label class="label-bold">Ownership&nbsp;:&nbsp;</label>' + ownership + '</div>'; return '<div><label class="label-bold">Ownership&nbsp;:&nbsp;</label>' + ownership + '</div>';
} }
} }
]; ];
var dataFilter = function(data){ var dataFilter = function (data) {
data = JSON.parse(data); data = JSON.parse(data);
var objects = []; var objects = [];
$(data.devices).each(function( index ) { $(data.devices).each(function (index) {
objects.push( objects.push(
{ {
model: getPropertyValue(data.devices[index].properties, 'DEVICE_MODEL'), model: getPropertyValue(data.devices[index].properties, "DEVICE_MODEL"),
vendor: getPropertyValue(data.devices[index].properties, 'VENDOR'), vendor: getPropertyValue(data.devices[index].properties, "VENDOR"),
owner: data.devices[index].enrolmentInfo.owner, user: data.devices[index].enrolmentInfo.owner,
status: data.devices[index].enrolmentInfo.status, status: data.devices[index].enrolmentInfo.status,
ownership: data.devices[index].enrolmentInfo.ownership, ownership: data.devices[index].enrolmentInfo.ownership,
deviceType: data.devices[index].type, deviceType: data.devices[index].type,
@ -283,135 +175,29 @@ function loadDevices(searchType, searchParam){
); );
}); });
json = { var json = {
"recordsTotal": data.count, "recordsTotal": data.count,
"recordsFiltered": data.count, "recordsFiltered": data.count,
"data": objects "data": objects
}; };
return JSON.stringify( json ); return JSON.stringify(json);
}; };
$('#device-grid').datatables_extended_serverside_paging(
$('#device-grid').datatables_extended_serverside_paging(null, '/api/device-mgt/v1.0/devices', dataFilter, columns, fnCreatedRow, null,
function( oSettings ) { "/api/device-mgt/v1.0/devices",
dataFilter,
columns,
fnCreatedRow,
function () {
$(".icon .text").res_text(0.2); $(".icon .text").res_text(0.2);
$('#device-grid').removeClass('hidden'); $('#device-grid').removeClass('hidden');
$("#loading-content").remove(); $("#loading-content").remove();
}, { }, {
"placeholder": "Search By Device Name", "placeholder" : "Search By Device Name",
"searchKey" : "name" "searchKey" : "name"
}); });
// $('#device-grid').datatables_extended({
// serverSide: true,
// processing: false,
// searching: true,
// ordering: false,
// filter: false,
// pageLength : 16,
// ajax: { url : '/emm/api/devices', data : {url : serviceURL},
// dataSrc: function (json) {
// $('#device-grid').removeClass('hidden');
// $("#loading-content").remove();
// var $list = $("#device-table :input[type='search']");
// $list.each(function(){
// $(this).addClass("hidden");
// });
// return json.devices;
// }
// },
// columnDefs: [
// { targets: 0, data: 'name', className: 'remove-padding icon-only content-fill viewEnabledIcon' , render: function ( data, type, row, meta ) {
// var deviceType = row.type;
// var deviceIdentifier = row.deviceIdentifier;
// var url = "#";
// if (status != 'REMOVED') {
// url = "devices/view?type=" + deviceType + "&id=" + deviceIdentifier;
// }
// return '<div onclick="javascript:InitiateViewOption(\'' + url + '\')" class="thumbnail icon"><i class="square-element text fw fw-mobile"></i></div>';
// }},
// { targets: 1, data: 'name', className: 'fade-edge' , render: function ( name, type, row, meta ) {
// var model = getPropertyValue(row.properties, 'DEVICE_MODEL');
// var vendor = getPropertyValue(row.properties, 'VENDOR');
// var html = '<h4>Device ' + name + '</h4>';
// if (model) {
// html += '<div>(' + vendor + '-' + model + ')</div>';
// }
// return html;
// }},
// { targets: 2, data: 'enrolmentInfo.owner', className: 'fade-edge remove-padding-top'},
// { targets: 3, data: 'enrolmentInfo.status', className: 'fade-edge remove-padding-top' ,
// render: function ( status, type, row, meta ) {
// var html;
// switch (status) {
// case 'ACTIVE' :
// html = '<span><i class="fw fw-ok icon-success"></i> Active</span>';
// break;
// case 'INACTIVE' :
// html = '<span><i class="fw fw-warning icon-warning"></i> Inactive</span>';
// break;
// case 'BLOCKED' :
// html = '<span><i class="fw fw-remove icon-danger"></i> Blocked</span>';
// break;
// case 'REMOVED' :
// html = '<span><i class="fw fw-delete icon-danger"></i> Removed</span>';
// break;
// }
// return html;
// }},
// { targets: 4, data: 'type' , 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' ,
// render: function ( status, type, row, meta ) {
// var deviceType = row.type;
// var deviceIdentifier = row.deviceIdentifier;
// var html = '<span></span>';
// return html;
// }}
// ],
// "createdRow": function( row, data, dataIndex ) {
// $(row).attr('data-type', 'selectable');
// $(row).attr('data-deviceid', data.deviceIdentifier);
// $(row).attr('data-devicetype', data.type);
// var model = getPropertyValue(data.properties, 'DEVICE_MODEL');
// var vendor = getPropertyValue(data.properties, 'VENDOR');
// var owner = data.enrolmentInfo.owner;
// var status = data.enrolmentInfo.status;
// var ownership = data.enrolmentInfo.ownership;
// var deviceType = data.type;
// $.each($('td', row), function (colIndex) {
// switch(colIndex) {
// case 1:
// $(this).attr('data-search', model + ',' + vendor);
// $(this).attr('data-display', model);
// break;
// case 2:
// $(this).attr('data-grid-label', "Owner");
// $(this).attr('data-search', owner);
// $(this).attr('data-display', owner);
// break;
// case 3:
// $(this).attr('data-grid-label', "Status");
// $(this).attr('data-search', status);
// $(this).attr('data-display', status);
// break;
// case 4:
// $(this).attr('data-grid-label', "Type");
// $(this).attr('data-search', deviceType);
// $(this).attr('data-display', deviceType);
// break;
// case 5:
// $(this).attr('data-grid-label', "Ownership");
// $(this).attr('data-search', ownership);
// $(this).attr('data-display', ownership);
// break;
// }
// });
// },
// "fnDrawCallback": function( oSettings ) {
// $(".icon .text").res_text(0.2);
// }
// });
$(deviceCheckbox).click(function () { $(deviceCheckbox).click(function () {
addDeviceSelectedClass(this); addDeviceSelectedClass(this);
}); });
@ -420,8 +206,7 @@ function loadDevices(searchType, searchParam){
/* /*
* Setting-up global variables. * Setting-up global variables.
*/ */
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; //var assetContainer = "#ast-container";
var assetContainer = "#ast-container";
function openCollapsedNav(){ function openCollapsedNav(){
$('.wr-hidden-nav-toggle-btn').addClass('active'); $('.wr-hidden-nav-toggle-btn').addClass('active');
@ -434,29 +219,25 @@ function openCollapsedNav(){
function initPage() { function initPage() {
var currentUser = $("#device-listing").data("currentUser"); var currentUser = $("#device-listing").data("currentUser");
var serviceURL; var serviceURL = "/api/device-mgt/v1.0/devices";
if ($.hasPermission("LIST_DEVICES")) {
serviceURL ="/api/device-mgt/v1.0/devices"
} else if ($.hasPermission("LIST_OWN_DEVICES")) {
//Get authenticated users devices
serviceURL = "/api/device-mgt/v1.0/devices?user=" + currentUser;
}
invokerUtil.get( invokerUtil.get(
serviceURL, serviceURL,
function (data) { function (data) {
if (data) { if (data) {
data = JSON.parse(data); data = JSON.parse(data);
if (data.devices.length > 0) { if (data.devices.length > 0) {
$(".bulk-action-row").removeClass('hidden');
loadDevices(); loadDevices();
} else { } else {
$("#loading-content").remove(); $("#loading-content").remove();
$("#device-table").remove(); $("#device-table").remove();
$("#no-device-view").removeClass(' hidden'); $("#no-device-view").removeClass('hidden');
$("#advanced-search-btn").addClass(' hidden'); $("#advanced-search-btn").addClass('hidden');
$("#enroll-btn").addClass(' hidden'); $("#enroll-btn").addClass('hidden');
} }
} }
}, function (message) { }, function () {
initPage(); initPage();
} }
); );
@ -473,12 +254,6 @@ $(document).ready(function () {
addDeviceSelectedClass(this); addDeviceSelectedClass(this);
}); });
var i;
var permissionList = $("#permission").data("permission");
for (i = 0; i < permissionList.length; i++) {
$.setPermission(permissionList[i]);
}
/* for device list sorting drop down */ /* for device list sorting drop down */
$(".ctrl-filter-type-switcher").popover({ $(".ctrl-filter-type-switcher").popover({
html : true, html : true,
@ -487,36 +262,14 @@ $(document).ready(function () {
} }
}); });
$(".ast-container").on("click", ".claim-btn", function(e){
e.stopPropagation();
var deviceId = $(this).data("deviceid");
var deviceListing = $("#device-listing");
var currentUser = deviceListing.data("current-user");
var serviceURL = "/temp-controller-agent/enrollment/claim?username=" + currentUser;
var deviceIdentifier = {id: deviceId, type: "TemperatureController"};
invokerUtil.put(serviceURL, deviceIdentifier, function(message){
console.log(message);
}, function(message){
console.log(message.content);
});
});
/* for data tables*/ /* for data tables*/
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
$("[data-toggle=popover]").popover(); $("[data-toggle=popover]").popover();
$(".ctrl-filter-type-switcher").popover({
html : true,
content: function() {
return $('#content-filter-types').html();
}
});
$('#nav').affix({ $('#nav').affix({
offset: { offset: {
top: $('header').height() top: $('header').height()
} }
}); });
}); });

@ -1,42 +0,0 @@
{{#each devices}}
{{deviceMap this}}
<tr data-type="selectable" data-deviceid="{{deviceIdentifier}}" data-devicetype="{{type}}">
<td class="remove-padding icon-only content-fill viewEnabledIcon"
{{#unequal enrolmentInfo.status "REMOVED"}}
data-url="device?type={{type}}&id={{deviceIdentifier}}"
{{/unequal}}
>
<div class="thumbnail icon">
<i class="square-element text fw fw-mobile"></i>
</div>
</td>
<td class="fade-edge" data-search="{{properties.DEVICE_MODEL}},{{properties.VENDOR}}" data-display="{{properties.DEVICE_MODEL}}">
<h4>Device {{name}}</h4>
{{#if properties.DEVICE_MODEL}}
<div>({{properties.VENDOR}} - {{properties.DEVICE_MODEL}})</div>
{{/if}}
</td>
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.owner}}" data-display="{{enrolmentInfo.owner}}" data-grid-label="Owner">{{enrolmentInfo.owner}}</td>
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.status}}" data-display="{{enrolmentInfo.status}}" data-grid-label="Status">
{{#equal enrolmentInfo.status "ACTIVE"}}<span><i class="fw fw-ok icon-success"></i> Active</span>{{/equal}}
{{#equal enrolmentInfo.status "INACTIVE"}}<span><i class="fw fw-warning icon-warning"></i> Inactive</span>{{/equal}}
{{#equal enrolmentInfo.status "BLOCKED"}}<span><i class="fw fw-remove icon-danger"></i> Blocked</span>{{/equal}}
{{#equal enrolmentInfo.status "REMOVED"}}<span><i class="fw fw-delete icon-danger"></i> Removed</span>{{/equal}}
</td>
<td class="fade-edge remove-padding-top" data-search="{{type}}" data-display="{{type}}" data-grid-label="Type">{{type}}</td>
<td class="fade-edge remove-padding-top" data-search="{{enrolmentInfo.ownership}}" data-display="{{enrolmentInfo.ownership}}" data-grid-label="Ownership">{{enrolmentInfo.ownership}}</td>
<td class="text-right content-fill text-left-on-grid-view no-wrap">
<!--{{#equal type "TemperatureController"}}
{{#equal status "INACTIVE"}}
<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view claim-btn" data-deviceid="{{deviceIdentifier}}">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-edit fw-stack-1x"></i>
</span>
<span class="hidden-xs hidden-on-grid-view">Claim</span>
</a>
{{/equal}}
{{/equal}}-->
</td>
</tr>
{{/each}}

@ -22,30 +22,20 @@
{{/zone}} {{/zone}}
{{#zone "navMenu-items"}} {{#zone "navMenu-items"}}
{{#if permissions.VIEW_DASHBOARD}}
<li> <li>
<a href="{{@app.context}}"> <a href="{{@app.context}}">
<i class="fw fw-dashboard"></i> <i class="fw fw-dashboard"></i>
Admin Dashboard Admin Dashboard
</a> </a>
</li> </li>
{{/if}}
{{#if permissions.LIST_DEVICES_ADMIN}} {{#if permissions.LIST_DEVICES}}
<li> <li>
<a href="{{@app.context}}/devices"> <a href="{{@app.context}}/devices">
<i class="fw fw-mobile"></i> <i class="fw fw-mobile"></i>
Device Management Device Management
</a> </a>
</li> </li>
{{else}}
{{#if permissions.LIST_OWN_DEVICES}}
<li>
<a href="{{@app.context}}/devices">
<i class="fw fw-mobile"></i>
Device Management
</a>
</li>
{{/if}}
{{/if}} {{/if}}
<li><a><i class="fw fw-user"></i>User Management</a> <li><a><i class="fw fw-user"></i>User Management</a>
@ -64,12 +54,12 @@
{{/if}} {{/if}}
<li><a><i class="fw fw-settings"></i>Configuration Management</a> <li><a><i class="fw fw-settings"></i>Configuration Management</a>
<ul> <ul>
{{#if permissions.TENANT_CONFIGURATION}} {{#if permissions.LIST_CONFIGURATION}}
<li><a href="{{@app.context}}/platform-configuration"><i class="fw fw-service"></i>Platform Configurations</a> <li><a href="{{@app.context}}/platform-configuration"><i class="fw fw-service"></i>Platform Configurations</a>
</li> </li>
{{/if}} {{/if}}
<!-- todo change the permission and get the related permission --> <!-- todo change the permission and get the related permission -->
{{#if permissions.TENANT_CONFIGURATION}} {{#if permissions.LIST_CONFIGURATION}}
<li><a href="{{@app.context}}/certificates"><i class="fw fw-security-policy"></i>Certificate Configurations</a> <li><a href="{{@app.context}}/certificates"><i class="fw fw-security-policy"></i>Certificate Configurations</a>
</li> </li>
{{/if}} {{/if}}
@ -93,7 +83,7 @@
</ul> </ul>
{{/zone}} {{/zone}}
{{#zone "sidePanes"}} {{#zone "sidePanes"}}
<div class="sidebar-wrapper" id="right-sidebar" is-authorized="{{isAuthorizedForNotifications}}" <div class="sidebar-wrapper" id="right-sidebar" is-authorized="{{permissions.LIST_NOTIFICATIONS}}"
data-side="right" data-width="320" data-sidebar-fixed="true" data-fixed-offset="50" data-spy="affix" data-side="right" data-width="320" data-sidebar-fixed="true" data-fixed-offset="50" data-spy="affix"
data-offset-top="80"> data-offset-top="80">
<ul class="sidebar-messages"> <ul class="sidebar-messages">

@ -30,27 +30,30 @@ function onRequest(context) {
var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"]; var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
var constants = require("/app/modules/constants.js"); var constants = require("/app/modules/constants.js");
var uiPermissions = userModule.getUIPermissions();
context["permissions"] = uiPermissions;
var links = { var links = {
"user-mgt": [], "user-mgt": [],
"role-mgt": [], "role-mgt": [],
"policy-mgt": [], "policy-mgt": [],
"device-mgt": [] "device-mgt": []
}; };
var viewModel = {};
// following context.link value comes here based on the value passed at the point // following viewModel.link value comes here based on the value passed at the point
// where units are attached to a page zone. // where units are attached to a page zone.
// eg: {{unit "appbar" pageLink="users" title="User Management"}} // eg: {{unit "appbar" pageLink="users" title="User Management"}}
context["currentActions"] = links[context["pageLink"]]; viewModel["currentActions"] = links[viewModel["pageLink"]];
context["enrollmentURL"] = mdmProps["generalConfig"]["host"] + mdmProps["enrollmentDir"]; viewModel["enrollmentURL"] = mdmProps["generalConfig"]["host"] + mdmProps["enrollmentDir"];
var isAuthorizedForNotifications =
userModule.isAuthorized("/permission/admin/device-mgt/emm-admin/notifications/view");
var currentUser = session.get(constants["USER_SESSION_KEY"]); var currentUser = session.get(constants["USER_SESSION_KEY"]);
context["isAuthorizedForNotifications"] = isAuthorizedForNotifications; var permissions = {};
context["currentUser"] = currentUser; permissions.LIST_DEVICES = userModule.isAuthorized("/permission/admin/device-mgt/devices/owning/view");
context["appContext"] = mdmProps["appContext"]; permissions.LIST_POLICIES = userModule.isAuthorized("/permission/admin/device-mgt/policies/view");
permissions.LIST_ROLES = userModule.isAuthorized("/permission/admin/device-mgt/roles/view");
permissions.LIST_USERS = userModule.isAuthorized("/permission/admin/device-mgt/users/view");
permissions.LIST_NOTIFICATIONS = userModule.isAuthorized("/permission/admin/device-mgt/notifications/view");
permissions.LIST_CONFIGURATION = userModule.isAuthorized("/permission/admin/device-mgt/configurations/view");
viewModel.permissions = permissions;
viewModel["currentUser"] = currentUser;
viewModel["appContext"] = mdmProps["appContext"];
return context; return viewModel;
} }
Loading…
Cancel
Save