Merge pull request #404 from sameeragunarathne/IoTS-1.0.0

add group listing  and group device listing fixes
revert-70aa11f8
Charitha Goonetilleke 8 years ago committed by GitHub
commit 353707c9c7

@ -128,6 +128,12 @@ public interface DeviceManagementService {
@QueryParam("status")
@Size(max = 45)
String status,
@ApiParam(
name = "groupId",
value = "Id of the group which device belongs",
required = false)
@QueryParam("groupId")
int groupId,
@ApiParam(
name = "since",
value = "Checks if the requested variant was created since the specified date-time.\n" +

@ -71,6 +71,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@QueryParam("user") String user,
@QueryParam("ownership") String ownership,
@QueryParam("status") String status,
@QueryParam("groupId") int groupId,
@QueryParam("since") String since,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset,
@ -107,6 +108,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
RequestValidationUtil.validateStatus(status);
request.setStatus(status);
}
if (groupId != 0 ) {
request.setGroupId(groupId);
}
// this is the user who initiates the request
String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername();

@ -53,11 +53,11 @@ var groupModule = {};
);
};
groupModule.getGroupDeviceCount = function (groupName, owner) {
endPoint = deviceServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices/count";
groupModule.getGroupDeviceCount = function (groupId) {
endPoint = deviceServiceEndpoint + "/groups/id/" + groupId + "/devices/count";
return serviceInvokers.XMLHttp.get(
endPoint, function (responsePayload) {
return responsePayload;
return responsePayload["responseText"];
},
function (responsePayload) {
log.error(responsePayload);
@ -67,7 +67,7 @@ var groupModule = {};
};
groupModule.getGroupDevices = function (groupName, owner) {
endPoint = deviceServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices";
endPoint = deviceServiceEndpoint + "/groups/owner/" + owner + "/name/" + groupName + "/devices";
return serviceInvokers.XMLHttp.get(
endPoint, function (responsePayload) {
return responsePayload;

@ -22,7 +22,7 @@ function onRequest(context) {
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
var groupName = request.getParameter("groupName");
var groupOwner = request.getParameter("groupOwner");
var groupId = request.getParameter("groupId");
var viewModel = {};
var title = "Devices";
@ -41,9 +41,9 @@ function onRequest(context) {
}
viewModel.currentUser = currentUser;
var deviceCount = 0;
if (groupName && groupOwner) {
if (groupId) {
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
deviceCount = groupModule.getGroupDeviceCount(groupName, groupOwner);
deviceCount = groupModule.getGroupDeviceCount(groupId);
} else {
deviceCount = deviceModule.getDevicesCount();
}

@ -554,7 +554,7 @@ function attachDeviceEvents() {
var serviceURL;
if ($.hasPermission("LIST_ALL_GROUPS")) {
serviceURL = "/api/device-mgt/v1.0/groups/all";
serviceURL = "/api/device-mgt/v1.0/groups";
} else if ($.hasPermission("LIST_GROUPS")) {
//Get authenticated users groups
serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser + "/all";
@ -563,18 +563,18 @@ function attachDeviceEvents() {
invokerUtil.get(serviceURL, function (data) {
var groups = JSON.parse(data);
var str = '<br /><select id="assign-group-selector" style="color:#3f3f3f;padding:5px;width:250px;">';
for (var i = 0; i < groups.length; i++) {
str += '<option value="' + groups[i].owner + "/name/" + groups[i].name + '">' +
groups[i].name + '</option>';
for (var i = 0; i < groups.deviceGroups.length; i++) {
str += '<option value="' + groups.deviceGroups[i].id + '">' +
groups.deviceGroups[i].name + '</option>';
}
str += '</select>';
$('#user-groups').html(str);
$("a#group-device-yes-link").show();
$("a#group-device-yes-link").click(function () {
var selectedGroup = $('#assign-group-selector').val();
serviceURL = "/api/device-mgt/v1.0/groups/owner/" + selectedGroup + "/devices";
var device = {"id": deviceId, "type": deviceType};
invokerUtil.post(serviceURL, device, function (data) {
serviceURL = "/api/device-mgt/v1.0/groups/id/" + selectedGroup + "/devices";
var deviceIdentifiers = [{"id":deviceId,"type":deviceType}];
invokerUtil.post(serviceURL, deviceIdentifiers, function (data) {
$(modalPopupContent).html($('#group-associate-device-200-content').html());
setTimeout(function () {
hidePopup();

@ -45,9 +45,8 @@ $(function () {
} else {
var group = {"name": name, "description": description};
var successCallback = function (jqXHR) {
var data = JSON.parse(jqXHR);
if (data.status == 201) {
var successCallback = function (jqXHR, status, resp) {
if (resp.status == 201) {
$('.wr-validation-summary strong').text("Group created. You will be redirected to groups");
$('.wr-validation-summary').removeClass("hidden");
$('.wr-validation-summary strong').removeClass("label-danger");
@ -56,11 +55,11 @@ $(function () {
window.location = "../groups";
}, 1500);
} else {
displayErrors(data.status);
displayErrors(resp.status);
}
};
invokerUtil.post("/devicemgt_admin/groups", group,
invokerUtil.post("/api/device-mgt/v1.0/groups", group,
successCallback, function (message) {
displayErrors(message);
});

@ -18,7 +18,7 @@
{{unit "cdmf.unit.ui.title" pageTitle="Group Management"}}
{{unit "cdmf.unit.ui.content.title" pageHeader="Groups"}}
{{unit "cdmf.unit.lib.data-table"}}
{{unit "cdmf.unit.data-tables-extended"}}
{{#zone "breadcrumbs"}}
<li>

@ -22,6 +22,12 @@
var groupCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
var assetContainer = "#ast-container";
function InitiateViewOption() {
if ($(".select-enable-btn").text() == "Select") {
$(location).attr('href', $(this).data("url"));
}
}
/*
* On Select All Groups button click function.
*
@ -100,10 +106,10 @@ function loadGroups() {
var currentUser = groupListing.data("currentUser");
var serviceURL;
if ($.hasPermission("LIST_ALL_GROUPS")) {
serviceURL = "/devicemgt_admin/groups";
serviceURL = "/api/device-mgt/v1.0/groups";
} else if ($.hasPermission("LIST_GROUPS")) {
//Get authenticated users groups
serviceURL = "/devicemgt_admin/groups/user/" + currentUser;
serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser;
} else {
$("#loading-content").remove();
$('#device-table').addClass('hidden');
@ -112,33 +118,46 @@ function loadGroups() {
return;
}
$('#group-grid').datatables_extended ({
serverSide: true,
processing: false,
searching: true,
ordering: false,
filter: false,
pageLength : 16,
ajax: { url : '/devicemgt/api/groups', data : {url : serviceURL},
dataSrc: function ( json ) {
$('#group-grid').removeClass('hidden');
var $list = $("#group-listing :input[type='search']");
$list.each(function(){
$(this).addClass("hidden");
});
return json.data;
var dataFilter = function (data) {
data = JSON.parse(data);
var objects = [];
$(data.deviceGroups).each(function (index) {
objects.push({
groupId: data.deviceGroups[index].id,
name: data.deviceGroups[index].name,
description: data.deviceGroups[index].description,
owner: data.deviceGroups[index].owner,
dateOfCreation: data.deviceGroups[index].dateOfCreation
})
});
var json = {
"recordsTotal": data.count,
"data": objects
}
return JSON.stringify(json);
};
var columns = [{
targets: 0,
data: 'id',
class: 'remove-padding icon-only content-fill',
render: function (data, type, row, meta) {
return '<div class="thumbnail icon"><img class="square-element text fw " src="public/cdmf.page.groups/images/group-icon.png"/></div>';
}
},
columnDefs: [
{ targets: 0, data: 'id', className: 'remove-padding icon-only content-fill' , render: function ( data, type, row, meta ) {
return '<div class="thumbnail icon"><img class="square-element text fw " src="public/cdmf.page.groups/images/group-icon.png"/></div>';
}},
{targets: 1, data: 'name', className: 'fade-edge'},
{ targets: 2, data: 'owner', className: 'fade-edge remove-padding-top'},
{ targets: 3, data: 'id', className: 'text-right content-fill text-left-on-grid-view no-wrap' ,
{
targets: 1,
data: 'name',
class: 'fade-edge'
},
{
targets: 3,
data: 'id',
class: 'text-right content-fill text-left-on-grid-view no-wrap',
render: function (id, type, row, meta) {
var html;
html = '<a href="devices?groupName=' + row.name + '&groupOwner=' + row.owner + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
html = '<a href="devices?groupId=' + row.groupId + '&groupOwner=' + row.owner + '" data-click-event="remove-form" class="btn padding-reduce-on-grid-view">' +
'<span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-view fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">View Devices</span></a>';
@ -151,17 +170,20 @@ function loadGroups() {
'<span class="hidden-xs hidden-on-grid-view">Share</span></a>';
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-group-link" data-group-name="' + row.name + '" ' +
'data-group-owner="' + row.owner + '" data-group-description="' + row.description + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
'data-group-owner="' + row.owner + '" data-group-description="' + row.description + '" data-group-id="'+row.groupId+'"><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">Edit</span></a>';
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-group-link" data-group-name="' + row.name + '" ' +
html += '<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-group-link" data-group-id="' + row.groupId + '" ' +
'data-group-owner="' + row.owner + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i><i class="fw fw-delete fw-stack-1x"></i>' +
'</span><span class="hidden-xs hidden-on-grid-view">Delete</span></a>';
return html;
}}
],
"createdRow": function( row, data, dataIndex ) {
}
}
];
var fnCreatedRow = function (row, data) {
$(row).attr('data-type', 'selectable');
$(row).attr('data-groupid', data.id);
$.each($('td', row), function (colIndex) {
@ -178,11 +200,22 @@ function loadGroups() {
break;
}
});
},
"fnDrawCallback": function( oSettings ) {
};
$('#group-grid').datatables_extended_serverside_paging(
null,
serviceURL,
dataFilter,
columns,
fnCreatedRow,
function (oSettings) {
$(".icon .text").res_text(0.2);
attachEvents();
}
},
{
"placeholder": "Search By Group Name",
"searchKey": "name"
});
$(groupCheckbox).click(function () {
addGroupSelectedClass(this);
@ -318,15 +351,13 @@ function attachEvents() {
* on Group Management page in WSO2 IoT Server Console.
*/
$("a.remove-group-link").click(function () {
var groupName = $(this).data("group-name");
var groupOwner = $(this).data("group-owner");
var groupId = $(this).data("group-id");
$(modalPopupContent).html($('#remove-group-modal-content').html());
showPopup();
$("a#remove-group-yes-link").click(function () {
var successCallback = function (data, textStatus, xhr) {
data = JSON.parse(data);
if (xhr.status == 200) {
$(modalPopupContent).html($('#remove-group-200-content').html());
setTimeout(function () {
@ -338,7 +369,7 @@ function attachEvents() {
}
};
invokerUtil.delete("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName,
invokerUtil.delete("/api/device-mgt/v1.0/groups/id/" + groupId,
successCallback, function (message) {
displayErrors(message);
});
@ -356,6 +387,7 @@ function attachEvents() {
* on Device Management page in WSO2 MDM Console.
*/
$("a.edit-group-link").click(function () {
var groupId = $(this).data("group-id");
var groupName = $(this).data("group-name");
var groupOwner = $(this).data("group-owner");
var groupDescription = $(this).data("group-description");
@ -371,8 +403,8 @@ function attachEvents() {
var group = {"name": newGroupName, "description": newGroupDescription, "owner": groupOwner};
var successCallback = function (data, textStatus, xhr) {
data = JSON.parse(data);
if (xhr.status == 200) {
$(modalPopupContent).html($('#edit-group-200-content').html());
setTimeout(function () {
hidePopup();
location.reload(false);
@ -382,7 +414,7 @@ function attachEvents() {
}
};
invokerUtil.put("/devicemgt_admin/groups/owner/" + groupOwner + "/name/" + groupName, group,
invokerUtil.put("/api/device-mgt/v1.0/groups/id/" + groupId, group,
successCallback, function (message) {
displayErrors(message);
});

Loading…
Cancel
Save