Merge branch 'release-2.0.x' of https://github.com/wso2/carbon-device-mgt into release-2.0.x

revert-70aa11f8
inoshperera 8 years ago
commit 148c8046fe

@ -0,0 +1,56 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.jaxrs.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.jaxrs.beans.BasePaginatedResult;
import java.util.ArrayList;
import java.util.List;
public class DeviceToGroupsAssignment extends BasePaginatedResult {
@ApiModelProperty(value = "List of device group ids.")
@JsonProperty("deviceGroupIds")
private List<Integer> deviceGroupIds = new ArrayList<>();
@ApiModelProperty(value = "Device identifier of the device needed to be assigned with group")
@JsonProperty("deviceIdentifier")
private DeviceIdentifier deviceIdentifier;
public List<Integer> getDeviceGroupIds() {
return deviceGroupIds;
}
public void setDeviceGroupIds(List<Integer> deviceGroupIds) {
this.deviceGroupIds = deviceGroupIds;
}
public DeviceIdentifier getDeviceIdentifier() {
return deviceIdentifier;
}
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
this.deviceIdentifier = deviceIdentifier;
}
}

@ -37,6 +37,7 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceToGroupsAssignment;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
@ -774,4 +775,115 @@ public interface GroupManagementService {
required = true)
@Valid List<DeviceIdentifier> deviceIdentifiers);
@Path("/device/assign")
@POST
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
value = "Assign devices to groups",
notes = "Add existing device to device groups.",
tags = "Device Group Management",
authorizations = {
@Authorization(
value = "permission",
scopes = {@AuthorizationScope(scope = "/device-mgt/groups/devices/add",
description = "Add devices")}
)
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully assign the device to groups.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while adding devices to the group.",
response = ErrorResponse.class)
})
Response updateDeviceAssigningToGroups(
@ApiParam(
name = "deviceToGroupsAssignment",
value = "Device to groups assignment",
required = true)
@Valid DeviceToGroupsAssignment deviceToGroupsAssignment);
@Path("/device")
@GET
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_GET,
value = "List of groups that have the device",
notes = "List of groups that have the device.",
tags = "Device Group Management",
authorizations = {
@Authorization(
value = "permission",
scopes = {@AuthorizationScope(scope = "/device-mgt/groups/devices/view",
description = "Add devices")}
)
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of " +
"the requested resource."),
@ApiResponse(
code = 404,
message = "No groups found.",
response = ErrorResponse.class),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred.",
response = ErrorResponse.class)
})
Response getGroups(
@ApiParam(
name = "deviceId",
value = "Id of the device.")
@QueryParam("deviceId") String deviceId,
@ApiParam(
name = "deviceType",
value = "Type of the device.")
@QueryParam("deviceType") String deviceType);
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
@ -35,12 +36,14 @@ import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceToGroupsAssignment;
import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList;
import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
public class GroupManagementServiceImpl implements GroupManagementService {
@ -243,7 +246,8 @@ public class GroupManagementServiceImpl implements GroupManagementService {
}
}
@Override public Response removeDevicesFromGroup(int groupId, List<DeviceIdentifier> deviceIdentifiers) {
@Override
public Response removeDevicesFromGroup(int groupId, List<DeviceIdentifier> deviceIdentifiers) {
try {
DeviceMgtAPIUtils.getGroupManagementProviderService().removeDevice(groupId, deviceIdentifiers);
return Response.status(Response.Status.OK).build();
@ -256,4 +260,45 @@ public class GroupManagementServiceImpl implements GroupManagementService {
}
}
@Override
public Response updateDeviceAssigningToGroups(DeviceToGroupsAssignment deviceToGroupsAssignment) {
try {
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(deviceToGroupsAssignment.getDeviceIdentifier());
GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService();
List<DeviceGroup> deviceGroups = service.getGroups(deviceToGroupsAssignment.getDeviceIdentifier());
for (DeviceGroup group : deviceGroups) {
Integer groupId = group.getGroupId();
if (deviceToGroupsAssignment.getDeviceGroupIds().contains(groupId)) {
deviceToGroupsAssignment.getDeviceGroupIds().remove(groupId);
} else if (!CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(group.getOwner())) {
DeviceMgtAPIUtils.getGroupManagementProviderService().removeDevice(groupId, deviceIdentifiers);
}
}
for (int groupId : deviceToGroupsAssignment.getDeviceGroupIds()) {
DeviceMgtAPIUtils.getGroupManagementProviderService().addDevices(groupId, deviceIdentifiers);
}
return Response.status(Response.Status.OK).build();
} catch (GroupManagementException e) {
String msg = "Error occurred while assigning device to groups.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (DeviceNotFoundException e) {
return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
}
}
@Override
public Response getGroups(String deviceId, String deviceType) {
try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType);
List<DeviceGroup> deviceGroups = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroups(deviceIdentifier);
return Response.status(Response.Status.OK).entity(deviceGroups).build();
} catch (GroupManagementException e) {
String msg = "Error occurred while removing devices from group.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -105,4 +105,33 @@ var groupModule = {};
);
};
groupModule.getGroup = function (groupId) {
return serviceInvokers.XMLHttp.get(
deviceServiceEndpoint + "/groups/id/" + groupId, function (responsePayload) {
return JSON.parse(responsePayload.responseText);
},
function (responsePayload) {
log.error(responsePayload);
return -1;
}
);
};
groupModule.getRolesOfGroup = function (groupId) {
return serviceInvokers.XMLHttp.get(
deviceServiceEndpoint + "/groups/id/" + groupId + "/roles", function (responsePayload) {
var data = JSON.parse(responsePayload.responseText);
if(data) {
return data.roles;
} else {
return [];
}
},
function (responsePayload) {
log.error(responsePayload);
return -1;
}
);
};
}(groupModule));

@ -171,7 +171,7 @@
</a>
{{/if}}
<!--suppress HtmlUnknownTarget -->
<a href="{{@app.context}}/roles/add-role">
<a href="{{@app.context}}/role/add">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>

@ -26,7 +26,7 @@
<i class="icon fw fw-home"></i>
</a>
</li>
{{#if groupName}}
{{#if group}}
<li>
<a href="{{@app.context}}/groups">
Groups
@ -34,7 +34,7 @@
</li>
<li>
<a href="#">
{{groupName}}
{{group.name}}
</a>
</li>
{{else}}
@ -47,7 +47,7 @@
{{/zone}}
{{#zone "navbarActions"}}
{{#if groupName}}
{{#if group}}
<li>
<a href="{{@app.context}}/devices" class="cu-btn">
<span class="icon fw-stack">
@ -57,6 +57,15 @@
Assign from My Devices
</a>
</li>
<li>
<a href="{{@app.context}}/group/{{group.id}}/analytics" class="cu-btn">
<span class="icon fw-stack">
<i class="fw fw-statistics fw-stack-1x"></i>
<i class="fw fw-ring fw-stack-2x"></i>
</span>
View Analytics
</a>
</li>
{{else}}
{{#if permissions.enroll}}
<li>
@ -73,6 +82,55 @@
{{/zone}}
{{#zone "content"}}
{{#if group}}
<h1 class="page-sub-title">
{{group.name}} group
</h1>
<div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;">
<div class="media">
<div id="device_overview">
<div class="media-left col-lg-1">
<div class="icon">
<img src="/devicemgt/public/cdmf.page.groups/images/group-icon.png" style="background-color: #11375b; height: 152px;">
</div>
</div>
<div class="media-body asset-desc add-padding-left-5x">
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
Overview
</div>
<table class="table table-responsive table-striped" id="members" style="margin-bottom: 0px;">
<tbody>
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Owner</td>
<td style="padding:10px 15px;">{{group.owner}}</td>
</tr>
<tr role="row" class="odd">
<td class="sorting_1" style="padding:10px 15px; width: 15%;">Shared with roles</td>
<td style="padding:10px 15px;">
{{#each roles}}
{{this}}<br/>
{{/each}}
</td>
</tr>
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px;width: 15%;">Device Count</td>
<td style="padding:10px 15px;">{{deviceCount}}</td>
</tr>
<tr role="row" class="odd">
<td class="sorting_1" style="padding:10px 15px;width: 15%;">Description</td>
<td style="padding:10px 15px;">{{group.description}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<br/>
<h1 class="page-sub-title add-margin-top-5x">
Devices in {{group.name}} group
</h1>
{{/if}}
<div class="wr-device-list row">
<div class="wr-hidden-operations wr-advance-operations"></div>
<div class="col-md-12 wr-page-content">
@ -82,7 +140,6 @@
{{#if deviceCount}}
<div id="loading-content" class="col-centered">
<i class="fw fw-settings fw-spin fw-2x"></i>
Loading devices . . .
<br>
</div>
@ -157,7 +214,7 @@
</h3>
<h3 class="text-muted">
You don't have any device
{{#if groupName}}
{{#if group}}
assigned to this group
{{else}}
enrolled
@ -165,7 +222,7 @@
at the moment.
</h3>
<h3>
{{#if groupName}}
{{#if group}}
<!--suppress HtmlUnknownTarget -->
<a href="{{@app.context}}/devices" class="btn-operations btn-default">
<span class="fw-stack">
@ -208,20 +265,16 @@
<div id="notification-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span>
</div>
<div>
<h4>
Please select group
<br>
<div id="user-groups">Loading...</div>
</h4>
</div>
<div id="user-groups">Loading...</div>
</div>
<div class="modal-footer">
<div class="buttons">
<a href="{{@app.context}}/group/add" id="group-add-link" class="btn-operations">
Add device group
</a>
<a href="#" id="group-device-yes-link" class="btn-operations">
Assign
Update assignment
</a>
<a href="#" id="group-device-cancel-link" class="btn-operations btn-default">
Cancel
</a>
@ -233,17 +286,7 @@
<div class="modal-content">
<div class="row">
<div class="col-md-3 col-centered">
<h3>Device was successfully associated with group.</h3>
</div>
</div>
</div>
</div>
<div id="group-deassociate-device-200-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-3 col-centered">
<h3>Device was successfully removed from group.</h3>
<h3>Device associations updated.</h3>
</div>
</div>
</div>

@ -20,15 +20,19 @@ function onRequest(context) {
var constants = require("/app/modules/constants.js");
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
var groupName = request.getParameter("groupName");
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
var groupId = request.getParameter("groupId");
var viewModel = {};
var title = "Devices";
if (groupName) {
title = groupName + " " + title;
viewModel.groupName = groupName;
if (groupId) {
var group = groupModule.getGroup(groupId);
if (group) {
title = group.name + " " + title;
viewModel.roles = groupModule.getRolesOfGroup(groupId);
viewModel.group = group;
}
}
viewModel.title = title;
var currentUser = session.get(constants.USER_SESSION_KEY);
@ -42,7 +46,6 @@ function onRequest(context) {
viewModel.currentUser = currentUser;
var deviceCount = 0;
if (groupId) {
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
deviceCount = groupModule.getGroupDeviceCount(groupId);
} else {
deviceCount = deviceModule.getDevicesCount();

@ -51,7 +51,7 @@ function InitiateViewOption(url) {
var deviceCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']";
var assetContainer = "#ast-container";
var deviceListing, currentUser, groupName, groupId;
var deviceListing, currentUser, groupId;
/*
* DOM ready functions.
@ -69,8 +69,7 @@ $(document).ready(function () {
deviceListing = $("#device-listing");
currentUser = deviceListing.data("current-user");
groupName = getParameterByName("groupName");
groupId = getParameterByName("groupId");
/* Adding selected class for selected devices */
@ -161,7 +160,7 @@ function toTitleCase(str) {
function loadDevices(searchType, searchParam) {
var serviceURL;
if (groupName && groupId && $.hasPermission("LIST_OWN_DEVICES")) {
if (groupId && $.hasPermission("LIST_OWN_DEVICES")) {
serviceURL = "/api/device-mgt/v1.0/groups/id/" + groupId + "/devices";
} else if ($.hasPermission("LIST_DEVICES")) {
serviceURL = "/api/device-mgt/v1.0/devices";
@ -261,7 +260,7 @@ function loadDevices(searchType, searchParam) {
return '<a href="' + context + '/device/' + row.deviceType + '?id=' + row.deviceIdentifier
+ '"><div class="thumbnail icon"><img class="square-element text fw " src="'
+ getDeviceTypeThumb(
row.deviceType) + '"/></div></a>';
row.deviceType) + '"/></div></a>';
}
},
{
@ -345,33 +344,33 @@ function loadDevices(searchType, searchParam) {
'<span class="hidden-xs hidden-on-grid-view">Analytics</span>';
}
if ((!groupName || !groupId) && groupingEnabled(row.deviceType)) {
if (!groupId && groupingEnabled(row.deviceType)) {
html +=
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view group-device-link" '
+
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
+ '" data-devicename="' +
row.name + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
'<i class="fw fw-grouping fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">Group</span></a>';
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view group-device-link" '
+
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
+ '" data-devicename="' +
row.name + '"><span class="fw-stack"><i class="fw fw-ring fw-stack-2x"></i>' +
'<i class="fw fw-grouping fw-stack-1x"></i></span>' +
'<span class="hidden-xs hidden-on-grid-view">Group</span></a>';
}
html +=
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-device-link" '
+
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
+ '" data-devicename="' + row.name + '">' +
'<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>';
'<a href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view edit-device-link" '
+
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
+ '" data-devicename="' + row.name + '">' +
'<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-device-link" '
+
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
+ '" data-devicename="' + row.name + '">' +
'<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 href="#" data-click-event="remove-form" class="btn padding-reduce-on-grid-view remove-device-link" '
+
'data-deviceid="' + deviceIdentifier + '" data-devicetype="' + deviceType
+ '" data-devicename="' + row.name + '">' +
'<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>';
}
return html;
}
@ -427,16 +426,16 @@ function loadDevices(searchType, searchParam) {
$(data.devices).each(function (index) {
objects.push(
{
model: getPropertyValue(data.devices[index].properties, "DEVICE_MODEL"),
vendor: getPropertyValue(data.devices[index].properties, "VENDOR"),
user: data.devices[index].enrolmentInfo.owner,
status: data.devices[index].enrolmentInfo.status,
ownership: data.devices[index].enrolmentInfo.ownership,
deviceType: data.devices[index].type,
deviceIdentifier: data.devices[index].deviceIdentifier,
name: data.devices[index].name
}
{
model: getPropertyValue(data.devices[index].properties, "DEVICE_MODEL"),
vendor: getPropertyValue(data.devices[index].properties, "VENDOR"),
user: data.devices[index].enrolmentInfo.owner,
status: data.devices[index].enrolmentInfo.status,
ownership: data.devices[index].enrolmentInfo.ownership,
deviceType: data.devices[index].type,
deviceIdentifier: data.devices[index].deviceIdentifier,
name: data.devices[index].name
}
);
});
@ -449,20 +448,20 @@ function loadDevices(searchType, searchParam) {
};
$('#device-grid').datatables_extended_serverside_paging(
null,
serviceURL,
dataFilter,
columns,
fnCreatedRow,
function () {
$(".icon .text").res_text(0.2);
$('#device-grid').removeClass('hidden');
$("#loading-content").remove();
attachDeviceEvents();
}, {
"placeholder": "Search By Device Name",
"searchKey": "name"
}
null,
serviceURL,
dataFilter,
columns,
fnCreatedRow,
function () {
$(".icon .text").res_text(0.2);
$('#device-grid').removeClass('hidden');
$("#loading-content").remove();
attachDeviceEvents();
}, {
"placeholder": "Search By Device Name",
"searchKey": "name"
}
);
$(deviceCheckbox).click(function () {
@ -556,6 +555,34 @@ function hidePopup() {
$('.modal-backdrop').remove();
}
function markAlreadyAssignedGroups(deviceId, deviceType) {
var successCallback = function (data, textStatus, xhr) {
data = JSON.parse(data);
if (xhr.status == 200) {
if (data.length > 0) {
for (var i = 0; i < data.length; i++) {
$('.groupCheckBoxes').each(
function () {
if (data[i].id == $(this).data('groupid')) {
$(this).attr('checked', true);
}
}
);
}
} else {
return;
}
} else {
displayErrors(xhr);
}
};
invokerUtil.get("/api/device-mgt/v1.0/groups/device?deviceId=" + deviceId + "&deviceType=" + deviceType,
successCallback, function (message) {
displayErrors(message);
});
}
/**
* Following functions should be triggered after AJAX request is made.
*/
@ -572,33 +599,58 @@ function attachDeviceEvents() {
var deviceType = $(this).data("devicetype");
$(modalPopupContent).html($('#group-device-modal-content').html());
$('#user-groups').html(
'<div style="height:100px" data-state="loading" data-loading-text="Loading..." data-loading-style="icon-only" data-loading-inverse="true"></div>');
'<div style="height:100px" data-state="loading" data-loading-text="Loading..." data-loading-style="icon-only" data-loading-inverse="true"></div>');
$("a#group-device-yes-link").hide();
showPopup();
var serviceURL;
if ($.hasPermission("LIST_ALL_GROUPS")) {
serviceURL = "/api/device-mgt/v1.0/groups";
serviceURL = "/api/device-mgt/v1.0/admin/groups?limit=100";
} else if ($.hasPermission("LIST_GROUPS")) {
//Get authenticated users groups
serviceURL = "/api/device-mgt/v1.0/groups/user/" + currentUser + "/all";
serviceURL = "/api/device-mgt/v1.0/groups?limit=100";
}
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;">';
var html = '';
var hasGroups = false;
for (var i = 0; i < groups.deviceGroups.length; i++) {
str += '<option value="' + groups.deviceGroups[i].id + '">' +
groups.deviceGroups[i].name + '</option>';
if (groups.deviceGroups[i].owner != "wso2.system.user") {
html += '<div class="wr-input-control"><label class="wr-input-control checkbox">' +
'<input class="groupCheckBoxes" type="checkbox" data-groupid="' + groups.deviceGroups[i].id + '" />' +
'<span class="helper" title="' + groups.deviceGroups[i].name + '">' + groups.deviceGroups[i].name +
'</span></label></div>';
hasGroups = true;
}
}
if (hasGroups) {
html = '<br/><h4>Please select device group(s)</h4><br/>' + html;
markAlreadyAssignedGroups(deviceId, deviceType);
$("a#group-device-yes-link").show();
$("a#group-add-link").hide();
} else {
$("a#group-device-yes-link").hide();
$("a#group-add-link").show();
html += '<br/><h4>You don\'t have any existing device groups. Please add new device group first.</h4>'
}
str += '</select>';
$('#user-groups').html(str);
$("a#group-device-yes-link").show();
$('#user-groups').html(html);
$("a#group-device-yes-link").click(function () {
var selectedGroup = $('#assign-group-selector').val();
serviceURL = "/api/device-mgt/v1.0/groups/id/" + selectedGroup + "/devices/add";
var deviceIdentifiers = [{"id": deviceId, "type": deviceType}];
invokerUtil.post(serviceURL, deviceIdentifiers, function (data) {
var deviceIdentifier = {"id": deviceId, "type": deviceType};
var deviceGroupIds = [];
$('.modal .groupCheckBoxes').each(
function () {
if ($(this).is(':checked')) {
deviceGroupIds.push($(this).data('groupid'));
}
}
);
var deviceToGroupsAssignment = {
deviceIdentifier: deviceIdentifier,
deviceGroupIds: deviceGroupIds
};
serviceURL = "/api/device-mgt/v1.0/groups/device/assign";
invokerUtil.post(serviceURL, deviceToGroupsAssignment, function (data) {
$(modalPopupContent).html($('#group-associate-device-200-content').html());
setTimeout(function () {
hidePopup();
@ -640,8 +692,8 @@ function attachDeviceEvents() {
showPopup();
$("a#remove-device-yes-link").click(function () {
if(groupId && groupName) {
var deviceIdentifiers = [{"id": deviceId,"type": deviceType}];
if (groupId) {
var deviceIdentifiers = [{"id": deviceId, "type": deviceType}];
serviceURL = "/api/device-mgt/v1.0/groups/id/" + groupId + "/devices/remove";
invokerUtil.post(serviceURL, deviceIdentifiers, function (message) {
$(modalPopupContent).html($('#remove-device-from-group-200-content').html());
@ -733,6 +785,6 @@ function displayDeviceErrors(jqXHR) {
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

@ -37,7 +37,7 @@
</a>
</li>
<li>
<a href="{{@app.context}}/devices?groupOwner={{groupOwner}}&groupName={{groupName}}">
<a href="{{@app.context}}/devices?groupId={{groupId}}&groupName={{groupName}}">
{{groupName}}
</a>
</li>

@ -19,8 +19,8 @@
function onRequest(context) {
var utility = require("/app/modules/utility.js").utility;
var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"];
var groupName = context.uriParams.name;
var groupId = context.uriParams.id;
var group = groupModule.getGroup(groupId);
var devices = [];
var deviceResponse = groupModule.getGroupDevices(groupId).responseText;
@ -29,8 +29,9 @@ function onRequest(context) {
devices = deviceResponseObj.devices;
}
var page = {
"groupName": groupName,
"title": groupName + " Analytics"
"groupId": groupId,
"groupName": group.name,
"title": group.name + " Analytics"
};
if (devices) {
var deviceTypes = [];

@ -1,5 +1,5 @@
{
"version": "1.0.0",
"uri": "/group/{name}/{id}/analytics",
"uri": "/group/{id}/analytics",
"layout": "cdmf.layout.default"
}

@ -16,18 +16,41 @@
* under the License.
*/
/**
* Following function would execute
* when a user clicks on the list item
* initial mode and with out select mode.
*/
function InitiateViewOption(url) {
if ($(".select-enable-btn").text() == "Select") {
$(location).attr('href', url);
}
}
(function () {
var cache = {};
var validateAndReturn = function (value) {
return (value == undefined || value == null) ? "Unspecified" : value;
};
Handlebars.registerHelper("deviceMap", function (device) {
device.owner = validateAndReturn(device.owner);
device.ownership = validateAndReturn(device.ownership);
var arr = device.properties;
if (arr) {
device.properties = arr.reduce(function (total, current) {
total[current.name] = validateAndReturn(current.value);
return total;
}, {});
}
});
})();
/*
* Setting-up global variables.
*/
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.
*
@ -118,9 +141,9 @@ function loadGroups() {
});
var json = {
"recordsTotal": data.count,
"recordsFiltered": data.count,
"data": objects
}
};
return JSON.stringify(json);
};
@ -129,7 +152,14 @@ function loadGroups() {
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>';
if ($.hasPermission("VIEW_GROUP_DEVICES")) {
return '<a href="devices?groupId=' + row.groupId + '&groupName=' + row.name
+ '"><div class="thumbnail icon"><img class="square-element text fw " '
+ 'src="public/cdmf.page.groups/images/group-icon.png"/></div></a>';
} else {
return '<div class="thumbnail icon"><img class="square-element text fw " ' +
'src="public/cdmf.page.groups/images/group-icon.png"/></div>';
}
}
},
{
@ -154,13 +184,7 @@ function loadGroups() {
render: function (id, type, row, meta) {
var html = '';
if ($.hasPermission("VIEW_GROUP_DEVICES")) {
html = '<a href="devices?groupId=' + row.groupId + '&groupName=' + row.name
+ '" 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>';
html += '<a href="group/' + row.name + '/' + row.groupId
html += '<a href="group/' + row.groupId
+ '/analytics" 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-statistics fw-stack-1x"></i></span>'
+
@ -224,21 +248,23 @@ function loadGroups() {
});
};
$('#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"
});
null,
serviceURL,
dataFilter,
columns,
fnCreatedRow,
function (oSettings) {
$(".icon .text").res_text(0.2);
attachEvents();
var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable();
thisTable.removeClass("table-selectable");
},
{
"placeholder": "Search By Group Name",
"searchKey": "name"
}
);
$(groupCheckbox).click(function () {
addGroupSelectedClass(this);
});
@ -257,6 +283,11 @@ function openCollapsedNav() {
* DOM ready functions.
*/
$(document).ready(function () {
/* Adding selected class for selected devices */
$(groupCheckbox).each(function () {
addGroupSelectedClass(this);
});
var permissionSet = {};
//This method is used to setup permission for device listing
@ -278,11 +309,6 @@ $(document).ready(function () {
loadGroups();
//$('#device-grid').datatables_extended();
/* Adding selected class for selected devices */
$(groupCheckbox).each(function () {
addGroupSelectedClass(this);
});
/* for device list sorting drop down */
$(".ctrl-filter-type-switcher").popover(
{

@ -16,26 +16,44 @@
under the License.
}}
<div class="row wr-device-board">
<div class="col-lg-12 wr-secondary-bar">
<span class="page-sub-title">Device Types</span>
{{#if virtualDeviceTypesList}}
<div class="row wr-device-board">
<div class="col-lg-12 wr-secondary-bar">
<span class="page-sub-title">Device Types</span>
</div>
</div>
</div>
<span id="device-listing-status-msg"></span>
<div class="container-fluid">
<table class="table table-striped table-hover list-table no-operations display responsive nowrap data-table grid-view no-toolbar"
id="device-type-grid">
<thead>
<tr class="sort-row">
<th class="no-sort"></th>
<th>By Device Type</th>
<th class="no-sort"></th>
</tr>
</thead>
<tbody id="ast-container">
</tbody>
</table>
</div>
<div class="container-fluid">
<table class="table table-striped table-hover list-table no-operations display responsive nowrap data-table grid-view no-toolbar"
id="device-type-grid">
<thead>
<tr class="sort-row">
<th class="no-sort"></th>
<th>By Device Type</th>
<th class="no-sort"></th>
</tr>
</thead>
<tbody id="ast-container">
</tbody>
</table>
</div>
{{else}}
<div class="ast-container list-view">
<div class="ctrl-info-panel col-centered text-center wr-login">
<h3 class="text-muted">
<i class="fw fw-mobile fw-3x"></i>
</h3>
<h3 class="text-muted">No device type is available to be displayed.</h3>
<a href="https://docs.wso2.com/display/IoTS100/Quick+Start+Guide" target="_blank"
class="btn-operations btn-default">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-document fw-stack-1x"></i>
</span>
Quick Startup Guide
</a>
</div>
</div>
{{/if}}
<br class="c-both"/>
{{#if virtualDeviceTypesList}}

@ -29,6 +29,9 @@ function onRequest(context) {
if (typesListResponse["status"] == "success") {
var deviceTypes = typesListResponse.content.deviceTypes;
if (deviceTypes) {
if (deviceTypes.length > 0){
viewModel.hasDeviceTypes = true;
}
var deviceTypesList = [], virtualDeviceTypesList = [];
for (var i = 0; i < deviceTypes.length; i++) {
var deviceType = deviceTypes[i];

@ -142,13 +142,6 @@ function loadDevices(searchType, searchParam){
}
} else {
$('#device-type-grid').addClass('hidden');
$('#device-listing-status-msg').html(
'<div class="col-centered text-center"><h3 class="text-muted"><i class="fw fw-mobile fw-3x"></i>' +
'</h3><h3 class="text-muted">No device type is available to be displayed.</h3>' +
'<a href="https://docs.wso2.com/display/IoTS100/Quick+Start+Guide" target="_blank" ' +
'class="btn-operations btn-default"><span class="fw-stack">' +
'<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-document fw-stack-1x"></i></span>' +
'Quick Startup Guide</a></div>');
}
$(".icon .text").res_text(0.2);

Loading…
Cancel
Save