mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 07:16:39 +00:00
[Search] Index checks for changes
When indexing items initially, the generic provider listens for mutations in case an item's composition changes, so it can then index the new children.
This commit is contained in:
parent
e0a0d293fa
commit
ee2d7efae2
@ -124,14 +124,15 @@ define(
|
|||||||
// Helper function for getItems(). Indexes the tree.
|
// Helper function for getItems(). Indexes the tree.
|
||||||
function indexItems(nodes) {
|
function indexItems(nodes) {
|
||||||
nodes.forEach(function (node) {
|
nodes.forEach(function (node) {
|
||||||
var id = node.getId();
|
var id = node && node.getId && node.getId();
|
||||||
|
|
||||||
|
// If we have not yet indexed this item, index it
|
||||||
if (!indexed[id]) {
|
if (!indexed[id]) {
|
||||||
// Index each item with the web worker
|
// Index each item with the web worker
|
||||||
indexItem(node);
|
indexItem(node);
|
||||||
indexed[id] = true;
|
indexed[id] = true;
|
||||||
|
|
||||||
if (node.hasCapability('composition')) {
|
if (node.hasCapability && node.hasCapability('composition')) {
|
||||||
// This node has children
|
// This node has children
|
||||||
node.getCapability('composition').invoke().then(function (children) {
|
node.getCapability('composition').invoke().then(function (children) {
|
||||||
// Index the children
|
// Index the children
|
||||||
@ -143,6 +144,26 @@ define(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watch for changes to this item, in case it gets new children
|
||||||
|
if (node && node.hasCapability && node.hasCapability('mutation')) {
|
||||||
|
node.getCapability('mutation').listen(function (listener) {
|
||||||
|
if (listener && listener.composition) {
|
||||||
|
// If the node was mutated to have children, get the child domain objects
|
||||||
|
objectService.getObjects(listener.composition).then(function (objectsById) {
|
||||||
|
var objects = [],
|
||||||
|
id;
|
||||||
|
|
||||||
|
// Get each of the domain objects in objectsById
|
||||||
|
for (id in objectsById) {
|
||||||
|
objects.push(objectsById[id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
indexItems(objects);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user