mirror of
https://github.com/nasa/openmct.git
synced 2025-05-06 10:38:23 +00:00
[Browse] Fix tree node autoexpand/highlighting
Repair tree node auto-expand/highlight behavior, to address WTD-627. Specifically: * Check the full path when deciding to highlight, instead of just the parent. This avoids duplicate highlighting in cases where the same parent is visible in two subtrees. * Don't make a redundant getId call in path-checking; domain object paths have already been mapped to identifier paths at this point. This avoids erroneous auto-expansion of the whole tree.
This commit is contained in:
parent
921aad9e2f
commit
4d94ab6fd6
@ -40,21 +40,6 @@ define(
|
|||||||
return obj && obj.getId && obj.getId();
|
return obj && obj.getId && obj.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if two domain objects have the same ID
|
|
||||||
function idsEqual(objA, objB) {
|
|
||||||
return getId(objA) === getId(objB);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the parent of a domain object, as reported by
|
|
||||||
// its context capability. This is used to distinguish
|
|
||||||
// two different instances of a domain object that have
|
|
||||||
// been reached in different ways.
|
|
||||||
function parentOf(domainObject) {
|
|
||||||
var context = domainObject &&
|
|
||||||
domainObject.getCapability("context");
|
|
||||||
return context && context.getParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify that id paths are equivalent, staring at
|
// Verify that id paths are equivalent, staring at
|
||||||
// index, ending at the end of the node path.
|
// index, ending at the end of the node path.
|
||||||
function checkPath(nodePath, navPath, index) {
|
function checkPath(nodePath, navPath, index) {
|
||||||
@ -66,30 +51,10 @@ define(
|
|||||||
// a recursive step for subsequent ids in the paths,
|
// a recursive step for subsequent ids in the paths,
|
||||||
// until we exceed path length or hit a mismatch.
|
// until we exceed path length or hit a mismatch.
|
||||||
return (index >= nodePath.length) ||
|
return (index >= nodePath.length) ||
|
||||||
(idsEqual(navPath[index], nodePath[index]) &&
|
((navPath[index] === nodePath[index]) &&
|
||||||
checkPath(nodePath, navPath, index + 1));
|
checkPath(nodePath, navPath, index + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the navigated object is in the subtree of this
|
|
||||||
// node's domain object, by comparing the paths reported
|
|
||||||
// by their context capability.
|
|
||||||
function isOnSelectionPath(nodeObject, navObject) {
|
|
||||||
var nodeContext = nodeObject &&
|
|
||||||
nodeObject.getCapability('context'),
|
|
||||||
navContext = navObject &&
|
|
||||||
navObject.getCapability('context'),
|
|
||||||
nodePath,
|
|
||||||
navPath;
|
|
||||||
|
|
||||||
if (nodeContext && navContext) {
|
|
||||||
nodePath = nodeContext.getPath().map(getId);
|
|
||||||
navPath = navContext.getPath().map(getId);
|
|
||||||
return (navPath.length > nodePath.length) &&
|
|
||||||
checkPath(nodePath, navPath);
|
|
||||||
}
|
|
||||||
return false; // No context to judge by
|
|
||||||
}
|
|
||||||
|
|
||||||
// Track that a node has been expanded, either by the
|
// Track that a node has been expanded, either by the
|
||||||
// user or automatically to show a selection.
|
// user or automatically to show a selection.
|
||||||
function trackExpansion() {
|
function trackExpansion() {
|
||||||
@ -104,25 +69,49 @@ define(
|
|||||||
// Consider the currently-navigated object and update
|
// Consider the currently-navigated object and update
|
||||||
// parameters which support display.
|
// parameters which support display.
|
||||||
function checkSelection() {
|
function checkSelection() {
|
||||||
var nodeObject = $scope.domainObject;
|
var nodeObject = $scope.domainObject,
|
||||||
|
navObject = selectedObject,
|
||||||
|
nodeContext = nodeObject &&
|
||||||
|
nodeObject.getCapability('context'),
|
||||||
|
navContext = navObject &&
|
||||||
|
navObject.getCapability('context'),
|
||||||
|
nodePath,
|
||||||
|
navPath;
|
||||||
|
|
||||||
// Check if we are the navigated object. Check the parent
|
// Deselect; we will reselect below, iff we are
|
||||||
// as well to make sure we are the same instance of the
|
// exactly at the end of the path.
|
||||||
// navigated object.
|
isSelected = false;
|
||||||
isSelected =
|
|
||||||
idsEqual(nodeObject, selectedObject) &&
|
|
||||||
idsEqual(parentOf(nodeObject), parentOf(selectedObject));
|
|
||||||
|
|
||||||
// Expand if necessary (if the navigated object will
|
// Expand if necessary (if the navigated object will
|
||||||
// be in this node's subtree)
|
// be in this node's subtree)
|
||||||
if (isOnSelectionPath(nodeObject, selectedObject) &&
|
if (nodeContext && navContext) {
|
||||||
$scope.toggle !== undefined) {
|
// Get the paths as arrays of identifiers
|
||||||
|
nodePath = nodeContext.getPath().map(getId);
|
||||||
|
navPath = navContext.getPath().map(getId);
|
||||||
|
|
||||||
|
// Check to see if the node's path lies entirely
|
||||||
|
// within the navigation path; otherwise, navigation
|
||||||
|
// has happened in some other subtree.
|
||||||
|
if (navPath.length >= nodePath.length &&
|
||||||
|
checkPath(nodePath, navPath)) {
|
||||||
|
|
||||||
|
// nodePath is along the navPath; if it's
|
||||||
|
// at the end of the path, highlight;
|
||||||
|
// otherwise, expand.
|
||||||
|
if (nodePath.length === navPath.length) {
|
||||||
|
isSelected = true;
|
||||||
|
} else { // node path is shorter: Expand!
|
||||||
|
if ($scope.toggle) {
|
||||||
$scope.toggle.setState(true);
|
$scope.toggle.setState(true);
|
||||||
|
}
|
||||||
trackExpansion();
|
trackExpansion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback for the navigation service; track the currently
|
// Callback for the selection updates; track the currently
|
||||||
// navigated object and update display parameters as needed.
|
// navigated object and update display parameters as needed.
|
||||||
function setSelection(object) {
|
function setSelection(object) {
|
||||||
selectedObject = object;
|
selectedObject = object;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user