Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions modules/documents/client/directives/documents.manager.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,11 +804,20 @@ angular.module('documents')
// Removal - check main and other documents
promises = _.union(_.map(added, function(c) {
return CollectionModel.addOtherDocument(c._id, documents._id);
}), _.map(removed, function(c) {
return CollectionModel.removeOtherDocument(c._id, documents._id);
}), _.map(removed, function(c) {
return CollectionModel.removeMainDocument(c._id, documents._id);
}));
// EPIC - 1215 Collections (info panel) do not get updated when removed from the document
// Dealing seperately with removal of documents (associated with the appropriate collections) here
// because saving documents after removing collections
// does not take into consideration the fact that the collections could be updated by something else
//Therefore, we serialize promises such that removal of one document only happens after the removal of another document.
var chain = _.reduce(removed, function(previousPromise, currentCollectionElement) {
return previousPromise.then(function() {
return CollectionModel.removeOtherDocument(currentCollectionElement._id, documents._id);
});
}, Promise.resolve());
promises.push(chain);

return Promise.all(promises).then(function() {
AlertService.success('The document\'s collections were successfully updated.');
Expand Down