mirror of
https://github.com/nasa/openmct.git
synced 2025-03-05 05:19:38 +00:00
[Fixed Position] Implement remove
Implement remove button for selected elements in fixed position view. WTD-879.
This commit is contained in:
parent
f66fb0a32d
commit
5680710c06
platform
commonUI/edit/src/representers
features/layout/src
@ -17,9 +17,10 @@ define(
|
|||||||
*
|
*
|
||||||
* @param structure toolbar structure, as provided by view definition
|
* @param structure toolbar structure, as provided by view definition
|
||||||
* @param {Array} selection the current selection state
|
* @param {Array} selection the current selection state
|
||||||
|
* @param {Function} commit callback to invoke after changes
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function EditToolbar(structure, selection) {
|
function EditToolbar(structure, selection, commit) {
|
||||||
var toolbarStructure = Object.create(structure || {}),
|
var toolbarStructure = Object.create(structure || {}),
|
||||||
toolbarState,
|
toolbarState,
|
||||||
properties = [];
|
properties = [];
|
||||||
@ -124,11 +125,14 @@ define(
|
|||||||
// Invoke all functions in selections with the given name
|
// Invoke all functions in selections with the given name
|
||||||
function invoke(method, value) {
|
function invoke(method, value) {
|
||||||
if (method) {
|
if (method) {
|
||||||
|
// Make the change in the selection
|
||||||
selection.forEach(function (selected) {
|
selection.forEach(function (selected) {
|
||||||
if (typeof selected[method] === 'function') {
|
if (typeof selected[method] === 'function') {
|
||||||
selected[method](value);
|
selected[method](value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// ...and commit!
|
||||||
|
commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +143,9 @@ define(
|
|||||||
converted.key = addKey(item.property);
|
converted.key = addKey(item.property);
|
||||||
}
|
}
|
||||||
if (item.method) {
|
if (item.method) {
|
||||||
converted.click = function (v) { invoke(item.method, v); };
|
converted.click = function (v) {
|
||||||
|
invoke(item.method, v);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return converted;
|
return converted;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,13 @@ define(
|
|||||||
toolbar,
|
toolbar,
|
||||||
toolbarObject = {};
|
toolbarObject = {};
|
||||||
|
|
||||||
|
// Mark changes as ready to persist
|
||||||
|
function commit(message) {
|
||||||
|
if (scope.commit) {
|
||||||
|
scope.commit(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle changes to the current selection
|
// Handle changes to the current selection
|
||||||
function updateSelection(selection) {
|
function updateSelection(selection) {
|
||||||
// Make sure selection is array-like
|
// Make sure selection is array-like
|
||||||
@ -28,7 +35,7 @@ define(
|
|||||||
(selection ? [selection] : []);
|
(selection ? [selection] : []);
|
||||||
|
|
||||||
// Instantiate a new toolbar...
|
// Instantiate a new toolbar...
|
||||||
toolbar = new EditToolbar(definition, selection);
|
toolbar = new EditToolbar(definition, selection, commit);
|
||||||
|
|
||||||
// ...and expose its structure/state
|
// ...and expose its structure/state
|
||||||
toolbarObject.structure = toolbar.getStructure();
|
toolbarObject.structure = toolbar.getStructure();
|
||||||
@ -37,6 +44,7 @@ define(
|
|||||||
|
|
||||||
// Update selection models to match changed toolbar state
|
// Update selection models to match changed toolbar state
|
||||||
function updateState(state) {
|
function updateState(state) {
|
||||||
|
// Update underlying state based on toolbar changes
|
||||||
state.forEach(function (value, index) {
|
state.forEach(function (value, index) {
|
||||||
toolbar.updateState(index, value);
|
toolbar.updateState(index, value);
|
||||||
});
|
});
|
||||||
|
@ -93,8 +93,28 @@ define(
|
|||||||
|
|
||||||
// Decorate elements in the current configuration
|
// Decorate elements in the current configuration
|
||||||
function refreshElements() {
|
function refreshElements() {
|
||||||
elementProxies = (($scope.configuration || {}).elements || [])
|
// Cache selection; we are instantiating new proxies
|
||||||
.map(makeProxyElement);
|
// so we may want to restore this.
|
||||||
|
var selected = selection && selection.get(),
|
||||||
|
elements = (($scope.configuration || {}).elements || []),
|
||||||
|
index = -1; // Start with a 'not-found' value
|
||||||
|
|
||||||
|
// Find the selection in the new array
|
||||||
|
if (selected !== undefined) {
|
||||||
|
index = elements.indexOf(selected.element);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the new proxies...
|
||||||
|
elementProxies = elements.map(makeProxyElement);
|
||||||
|
|
||||||
|
// Clear old selection, and restore if appropriate
|
||||||
|
if (selection) {
|
||||||
|
selection.deselect();
|
||||||
|
if (index > -1) {
|
||||||
|
selection.select(elementProxies[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Ensure elements for all domain objects?
|
// TODO: Ensure elements for all domain objects?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,11 @@ define(
|
|||||||
return (obj === selected) || (obj === proxy);
|
return (obj === selected) || (obj === proxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Getter for current selection
|
||||||
|
function get() {
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
// Start with the proxy selected
|
// Start with the proxy selected
|
||||||
selection.push(proxy);
|
selection.push(proxy);
|
||||||
|
|
||||||
@ -95,6 +100,11 @@ define(
|
|||||||
* @returns {boolean} true if selection changed
|
* @returns {boolean} true if selection changed
|
||||||
*/
|
*/
|
||||||
deselect: deselect,
|
deselect: deselect,
|
||||||
|
/**
|
||||||
|
* Get the currently-selected object.
|
||||||
|
* @returns the currently selected object
|
||||||
|
*/
|
||||||
|
get: get,
|
||||||
/**
|
/**
|
||||||
* Clear the selection, including the proxy, and dispose
|
* Clear the selection, including the proxy, and dispose
|
||||||
* of this selection scope. No other calls to methods on
|
* of this selection scope. No other calls to methods on
|
||||||
|
@ -17,6 +17,7 @@ define(
|
|||||||
*/
|
*/
|
||||||
function ElementProxy(element, index, elements) {
|
function ElementProxy(element, index, elements) {
|
||||||
return {
|
return {
|
||||||
|
element: element,
|
||||||
x: new Accessor(element, 'x'),
|
x: new Accessor(element, 'x'),
|
||||||
y: new Accessor(element, 'y'),
|
y: new Accessor(element, 'y'),
|
||||||
z: new Accessor(element, 'z'),
|
z: new Accessor(element, 'z'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user