Commit 7281c005 authored by Piotr Gawron's avatar Piotr Gawron

possibility to show/hide and retrieve all data overlays from plugins implemented

parent 38fe8c58
......@@ -25,6 +25,42 @@ var Promise = require("bluebird");
* @property {number} options.lineOpacity
*/
/**
* @typedef {Object} PluginProjectData
*
* @property {function(*=): Promise<any>} getBioEntityById
* @property {function(): *} getAllBioEntities
* @property {function(*=): *} getReactionsWithElement
* @property {function(): string} getProjectId
* @property {function(): string} getName
* @property {function(): string} getVersion
* @property {function(): *} getDisease
* @property {function(): *} getOrganism
* @property {function(): *[]} getModels
* @property {function(): DataOverlay[]} getDataOverlays
*/
/**
* @typedef {Object} PluginProjectMap
*
* @property {function(): (Promise<DataOverlay[]>|*)} getVisibleDataOverlays
* @property {function(number|DataOverlay): (Promise<DataOverlay[]>|*)} showDataOverlay
* @property {function(number|DataOverlay): (Promise<DataOverlay[]>|*)} hideDataOverlay
* @property {function(*)} addListener
* @property {function(*)} removeListener
* @property {function(): Array} removeAllListeners
* @property {(function(*=): Promise<Array|never>)} getHighlightedBioEntities
* @property {(function(*=): Promise<any|never>)} hideBioEntity
* @property {(function(*): PromiseLike)} setCenter
* @property {(function(*): Point)} getCenter
* @property {(function(*): Bounds)} getBounds
* @property {(function(*): void)} fitBounds
* @property {(function(*): *)} setZoom
* @property {(function(*): number)} getZoom
* @property {(function(*): PromiseLike)} openMap
*/
/**
*
* @param {CustomMap} customMap
......@@ -118,7 +154,7 @@ function getElements(elementIdentifiers, customMap) {
*
* @param {Object} options
* @param {CustomMap} options.map
* @returns {{getBioEntityById: function(*=): Promise<any>, getAllBioEntities: function(): *, getReactionsWithElement: function(*=): *, getProjectId: function(): string, getName: function(): string, getVersion: function(): string, getDisease: getDisease, getOrganism: getOrganism, getModels: function(): *[]}}
* @returns {PluginProjectData}
*/
function createProjectData(options) {
var map = options.map;
......@@ -137,6 +173,16 @@ function createProjectData(options) {
}
});
},
getDataOverlays: function () {
var overlays = map.getProject().getDataOverlays();
var result = [];
for (var i = 0; i < overlays.length; i++) {
if (overlays[i].getInputDataAvailable()) {
result.push(overlays[i]);
}
}
return result;
},
/**
* Export part of the map that includes bioEntities into a known format.
*
......@@ -344,7 +390,7 @@ function createWrapperFunctionForDialogGuiUpdate(param) {
* @param {CustomMap} options.map
* @param {Plugin} options.plugin
* @param {string} options.pluginId
* @returns {{getVisibleDataOverlays: (function(): (Promise<DataOverlay[]>|*)), addListener: addListener, removeListener: removeListener, removeAllListeners: (function(): Array), getHighlightedBioEntities: (function(*=): Promise<Array | never>), showBioEntity: (function(*=): *), hideBioEntity: (function(*=): Promise<any | never>), setCenter: (function(*): PromiseLike), getCenter: (function(*): Point), getBounds: (function(*): Bounds), fitBounds: (function(*): void), setZoom: (function(*): *), getZoom: (function(*): number), openMap: (function(*): PromiseLike)}}
* @returns {PluginProjectMap}
*/
function createProjectMap(options) {
var map = options.map;
......@@ -358,6 +404,22 @@ function createProjectMap(options) {
getVisibleDataOverlays: function () {
return map.getVisibleDataOverlays();
},
/**
*
* @param {number|DataOverlay} param
* @return {PromiseLike|Promise}
*/
showDataOverlay: function (param) {
return map.openDataOverlay(param);
},
/**
*
* @param {number|DataOverlay} param
* @return {PromiseLike|Promise}
*/
hideDataOverlay: function (param) {
return map.hideDataOverlay(param);
},
/**
*
* @param {Object} param
......@@ -601,7 +663,7 @@ function createProjectMap(options) {
* @param {CustomMap} options.map
* @param {Plugin} options.plugin
* @param {string} options.pluginId
* @returns {{data: {getBioEntityById: (function(*=): Promise<any>), getAllBioEntities: (function(): *), getReactionsWithElement: (function(*=): *), getProjectId: (function(): string), getName: (function(): string), getVersion: (function(): string), getDisease: getDisease, getOrganism: getOrganism, getModels: (function(): *[])}, map: {getVisibleDataOverlays: (function(): (Promise<DataOverlay[]>|*)), addListener: addListener, removeListener: removeListener, removeAllListeners: (function(): Array), getHighlightedBioEntities: (function(*=): Promise<Array|never>), showBioEntity: (function(*=): *), hideBioEntity: (function(*=): Promise<any|never>), setCenter: (function(*): PromiseLike), getCenter: (function(*): Point), getBounds: (function(*): Bounds), fitBounds: (function(*): void), setZoom: (function(*): *), getZoom: (function(*): number), openMap: (function(*): PromiseLike)}}}
* @returns {{data: PluginProjectData, map: PluginProjectMap}}
*/
function createProject(options) {
return {
......@@ -667,7 +729,7 @@ function createPluginData(options) {
* @param {HTMLElement} options.element
* @param {Configuration} options.configuration
* @param {ServerConnector} options.serverConnector
* @returns {{pluginId: (string|string), element: HTMLElement, project: {data: {getBioEntityById: (function(*=): Promise<any>), getAllBioEntities: (function(): *), getReactionsWithElement: (function(*=): *), getProjectId: (function(): string), getName: (function(): string), getVersion: (function(): string), getDisease: getDisease, getOrganism: getOrganism, getModels: (function(): *[])}, map: {getVisibleDataOverlays: (function(): (Promise<DataOverlay[]>|*)), addListener: addListener, removeListener: removeListener, removeAllListeners: (function(): Array), getHighlightedBioEntities: (function(*=): Promise<Array|never>), showBioEntity: (function(*=): *), hideBioEntity: (function(*=): Promise<any|never>), setCenter: (function(*): PromiseLike), getCenter: (function(*): Point), getBounds: (function(*): Bounds), fitBounds: (function(*): void), setZoom: (function(*): *), getZoom: (function(*): number), openMap: (function(*): PromiseLike)}}, configuration: {options: ConfigurationOption[], overlayTypes: string[], imageConverters: ImageConverter[], modelConverters: ModelConverter[], elementTypes: BioEntityType[], reactionTypes: BioEntityType[], miriamTypes: MiriamType[], mapTypes: MapType[], modificationStateTypes: ModificationStateType[], privilegeTypes: PrivilegeType[], annotators: Annotator[]}, pluginData: {setGlobalParam: (function(*=, *=): *), getGlobalParam: (function(*=): *), setUserParam: (function(*=, *=): *), getUserParam: (function(*=): *)}}}
* @returns {{pluginId: (string|string), element: HTMLElement, project: {data: PluginProjectData, map: PluginProjectMap}, configuration: {options: ConfigurationOption[], overlayTypes: string[], imageConverters: ImageConverter[], modelConverters: ModelConverter[], elementTypes: BioEntityType[], reactionTypes: BioEntityType[], miriamTypes: MiriamType[], mapTypes: MapType[], modificationStateTypes: ModificationStateType[], privilegeTypes: PrivilegeType[], annotators: Annotator[]}, pluginData: {setGlobalParam: (function(*=, *=): *), getGlobalParam: (function(*=): *), setUserParam: (function(*=, *=): *), getUserParam: (function(*=): *)}}}
* @constructor
*/
function MinervaPluginProxy(options) {
......
......@@ -563,6 +563,140 @@ describe('MinervaPluginProxy', function () {
});
});
/**
*
* @param {Project} project
* @return {DataOverlay}
*/
function getDataOverlayFromProject(project) {
for (var i = 0; i < project.getDataOverlays().length; i++) {
if (project.getDataOverlays()[i].getInputDataAvailable()) {
return project.getDataOverlays()[i];
}
}
return null;
}
describe('showDataOverlay', function () {
it('by id', function () {
var map, proxy, overlay;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
proxy = createProxy(map);
overlay = getDataOverlayFromProject(project);
return proxy.project.map.showDataOverlay(overlay.getId());
}).then(function () {
return proxy.project.map.getVisibleDataOverlays();
}).then(function (visibleDataOverlays) {
assert.equal(1, visibleDataOverlays.length);
return map.destroy();
});
});
it('by invalid id', function () {
var map;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
var proxy = createProxy(map);
return proxy.project.map.showDataOverlay(-1);
}).then(function () {
assert.notOk("Expected error");
}).catch(function () {
}).finally(function () {
return map.destroy();
});
});
it('by object', function () {
var map, proxy, overlay;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
proxy = createProxy(map);
overlay = getDataOverlayFromProject(project);
return proxy.project.map.showDataOverlay(overlay);
}).then(function () {
return proxy.project.map.getVisibleDataOverlays();
}).then(function (visibleDataOverlays) {
assert.equal(1, visibleDataOverlays.length);
return map.destroy();
});
});
});
describe('hideDataOverlay', function () {
it('by id', function () {
var map, proxy, overlay;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
proxy = createProxy(map);
overlay = getDataOverlayFromProject(project);
return proxy.project.map.showDataOverlay(overlay.getId());
}).then(function () {
return proxy.project.map.hideDataOverlay(overlay.getId());
}).then(function () {
return proxy.project.map.getVisibleDataOverlays();
}).then(function (visibleDataOverlays) {
assert.equal(0, visibleDataOverlays.length);
return map.destroy();
});
});
it('by invalid id', function () {
var map, proxy;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
proxy = createProxy(map);
return proxy.project.map.hideDataOverlay(-1);
}).then(function () {
assert.notOk("Expected error");
}).catch(function () {
}).finally(function () {
return map.destroy();
});
});
it('by object', function () {
var map, proxy, overlay;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
proxy = createProxy(map);
overlay = getDataOverlayFromProject(project);
return proxy.project.map.showDataOverlay(overlay.getId());
}).then(function () {
return proxy.project.map.hideDataOverlay(overlay.getId());
}).then(function () {
return proxy.project.map.getVisibleDataOverlays();
}).then(function (visibleDataOverlays) {
assert.equal(0, visibleDataOverlays.length);
return map.destroy();
});
});
});
describe('getDataOverlays', function () {
it('default', function () {
var map, proxy;
return ServerConnector.getProject().then(function (project) {
map = helper.createCustomMap(project);
helper.createSearchDbOverlay(map);
proxy = createProxy(map);
var overlays = proxy.project.data.getDataOverlays();
assert.ok(overlays.length>0);
for (var i=0;i<overlays.length;i++) {
assert.ok(overlays[i].getInputDataAvailable());
}
return map.destroy();
});
});
});
describe('addListener', function () {
it('on show overlay', function () {
var callbackOk = false;
......
[{"bounds":{"height":25.0,"width":70.0,"x":1214.2682370820667,"y":128.5000000000009},"id":329163,"linkedSubmodel":null,"modelId":15781},{"bounds":{"height":40.0,"width":80.0,"x":695.0,"y":239.0},"id":329178,"linkedSubmodel":null,"modelId":15781},{"bounds":{"height":40.0,"width":80.0,"x":656.0,"y":42.0},"id":329183,"linkedSubmodel":null,"modelId":15781}]
\ No newline at end of file
[{"overlayContent":{"modelId":15781,"idObject":"329163","value":1.0,"color":null,"uniqueId":"329163"},"type":"ALIAS"},{"overlayContent":{"modelId":15781,"idObject":"329178","value":-1.0,"color":null,"uniqueId":"329178"},"type":"ALIAS"},{"overlayContent":{"modelId":15781,"idObject":"329183","value":-1.0,"color":null,"uniqueId":"329183"},"type":"ALIAS"}]
\ No newline at end of file
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