fixing issues in events api

application-manager-new
Rasika Perera 10 years ago
commit 42a04c2660

@ -25,12 +25,6 @@ var log = new Log("api/event-api.jag");
var constants = require("/modules/constants.js"); var constants = require("/modules/constants.js");
var dcProps = require('/config/dc-props.js').config(); var dcProps = require('/config/dc-props.js').config();
var carbon = require('carbon');
var carbonHttpsServletTransport = carbon.server.address('https');
var deviceCloudService = carbonHttpsServletTransport + "/devicecloud/group_manager";
var statsClient = new Packages.org.wso2.carbon.device.mgt.iot.common.analytics.statistics.IoTEventsStatisticsClient;
var user = session.get(constants.USER_SESSION_KEY); var user = session.get(constants.USER_SESSION_KEY);
if (!user) { if (!user) {
response.sendRedirect(dcProps.appContext + "login?#login-required"); response.sendRedirect(dcProps.appContext + "login?#login-required");
@ -38,32 +32,32 @@ if (!user) {
} }
var result; var result;
var endPoint;
var data;
var groupId;
if (uriMatcher.match("/{context}/api/event/list")) { if (uriMatcher.match("/{context}/api/event/list")) {
/* /*
var timeInterval = 30; var timeInterval = 30;
var i, rnd; var i, rnd;
result = []; result = [];
var currentDay = new Date(); var currentDay = new Date();
var startDate = currentDay.getTime() - (60 * 60 * 24 * 100); var startDate = currentDay.getTime() - (60 * 60 * 24 * 100);
var endDate = currentDay.getTime(); var endDate = currentDay.getTime();
var i = parseInt(startDate / 1000);
while (i < parseInt(endDate / 1000)) {
rnd = rnd = Math.random() * 50;
result.push({time: i * 1000, deviceName: 'device' + rnd, activity:'Event number ' + rnd});
i += timeInterval;
}
*/
var i = parseInt(startDate / 1000);
while (i < parseInt(endDate / 1000)) {
rnd = rnd = Math.random() * 50;
result.push({time: i, deviceName: 'device' + rnd, activity:'Event number ' + rnd});
i += timeInterval;
}
*/
try { try {
result = statsClient.getRecentDeviceStats(user, 10); result = statsClient.getRecentDeviceStats(user, 10);
} catch (error) { } catch (error) {
log.error(error); log.error(error);
} }
<<<<<<< HEAD
var eventsData = []; var eventsData = [];
if (fetchedData == null) return []; if (fetchedData == null) return [];
@ -83,6 +77,8 @@ if (uriMatcher.match("/{context}/api/event/list")) {
} }
return eventsData; return eventsData;
=======
>>>>>>> 91ab732dba19d87bc74860cfc7eca8953beb2120
} }
// returning the result. // returning the result.

@ -30,62 +30,64 @@
</div> </div>
</div> </div>
</div> </div>
{{#if permissions.ADD_USER}}
<div class="col-md-4"> <div class="col-md-4">
<div class="wr-stats-board-tile"> <div class="wr-stats-board-tile">
<div class="tile-name">Users</div> <div class="tile-name">Groups</div>
<div> <div>
<div class="tile-icon"><i class="fw fw-user"></i></div> <div class="tile-icon"><i class="fw fw-policy"></i></div>
<div class="tile-stats"> <div class="tile-stats">
<span id="user-count">Loading...</span> <span id="group-count">Loading...</span>
<span class="tile-stats-free"> <span class="tile-stats-free">
<a href="users/"> <a href="groups">
<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="user-create.html">--> <a href="groups/add-group">
<!--<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>
<!--</span>--> </span>
<!--Add--> Add
<!--</a>--> </a>
</span> </span>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{{/if}}
{{#if permissions.ADD_USER}}
<div class="col-md-4"> <div class="col-md-4">
<div class="wr-stats-board-tile"> <div class="wr-stats-board-tile">
<div class="tile-name">Groups</div> <div class="tile-name">Users</div>
<div> <div>
<div class="tile-icon"><i class="fw fw-policy"></i></div> <div class="tile-icon"><i class="fw fw-user"></i></div>
<div class="tile-stats"> <div class="tile-stats">
<span id="group-count">Loading...</span> <span id="user-count">Loading...</span>
<span class="tile-stats-free"> <span class="tile-stats-free">
<a href="groups"> <a href="users/">
<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="groups/add-group"> <!--<a href="user-create.html">-->
<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>-->
</span> <!--</span>-->
Add <!--Add-->
</a> <!--</a>-->
</span> </span>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{{/if}}
<div class="col-md-4"> <div class="col-md-4">
<div class="wr-stats-board-tile"> <div class="wr-stats-board-tile">

@ -64,7 +64,14 @@ $(document).ready(function () {
return $("#content-filter-types").html(); return $("#content-filter-types").html();
} }
}); });
loadGroups();
changeGroupView('grid', $('a.ctrl-filter-grid')); changeGroupView('grid', $('a.ctrl-filter-grid'));
var path = window.location.pathname;
if (path == '/iotserver/groups/add-group'){
addNewGroup();
}
}); });
/* /*
@ -168,9 +175,6 @@ function loadGroups(searchType, searchParam) {
}); });
}); });
} }
$(document).ready(function () {
loadGroups();
});
function formatDates() { function formatDates() {
$(".formatDate").each(function () { $(".formatDate").each(function () {
@ -236,58 +240,60 @@ function attachGroupAdding() {
* when a user clicks on "Remove" link * when a user clicks on "Remove" link
* on Group Management page in WSO2 IoT Server Console. * on Group Management page in WSO2 IoT Server Console.
*/ */
$("a.add-group-link").click(function () { $("a.add-group-link").click(addNewGroup);
var addGroupApi = "/iotserver/api/group/add"; }
$(modalPopupContent).html($('#add-group-modal-content').html());
showPopup();
$("a#add-group-yes-link").click(function () { var addNewGroup = function () {
var newGroupName = $('#add-group-name').val(); var addGroupApi = "/iotserver/api/group/add";
var newGroupDescription = $('#add-group-description').val(); $(modalPopupContent).html($('#add-group-modal-content').html());
var group = {"name": newGroupName, "description": newGroupDescription}; showPopup();
invokerUtil.post(
addGroupApi, $("a#add-group-yes-link").click(function () {
group, var newGroupName = $('#add-group-name').val();
function (data, txtStatus, jqxhr) { var newGroupDescription = $('#add-group-description').val();
var status = jqxhr.status; var group = {"name": newGroupName, "description": newGroupDescription};
if (status == 200) { invokerUtil.post(
if (data != "false") { addGroupApi,
$(modalPopupContent).html($('#add-group-200-content').html()); group,
loadGroups(); function (data, txtStatus, jqxhr) {
setTimeout(function () { var status = jqxhr.status;
hidePopup(); if (status == 200) {
}, 2000); if (data != "false") {
} else { $(modalPopupContent).html($('#add-group-200-content').html());
$(modalPopupContent).html($('#group-400-content').html()); loadGroups();
$("a#group-400-link").click(function () { setTimeout(function () {
hidePopup(); hidePopup();
}); }, 2000);
} } else {
} else if (status == 400) {
$(modalPopupContent).html($('#group-400-content').html()); $(modalPopupContent).html($('#group-400-content').html());
$("a#group-400-link").click(function () { $("a#group-400-link").click(function () {
hidePopup(); hidePopup();
}); });
} else if (status == 403) {
$(modalPopupContent).html($('#agroup-403-content').html());
$("a#group-403-link").click(function () {
hidePopup();
});
} else if (status == 409) {
$(modalPopupContent).html($('#group-409-content').html());
$("a#group-409-link").click(function () {
hidePopup();
});
} }
}, errorHandler } else if (status == 400) {
); $(modalPopupContent).html($('#group-400-content').html());
}); $("a#group-400-link").click(function () {
hidePopup();
$("a#add-group-cancel-link").click(function () { });
hidePopup(); } else if (status == 403) {
}); $(modalPopupContent).html($('#agroup-403-content').html());
$("a#group-403-link").click(function () {
hidePopup();
});
} else if (status == 409) {
$(modalPopupContent).html($('#group-409-content').html());
$("a#group-409-link").click(function () {
hidePopup();
});
}
}, errorHandler
);
});
$("a#add-group-cancel-link").click(function () {
hidePopup();
}); });
} }
/** /**

Loading…
Cancel
Save