mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 07:16:39 +00:00
[Search] Break up item indexing
Use timeouts to make the generic search's item indexing not block up the page. Updated tests accordingly.
This commit is contained in:
parent
9939c809be
commit
9dd520f17b
@ -39,7 +39,7 @@
|
||||
"provides": "searchService",
|
||||
"type": "provider",
|
||||
"implementation": "services/GenericSearchProvider.js",
|
||||
"depends": [ "$q", "objectService", "workerService", "GENERIC_SEARCH_ROOTS" ]
|
||||
"depends": [ "$q", "$timeout", "objectService", "workerService", "GENERIC_SEARCH_ROOTS" ]
|
||||
},
|
||||
{
|
||||
"provides": "searchService",
|
||||
|
@ -39,6 +39,7 @@ define(
|
||||
*
|
||||
* @constructor
|
||||
* @param $q Angular's $q, for promise consolidation.
|
||||
* @param $timeout Angular's $timeout, for delayed funtion execution.
|
||||
* @param {ObjectService} objectService The service from which
|
||||
* domain objects can be gotten.
|
||||
* @param {WorkerService} workerService The service which allows
|
||||
@ -46,7 +47,7 @@ define(
|
||||
* @param {GENERIC_SEARCH_ROOTS} ROOTS An array of the root
|
||||
* domain objects' IDs.
|
||||
*/
|
||||
function GenericSearchProvider($q, objectService, workerService, ROOTS) {
|
||||
function GenericSearchProvider($q, $timeout, objectService, workerService, ROOTS) {
|
||||
var worker = workerService.run('genericSearchWorker'),
|
||||
indexed = {},
|
||||
pendingQueries = {};
|
||||
@ -132,16 +133,23 @@ define(
|
||||
indexItem(node);
|
||||
indexed[id] = true;
|
||||
|
||||
if (node.hasCapability && node.hasCapability('composition')) {
|
||||
if (node && node.hasCapability && node.hasCapability('composition')) {
|
||||
// This node has children
|
||||
node.getCapability('composition').invoke().then(function (children) {
|
||||
// Index the children
|
||||
if (children.constructor === Array) {
|
||||
indexItems(children);
|
||||
} else {
|
||||
indexItems([children]);
|
||||
}
|
||||
});
|
||||
|
||||
// Make sure that this is async, so doesn't block up page
|
||||
$timeout(function () {
|
||||
// Get the children...
|
||||
node.useCapability('composition').then(function (children) {
|
||||
$timeout(function () {
|
||||
// ... then index the children
|
||||
if (children.constructor === Array) {
|
||||
indexItems(children);
|
||||
} else {
|
||||
indexItems([children]);
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ define(
|
||||
|
||||
describe("The generic search provider ", function () {
|
||||
var mockQ,
|
||||
mockTimeout,
|
||||
mockDeferred,
|
||||
mockObjectService,
|
||||
mockObjectPromise,
|
||||
@ -57,6 +58,8 @@ define(
|
||||
mockDeferred.promise = "mock promise";
|
||||
mockQ.defer.andReturn(mockDeferred);
|
||||
|
||||
mockTimeout = jasmine.createSpy("$timeout");
|
||||
|
||||
mockObjectService = jasmine.createSpyObj(
|
||||
"objectService",
|
||||
[ "getObjects" ]
|
||||
@ -83,7 +86,7 @@ define(
|
||||
mockDomainObjects[i] = (
|
||||
jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "hasCapability", "getCapability" ]
|
||||
[ "getId", "getModel", "hasCapability", "getCapability", "useCapability" ]
|
||||
)
|
||||
);
|
||||
mockDomainObjects[i].getId.andReturn(i);
|
||||
@ -102,14 +105,17 @@ define(
|
||||
mockCapability.invoke.andReturn(mockCapabilityPromise);
|
||||
mockDomainObjects[0].getCapability.andReturn(mockCapability);
|
||||
|
||||
provider = new GenericSearchProvider(mockQ, mockObjectService, mockWorkerService, mockRoots);
|
||||
provider = new GenericSearchProvider(mockQ, mockTimeout, mockObjectService, mockWorkerService, mockRoots);
|
||||
});
|
||||
|
||||
it("indexes tree on initialization", function () {
|
||||
mockObjectPromise.then.mostRecentCall.args[0](mockDomainObjects);
|
||||
mockCapabilityPromise.then.mostRecentCall.args[0](mockDomainObjects[1]);
|
||||
|
||||
expect(mockObjectService.getObjects).toHaveBeenCalled();
|
||||
expect(mockObjectPromise.then).toHaveBeenCalled();
|
||||
|
||||
mockObjectPromise.then.mostRecentCall.args[0](mockDomainObjects);
|
||||
|
||||
//mockCapabilityPromise.then.mostRecentCall.args[0](mockDomainObjects[1]);
|
||||
|
||||
expect(mockWorker.postMessage).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user