moving events into page

application-manager-new
Rasika Perera 9 years ago
parent fbaa9a2e2f
commit 08e30b1efb

@ -29,6 +29,8 @@ var carbon = require('carbon');
var carbonHttpsServletTransport = carbon.server.address('https'); var carbonHttpsServletTransport = carbon.server.address('https');
var deviceCloudService = carbonHttpsServletTransport + "/devicecloud/group_manager"; 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");
@ -41,12 +43,15 @@ var data;
var groupId; var groupId;
if (uriMatcher.match("/{context}/api/event/list")) { if (uriMatcher.match("/{context}/api/event/list")) {
try {
fetchedData = statsClient.getRecentDeviceStats(user, 10);
} catch (error) {
log.error(error);
}
} }
// returning the result. // returning the result.
if (result) { if (result) {
response.status = result.xhr.status; print(result);
print(result.data);
} }
%> %>

@ -0,0 +1,9 @@
{{authorized}}
{{layout "fluid"}}
{{#zone "title"}}
Events
{{/zone}}
{{#zone "body"}}
{{unit "appbar" link="events" title="My Events"}}
{{unit "events"}}
{{/zone}}

@ -10,7 +10,8 @@ function onRequest(context) {
"group-mgt": [], "group-mgt": [],
"store": [], "store": [],
"dashboard": [], "dashboard": [],
"analytics" : [] "analytics" : [],
"events" : []
}; };
var dashboardLink = { var dashboardLink = {
title: "Go back to Dashboard", title: "Go back to Dashboard",
@ -39,8 +40,11 @@ function onRequest(context) {
links.users.push(dashboardLink); links.users.push(dashboardLink);
links.policies.push(dashboardLink); links.policies.push(dashboardLink);
links.profiles.push(dashboardLink); links.profiles.push(dashboardLink);
links.events.push(dashboardLink);
//links.store.push(dashboardLink); //links.store.push(dashboardLink);
links.store.push(storeLink); links.store.push(storeLink);
links['group-mgt'].push(dashboardLink); links['group-mgt'].push(dashboardLink);
var groupId = request.getParameter("groupId"); var groupId = request.getParameter("groupId");
if (groupId){ if (groupId){

@ -115,6 +115,26 @@
</div> </div>
</div> </div>
<div class="col-md-4">
<div class="wr-stats-board-tile">
<div class="tile-name">Events</div>
<div>
<div class="tile-icon"><i class="fw fw-apn"></i></div>
<div class="tile-stats">
<span class="tile-stats-free">
<a href="events">
<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>
</div>
</div>
</div> </div>
</div> </div>
<!-- /dashboard --> <!-- /dashboard -->

@ -0,0 +1,20 @@
{{#zone "main"}}
<div class="container container-bg white-bg">
<div class=" margin-top-double">
<div class="row row padding-top-double padding-bottom-double margin-bottom-double">
<div class="col-lg-12 margin-top-double">
<h1 class="grey ">Events</h1>
<hr>
<p class="margin-bottom-double light-grey ">Events Analyzer </p>
</div>
<div id="event-stream-place-holder" style="padding-top: 20px;">
</div>
</div>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
<script src="{{self.publicURL}}/js/events.js"></script>
<script id="event-stream" src="{{self.publicURL}}/templates/event-stream.hbs"
type="text/x-handlebars-template"></script>
{{/zone}}

@ -0,0 +1,6 @@
function onRequest(context){
var userModule = require("/modules/user.js").userModule;
var permissions = userModule.getUIPermissions();
context.permissions = permissions;
return context;
}

@ -0,0 +1,22 @@
$(document).ready(function () {
displayEvents();
});
var displayEvents = function () {
var eventListing = $("#event-stream");
var eventListingSrc = eventListing.attr("src");
$.template("event-stream", eventListingSrc, function (template) {
var serviceURL = "/iotserver/api/event/list";
var successCallback = function (data) {
var viewModel = {};
viewModel.data = JSON.parse(data);
var content = template(viewModel);
$("#event-stream-place-holder").html(content);
formatDates();
};
invokerUtil.get(serviceURL,
successCallback, function (message) {
console.log(message);
});
});
};

@ -0,0 +1,27 @@
<div class="col-lg-12 wr-secondary-bar" style="width: inherit;">
<label class="device-id device-select" style="font-size: 20px; margin-bottom: 0px;">
Device Events Stream
</label>
</div>
<br/>
<div style="padding: 15px;">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th width="20%">Time</th>
<th width="20%">Device</th>
<th>Activity</th>
</tr>
</thead>
<tbody>
{{#each data}}
<tr>
<td width="20%" class="formatDate">{{time}}</td>
<td width="20%">{{deviceName}}</td>
<td>{{activity}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
Loading…
Cancel
Save