mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 15:26:39 +00:00
Merge pull request #1060 from nasa/clear-transactions-1046-squashed
[Edit] Clear transactions on Save As
This commit is contained in:
commit
d05a1cef9b
@ -222,7 +222,8 @@ define([
|
|||||||
"policyService",
|
"policyService",
|
||||||
"dialogService",
|
"dialogService",
|
||||||
"creationService",
|
"creationService",
|
||||||
"copyService"
|
"copyService",
|
||||||
|
"transactionService"
|
||||||
],
|
],
|
||||||
"priority": "mandatory"
|
"priority": "mandatory"
|
||||||
},
|
},
|
||||||
|
@ -44,6 +44,7 @@ define([
|
|||||||
dialogService,
|
dialogService,
|
||||||
creationService,
|
creationService,
|
||||||
copyService,
|
copyService,
|
||||||
|
transactionService,
|
||||||
context
|
context
|
||||||
) {
|
) {
|
||||||
this.domainObject = (context || {}).domainObject;
|
this.domainObject = (context || {}).domainObject;
|
||||||
@ -54,6 +55,7 @@ define([
|
|||||||
this.dialogService = dialogService;
|
this.dialogService = dialogService;
|
||||||
this.creationService = creationService;
|
this.creationService = creationService;
|
||||||
this.copyService = copyService;
|
this.copyService = copyService;
|
||||||
|
this.transactionService = transactionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,6 +113,8 @@ define([
|
|||||||
var self = this,
|
var self = this,
|
||||||
domainObject = this.domainObject,
|
domainObject = this.domainObject,
|
||||||
copyService = this.copyService,
|
copyService = this.copyService,
|
||||||
|
transactionService = this.transactionService,
|
||||||
|
cancelOldTransaction,
|
||||||
dialog = new SaveInProgressDialog(this.dialogService);
|
dialog = new SaveInProgressDialog(this.dialogService);
|
||||||
|
|
||||||
function doWizardSave(parent) {
|
function doWizardSave(parent) {
|
||||||
@ -156,6 +160,16 @@ define([
|
|||||||
.then(resolveWith(clonedObject));
|
.then(resolveWith(clonedObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function restartTransaction(object) {
|
||||||
|
cancelOldTransaction = transactionService.restartTransaction();
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
function doCancelOldTransaction(object) {
|
||||||
|
cancelOldTransaction();
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
function onFailure() {
|
function onFailure() {
|
||||||
hideBlockingDialog();
|
hideBlockingDialog();
|
||||||
return false;
|
return false;
|
||||||
@ -165,8 +179,10 @@ define([
|
|||||||
.then(doWizardSave)
|
.then(doWizardSave)
|
||||||
.then(showBlockingDialog)
|
.then(showBlockingDialog)
|
||||||
.then(getParent)
|
.then(getParent)
|
||||||
|
.then(restartTransaction)
|
||||||
.then(cloneIntoParent)
|
.then(cloneIntoParent)
|
||||||
.then(commitEditingAfterClone)
|
.then(commitEditingAfterClone)
|
||||||
|
.then(doCancelOldTransaction)
|
||||||
.then(hideBlockingDialog)
|
.then(hideBlockingDialog)
|
||||||
.catch(onFailure);
|
.catch(onFailure);
|
||||||
};
|
};
|
||||||
|
@ -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 () {
|
TransactionService.prototype.size = function () {
|
||||||
return this.onCommits.length;
|
return this.onCommits.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
return TransactionService;
|
return TransactionService;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
@ -34,6 +34,7 @@ define(
|
|||||||
mockCopyService,
|
mockCopyService,
|
||||||
mockParent,
|
mockParent,
|
||||||
mockUrlService,
|
mockUrlService,
|
||||||
|
mockTransactionService,
|
||||||
actionContext,
|
actionContext,
|
||||||
capabilities = {},
|
capabilities = {},
|
||||||
action;
|
action;
|
||||||
@ -119,11 +120,26 @@ define(
|
|||||||
["urlForLocation"]
|
["urlForLocation"]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
mockTransactionService = jasmine.createSpyObj(
|
||||||
|
"transactionService",
|
||||||
|
["restartTransaction"]
|
||||||
|
);
|
||||||
|
mockTransactionService.restartTransaction
|
||||||
|
.andReturn(jasmine.createSpy());
|
||||||
|
|
||||||
actionContext = {
|
actionContext = {
|
||||||
domainObject: mockDomainObject
|
domainObject: mockDomainObject
|
||||||
};
|
};
|
||||||
|
|
||||||
action = new SaveAsAction(undefined, undefined, mockDialogService, undefined, mockCopyService, actionContext);
|
action = new SaveAsAction(
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
mockDialogService,
|
||||||
|
undefined,
|
||||||
|
mockCopyService,
|
||||||
|
mockTransactionService,
|
||||||
|
actionContext
|
||||||
|
);
|
||||||
|
|
||||||
spyOn(action, "getObjectService");
|
spyOn(action, "getObjectService");
|
||||||
action.getObjectService.andReturn(mockObjectService);
|
action.getObjectService.andReturn(mockObjectService);
|
||||||
|
Loading…
Reference in New Issue
Block a user