forked from community/device-mgt-core
commit
6667a41378
@ -1,113 +0,0 @@
|
||||
/*
|
||||
* 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.service.api;
|
||||
|
||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@API(name = "GroupManagement", version = "1.0.0", context = "/api/device-mgt/v1.0/groups", tags = {"device_management"})
|
||||
|
||||
@Path("/groups")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public interface GroupManagementService {
|
||||
|
||||
@GET
|
||||
@Permission(name = "View Group", permission = "/permission/admin/device-mgt/user/groups/list")
|
||||
Response getGroups(@QueryParam("user") String user, @QueryParam("offset") int offset,
|
||||
@QueryParam("limit") int limit);
|
||||
|
||||
@POST
|
||||
@Permission(name = "Add Group", permission = "/permission/admin/device-mgt/user/groups/add")
|
||||
Response createGroup(DeviceGroup group);
|
||||
|
||||
@Path("/{groupName}")
|
||||
@GET
|
||||
@Permission(name = "View Group", permission = "/permission/admin/device-mgt/user/groups/view")
|
||||
Response getGroup(@PathParam("groupName") String groupName);
|
||||
|
||||
@Path("/{groupName}")
|
||||
@PUT
|
||||
@Permission(name = "Update Group", permission = "/permission/admin/device-mgt/user/groups/update")
|
||||
Response updateGroup(@PathParam("groupName") String groupName, DeviceGroup deviceGroup);
|
||||
|
||||
@Path("/{groupName}")
|
||||
@DELETE
|
||||
@Permission(name = "Remove Groups", permission = "/permission/admin/device-mgt/user/groups/remove")
|
||||
Response deleteGroup(@PathParam("groupName") String groupName);
|
||||
|
||||
@Path("/{groupName}/share-with-user")
|
||||
@POST
|
||||
@Permission(name = "Share Group to a User", permission = "/permission/admin/device-mgt/user/groups/share")
|
||||
Response shareGroupWithUser(@PathParam("groupName") String groupName, String targetUser);
|
||||
|
||||
@Path("/{groupName}/share-with-role")
|
||||
@POST
|
||||
@Permission(name = "Share Group to a Role", permission = "/permission/admin/device-mgt/user/groups/share")
|
||||
Response shareGroupWithRole(@PathParam("groupName") String groupName, String targetRole);
|
||||
|
||||
@Path("/{groupName}/remove-share-with-user")
|
||||
@POST
|
||||
@Permission(name = "Unshare a Group", permission = "/permission/admin/device-mgt/user/groups/unshare")
|
||||
Response removeShareWithUser(@PathParam("groupName") String groupName, String targetUser);
|
||||
|
||||
@Path("/{groupName}/remove-share-with-role")
|
||||
@POST
|
||||
@Permission(name = "Unshare a Group", permission = "/permission/admin/device-mgt/user/groups/unshare")
|
||||
Response removeShareWithRole(@PathParam("groupName") String groupName, String targetUser);
|
||||
|
||||
@GET
|
||||
@Path("/{groupName}/users")
|
||||
@Permission(name = "Get Users of Group", permission = "/permission/admin/device-mgt/user/groups/list")
|
||||
Response getUsersOfGroup(@PathParam("groupName") String groupName);
|
||||
|
||||
@GET
|
||||
@Path("/{groupName}/devices")
|
||||
@Permission(name = "Get Devices of Group", permission = "/permission/admin/device-mgt/groups/roles")
|
||||
Response getDevicesOfGroup(@PathParam("groupName") String groupName, @QueryParam("offset") int offset,
|
||||
@QueryParam("limit") int limit);
|
||||
|
||||
@POST
|
||||
@Path("/{groupName}/devices")
|
||||
@Produces("application/json")
|
||||
@Permission(name = "Add Device to a Group", permission = "/permission/admin/device-mgt/user/groups/devices/add")
|
||||
Response addDeviceToGroup(@PathParam("groupName") String groupName, DeviceIdentifier deviceIdentifier);
|
||||
|
||||
@DELETE
|
||||
@Path("/{groupName}/devices")
|
||||
@Permission(name = "Remove Devices from Group",
|
||||
permission = "/permission/admin/device-mgt/user/groups/devices/remove")
|
||||
Response removeDeviceFromGroup(@PathParam("groupName") String groupName, @QueryParam("type") String type,
|
||||
@QueryParam("id") String id);
|
||||
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* 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.service.api.admin;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import io.swagger.annotations.ResponseHeader;
|
||||
import org.wso2.carbon.apimgt.annotations.api.API;
|
||||
import org.wso2.carbon.apimgt.annotations.api.Permission;
|
||||
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@API(name = "GroupManagementAdmin", version = "1.0.0", context = "/api/device-mgt/v1.0/admin/groups", tags = {"device_management"})
|
||||
|
||||
@Path("/admin/groups")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Api(value = "Group Management Administrative Service", description = "This an API intended to be used by " +
|
||||
"'internal' components to log in as an admin user and do a selected number of operations. " +
|
||||
"Further, this is strictly restricted to admin users only ")
|
||||
public interface GroupManagementAdminService {
|
||||
|
||||
@GET
|
||||
@ApiOperation(
|
||||
produces = MediaType.APPLICATION_JSON,
|
||||
httpMethod = "GET",
|
||||
value = "Grouping Devices",
|
||||
notes = "Many devices can be registered with WSO2 IoTS. In order to manage them in an efficient manner, " +
|
||||
"you can group devices and view the data gathered by the devices or share the groups with users so that they can monitor the devices in the respective group.",
|
||||
response = DeviceGroupWrapper.class,
|
||||
responseContainer = "List",
|
||||
tags = "Group Management Administrative Service")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of groups.",
|
||||
response = DeviceGroupWrapper.class,
|
||||
responseContainer = "List",
|
||||
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 was last modified.\n" +
|
||||
"Used by caches, or in conditional requests."),
|
||||
}),
|
||||
@ApiResponse(
|
||||
code = 304,
|
||||
message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."),
|
||||
@ApiResponse(
|
||||
code = 406,
|
||||
message = "Not Acceptable.\n The requested media type is not supported"),
|
||||
@ApiResponse(
|
||||
code = 500,
|
||||
message = "Internal Server ErrorResponse. \n Server error occurred while fetching the list of device groups.")
|
||||
})
|
||||
@Permission(name = "View All Groups", permission = "/permission/admin/device-mgt/user/groups/list")
|
||||
Response getGroupsOfUser(
|
||||
@ApiParam(
|
||||
name = "username",
|
||||
value = "The sername of the user.",
|
||||
required = true)
|
||||
@QueryParam("username") String username,
|
||||
@ApiParam(
|
||||
name = "If-Modified-Since",
|
||||
value = "Timestamp of the last modified date",
|
||||
required = false)
|
||||
@HeaderParam("If-Modified-Since") String timestamp,
|
||||
@ApiParam(
|
||||
name = "offset",
|
||||
value = "Starting point within the complete list of items qualified.",
|
||||
required = false,
|
||||
defaultValue = "0")
|
||||
@QueryParam("offset") int offset,
|
||||
@ApiParam(
|
||||
name = "limit",
|
||||
value = "Maximum size of resource array to return.",
|
||||
required = false,
|
||||
defaultValue = "5")
|
||||
@QueryParam("limit") int limit);
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
/*
|
||||
* 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.service.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.GroupManagementService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Path("/groups")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class GroupManagementServiceImpl implements GroupManagementService {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GroupManagementServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public Response getGroups(@QueryParam("user") String user, @QueryParam("offset") int offset,
|
||||
@QueryParam("limit") int limit) {
|
||||
try {
|
||||
List<DeviceGroupWrapper> groupWrappers = new ArrayList<>();
|
||||
GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService();
|
||||
List<DeviceGroup> deviceGroups = service.getGroups(user);
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
for (DeviceGroup dg : deviceGroups) {
|
||||
DeviceGroupWrapper gw = new DeviceGroupWrapper();
|
||||
gw.setId(dg.getId());
|
||||
gw.setOwner(dg.getOwner());
|
||||
gw.setName(dg.getName());
|
||||
gw.setTenantId(tenantId);
|
||||
groupWrappers.add(gw);
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity(groupWrappers).build();
|
||||
} catch (GroupManagementException e) {
|
||||
String error = "ErrorResponse occurred while getting the groups related to users for policy.";
|
||||
log.error(error, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response createGroup(DeviceGroup group) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getGroup(@PathParam("groupName") String groupName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response updateGroup(@PathParam("groupName") String groupName, DeviceGroup deviceGroup) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response deleteGroup(@PathParam("groupName") String groupName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response shareGroupWithUser(String groupName, String targetUser) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response shareGroupWithRole(String groupName, String targetRole) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response removeShareWithUser(@PathParam("groupName") String groupName,
|
||||
@QueryParam("username") String targetUser) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response removeShareWithRole(@PathParam("groupName") String groupName,
|
||||
@QueryParam("roleName") String targetUser) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getUsersOfGroup(@PathParam("groupName") String groupName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response getDevicesOfGroup(@PathParam("groupName") String groupName, @QueryParam("offset") int offset,
|
||||
@QueryParam("limit") int limit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response addDeviceToGroup(@PathParam("groupName") String groupName, DeviceIdentifier deviceIdentifier) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response removeDeviceFromGroup(@PathParam("groupName") String groupName, @QueryParam("type") String type,
|
||||
@QueryParam("id") String id) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* 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.service.impl.admin;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||
import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.admin.GroupManagementAdminService;
|
||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.HeaderParam;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Path("/admin/groups")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class GroupManagementAdminServiceImpl implements GroupManagementAdminService {
|
||||
|
||||
private static final Log log = LogFactory.getLog(GroupManagementAdminServiceImpl.class);
|
||||
|
||||
@GET
|
||||
@Override
|
||||
public Response getGroupsOfUser(
|
||||
@QueryParam("username") String username,
|
||||
@HeaderParam("If-Modified-Since") String timestamp,
|
||||
@QueryParam("offset") int offset,
|
||||
@QueryParam("limit") int limit) {
|
||||
try {
|
||||
PaginationResult result =
|
||||
DeviceMgtAPIUtils.getGroupManagementProviderService().getGroups(username, offset, limit);
|
||||
if (result != null && result.getRecordsTotal() > 0) {
|
||||
return Response.status(Response.Status.OK).entity(result).build();
|
||||
} else {
|
||||
return Response.status(Response.Status.NOT_FOUND).build();
|
||||
}
|
||||
} catch (GroupManagementException e) {
|
||||
String msg = "ErrorResponse occurred while retrieving the groups of user '" + username + "'";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,118 +1,210 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* Copyright (c) 2015, 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
|
||||
* 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
|
||||
* "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.
|
||||
*/
|
||||
|
||||
function onRequest(context) {
|
||||
var log = new Log("detail.js");
|
||||
var deviceType = context.uriParams.deviceType;
|
||||
var log = new Log("cdmf.unit.device.view/view.js");
|
||||
var deviceType = context["uriParams"]["deviceType"];
|
||||
var deviceId = request.getParameter("id");
|
||||
|
||||
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
|
||||
var deviceViewData = {};
|
||||
if (deviceType && deviceId) {
|
||||
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
||||
var device = deviceModule.viewDevice(deviceType, deviceId)["content"];
|
||||
var response = deviceModule.viewDevice(deviceType, deviceId);
|
||||
if (response["status"] == "success") {
|
||||
deviceViewData["deviceFound"] = true;
|
||||
deviceViewData["isAuthorized"] = true;
|
||||
|
||||
var filteredDeviceData = response["content"];
|
||||
|
||||
if (device) {
|
||||
// creating deviceView information model from filtered device data
|
||||
var viewModel = {};
|
||||
var deviceInfo = (device.properties) ? device.properties.DEVICE_INFO : null;
|
||||
if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0) {
|
||||
deviceInfo = parse(stringify(deviceInfo));
|
||||
if (device.type == "ios") {
|
||||
deviceInfo = parse(deviceInfo);
|
||||
viewModel.imei = device.properties.IMEI;
|
||||
viewModel.phoneNumber = deviceInfo.PhoneNumber;
|
||||
viewModel.udid = deviceInfo.UDID;
|
||||
viewModel.BatteryLevel = Math.round(deviceInfo.BatteryLevel * 100);
|
||||
viewModel.DeviceCapacity = Math.round(deviceInfo.DeviceCapacity * 100) / 100;
|
||||
viewModel.AvailableDeviceCapacity = Math.round(deviceInfo.AvailableDeviceCapacity * 100) / 100;
|
||||
viewModel.DeviceCapacityUsed = Math.round((viewModel.DeviceCapacity
|
||||
- viewModel.AvailableDeviceCapacity) * 100) / 100;
|
||||
viewModel.DeviceCapacityPercentage = Math.round(viewModel.AvailableDeviceCapacity
|
||||
/ viewModel.DeviceCapacity * 10000) / 100;
|
||||
viewModel.location = {
|
||||
latitude: device.properties.LATITUDE,
|
||||
longitude: device.properties.LONGITUDE
|
||||
};
|
||||
} else if (device.type == "android") {
|
||||
viewModel.imei = device.properties.IMEI;
|
||||
viewModel.model = device.properties.DEVICE_MODEL;
|
||||
viewModel.vendor = device.properties.VENDOR;
|
||||
viewModel.internal_memory = {};
|
||||
viewModel.external_memory = {};
|
||||
viewModel.location = {
|
||||
latitude: device.properties.LATITUDE,
|
||||
longitude: device.properties.LONGITUDE
|
||||
};
|
||||
var info = {};
|
||||
var infoList = parse(deviceInfo);
|
||||
if (infoList != null && infoList != undefined) {
|
||||
for (var j = 0; j < infoList.length; j++) {
|
||||
info[infoList[j].name] = infoList[j].value;
|
||||
if (filteredDeviceData["type"]) {
|
||||
viewModel["deviceType"] = filteredDeviceData["type"];
|
||||
viewModel.isNotWindows = true;
|
||||
if (viewModel["deviceType"] == "windows") {
|
||||
viewModel.isNotWindows = false;
|
||||
}
|
||||
}
|
||||
if (filteredDeviceData["deviceIdentifier"]) {
|
||||
viewModel["deviceIdentifier"] = filteredDeviceData["deviceIdentifier"];
|
||||
}
|
||||
if (filteredDeviceData["name"]) {
|
||||
viewModel["name"] = filteredDeviceData["name"];
|
||||
}
|
||||
if (filteredDeviceData["enrolmentInfo"]) {
|
||||
if (filteredDeviceData["enrolmentInfo"]["status"]) {
|
||||
viewModel["status"] = filteredDeviceData["enrolmentInfo"]["status"];
|
||||
viewModel.isActive = false ;
|
||||
viewModel.isNotRemoved = true;
|
||||
if (filteredDeviceData["enrolmentInfo"]["status"]== "ACTIVE") {
|
||||
viewModel.isActive = true ;
|
||||
}
|
||||
if (filteredDeviceData["enrolmentInfo"]["status"]== "REMOVED") {
|
||||
viewModel.isNotRemoved = false ;
|
||||
}
|
||||
}
|
||||
if (filteredDeviceData["enrolmentInfo"]["owner"]) {
|
||||
viewModel["owner"] = filteredDeviceData["enrolmentInfo"]["owner"];
|
||||
}
|
||||
if (filteredDeviceData["enrolmentInfo"]["ownership"]) {
|
||||
viewModel["ownership"] = filteredDeviceData["enrolmentInfo"]["ownership"];
|
||||
}
|
||||
}
|
||||
if (filteredDeviceData["initialDeviceInfo"]) {
|
||||
viewModel["deviceInfoAvailable"] = true;
|
||||
if (filteredDeviceData["initialDeviceInfo"]["IMEI"]) {
|
||||
viewModel["imei"] = filteredDeviceData["initialDeviceInfo"]["IMEI"];
|
||||
}
|
||||
if (!filteredDeviceData["latestDeviceInfo"]) {
|
||||
if (filteredDeviceData["initialDeviceInfo"]["OS_BUILD_DATE"]) {
|
||||
if (filteredDeviceData["initialDeviceInfo"]["OS_BUILD_DATE"] != "0") {
|
||||
viewModel["osBuildDate"] = new Date(filteredDeviceData["initialDeviceInfo"]["OS_BUILD_DATE"] * 1000);
|
||||
}
|
||||
}
|
||||
if (filteredDeviceData["initialDeviceInfo"]["LATITUDE"] && filteredDeviceData["initialDeviceInfo"]["LONGITUDE"]) {
|
||||
viewModel["location"] = {};
|
||||
viewModel["location"]["latitude"] = filteredDeviceData["initialDeviceInfo"]["LATITUDE"];
|
||||
viewModel["location"]["longitude"] = filteredDeviceData["initialDeviceInfo"]["LONGITUDE"];
|
||||
}
|
||||
if (filteredDeviceData["initialDeviceInfo"]["VENDOR"] && filteredDeviceData["initialDeviceInfo"]["DEVICE_MODEL"]) {
|
||||
viewModel["vendor"] = filteredDeviceData["initialDeviceInfo"]["VENDOR"];
|
||||
viewModel["model"] = filteredDeviceData["initialDeviceInfo"]["DEVICE_MODEL"];
|
||||
}
|
||||
if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]) {
|
||||
if (deviceType == "android") {
|
||||
viewModel["BatteryLevel"] = {};
|
||||
viewModel["BatteryLevel"]["value"] = filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["BATTERY_LEVEL"];
|
||||
|
||||
viewModel["internalMemory"] = {};
|
||||
viewModel["internalMemory"]["total"] = Math.
|
||||
round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] * 100) / 100;
|
||||
if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] != 0) {
|
||||
viewModel["internalMemory"]["usage"] = Math.
|
||||
round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] -
|
||||
filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_AVAILABLE_MEMORY"])
|
||||
/ filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["INTERNAL_TOTAL_MEMORY"] * 10000) / 100;
|
||||
} else {
|
||||
viewModel["internalMemory"]["usage"] = 0;
|
||||
}
|
||||
|
||||
viewModel["externalMemory"] = {};
|
||||
viewModel["externalMemory"]["total"] = Math.
|
||||
round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] * 100) / 100;
|
||||
if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] != 0) {
|
||||
viewModel["externalMemory"]["usage"] = Math.
|
||||
round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] -
|
||||
filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_AVAILABLE_MEMORY"])
|
||||
/ filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["EXTERNAL_TOTAL_MEMORY"] * 10000) / 100;
|
||||
} else {
|
||||
viewModel["externalMemory"]["usage"] = 0;
|
||||
}
|
||||
} else if (deviceType == "ios") {
|
||||
viewModel["BatteryLevel"] = {};
|
||||
viewModel["BatteryLevel"]["value"] = filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["BatteryLevel"];
|
||||
|
||||
viewModel["internalMemory"] = {};
|
||||
viewModel["internalMemory"]["total"] = Math.
|
||||
round(filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] * 100) / 100;
|
||||
if (filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] != 0) {
|
||||
viewModel["internalMemory"]["usage"] = Math.
|
||||
round((filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] -
|
||||
filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["AvailableDeviceCapacity"])
|
||||
/ filteredDeviceData["initialDeviceInfo"]["DEVICE_INFO"]["DeviceCapacity"] * 10000) / 100;
|
||||
} else {
|
||||
viewModel["internalMemory"]["usage"] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
deviceInfo = info;
|
||||
viewModel.BatteryLevel = deviceInfo.BATTERY_LEVEL;
|
||||
viewModel.internal_memory.FreeCapacity = Math.round(deviceInfo.INTERNAL_AVAILABLE_MEMORY * 100)/100;
|
||||
viewModel.internal_memory.DeviceCapacityPercentage = Math.round(deviceInfo.INTERNAL_AVAILABLE_MEMORY
|
||||
/ deviceInfo.INTERNAL_TOTAL_MEMORY * 10000) / 100;
|
||||
viewModel.external_memory.FreeCapacity = Math.round(deviceInfo.EXTERNAL_AVAILABLE_MEMORY * 100) / 100;
|
||||
viewModel.external_memory.DeviceCapacityPercentage = Math.round(deviceInfo.EXTERNAL_AVAILABLE_MEMORY
|
||||
/ deviceInfo.EXTERNAL_TOTAL_MEMORY * 10000) / 100;
|
||||
} else if (device.type == "windows") {
|
||||
viewModel.imei = device.properties.IMEI;
|
||||
viewModel.model = device.properties.DEVICE_MODEL;
|
||||
viewModel.vendor = device.properties.VENDOR;
|
||||
viewModel.internal_memory = {};
|
||||
viewModel.external_memory = {};
|
||||
viewModel.location = {
|
||||
latitude: device.properties.LATITUDE,
|
||||
longitude: device.properties.LONGITUDE
|
||||
};
|
||||
/*var info = {};
|
||||
if (deviceInfo != null && deviceInfo != undefined){
|
||||
var infoList = parse(deviceInfo);
|
||||
if (infoList != null && infoList != undefined) {
|
||||
for (var j = 0; j < infoList.length; j++) {
|
||||
info[infoList[j].name] = infoList[j].value;
|
||||
}
|
||||
}
|
||||
deviceInfo = info;
|
||||
viewModel.BatteryLevel = deviceInfo.BATTERY_LEVEL;
|
||||
viewModel.internal_memory.FreeCapacity = Math.round((deviceInfo.INTERNAL_TOTAL_MEMORY -
|
||||
deviceInfo.INTERNAL_AVAILABLE_MEMORY) * 100) / 100;
|
||||
viewModel.internal_memory.DeviceCapacityPercentage = Math.round(deviceInfo.INTERNAL_AVAILABLE_MEMORY
|
||||
/ deviceInfo.INTERNAL_TOTAL_MEMORY * 10000) / 100;
|
||||
viewModel.external_memory.FreeCapacity = Math.round((deviceInfo.EXTERNAL_TOTAL_MEMORY -
|
||||
deviceInfo.EXTERNAL_AVAILABLE_MEMORY) * 100) / 100;
|
||||
viewModel.external_memory.DeviceCapacityPercentage = Math.round(deviceInfo.EXTERNAL_AVAILABLE_MEMORY
|
||||
/ deviceInfo.EXTERNAL_TOTAL_MEMORY * 10000) / 100;
|
||||
}*/
|
||||
}else if (device.type == "TemperatureController") {
|
||||
viewModel.system = device.properties.IMEI;
|
||||
viewModel.machine = device.properties.DEVICE_MODEL;
|
||||
viewModel.vendor = device.properties.VENDOR;
|
||||
viewModel.internal_memory = {};
|
||||
viewModel.external_memory = {};
|
||||
}
|
||||
device.viewModel = viewModel;
|
||||
}
|
||||
}
|
||||
if (filteredDeviceData["latestDeviceInfo"]) {
|
||||
viewModel["deviceInfoAvailable"] = true;
|
||||
if (filteredDeviceData["latestDeviceInfo"]["osBuildDate"]) {
|
||||
if (filteredDeviceData["latestDeviceInfo"]["osBuildDate"] != "0") {
|
||||
viewModel["osBuildDate"] = new Date(filteredDeviceData["latestDeviceInfo"]["osBuildDate"] * 1000);
|
||||
}
|
||||
}
|
||||
if (filteredDeviceData["latestDeviceInfo"]["location"]["latitude"] &&
|
||||
filteredDeviceData["latestDeviceInfo"]["location"]["longitude"]) {
|
||||
viewModel["location"] = {};
|
||||
viewModel["location"]["latitude"] = filteredDeviceData["latestDeviceInfo"]["location"]["latitude"];
|
||||
viewModel["location"]["longitude"] = filteredDeviceData["latestDeviceInfo"]["location"]["longitude"];
|
||||
}
|
||||
if (filteredDeviceData["latestDeviceInfo"]["vendor"] && filteredDeviceData["latestDeviceInfo"]["deviceModel"]) {
|
||||
viewModel["vendor"] = filteredDeviceData["latestDeviceInfo"]["vendor"];
|
||||
viewModel["model"] = filteredDeviceData["latestDeviceInfo"]["deviceModel"];
|
||||
}
|
||||
if (filteredDeviceData["latestDeviceInfo"]["updatedTime"]) {
|
||||
viewModel["lastUpdatedTime"] = filteredDeviceData["latestDeviceInfo"]["updatedTime"].
|
||||
substr(0, filteredDeviceData["latestDeviceInfo"]["updatedTime"].indexOf("+"));
|
||||
}
|
||||
viewModel["BatteryLevel"] = {};
|
||||
viewModel["BatteryLevel"]["value"] = filteredDeviceData["latestDeviceInfo"]["batteryLevel"];
|
||||
|
||||
viewModel["cpuUsage"] = {};
|
||||
viewModel["cpuUsage"]["value"] = filteredDeviceData["latestDeviceInfo"]["cpuUsage"];
|
||||
|
||||
var utility = require("/app/modules/utility.js").utility;
|
||||
var configs = utility.getDeviceTypeConfig(deviceType);
|
||||
return {"device": device, "label" : configs["deviceType"]["label"]};
|
||||
viewModel["ramUsage"] = {};
|
||||
if (filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] != 0) {
|
||||
viewModel["ramUsage"]["value"] = Math.
|
||||
round((filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] -
|
||||
filteredDeviceData["latestDeviceInfo"]["availableRAMMemory"])
|
||||
/ filteredDeviceData["latestDeviceInfo"]["totalRAMMemory"] * 10000) / 100;
|
||||
} else {
|
||||
viewModel["ramUsage"]["value"] = 0;
|
||||
}
|
||||
|
||||
viewModel["internalMemory"] = {};
|
||||
viewModel["internalMemory"]["total"] = Math.
|
||||
round(filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] * 100) / 100;
|
||||
if (filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] != 0) {
|
||||
viewModel["internalMemory"]["usage"] = Math.
|
||||
round((filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] -
|
||||
filteredDeviceData["latestDeviceInfo"]["internalAvailableMemory"])
|
||||
/ filteredDeviceData["latestDeviceInfo"]["internalTotalMemory"] * 10000) / 100;
|
||||
} else {
|
||||
viewModel["internalMemory"]["usage"] = 0;
|
||||
}
|
||||
|
||||
viewModel["externalMemory"] = {};
|
||||
viewModel["externalMemory"]["total"] = Math.
|
||||
round(filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] * 100) / 100;
|
||||
if (filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] != 0) {
|
||||
viewModel["externalMemory"]["usage"] = Math.
|
||||
round((filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] -
|
||||
filteredDeviceData["latestDeviceInfo"]["externalAvailableMemory"])
|
||||
/ filteredDeviceData["latestDeviceInfo"]["externalTotalMemory"] * 10000) / 100;
|
||||
} else {
|
||||
viewModel["externalMemory"]["usage"] = 0;
|
||||
}
|
||||
}
|
||||
if (!filteredDeviceData["initialDeviceInfo"] && !filteredDeviceData["latestDeviceInfo"]) {
|
||||
viewModel["deviceInfoAvailable"] = false;
|
||||
}
|
||||
|
||||
deviceViewData["deviceView"] = viewModel;
|
||||
} else if (response["status"] == "unauthorized") {
|
||||
deviceViewData["deviceFound"] = true;
|
||||
deviceViewData["isAuthorized"] = false;
|
||||
} else if (response["status"] == "notFound") {
|
||||
deviceViewData["deviceFound"] = false;
|
||||
}
|
||||
} else {
|
||||
deviceViewData["deviceFound"] = false;
|
||||
}
|
||||
return deviceViewData;
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
{{!
|
||||
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.
|
||||
}}
|
||||
|
||||
{{#zone "content"}}
|
||||
|
||||
<div id="basic-modal-view" class="hidden modal modal-content">
|
||||
<div class="modal-header">
|
||||
<h3 class="pull-left modal-title">
|
||||
<span class="fw-stack error-msg-icon hidden">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-error fw-stack-1x"></i>
|
||||
</span>
|
||||
<span class="fw-stack warning-msg-icon hidden">
|
||||
<i class="fw fw-ring fw-stack-2x"></i>
|
||||
<i class="fw fw-warning fw-stack-1x"></i>
|
||||
</span>
|
||||
<span id="modal-title-text"></span>
|
||||
</h3>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="fw fw-cancel"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body add-margin-top-2x add-margin-bottom-2x">
|
||||
<h4 id="modal-content-text">
|
||||
|
||||
</h4>
|
||||
</div>
|
||||
<div id="modal-footer-content" class="modal-footer">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{{/zone}}
|
||||
|
||||
{{#zone "topJs"}}
|
||||
{{js "js/modal.js"}}
|
||||
{{/zone}}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"version": "1.0.0",
|
||||
"isAnonymous": true,
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
var modalDialog = (function () {
|
||||
var publicMethoads = {};
|
||||
publicMethoads.header = function (headerText) {
|
||||
$("#modal-title-text").html(headerText);
|
||||
|
||||
};
|
||||
publicMethoads.content = function (contentText) {
|
||||
$("#modal-content-text").html(contentText);
|
||||
|
||||
};
|
||||
publicMethoads.footer = function (footerContent) {
|
||||
$("#modal-footer-content").html(footerContent);
|
||||
|
||||
};
|
||||
publicMethoads.footerButtons = function (buttonList) {
|
||||
var footerContent = "";
|
||||
for (var btn in buttonList) {
|
||||
footerContent = footerContent + '<div class="buttons"><a href="#" id="' + btn.id +
|
||||
'" class="btn-operations">' + btn.text + '</a></div>';
|
||||
}
|
||||
$("#modal-footer-content").html(footerContent);
|
||||
};
|
||||
publicMethoads.show = function () {
|
||||
|
||||
$(".error-msg-icon").addClass("hidden");
|
||||
$(".warning-msg-icon").addClass("hidden");
|
||||
$("#basic-modal-view").removeClass('hidden');
|
||||
$("#basic-modal-view").modal('show');
|
||||
|
||||
};
|
||||
publicMethoads.showAsError = function () {
|
||||
$(".error-msg-icon").removeClass("hidden");
|
||||
$("#basic-modal-view").removeClass('hidden');
|
||||
$("#basic-modal-view").modal('show');
|
||||
|
||||
};
|
||||
publicMethoads.showAsAWarning = function () {
|
||||
$(".warning-msg-icon").removeClass("hidden");
|
||||
$("#basic-modal-view").removeClass('hidden');
|
||||
$("#basic-modal-view").modal('show');
|
||||
|
||||
};
|
||||
publicMethoads.hide = function () {
|
||||
$("#basic-modal-view").addClass('hidden');
|
||||
$("#basic-modal-view").modal('hide');
|
||||
$("#modal-title-text").html("");
|
||||
$("#modal-content-text").html("");
|
||||
$("#modal-footer-content").html("");
|
||||
$('body').removeClass('modal-open').css('padding-right', '0px');
|
||||
$('.modal-backdrop').remove();
|
||||
};
|
||||
return publicMethoads;
|
||||
}(modalDialog));
|
Loading…
Reference in new issue