From d1c01d3c8681bf335ca6b1ceb1529bc3e389816d Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 27 Jun 2016 09:12:57 -0700 Subject: [PATCH] Squashed commit of the following: commit 3f199a9f061237a8d1d0dff46b6334ad78356e6a Merge: 27fe4ed 736cba7 Author: Victor Woeltjen Date: Mon Jun 27 09:04:40 2016 -0700 Merge remote-tracking branch 'origin/master' into clear-transactions-1046 Conflicts: platform/commonUI/edit/src/actions/SaveAsAction.js commit 27fe4edb30931c2eed0c0e027e6c335b2eca79db Author: Victor Woeltjen Date: Wed Jun 22 15:04:06 2016 -0700 [Edit] Mark restartTransaction as private API commit 21d1938a0f6c2430e7350c69075f51ea6cb064ac Author: Victor Woeltjen Date: Wed Jun 22 15:03:17 2016 -0700 [Edit] Clarify JSDoc commit 06a83f9fa98b6257c0ec8e937289256edaf918ff Author: Victor Woeltjen Date: Wed Jun 22 15:01:35 2016 -0700 [Edit] Update failing spec commit 1f525160e007c5c436b738833dcd0db3faeedca0 Author: Victor Woeltjen Date: Wed Jun 22 14:52:43 2016 -0700 [Edit] Refer to correct variable ...when clearing transactions after a restartTransaction commit b60e94bce414044ce04b99467a8828be90ea871e Author: Victor Woeltjen Date: Wed Jun 22 14:38:54 2016 -0700 [Edit] Clear transactions on Save As ...such that only persistence calls associated with the saved clones are actually issued. Fixes #1046. --- platform/commonUI/edit/bundle.js | 3 +- .../commonUI/edit/src/actions/SaveAsAction.js | 16 ++++++++++ .../edit/src/services/TransactionService.js | 31 ++++++++++++++++++- .../edit/test/actions/SaveAsActionSpec.js | 18 ++++++++++- 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/platform/commonUI/edit/bundle.js b/platform/commonUI/edit/bundle.js index aac5de49e5..4f79d11787 100644 --- a/platform/commonUI/edit/bundle.js +++ b/platform/commonUI/edit/bundle.js @@ -222,7 +222,8 @@ define([ "policyService", "dialogService", "creationService", - "copyService" + "copyService", + "transactionService" ], "priority": "mandatory" }, diff --git a/platform/commonUI/edit/src/actions/SaveAsAction.js b/platform/commonUI/edit/src/actions/SaveAsAction.js index 9c34c06c9a..4c4206b8a6 100644 --- a/platform/commonUI/edit/src/actions/SaveAsAction.js +++ b/platform/commonUI/edit/src/actions/SaveAsAction.js @@ -44,6 +44,7 @@ define([ dialogService, creationService, copyService, + transactionService, context ) { this.domainObject = (context || {}).domainObject; @@ -54,6 +55,7 @@ define([ this.dialogService = dialogService; this.creationService = creationService; this.copyService = copyService; + this.transactionService = transactionService; } /** @@ -111,6 +113,8 @@ define([ var self = this, domainObject = this.domainObject, copyService = this.copyService, + transactionService = this.transactionService, + cancelOldTransaction, dialog = new SaveInProgressDialog(this.dialogService); function doWizardSave(parent) { @@ -156,6 +160,16 @@ define([ .then(resolveWith(clonedObject)); } + function restartTransaction(object) { + cancelOldTransaction = transactionService.restartTransaction(); + return object; + } + + function doCancelOldTransaction(object) { + cancelOldTransaction(); + return object; + } + function onFailure() { hideBlockingDialog(); return false; @@ -165,8 +179,10 @@ define([ .then(doWizardSave) .then(showBlockingDialog) .then(getParent) + .then(restartTransaction) .then(cloneIntoParent) .then(commitEditingAfterClone) + .then(doCancelOldTransaction) .then(hideBlockingDialog) .catch(onFailure); }; diff --git a/platform/commonUI/edit/src/services/TransactionService.js b/platform/commonUI/edit/src/services/TransactionService.js index 8d6c465959..00bc96e1dd 100644 --- a/platform/commonUI/edit/src/services/TransactionService.js +++ b/platform/commonUI/edit/src/services/TransactionService.js @@ -140,9 +140,38 @@ define( }); }; + /** + * Clear and restart the active transaction. + * + * This neither cancels nor commits the active transaction; + * instead, it returns a function that can be used to cancel that + * transaction. + * + * @returns {Function} a function to cancel the prior transaction + * @private + */ + TransactionService.prototype.restartTransaction = function () { + var oldOnCancels = this.onCancels; + + this.onCommits = []; + this.onCancels = []; + + return function () { + while (oldOnCancels.length > 0) { + var onCancel = oldOnCancels.pop(); + try { + onCancel(); + } catch (error) { + this.$log.error("Error cancelling transaction."); + } + } + }; + }; + TransactionService.prototype.size = function () { return this.onCommits.length; }; return TransactionService; - }); + } +); diff --git a/platform/commonUI/edit/test/actions/SaveAsActionSpec.js b/platform/commonUI/edit/test/actions/SaveAsActionSpec.js index 37e35aa5af..850e18ecca 100644 --- a/platform/commonUI/edit/test/actions/SaveAsActionSpec.js +++ b/platform/commonUI/edit/test/actions/SaveAsActionSpec.js @@ -34,6 +34,7 @@ define( mockCopyService, mockParent, mockUrlService, + mockTransactionService, actionContext, capabilities = {}, action; @@ -119,11 +120,26 @@ define( ["urlForLocation"] ); + mockTransactionService = jasmine.createSpyObj( + "transactionService", + ["restartTransaction"] + ); + mockTransactionService.restartTransaction + .andReturn(jasmine.createSpy()); + actionContext = { domainObject: mockDomainObject }; - action = new SaveAsAction(undefined, undefined, mockDialogService, undefined, mockCopyService, actionContext); + action = new SaveAsAction( + undefined, + undefined, + mockDialogService, + undefined, + mockCopyService, + mockTransactionService, + actionContext + ); spyOn(action, "getObjectService"); action.getObjectService.andReturn(mockObjectService);