From f6f99ed06a5f69909599eb0e22851629c1396724 Mon Sep 17 00:00:00 2001 From: charitha Date: Wed, 4 Jan 2017 15:09:36 +0530 Subject: [PATCH] Fixed following issues: https://wso2.org/jira/browse/IOTS-271 --- .../app/modules/business-controllers/group.js | 29 ++++++ .../pages/cdmf.page.dashboard/dashboard.hbs | 2 +- .../app/pages/cdmf.page.devices/devices.hbs | 83 +++++++++++++--- .../app/pages/cdmf.page.devices/devices.js | 15 +-- .../cdmf.page.devices/public/js/listing.js | 27 ++++-- .../cdmf.page.group.analytics/analytics.hbs | 2 +- .../cdmf.page.group.analytics/analytics.js | 7 +- .../cdmf.page.group.analytics/analytics.json | 2 +- .../cdmf.page.groups/public/js/listing.js | 96 ++++++++++++------- 9 files changed, 192 insertions(+), 71 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js index fefd73bd0b..de20da586d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/group.js @@ -105,4 +105,33 @@ var groupModule = {}; ); }; + groupModule.getGroup = function (groupId) { + return serviceInvokers.XMLHttp.get( + deviceServiceEndpoint + "/groups/id/" + groupId, function (responsePayload) { + return JSON.parse(responsePayload.responseText); + }, + function (responsePayload) { + log.error(responsePayload); + return -1; + } + ); + }; + + groupModule.getRolesOfGroup = function (groupId) { + return serviceInvokers.XMLHttp.get( + deviceServiceEndpoint + "/groups/id/" + groupId + "/roles", function (responsePayload) { + var data = JSON.parse(responsePayload.responseText); + if(data) { + return data.roles; + } else { + return []; + } + }, + function (responsePayload) { + log.error(responsePayload); + return -1; + } + ); + }; + }(groupModule)); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs index 6b466d90a3..a294732b26 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.hbs @@ -171,7 +171,7 @@ {{/if}} - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs index 863c85842f..8a32659700 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs @@ -26,7 +26,7 @@ - {{#if groupName}} + {{#if group}}
  • Groups @@ -34,7 +34,7 @@
  • - {{groupName}} + {{group.name}}
  • {{else}} @@ -47,7 +47,7 @@ {{/zone}} {{#zone "navbarActions"}} - {{#if groupName}} + {{#if group}}
  • @@ -57,6 +57,15 @@ Assign from My Devices
  • +
  • + + + + + + View Analytics + +
  • {{else}} {{#if permissions.enroll}}
  • @@ -73,6 +82,55 @@ {{/zone}} {{#zone "content"}} + {{#if group}} +

    + {{group.name}} group +

    +
    +
    +
    +
    +
    + +
    +
    +
    +
    + Overview +
    + + + + + + + + + + + + + + + + + + + +
    Owner{{group.owner}}
    Shared with roles + {{#each roles}} + {{this}}
    + {{/each}} +
    Device Count{{deviceCount}}
    Description{{group.description}}
    +
    +
    +
    +
    +
    +

    + Devices in {{group.name}} group +

    + {{/if}}
    @@ -82,7 +140,6 @@ {{#if deviceCount}}
    - Loading devices . . .
    @@ -157,7 +214,7 @@

    You don't have any device - {{#if groupName}} + {{#if group}} assigned to this group {{else}} enrolled @@ -165,7 +222,7 @@ at the moment.

    - {{#if groupName}} + {{#if group}} @@ -208,20 +265,16 @@ -
    -

    - Please select group -
    -
    Loading...
    -

    -
    +
    Loading...

  • - + {{groupName}}
  • diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js index 19f783ed56..6a34a26b0c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.js @@ -19,8 +19,8 @@ function onRequest(context) { var utility = require("/app/modules/utility.js").utility; var groupModule = require("/app/modules/business-controllers/group.js")["groupModule"]; - var groupName = context.uriParams.name; var groupId = context.uriParams.id; + var group = groupModule.getGroup(groupId); var devices = []; var deviceResponse = groupModule.getGroupDevices(groupId).responseText; @@ -29,8 +29,9 @@ function onRequest(context) { devices = deviceResponseObj.devices; } var page = { - "groupName": groupName, - "title": groupName + " Analytics" + "groupId": groupId, + "groupName": group.name, + "title": group.name + " Analytics" }; if (devices) { var deviceTypes = []; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.json index 2e2fea333e..8535dab982 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.analytics/analytics.json @@ -1,5 +1,5 @@ { "version": "1.0.0", - "uri": "/group/{name}/{id}/analytics", + "uri": "/group/{id}/analytics", "layout": "cdmf.layout.default" } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index 4597a71297..6661e775b4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js @@ -16,18 +16,41 @@ * under the License. */ +/** + * Following function would execute + * when a user clicks on the list item + * initial mode and with out select mode. + */ +function InitiateViewOption(url) { + if ($(".select-enable-btn").text() == "Select") { + $(location).attr('href', url); + } +} + +(function () { + var cache = {}; + var validateAndReturn = function (value) { + return (value == undefined || value == null) ? "Unspecified" : value; + }; + Handlebars.registerHelper("deviceMap", function (device) { + device.owner = validateAndReturn(device.owner); + device.ownership = validateAndReturn(device.ownership); + var arr = device.properties; + if (arr) { + device.properties = arr.reduce(function (total, current) { + total[current.name] = validateAndReturn(current.value); + return total; + }, {}); + } + }); +})(); + /* * Setting-up global variables. */ var groupCheckbox = "#ast-container .ctrl-wr-asset .itm-select input[type='checkbox']"; var assetContainer = "#ast-container"; -function InitiateViewOption() { - if ($(".select-enable-btn").text() == "Select") { - $(location).attr('href', $(this).data("url")); - } -} - /* * On Select All Groups button click function. * @@ -118,9 +141,9 @@ function loadGroups() { }); var json = { "recordsTotal": data.count, + "recordsFiltered": data.count, "data": objects - } - + }; return JSON.stringify(json); }; @@ -129,7 +152,14 @@ function loadGroups() { data: 'id', class: 'remove-padding icon-only content-fill', render: function (data, type, row, meta) { - return '
    '; + if ($.hasPermission("VIEW_GROUP_DEVICES")) { + return '
    '; + } else { + return '
    '; + } } }, { @@ -154,13 +184,7 @@ function loadGroups() { render: function (id, type, row, meta) { var html = ''; if ($.hasPermission("VIEW_GROUP_DEVICES")) { - html = '' + - '' - + - ''; - - html += '' + '' + @@ -224,21 +248,23 @@ function loadGroups() { }); }; - $('#group-grid').datatables_extended_serverside_paging( - null, - serviceURL, - dataFilter, - columns, - fnCreatedRow, - function (oSettings) { - $(".icon .text").res_text(0.2); - attachEvents(); - }, - { - "placeholder": "Search By Group Name", - "searchKey": "name" - }); + null, + serviceURL, + dataFilter, + columns, + fnCreatedRow, + function (oSettings) { + $(".icon .text").res_text(0.2); + attachEvents(); + var thisTable = $(this).closest('.dataTables_wrapper').find('.dataTable').dataTable(); + thisTable.removeClass("table-selectable"); + }, + { + "placeholder": "Search By Group Name", + "searchKey": "name" + } + ); $(groupCheckbox).click(function () { addGroupSelectedClass(this); }); @@ -257,6 +283,11 @@ function openCollapsedNav() { * DOM ready functions. */ $(document).ready(function () { + /* Adding selected class for selected devices */ + $(groupCheckbox).each(function () { + addGroupSelectedClass(this); + }); + var permissionSet = {}; //This method is used to setup permission for device listing @@ -278,11 +309,6 @@ $(document).ready(function () { loadGroups(); //$('#device-grid').datatables_extended(); - /* Adding selected class for selected devices */ - $(groupCheckbox).each(function () { - addGroupSelectedClass(this); - }); - /* for device list sorting drop down */ $(".ctrl-filter-type-switcher").popover( {