fix bug with only showing selected collections

This commit is contained in:
Kyle Spearrin 2017-10-19 21:18:45 -04:00
parent 1eb5a99ba3
commit c3653577c6
1 changed files with 28 additions and 21 deletions

View File

@ -11,6 +11,7 @@
$scope.selectedCollections = {}; $scope.selectedCollections = {};
$scope.collections = []; $scope.collections = [];
var cipherAndCols = null;
$uibModalInstance.opened.then(function () { $uibModalInstance.opened.then(function () {
apiService.ciphers.getDetails({ id: cipherId }).$promise.then(function (cipher) { apiService.ciphers.getDetails({ id: cipherId }).$promise.then(function (cipher) {
$scope.loadingCipher = false; $scope.loadingCipher = false;
@ -35,27 +36,34 @@
} }
return null; return null;
}).then(function (cipherAndCols) { }).then(function (result) {
if (!cipherAndCols) { if (!result) {
$scope.loadingCollections = false; $scope.loadingCollections = false;
return false;
}
cipherAndCols = result;
return apiService.collections.listMe({ writeOnly: true }).$promise;
}).then(function (response) {
if (response === false) {
return; return;
} }
apiService.collections.listMe({ writeOnly: true }, function (response) {
var collections = []; var collections = [];
var selectedCollections = {}; var selectedCollections = {};
var writeableCollections = response.Data;
for (var i = 0; i < response.Data.length; i++) { for (var i = 0; i < writeableCollections.length; i++) {
// clean out selectCollections that aren't from this organization or read only // clean out selectCollections that aren't from this organization
if (response.Data[i].Id in cipherAndCols.cipherCollections && if (writeableCollections[i].OrganizationId !== cipherAndCols.cipher.OrganizationId) {
response.Data[i].OrganizationId === cipherAndCols.cipher.OrganizationId) {
selectedCollections[response.Data[i].Id] = true;
}
else {
continue; continue;
} }
var decCollection = cipherService.decryptCollection(response.Data[i]); if (writeableCollections[i].Id in cipherAndCols.cipherCollections) {
selectedCollections[writeableCollections[i].Id] = true;
}
var decCollection = cipherService.decryptCollection(writeableCollections[i]);
collections.push(decCollection); collections.push(decCollection);
} }
@ -64,7 +72,6 @@
$scope.selectedCollections = selectedCollections; $scope.selectedCollections = selectedCollections;
}); });
}); });
});
$scope.toggleCollectionSelectionAll = function ($event) { $scope.toggleCollectionSelectionAll = function ($event) {
var collections = {}; var collections = {};