root scope bug fixes

This commit is contained in:
Kyle Spearrin 2017-04-18 10:45:35 -04:00
parent dc0bf54401
commit 9863a95a71
2 changed files with 37 additions and 79 deletions

View File

@ -135,33 +135,20 @@
}); });
editModel.result.then(function (returnVal) { editModel.result.then(function (returnVal) {
var loginToUpdate;
if (returnVal.action === 'edit') { if (returnVal.action === 'edit') {
loginToUpdate = $filter('filter')($rootScope.vaultLogins, { id: returnVal.data.id }, true); login.folderId = returnVal.data.folderId;
if (loginToUpdate && loginToUpdate.length > 0) { login.name = returnVal.data.name;
loginToUpdate[0].folderId = returnVal.data.folderId; login.username = returnVal.data.username;
loginToUpdate[0].name = returnVal.data.name; login.favorite = returnVal.data.favorite;
loginToUpdate[0].username = returnVal.data.username;
loginToUpdate[0].favorite = returnVal.data.favorite;
sortScopedLoginData(); sortScopedLoginData();
}
} }
else if (returnVal.action === 'partialEdit') { else if (returnVal.action === 'partialEdit') {
loginToUpdate = $filter('filter')($rootScope.vaultLogins, { id: returnVal.data.id }, true); login.folderId = returnVal.data.folderId;
if (loginToUpdate && loginToUpdate.length > 0) { login.favorite = returnVal.data.favorite;
loginToUpdate[0].folderId = returnVal.data.folderId;
loginToUpdate[0].favorite = returnVal.data.favorite;
}
} }
else if (returnVal.action === 'delete') { else if (returnVal.action === 'delete') {
var loginToDelete = $filter('filter')($rootScope.vaultLogins, { id: returnVal.data }, true); removeLoginFromScopes(login);
if (loginToDelete && loginToDelete.length > 0) {
var index = $rootScope.vaultLogins.indexOf(loginToDelete[0]);
if (index > -1) {
$rootScope.vaultLogins.splice(index, 1);
}
}
} }
}); });
}; };
@ -193,10 +180,7 @@
} }
apiService.logins.del({ id: login.id }, function () { apiService.logins.del({ id: login.id }, function () {
var index = $rootScope.vaultLogins.indexOf(login); removeLoginFromScopes(login);
if (index > -1) {
$rootScope.vaultLogins.splice(index, 1);
}
}); });
}; };
@ -212,10 +196,7 @@
}); });
editModel.result.then(function (editedFolder) { editModel.result.then(function (editedFolder) {
var folder = $filter('filter')($rootScope.vaultFolders, { id: editedFolder.id }, true); folder.name = editedFolder.name;
if (folder && folder.length > 0) {
folder[0].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);
}
}
}); });

View File

@ -2,7 +2,7 @@
.module('bit.vault') .module('bit.vault')
.controller('vaultSubvaultsController', function ($scope, apiService, cipherService, $analytics, $q, $localStorage, .controller('vaultSubvaultsController', function ($scope, apiService, cipherService, $analytics, $q, $localStorage,
$uibModal, $filter) { $uibModal, $filter, $rootScope) {
$scope.logins = []; $scope.logins = [];
$scope.subvaults = []; $scope.subvaults = [];
$scope.folders = []; $scope.folders = [];
@ -65,36 +65,25 @@
templateUrl: 'app/vault/views/vaultEditLogin.html', templateUrl: 'app/vault/views/vaultEditLogin.html',
controller: 'vaultEditLoginController', controller: 'vaultEditLoginController',
resolve: { resolve: {
loginId: function () { return login.id; }, loginId: function () { return login.id; }
folders: getFoldersPromise()
} }
}); });
editModel.result.then(function (returnVal) { editModel.result.then(function (returnVal) {
var loginToUpdate;
if (returnVal.action === 'edit') { if (returnVal.action === 'edit') {
loginToUpdate = $filter('filter')($scope.logins, { id: returnVal.data.id }, true); login.folderId = returnVal.data.folderId;
if (loginToUpdate && loginToUpdate.length > 0) { login.name = returnVal.data.name;
loginToUpdate[0].folderId = returnVal.data.folderId; login.username = returnVal.data.username;
loginToUpdate[0].name = returnVal.data.name; login.favorite = returnVal.data.favorite;
loginToUpdate[0].username = returnVal.data.username;
loginToUpdate[0].favorite = returnVal.data.favorite;
}
} }
else if (returnVal.action === 'partialEdit') { else if (returnVal.action === 'partialEdit') {
loginToUpdate = $filter('filter')($scope.logins, { id: returnVal.data.id }, true); login.folderId = returnVal.data.folderId;
if (loginToUpdate && loginToUpdate.length > 0) { login.favorite = returnVal.data.favorite;
loginToUpdate[0].folderId = returnVal.data.folderId;
loginToUpdate[0].favorite = returnVal.data.favorite;
}
} }
else if (returnVal.action === 'delete') { else if (returnVal.action === 'delete') {
var loginToDelete = $filter('filter')($scope.logins, { id: returnVal.data }, true); var index = $scope.logins.indexOf(login);
if (loginToDelete && loginToDelete.length > 0) { if (index > -1) {
var index = $scope.logins.indexOf(loginToDelete[0]); $scope.logins.splice(index, 1);
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;
}
}); });