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) {
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);
}
}
});

View File

@ -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;
}
});