mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 19:27:07 +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:
parent
5faf81e9a5
commit
3f41dc716f
@ -93,7 +93,7 @@
|
||||
"representers": [
|
||||
{
|
||||
"implementation": "EditRepresenter.js",
|
||||
"depends": [ "$q" ]
|
||||
"depends": [ "$q", "$log" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -22,9 +22,8 @@ define(
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
function EditRepresenter($q, scope) {
|
||||
var watches = [],
|
||||
domainObject,
|
||||
function EditRepresenter($q, $log, scope) {
|
||||
var domainObject,
|
||||
key;
|
||||
|
||||
// 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
|
||||
function update() {
|
||||
function commit(message) {
|
||||
// Look up from scope; these will have been populated by
|
||||
// mct-representation.
|
||||
var model = scope.model,
|
||||
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.
|
||||
if (domainObject && domainObject.hasCapability("persistence")) {
|
||||
// Configurations for specific views are stored by
|
||||
@ -60,9 +67,7 @@ define(
|
||||
|
||||
// Respond to the destruction of the current representation.
|
||||
function destroy() {
|
||||
// Stop watching for changes
|
||||
watches.forEach(function (deregister) { deregister(); });
|
||||
watches = [];
|
||||
// No op
|
||||
}
|
||||
|
||||
// Handle a specific representation of a specific domain object
|
||||
@ -74,16 +79,11 @@ define(
|
||||
|
||||
// Ensure existing watches are released
|
||||
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 {
|
||||
/**
|
||||
* Set the current representation in use, and the domain
|
||||
|
@ -158,6 +158,10 @@ define(
|
||||
// Store the position of this panel.
|
||||
$scope.configuration.panels[activeDragId] =
|
||||
rawPositions[activeDragId];
|
||||
// Mark this object as dirty to encourage persistence
|
||||
if ($scope.commit) {
|
||||
$scope.commit("Moved frame.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user