diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs index 1a3344c14c7..b42f90ceea0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/create.hbs @@ -19,5 +19,105 @@ {{/zone}} {{#zone "content"}} - {{unit "cdmf.unit.group.create"}} +
+
+ +

Add New Group

+ +

Create new device group on IoT Server

+ + + + +
+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+{{/zone}} +{{#zone "bottomJs"}} + {{js "js/group-add.js"}} {{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.create/public/js/group-add.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js similarity index 71% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.create/public/js/group-add.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js index 9f898d701b1..1d54a59b36a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.create/public/js/group-add.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.group.create/public/js/group-add.js @@ -27,20 +27,10 @@ $(function () { $('.wr-validation-summary').removeClass("hidden"); return false; } else { - var addGroupAPI = "../api/group/add"; var group = {"name": name, "description": description}; - var postRequest = $.ajax({ - url: addGroupAPI, - method: "POST", - contentType: "application/json", - accept: "application/json", - data: JSON.stringify(group) - }); - postRequest.done(function (data, textStatus, jqxhr) { - var status = JSON.parse(jqxhr.responseText).data.statusCode; - console.log(status); - if (status == 200) { + var successCallback = function (data) { + if (data.status == 201) { $('.wr-validation-summary strong').text("Group created. You will be redirected to groups"); $('.wr-validation-summary').removeClass("hidden"); $('.wr-validation-summary strong').removeClass("label-danger"); @@ -51,16 +41,12 @@ $(function () { } else { displayErrors(status); } - }); + }; - postRequest.fail(function (jqXHR, textStatus) { - displayErrors(status); - }); - - //invokerUtil.post("/common/group_manager/group", group, - // successCallback, function (message) { - // console.log(message.content); - // }); + invokerUtil.post("/common/group_manager/groups", group, + successCallback, function (message) { + displayErrors(message.content); + }); return false; } 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 8c449f127c7..19b999c8f9c 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 @@ -33,8 +33,244 @@
- {{unit "cdmf.unit.group.listing"}} + {{#if groupCount}} +
+ + + + + + + + + + + + + + + + +
By Owner
+
+ {{else}} +
+ +
+ {{/if}} + +
+
+
+
+

Select user to manage group sharing

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

Select sharing roles

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

Group sharing updated successfully.

+
+
+
+
+ +
+
+
+
+

Do you really want to remove this group from your Group List?

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

Group was successfully removed.

+
+
+
+
+ +
+
+
+
+

Please enter new name and description for the group

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

Group was successfully updated.

+
+
+
+
+ +
+
+
+
+

Exception at backend. Try Later.

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

Operation not permitted.

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

Group does not exist.

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

Unexpected error occurred!

+ + +
+
+
+
-{{/zone}} \ No newline at end of file +{{/zone}} + +{{#zone "bottomJs"}} + + {{#if groupCount}} + {{js "js/listing.js"}} + {{/if}} +{{/zone}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.js similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/listing.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.js diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/public/images/group-icon.png b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/images/group-icon.png similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/public/images/group-icon.png rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/images/group-icon.png diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/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 similarity index 60% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/public/js/listing.js rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index 202826315e3..7b5f877d9f3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/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 @@ -87,14 +87,8 @@ function loadGroups() { var groupListingSrc = groupListing.attr("src"); var currentUser = groupListing.data("currentUser"); $.template("group-listing", groupListingSrc, function (template) { - var serviceURL = "api/group/all"; - var getGroupsRequest = $.ajax({ - url: serviceURL, - method: "GET" - }); - - getGroupsRequest.done(function (data) { + var successCallback = function (data) { data = JSON.parse(data); var viewModel = {}; viewModel.groups = data.data; @@ -112,7 +106,12 @@ function loadGroups() { $('#group-grid').datatables_extended(); $(".icon .text").res_text(0.2); - }); + }; + + invokerUtil.get("/common/group_manager/groups?start=0&rowCount=1000", + successCallback, function (message) { + displayErrors(message.content); + }); }); } @@ -199,24 +198,16 @@ function hidePopup() { * 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. - */ - $(".view-group-link").click(function () { - var groupId = $(this).data("groupid"); - window.location = "devices?groupId=" + groupId; - }); /** * Following click function would execute * when a user clicks on "Share" link - * on Group Management page in WSO2 IoT Server Console. + * on Group Management page in WSO2 Device Management Server Console. */ $("a.share-group-link").click(function () { - var groupId = $(this).data("groupid"); var username = $("#group-listing").data("current-user"); + var groupName = $(this).data("group-name"); + var groupOwner = $(this).data("group-owner"); $(modalPopupContent).html($('#share-group-w1-modal-content').html()); $('#user-names').html('
'); showPopup(); @@ -250,86 +241,7 @@ function attachEvents() { $("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('
'); - $("a#share-group-yes-link").hide(); - - var roleMappingRequest = $.ajax({ - url: "api/group/id/" + groupId + "/" + selectedUser + "/rolemapping", - method: "GET", - contentType: "application/json", - accept: "application/json" - }); - - roleMappingRequest.done(function (data, txtStatus, jqxhr) { - var roleMap = JSON.parse(data); - var status = jqxhr.status; - if (status == 200) { - roleMap = roleMap.data; - var str = ''; - var isChecked = ''; - var hasRoles; - 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]); - } - } - - var roleUpdateRequest = $.ajax({ - url: "api/group/id/" + groupId + "/" + selectedUser + "/roleupdate", - method: "POST", - contentType: "application/json", - accept: "application/json", - data: JSON.stringify(updatedRoleMap) - }); - - roleUpdateRequest.done(function (data, txtStatus, - jqxhr) { - var status = jqxhr.status; - if (status == 200) { - $(modalPopupContent).html($('#share-group-200-content').html()); - setTimeout(function () { - hidePopup(); - location.reload(false); - }, 2000); - } else { - displayErrors(status); - } - }); - - roleUpdateRequest.fail(function (jqXHR) { - displayErrors(jqXHR); - }); - }); - } else { - displayErrors(status); - } - }); - - roleMappingRequest.fail(function (jqXHR) { - displayErrors(jqXHR); - }); - - $("a#share-group-w2-cancel-link").click(function () { - hidePopup(); - }); + getAllRoles(groupName, groupOwner, selectedUser); }); } else { displayErrors(status); @@ -351,23 +263,15 @@ function attachEvents() { * on Group Management page in WSO2 IoT Server Console. */ $("a.remove-group-link").click(function () { - var groupId = $(this).data("groupid"); - var removeGroupApi = "api/group/id/" + groupId + "/remove"; + var groupName = $(this).data("group-name"); + var groupOwner = $(this).data("group-owner"); $(modalPopupContent).html($('#remove-group-modal-content').html()); showPopup(); $("a#remove-group-yes-link").click(function () { - var deleteRequest = $.ajax({ - url: removeGroupApi, - method: "DELETE", - contentType: "application/json", - accept: "application/json" - }); - - deleteRequest.done(function (data, txtStatus, jqxhr) { - var status = jqxhr.status; - if (status == 200) { + var successCallback = function (data) { + if (data.status == 200) { $(modalPopupContent).html($('#remove-group-200-content').html()); setTimeout(function () { hidePopup(); @@ -376,11 +280,12 @@ function attachEvents() { } else { displayErrors(status); } - }); + }; - deleteRequest.fail(function (jqXHR) { - displayErrors(jqXHR); - }); + invokerUtil.delete("/common/group_manager/groups/" + groupOwner + "/" + groupName, + successCallback, function (message) { + displayErrors(message.content); + }); }); $("a#remove-group-cancel-link").click(function () { @@ -395,10 +300,9 @@ function attachEvents() { * on Device Management page in WSO2 MDM Console. */ $("a.edit-group-link").click(function () { - var groupId = $(this).data("groupid"); - var groupName = $(this).data("groupname"); - var groupDescription = $(this).data("groupdescription"); - var editGroupApi = "api/group/id/" + groupId + "/update"; + var groupName = $(this).data("group-name"); + var groupOwner = $(this).data("group-owner"); + var groupDescription = $(this).data("group-description"); $(modalPopupContent).html($('#edit-group-modal-content').html()); $('#edit-group-name').val(groupName); @@ -408,19 +312,10 @@ function attachEvents() { $("a#edit-group-yes-link").click(function () { var newGroupName = $('#edit-group-name').val(); var newGroupDescription = $('#edit-group-description').val(); - var group = {"name": newGroupName, "description": newGroupDescription}; - - var groupUpdateRequest = $.ajax({ - url: editGroupApi, - method: "POST", - contentType: "application/json", - accept: "application/json", - data: JSON.stringify(group) - }); + var group = {"name": newGroupName, "description": newGroupDescription, "owner": groupOwner}; - groupUpdateRequest.done(function (data, txtStatus, jqxhr) { - var status = jqxhr.status; - if (status == 200) { + var successCallback = function (data) { + if (data.status == 200) { $(modalPopupContent).html($('#edit-group-200-content').html()); $("h4[data-groupid='" + groupId + "']").html(newGroupName); setTimeout(function () { @@ -429,11 +324,12 @@ function attachEvents() { } else { displayErrors(status); } - }); + }; - groupUpdateRequest.fail(function (jqXHR) { - displayErrors(jqXHR); - }); + invokerUtil.put("/common/group_manager/groups/" + groupOwner + "/" + groupName, + successCallback, function (message) { + displayErrors(message.content); + }); }); $("a#edit-group-cancel-link").click(function () { @@ -442,6 +338,105 @@ function attachEvents() { }); } +function getAllRoles(groupName, groupOwner, selectedUser) { + $(modalPopupContent).html($('#share-group-w2-modal-content').html()); + $('#user-roles').html('
'); + $("a#share-group-yes-link").hide(); + var successCallback = function (data) { + if (data.status == 200) { + if (data.data.length > 0) { + generateRoleMap(groupName, groupOwner, selectedUser, data.data); + } else { + $('#user-roles').html("There is no any roles for this group."); + } + } else { + displayErrors(status); + } + }; + + invokerUtil.get("/common/group_manager/groups/" + groupOwner + "/" + groupName + "/share/roles", + successCallback, function (message) { + displayErrors(message.content); + }); + + $("a#share-group-w2-cancel-link").click(function () { + hidePopup(); + }); +} + +function generateRoleMap(groupName, groupOwner, selectedUser, allRoles) { + var successCallback = function (data) { + if (data.status == 200) { + var userRoles = data.data; + var roleMap = []; + var str = ''; + var isChecked = ''; + + 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; + isChecked = 'checked'; + break; + } + } + str += '    '; + roleMap.push(objRole); + } + + $('#user-roles').html(str); + $("a#share-group-yes-link").show(); + var isOngoing; + $("a#share-group-yes-link").click(function () { + if (isOngoing) { + return false; + } + $("a#share-group-yes-link").html("Wait..."); + isOngoing = true; + 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'); + updateGroupShare(groupName, groupOwner, selectedUser, roleMap[role]); + } + } + }); + } else { + displayErrors(status); + } + }; + + invokerUtil.get("/common/group_manager/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser, + successCallback, function (message) { + displayErrors(message.content); + }); + + $("a#share-group-w2-cancel-link").click(function () { + hidePopup(); + }); +} + +function updateGroupShare(groupName, groupOwner, selectedUser, role) { + var successCallback = function (data) { + var status = data.status; + if (status == 200) { + $(modalPopupContent).html($('#share-group-200-content').html()); + setTimeout(function () { + hidePopup(); + location.reload(false); + }, 2000); + } else { + displayErrors(status); + } + }; + + invokerUtil.put("/common/group_manager/groups/" + groupOwner + "/" + groupName + "/share/roles?userName=" + selectedUser, + role, successCallback, function (message) { + displayErrors(message.content); + }); +} + function displayErrors(jqXHR) { showPopup(); if (jqXHR.status == 400) { @@ -466,4 +461,4 @@ function displayErrors(jqXHR) { }); console.log("Error code: " + jqXHR.status); } -} \ No newline at end of file +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/public/templates/listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/templates/listing.hbs similarity index 80% rename from components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/public/templates/listing.hbs rename to components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/templates/listing.hbs index b57acc8acaa..929b40be8a1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/public/templates/listing.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/templates/listing.hbs @@ -1,19 +1,19 @@ {{#each groups}} - +
+ src="public/cdmf.page.groups/images/group-icon.png"/>
-

{{name}}

+

{{name}}

{{owner}} - @@ -21,7 +21,7 @@ - @@ -31,7 +31,7 @@ + data-group-name="{{name}}" data-group-owner="{{owner}}"> @@ -40,8 +40,8 @@ + data-group-name="{{name}}" data-group-owner="{{owner}}" + data-group-description="{{description}}"> @@ -50,7 +50,7 @@ + data-group-name="{{name}}" data-group-owner="{{owner}}"> diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.create/create.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.create/create.hbs deleted file mode 100644 index 119fa7baae1..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.create/create.hbs +++ /dev/null @@ -1,101 +0,0 @@ -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- -{{#zone "bottomJs"}} - {{js "js/group-add.js"}} -{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.create/create.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.create/create.json deleted file mode 100644 index 688e939808b..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.create/create.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "version": "1.0.0" -} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/listing.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/listing.hbs deleted file mode 100644 index 297c3b1734b..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/listing.hbs +++ /dev/null @@ -1,240 +0,0 @@ -{{#if groupCount}} -
- - - - - - - - - - - - - - - - - -
By Owner
- -
-{{else}} -
-
-

You don't have any group registered at the moment.

-
- {{#if permissions.ADD_GROUP}} -

- - - - - - Add New Group - -

- {{/if}} -
-
-{{/if}} - -
-
-
-
-

Select user to manage group sharing

-
Loading...
- -
-
-
-
- -
-
-
-
-

Select sharing roles

-
-
Loading...
- -
-
-
-
- -
-
-
-
-

Group sharing updated successfully.

-
-
-
-
- -
-
-
-
-

Do you really want to remove this group from your Group List?

- - -
-
-
-
- -
-
-
-
-

Group was successfully removed.

-
-
-
-
- -
-
-
-
-

Please enter new name and description for the group

-
- -
- -
-
- -
- -
- -
-
-
-
- -
-
-
-
-

Group was successfully updated.

-
-
-
-
- -
-
-
-
-

Exception at backend. Try Later.

- - -
-
-
-
- -
-
-
-
-

Operation not permitted.

- - -
-
-
-
- -
-
-
-
-

Group does not exist.

- - -
-
-
-
- -
-
-
-
-

Unexpected error occurred!

- - -
-
-
-
- - -{{#zone "bottomJs"}} - - {{#if groupCount}} - {{js "js/listing.js"}} - {{/if}} -{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/listing.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/listing.json deleted file mode 100644 index 36e949136e0..00000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.group.listing/listing.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "version": "1.0.0", - "index": 30 -} \ No newline at end of file