From 03f965adf62a7cbb6c5215af44f52da613990470 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Fri, 25 Nov 2016 11:18:17 +0530 Subject: [PATCH] Decrease group listing page loading time with lazy roles listing --- .../app/pages/cdmf.page.groups/groups.hbs | 13 +------ .../app/pages/cdmf.page.groups/groups.js | 4 -- .../cdmf.page.groups/public/js/listing.js | 37 ++++++++++++++++++- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs index ad4c096949..d77f18dc7a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs @@ -117,18 +117,7 @@

Select user roles to manage group sharing

-
-
- {{#each userRoles}} -
- -
- {{/each}} +

diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.js index f432193231..0c04f9bb2d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.js @@ -23,10 +23,6 @@ function onRequest(context) { var groupPermissions = require("/app/pages/cdmf.page.groups/public/group-permissions.json"); var currentUser = session.get(constants.USER_SESSION_KEY); var page = {}; - var rolesResult = userModule.getRoles(); - if (rolesResult.status == "success") { - page.userRoles = rolesResult.content; - } if (currentUser) { page.permissions = userModule.getUIPermissions(); page.permissions.list = stringify(page.permissions); 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 1548ff4c71..04f044e11a 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 @@ -372,7 +372,7 @@ function attachEvents() { $(modalPopupContent).html($('#share-group-w1-modal-content').html()); showPopup(); - markAlreadySavedUsersRoles(groupId); + listAllRoles(groupId); var shareGroupNextLink = $("a#share-group-next-link"); shareGroupNextLink.click(function () { var roles = []; @@ -512,6 +512,41 @@ function markAlreadySavedUsersRoles(groupId) { }); } +function listAllRoles(groupId) { + var successCallback = function (data, textStatus, xhr) { + data = JSON.parse(data); + if (xhr.status == 200) { + if (data.roles.length > 0) { + var html = "
"; + for (var i = 0; i < data.roles.length; i++) { + html += '
'; + $('.roleCheckBoxes').each( + function () { + if (data.roles[i] == $(this).data('role-name')) { + $(this).attr('checked', true); + } + } + ); + } + $("#rolesListing").html(html); + markAlreadySavedUsersRoles(groupId); + } else { + $("#rolesListing").html("No roles available"); + } + } else { + displayErrors(xhr); + } + }; + + invokerUtil.get("/api/device-mgt/v1.0/roles?offset=0&limit=100&user-store=all", + successCallback, function (message) { + displayErrors(message); + }); +} + function addNewRole(roles) { $(modalPopupContent).html($('#share-group-w3-modal-content').html()); $("a#share-group-w3-yes-link").click(function () {