mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
add group listing and group device listing fixes
This commit is contained in:
parent
072119d7df
commit
41f367abfa
@ -128,6 +128,12 @@ public interface DeviceManagementService {
|
|||||||
@QueryParam("status")
|
@QueryParam("status")
|
||||||
@Size(max = 45)
|
@Size(max = 45)
|
||||||
String status,
|
String status,
|
||||||
|
@ApiParam(
|
||||||
|
name = "groupId",
|
||||||
|
value = "The group name of the device included",
|
||||||
|
required = false)
|
||||||
|
@QueryParam("groupId")
|
||||||
|
int groupId,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "since",
|
name = "since",
|
||||||
value = "Checks if the requested variant was created since the specified date-time.\n" +
|
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("user") String user,
|
||||||
@QueryParam("ownership") String ownership,
|
@QueryParam("ownership") String ownership,
|
||||||
@QueryParam("status") String status,
|
@QueryParam("status") String status,
|
||||||
|
@QueryParam("groupId") int groupId,
|
||||||
@QueryParam("since") String since,
|
@QueryParam("since") String since,
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||||
@QueryParam("offset") int offset,
|
@QueryParam("offset") int offset,
|
||||||
@ -107,6 +108,9 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
RequestValidationUtil.validateStatus(status);
|
RequestValidationUtil.validateStatus(status);
|
||||||
request.setStatus(status);
|
request.setStatus(status);
|
||||||
}
|
}
|
||||||
|
if (groupId != 0 ) {
|
||||||
|
request.setGroupId(groupId);
|
||||||
|
}
|
||||||
|
|
||||||
// this is the user who initiates the request
|
// this is the user who initiates the request
|
||||||
String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername();
|
||||||
|
|||||||
@ -53,11 +53,11 @@ var groupModule = {};
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
groupModule.getGroupDeviceCount = function (groupName, owner) {
|
groupModule.getGroupDeviceCount = function (groupId, owner) {
|
||||||
endPoint = deviceServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices/count";
|
endPoint = deviceServiceEndpoint + "/groups/id/" + groupId + "/devices/count";
|
||||||
return serviceInvokers.XMLHttp.get(
|
return serviceInvokers.XMLHttp.get(
|
||||||
endPoint, function (responsePayload) {
|
endPoint, function (responsePayload) {
|
||||||
return responsePayload;
|
return responsePayload["responseText"];
|
||||||
},
|
},
|
||||||
function (responsePayload) {
|
function (responsePayload) {
|
||||||
log.error(responsePayload);
|
log.error(responsePayload);
|
||||||
@ -67,7 +67,7 @@ var groupModule = {};
|
|||||||
};
|
};
|
||||||
|
|
||||||
groupModule.getGroupDevices = function (groupName, owner) {
|
groupModule.getGroupDevices = function (groupName, owner) {
|
||||||
endPoint = deviceServiceEndpoint + "/owner/" + owner + "/name/" + groupName + "/devices";
|
endPoint = deviceServiceEndpoint + "/groups/owner/" + owner + "/name/" + groupName + "/devices";
|
||||||
return serviceInvokers.XMLHttp.get(
|
return serviceInvokers.XMLHttp.get(
|
||||||
endPoint, function (responsePayload) {
|
endPoint, function (responsePayload) {
|
||||||
return responsePayload;
|
return responsePayload;
|
||||||
|
|||||||
@ -23,6 +23,7 @@ function onRequest(context) {
|
|||||||
|
|
||||||
var groupName = request.getParameter("groupName");
|
var groupName = request.getParameter("groupName");
|
||||||
var groupOwner = request.getParameter("groupOwner");
|
var groupOwner = request.getParameter("groupOwner");
|
||||||
|
var groupId = request.getParameter("groupId");
|
||||||
|
|
||||||
var viewModel = {};
|
var viewModel = {};
|
||||||
var title = "Devices";
|
var title = "Devices";
|
||||||
@ -41,9 +42,9 @@ function onRequest(context) {
|
|||||||
}
|
}
|
||||||
viewModel.currentUser = currentUser;
|
viewModel.currentUser = currentUser;
|
||||||
var deviceCount = 0;
|
var deviceCount = 0;
|
||||||
if (groupName && groupOwner) {
|
if (groupId && groupOwner) {
|
||||||
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
|
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
|
||||||
deviceCount = groupModule.getGroupDeviceCount(groupName, groupOwner);
|
deviceCount = groupModule.getGroupDeviceCount(groupId, groupOwner);
|
||||||
} else {
|
} else {
|
||||||
deviceCount = deviceModule.getDevicesCount();
|
deviceCount = deviceModule.getDevicesCount();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -554,7 +554,7 @@ function attachDeviceEvents() {
|
|||||||
|
|
||||||
var serviceURL;
|
var serviceURL;
|
||||||
if ($.hasPermission("LIST_ALL_GROUPS")) {
|
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")) {
|
} else if ($.hasPermission("LIST_GROUPS")) {
|
||||||
//Get authenticated users groups
|
//Get authenticated users groups
|
||||||
serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser + "/all";
|
serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser + "/all";
|
||||||
@ -563,18 +563,18 @@ function attachDeviceEvents() {
|
|||||||
invokerUtil.get(serviceURL, function (data) {
|
invokerUtil.get(serviceURL, function (data) {
|
||||||
var groups = JSON.parse(data);
|
var groups = JSON.parse(data);
|
||||||
var str = '<br /><select id="assign-group-selector" style="color:#3f3f3f;padding:5px;width:250px;">';
|
var str = '<br /><select id="assign-group-selector" style="color:#3f3f3f;padding:5px;width:250px;">';
|
||||||
for (var i = 0; i < groups.length; i++) {
|
for (var i = 0; i < groups.deviceGroups.length; i++) {
|
||||||
str += '<option value="' + groups[i].owner + "/name/" + groups[i].name + '">' +
|
str += '<option value="' + groups.deviceGroups[i].id + '">' +
|
||||||
groups[i].name + '</option>';
|
groups.deviceGroups[i].name + '</option>';
|
||||||
}
|
}
|
||||||
str += '</select>';
|
str += '</select>';
|
||||||
$('#user-groups').html(str);
|
$('#user-groups').html(str);
|
||||||
$("a#group-device-yes-link").show();
|
$("a#group-device-yes-link").show();
|
||||||
$("a#group-device-yes-link").click(function () {
|
$("a#group-device-yes-link").click(function () {
|
||||||
var selectedGroup = $('#assign-group-selector').val();
|
var selectedGroup = $('#assign-group-selector').val();
|
||||||
serviceURL = "/api/device-mgt/v1.0/groups/owner/" + selectedGroup + "/devices";
|
serviceURL = "/api/device-mgt/v1.0/groups/id/" + selectedGroup + "/devices";
|
||||||
var device = {"id": deviceId, "type": deviceType};
|
var deviceIdentifiers = [{"id":deviceId,"type":deviceType}];
|
||||||
invokerUtil.post(serviceURL, device, function (data) {
|
invokerUtil.post(serviceURL, deviceIdentifiers, function (data) {
|
||||||
$(modalPopupContent).html($('#group-associate-device-200-content').html());
|
$(modalPopupContent).html($('#group-associate-device-200-content').html());
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
hidePopup();
|
hidePopup();
|
||||||
|
|||||||
@ -45,9 +45,8 @@ $(function () {
|
|||||||
} else {
|
} else {
|
||||||
var group = {"name": name, "description": description};
|
var group = {"name": name, "description": description};
|
||||||
|
|
||||||
var successCallback = function (jqXHR) {
|
var successCallback = function (jqXHR, status, resp) {
|
||||||
var data = JSON.parse(jqXHR);
|
if (resp.status == 201) {
|
||||||
if (data.status == 201) {
|
|
||||||
$('.wr-validation-summary strong').text("Group created. You will be redirected to groups");
|
$('.wr-validation-summary strong').text("Group created. You will be redirected to groups");
|
||||||
$('.wr-validation-summary').removeClass("hidden");
|
$('.wr-validation-summary').removeClass("hidden");
|
||||||
$('.wr-validation-summary strong').removeClass("label-danger");
|
$('.wr-validation-summary strong').removeClass("label-danger");
|
||||||
@ -56,7 +55,7 @@ $(function () {
|
|||||||
window.location = "../groups";
|
window.location = "../groups";
|
||||||
}, 1500);
|
}, 1500);
|
||||||
} else {
|
} else {
|
||||||
displayErrors(data.status);
|
displayErrors(resp.status);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
{{unit "cdmf.unit.ui.title" pageTitle="Group Management"}}
|
{{unit "cdmf.unit.ui.title" pageTitle="Group Management"}}
|
||||||
{{unit "cdmf.unit.ui.content.title" pageHeader="Groups"}}
|
{{unit "cdmf.unit.ui.content.title" pageHeader="Groups"}}
|
||||||
|
|
||||||
{{unit "cdmf.unit.lib.data-table"}}
|
{{unit "cdmf.unit.data-tables-extended"}}
|
||||||
|
|
||||||
{{#zone "breadcrumbs"}}
|
{{#zone "breadcrumbs"}}
|
||||||
<li>
|
<li>
|
||||||
|
|||||||
@ -22,6 +22,12 @@
|
|||||||
var groupCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
|
var groupCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
|
||||||
var assetContainer = "#ast-container";
|
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.
|
* On Select All Groups button click function.
|
||||||
*
|
*
|
||||||
@ -100,10 +106,10 @@ function loadGroups() {
|
|||||||
var currentUser = groupListing.data("currentUser");
|
var currentUser = groupListing.data("currentUser");
|
||||||
var serviceURL;
|
var serviceURL;
|
||||||
if ($.hasPermission("LIST_ALL_GROUPS")) {
|
if ($.hasPermission("LIST_ALL_GROUPS")) {
|
||||||
serviceURL = "/devicemgt_admin/groups";
|
serviceURL = "/api/device-mgt/v1.0/groups";
|
||||||
} else if ($.hasPermission("LIST_GROUPS")) {
|
} else if ($.hasPermission("LIST_GROUPS")) {
|
||||||
//Get authenticated users groups
|
//Get authenticated users groups
|
||||||
serviceURL = "/devicemgt_admin/groups/user/" + currentUser;
|
serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser;
|
||||||
} else {
|
} else {
|
||||||
$("#loading-content").remove();
|
$("#loading-content").remove();
|
||||||
$('#device-table').addClass('hidden');
|
$('#device-table').addClass('hidden');
|
||||||
@ -112,33 +118,46 @@ function loadGroups() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#group-grid').datatables_extended ({
|
var dataFilter = function (data) {
|
||||||
serverSide: true,
|
data = JSON.parse(data);
|
||||||
processing: false,
|
var objects = [];
|
||||||
searching: true,
|
$(data.deviceGroups).each(function (index) {
|
||||||
ordering: false,
|
objects.push({
|
||||||
filter: false,
|
groupId: data.deviceGroups[index].id,
|
||||||
pageLength : 16,
|
name: data.deviceGroups[index].name,
|
||||||
ajax: { url : '/devicemgt/api/groups', data : {url : serviceURL},
|
description: data.deviceGroups[index].description,
|
||||||
dataSrc: function ( json ) {
|
owner: data.deviceGroups[index].owner,
|
||||||
$('#group-grid').removeClass('hidden');
|
dateOfCreation: data.deviceGroups[index].dateOfCreation
|
||||||
var $list = $("#group-listing :input[type='search']");
|
})
|
||||||
$list.each(function(){
|
|
||||||
$(this).addClass("hidden");
|
|
||||||
});
|
});
|
||||||
return json.data;
|
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 ) {
|
targets: 1,
|
||||||
return '<div class="thumbnail icon"><img class="square-element text fw " src="public/cdmf.page.groups/images/group-icon.png"/></div>';
|
data: 'name',
|
||||||
}},
|
class: 'fade-edge'
|
||||||
{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: 3,
|
||||||
|
data: 'id',
|
||||||
|
class: 'text-right content-fill text-left-on-grid-view no-wrap',
|
||||||
render: function (id, type, row, meta) {
|
render: function (id, type, row, meta) {
|
||||||
var html;
|
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="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>';
|
'<span class="hidden-xs hidden-on-grid-view">View Devices</span></a>';
|
||||||
|
|
||||||
@ -159,9 +178,12 @@ function loadGroups() {
|
|||||||
'</span><span class="hidden-xs hidden-on-grid-view">Delete</span></a>';
|
'</span><span class="hidden-xs hidden-on-grid-view">Delete</span></a>';
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
}}
|
}
|
||||||
],
|
}
|
||||||
"createdRow": function( row, data, dataIndex ) {
|
|
||||||
|
];
|
||||||
|
|
||||||
|
var fnCreatedRow = function (row, data) {
|
||||||
$(row).attr('data-type', 'selectable');
|
$(row).attr('data-type', 'selectable');
|
||||||
$(row).attr('data-groupid', data.id);
|
$(row).attr('data-groupid', data.id);
|
||||||
$.each($('td', row), function (colIndex) {
|
$.each($('td', row), function (colIndex) {
|
||||||
@ -178,11 +200,22 @@ function loadGroups() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
"fnDrawCallback": function( oSettings ) {
|
|
||||||
|
|
||||||
|
$('#group-grid').datatables_extended_serverside_paging(
|
||||||
|
null,
|
||||||
|
serviceURL,
|
||||||
|
dataFilter,
|
||||||
|
columns,
|
||||||
|
fnCreatedRow,
|
||||||
|
function (oSettings) {
|
||||||
$(".icon .text").res_text(0.2);
|
$(".icon .text").res_text(0.2);
|
||||||
attachEvents();
|
attachEvents();
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"placeholder": "Search By Group Name",
|
||||||
|
"searchKey": "name"
|
||||||
});
|
});
|
||||||
$(groupCheckbox).click(function () {
|
$(groupCheckbox).click(function () {
|
||||||
addGroupSelectedClass(this);
|
addGroupSelectedClass(this);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user