From 08e30b1efbae00d6f5e074a2387c57cc85412675 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Fri, 7 Aug 2015 14:49:54 +0530 Subject: [PATCH] moving events into page --- .../jaggeryapps/iotserver/api/event-api.jag | 11 +++++--- .../iotserver/pages/events/index.hbs | 9 +++++++ .../iotserver/units/appbar/appbar.js | 6 ++++- .../iotserver/units/dashboard/dashboard.hbs | 20 ++++++++++++++ .../iotserver/units/events/events.hbs | 20 ++++++++++++++ .../iotserver/units/events/events.js | 6 +++++ .../iotserver/units/events/events.json | 3 +++ .../units/events/public/js/events.js | 22 +++++++++++++++ .../events/public/templates/event-stream.hbs | 27 +++++++++++++++++++ 9 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/pages/events/index.hbs create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.hbs create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.js create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.json create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/events/public/js/events.js create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/units/events/public/templates/event-stream.hbs diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/event-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/event-api.jag index 5dff6ff9..944722c1 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/event-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/event-api.jag @@ -29,6 +29,8 @@ 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); if (!user) { response.sendRedirect(dcProps.appContext + "login?#login-required"); @@ -41,12 +43,15 @@ var data; var groupId; if (uriMatcher.match("/{context}/api/event/list")) { - + try { + fetchedData = statsClient.getRecentDeviceStats(user, 10); + } catch (error) { + log.error(error); + } } // returning the result. if (result) { - response.status = result.xhr.status; - print(result.data); + print(result); } %> \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/events/index.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/events/index.hbs new file mode 100644 index 00000000..30fa1e8a --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/events/index.hbs @@ -0,0 +1,9 @@ +{{authorized}} +{{layout "fluid"}} +{{#zone "title"}} + Events +{{/zone}} +{{#zone "body"}} + {{unit "appbar" link="events" title="My Events"}} + {{unit "events"}} +{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js index c7c27bec..e1a7f8d8 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/appbar/appbar.js @@ -10,7 +10,8 @@ function onRequest(context) { "group-mgt": [], "store": [], "dashboard": [], - "analytics" : [] + "analytics" : [], + "events" : [] }; var dashboardLink = { title: "Go back to Dashboard", @@ -39,8 +40,11 @@ function onRequest(context) { links.users.push(dashboardLink); links.policies.push(dashboardLink); links.profiles.push(dashboardLink); + links.events.push(dashboardLink); + //links.store.push(dashboardLink); links.store.push(storeLink); + links['group-mgt'].push(dashboardLink); var groupId = request.getParameter("groupId"); if (groupId){ diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/dashboard/dashboard.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/dashboard/dashboard.hbs index 8d897e66..9f8604ab 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/dashboard/dashboard.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/dashboard/dashboard.hbs @@ -115,6 +115,26 @@ +
+
+
Events
+
+
+ +
+
+
+ diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.hbs new file mode 100644 index 00000000..c87c6592 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.hbs @@ -0,0 +1,20 @@ +{{#zone "main"}} +
+
+
+
+

Events

+
+

Events Analyzer

+
+
+
+
+
+
+{{/zone}} +{{#zone "bottomJs"}} + + +{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.js new file mode 100644 index 00000000..a28530c1 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.js @@ -0,0 +1,6 @@ +function onRequest(context){ + var userModule = require("/modules/user.js").userModule; + var permissions = userModule.getUIPermissions(); + context.permissions = permissions; + return context; +} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.json new file mode 100644 index 00000000..0e0dcd23 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/events.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/public/js/events.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/public/js/events.js new file mode 100644 index 00000000..b88cb586 --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/public/js/events.js @@ -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); + }); + }); +}; \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/public/templates/event-stream.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/public/templates/event-stream.hbs new file mode 100644 index 00000000..accd43dc --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/events/public/templates/event-stream.hbs @@ -0,0 +1,27 @@ +
+ +
+
+ +
+ + + + + + + + + + {{#each data}} + + + + + + {{/each}} + +
TimeDeviceActivity
{{time}}{{deviceName}}{{activity}}
+
\ No newline at end of file