From cd5ad9f85b320694b8de3401c30f07ebc023541b Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 8 May 2017 22:13:31 -0400 Subject: [PATCH] select collections on group add/edit --- .../organizationGroupsAddController.js | 50 +++++++++++++- .../organizationGroupsEditController.js | 69 ++++++++++++++++--- .../views/organizationGroupsAdd.html | 46 +++++++++++-- .../views/organizationGroupsEdit.html | 47 +++++++++++-- src/app/services/apiService.js | 1 + 5 files changed, 191 insertions(+), 22 deletions(-) diff --git a/src/app/organization/organizationGroupsAddController.js b/src/app/organization/organizationGroupsAddController.js index f3af1cd1d0..ef78c369b3 100644 --- a/src/app/organization/organizationGroupsAddController.js +++ b/src/app/organization/organizationGroupsAddController.js @@ -1,14 +1,60 @@ angular .module('bit.organization') - .controller('organizationGroupsAddController', function ($scope, $state, $uibModalInstance, apiService, + .controller('organizationGroupsAddController', function ($scope, $state, $uibModalInstance, apiService, cipherService, $analytics) { $analytics.eventTrack('organizationGroupsAddController', { category: 'Modal' }); + $scope.collections = []; + $scope.selectedCollections = {}; + $scope.loading = true; + + $uibModalInstance.opened.then(function () { + return apiService.collections.listOrganization({ orgId: $state.params.orgId }).$promise; + }).then(function (collections) { + $scope.collections = cipherService.decryptCollections(collections.Data, $state.params.orgId, true); + $scope.loading = false; + }); + + $scope.toggleCollectionSelectionAll = function ($event) { + var collections = {}; + if ($event.target.checked) { + for (var i = 0; i < $scope.collections.length; i++) { + collections[$scope.collections[i].id] = true; + } + } + + $scope.selectedCollections = collections; + }; + + $scope.toggleCollectionSelection = function (id) { + if (id in $scope.selectedCollections) { + delete $scope.selectedCollections[id]; + } + else { + $scope.selectedCollections[id] = true; + } + }; + + $scope.collectionSelected = function (collection) { + return collection.id in $scope.selectedCollections; + }; + + $scope.allSelected = function () { + return Object.keys($scope.selectedCollections).length === $scope.collections.length; + }; $scope.submit = function (model) { var group = { - name: model.name + name: model.name, + collectionIds: [] }; + + for (var id in $scope.selectedCollections) { + if ($scope.selectedCollections.hasOwnProperty(id)) { + group.collectionIds.push(id); + } + } + $scope.submitPromise = apiService.groups.post({ orgId: $state.params.orgId }, group, function (response) { $analytics.eventTrack('Created Group'); $uibModalInstance.close({ diff --git a/src/app/organization/organizationGroupsEditController.js b/src/app/organization/organizationGroupsEditController.js index 2366ac9394..2a0b33862c 100644 --- a/src/app/organization/organizationGroupsEditController.js +++ b/src/app/organization/organizationGroupsEditController.js @@ -1,22 +1,73 @@ angular .module('bit.organization') - .controller('organizationGroupsEditController', function ($scope, $state, $uibModalInstance, apiService, + .controller('organizationGroupsEditController', function ($scope, $state, $uibModalInstance, apiService, cipherService, $analytics, id) { $analytics.eventTrack('organizationGroupsEditController', { category: 'Modal' }); - $scope.collection = {}; + $scope.collections = []; + $scope.selectedCollections = {}; + $scope.loading = true; $uibModalInstance.opened.then(function () { - apiService.groups.get({ orgId: $state.params.orgId, id: id }, function (group) { - $scope.group = { - id: id, - name: group.Name - }; - }); + return apiService.groups.getDetails({ orgId: $state.params.orgId, id: id }).$promise; + }).then(function (group) { + $scope.group = { + id: id, + name: group.Name + }; + + var collections = {}; + if (group.CollectionIds) { + for (var i = 0; i < group.CollectionIds.length; i++) { + collections[group.CollectionIds[i]] = true; + } + } + $scope.selectedCollections = collections; + + return apiService.collections.listOrganization({ orgId: $state.params.orgId }).$promise; + }).then(function (collections) { + $scope.collections = cipherService.decryptCollections(collections.Data, $state.params.orgId, true); + $scope.loading = false; }); + $scope.toggleCollectionSelectionAll = function ($event) { + var collections = {}; + if ($event.target.checked) { + for (var i = 0; i < $scope.collections.length; i++) { + collections[$scope.collections[i].id] = true; + } + } + + $scope.selectedCollections = collections; + }; + + $scope.toggleCollectionSelection = function (id) { + if (id in $scope.selectedCollections) { + delete $scope.selectedCollections[id]; + } + else { + $scope.selectedCollections[id] = true; + } + }; + + $scope.collectionSelected = function (collection) { + return collection.id in $scope.selectedCollections; + }; + + $scope.allSelected = function () { + return Object.keys($scope.selectedCollections).length === $scope.collections.length; + }; + $scope.submit = function () { - $scope.submitPromise = apiService.groups.put({ orgId: $state.params.orgId }, $scope.group, function (response) { + var group = $scope.group; + group.collectionIds = []; + for (var id in $scope.selectedCollections) { + if ($scope.selectedCollections.hasOwnProperty(id)) { + group.collectionIds.push(id); + } + } + + $scope.submitPromise = apiService.groups.put({ orgId: $state.params.orgId }, group, function (response) { $analytics.eventTrack('Edited Group'); $uibModalInstance.close({ id: response.Id, diff --git a/src/app/organization/views/organizationGroupsAdd.html b/src/app/organization/views/organizationGroupsAdd.html index 07100589c0..c9fcf4f292 100644 --- a/src/app/organization/views/organizationGroupsAdd.html +++ b/src/app/organization/views/organizationGroupsAdd.html @@ -4,6 +4,13 @@