diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag index de7e65f6..924a53d6 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag @@ -109,7 +109,7 @@ if (uriMatcher.match("/{context}/api/group/add")) { //URL: PUT https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share endPoint = deviceCloudService + "/group/id/" + groupId + "/share"; - data = {"username": user.username, "shareUser":shareUser, "role":role}; + data = {"username": user.username, "shareUser": shareUser, "role": role}; result = post(endPoint, data, "json"); } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/unshare")) { @@ -118,10 +118,10 @@ if (uriMatcher.match("/{context}/api/group/add")) { var unShareUser = request.getContent()["unShareUser"]; role = request.getContent()["role"]; - //URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share - endPoint = deviceCloudService + "/group/id/" + groupId + "/share"; - data = {"username": user.username, "unShareUser":unShareUser, "role":role}; - result = del(endPoint, data, "json"); + //URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/unshare + endPoint = deviceCloudService + "/group/id/" + groupId + "/unshare"; + data = {"username": user.username, "unShareUser": unShareUser, "role": role}; + result = post(endPoint, data, "json"); } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/add")) { @@ -131,7 +131,7 @@ if (uriMatcher.match("/{context}/api/group/add")) { //URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role endPoint = deviceCloudService + "/group/id/" + groupId + "/role"; - data = {"username": user.username, "permissions":permissions, "role":role}; + data = {"username": user.username, "permissions": permissions, "role": role}; result = post(endPoint, data, "json"); } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/delete")) { @@ -141,7 +141,7 @@ if (uriMatcher.match("/{context}/api/group/add")) { //URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role endPoint = deviceCloudService + "/group/id/" + groupId + "/role"; - data = {"username": user.username, "role":role}; + data = {"username": user.username, "role": role}; result = del(endPoint, data, "json"); } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/role/all")) { @@ -159,10 +159,60 @@ if (uriMatcher.match("/{context}/api/group/add")) { var userId = uriMatcher.elements().userId; //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/{user}/role/all - endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId +"/role/all"; + endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId + "/role/all"; data = {"username": user.username}; result = get(endPoint, data, "json"); +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/rolemapping")) { + + groupId = uriMatcher.elements().groupId; + userId = uriMatcher.elements().userId; + + data = {"username": user.username}; + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/role/all + endPoint = deviceCloudService + "/group/id/" + groupId + "/role/all"; + var allRoles = get(endPoint, data, "json").data; + + //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/{user}/role/all + endPoint = deviceCloudService + "/group/id/" + groupId + "/" + userId + "/role/all"; + var userRolesObj = get(endPoint, data, "json"); + var userRoles = userRolesObj.data; + var roleMap = []; + for (var role in allRoles) { + var objRole = {"role": allRoles[role], "assigned": false}; + for (var usrRole in userRoles) { + if (allRoles[role] == userRoles[usrRole]) { + objRole.assigned = true; + break; + } + } + roleMap.push(objRole); + } + result = {}; + result.data = roleMap; + result.xhr = userRolesObj.xhr; + +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/{userId}/roleupdate")) { + + groupId = uriMatcher.elements().groupId; + userId = uriMatcher.elements().userId; + roleMap = request.getContent(); + + for (role in roleMap) { + if (roleMap[role].assigned == true) { + //URL: POST https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/share + endPoint = deviceCloudService + "/group/id/" + groupId + "/share"; + data = {"username": user.username, "shareUser": userId, "role": roleMap[role].role}; + result = post(endPoint, data, "json"); + } else { + //URL: DELETE https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/unshare + endPoint = deviceCloudService + "/group/id/" + groupId + "/unshare"; + data = {"username": user.username, "unShareUser": userId, "role": roleMap[role].role}; + result = post(endPoint, data, "json"); + } + } + } else if (uriMatcher.match("/{context}/api/group/id/{groupId}/user/all")) { groupId = uriMatcher.elements().groupId; @@ -189,7 +239,7 @@ if (uriMatcher.match("/{context}/api/group/add")) { //URL: GET https://localhost:9443/devicecloud/group_manager/group/id/{groupId}/device/assign endPoint = deviceCloudService + "/group/id/" + groupId + "/device/assign"; - data = {"username": user.username, "deviceId":deviceId, "deviceType":deviceType}; + data = {"username": user.username, "deviceId": deviceId, "deviceType": deviceType}; result = put(endPoint, data, "json"); } diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs index 8b091435..e4fe30c4 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.hbs @@ -1,5 +1,6 @@ {{#zone "main"}} +
@@ -30,13 +31,38 @@
-
+
-

Share group with others

+

Select user to manage group sharing

+
Loading...
+ +
+
+
+
+
+
+
+
+

Select sharing roles

+
+
Loading...
+ +     Cancel     + +        OK     @@ -53,7 +79,7 @@

Group sharing updated successfully.

diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js index 6906a242..fc048f66 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/group-listing.js @@ -1,4 +1,7 @@ +var log = new Log("modules/group-listing.js"); + function onRequest(context){ + var constants = require("/modules/constants.js"); var permissions = []; //var userModule = require("/modules/user.js").userModule; //if(userModule.isAuthorized("/permission/device-mgt/admin/groups/list")){ @@ -13,5 +16,6 @@ function onRequest(context){ permissions.push("SHARE_GROUPS"); context.permissions = stringify(permissions); context.SHARE_GROUPS = true; + context.user = session.get(constants.USER_SESSION_KEY); return context; } \ No newline at end of file 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 70414fd8..d46d9bd0 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 @@ -223,6 +223,13 @@ function hidePopup() { $(modalPopup).hide(); } +var errorHandler = function () { + $(modalPopupContent).html($('#add-group-unexpected-error-content').html()); + $("a#group-unexpected-error-link").click(function () { + hidePopup(); + }); +}; + function attachGroupAdding() { /** * Following click function would execute @@ -272,13 +279,7 @@ function attachGroupAdding() { hidePopup(); }); } - }, - function () { - $(modalPopupContent).html($('#add-group-unexpected-error-content').html()); - $("a#group-unexpected-error-link").click(function () { - hidePopup(); - }); - } + }, errorHandler ); }); @@ -309,62 +310,94 @@ function attachEvents() { */ $("a.share-group-link").click(function () { var groupId = $(this).data("groupid"); - var shareGroupApi = "/iotserver/api/group/id/" + groupId + "/share"; - var unShareGroupApi = "/iotserver/api/group/id/" + groupId + "/unshare"; - - $(modalPopupContent).html($('#share-group-modal-content').html()); + var username = $("#user-details").data("username"); + $(modalPopupContent).html($('#share-group-w1-modal-content').html()); + $('#user-names').html('Loading...'); showPopup(); - - $("a#share-group-share-link").click(function () { - var data = {"shareUser":"", "role":""}; - invokerUtil.post( - shareGroupApi, - data, - function (data, txtStatus, jqxhr) { - var status = jqxhr.status; - if (status == 200) { - - } else { - displayErrors(status); + $("a#share-group-next-link").hide(); + invokerUtil.get("/iotserver/api/users", + function (data, txtStatus, jqxhr) { + var users = JSON.parse(data); + var status = jqxhr.status; + if (status == 200) { + var str = '
'; + if (!hasUsers) { + str = "There is no any other users registered"; + return; } - }, - function () { - $(modalPopupContent).html($('#group-unexpected-error-content').html()); - $("a#group-unexpected-error-link").click(function () { - hidePopup(); + $('#user-names').html(str); + $("a#share-group-next-link").show(); + $("a#share-group-next-link").click(function () { + var selectedUser = $('#share-user-selector').val(); + $(modalPopupContent).html($('#share-group-w2-modal-content').html()); + $('#user-roles').html('Loading...'); + $("a#share-group-yes-link").hide(); + invokerUtil.get("/iotserver/api/group/id/" + groupId + "/" + selectedUser + "/rolemapping", + function (data, txtStatus, jqxhr) { + var roleMap = JSON.parse(data); + var status = jqxhr.status; + if (status == 200) { + var str = ''; + var isChecked = ''; + var hasRoles = false; + for (var role in roleMap) { + if (roleMap[role].assigned == true) { + isChecked = 'checked'; + } + str += '    '; + hasRoles = true; + } + if (!hasRoles) { + str = "There is no any roles for this group"; + return; + } + $('#user-roles').html(str); + $("a#share-group-yes-link").show(); + $("a#share-group-yes-link").click(function () { + var updatedRoleMap = []; + for (var role in roleMap) { + if ($('#user-role-' + roleMap[role].role).is(':checked') != roleMap[role].assigned){ + roleMap[role].assigned = $('#user-role-' + roleMap[role].role).is(':checked'); + updatedRoleMap.push(roleMap[role]); + } + } + invokerUtil.post("/iotserver/api/group/id/" + groupId + "/" + selectedUser + "/roleupdate", + updatedRoleMap, + function (data, txtStatus, jqxhr) { + var status = jqxhr.status; + if (status == 200) { + $(modalPopupContent).html($('#share-group-200-content').html()); + $("a#share-group-200-link").click(function () { + hidePopup(); + }); + }else { + displayErrors(status); + } + }, errorHandler); + }); + } else { + displayErrors(status); + } + }, errorHandler); + $("a#share-group-w2-cancel-link").click(function () { + hidePopup(); + }); }); + } else { + displayErrors(status); } - ); - }); - - $("a#share-group-yes-link").click(function () { - hidePopup(); - location.reload(); - }); + }, errorHandler); - $("a#share-group-cancel-link").click(function () { + $("a#share-group-w1-cancel-link").click(function () { hidePopup(); }); @@ -477,7 +510,7 @@ function attachEvents() { }); } -function displayErrors(status){ +function displayErrors(status) { if (status == 400) { $(modalPopupContent).html($('#group-400-content').html()); $("a#group-400-link").click(function () { diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/main.css b/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/main.css index 23f3461e..b6f92077 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/main.css +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/theme/public/css/main.css @@ -611,4 +611,23 @@ header{background-color: #2a2a2a;} } :-ms-input-placeholder { /* Internet Explorer 10+ */ color: #b2b2b2; +} + +input[type=checkbox] { + width: 13px; + height: 13px; + padding: 0; + margin:0; + vertical-align: bottom; + position: relative; + top: -1px; + *overflow: hidden; +} + +.checkbox-text +{ + /* Checkbox text */ + display: inline; + padding-left: 15px; + text-indent: -15px; } \ No newline at end of file