Add groups in device list

merge-requests/1/head
charithag 9 years ago
parent dbe107e538
commit b7780e1742

@ -1,8 +1,8 @@
{{#zone "main"}} {{#zone "main"}}
<span id="permission" data-permission="{{permissions}}"></span> <span id="permission" data-user="{{user}}" data-permission="{{permissions}}"></span>
<span id="request-group-id" data-groupid="{{groupId}}"></span> <span id="request-group-id" data-groupid="{{groupId}}"></span>
<!-- form content placeholder --> <!-- form content placeholder -->
<div id="ast-container" class="ast-container list-view"> <div id="ast-container-parent" class="ast-container list-view">
<!-- no devices found --> <!-- no devices found -->
<div class="container-fluid wr-content-alt"> <div class="container-fluid wr-content-alt">
<div class="ctrl-info-panel col-md-6 col-centered"> <div class="ctrl-info-panel col-md-6 col-centered">
@ -52,6 +52,16 @@
<!-- /no devices found --> <!-- /no devices found -->
</div> </div>
<div id="no-devices-in-group-div-content" class="hide">
<!-- no devices found -->
<div class="container-fluid">
<div class="ctrl-info-panel col-md-6 col-centered">
<h3>You don't have any associated devices here.</h3>
</div>
</div>
<!-- /no devices found -->
</div>
<div id="remove-device-modal-content" class="hide"> <div id="remove-device-modal-content" class="hide">
<div class="content"> <div class="content">
<div class="row"> <div class="row">
@ -248,6 +258,8 @@
</div> </div>
{{/zone}} {{/zone}}
{{#zone "bottomJs"}} {{#zone "bottomJs"}}
<script id="group-listing" src="{{self.publicURL}}/templates/group-listing.hbs"
type="text/x-handlebars-template"></script>
<script id="device-listing" data-image-resource="{{self.publicURL}}/images/" <script id="device-listing" data-image-resource="{{self.publicURL}}/images/"
src="{{self.publicURL}}/templates/device-listing.hbs" type="text/x-handlebars-template"></script> src="{{self.publicURL}}/templates/device-listing.hbs" type="text/x-handlebars-template"></script>
<script src="{{self.publicURL}}/js/device-listing.js"></script> <script src="{{self.publicURL}}/js/device-listing.js"></script>

@ -1,6 +1,7 @@
var log = new Log("modules/device-listing.js"); var log = new Log("modules/device-listing.js");
function onRequest(context){ function onRequest(context){
var constants = require("/modules/constants.js");
var userModule = require("/modules/user.js").userModule; var userModule = require("/modules/user.js").userModule;
var permissions = []; var permissions = [];
if(userModule.isAuthorized("/permission/device-mgt/admin/devices/list")){ if(userModule.isAuthorized("/permission/device-mgt/admin/devices/list")){
@ -19,6 +20,6 @@ function onRequest(context){
}else{ }else{
context.groupId = 0; context.groupId = 0;
} }
context.user = session.get(constants.USER_SESSION_KEY).username;
return context; return context;
} }

@ -16,12 +16,17 @@
* under the License. * under the License.
*/ */
var groupId, user;
(function () { (function () {
var cache = {}; var cache = {};
var permissionSet = {}; var permissionSet = {};
var validateAndReturn = function (value) { var validateAndReturn = function (value) {
return (value == undefined || value == null) ? "Unspecified" : value; return (value == undefined || value == null) ? "Unspecified" : value;
}; };
Handlebars.registerHelper("groupMap", function (group) {
group.id = validateAndReturn(group.id);
});
Handlebars.registerHelper("deviceMap", function (device) { Handlebars.registerHelper("deviceMap", function (device) {
device.owner = validateAndReturn(device.owner); device.owner = validateAndReturn(device.owner);
device.ownership = validateAndReturn(device.ownership); device.ownership = validateAndReturn(device.ownership);
@ -33,6 +38,13 @@
}, {}); }, {});
} }
}); });
Handlebars.registerHelper("if_owner", function (owner, opts) {
if (owner == user){
return opts.fn(this);
}else{
opts.inverse(this);
}
});
//This method is used to setup permission for device listing //This method is used to setup permission for device listing
$.setPermission = function (permission) { $.setPermission = function (permission) {
@ -47,13 +59,12 @@
/* /*
* Setting-up global variables. * Setting-up global variables.
*/ */
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; var deviceCheckbox = "#ast-container-parent .ctrl-wr-asset .itm-select input[type='checkbox']";
var assetContainer = "#ast-container"; var assetContainerParent = "#ast-container-parent";
/* /*
* DOM ready functions. * DOM ready functions.
*/ */
var groupId;
$(document).ready(function () { $(document).ready(function () {
/* Adding selected class for selected devices */ /* Adding selected class for selected devices */
$(deviceCheckbox).each(function () { $(deviceCheckbox).each(function () {
@ -61,6 +72,7 @@ $(document).ready(function () {
}); });
var i; var i;
user = $("#permission").data("user");
var permissionList = $("#permission").data("permission"); var permissionList = $("#permission").data("permission");
for (i = 0; i < permissionList.length; i++) { for (i = 0; i < permissionList.length; i++) {
$.setPermission(permissionList[i]); $.setPermission(permissionList[i]);
@ -113,9 +125,9 @@ function changeDeviceView(view, selection) {
}); });
$(selection).addClass("selected"); $(selection).addClass("selected");
if (view == "list") { if (view == "list") {
$(assetContainer).addClass("list-view"); $(assetContainerParent).addClass("list-view");
} else { } else {
$(assetContainer).removeClass("list-view"); $(assetContainerParent).removeClass("list-view");
} }
} }
@ -131,63 +143,60 @@ function addDeviceSelectedClass(checkbox) {
$(checkbox).closest(".ctrl-wr-asset").removeClass("selected device-select"); $(checkbox).closest(".ctrl-wr-asset").removeClass("selected device-select");
} }
} }
function loadDevices(searchType, searchParam) {
var deviceListing = $("#device-listing"); function loadDevices() {
var deviceListingSrc = deviceListing.attr("src"); var groupListing = $("#group-listing");
var imageResource = deviceListing.data("image-resource"); var groupListingSrc = groupListing.attr("src");
$.template("device-listing", deviceListingSrc, function (template) { $.template("group-listing", groupListingSrc, function (template) {
var serviceURL; var serviceURL;
if ($.hasPermission("LIST_DEVICES")) { if (groupId && groupId != "0") {
if (groupId && groupId != "0") { serviceURL = "/iotserver/api/group/id/" + groupId + "/device/all";
serviceURL = "/iotserver/api/group/id/" + groupId + "/device/all";
} else {
serviceURL = "/iotserver/api/devices/all";
}
} else if ($.hasPermission("LIST_OWN_DEVICES")) {
//Get authenticated users devices
if (groupId && groupId != "0") {
serviceURL = "/iotserver/api/group/id/" + groupId + "/device/all";
} else {
serviceURL = "/iotserver/api/devices/all";
}
} else { } else {
$("#ast-container").html("Permission denied"); serviceURL = "/iotserver/api/devices/all";
return;
}
if (searchParam) {
if (searchType == "users") {
serviceURL = serviceURL + "?user=" + searchParam;
} else if (searchType == "user-roles") {
serviceURL = serviceURL + "?role=" + searchParam;
} else {
serviceURL = serviceURL + "?type=" + searchParam;
}
} }
var successCallback = function (data) { var successCallback = function (data) {
data = JSON.parse(data); data = JSON.parse(data);
var viewModel = {}; var viewModel = {};
var groups;
if (groupId && groupId != "0") { if (groupId && groupId != "0") {
data.data = data; groups = data;
} else {
groups = data.data;
} }
viewModel.devices = data.data; viewModel.groups = groups;
viewModel.imageLocation = imageResource; if (!groups || groups.length <= 0) {
if (!data.data || data.data.length <= 0) {
if (groupId && groupId != "0") { if (groupId && groupId != "0") {
$("#ast-container").html($("#no-grouped-devices-div-content").html()); $("#ast-container-parent").html($("#no-grouped-devices-div-content").html());
} else { } else {
$("#ast-container").html($("#no-devices-div-content").html()); $("#ast-container-parent").html($("#no-devices-div-content").html());
} }
} else { } else {
var content = template(viewModel); var content = template(viewModel);
$("#ast-container").html(content); $("#ast-container-parent").html(content);
/* var deviceListing = $("#device-listing");
* On device checkbox select add parent selected style class var deviceListingSrc = deviceListing.attr("src");
*/ var imageResource = deviceListing.data("image-resource");
$(deviceCheckbox).click(function () { $.template("device-listing", deviceListingSrc, function (template) {
addDeviceSelectedClass(this); for (var g in groups) {
if (groups[g].devices && groups[g].devices.length > 0){
viewModel = {};
viewModel.devices = groups[g].devices;
viewModel.imageLocation = imageResource;
content = template(viewModel);
}else{
content = $("#no-devices-in-group-div-content").html();
}
$("#ast-container-" + groups[g].id).html(content);
}
/*
* On device checkbox select add parent selected style class
*/
$(deviceCheckbox).click(function () {
addDeviceSelectedClass(this);
});
attachEvents();
formatDates();
}); });
attachEvents();
formatDates();
} }
}; };
invokerUtil.get(serviceURL, invokerUtil.get(serviceURL,
@ -376,7 +385,7 @@ function attachEvents() {
*/ */
if (groupId && groupId != "0") { if (groupId && groupId != "0") {
$("a.group-device-link").remove(); $("a.group-device-link").remove();
}else{ } else {
$("a.group-device-link").click(function () { $("a.group-device-link").click(function () {
var deviceId = $(this).data("deviceid"); var deviceId = $(this).data("deviceid");
var deviceType = $(this).data("devicetype"); var deviceType = $(this).data("devicetype");

@ -28,13 +28,15 @@
</span> </span>
<span class="lbl-action">View</span> <span class="lbl-action">View</span>
</a> </a>
<a href="#" class="group-device-link" data-deviceid="{{deviceIdentifier}}" data-devicetype="{{type}}" data-devicename="{{name}}"> {{#if_owner enrolmentInfo.owner }}
<a href="#" class="group-device-link" data-deviceid="{{deviceIdentifier}}" data-devicetype="{{type}}" data-devicename="{{name}}">
<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-group fw-stack-1x"></i> <i class="fw fw-group fw-stack-1x"></i>
</span> </span>
<span class="lbl-action">Group</span> <span class="lbl-action">Group</span>
</a> </a>
{{/if_owner}}
<a href="#" class="edit-device-link" data-deviceid="{{deviceIdentifier}}" data-devicetype="{{type}}" data-devicename="{{name}}"> <a href="#" class="edit-device-link" data-deviceid="{{deviceIdentifier}}" data-devicetype="{{type}}" data-devicename="{{name}}">
<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>

@ -0,0 +1,19 @@
{{#each groups}}
{{groupMap this}}
<br/>
<div class="row wr-device-board">
<div class="col-lg-12 wr-secondary-bar">
<label class="device-id device-select">
{{#if name}}
{{name}} Devices
{{else}}
Ungrouped Devices
{{/if}}
</label>
</div>
</div>
<hr/>
<div id="ast-container-{{id}}" class="ast-container">
</div>
{{/each}}
Loading…
Cancel
Save