From f17015781738c972aec76bb66f7eaa89ab53a9b6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 9 Jun 2017 00:44:56 -0400 Subject: [PATCH] bulk actions with move and delete --- src/app/services/apiService.js | 4 ++- src/app/vault/vaultController.js | 53 ++++++++++++++++++++++++++++++++ src/app/vault/views/vault.html | 25 +++++++++++++++ src/less/vault.less | 28 +++++++++++------ 4 files changed, 99 insertions(+), 11 deletions(-) diff --git a/src/app/services/apiService.js b/src/app/services/apiService.js index f32041b6e2..bd990542ec 100644 --- a/src/app/services/apiService.js +++ b/src/app/services/apiService.js @@ -38,7 +38,9 @@ putCollections: { url: _apiUri + '/ciphers/:id/collections', method: 'POST', params: { id: '@id' } }, putCollectionsAdmin: { url: _apiUri + '/ciphers/:id/collections-admin', method: 'POST', params: { id: '@id' } }, del: { url: _apiUri + '/ciphers/:id/delete', method: 'POST', params: { id: '@id' } }, - delAdmin: { url: _apiUri + '/ciphers/:id/delete-admin', method: 'POST', params: { id: '@id' } } + delAdmin: { url: _apiUri + '/ciphers/:id/delete-admin', method: 'POST', params: { id: '@id' } }, + delMany: { url: _apiUri + '/ciphers/delete', method: 'POST' }, + moveMany: { url: _apiUri + '/ciphers/move', method: 'POST' } }); _service.organizations = $resource(_apiUri + '/organizations/:id', {}, { diff --git a/src/app/vault/vaultController.js b/src/app/vault/vaultController.js index e2b05ac0f5..f1bbe875a1 100644 --- a/src/app/vault/vaultController.js +++ b/src/app/vault/vaultController.js @@ -312,6 +312,59 @@ return $scope.folderIdFilter === undefined || folder.id === $scope.folderIdFilter; }; + function distinct(value, index, self) { + return self.indexOf(value) === index; + } + + function getSelectedLogins() { + return $('input[name="loginSelection"]:checked').map(function () { + return $(this).val(); + }).get().filter(distinct); + } + + function clearLoginSelections() { + $('input[name="loginSelection"]').attr('checked', false); + } + + $scope.bulkMove = function () { + var ids = getSelectedLogins(); + if (ids.length === 0) { + alert('You have not selected anything.'); + return; + } + + // TODO + }; + + $scope.bulkDelete = function () { + var ids = getSelectedLogins(); + if (ids.length === 0) { + alert('You have not selected anything.'); + return; + } + + if (!confirm('Are you sure you want to delete the selected logins (total: ' + ids.length + ')?')) { + return; + } + + $scope.bulkActionLoading = true; + apiService.ciphers.delMany({ ids: ids }, function () { + $analytics.eventTrack('Bulk Deleted Logins'); + + for (var i = 0; i < ids.length; i++) { + var login = $filter('filter')($rootScope.vaultLogins, { id: ids[i] }); + if (login.length && login[0].edit) { + removeLoginFromScopes(login[0]); + } + } + + clearLoginSelections(); + $scope.bulkActionLoading = false; + }, function () { + $scope.bulkActionLoading = false; + }); + }; + function removeLoginFromScopes(login) { var index = $rootScope.vaultLogins.indexOf(login); if (index > -1) { diff --git a/src/app/vault/views/vault.html b/src/app/vault/views/vault.html index 7b80d336bd..85fc259b86 100644 --- a/src/app/vault/views/vault.html +++ b/src/app/vault/views/vault.html @@ -1,4 +1,23 @@ 
+
+ + +

My Vault @@ -85,6 +104,9 @@ + + + {{login.name}} @@ -179,6 +201,9 @@ + + + {{login.name}} diff --git a/src/less/vault.less b/src/less/vault.less index 54ab184306..90cf402b8d 100644 --- a/src/less/vault.less +++ b/src/less/vault.less @@ -228,8 +228,17 @@ form .btn .loading-icon { } } -/* Forms */ +.btn-link:active { + .box-shadow(none); +} +@media (max-width: @screen-sm-max) { + .content-header .btn-group { + display: none; + } +} + +/* Forms */ .form-control { border-radius: 0 !important; } @@ -331,8 +340,15 @@ form .btn .loading-icon { border-top: 0; } -/* Callouts */ +.table td.action-select { + text-align: center; + width: 30px; + @media (max-width: @screen-sm-max) { + display: none; + } +} +/* Callouts */ .callout.callout-default { background-color: #fff; border-color: darken(@gray, 10%); @@ -364,9 +380,7 @@ form .btn .loading-icon { color: @btn-default-color; } } - /* Boxes */ - .box > .list-group { margin-bottom: 0; } @@ -423,9 +437,7 @@ form .btn .loading-icon { } } } - /* Toastr */ - #toast-container { position: absolute; @@ -497,15 +509,11 @@ form .btn .loading-icon { } } } - /* Typography */ - h1, h2, h3, h4, h5, h6 { margin-top: 0; } - /* Misc */ - .strike { text-decoration: line-through; color: @text-muted;