mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 14:48:13 +00:00
[Layout] Add commit to scope
Add a commit function to scope from the edit representer; this avoids issues trying to transparently detect and persist changes made during edit mode, while still requiring only minimal action from individual views. WTD-535.
This commit is contained in:
@ -93,7 +93,7 @@
|
|||||||
"representers": [
|
"representers": [
|
||||||
{
|
{
|
||||||
"implementation": "EditRepresenter.js",
|
"implementation": "EditRepresenter.js",
|
||||||
"depends": [ "$q" ]
|
"depends": [ "$q", "$log" ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,8 @@ define(
|
|||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function EditRepresenter($q, scope) {
|
function EditRepresenter($q, $log, scope) {
|
||||||
var watches = [],
|
var domainObject,
|
||||||
domainObject,
|
|
||||||
key;
|
key;
|
||||||
|
|
||||||
// Mutate and persist a new version of a domain object's model.
|
// Mutate and persist a new version of a domain object's model.
|
||||||
@ -40,12 +39,20 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle changes to model and/or view configuration
|
// Handle changes to model and/or view configuration
|
||||||
function update() {
|
function commit(message) {
|
||||||
// Look up from scope; these will have been populated by
|
// Look up from scope; these will have been populated by
|
||||||
// mct-representation.
|
// mct-representation.
|
||||||
var model = scope.model,
|
var model = scope.model,
|
||||||
configuration = scope.configuration;
|
configuration = scope.configuration;
|
||||||
|
|
||||||
|
// Log the commit message
|
||||||
|
$log.debug([
|
||||||
|
"Committing ",
|
||||||
|
domainObject && domainObject.getModel().name,
|
||||||
|
"(" + (domainObject && domainObject.getId()) + "):",
|
||||||
|
message
|
||||||
|
].join(" "));
|
||||||
|
|
||||||
// Update the configuration stored in the model, and persist.
|
// Update the configuration stored in the model, and persist.
|
||||||
if (domainObject && domainObject.hasCapability("persistence")) {
|
if (domainObject && domainObject.hasCapability("persistence")) {
|
||||||
// Configurations for specific views are stored by
|
// Configurations for specific views are stored by
|
||||||
@ -60,9 +67,7 @@ define(
|
|||||||
|
|
||||||
// Respond to the destruction of the current representation.
|
// Respond to the destruction of the current representation.
|
||||||
function destroy() {
|
function destroy() {
|
||||||
// Stop watching for changes
|
// No op
|
||||||
watches.forEach(function (deregister) { deregister(); });
|
|
||||||
watches = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle a specific representation of a specific domain object
|
// Handle a specific representation of a specific domain object
|
||||||
@ -74,16 +79,11 @@ define(
|
|||||||
|
|
||||||
// Ensure existing watches are released
|
// Ensure existing watches are released
|
||||||
destroy();
|
destroy();
|
||||||
|
|
||||||
// Watch for changes to model or configuration; keep the
|
|
||||||
// results, as $watch returns an de-registration function.
|
|
||||||
// Use the "editor" capability to check if we are in Edit mode.
|
|
||||||
watches = representedObject.hasCapability("editor") ? [
|
|
||||||
scope.$watch("model", update, true),
|
|
||||||
scope.$watch("configuration", update, true)
|
|
||||||
] : [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Place the "commit" method in the scope
|
||||||
|
scope.commit = commit;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
* Set the current representation in use, and the domain
|
* Set the current representation in use, and the domain
|
||||||
|
@ -158,6 +158,10 @@ define(
|
|||||||
// Store the position of this panel.
|
// Store the position of this panel.
|
||||||
$scope.configuration.panels[activeDragId] =
|
$scope.configuration.panels[activeDragId] =
|
||||||
rawPositions[activeDragId];
|
rawPositions[activeDragId];
|
||||||
|
// Mark this object as dirty to encourage persistence
|
||||||
|
if ($scope.commit) {
|
||||||
|
$scope.commit("Moved frame.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user