mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 13:17:53 +00:00
[Search] Use new composition in search
Use private parts of new composition API for generic search indexer so that all objects are properly accessible in search results. Also prevent ROOT object from getting indexed but still traverse composition. That way, "The root object" no longer shows in search results. Update tests to cover changes. Fixes #1579
This commit is contained in:
parent
cc9a2cbf4f
commit
9956ce31e5
@ -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;
|
||||
|
||||
if (id !== 'ROOT') {
|
||||
this.worker.postMessage({
|
||||
request: 'index',
|
||||
model: model,
|
||||
id: id
|
||||
});
|
||||
|
||||
if (Array.isArray(model.composition)) {
|
||||
model.composition.forEach(function (idToIndex) {
|
||||
provider.scheduleForIndexing(idToIndex);
|
||||
});
|
||||
}
|
||||
|
||||
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,9 +226,26 @@ 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(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)
|
||||
@ -218,6 +253,18 @@ define([
|
||||
});
|
||||
});
|
||||
|
||||
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: ''}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('beginIndexRequest', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
|
Loading…
Reference in New Issue
Block a user