diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/GroupResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/GroupResource.java index 778ba2e6..e0cf17b1 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/GroupResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/GroupResource.java @@ -21,7 +21,9 @@ import com.google.common.base.Strings; import com.sismics.docs.core.dao.jpa.GroupDao; import com.sismics.docs.core.dao.jpa.UserDao; import com.sismics.docs.core.dao.jpa.criteria.GroupCriteria; +import com.sismics.docs.core.dao.jpa.criteria.UserCriteria; import com.sismics.docs.core.dao.jpa.dto.GroupDto; +import com.sismics.docs.core.dao.jpa.dto.UserDto; import com.sismics.docs.core.model.jpa.Group; import com.sismics.docs.core.model.jpa.User; import com.sismics.docs.core.model.jpa.UserGroup; @@ -327,7 +329,14 @@ public class GroupResource extends BaseResource { response.add("parent", parentGroup.getName()); } - // TODO Add members + // Members + JsonArrayBuilder members = Json.createArrayBuilder(); + UserDao userDao = new UserDao(); + List userDtoList = userDao.findByCriteria(new UserCriteria().setGroupId(group.getId()), new SortCriteria(1, true)); + for (UserDto userDto : userDtoList) { + members.add(userDto.getUsername()); + } + response.add("members", members); return Response.ok().entity(response.build()).build(); } diff --git a/docs-web/src/main/webapp/src/app/docs/controller/SettingsGroupEdit.js b/docs-web/src/main/webapp/src/app/docs/controller/SettingsGroupEdit.js index 3bb2f7f2..d63bba42 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/SettingsGroupEdit.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/SettingsGroupEdit.js @@ -51,7 +51,7 @@ angular.module('docs').controller('SettingsGroupEdit', function($scope, $dialog, /** * Delete the current group. */ - $scope.remove = function () { + $scope.remove = function() { var title = 'Delete group'; var msg = 'Do you really want to delete this group?'; var btns = [{result:'cancel', label: 'Cancel'}, {result:'ok', label: 'OK', cssClass: 'btn-primary'}]; @@ -61,7 +61,7 @@ angular.module('docs').controller('SettingsGroupEdit', function($scope, $dialog, Restangular.one('group', $stateParams.name).remove().then(function() { $scope.loadGroups(); $state.go('settings.group'); - }, function () { + }, function() { $state.go('settings.group'); }); } @@ -84,4 +84,43 @@ angular.module('docs').controller('SettingsGroupEdit', function($scope, $dialog, }); return deferred.promise; }; + + /** + * Returns a promise for typeahead user. + */ + $scope.getUserTypeahead = function($viewValue) { + var deferred = $q.defer(); + Restangular.one('user') + .getList('list', { + search: $viewValue, + sort_column: 1, + asc: true + }).then(function(data) { + deferred.resolve(_.pluck(data.users, 'username')); + }); + return deferred.promise; + }; + + /** + * Add a new member. + */ + $scope.addMember = function(member) { + $scope.member = ''; + Restangular.one('group/' + $stateParams.name).put({ + username: member + }).then(function() { + if ($scope.group.members.indexOf(member) === -1) { + $scope.group.members.push(member); + } + }); + }; + + /** + * Remove a member. + */ + $scope.removeMember = function(member) { + Restangular.one('group/' + $stateParams.name, member).remove().then(function() { + $scope.group.members.splice($scope.group.members.indexOf(member), 1); + }); + }; }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/app/docs/controller/SettingsUser.js b/docs-web/src/main/webapp/src/app/docs/controller/SettingsUser.js index 4ad78169..de06b121 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/SettingsUser.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/SettingsUser.js @@ -8,7 +8,10 @@ angular.module('docs').controller('SettingsUser', function($scope, $state, Resta * Load users from server. */ $scope.loadUsers = function() { - Restangular.one('user/list').get().then(function(data) { + Restangular.one('user/list').get({ + sort_column: 1, + asc: true + }).then(function(data) { $scope.users = data.users; }); }; diff --git a/docs-web/src/main/webapp/src/app/docs/controller/SettingsUserEdit.js b/docs-web/src/main/webapp/src/app/docs/controller/SettingsUserEdit.js index 44b93ea6..599001ee 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/SettingsUserEdit.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/SettingsUserEdit.js @@ -48,7 +48,7 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog, /** * Delete the current user. */ - $scope.remove = function () { + $scope.remove = function() { var title = 'Delete user'; var msg = 'Do you really want to delete this user? All associated documents, files and tags will be deleted'; var btns = [{result:'cancel', label: 'Cancel'}, {result:'ok', label: 'OK', cssClass: 'btn-primary'}]; @@ -58,7 +58,7 @@ angular.module('docs').controller('SettingsUserEdit', function($scope, $dialog, Restangular.one('user', $stateParams.username).remove().then(function() { $scope.loadUsers(); $state.go('settings.user'); - }, function () { + }, function() { $state.go('settings.user'); }); } diff --git a/docs-web/src/main/webapp/src/app/docs/controller/User.js b/docs-web/src/main/webapp/src/app/docs/controller/User.js index 77bec639..bf5420a9 100644 --- a/docs-web/src/main/webapp/src/app/docs/controller/User.js +++ b/docs-web/src/main/webapp/src/app/docs/controller/User.js @@ -5,7 +5,10 @@ */ angular.module('docs').controller('User', function(Restangular, $scope, $state) { // Load users - Restangular.one('user/list').get({ limit: 100 }).then(function(data) { + Restangular.one('user/list').get({ + sort_column: 1, + asc: true + }).then(function(data) { $scope.users = data.users; }); diff --git a/docs-web/src/main/webapp/src/partial/docs/directive.selectrelation.html b/docs-web/src/main/webapp/src/partial/docs/directive.selectrelation.html index c4ec6a53..82f8a9c3 100644 --- a/docs-web/src/main/webapp/src/partial/docs/directive.selectrelation.html +++ b/docs-web/src/main/webapp/src/partial/docs/directive.selectrelation.html @@ -7,7 +7,6 @@ \ No newline at end of file diff --git a/docs-web/src/main/webapp/src/partial/docs/document.edit.html b/docs-web/src/main/webapp/src/partial/docs/document.edit.html index e03bc32c..049c0d77 100644 --- a/docs-web/src/main/webapp/src/partial/docs/document.edit.html +++ b/docs-web/src/main/webapp/src/partial/docs/document.edit.html @@ -9,7 +9,7 @@
diff --git a/docs-web/src/main/webapp/src/partial/docs/settings.group.edit.html b/docs-web/src/main/webapp/src/partial/docs/settings.group.edit.html index 3e4fde42..38066ea6 100644 --- a/docs-web/src/main/webapp/src/partial/docs/settings.group.edit.html +++ b/docs-web/src/main/webapp/src/partial/docs/settings.group.edit.html @@ -27,8 +27,8 @@
@@ -44,6 +44,30 @@ -

Members

- +
+

Members

+
+
+ +
+ +
+
+ +
+ +
+ + + {{ member }} + +   + +
+
+
+
\ No newline at end of file diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestGroupResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestGroupResource.java index eb7b0ee8..ae40300d 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestGroupResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestGroupResource.java @@ -130,6 +130,9 @@ public class TestGroupResource extends BaseJerseyTest { .get(JsonObject.class); Assert.assertEquals("g12new", json.getString("name")); Assert.assertEquals("g11", json.getString("parent")); + JsonArray members = json.getJsonArray("members"); + Assert.assertEquals(1, members.size()); + Assert.assertEquals("group1", members.getString(0)); // Remove group1 from g12new json = target().path("/group/g12new/group1").request()