From d7c6c083a07dea4401f438469a06327b1280761f Mon Sep 17 00:00:00 2001 From: charithag Date: Mon, 27 Jul 2015 11:59:50 +0530 Subject: [PATCH] Add Sonar graph to analytics. Fix undefined content issue in device details --- .../jaggeryapps/iotserver/api/stats-api.jag | 1 + .../iotserver/pages/groups/analytics.hbs | 9 ++ .../iotserver/units/analytics/analytics.hbs | 3 +- .../iotserver/units/analytics/analytics.js | 9 ++ .../units/device-detail/device-detail.hbs | 123 ++++++++------- .../device-detail/public/js/device-detail.js | 51 +------ .../public/js/device-listing.js | 143 +++++++++--------- .../public/templates/device-listing.hbs | 4 +- 8 files changed, 169 insertions(+), 174 deletions(-) create mode 100644 modules/distribution/src/repository/jaggeryapps/iotserver/pages/groups/analytics.hbs diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag index 9f3fa5fb..852a8589 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/stats-api.jag @@ -79,6 +79,7 @@ function getFireAlarmData(user, deviceId, from, to) { result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to); result['fanData'] = getSensorData("DEVICE_FAN_USAGE_SUMMARY", "status", user, deviceId, from, to); result['bulbData'] = getSensorData("DEVICE_BULB_USAGE_SUMMARY", "status", user, deviceId, from, to); + result['sonarData'] = getSensorData("SONAR_SENSOR_SUMMARY", "sonar", user, deviceId, from, to); return result; } diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/pages/groups/analytics.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/groups/analytics.hbs new file mode 100644 index 00000000..d34ba39c --- /dev/null +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/pages/groups/analytics.hbs @@ -0,0 +1,9 @@ +{{authorized}} +{{layout "fluid"}} +{{#zone "title"}} + WSO2 DC | Analytics +{{/zone}} +{{#zone "body"}} + {{unit "appbar" link="analytics" title="Group Analytics"}} + {{unit "analytics"}} +{{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs index 27abf139..5fa265cb 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.hbs @@ -1,9 +1,10 @@ {{#zone "main"}} +
-

Device Statistics

+

{{title}}


diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.js index 2a96b071..353852b2 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/analytics/analytics.js @@ -1,4 +1,13 @@ function onRequest(context){ context.sketchPath = "api/device/sketch"; + var groupId = request.getParameter("groupId"); + if (groupId){ + context.groupId = groupId; + context.title = "Group Analytics"; + }else{ + context.groupId = 0; + context.title = "Device Analytics"; + } + return context; } diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/device-detail.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/device-detail.hbs index bf566146..b261e3bc 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/device-detail.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/device-detail.hbs @@ -1,22 +1,22 @@ {{#zone "main"}}
-
-
- {{unit "operation-bar" deviceType=device.type}} + {{unit "operation-bar" deviceType=device.type}}
@@ -25,11 +25,12 @@
- +
Owner: {{device.owner}}
-
Date of Enrollment:
{{device.enrollment}}
+
Date of Enrollment:
{{device.dateOfEnrolment}}
@@ -45,7 +46,7 @@
- {{#if device.viewModel.BatteryLevel}} + {{#if device.viewModel.BatteryLevel}}
BATTERY
@@ -55,41 +56,47 @@
- {{/if}} + {{/if}} - {{#if device.viewModel.DeviceCapacity}} + {{#if device.viewModel.DeviceCapacity}}
STORAGE
-
{{device.viewModel.DeviceCapacityPercentage}}%{{device.viewModel.DeviceCapacityUsed}} GB Free
+
{{device.viewModel.DeviceCapacityPercentage}} + %{{device.viewModel.DeviceCapacityUsed}} + GB Free
- {{/if}} - {{#if device.viewModel.internal_memory.FreeCapacity}} + {{/if}} + {{#if device.viewModel.internal_memory.FreeCapacity}}
LOCAL STORAGE
-
{{device.viewModel.internal_memory.DeviceCapacityPercentage}}%{{device.viewModel.internal_memory.FreeCapacity}} GB Free
+
{{device.viewModel.internal_memory.DeviceCapacityPercentage}} + %{{device.viewModel.internal_memory.FreeCapacity}} + GB Free
- {{/if}} - {{#if device.viewModel.external_memory.FreeCapacity}} + {{/if}} + {{#if device.viewModel.external_memory.FreeCapacity}}
EXTERNAL STORAGE
-
{{device.viewModel.external_memory.DeviceCapacityPercentage}}%{{device.viewModel.external_memory.FreeCapacity}} GB Free
+
{{device.viewModel.external_memory.DeviceCapacityPercentage}} + %{{device.viewModel.external_memory.FreeCapacity}} + GB Free
- {{/if}} + {{/if}}
@@ -101,7 +108,8 @@
- @@ -120,22 +130,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -143,7 +153,8 @@
-
+
Not available yet
@@ -162,27 +174,26 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + -
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/public/js/device-detail.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/public/js/device-detail.js index c453c889..a86523fd 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/public/js/device-detail.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-detail/public/js/device-detail.js @@ -16,54 +16,13 @@ * under the License. */ -function formatDates(){ - $(".formatDate").each(function(){ +function formatDates() { + $(".formatDate").each(function () { var timeStamp = $(this).html(); $(this).html(new Date(parseInt(timeStamp)).toUTCString()); }); } -(function () { - var deviceId = $(".device-id"); - var deviceIdentifier = deviceId.data("deviceid"); - var deviceType = deviceId.data("type"); - var payload = [deviceIdentifier]; - if (deviceType == "ios") { - var serviceUrl = "/ios/operation/deviceinfo"; - } else if (deviceType == "android") { - var serviceUrl = "/mdm-android-agent/operation/device-info"; - } - invokerUtil.post(serviceUrl, payload, - function(message){ - console.log(message); - }, function (message) { - console.log(message); - }); - $(document).ready(function(){ - loadOperationBar(deviceType); - loadMap(); - formatDates(); - }); - function loadMap(){ - var map; - function initialize() { - var mapOptions = { - zoom: 18 - }; - var lat = 6.9098591; - var long = 79.8523753; - map = new google.maps.Map(document.getElementById('device-location'), - mapOptions); - - var pos = new google.maps.LatLng(lat, - long); - var marker = new google.maps.Marker({ - position: pos, - map: map - }); - - map.setCenter(pos); - } - google.maps.event.addDomListener(window, 'load', initialize); - } -}()); +$(document).ready(function () { + formatDates(); +}); \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js index acc0984c..c3b570ae 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/js/device-listing.js @@ -187,7 +187,7 @@ function loadDevices(searchType, searchParam) { addDeviceSelectedClass(this); }); attachEvents(); - //formatDates(); + formatDates(); } }; invokerUtil.get(serviceURL, @@ -374,81 +374,86 @@ function attachEvents() { * when a user clicks on "Group" link * on Device Management page in WSO2 MDM Console. */ - $("a.group-device-link").click(function () { - var deviceId = $(this).data("deviceid"); - var deviceType = $(this).data("devicetype"); - var endPoint = "/iotserver/api/group/all"; + if (groupId && groupId != "0") { + $("a.group-device-link").remove(); + }else{ + $("a.group-device-link").click(function () { + var deviceId = $(this).data("deviceid"); + var deviceType = $(this).data("devicetype"); + var endPoint = "/iotserver/api/group/all"; - $(modalPopupContent).html($('#group-device-modal-content').html()); - $('#user-groups').html("Loading..."); - $("a#group-device-yes-link").hide(); - showPopup(); + $(modalPopupContent).html($('#group-device-modal-content').html()); + $('#user-groups').html("Loading..."); + $("a#group-device-yes-link").hide(); + showPopup(); - invokerUtil.get(endPoint, - function (data, txtStatus, jqxhr) { - var groups = JSON.parse(data); - var status = jqxhr.status; - if (status == 200) { - if (groups.length <= 0) { - $('#user-groups').html("There is no any groups available"); - return; - } - var str = '
'; - $('#user-groups').html(str); - $("a#group-device-yes-link").show(); - $("a#group-device-yes-link").click(function () { - var selectedGroupId = $('#assign-group-selector').val(); - endPoint = "/iotserver/api/group/id/" + selectedGroupId + "/assign"; - var device = {"deviceId": deviceId, "deviceType": deviceType}; - invokerUtil.post( - endPoint, - device, - function (data, txtStatus, jqxhr) { - var status = jqxhr.status; - if (status == 200) { - $(modalPopupContent).html($('#group-associate-device-200-content').html()); - $("a#group-associate-device-200-link").click(function () { - hidePopup(); - }); - } else if (status == 400) { - $(modalPopupContent).html($('#device-400-content').html()); - $("a#device-400-link").click(function () { - hidePopup(); - }); - } else if (status == 403) { - $(modalPopupContent).html($('#device-403-content').html()); - $("a#device-403-link").click(function () { - hidePopup(); - }); - } else if (status == 409) { - $(modalPopupContent).html($('#device-409-content').html()); - $("a#device-409-link").click(function () { + invokerUtil.get(endPoint, + function (data, txtStatus, jqxhr) { + var groups = JSON.parse(data); + var status = jqxhr.status; + if (status == 200) { + if (groups.length <= 0) { + $('#user-groups').html("There is no any groups available"); + return; + } + var str = '
'; + $('#user-groups').html(str); + $("a#group-device-yes-link").show(); + $("a#group-device-yes-link").click(function () { + var selectedGroupId = $('#assign-group-selector').val(); + endPoint = "/iotserver/api/group/id/" + selectedGroupId + "/assign"; + var device = {"deviceId": deviceId, "deviceType": deviceType}; + invokerUtil.post( + endPoint, + device, + function (data, txtStatus, jqxhr) { + var status = jqxhr.status; + if (status == 200) { + $(modalPopupContent).html($('#group-associate-device-200-content').html()); + $("a#group-associate-device-200-link").click(function () { + hidePopup(); + }); + } else if (status == 400) { + $(modalPopupContent).html($('#device-400-content').html()); + $("a#device-400-link").click(function () { + hidePopup(); + }); + } else if (status == 403) { + $(modalPopupContent).html($('#device-403-content').html()); + $("a#device-403-link").click(function () { + hidePopup(); + }); + } else if (status == 409) { + $(modalPopupContent).html($('#device-409-content').html()); + $("a#device-409-link").click(function () { + hidePopup(); + }); + } + }, + function () { + $(modalPopupContent).html($('#device-unexpected-error-content').html()); + $("a#device-unexpected-error-link").click(function () { hidePopup(); }); - } - }, - function () { - $(modalPopupContent).html($('#device-unexpected-error-content').html()); - $("a#device-unexpected-error-link").click(function () { - hidePopup(); }); - }); + }); + } + }, + function () { + $(modalPopupContent).html($('#device-unexpected-error-content').html()); + $("a#device-unexpected-error-link").click(function () { + hidePopup(); }); - } - }, - function () { - $(modalPopupContent).html($('#device-unexpected-error-content').html()); - $("a#device-unexpected-error-link").click(function () { - hidePopup(); }); - }); - $("a#group-device-cancel-link").click(function () { - hidePopup(); + $("a#group-device-cancel-link").click(function () { + hidePopup(); + }); }); - }); + + } } diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs index f1fe2032..23eb0086 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/device-listing/public/templates/device-listing.hbs @@ -14,10 +14,10 @@

{{name}}

Device Type: {{type}} - Date of Enrollment: {{dateOfEnrolment}} + Date of Enrollment: {{enrolmentInfo.dateOfEnrolment}}
- {{owner}} + {{enrolmentInfo.owner}} {{status}}