From 9f99e6e4da30947bff9c0c6f5e48d1b2f571cdb4 Mon Sep 17 00:00:00 2001 From: charithag Date: Fri, 7 Aug 2015 15:06:11 +0530 Subject: [PATCH 1/2] Add data simulation as comment --- .../jaggeryapps/iotserver/api/event-api.jag | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) 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 5a052ed0..a0d28c44 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/event-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/event-api.jag @@ -25,12 +25,6 @@ var log = new Log("api/event-api.jag"); var constants = require("/modules/constants.js"); 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); if (!user) { response.sendRedirect(dcProps.appContext + "login?#login-required"); @@ -38,31 +32,31 @@ if (!user) { } var result; -var endPoint; -var data; -var groupId; if (uriMatcher.match("/{context}/api/event/list")) { + /* - var timeInterval = 30; - var i, rnd; - result = []; - var currentDay = new Date(); - var startDate = currentDay.getTime() - (60 * 60 * 24 * 100); - var endDate = currentDay.getTime(); + var timeInterval = 30; + var i, rnd; + result = []; + var currentDay = new Date(); + var startDate = currentDay.getTime() - (60 * 60 * 24 * 100); + 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 { result = statsClient.getRecentDeviceStats(user, 10); } catch (error) { log.error(error); } + } // returning the result. From 91ab732dba19d87bc74860cfc7eca8953beb2120 Mon Sep 17 00:00:00 2001 From: charithag Date: Fri, 7 Aug 2015 15:20:23 +0530 Subject: [PATCH 2/2] Set trigger to display add group popup --- .../iotserver/units/dashboard/dashboard.hbs | 50 ++++----- .../group-listing/public/js/group-listing.js | 100 ++++++++++-------- 2 files changed, 79 insertions(+), 71 deletions(-) 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 5b2ed67a..5a353abd 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/dashboard/dashboard.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/dashboard/dashboard.hbs @@ -30,62 +30,64 @@ - {{#if permissions.ADD_USER}} +
-
Users
+
Groups
-
+
- Loading... + Loading... - + View - - - - - - - + + + + + + Add +
- {{/if}} + + {{#if permissions.ADD_USER}}
-
Groups
+
Users
-
+
- Loading... + Loading... - + View - - - - - - Add - + + + + + + +
+ {{/if}}
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js index cdfbd19d..24be4bce 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/js/group-listing.js @@ -64,7 +64,14 @@ $(document).ready(function () { return $("#content-filter-types").html(); } }); + + loadGroups(); 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() { $(".formatDate").each(function () { @@ -236,58 +240,60 @@ function attachGroupAdding() { * when a user clicks on "Remove" link * on Group Management page in WSO2 IoT Server Console. */ - $("a.add-group-link").click(function () { - var addGroupApi = "/iotserver/api/group/add"; - $(modalPopupContent).html($('#add-group-modal-content').html()); - showPopup(); + $("a.add-group-link").click(addNewGroup); +} - $("a#add-group-yes-link").click(function () { - var newGroupName = $('#add-group-name').val(); - var newGroupDescription = $('#add-group-description').val(); - var group = {"name": newGroupName, "description": newGroupDescription}; - invokerUtil.post( - addGroupApi, - group, - function (data, txtStatus, jqxhr) { - var status = jqxhr.status; - if (status == 200) { - if (data != "false") { - $(modalPopupContent).html($('#add-group-200-content').html()); - loadGroups(); - setTimeout(function () { - hidePopup(); - }, 2000); - } else { - $(modalPopupContent).html($('#group-400-content').html()); - $("a#group-400-link").click(function () { - hidePopup(); - }); - } - } else if (status == 400) { +var addNewGroup = function () { + var addGroupApi = "/iotserver/api/group/add"; + $(modalPopupContent).html($('#add-group-modal-content').html()); + showPopup(); + + $("a#add-group-yes-link").click(function () { + var newGroupName = $('#add-group-name').val(); + var newGroupDescription = $('#add-group-description').val(); + var group = {"name": newGroupName, "description": newGroupDescription}; + invokerUtil.post( + addGroupApi, + group, + function (data, txtStatus, jqxhr) { + var status = jqxhr.status; + if (status == 200) { + if (data != "false") { + $(modalPopupContent).html($('#add-group-200-content').html()); + loadGroups(); + setTimeout(function () { + hidePopup(); + }, 2000); + } else { $(modalPopupContent).html($('#group-400-content').html()); $("a#group-400-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(); - }); + } else if (status == 400) { + $(modalPopupContent).html($('#group-400-content').html()); + $("a#group-400-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(); }); + } /**