Commit f5076143 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

plugin api allows to tigger search on the map

parent 7aa060dc
......@@ -8,6 +8,7 @@ minerva (12.3.0~alpha.0) unstable; urgency=low
* Small improvement: Left logo is configurable (#731)
* Small improvement: Plugin API provides list of overview images (#702)
* Small improvement: Plugin API allows to show/hide overview images (#702)
* Small improvement: Plugin API allows to trigger search on the map (#702)
* Bug fix: progress bar of gene genome mapping upload is refreshing properly
(#728)
......
"use strict";
var Annotation = require('../map/data/Annotation');
var Chemical = require('../map/data/Chemical');
var Drug = require('../map/data/Drug');
var IdentifiedElement = require('../map/data/IdentifiedElement');
var MiRna = require('../map/data/MiRna');
var UserDbOverlay = require('../map/overlay/UserDbOverlay');
var SearchDbOverlay = require('../map/overlay/SearchDbOverlay');
var Configuration = require('../Configuration');
var Bounds = require('../map/canvas/Bounds');
......@@ -61,6 +65,7 @@ var Promise = require("bluebird");
* @property {(function(*): *)} setZoom
* @property {(function(*): number)} getZoom
* @property {(function(*): PromiseLike)} openMap
* @property {function({dbOverlayName: string, [query]:string, [perfect]: boolean, [fitBounds]:boolean, [coordinates]:Point}): Promise|PromiseLike} triggerSearch
*/
......@@ -98,10 +103,20 @@ function getFullElements(customMap, identifiedElements) {
identifiedElements,
function (item) {
if (item.length === undefined) {
return customMap.getSubmapById(item.getModelId()).getModel().getByIdentifiedElement(item, true).then(
function (fullElement) {
result.push(fullElement);
});
if (item instanceof IdentifiedElement) {
return customMap.getSubmapById(item.getModelId()).getModel().getByIdentifiedElement(item, true).then(
function (fullElement) {
result.push(fullElement);
});
} else if (item instanceof Drug) {
result.push(new Drug(item));
} else if (item instanceof Chemical) {
result.push(new Chemical(item));
} else if (item instanceof MiRna) {
result.push(new MiRna(item));
} else {
return Promise.reject(new Error("Unknown object type: " + item.constructor.name));
}
} else {
return getFullElements(customMap, item).then(function (resultRow) {
result.push(resultRow);
......@@ -417,6 +432,37 @@ function createProjectMap(options) {
var listenersData = [];
return {
/**
*
* @param {Object} params
* @param {string} params.dbOverlayName
* @param {string} [params.query]
* @param {boolean} [params.perfect]
* @param {boolean} [params.fitBounds]
* @param {Point} [params.coordinates]
* @param {number} [params.modelId]
* @param {number} [params.zoom]
*
*
* @return {Promise|PromiseLike}
*/
triggerSearch: function (params) {
var dbOverlay = getOverlayByName(map, params.dbOverlayName);
if (params.query !== undefined) {
return dbOverlay.searchByQuery(params.query, params.perfect, params.fitBounds);
} else if (dbOverlay instanceof SearchDbOverlay) {
return dbOverlay.searchByCoordinates({
coordinates: params.coordinates,
modelId: params.modelId,
fitBounds: params.fitBounds,
zoom: params.zoom
});
} else {
return Promise.reject(new Error("Don't know how to handle your query"));
}
},
getVisibleDataOverlays: function () {
return map.getVisibleDataOverlays();
},
......
......@@ -923,4 +923,134 @@ describe('MinervaPluginProxy', function () {
});
});
});
describe('triggerSearch', function () {
describe('general', function () {
it('query search', function () {
var callbackOk = false;
var map;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
var proxy = createProxy(map);
proxy.project.map.addListener({
dbOverlayName: "search",
type: "onSearch",
callback: function (elements) {
assert.ok(elements.length > 0);
callbackOk = true;
}
});
return proxy.project.map.triggerSearch({query: "s1", dbOverlayName: "search"});
}).then(function () {
assert.ok(callbackOk);
return map.destroy();
});
});
it('coordinates search', function () {
var callbackOk = false;
var map;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
var proxy = createProxy(map);
proxy.project.map.addListener({
dbOverlayName: "search",
type: "onSearch",
callback: function (elements) {
assert.ok(elements.length > 0);
callbackOk = true;
}
});
return proxy.project.map.triggerSearch({
coordinates: new Point(316.05, 253.61),
modelId: map.getModel().getId(),
dbOverlayName: "search",
zoom: 2
});
}).then(function () {
assert.ok(callbackOk);
return map.destroy();
});
});
});
describe('drug', function () {
it('query search', function () {
var callbackOk = false;
var map;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createDrugDbOverlay(map);
var proxy = createProxy(map);
proxy.project.map.addListener({
dbOverlayName: "drug",
type: "onSearch",
callback: function (elements) {
assert.ok(elements.length > 0);
callbackOk = true;
}
});
return proxy.project.map.triggerSearch({query: "aspirin", dbOverlayName: "drug"});
}).then(function () {
assert.ok(callbackOk);
return map.destroy();
});
});
});
describe('chemical', function () {
it('query search', function () {
var callbackOk = false;
var map;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createChemicalDbOverlay(map);
var proxy = createProxy(map);
proxy.project.map.addListener({
dbOverlayName: "chemical",
type: "onSearch",
callback: function (elements) {
assert.ok(elements.length > 0);
callbackOk = true;
}
});
return proxy.project.map.triggerSearch({query: "rotenone", dbOverlayName: "chemical"});
}).then(function () {
assert.ok(callbackOk);
return map.destroy();
});
});
});
describe('mi rna', function () {
it('query search', function () {
var callbackOk = false;
var map;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createMiRnaDbOverlay(map);
var proxy = createProxy(map);
proxy.project.map.addListener({
dbOverlayName: "mirna",
type: "onSearch",
callback: function (elements) {
assert.ok(elements.length > 0);
callbackOk = true;
}
});
return proxy.project.map.triggerSearch({query: "hsa-miR-125a-3p", dbOverlayName: "mirna"});
}).then(function () {
assert.ok(callbackOk);
return map.destroy();
});
});
});
});
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment