From 0f789d25e524583431813508112c77170269b1ae Mon Sep 17 00:00:00 2001 From: pangara Date: Wed, 4 Oct 2017 15:59:35 -0700 Subject: [PATCH 1/2] EPIC-1215 Collections (info panel) do not get updated when removed from the document --- .../directives/documents.manager.directive.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/documents/client/directives/documents.manager.directive.js b/modules/documents/client/directives/documents.manager.directive.js index 3833a0ff5..52de5d35d 100644 --- a/modules/documents/client/directives/documents.manager.directive.js +++ b/modules/documents/client/directives/documents.manager.directive.js @@ -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 prev.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) { From 586cffe459affcb18c406c6bc1826f055dc4551f Mon Sep 17 00:00:00 2001 From: Priya Angara Date: Wed, 4 Oct 2017 17:38:51 -0700 Subject: [PATCH 2/2] EPIC-1215 tweak modify variable name --- .../documents/client/directives/documents.manager.directive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/documents/client/directives/documents.manager.directive.js b/modules/documents/client/directives/documents.manager.directive.js index 52de5d35d..71abb6180 100644 --- a/modules/documents/client/directives/documents.manager.directive.js +++ b/modules/documents/client/directives/documents.manager.directive.js @@ -755,7 +755,7 @@ angular.module('documents') // 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 prev.then(function() { + return previousPromise.then(function() { return CollectionModel.removeOtherDocument(currentCollectionElement._id, documents._id); }); }, Promise.resolve());