mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 06:03:08 +00:00
[Browse] Simplify Edit Representation
Simplify edit registration and remove extra abstractions. No longer attach a status listener for every representation-- just use a single watch for the edit controller. Simplifies logic involved in switching controllers. https://github.com/nasa/openmct/issues/1360
This commit is contained in:
parent
b9601ff819
commit
0b79ec1235
@ -41,7 +41,6 @@ define([
|
|||||||
"text!./res/templates/items/items.html",
|
"text!./res/templates/items/items.html",
|
||||||
"text!./res/templates/browse/object-properties.html",
|
"text!./res/templates/browse/object-properties.html",
|
||||||
"text!./res/templates/browse/inspector-region.html",
|
"text!./res/templates/browse/inspector-region.html",
|
||||||
"text!./res/templates/view-object.html",
|
|
||||||
'legacyRegistry'
|
'legacyRegistry'
|
||||||
], function (
|
], function (
|
||||||
BrowseController,
|
BrowseController,
|
||||||
@ -64,7 +63,6 @@ define([
|
|||||||
itemsTemplate,
|
itemsTemplate,
|
||||||
objectPropertiesTemplate,
|
objectPropertiesTemplate,
|
||||||
inspectorRegionTemplate,
|
inspectorRegionTemplate,
|
||||||
viewObjectTemplate,
|
|
||||||
legacyRegistry
|
legacyRegistry
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@ -141,10 +139,6 @@ define([
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"representations": [
|
"representations": [
|
||||||
{
|
|
||||||
"key": "view-object",
|
|
||||||
"template": viewObjectTemplate
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"key": "browse-object",
|
"key": "browse-object",
|
||||||
"template": browseObjectTemplate,
|
"template": browseObjectTemplate,
|
||||||
|
@ -63,7 +63,7 @@
|
|||||||
<mct-split-pane class='l-object-and-inspector contents abs' anchor='right'>
|
<mct-split-pane class='l-object-and-inspector contents abs' anchor='right'>
|
||||||
<div class='split-pane-component t-object pane primary-pane left'>
|
<div class='split-pane-component t-object pane primary-pane left'>
|
||||||
<mct-representation mct-object="navigatedObject"
|
<mct-representation mct-object="navigatedObject"
|
||||||
key="'view-object'"
|
key="navigatedObject.getCapability('status').get('editing') ? 'edit-object' : 'browse-object'"
|
||||||
class="abs holder holder-object">
|
class="abs holder holder-object">
|
||||||
</mct-representation>
|
</mct-representation>
|
||||||
<a class="mini-tab-icon anchor-right mobile-hide toggle-pane toggle-inspect flush-right"
|
<a class="mini-tab-icon anchor-right mobile-hide toggle-pane toggle-inspect flush-right"
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
<!--
|
|
||||||
Open MCT, Copyright (c) 2014-2016, United States Government
|
|
||||||
as represented by the Administrator of the National Aeronautics and Space
|
|
||||||
Administration. All rights reserved.
|
|
||||||
|
|
||||||
Open MCT is licensed under the Apache License, Version 2.0 (the
|
|
||||||
"License"); you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0.
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
License for the specific language governing permissions and limitations
|
|
||||||
under the License.
|
|
||||||
|
|
||||||
Open MCT includes source code licensed under additional open source
|
|
||||||
licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
||||||
this source code distribution or the Licensing information page available
|
|
||||||
at runtime from the About dialog for additional information.
|
|
||||||
-->
|
|
||||||
<!--
|
|
||||||
A representation that allows the 'View' region of an object view to change
|
|
||||||
dynamically (eg. between browse and edit modes). Values correspond to a
|
|
||||||
representation key, and currently defaults to 'browse-object'.
|
|
||||||
|
|
||||||
In the case of edit, the EditRepresenter will change this to editable
|
|
||||||
representation of the object as needed.
|
|
||||||
-->
|
|
||||||
<mct-representation mct-object="domainObject"
|
|
||||||
key="viewObjectTemplate || 'browse-object'"
|
|
||||||
class="abs holder">
|
|
||||||
</mct-representation>
|
|
@ -47,7 +47,6 @@ define(
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.listenHandle = undefined;
|
|
||||||
|
|
||||||
// Mutate and persist a new version of a domain object's model.
|
// Mutate and persist a new version of a domain object's model.
|
||||||
function doMutate(model) {
|
function doMutate(model) {
|
||||||
@ -90,51 +89,15 @@ define(
|
|||||||
// Place the "commit" method in the scope
|
// Place the "commit" method in the scope
|
||||||
scope.commit = commit;
|
scope.commit = commit;
|
||||||
|
|
||||||
// Clean up when the scope is destroyed
|
|
||||||
scope.$on("$destroy", function () {
|
|
||||||
self.destroy();
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle a specific representation of a specific domain object
|
// Handle a specific representation of a specific domain object
|
||||||
EditRepresenter.prototype.represent = function represent(representation, representedObject) {
|
EditRepresenter.prototype.represent = function (representation, representedObject) {
|
||||||
var scope = this.scope;
|
|
||||||
|
|
||||||
// Track the key, to know which view configuration to save to.
|
|
||||||
this.key = (representation || {}).key;
|
|
||||||
// Track the represented object
|
|
||||||
this.domainObject = representedObject;
|
this.domainObject = representedObject;
|
||||||
|
|
||||||
// Ensure existing watches are released
|
|
||||||
this.destroy();
|
|
||||||
|
|
||||||
function setEditing() {
|
|
||||||
scope.viewObjectTemplate = 'edit-object';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listen for changes in object state. If the object becomes
|
|
||||||
* editable then change the view and inspector regions
|
|
||||||
* object representation accordingly
|
|
||||||
*/
|
|
||||||
this.listenHandle = this.domainObject.getCapability('status').listen(function (statuses) {
|
|
||||||
if (statuses.indexOf('editing') !== -1) {
|
|
||||||
setEditing();
|
|
||||||
} else {
|
|
||||||
delete scope.viewObjectTemplate;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (representedObject.hasCapability('editor') && representedObject.getCapability('editor').isEditContextRoot()) {
|
|
||||||
setEditing();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Respond to the destruction of the current representation.
|
// Respond to the destruction of the current representation.
|
||||||
EditRepresenter.prototype.destroy = function destroy() {
|
EditRepresenter.prototype.destroy = function () {};
|
||||||
return this.listenHandle && this.listenHandle();
|
|
||||||
};
|
|
||||||
|
|
||||||
return EditRepresenter;
|
return EditRepresenter;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user