mirror of
https://github.com/nasa/openmct.git
synced 2025-04-10 12:50:15 +00:00
Merge pull request #1587 from nasa/fix-search-indexing
[Search] Use new composition in search
This commit is contained in:
commit
0fa5609396
@ -100,7 +100,8 @@ define([
|
||||
"modelService",
|
||||
"workerService",
|
||||
"topic",
|
||||
"GENERIC_SEARCH_ROOTS"
|
||||
"GENERIC_SEARCH_ROOTS",
|
||||
"openmct"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -25,9 +25,11 @@
|
||||
* Module defining GenericSearchProvider. Created by shale on 07/16/2015.
|
||||
*/
|
||||
define([
|
||||
|
||||
'../../../../src/api/objects/object-utils',
|
||||
'lodash'
|
||||
], function (
|
||||
|
||||
objectUtils,
|
||||
_
|
||||
) {
|
||||
|
||||
/**
|
||||
@ -42,11 +44,12 @@ define([
|
||||
* @param {TopicService} topic the topic service.
|
||||
* @param {Array} ROOTS An array of object Ids to begin indexing.
|
||||
*/
|
||||
function GenericSearchProvider($q, $log, modelService, workerService, topic, ROOTS) {
|
||||
function GenericSearchProvider($q, $log, modelService, workerService, topic, ROOTS, openmct) {
|
||||
var provider = this;
|
||||
this.$q = $q;
|
||||
this.$log = $log;
|
||||
this.modelService = modelService;
|
||||
this.openmct = openmct;
|
||||
|
||||
this.indexedIds = {};
|
||||
this.idsToIndex = [];
|
||||
@ -171,17 +174,29 @@ define([
|
||||
GenericSearchProvider.prototype.index = function (id, model) {
|
||||
var provider = this;
|
||||
|
||||
this.worker.postMessage({
|
||||
request: 'index',
|
||||
model: model,
|
||||
id: id
|
||||
});
|
||||
|
||||
if (Array.isArray(model.composition)) {
|
||||
model.composition.forEach(function (idToIndex) {
|
||||
provider.scheduleForIndexing(idToIndex);
|
||||
if (id !== 'ROOT') {
|
||||
this.worker.postMessage({
|
||||
request: 'index',
|
||||
model: model,
|
||||
id: id
|
||||
});
|
||||
}
|
||||
|
||||
var domainObject = objectUtils.toNewFormat(model, id);
|
||||
var composition = _.find(this.openmct.composition.registry, function (p) {
|
||||
return p.appliesTo(domainObject);
|
||||
});
|
||||
|
||||
if (!composition) {
|
||||
return;
|
||||
}
|
||||
|
||||
composition.load(domainObject)
|
||||
.then(function (children) {
|
||||
children.forEach(function (child) {
|
||||
provider.scheduleForIndexing(objectUtils.makeKeyString(child));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -39,6 +39,8 @@ define([
|
||||
topic,
|
||||
mutationTopic,
|
||||
ROOTS,
|
||||
compositionProvider,
|
||||
openmct,
|
||||
provider;
|
||||
|
||||
beforeEach(function () {
|
||||
@ -77,6 +79,21 @@ define([
|
||||
ROOTS = [
|
||||
'mine'
|
||||
];
|
||||
compositionProvider = jasmine.createSpyObj(
|
||||
'compositionProvider',
|
||||
['load', 'appliesTo']
|
||||
);
|
||||
compositionProvider.load.andCallFake(function (domainObject) {
|
||||
return Promise.resolve(domainObject.composition);
|
||||
});
|
||||
compositionProvider.appliesTo.andCallFake(function (domainObject) {
|
||||
return !!domainObject.composition;
|
||||
});
|
||||
openmct = {
|
||||
composition: {
|
||||
registry: [compositionProvider]
|
||||
}
|
||||
};
|
||||
|
||||
spyOn(GenericSearchProvider.prototype, 'scheduleForIndexing');
|
||||
|
||||
@ -86,7 +103,8 @@ define([
|
||||
modelService,
|
||||
workerService,
|
||||
topic,
|
||||
ROOTS
|
||||
ROOTS,
|
||||
openmct
|
||||
);
|
||||
});
|
||||
|
||||
@ -208,13 +226,42 @@ define([
|
||||
|
||||
it('schedules composed ids for indexing', function () {
|
||||
var id = 'anId',
|
||||
model = {composition: ['abc', 'def']};
|
||||
model = {composition: ['abc', 'def']},
|
||||
calls = provider.scheduleForIndexing.calls.length;
|
||||
|
||||
provider.index(id, model);
|
||||
expect(provider.scheduleForIndexing)
|
||||
.toHaveBeenCalledWith('abc');
|
||||
expect(provider.scheduleForIndexing)
|
||||
.toHaveBeenCalledWith('def');
|
||||
|
||||
expect(compositionProvider.appliesTo).toHaveBeenCalledWith({
|
||||
identifier: {key: 'anId', namespace: ''},
|
||||
composition: [jasmine.any(Object), jasmine.any(Object)]
|
||||
});
|
||||
|
||||
expect(compositionProvider.load).toHaveBeenCalledWith({
|
||||
identifier: {key: 'anId', namespace: ''},
|
||||
composition: [jasmine.any(Object), jasmine.any(Object)]
|
||||
});
|
||||
|
||||
waitsFor(function () {
|
||||
return provider.scheduleForIndexing.calls.length > calls;
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
expect(provider.scheduleForIndexing)
|
||||
.toHaveBeenCalledWith('abc');
|
||||
expect(provider.scheduleForIndexing)
|
||||
.toHaveBeenCalledWith('def');
|
||||
});
|
||||
});
|
||||
|
||||
it('does not index ROOT, but checks composition', function () {
|
||||
var id = 'ROOT',
|
||||
model = {};
|
||||
|
||||
provider.index(id, model);
|
||||
expect(worker.postMessage).not.toHaveBeenCalled();
|
||||
expect(compositionProvider.appliesTo).toHaveBeenCalledWith({
|
||||
identifier: {key: 'ROOT', namespace: ''}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user