Add groups in device list

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

@ -1,8 +1,8 @@
{{#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>
<!-- 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 -->
<div class="container-fluid wr-content-alt">
<div class="ctrl-info-panel col-md-6 col-centered">
@ -52,6 +52,16 @@
<!-- /no devices found -->
</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 class="content">
<div class="row">
@ -248,6 +258,8 @@
</div>
{{/zone}}
{{#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/"
src="{{self.publicURL}}/templates/device-listing.hbs" type="text/x-handlebars-template"></script>
<script src="{{self.publicURL}}/js/device-listing.js"></script>

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

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

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