Complete dashboard functionality

merge-requests/1/head
charithag 9 years ago
parent d46e52c256
commit 7481505342

@ -152,6 +152,49 @@ if (uriMatcher.match("/{context}/api/device/sketch/download/{downloadId}")) {
allDevices.push({id: 0, devices: unsharedDevices}); allDevices.push({id: 0, devices: unsharedDevices});
result.data = allDevices; result.data = allDevices;
} else if (uriMatcher.match("/{context}/api/devices/count")) {
var user = session.get(constants.USER_SESSION_KEY);
if (!user) {
response.sendRedirect(dcProps.appContext + "login?#login-required");
exit();//stop execution
}
//URL: https://localhost:9443/devicecloud/manager/devices/username/{username}
deviceCloudService = carbonHttpsServletTransport + "/devicecloud/device_manager";
listAllDevicesEndPoint = deviceCloudService + "/devices/username/" + user.username;
result = get(listAllDevicesEndPoint, {}, "json");
var ownDevices = result.data;
var allDevices = [];
deviceCloudService = carbonHttpsServletTransport + "/devicecloud/group_manager";
var endPoint = deviceCloudService + "/group/all";
var data = {"username": user.username};
var groups = get(endPoint, data, "json").data;
var count = 0;
for (var g in groups) {
endPoint = deviceCloudService + "/group/id/" + groups[g].id + "/device/all";
data = {"username": user.username};
var deviceInGroup = get(endPoint, data, "json").data;
groups[g].devices = deviceInGroup;
allDevices.push(groups[g]);
for (var od in ownDevices) {
for (var gd in deviceInGroup) {
if (deviceInGroup[gd].deviceIdentifier == ownDevices[od].deviceIdentifier) {
ownDevices[od].deviceIdentifier = -1;
}
}
}
count += deviceInGroup.length;
}
for (var od in ownDevices) {
if (ownDevices[od].deviceIdentifier != -1){
count++;
}
}
result.data = count;
} else if (uriMatcher.match("/{context}/api/devices/types")) { } else if (uriMatcher.match("/{context}/api/devices/types")) {
result = deviceModule.listDeviceTypes(); result = deviceModule.listDeviceTypes();

@ -58,6 +58,9 @@ if (uriMatcher.match("/{context}/api/policies/update")) {
// http status code 500 refers to - Internal Server Error. // http status code 500 refers to - Internal Server Error.
result = 500; result = 500;
} }
} else if (uriMatcher.match("/{context}/api/policies/count")) {
result = {}
result.data = policyModule.getPolicies().length;
} }
// returning the result. // returning the result.

@ -139,6 +139,10 @@ if (uriMatcher.match("/{context}/api/user/login/")) {
} else if (uriMatcher.match("/{context}/api/users")) { } else if (uriMatcher.match("/{context}/api/users")) {
result = userModule.getUsers(); result = userModule.getUsers();
} else if (uriMatcher.match("/{context}/api/users/count")) {
result = {};
result.data = userModule.getUsers().length;
} }
// returning the result. // returning the result.

@ -4,6 +4,6 @@
WSO2 DC | Device Cloud WSO2 DC | Device Cloud
{{/zone}} {{/zone}}
{{#zone "body"}} {{#zone "body"}}
{{unit "appbar"}} {{unit "appbar" title="Dashboard"}}
{{unit "dashboard"}} {{unit "dashboard"}}
{{/zone}} {{/zone}}

@ -41,13 +41,13 @@
<!-- common navigation --> <!-- common navigation -->
<div id="hiddenNav" class="wr-hidden-nav"> <div id="hiddenNav" class="wr-hidden-nav">
<ul> <ul>
<li><a href="/iotserver/dashboard"><i class="fw fw-globe"></i>Dashboard</a></li>
<li><a href="/iotserver/devices"><i class="fw fw-mobile"></i>My Devices</a></li> <li><a href="/iotserver/devices"><i class="fw fw-mobile"></i>My Devices</a></li>
<li><a href="/iotserver/groups"><i class="fw fw-group"></i>My Groups</a></li> <li><a href="/iotserver/groups"><i class="fw fw-group"></i>My Groups</a></li>
{{#if permissions.ADD_USER}} {{#if permissions.ADD_USER}}
<li><a href="/iotserver/users"><i class="fw fw-user"></i>User Management</a></li> <li><a href="/iotserver/users"><i class="fw fw-user"></i>User Management</a></li>
{{/if}} {{/if}}
<li><a href="/iotserver/policies"><i class="fw fw-policy"></i>Policy Management</a></li> <li><a href="/iotserver/policies"><i class="fw fw-policy"></i>Policy Management</a></li>
<li><a href="/iotserver/dashboard"><i class="fw fw-settings"></i>Dashboard</a></li>
</ul> </ul>
</div> </div>
<!-- /common navigation --> <!-- /common navigation -->

@ -18,6 +18,13 @@
</span> </span>
View View
</a> </a>
<a href="devices/add-device">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add
</a>
</span> </span>
</div> </div>
</div> </div>
@ -60,14 +67,14 @@
<div class="tile-stats"> <div class="tile-stats">
<span id="policy-count">Loading...</span> <span id="policy-count">Loading...</span>
<span class="tile-stats-free"> <span class="tile-stats-free">
<a href="policies.html"> <a href="policies">
<span class="fw-stack"> <span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-view fw-stack-1x"></i> <i class="fw fw-view fw-stack-1x"></i>
</span> </span>
View View
</a> </a>
<a href="policy-create-wizard.html"> <a href="policies/add-policy">
<span class="fw-stack"> <span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i> <i class="fw fw-add fw-stack-1x"></i>

@ -1,8 +1,8 @@
var updateStats = function (serviceURL, id) { var updateStats = function (serviceURL, id) {
invokerUtil.get( invokerUtil.get(
serviceURL, serviceURL,
function (data) { function (result) {
$(id).html(data); $(id).html(JSON.parse(result).data);
}, function (message) { }, function (message) {
console.log(message); console.log(message);
} }
@ -10,11 +10,7 @@ var updateStats = function (serviceURL, id) {
}; };
$(document).ready(function(){ $(document).ready(function(){
//updateStats("/mdm-admin/devices/count", "#device-count"); updateStats("/iotserver/api/devices/count", "#device-count");
//updateStats("/mdm-admin/policies/count", "#policy-count"); updateStats("/iotserver/api/policies/count", "#policy-count");
//updateStats("/mdm-admin/users/count/" + "carbon.super", "#user-count"); updateStats("/iotserver/api/users/count", "#user-count");
//TODO: get this value from devicecloud webservice
$("#device-count").html("0");
$("#policy-count").html("0");
$("#user-count").html("0");
}); });
Loading…
Cancel
Save