Fix the device view related issues

revert-dabc3590
kamidu 8 years ago
parent fe2b861932
commit 04d1a3912a

@ -0,0 +1,44 @@
{{!
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.
}}
{{unit "cdmf.unit.ui.title" pageTitle="Device Details"}}
{{unit "cdmf.unit.lib.service-invoker-utility"}}
{{unit "cdmf.unit.lib.handlebars"}}
{{#zone "breadcrumbs"}}
<li>
<a href="{{@app.context}}/">
<i class="icon fw fw-home"></i>
</a>
</li>
<li>
<a href="{{@app.context}}/devices">
Devices
</a>
</li>
<li>
<a href="#">
Device Details
</a>
</li>
{{/zone}}
{{#zone "content"}}
{{unit "cdmf.unit.lib.data-table"}}
{{unit "cdmf.unit.device.operation-mod"}}
{{unit "cdmf.unit.device.view"}}
{{/zone}}

@ -0,0 +1,33 @@
/*
* 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.
*/
function onRequest(context){
var utility = require("/app/modules/utility.js").utility;
context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) {
if (arguments.length < 3)
throw new Error("Handlebars Helper equal needs 2 parameters");
if( lvalue!=rvalue ) {
return options.inverse(this);
} else {
return options.fn(this);
}
});
var deviceType = context.uriParams.deviceType;
return {"deviceViewUnitName": utility.getTenantedDeviceUnitName(deviceType, "device-view")};
}

@ -204,7 +204,7 @@ function loadDevices(searchType, searchParam){
var deviceIdentifier = row.deviceIdentifier;
var url = "#";
if (status != 'REMOVED') {
url = "devices/view?type=" + deviceType + "&id=" + deviceIdentifier;
url = "device/" + deviceType + "?id=" + deviceIdentifier;
}
return '<div onclick="javascript:InitiateViewOption(\'' + url + '\')" class="thumbnail icon"><i class="square-element text fw fw-mobile"></i></div>'
}

@ -0,0 +1,318 @@
/*
* 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
*
* 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 InitiateViewOption = null;
(function () {
var deviceId = $(".device-id");
var deviceIdentifier = deviceId.data("deviceid");
var deviceType = deviceId.data("type");
var payload = [deviceIdentifier];
var operationTable;
var serviceUrl;
if (deviceType == "ios") {
serviceUrl = "/ios/operation/deviceinfo";
} else if (deviceType == "android") {
//var serviceUrl = "/mdm-android-agent/operation/device-info";
serviceUrl = "/api/device-mgt/android/v1.0/admin/devices/info";
}
if (serviceUrl) {
invokerUtil.post(
serviceUrl,
payload,
// success-callback
function () {
$(".panel-body").show();
},
// error-callback
function () {
var defaultInnerHTML =
"<br><p class='fw-warning'>Device data may not have been updated. Please refresh to try again.<p>";
$(".panel-body").append(defaultInnerHTML);
}
);
}
$(".media.tab-responsive [data-toggle=tab]").on("shown.bs.tab", function (e) {
var activeTabPane = $(e.target).attr("href"),
activeCollapsePane = $(activeTabPane).find("[data-toggle=collapse]").data("target"),
activeCollapsePaneSiblings = $(activeTabPane).siblings().find("[data-toggle=collapse]").data("target"),
activeListGroupItem = $(".media .list-group-item.active");
$(activeCollapsePaneSiblings).collapse("hide");
$(activeCollapsePane).collapse("show");
positionArrow(activeListGroupItem);
$(".panel-heading .caret-updown").removeClass("fw-sort-down");
$(".panel-heading.collapsed .caret-updown").addClass("fw-sort-up");
});
$(".media.tab-responsive .tab-content").on("shown.bs.collapse", function (e) {
var activeTabPane = $(e.target).parent().attr("id");
$(".media.tab-responsive [data-toggle=tab][href=#" + activeTabPane + "]").tab("show");
$(".panel-heading .caret-updown").removeClass("fw-sort-up");
$(".panel-heading.collapsed .caret-updown").addClass("fw-sort-down");
});
function positionArrow(selectedTab) {
var selectedTabHeight = $(selectedTab).outerHeight();
var arrowPosition = 0;
var totalHeight = 0;
var arrow = $(".media .panel-group.tab-content .arrow-left");
var parentHeight = $(arrow).parent().outerHeight();
// if($(selectedTab).prev().length){
// $(selectedTab).prevAll().each(function() {
// totalHeight += $(this).outerHeight();
// });
// arrowPosition = totalHeight + (selectedTabHeight / 2);
// }else{
// arrowPosition = selectedTabHeight / 2;
// }
if(arrowPosition >= parentHeight){
parentHeight = arrowPosition + 10;
$(arrow).parent().height(parentHeight);
}else{
$(arrow).parent().removeAttr("style");
}
$(arrow).css("top", arrowPosition - 10);
}
$(document).ready(function() {
$(".device-detail-body").removeClass("hidden");
$("#loading-content").remove();
loadOperationBar(deviceType);
loadOperationsLog(false);
loadApplicationsList();
loadPolicyCompliance();
$("#refresh-policy").click(function () {
$("#policy-spinner").removeClass("hidden");
loadPolicyCompliance();
});
$("#refresh-apps").click(function () {
$("#apps-spinner").removeClass("hidden");
loadApplicationsList();
});
$("#refresh-operations").click(function () {
$("#operations-spinner").removeClass("hidden");
loadOperationsLog(true);
});
});
function loadOperationsLog(update) {
var operationsLogTable = "#operations-log-table";
if (update) {
operationTable = $(operationsLogTable).DataTable();
operationTable.ajax.reload(false);
return;
}
operationTable = $(operationsLogTable).datatables_extended({
serverSide: true,
processing: false,
searching: false,
ordering: false,
pageLength : 10,
order: [],
ajax: {
url: "/emm/api/operation/paginate",
data: {deviceId : deviceIdentifier, deviceType: deviceType},
dataSrc: function (json) {
$("#operations-spinner").addClass("hidden");
$("#operations-log-container").empty();
return json.data;
}
},
columnDefs: [
{targets: 0, data: "code" },
{targets: 1, data: "status", render:
function (status) {
var html;
switch (status) {
case "COMPLETED" :
html = "<span><i class='fw fw-ok icon-success'></i> Completed</span>";
break;
case "PENDING" :
html = "<span><i class='fw fw-warning icon-warning'></i> Pending</span>";
break;
case "ERROR" :
html = "<span><i class='fw fw-error icon-danger'></i> Error</span>";
break;
case "IN_PROGRESS" :
html = "<span><i class='fw fw-ok icon-warning'></i> In Progress</span>";
break;
case "REPEATED" :
html = "<span><i class='fw fw-ok icon-warning'></i> Repeated</span>";
break;
}
return html;
}
},
{targets: 2, data: "createdTimeStamp", render:
function (date) {
var value = String(date);
return value.slice(0, 16);
}
}
],
"createdRow": function(row, data) {
$(row).attr("data-type", "selectable");
$(row).attr("data-id", data["id"]);
$.each($("td", row),
function(colIndex) {
switch(colIndex) {
case 1:
$(this).attr("data-grid-label", "Code");
$(this).attr("data-display", data["code"]);
break;
case 2:
$(this).attr("data-grid-label", "Status");
$(this).attr("data-display", data["status"]);
break;
case 3:
$(this).attr("data-grid-label", "Created Timestamp");
$(this).attr("data-display", data["createdTimeStamp"]);
break;
}
}
);
}
});
}
function loadApplicationsList() {
var applicationsList = $("#applications-list");
var applicationListingTemplate = applicationsList.attr("src");
var deviceId = applicationsList.data("device-id");
var deviceType = applicationsList.data("device-type");
$.template("application-list", applicationListingTemplate, function (template) {
var serviceURL = "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/applications";
invokerUtil.get(
serviceURL,
// success-callback
function (data, textStatus, jqXHR) {
if (jqXHR.status == 200 && data) {
data = JSON.parse(data);
$("#apps-spinner").addClass("hidden");
if (data.length > 0) {
for (var i = 0; i < data.length; i++) {
data[i]["name"] = decodeURIComponent(data[i]["name"]);
data[i]["platform"] = deviceType;
}
var viewModel = {};
viewModel["applications"] = data;
viewModel["deviceType"] = deviceType;
var content = template(viewModel);
$("#applications-list-container").html(content);
} else {
$("#applications-list-container").
html("<div class='panel-body'><br><p class='fw-warning'>&nbsp;No applications found. " +
"please try refreshing the list in a while.<p></div>");
}
}
},
// error-callback
function () {
$("#applications-list-container").
html("<div class='panel-body'><br><p class='fw-warning'>&nbsp;Loading application list " +
"was not successful. please try refreshing the list in a while.<p></div>");
});
});
}
function loadPolicyCompliance() {
var policyCompliance = $("#policy-view");
var policyComplianceTemplate = policyCompliance.attr("src");
var deviceId = policyCompliance.data("device-id");
var deviceType = policyCompliance.data("device-type");
var activePolicy = null;
$.template(
"policy-view",
policyComplianceTemplate,
function (template) {
var getEffectivePolicyURL = "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/effective-policy";
var getDeviceComplianceURL = "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/compliance-data";
invokerUtil.get(
getEffectivePolicyURL,
// success-callback
function (data, textStatus, jqXHR) {
if (jqXHR.status == 200 && data) {
data = JSON.parse(data);
$("#policy-spinner").addClass("hidden");
if (data["active"] == true) {
activePolicy = data;
invokerUtil.get(
getDeviceComplianceURL,
// success-callback
function (data, textStatus, jqXHR) {
if (jqXHR.status == 200 && data) {
var viewModel = {};
viewModel["policy"] = activePolicy;
viewModel["deviceType"] = deviceType;
data = JSON.parse(data);
var content;
if (data["complianceData"]) {
if (data["complianceData"]["complianceFeatures"] &&
data["complianceData"]["complianceFeatures"].length > 0) {
viewModel["compliance"] = "NON-COMPLIANT";
viewModel["complianceFeatures"] = data["complianceData"]["complianceFeatures"];
content = template(viewModel);
$("#policy-list-container").html(content);
} else {
viewModel["compliance"] = "COMPLIANT";
content = template(viewModel);
$("#policy-list-container").html(content);
$("#policy-compliance-table").addClass("hidden");
}
} else {
$("#policy-list-container").
html("<div class='panel-body'><br><p class='fw-warning'> This device " +
"has no policy applied.<p></div>");
}
}
},
// error-callback
function () {
$("#policy-list-container").
html("<div class='panel-body'><br><p class='fw-warning'> Loading policy compliance related data " +
"was not successful. please try refreshing data in a while.<p></div>");
}
);
}
}
},
// error-callback
function () {
$("#policy-list-container").
html("<div class='panel-body'><br><p class='fw-warning'> Loading policy compliance related data " +
"was not successful. please try refreshing data in a while.<p></div>");
}
);
}
);
}
}());

@ -0,0 +1,54 @@
/*
* 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
*
* 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 map;
function loadLeafletMap() {
var deviceLocationID = "#device-location",
lat = $(deviceLocationID).data("lat"),
long = $(deviceLocationID).data("long"),
container = "device-location",
zoomLevel = 13,
tileSet = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
attribution = "&copy; <a href='https://openstreetmap.org/copyright'>OpenStreetMap</a> contributors";
if (lat && long) {
map = L.map(container).setView([lat, long], zoomLevel);
L.tileLayer(tileSet, {attribution: attribution}).addTo(map);
L.marker([lat, long]).addTo(map).bindPopup("Device is here...").openPopup();
$("#map-error").hide();
$("#device-location").show();
} else {
$("#device-location").hide();
$("#map-error").show();
}
}
$(document).ready(function () {
$("a[data-toggle='tab']").on("shown.bs.tab", function() {
var url = $(this).prop("href");
var hash = url.substring(url.indexOf("#") + 1);
if (hash == "device_location") {
if (!map) {
loadLeafletMap();
}
}
});
});

@ -0,0 +1,31 @@
<div class="wr-app-listing">
<div class="wr-applist">
{{#each applications}}
<a style="text-align: center; width: 110px; height: 140px;">
{{#equal platform "android"}}<i class="icon fw fw-android"></i>{{/equal}}
{{#equal platform "ios"}}<i class="icon fw fw-apple"></i>{{/equal}}
{{#equal platform "windows"}}<i class="icon fw fw-windows"></i>{{/equal}}
{{#equal isActive true}}
<span style="word-wrap: break-word;">
<i class="fw fw-ok icon-success" style="font-size: 14px;"></i>
&nbsp;Active
</span>
<span style="word-wrap: break-word;"><b>{{name}}</b></span>
<span style="word-wrap: break-word;"><b>V:{{version}}</b></span>
{{#if memoryUsage}}
<span style="word-wrap: break-word;">
Memory Usage
</span>
<span style="word-wrap: break-word;">
( {{memoryUsage}} Bytes )
</span>
{{/if}}
{{/equal}}
{{#equal isActive false}}
<span style="word-wrap: break-word;">{{name}}</span>
<span style="word-wrap: break-word;"><b>V:{{version}}</b></span>
{{/equal}}
</a>
{{/each}}
</div>
</div>

@ -0,0 +1,24 @@
<table class="table table-striped table-hover table-bordered display data-table" id="operations-log-table">
<thead>
<tr class="sort-row">
<th>Operation Code</th>
<th>Status</th>
<th>Request created at</th>
</tr>
</thead>
<tbody>
{{#each operations}}
<tr data-type="selectable" data-id="{{id}}">
<td data-display="{{code}}" data-grid-label="Code">{{code}}</td>
<td data-display="{{status}}" data-grid-label="Status">
{{#equal status "COMPLETED"}}<span><i class="fw fw-ok icon-success"></i> Completed</span>{{/equal}}
{{#equal status "PENDING"}}<span><i class="fw fw-warning icon-warning"></i> Pending</span>{{/equal}}
{{#equal status "ERROR"}}<span><i class="fw fw-error icon-danger"></i> Error</span>{{/equal}}
{{#equal status "IN_PROGRESS"}}<span><i class="fw fw-ok icon-warning"></i> In Progress</span>{{/equal}}
</td>
<td data-display="{{createdTimeStamp}}" data-grid-label="Created Timestamp">{{createdTimeStamp}}</td>
</tr>
{{/each}}
<br class="c-both" />
</tbody>
</table>

@ -0,0 +1,79 @@
<div class="wr-list-group wr-sortable policy-list">
<span class="list-group-item" id="{{id}}">
<div class="row">
<div class="col-lg-3 clearfix">
<span class="wr-list-icon">
{{#equal deviceType "android"}}
<i class=" fw fw-android"></i>
{{/equal}}
{{#equal deviceType "ios"}}
<i class=" fw fw-apple"></i>
{{/equal}}
{{#equal deviceType "windows"}}
<i class=" fw fw-windows"></i>
{{/equal}}
</span>
<span class="wr-list-desc">
<h3 class="wr-list-name">{{policy.policyName}}</h3>
<span class="wr-list-username">{{deviceType}}</span>
</span>
</div>
<div class="col-lg-6">
<div class="row no-gutter">
<div class="wr-desc-list-configs col-lg-4">
<div>
<b>Ownership Type : </b> {{policy.ownershipType}}
</div>
</div>
<div class="wr-desc-list-configs col-lg-4">
<div>
<b>Compliance Type :</b> {{policy.compliance}}
</div>
</div>
<div class="wr-desc-list-configs col-lg-4">
<div>
<b>Compliance :</b>
{{#equal compliance "COMPLIANT"}}
<span><i class="fw fw-ok icon-success"></i> Compliant</span>
{{/equal}}
{{#equal compliance "NON-COMPLIANT"}}
<span><i class="fw fw-warning icon-danger"></i> Not Compliant</span>
{{/equal}}
</div>
</div>
</div>
</div>
<div class="col-lg-3">
<span class="list-group-item-actions">
<a href="/emm/policies/view?id={{policy.id}}" class="cu-btn-inner policy-view-link" data-id="{{id}}">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i>
</span>
View
</a>
</span>
</div>
</div>
</span>
</div>
<table class="table table-striped table-hover table-bordered display data-table" id="policy-compliance-table">
<thead>
<tr class="sort-row">
<th>Feature</th>
<th>Compliance</th>
</tr>
</thead>
<tbody>
{{#each complianceFeatures}}
<tr data-type="selectable">
<td data-display="{{featureCode}}" data-grid-label="Feature Code">{{featureCode}}</td>
<td data-display="{{compliance}}" data-grid-label="Status">
{{#equal compliance true}}<span><i class="fw fw-ok icon-success"></i> Compliant</span>{{/equal}}
{{#equal compliance false}}<span><i class="fw fw-warning icon-danger"></i> Not Compliant</span>{{/equal}}
</td>
</tr>
{{/each}}
<br class="c-both" />
</tbody>
</table>

@ -0,0 +1,378 @@
{{#zone "content"}}
{{#defineZone "device-detail-top"}}
<div class="row wr-device-board">
<div class="col-lg-12 wr-secondary-bar">
<label class="device-id device-select" data-deviceid="{{device.deviceIdentifier}}"
data-type="{{device.type}}">
Device {{device.name}}
{{#if device.viewModel.model}}
<span class="lbl-device">
( {{device.viewModel.vendor}} {{device.viewModel.model}} )
</span>
{{/if}}
</label>
</div>
</div>
{{/defineZone}}
<div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;">
<div class="media">
<div class="media-left media-middle asset-image col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="thumbnail icon"><i class="square-element text fw fw-mobile"></i></div>
</div>
<div class="media-body asset-desc add-padding-left-5x">
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">Device Overview</div>
{{#defineZone "device-detail-properties"}}
<table class="table table-responsive table-striped" id="members">
<tbody>
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px; width: 1%;">Device</td>
<td style="padding:10px 15px;">{{device.viewModel.vendor}} {{device.properties.model}}</td>
</tr>
{{#if device.viewModel.model}}
<tr role="row" class="odd">
<td class="sorting_1" style="padding:10px 15px;">Model</td>
<td style="padding:10px 15px;">{{device.viewModel.model}}</td>
</tr>
{{/if}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px;">IMEI</td>
<td style="padding:10px 15px;">{{device.viewModel.imei}}</td>
</tr>
{{#if device.viewModel.udid}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px;">UDID</td>
<td style="padding:10px 15px;">{{device.viewModel.udid}}</td>
</tr>
{{/if}}
{{#if device.viewModel.os_build_date}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px;">Firmware Build Date</td>
<td style="padding:10px 15px;">{{device.viewModel.os_build_date}}</td>
</tr>
{{/if}}
{{#if device.viewModel.phoneNumber}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px;">Phone Number</td>
<td style="padding:10px 15px;">{{device.viewModel.phoneNumber}}</td>
</tr>
{{/if}}
<tr role="row" class="even">
<td class="sorting_1" style="padding:10px 15px;">Status</td>
<td style="padding:10px 15px;">
{{#equal device.status "ACTIVE"}}<span><i class="fw fw-ok icon-success"></i>&nbsp;&nbsp;Active</span>{{/equal}}
{{#equal device.status "INACTIVE"}}<span><i class="fw fw-warning icon-warning"></i>&nbsp;&nbsp;Inactive</span>{{/equal}}
{{#equal device.status "BLOCKED"}}<span><i class="fw fw-remove icon-danger"></i>&nbsp;&nbsp;Blocked</span>{{/equal}}
{{#equal device.status "REMOVED"}}<span><i class="fw fw-delete icon-danger"></i>&nbsp;&nbsp;Removed</span>{{/equal}}
</td>
</tr>
</tbody>
</table>
{{/defineZone}}
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">Operations</div>
<div class="add-margin-top-4x">
{{unit "mdm.unit.device.operation-bar" deviceType=device.type}}
</div>
</div>
</div>
<div class="media tab-responsive">
<div class="media-left col-xs-1 col-sm-1 col-md-2 col-lg-2 hidden-xs">
<ul class="list-group nav nav-pills nav-stacked" role="tablist">
<li class="list-group-item active">
<a href="#device_details" role="tab" data-toggle="tab" aria-controls="device_details">
<i class="icon fw fw-mobile"></i>Device Details
</a>
</li>
<li class="list-group-item">
<a href="#policy_compliance" role="tab" data-toggle="tab" aria-controls="policy_compliance">
<i class="icon fw fw-policy"></i>Policy Compliance
</a>
</li>
<li class="list-group-item">
<a href="#device_location" role="tab" data-toggle="tab"
data-lat="{{device.viewModel.location.latitude}}"
data-long="{{device.viewModel.location.longitude}}"
aria-controls="device_location">
<i class="icon fw fw-map-location"></i> Device Location
</a>
</li>
<li class="list-group-item">
<a href="#installed_applications" role="tab" data-toggle="tab" aria-controls="installed_applications">
<i class="icon fw fw-application"></i> Installed Applications
</a>
</li>
<li class="list-group-item">
<a href="#event_log" role="tab" data-toggle="tab" aria-controls="event_log">
<i class="icon fw fw-text"></i> Operations Log
</a>
</li>
</ul>
</div>
<div class="media-body remove-padding-xs">
{{#defineZone "device-detail-properties"}}
<div class="media-body add-padding-left-5x remove-padding-xs">
<div class="panel-group tab-content" id="tabs">
<div class="arrow-left hidden-xs"></div>
<div class="panel panel-default tab-pane fade in active fade-in-xs visible-block"
id="device_details" role="tabpanel"
aria-labelledby="device_details">
<div class="panel-heading dropup visible-xs" role="tab" id="tab1" data-toggle="collapse"
data-target="#tabContent1" aria-expanded="false" data-parent="#tabs">
<h4 class="panel-title">
<i class="fw fw-map-location fw-2x"></i>
Device Details
<i class="caret-updown fw fw-sort-up"></i>
</h4>
</div>
<div class="panel-heading display-none-xs">Device Details</div>
<div id="loading-content" class="col-centered">
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;<i class="fw fw-settings fw-spin fw-2x"></i>&nbsp;&nbsp;&nbsp;Loading Device Details . . .<br>
</div>
<div class="panel-body collapse display-block-sm display-block-md display-block-lg in"
id="tabContent1">
<div class="device-detail-body hidden">
<!-- device summary -->
{{#equal device.type "windows"}}
<div class="panel-body">
Not available yet
</div>
<br class="c-both"/>
{{/equal}}
{{#if device.viewModel.BatteryLevel}}
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="col-md-12">
<div class="wr-stats-board-tile">
<div class="tile-name">BATTERY</div>
<div>
<div class="tile-icon"><i class="fw fw-battery"></i></div>
<div class="tile-stats">
{{device.viewModel.BatteryLevel}} %
</div>
</div>
</div>
</div>
</div>
{{/if}}
{{#if device.viewModel.DeviceCapacity}}
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="col-md-12">
<div class="wr-stats-board-tile">
<div class="tile-name">STORAGE</div>
<div>
<div class="tile-icon"><i class="fw fw-hdd"></i></div>
<div class="tile-stats">
{{device.viewModel.DeviceCapacityPercentage}} %
<span class="tile-stats-free">
{{device.viewModel.AvailableDeviceCapacity}} GB Free
</span>
</div>
</div>
</div>
</div>
</div>
{{/if}}
{{#if device.viewModel.internal_memory.FreeCapacity}}
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="col-md-12">
<div class="wr-stats-board-tile">
<div class="tile-name">LOCAL STORAGE</div>
<div>
<div class="tile-icon"><i class="fw fw-hdd"></i></div>
<div class="tile-stats">
{{device.viewModel.internal_memory.DeviceCapacityPercentage}} %
<span class="tile-stats-free">
{{device.viewModel.internal_memory.FreeCapacity}} GB Free
</span>
</div>
</div>
</div>
</div>
</div>
{{/if}}
{{#if device.viewModel.external_memory.FreeCapacity}}
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6">
<div class="col-md-12">
<div class="wr-stats-board-tile">
<div class="tile-name">EXTERNAL STORAGE</div>
<div>
<div class="tile-icon"><i class="fw fw-usb-drive"></i></div>
<div class="tile-stats">
{{device.viewModel.external_memory.DeviceCapacityPercentage}} %
<span class="tile-stats-free">
{{device.viewModel.external_memory.FreeCapacity}} GB Free
</span>
</div>
</div>
</div>
</div>
</div>
{{/if}}
</div>
</div>
</div>
<div class="panel panel-default tab-pane fade fade-in-xs visible-block"
id="policy_compliance">
<div class="panel-heading dropdown visible-xs collapsed" role="tab" id="tab2"
data-toggle="collapse" data-target="#tabContent2" aria-expanded="false"
data-parent="#tabs">
<h4 class="panel-title"><i class="fw fw-text fw-2x"></i>
Policy Compliance
<i class="caret-updown fw fw-sort-down"></i>
</h4>
</div>
<div class="panel-heading display-none-xs">
Policy Compliance
&nbsp;&nbsp;
<span>
<a href="#" id="refresh-policy">
<i class="fw fw-refresh"></i>
</a>
</span>
</div>
<div id="policy-spinner" class="wr-advance-operations-init hidden">
<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Policy Compliance . . .
<br>
<br>
</div>
<div class="panel-body collapse display-block-sm display-block-md display-block-lg" id="tabContent2">
<div id="policy-list-container">
<div class="panel-body">
There is no active policy for this device.
</div>
<br class="c-both"/>
</div>
</div>
</div>
<div class="panel panel-default tab-pane fade fade-in-xs visible-block"
id="device_location">
<div class="panel-heading dropdown visible-xs collapsed" role="tab" id="tab3"
data-toggle="collapse" data-target="#tabContent3" aria-expanded="false"
data-parent="#tabs">
<h4 class="panel-title">
<i class="fw fw-text fw-2x"></i>
Device Location
<i class="caret-updown fw fw-sort-down"></i>
</h4>
</div>
<div class="panel-heading display-none-xs">Device Location</div>
<div class="panel-body collapse display-block-sm display-block-md display-block-lg"
id="tabContent3">
<div id="device-location"
data-lat="{{device.viewModel.location.latitude}}"
data-long="{{device.viewModel.location.longitude}}"
class="panel-body">
</div>
<div id="map-error" class="panel-body" style="margin: auto;">
Device location cannot be retrieved.
</div>
<br class="c-both"/>
</div>
</div>
<div class="panel panel-default tab-pane fade fade-in-xs visible-block"
id="installed_applications">
<div class="panel-heading dropdown visible-xs collapsed" role="tab" id="tab4"
data-toggle="collapse" data-target="#tabContent4" aria-expanded="false"
data-parent="#tabs">
<h4 class="panel-title">
<i class="fw fw-text fw-2x"></i>
Installed Applications
<i class="caret-updown fw fw-sort-down"></i></h4>
</div>
<div class="panel-heading display-none-xs">
Installed Applications
&nbsp;&nbsp;
<span>
<a href="#" id="refresh-apps">
<i class="fw fw-refresh"></i>
</a>
</span>
</div>
<div class="panel-body collapse display-block-sm display-block-md display-block-lg"
id="tabContent4">
<div id="apps-spinner" class="wr-advance-operations-init hidden">
<br><br>
&nbsp;&nbsp;&nbsp;&nbsp;<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;Loading Applications List . . .<br><br>
</div>
<div id="applications-list-container">
<div class="panel-body">
<br>
<p class="fw-warning">
No applications found. please try refreshing the list in a while.
<p>
</div>
<br class="c-both"/>
</div>
</div>
</div>
<div class="panel panel-default tab-pane fade fade-in-xs visible-block" id="event_log">
<div class="panel-heading dropdown visible-xs collapsed" role="tab" id="tab5"
data-toggle="collapse" data-target="#tabContent5" aria-expanded="false"
data-parent="#tabs">
<h4 class="panel-title">
<i class="fw fw-text fw-2x"></i>
Operations Logs
<i class="caret-updown fw fw-sort-down"></i>
</h4>
</div>
<div class="panel-heading display-none-xs">
Operations Logs
&nbsp;&nbsp;
<span>
<a href="#" id="refresh-operations">
<i class="fw fw-refresh"></i>
</a>
</span>
</div>
<div class="panel-body collapse display-block-sm display-block-md display-block-lg"
id="tabContent5">
<div id="operations-spinner" class="wr-advance-operations-init hidden">
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;<i class="fw fw-settings fw-spin fw-2x"></i>&nbsp;&nbsp;&nbsp;
Loading Operations Log . . .
<br><br>
</div>
<div id="operations-log-container">
<div class="panel-body">
There are no operations, performed yet on this device.
</div>
<br class="c-both"/>
</div>
<table class="table table-striped table-hover table-bordered display data-table"
id="operations-log-table">
<thead>
<tr class="sort-row">
<th>Operation Code</th>
<th>Status</th>
<th>Request created at</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{{/defineZone}}
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
<script id="policy-view" src="{{@unit.publicUri}}/templates/policy-compliance.hbs"
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
type="text/x-handlebars-template"></script>
<script id="applications-list" src="{{@unit.publicUri}}/templates/applications-list.hbs"
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
type="text/x-handlebars-template"></script>
<script id="operations-log" src="{{@unit.publicUri}}/templates/operations-log.hbs"
data-device-id="{{device.deviceIdentifier}}" data-device-type="{{device.type}}"
type="text/x-handlebars-template"></script>
{{js "js/device-detail.js"}}
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>
{{js "js/load-map.js"}}
{{/zone}}

@ -0,0 +1,102 @@
/*
* 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
*
* 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.
*/
function onRequest(context) {
var log = new Log("view.js");
var deviceType = context.uriParams.deviceType;
var deviceId = request.getParameter("id");
var deviceData = {};
if (deviceType && deviceId) {
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
var response = deviceModule.viewDevice(deviceType, deviceId);
if (response["status"] == "success") {
var device = response["content"];
var viewModel = {};
var deviceInfo = device["properties"]["DEVICE_INFO"];
if (deviceInfo && 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"];
var osBuildDate = device["properties"]["OS_BUILD_DATE"];
if (osBuildDate != null && osBuildDate != "0") {
var formattedDate = new Date(osBuildDate * 1000);
viewModel["os_build_date"] = formattedDate;
}
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;
}
}
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"]
};
}
device["viewModel"] = viewModel;
}
deviceData["device"] = device;
}
return deviceData;
}
}
Loading…
Cancel
Save