From 9863a95a718bf90773f0396f24bde56aa194cba0 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Tue, 18 Apr 2017 10:45:35 -0400 Subject: [PATCH] root scope bug fixes --- src/app/vault/vaultController.js | 57 ++++++++++------------ src/app/vault/vaultSubvaultsController.js | 59 +++++------------------ 2 files changed, 37 insertions(+), 79 deletions(-) diff --git a/src/app/vault/vaultController.js b/src/app/vault/vaultController.js index f006d0c08c..d247eaca9a 100644 --- a/src/app/vault/vaultController.js +++ b/src/app/vault/vaultController.js @@ -135,33 +135,20 @@ }); editModel.result.then(function (returnVal) { - var loginToUpdate; if (returnVal.action === 'edit') { - loginToUpdate = $filter('filter')($rootScope.vaultLogins, { id: returnVal.data.id }, true); - if (loginToUpdate && loginToUpdate.length > 0) { - loginToUpdate[0].folderId = returnVal.data.folderId; - loginToUpdate[0].name = returnVal.data.name; - loginToUpdate[0].username = returnVal.data.username; - loginToUpdate[0].favorite = returnVal.data.favorite; + login.folderId = returnVal.data.folderId; + login.name = returnVal.data.name; + login.username = returnVal.data.username; + login.favorite = returnVal.data.favorite; - sortScopedLoginData(); - } + sortScopedLoginData(); } else if (returnVal.action === 'partialEdit') { - loginToUpdate = $filter('filter')($rootScope.vaultLogins, { id: returnVal.data.id }, true); - if (loginToUpdate && loginToUpdate.length > 0) { - loginToUpdate[0].folderId = returnVal.data.folderId; - loginToUpdate[0].favorite = returnVal.data.favorite; - } + login.folderId = returnVal.data.folderId; + login.favorite = returnVal.data.favorite; } else if (returnVal.action === 'delete') { - var loginToDelete = $filter('filter')($rootScope.vaultLogins, { id: returnVal.data }, true); - if (loginToDelete && loginToDelete.length > 0) { - var index = $rootScope.vaultLogins.indexOf(loginToDelete[0]); - if (index > -1) { - $rootScope.vaultLogins.splice(index, 1); - } - } + removeLoginFromScopes(login); } }); }; @@ -193,10 +180,7 @@ } apiService.logins.del({ id: login.id }, function () { - var index = $rootScope.vaultLogins.indexOf(login); - if (index > -1) { - $rootScope.vaultLogins.splice(index, 1); - } + removeLoginFromScopes(login); }); }; @@ -212,10 +196,7 @@ }); editModel.result.then(function (editedFolder) { - var folder = $filter('filter')($rootScope.vaultFolders, { id: editedFolder.id }, true); - if (folder && folder.length > 0) { - folder[0].name = editedFolder.name; - } + folder.name = editedFolder.name; }); }; @@ -284,8 +265,22 @@ } }); - modal.result.then(function () { - + modal.result.then(function (response) { + if (response.subvaultIds && !response.subvaultIds.length) { + removeLoginFromScopes(login); + } }); }; + + function removeLoginFromScopes(login) { + var index = $rootScope.vaultLogins.indexOf(login); + if (index > -1) { + $rootScope.vaultLogins.splice(index, 1); + } + + index = $scope.logins.indexOf(login); + if (index > -1) { + $scope.logins.splice(index, 1); + } + } }); diff --git a/src/app/vault/vaultSubvaultsController.js b/src/app/vault/vaultSubvaultsController.js index 5c653c78b3..5fce250df6 100644 --- a/src/app/vault/vaultSubvaultsController.js +++ b/src/app/vault/vaultSubvaultsController.js @@ -2,7 +2,7 @@ .module('bit.vault') .controller('vaultSubvaultsController', function ($scope, apiService, cipherService, $analytics, $q, $localStorage, - $uibModal, $filter) { + $uibModal, $filter, $rootScope) { $scope.logins = []; $scope.subvaults = []; $scope.folders = []; @@ -65,36 +65,25 @@ templateUrl: 'app/vault/views/vaultEditLogin.html', controller: 'vaultEditLoginController', resolve: { - loginId: function () { return login.id; }, - folders: getFoldersPromise() + loginId: function () { return login.id; } } }); editModel.result.then(function (returnVal) { - var loginToUpdate; if (returnVal.action === 'edit') { - loginToUpdate = $filter('filter')($scope.logins, { id: returnVal.data.id }, true); - if (loginToUpdate && loginToUpdate.length > 0) { - loginToUpdate[0].folderId = returnVal.data.folderId; - loginToUpdate[0].name = returnVal.data.name; - loginToUpdate[0].username = returnVal.data.username; - loginToUpdate[0].favorite = returnVal.data.favorite; - } + login.folderId = returnVal.data.folderId; + login.name = returnVal.data.name; + login.username = returnVal.data.username; + login.favorite = returnVal.data.favorite; } else if (returnVal.action === 'partialEdit') { - loginToUpdate = $filter('filter')($scope.logins, { id: returnVal.data.id }, true); - if (loginToUpdate && loginToUpdate.length > 0) { - loginToUpdate[0].folderId = returnVal.data.folderId; - loginToUpdate[0].favorite = returnVal.data.favorite; - } + login.folderId = returnVal.data.folderId; + login.favorite = returnVal.data.favorite; } else if (returnVal.action === 'delete') { - var loginToDelete = $filter('filter')($scope.logins, { id: returnVal.data }, true); - if (loginToDelete && loginToDelete.length > 0) { - var index = $scope.logins.indexOf(loginToDelete[0]); - if (index > -1) { - $scope.logins.splice(index, 1); - } + var index = $scope.logins.indexOf(login); + if (index > -1) { + $scope.logins.splice(index, 1); } } }); @@ -116,30 +105,4 @@ } }); }; - - function getFoldersPromise() { - var deferred = $q.defer(); - - if (!$scope.folders || !$scope.folders.length) { - apiService.folders.list({}).$promise.then(function (folders) { - var decFolders = [{ - id: null, - name: 'No Folder' - }]; - - for (var i = 0; i < folders.Data.length; i++) { - var decFolder = cipherService.decryptFolderPreview(folders.Data[i]); - decFolders.push(decFolder); - } - - $scope.folders = decFolders; - deferred.resolve($scope.folders); - }); - } - else { - deferred.resolve($scope.folders); - } - - return deferred.promise; - } });