From 93e88d8b237bfe4e41ebb73051b9cdcaf5890294 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 9 May 2017 19:04:26 -0400 Subject: [PATCH] group user assignment --- ...organizationCollectionsGroupsController.js | 11 --- .../organizationGroupsController.js | 14 ++- .../organizationGroupsUsersController.js | 56 ++++++++++++ .../organizationPeopleController.js | 15 ++++ .../organizationPeopleGroupsController.js | 87 +++++++++++++++++++ .../views/organizationCollections.html | 5 -- .../views/organizationCollectionsGroups.html | 10 --- .../views/organizationGroupsUsers.html | 55 ++++++++++++ .../views/organizationPeople.html | 5 ++ .../views/organizationPeopleGroups.html | 55 ++++++++++++ src/app/services/apiService.js | 3 + src/index.html | 2 + 12 files changed, 291 insertions(+), 27 deletions(-) delete mode 100644 src/app/organization/organizationCollectionsGroupsController.js create mode 100644 src/app/organization/organizationGroupsUsersController.js create mode 100644 src/app/organization/organizationPeopleGroupsController.js delete mode 100644 src/app/organization/views/organizationCollectionsGroups.html create mode 100644 src/app/organization/views/organizationGroupsUsers.html create mode 100644 src/app/organization/views/organizationPeopleGroups.html diff --git a/src/app/organization/organizationCollectionsGroupsController.js b/src/app/organization/organizationCollectionsGroupsController.js deleted file mode 100644 index 170dd2f349..0000000000 --- a/src/app/organization/organizationCollectionsGroupsController.js +++ /dev/null @@ -1,11 +0,0 @@ -angular - .module('bit.organization') - - .controller('organizationCollectionsGroupsController', function ($scope, $state, $uibModalInstance, collection, $analytics) { - $analytics.eventTrack('organizationCollectionsGroupsController', { category: 'Modal' }); - $scope.collection = collection; - - $scope.close = function () { - $uibModalInstance.dismiss('cancel'); - }; - }); diff --git a/src/app/organization/organizationGroupsController.js b/src/app/organization/organizationGroupsController.js index 8573058cca..f8a54229d0 100644 --- a/src/app/organization/organizationGroupsController.js +++ b/src/app/organization/organizationGroupsController.js @@ -44,7 +44,19 @@ }; $scope.users = function (group) { - + var modal = $uibModal.open({ + animation: true, + templateUrl: 'app/organization/views/organizationGroupsUsers.html', + controller: 'organizationGroupsUsersController', + size: 'lg', + resolve: { + group: function () { return group; } + } + }); + + modal.result.then(function () { + // nothing to do + }); }; $scope.delete = function (group) { diff --git a/src/app/organization/organizationGroupsUsersController.js b/src/app/organization/organizationGroupsUsersController.js new file mode 100644 index 0000000000..f9ba86ca01 --- /dev/null +++ b/src/app/organization/organizationGroupsUsersController.js @@ -0,0 +1,56 @@ +angular + .module('bit.organization') + + .controller('organizationGroupsUsersController', function ($scope, $state, $uibModalInstance, apiService, + $analytics, group, toastr) { + $analytics.eventTrack('organizationGroupUsersController', { category: 'Modal' }); + $scope.loading = true; + $scope.group = group; + $scope.users = []; + + $uibModalInstance.opened.then(function () { + return apiService.groups.listUsers({ + orgId: $state.params.orgId, + id: group.id + }).$promise; + }).then(function (userList) { + var users = []; + if (userList && userList.Data.length) { + for (var i = 0; i < userList.Data.length; i++) { + users.push({ + organizationUserId: userList.Data[i].OrganizationUserId, + name: userList.Data[i].Name, + email: userList.Data[i].Email, + type: userList.Data[i].Type, + status: userList.Data[i].Status, + accessAll: userList.Data[i].AccessAll + }); + } + } + + $scope.users = users; + $scope.loading = false; + }); + + $scope.remove = function (user) { + if (!confirm('Are you sure you want to remove this user (' + user.email + ') from this ' + + 'group (' + group.name + ')?')) { + return; + } + + //apiService.collectionUsers.del({ orgId: $state.params.orgId, id: user.id }, null, function () { + // toastr.success(user.email + ' has been removed.', 'User Removed'); + // $analytics.eventTrack('Removed User From Collection'); + // var index = $scope.users.indexOf(user); + // if (index > -1) { + // $scope.users.splice(index, 1); + // } + //}, function () { + // toastr.error('Unable to remove user.', 'Error'); + //}); + }; + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/organization/organizationPeopleController.js b/src/app/organization/organizationPeopleController.js index 4a5bea7e7a..6a80a1cd0d 100644 --- a/src/app/organization/organizationPeopleController.js +++ b/src/app/organization/organizationPeopleController.js @@ -86,6 +86,21 @@ }); }; + $scope.groups = function (user) { + var modal = $uibModal.open({ + animation: true, + templateUrl: 'app/organization/views/organizationPeopleGroups.html', + controller: 'organizationPeopleGroupsController', + resolve: { + orgUser: function () { return user; } + } + }); + + modal.result.then(function () { + + }); + }; + function loadList() { apiService.organizationUsers.list({ orgId: $state.params.orgId }, function (list) { var users = []; diff --git a/src/app/organization/organizationPeopleGroupsController.js b/src/app/organization/organizationPeopleGroupsController.js new file mode 100644 index 0000000000..07cba512b0 --- /dev/null +++ b/src/app/organization/organizationPeopleGroupsController.js @@ -0,0 +1,87 @@ +angular + .module('bit.organization') + + .controller('organizationPeopleGroupsController', function ($scope, $state, $uibModalInstance, apiService, + orgUser, $analytics) { + $analytics.eventTrack('organizationPeopleGroupsController', { category: 'Modal' }); + + $scope.loading = true; + $scope.groups = []; + $scope.selectedGroups = {}; + $scope.orgUser = orgUser; + + $uibModalInstance.opened.then(function () { + return apiService.groups.listOrganization({ orgId: $state.params.orgId }).$promise; + }).then(function (groupsList) { + var groups = []; + for (var i = 0; i < groupsList.Data.length; i++) { + groups.push({ + id: groupsList.Data[i].Id, + name: groupsList.Data[i].Name + }); + } + $scope.groups = groups; + + return apiService.organizationUsers.listGroups({ orgId: $state.params.orgId, id: orgUser.id }).$promise; + }).then(function (groupIds) { + var selectedGroups = {}; + if (groupIds) { + for (var i = 0; i < groupIds.length; i++) { + selectedGroups[groupIds[i]] = true; + } + } + $scope.selectedGroups = selectedGroups; + $scope.loading = false; + }, function (error) { + + }); + + $scope.toggleGroupSelectionAll = function ($event) { + var groups = {}; + if ($event.target.checked) { + for (var i = 0; i < $scope.groups.length; i++) { + groups[$scope.groups[i].id] = true; + } + } + + $scope.selectedGroups = groups; + }; + + $scope.toggleGroupSelection = function (id) { + if (id in $scope.selectedGroups) { + delete $scope.selectedGroups[id]; + } + else { + $scope.selectedGroups[id] = true; + } + }; + + $scope.groupSelected = function (group) { + return group.id in $scope.selectedGroups; + }; + + $scope.allSelected = function () { + return Object.keys($scope.selectedGroups).length === $scope.groups.length; + }; + + $scope.submitPromise = null; + $scope.submit = function (model) { + var groups = []; + for (var groupId in $scope.selectedGroups) { + if ($scope.selectedGroups.hasOwnProperty(groupId)) { + groups.push(groupId); + } + } + + $scope.submitPromise = apiService.organizationUsers.putGroups({ orgId: $state.params.orgId, id: orgUser.id }, { + groupIds: groups, + }, function () { + $analytics.eventTrack('Edited User Groups'); + $uibModalInstance.close(); + }).$promise; + }; + + $scope.close = function () { + $uibModalInstance.dismiss('cancel'); + }; + }); diff --git a/src/app/organization/views/organizationCollections.html b/src/app/organization/views/organizationCollections.html index 7957d3bf1b..9e785aeb1b 100644 --- a/src/app/organization/views/organizationCollections.html +++ b/src/app/organization/views/organizationCollections.html @@ -48,11 +48,6 @@ Users -
  • - - Groups - -
  • Delete diff --git a/src/app/organization/views/organizationCollectionsGroups.html b/src/app/organization/views/organizationCollectionsGroups.html deleted file mode 100644 index 03014dfa55..0000000000 --- a/src/app/organization/views/organizationCollectionsGroups.html +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/src/app/organization/views/organizationGroupsUsers.html b/src/app/organization/views/organizationGroupsUsers.html new file mode 100644 index 0000000000..ac3b4dfa1e --- /dev/null +++ b/src/app/organization/views/organizationGroupsUsers.html @@ -0,0 +1,55 @@ + + + diff --git a/src/app/organization/views/organizationPeople.html b/src/app/organization/views/organizationPeople.html index 8034b74f89..1a541592dc 100644 --- a/src/app/organization/views/organizationPeople.html +++ b/src/app/organization/views/organizationPeople.html @@ -41,6 +41,11 @@ Edit
  • +
  • + + Groups + +
  • Confirm diff --git a/src/app/organization/views/organizationPeopleGroups.html b/src/app/organization/views/organizationPeopleGroups.html new file mode 100644 index 0000000000..1e067e1c1e --- /dev/null +++ b/src/app/organization/views/organizationPeopleGroups.html @@ -0,0 +1,55 @@ + +
    + + +
    diff --git a/src/app/services/apiService.js b/src/app/services/apiService.js index 5bbf9c9387..3f3daf3fbe 100644 --- a/src/app/services/apiService.js +++ b/src/app/services/apiService.js @@ -59,11 +59,13 @@ _service.organizationUsers = $resource(_apiUri + '/organizations/:orgId/users/:id', {}, { get: { method: 'GET', params: { id: '@id', orgId: '@orgId' } }, list: { method: 'GET', params: { orgId: '@orgId' } }, + listGroups: { url: _apiUri + '/organizations/:orgId/users/:id/groups', method: 'GET', params: { id: '@id', orgId: '@orgId' }, isArray: true }, invite: { url: _apiUri + '/organizations/:orgId/users/invite', method: 'POST', params: { orgId: '@orgId' } }, reinvite: { url: _apiUri + '/organizations/:orgId/users/:id/reinvite', method: 'POST', params: { id: '@id', orgId: '@orgId' } }, accept: { url: _apiUri + '/organizations/:orgId/users/:id/accept', method: 'POST', params: { id: '@id', orgId: '@orgId' } }, confirm: { url: _apiUri + '/organizations/:orgId/users/:id/confirm', method: 'POST', params: { id: '@id', orgId: '@orgId' } }, put: { method: 'POST', params: { id: '@id', orgId: '@orgId' } }, + putGroups: { url: _apiUri + '/organizations/:orgId/users/:id/groups', method: 'POST', params: { id: '@id', orgId: '@orgId' } }, del: { url: _apiUri + '/organizations/:orgId/users/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } } }); @@ -86,6 +88,7 @@ get: { method: 'GET', params: { id: '@id', orgId: '@orgId' } }, getDetails: { url: _apiUri + '/organizations/:orgId/groups/:id/details', method: 'GET', params: { id: '@id', orgId: '@orgId' } }, listOrganization: { method: 'GET', params: { orgId: '@orgId' } }, + listUsers: { url: _apiUri + '/organizations/:orgId/groups/:id/users', method: 'GET', params: { id: '@id', orgId: '@orgId' } }, post: { method: 'POST', params: { orgId: '@orgId' } }, put: { method: 'POST', params: { id: '@id', orgId: '@orgId' } }, del: { url: _apiUri + '/organizations/:orgId/groups/:id/delete', method: 'POST', params: { id: '@id', orgId: '@orgId' } } diff --git a/src/index.html b/src/index.html index ca699c7970..d004daaab8 100644 --- a/src/index.html +++ b/src/index.html @@ -134,6 +134,7 @@ + @@ -151,6 +152,7 @@ +