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 6014b482..de7e65f6 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/group-api.jag @@ -112,7 +112,7 @@ if (uriMatcher.match("/{context}/api/group/add")) { data = {"username": user.username, "shareUser":shareUser, "role":role}; result = post(endPoint, data, "json"); -} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/share")) { +} else if (uriMatcher.match("/{context}/api/group/id/{groupId}/unshare")) { groupId = uriMatcher.elements().groupId; var unShareUser = request.getContent()["unShareUser"]; @@ -197,6 +197,6 @@ if (uriMatcher.match("/{context}/api/group/add")) { // returning the result. if (result) { response.status = result.xhr.status; - print(false); + print(result.data); } %> diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag b/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag index 1bf40351..637c3fdd 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/api/user-api.jag @@ -135,6 +135,8 @@ if (uriMatcher.match("/{context}/api/user/login/")) { result = 403; } +} else if (uriMatcher.match("/{context}/api/users")) { + result = userModule.getUsers(); } // returning the result. diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js index 75683235..175031a0 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/modules/utility.js @@ -119,6 +119,10 @@ utility = function () { key: "groups/operation", name: "Perform Device Operation" }], "device-mgt/user", type); + userModule.addPermissions([{ + key: "groups/list", + name: "List Groups of User" + }], "device-mgt/user", type); }; return publicMethods; diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.hbs index 4031ac65..c15cf4f9 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.hbs @@ -1,13 +1,8 @@ {{#zone "main"}} -
+
@@ -16,7 +11,7 @@
- {{unit "operation-bar"}} + {{unit "operation-bar"}}
@@ -25,13 +20,21 @@
- +
+
+
+
Description
{{group.description}} +
+
+
No. of Devices: {{group.deviceCount}}
Users: {{group.users}}
-
Created on:
{{group.dateOfCreation}}
-
Modified on:
{{group.dateOfLastUpdate}}
+
Created on: {{group.dateOfCreation}}
+
Modified on: {{group.dateOfLastUpdate}}
@@ -42,51 +45,6 @@
- {{#if group.viewModel.BatteryLevel}} -
-
-
BATTERY
-
-
-
{{group.viewModel.BatteryLevel}}%
-
-
-
- {{/if}} - - {{#if group.viewModel.DeviceCapacity}} -
-
-
STORAGE
-
-
-
{{group.viewModel.DeviceCapacityPercentage}}%{{group.viewModel.DeviceCapacityUsed}} GB Free
-
-
-
- {{/if}} - {{#if group.viewModel.internal_memory.FreeCapacity}} -
-
-
LOCAL STORAGE
-
-
-
{{group.viewModel.internal_memory.DeviceCapacityPercentage}}%{{group.viewModel.internal_memory.FreeCapacity}} GB Free
-
-
-
- {{/if}} - {{#if group.viewModel.external_memory.FreeCapacity}} -
-
-
EXTERNAL STORAGE
-
-
-
{{group.viewModel.external_memory.DeviceCapacityPercentage}}%{{group.viewModel.external_memory.FreeCapacity}} GB Free
-
-
-
- {{/if}}
@@ -98,7 +56,8 @@
- - +
-
+
- Not available yet + Show Devices + in Group
- - - - - - - - - - - - - - - - - - - - - - -
@@ -171,6 +112,5 @@ {{/zone}} {{#zone "bottomJs"}} - {{/zone}} \ No newline at end of file diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.js index 9b3738ee..6781cd38 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.js +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-detail/group-detail.js @@ -5,19 +5,15 @@ function onRequest(context) { var uriMatcher = new URIMatcher(String(uri)); var isMatched = uriMatcher.match("/{context}/group/{groupId}"); if (isMatched) { - var carbon = require('carbon'); - var carbonHttpsServletTransport = carbon.server.address('https'); - - var matchedElements = uriMatcher.elements(); - var groupId = matchedElements.groupId; - var endpoint = carbonHttpsServletTransport + "/" + matchedElements.context + "/api/group/id/" + groupId; - log.info(endpoint); - //var result = get(endpoint, {}, "json"); - //if (result){ - // context.group = result.data; - //}else{ - // response.sendError(503); - //} + var group = {}; + group.id = uriMatcher.elements().groupId; + group.name = request.getParameter("name"); + group.deviceCount = request.getParameter("deviceCount"); + group.dateOfCreation = request.getParameter("dateOfCreation"); + group.dateOfLastUpdate = request.getParameter("dateOfLastUpdate"); + group.description = request.getParameter("description"); + group.users = request.getParameter("users"); + context.group =group; } else { response.sendError(404); } 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 54bcd732..8b091435 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 @@ -30,6 +30,38 @@
+
+
+
+
+

Share group with others

+ + +
+
+
+
+ +
+
+
+
+

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 96820097..6906a242 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,12 +1,17 @@ function onRequest(context){ - //var userModule = require("/modules/user.js").userModule; var permissions = []; - //if(userModule.isAuthorized("/permission/device-mgt/admin/devices/list")){ + //var userModule = require("/modules/user.js").userModule; + //if(userModule.isAuthorized("/permission/device-mgt/admin/groups/list")){ // permissions.push("LIST_GROUPS"); - //}else if(userModule.isAuthorized("/permission/device-mgt/user/devices/list")){ - // permissions.push("LIST_OWN_GROUPS"); + //}else if(userModule.isAuthorized("/permission/device-mgt/groups/remove")){ + // permissions.push("REMOVE_GROUPS"); + //}else if(userModule.isAuthorized("/permission/device-mgt/groups/share")){ + // permissions.push("SHARE_GROUPS"); //} permissions.push("LIST_GROUPS"); + permissions.push("ADD_GROUPS"); + permissions.push("SHARE_GROUPS"); context.permissions = stringify(permissions); + context.SHARE_GROUPS = true; 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 d6e7ba65..70414fd8 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 @@ -245,11 +245,11 @@ function attachGroupAdding() { var status = jqxhr.status; if (status == 200) { if (data != "false") { - $(modalPopupContent).html($('#add-group-200-content').html()); - $("a#add-group-200-link").click(function () { - hidePopup(); - location.reload(); - }); + $(modalPopupContent).html($('#add-group-200-content').html()); + $("a#add-group-200-link").click(function () { + hidePopup(); + location.reload(); + }); } else { $(modalPopupContent).html($('#group-400-content').html()); $("a#group-400-link").click(function () { @@ -293,6 +293,83 @@ function attachGroupAdding() { * Following functions should be triggered after AJAX request is made. */ function attachEvents() { + /** + * Following click function would execute + * when a user clicks on "Share" link + * on Group Management page in WSO2 IoT Server Console. + */ + $("a.view-group-link").click(function () { + $("#group_data").closest('form').submit(); + }); + + /** + * Following click function would execute + * when a user clicks on "Share" link + * on Group Management page in WSO2 IoT Server Console. + */ + $("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()); + 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); + } + }, + function () { + $(modalPopupContent).html($('#group-unexpected-error-content').html()); + $("a#group-unexpected-error-link").click(function () { + hidePopup(); + }); + } + ); + }); + + $("a#share-group-unshare-link").click(function () { + var data = {"shareUser":"", "role":""}; + invokerUtil.post( + unShareGroupApi, + data, + function (data, txtStatus, jqxhr) { + var status = jqxhr.status; + if (status == 200) { + + } else { + displayErrors(status); + } + }, + function () { + $(modalPopupContent).html($('#group-unexpected-error-content').html()); + $("a#group-unexpected-error-link").click(function () { + hidePopup(); + }); + } + ); + }); + + $("a#share-group-yes-link").click(function () { + hidePopup(); + location.reload(); + }); + + $("a#share-group-cancel-link").click(function () { + hidePopup(); + }); + + }); + /** * Following click function would execute * when a user clicks on "Remove" link @@ -324,26 +401,13 @@ function attachEvents() { hidePopup(); }); } - } else if (status == 400) { - $(modalPopupContent).html($('#group-400-content').html()); - $("a#remove-group-400-link").click(function () { - hidePopup(); - }); - } else if (status == 403) { - $(modalPopupContent).html($('#group-403-content').html()); - $("a#remove-group-403-link").click(function () { - hidePopup(); - }); - } else if (status == 409) { - $(modalPopupContent).html($('#group-409-content').html()); - $("a#remove-group-409-link").click(function () { - hidePopup(); - }); + } else { + displayErrors(status); } }, function () { $(modalPopupContent).html($('#group-unexpected-error-content').html()); - $("a#remove-group-unexpected-error-link").click(function () { + $("a#group-unexpected-error-link").click(function () { hidePopup(); }); } @@ -387,7 +451,6 @@ function attachEvents() { $("div[data-groupid='" + groupId + "'] .ast-name").html(newGroupName); $("a#edit-group-200-link").click(function () { hidePopup(); - location.reload(); }); } else { $(modalPopupContent).html($('#group-409-content').html()); @@ -395,21 +458,8 @@ function attachEvents() { hidePopup(); }); } - } else if (status == 400) { - $(modalPopupContent).html($('#group-400-content').html()); - $("a#group-400-link").click(function () { - hidePopup(); - }); - } else if (status == 403) { - $(modalPopupContent).html($('#group-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(); - }); + } else { + displayErrors(status); } }, function () { @@ -426,3 +476,22 @@ function attachEvents() { }); }); } + +function displayErrors(status){ + if (status == 400) { + $(modalPopupContent).html($('#group-400-content').html()); + $("a#group-400-link").click(function () { + hidePopup(); + }); + } else if (status == 403) { + $(modalPopupContent).html($('#group-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(); + }); + } +} diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs index 14080028..844645b9 100644 --- a/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs +++ b/modules/distribution/src/repository/jaggeryapps/iotserver/units/group-listing/public/templates/group-listing.hbs @@ -1,5 +1,14 @@ {{#each groups}} - {{groupMap this}} + {{groupMap this}} +
+ + + + + + +
+
- -
-
diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/select2/public/css/select2.min.css b/modules/distribution/src/repository/jaggeryapps/iotserver/units/select2/public/css/select2.min.css old mode 100755 new mode 100644 diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/select2/public/js/select2.full.min.js b/modules/distribution/src/repository/jaggeryapps/iotserver/units/select2/public/js/select2.full.min.js old mode 100755 new mode 100644 diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/select2/select2.hbs b/modules/distribution/src/repository/jaggeryapps/iotserver/units/select2/select2.hbs old mode 100755 new mode 100644 diff --git a/modules/distribution/src/repository/jaggeryapps/iotserver/units/select2/select2.json b/modules/distribution/src/repository/jaggeryapps/iotserver/units/select2/select2.json old mode 100755 new mode 100644