Skip to content

Commit

Permalink
Merge pull request #114 from pangara/MEM-548
Browse files Browse the repository at this point in the history
MEM-548 Collections (info panel) do not get updated when removed from…
  • Loading branch information
marklise authored Oct 5, 2017
2 parents 32d4576 + cb13f42 commit c75923c
Showing 1 changed file with 11 additions and 2 deletions.
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

0 comments on commit c75923c

Please sign in to comment.