mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 23:53:49 +00:00
[Toolbar] set selection initially in fixed controller and toolbar... (#1994)
* [Toolbar] set selection initially in fixed controller and toolbar... ... to make the add button appear in the toolbar when a fixed position is created. Remove selection change listener on destroy. Start a digest cycle when handling selection in toolbar to avoid delays in toolbar. Fixes #1991, #1987 * fixed checkstyle and lint errors * Fix tests * Update comment
This commit is contained in:
committed by
Pete Richards
parent
78a5ace18d
commit
75ae5ab3bb
@ -88,12 +88,6 @@ define(
|
||||
commit("Changes from toolbar.");
|
||||
}
|
||||
}
|
||||
|
||||
// Avoid attaching scope to this;
|
||||
// http://errors.angularjs.org/1.2.26/ng/cpws
|
||||
this.setSelection = function (s) {
|
||||
scope.selection = s;
|
||||
};
|
||||
this.clearExposedToolbar = function () {
|
||||
// Clear exposed toolbar state (if any)
|
||||
if (attrs.toolbar) {
|
||||
@ -110,6 +104,7 @@ define(
|
||||
this.toolbar = undefined;
|
||||
this.toolbarObject = {};
|
||||
this.openmct = openmct;
|
||||
this.scope = scope;
|
||||
|
||||
// If this representation exposes a toolbar, set up watches
|
||||
// to synchronize with it.
|
||||
@ -130,26 +125,23 @@ define(
|
||||
// Represent a domain object using this definition
|
||||
EditToolbarRepresenter.prototype.represent = function (representation) {
|
||||
// Get the newest toolbar definition from the view
|
||||
var definition = (representation || {}).toolbar || {},
|
||||
self = this;
|
||||
var definition = (representation || {}).toolbar || {};
|
||||
|
||||
// Initialize toolbar (expose object to parent scope)
|
||||
function initialize(def) {
|
||||
// If we have been asked to expose toolbar state...
|
||||
if (self.attrs.toolbar) {
|
||||
// Initialize toolbar object
|
||||
self.toolbar = new EditToolbar(def, self.commit);
|
||||
// Ensure toolbar state is exposed
|
||||
self.exposeToolbar();
|
||||
}
|
||||
// If we have been asked to expose toolbar state...
|
||||
if (this.attrs.toolbar) {
|
||||
// Initialize toolbar object
|
||||
this.toolbar = new EditToolbar(definition, this.commit);
|
||||
// Ensure toolbar state is exposed
|
||||
this.exposeToolbar();
|
||||
}
|
||||
|
||||
// Expose the toolbar object to the parent scope
|
||||
initialize(definition);
|
||||
// Create a selection scope
|
||||
this.setSelection(new EditToolbarSelection(this.openmct));
|
||||
// Initialize toolbar to an empty selection
|
||||
this.updateSelection([]);
|
||||
// Add toolbar selection to scope.
|
||||
this.scope.selection = new EditToolbarSelection(
|
||||
this.scope,
|
||||
this.openmct
|
||||
);
|
||||
// Initialize toolbar to current selection
|
||||
this.updateSelection(this.scope.selection.all());
|
||||
};
|
||||
|
||||
// Destroy; remove toolbar object from parent scope
|
||||
|
@ -38,24 +38,37 @@ define(
|
||||
* @memberof platform/commonUI/edit
|
||||
* @constructor
|
||||
*/
|
||||
function EditToolbarSelection(openmct) {
|
||||
function EditToolbarSelection($scope, openmct) {
|
||||
this.selection = [{}];
|
||||
this.selecting = false;
|
||||
this.selectedObj = undefined;
|
||||
this.openmct = openmct;
|
||||
var self = this;
|
||||
|
||||
openmct.selection.on('change', function (selection) {
|
||||
function setSelection(selection) {
|
||||
var selected = selection[0];
|
||||
|
||||
if (selected && selected.context.toolbar) {
|
||||
this.select(selected.context.toolbar);
|
||||
self.select(selected.context.toolbar);
|
||||
} else {
|
||||
this.deselect();
|
||||
self.deselect();
|
||||
}
|
||||
|
||||
if (selected && selected.context.viewProxy) {
|
||||
this.proxy(selected.context.viewProxy);
|
||||
self.proxy(selected.context.viewProxy);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
setTimeout(function () {
|
||||
$scope.$apply();
|
||||
});
|
||||
}
|
||||
|
||||
$scope.$on("$destroy", function () {
|
||||
self.openmct.selection.off('change', setSelection);
|
||||
});
|
||||
|
||||
this.openmct.selection.on('change', setSelection);
|
||||
setSelection(this.openmct.selection.get());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user