Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #276 from pangara/EPIC-1215
Browse files Browse the repository at this point in the history
EPIC-1215 Collections (info panel) do not get updated when removed fr…
  • Loading branch information
marklise authored Oct 5, 2017
2 parents 7cb83b7 + 586cffe commit 1704d78
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions modules/documents/client/directives/documents.manager.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,18 +741,25 @@ angular.module('documents')
var removed = _.filter(original, function(o) {
return !_.find(collections, function(c) { return o._id === c._id; });
});

// Updating collections:
// Addition - only other 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.');
}, function(err) {
Expand Down

0 comments on commit 1704d78

Please sign in to comment.