mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 22:28:13 +00:00
[Edit] Persist in a group
Invoke persist calls when leaving Edit mode in a group, instead of in-order, to allow these revision-checking to be handling for the group as a whole. WTD-1033.
This commit is contained in:
@ -10,7 +10,7 @@
|
|||||||
{
|
{
|
||||||
"key": "EditController",
|
"key": "EditController",
|
||||||
"implementation": "controllers/EditController.js",
|
"implementation": "controllers/EditController.js",
|
||||||
"depends": [ "$scope", "navigationService" ]
|
"depends": [ "$scope", "$q", "navigationService" ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "EditActionController",
|
"key": "EditActionController",
|
||||||
|
@ -70,14 +70,15 @@ define(
|
|||||||
* Save any changes that have been made to this domain object
|
* Save any changes that have been made to this domain object
|
||||||
* (as well as to others that might have been retrieved and
|
* (as well as to others that might have been retrieved and
|
||||||
* modified during the editing session)
|
* modified during the editing session)
|
||||||
|
* @param {boolean} nonrecursive if true, save only this
|
||||||
|
* object (and not other objects with associated changes)
|
||||||
* @returns {Promise} a promise that will be fulfilled after
|
* @returns {Promise} a promise that will be fulfilled after
|
||||||
* persistence has completed.
|
* persistence has completed.
|
||||||
*/
|
*/
|
||||||
save: function () {
|
save: function (nonrecursive) {
|
||||||
return resolvePromise(doMutate())
|
return nonrecursive ?
|
||||||
.then(doPersist)
|
resolvePromise(doMutate()).then(doPersist) :
|
||||||
.then(markClean)
|
resolvePromise(cache.saveAll());
|
||||||
.then(saveOthers);
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Cancel editing; Discard any changes that have been made to
|
* Cancel editing; Discard any changes that have been made to
|
||||||
|
@ -14,12 +14,12 @@ define(
|
|||||||
* navigated domain object into the scope.
|
* navigated domain object into the scope.
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function EditController($scope, navigationService) {
|
function EditController($scope, $q, navigationService) {
|
||||||
function setNavigation(domainObject) {
|
function setNavigation(domainObject) {
|
||||||
// Wrap the domain object such that all mutation is
|
// Wrap the domain object such that all mutation is
|
||||||
// confined to edit mode (until Save)
|
// confined to edit mode (until Save)
|
||||||
$scope.navigatedObject =
|
$scope.navigatedObject =
|
||||||
domainObject && new EditableDomainObject(domainObject);
|
domainObject && new EditableDomainObject(domainObject, $q);
|
||||||
}
|
}
|
||||||
|
|
||||||
setNavigation(navigationService.getNavigation());
|
setNavigation(navigationService.getNavigation());
|
||||||
|
@ -48,7 +48,7 @@ define(
|
|||||||
* and provides a "working copy" of the object's
|
* and provides a "working copy" of the object's
|
||||||
* model to allow changes to be easily cancelled.
|
* model to allow changes to be easily cancelled.
|
||||||
*/
|
*/
|
||||||
function EditableDomainObject(domainObject) {
|
function EditableDomainObject(domainObject, $q) {
|
||||||
// The cache will hold all domain objects reached from
|
// The cache will hold all domain objects reached from
|
||||||
// the initial EditableDomainObject; this ensures that
|
// the initial EditableDomainObject; this ensures that
|
||||||
// different versions of the same editable domain object
|
// different versions of the same editable domain object
|
||||||
@ -81,7 +81,7 @@ define(
|
|||||||
return editableObject;
|
return editableObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
cache = new EditableDomainObjectCache(EditableDomainObjectImpl);
|
cache = new EditableDomainObjectCache(EditableDomainObjectImpl, $q);
|
||||||
|
|
||||||
return cache.getEditableObject(domainObject);
|
return cache.getEditableObject(domainObject);
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,11 @@ define(
|
|||||||
* constructor function which takes a regular domain object as
|
* constructor function which takes a regular domain object as
|
||||||
* an argument, and returns an editable domain object as its
|
* an argument, and returns an editable domain object as its
|
||||||
* result.
|
* result.
|
||||||
|
* @param $q Angular's $q, for promise handling
|
||||||
* @constructor
|
* @constructor
|
||||||
* @memberof module:editor/object/editable-domain-object-cache
|
* @memberof module:editor/object/editable-domain-object-cache
|
||||||
*/
|
*/
|
||||||
function EditableDomainObjectCache(EditableDomainObject) {
|
function EditableDomainObjectCache(EditableDomainObject, $q) {
|
||||||
var cache = new EditableModelCache(),
|
var cache = new EditableModelCache(),
|
||||||
dirty = {},
|
dirty = {},
|
||||||
root;
|
root;
|
||||||
@ -88,23 +89,20 @@ define(
|
|||||||
* Initiate a save on all objects that have been cached.
|
* Initiate a save on all objects that have been cached.
|
||||||
*/
|
*/
|
||||||
saveAll: function () {
|
saveAll: function () {
|
||||||
var object;
|
// Get a list of all dirty objects
|
||||||
|
var objects = Object.keys(dirty).map(function (k) {
|
||||||
|
return dirty[k];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clear dirty set, since we're about to save.
|
||||||
|
dirty = {};
|
||||||
|
|
||||||
// Most save logic is handled by the "editor.completion"
|
// Most save logic is handled by the "editor.completion"
|
||||||
// capability, but this in turn will typically invoke
|
// capability, so that is delegated here.
|
||||||
// Save All. An infinite loop is avoided by marking
|
return $q.all(objects.map(function (object) {
|
||||||
// objects as clean as we go.
|
// Save; pass a nonrecursive flag to avoid looping
|
||||||
|
return object.getCapability('editor').save(true);
|
||||||
while (Object.keys(dirty).length > 0) {
|
}));
|
||||||
// Pick the first dirty object
|
|
||||||
object = dirty[Object.keys(dirty)[0]];
|
|
||||||
|
|
||||||
// Mark non-dirty to avoid successive invocations
|
|
||||||
this.markClean(object);
|
|
||||||
|
|
||||||
// Invoke its save behavior
|
|
||||||
object.getCapability('editor').save();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user