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

odl overlayCollection implementation removed

parent 1c710d15
......@@ -6,12 +6,12 @@ var logger = require('../logger');
var functions = require('../Functions');
var AbstractCustomMap = require('./AbstractCustomMap');
var AbstractDbOverlay = require('./overlay/AbstractDbOverlay');
var AliasMarker = require('./marker/AliasMarker');
var CommentDialog = require('../gui/CommentDialog');
var ControlType = require('./ControlType');
var CustomMapOptions = require('./CustomMapOptions');
var IdentifiedElement = require('./data/IdentifiedElement');
var OverlayCollection = require('./overlay/OverlayCollection');
var PointMarker = require('./marker/PointMarker');
var ReactionMarker = require('./marker/ReactionMarker');
var ReactionOverlay = require('./overlay/ReactionOverlay');
......@@ -1268,7 +1268,7 @@ CustomMap.prototype.openInfoWindowForAlias = function(aliasId, modelId) {
*/
CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBounds) {
var self = this;
if (overlayCollection instanceof OverlayCollection) {
if (overlayCollection instanceof AbstractDbOverlay) {
logger.warn("Deprecated method use: renderOverlayCollection(overlayCollection)");
} else {
fitBounds = overlayCollection.fitBounds;
......@@ -1421,16 +1421,7 @@ CustomMap.prototype.retrieveOverlayDetailDataForElement = function(element, gene
}
generalRequest = generalRequest || !overlay.allowSearchById();
if (overlay.constructor.name === "OverlayCollection") {
if (overlay.allowGeneralSearch() || overlay.allowSearchById()) {
if (overlay.isMissingDetailData(element, generalRequest)) {
logger.warn("Unsupported call for overlay collection: "+overlay.getName());
// ServerConnector.sendOverlayDetailDataRequest(overlayName, element, generalRequest);
}
}
} else {
promises.push(overlay.getDetailDataByIdentifiedElement(element, generalRequest));
}
promises.push(overlay.getDetailDataByIdentifiedElement(element, generalRequest));
}
}
return Promise.all(promises);
......
......@@ -7,14 +7,24 @@ var logger = require('../../logger');
var Promise = require("bluebird");
var IdentifiedElement = require('../data/IdentifiedElement');
var OverlayCollection = require('./OverlayCollection');
var ObjectWithListeners = require('../../ObjectWithListeners');
var ServerConnector = require('../../ServerConnector');
function AbstractDbOverlay(params) {
// call super constructor
OverlayCollection.call(this, params);
ObjectWithListeners.call(this);
if (params.map === undefined) {
throw new Error("map param must be defined");
}
this.setName(params.name);
this.setMap(params.map);
this.setAllowSearchById(params.allowSearchById);
this.setAllowGeneralSearch(params.allowGeneralSearch);
this.setIconType(params.iconType);
this.setIconStart(params.iconColorStart);
......@@ -27,7 +37,7 @@ function AbstractDbOverlay(params) {
this.setQueries([]);
}
AbstractDbOverlay.prototype = Object.create(OverlayCollection.prototype);
AbstractDbOverlay.prototype = Object.create(ObjectWithListeners.prototype);
AbstractDbOverlay.prototype.constructor = AbstractDbOverlay;
AbstractDbOverlay.QueryType = {
......@@ -168,4 +178,100 @@ AbstractDbOverlay.prototype.clear = function() {
return this.searchByQuery("");
};
/**
* Returns true if overlay allows to get general data for element.
*/
AbstractDbOverlay.prototype.allowGeneralSearch = function() {
return this._allowGeneralSearch;
};
AbstractDbOverlay.prototype.getName = function() {
return this.name;
};
/**
* Returns true if overlay allows to get data for element by search id.
*/
AbstractDbOverlay.prototype.allowSearchById = function() {
return this._allowSearchById;
};
AbstractDbOverlay.prototype.setMap = function(map) {
this._map = map;
};
AbstractDbOverlay.prototype.getMap = function() {
return this._map;
};
AbstractDbOverlay.prototype.setName = function(name) {
this.name = name;
};
AbstractDbOverlay.prototype.getName = function() {
return this.name;
};
AbstractDbOverlay.prototype.setAllowSearchById = function(allowSearchById) {
// configure if the overlay can contain detailed data about elements that
// should be visualized in detailed mode of the Info Window
if (typeof allowSearchById === "boolean") {
this._allowSearchById = allowSearchById;
} else if (allowSearchById === undefined) {
this._allowSearchById = false;
} else {
throw new Error("Unknown type of allowSearchById: ", allowSearchById);
}
};
AbstractDbOverlay.prototype.setAllowGeneralSearch = function(allowGeneralSearch) {
if (typeof allowGeneralSearch === "boolean") {
this._allowGeneralSearch = allowGeneralSearch;
} else if (allowGeneralSearch === undefined) {
this._allowGeneralSearch = false;
} else {
throw new Error("Unknown type of allowSearchById: ", allowGeneralSearch);
}
};
AbstractDbOverlay.prototype.setIconType = function(iconType) {
this._iconType = iconType;
};
AbstractDbOverlay.prototype.setIconStart = function(iconStart) {
this._iconStart = iconStart;
};
AbstractDbOverlay.IconColors = [ "red", "blue", "green", "purple", "yellow", "pink", "paleblue", "brown", "orange" ];
AbstractDbOverlay.prototype.getColor = function(colorId) {
var id = colorId + this._iconStart;
id %= AbstractDbOverlay.IconColors.length;
return AbstractDbOverlay.IconColors[id];
};
AbstractDbOverlay.prototype.getIcon = function(colorId, id) {
if (id >= 100) {
id = 1;
}
var color = this.getColor(colorId);
return "marker/" + this._iconType + "/" + this._iconType + "_" + color + "_" + id + ".png";
};
AbstractDbOverlay.prototype.splitQuery = function(query, useFullName) {
var result = [];
if (query.indexOf(";") >= 0) {
result = query.split(";");
} else {
result = query.split(",");
}
for (var i = 0; i < result.length; i++) {
result[i] = result[i].trim();
}
if (result.length > 1 && useFullName) {
result.push(query);
}
return result;
};
module.exports = AbstractDbOverlay;
......@@ -2,33 +2,37 @@
var Promise = require("bluebird");
var OverlayCollection = require('./OverlayCollection');
var AbstractDbOverlay = require('./AbstractDbOverlay');
var ServerConnector = require('../../ServerConnector');
function CommentDbOverlay(params) {
// call super constructor
OverlayCollection.call(this, params);
AbstractDbOverlay.call(this, params);
this._elements = [];
this._detailDataByIdentifiedElement = [];
}
CommentDbOverlay.prototype = Object.create(OverlayCollection.prototype);
CommentDbOverlay.prototype = Object.create(AbstractDbOverlay.prototype);
CommentDbOverlay.prototype.constructor = CommentDbOverlay;
CommentDbOverlay.prototype.refresh = function() {
var self = this;
return new Promise(function(resolve, reject) {
return ServerConnector.getLightComments({}).then(function(comments) {
self.elements = comments;
resolve(self.elements);
self._elements = comments;
resolve(self._elements);
}).catch(reject);
});
};
CommentDbOverlay.prototype.clear = function() {
this.elements = [];
this._elements = [];
this._detailDataByIdentifiedElement = [];
return new Promise.resolve();
};
CommentDbOverlay.prototype._getDetailArrayByIdentifiedElement = function(element) {
CommentDbOverlay.prototype.getDetailDataByIdentifiedElement = function(element) {
var self = this;
var elementKey = element.getId() + "," + element.getType() + "," + element.getModelId();
if (this._detailDataByIdentifiedElement[elementKey] !== undefined) {
......@@ -46,10 +50,10 @@ CommentDbOverlay.prototype.getIdentifiedElements = function(){
var self = this;
return new Promise(function(resolve){
var result = [];
for (var i=0;i<self.elements.length;i++) {
for (var i=0;i<self._elements.length;i++) {
// we return only elements that are pinned to the map and weren't removed
if (!self.elements[i].isRemoved()) {
result.push(self.elements[i].getIdentifiedElement());
if (!self._elements[i].isRemoved()) {
result.push(self._elements[i].getIdentifiedElement());
}
}
resolve(result);
......
"use strict";
var logger = require('../../logger');
var IdentifiedElement = require('../data/IdentifiedElement');
var ObjectWithListeners = require('../../ObjectWithListeners');
/**
* This class is responsible for collecting and updating markers found by
* different panels (ie. search, comments, drug, targets).
*
* @param map
* element of type CustomMap that represents custom extension to google
* map
* @param name
* name of the collection used to distinguish it from the other
* sources.
*/
function OverlayCollection(params) {
// map, name, allowSearchById, allowGeneralSearch
ObjectWithListeners.call(this);
if (params.map === undefined) {
throw new Error("map param must be defined");
}
this.elements = [];
this.setName(params.name);
this.setMap(params.map);
this._ids = [];
this.setAllowSearchById(params.allowSearchById);
this.setAllowGeneralSearch(params.allowGeneralSearch);
this._detailDataByIdentifiedElement = [];
// register source in the map
// this.getMap().registerSource(self);
}
OverlayCollection.prototype = Object.create(ObjectWithListeners.prototype);
OverlayCollection.prototype.constructor = OverlayCollection;
/**
* Returns true if overlay allows to get general data for element.
*/
OverlayCollection.prototype.allowGeneralSearch = function() {
return this._allowGeneralSearch;
};
OverlayCollection.prototype.getName = function() {
return this.name;
};
/**
* Returns true if overlay allows to get data for element by search id.
*/
OverlayCollection.prototype.allowSearchById = function() {
return this._allowSearchById;
};
/**
* Method that should be called when new data from server appears. It updates
* markers associated with the object.
*
* @param newElements
* new elements that should be associated with the overlay
* @param fitBounds
* should the bound on the map be fit after creating markers on the map
* representing newElements
*/
OverlayCollection.prototype.updateOverlays = function(newElements, fitBounds) {
var self = this;
this.elements = [];
for (var i = 0; i < newElements.length; i++) {
this.elements.push(new IdentifiedElement(newElements[i]));
}
this.fitBounds = fitBounds;
this.getMap().updateOverlayCollection(self, fitBounds);
};
/**
* Clears all elements.
*/
OverlayCollection.prototype.clear = function() {
var self = this;
this.elements = [];
this.getMap().updateOverlayCollection(self);
};
/**
* Sends request to server to refresh data.
*/
OverlayCollection.prototype.refresh = function() {
ServerConnector.sendRefreshRequest(this.name);
};
OverlayCollection.prototype.setResultsIds = function(ids) {
this._ids = ids;
this.getMap().refreshInfoWindows();
};
OverlayCollection.prototype.getResultsIds = function() {
return this._ids;
};
OverlayCollection.prototype.isMissingDetailData = function(element, general) {
var data = this._getDetailArrayByIdentifiedElement(element);
if (typeof general !== "boolean") {
logger.warn("general parameter is invalid, assuming 'false': ", general);
}
if (general === true) {
if (this.allowGeneralSearch()) {
return data['__FULL__'] === undefined;
} else {
throw new Error("Cannot execute general search for overlay: ", this.getName());
}
} else if (this.allowSearchById()) {
for (var i = 0; i < this._ids.length; i++) {
if (data[this._ids[i]] === undefined) {
return true;
}
}
return false;
} else {
logger.warn("No data is available for overlay: ", this.getName());
return false;
}
};
OverlayCollection.prototype.getMissingDetailDataIds = function(element, general) {
if (typeof general !== "boolean") {
logger.warn("general parameter is invalid, assuming 'false': ", general);
}
var data = this._getDetailArrayByIdentifiedElement(element);
var result = [];
if (general === true) {
if (this.allowGeneralSearch()) {
if (data['__FULL__'] === undefined) {
result.push(null);
}
} else {
throw new Error("Cannot execute general search for overlay: ", this.getName());
}
} else if (this.allowSearchById()) {
for (var i = 0; i < this._ids.length; i++) {
if (data[this._ids[i]] === undefined) {
result.push(this._ids[i]);
}
}
} else {
logger
.warn("Nothing is missing, because overlay doesn't allow this kind of search. Overlay name: ", this.getName());
}
return result;
};
OverlayCollection.prototype.updateOverviewElementDetailData = function(javaObject, searchResultIdentifier, newData) {
var element = new IdentifiedElement(javaObject);
var data = this._getDetailArrayByIdentifiedElement(element);
if (searchResultIdentifier === null || searchResultIdentifier === undefined || searchResultIdentifier === "") {
data.push(newData);
} else {
data[searchResultIdentifier] = newData;
}
this.getMap().updateInfoWindowForIdentifiedElement(element);
};
OverlayCollection.prototype.getDetailDataByIdentifiedElement = function(element, general) {
if (typeof general !== "boolean") {
logger.warn("general parameter is invalid, assuming 'false': ", general);
}
var data = this._getDetailArrayByIdentifiedElement(element);
if (general === true) {
if (this.allowGeneralSearch()) {
return data;
} else {
logger.warn("No general data type for overlay: " + this.getName());
return [];
}
} else {
var result = [];
for (var i = 0; i < this.getResultsIds().length; i++) {
var id = this.getResultsIds()[i];
var rowRes = data[id];
if (rowRes !== undefined) {
result[id] = rowRes;
}
}
return result;
}
};
OverlayCollection.prototype._getDetailArrayByIdentifiedElement = function(element) {
var elementKey = element.getId() + "," + element.getType() + "," + element.getModelId();
if (this._detailDataByIdentifiedElement[elementKey] === undefined) {
this._detailDataByIdentifiedElement[elementKey] = [];
}
return this._detailDataByIdentifiedElement[elementKey];
};
OverlayCollection.prototype.setMap = function(map) {
this._map = map;
};
OverlayCollection.prototype.getMap = function() {
return this._map;
};
OverlayCollection.prototype.setName = function(name) {
this.name = name;
};
OverlayCollection.prototype.getName = function() {
return this.name;
};
OverlayCollection.prototype.setAllowSearchById = function(allowSearchById) {
// configure if the overlay can contain detailed data about elements that
// should be visualized in detailed mode of the Info Window
if (typeof allowSearchById === "boolean") {
this._allowSearchById = allowSearchById;
} else if (allowSearchById === undefined) {
this._allowSearchById = false;
} else {
throw new Error("Unknown type of allowSearchById: ", allowSearchById);
}
};
OverlayCollection.prototype.setAllowGeneralSearch = function(allowGeneralSearch) {
if (typeof allowGeneralSearch === "boolean") {
this._allowGeneralSearch = allowGeneralSearch;
} else if (allowGeneralSearch === undefined) {
this._allowGeneralSearch = false;
} else {
throw new Error("Unknown type of allowSearchById: ", allowGeneralSearch);
}
};
OverlayCollection.prototype.getIdentifiedElements = function() {
var self = this;
return new Promise(function(resolve) {
resolve(self.elements);
});
};
OverlayCollection.prototype.setIconType = function(iconType) {
this._iconType = iconType;
};
OverlayCollection.prototype.setIconStart = function(iconStart) {
this._iconStart = iconStart;
};
OverlayCollection.IconColors = [ "red", "blue", "green", "purple", "yellow", "pink", "paleblue", "brown", "orange" ];
OverlayCollection.prototype.getColor = function(colorId) {
var id = colorId + this._iconStart;
id %= OverlayCollection.IconColors.length;
return OverlayCollection.IconColors[id];
};
OverlayCollection.prototype.getIcon = function(colorId, id) {
if (id >= 100) {
id = 1;
}
var color = this.getColor(colorId);
return "marker/" + this._iconType + "/" + this._iconType + "_" + color + "_" + id + ".png";
};
OverlayCollection.prototype.splitQuery = function (query, useFullName) {
var result = [];
if (query.indexOf(";")>=0) {
result = query.split(";");
} else {
result = query.split(",");
}
for (var i=0;i<result.length;i++) {
result[i]=result[i].trim();
}
if (result.length>1 && useFullName) {
result.push(query);
}
return result;
};
module.exports = OverlayCollection;
......@@ -12,7 +12,6 @@ var DrugDbOverlay = require('./map/overlay/DrugDbOverlay');
var DrugPanel = require('./gui/DrugPanel');
var MiRnaDbOverlay = require('./map/overlay/MiRnaDbOverlay');
var MiRnaPanel = require('./gui/MiRnaPanel');
var OverlayCollection = require('./map/overlay/OverlayCollection');
var SearchDbOverlay = require('./map/overlay/SearchDbOverlay');
var SearchPanel = require('./gui/SearchPanel');
......@@ -163,8 +162,7 @@ function create(params) {
customMap : result
});
} else {
collection = new OverlayCollection(collectionParams);
result.registerSource(collection);
throw new Error("Unknown overlay db: "+collectionParams.name);
}
}
} else {
......
......@@ -16,7 +16,7 @@ var LayoutData = require("../../main/js/map/data/LayoutData");
var LayoutReaction = require("../../main/js/map/data/LayoutReaction");
var MiRnaDbOverlay = require("../../main/js/map/overlay/MiRnaDbOverlay");
var Model = require("../../main/js/map/data/MapModel");
var OverlayCollection = require("../../main/js/map/overlay/OverlayCollection");
var AbstractDbOverlay = require("../../main/js/map/overlay/AbstractDbOverlay");
var Project = require("../../main/js/map/data/Project");
var Reaction = require("../../main/js/map/data/Reaction");
var SearchDbOverlay = require("../../main/js/map/overlay/SearchDbOverlay");
......@@ -98,6 +98,15 @@ Helper.prototype.createSearchDbOverlay = function(map) {
return result;
};
Helper.prototype.createDbOverlay = function(map) {
var result = new AbstractDbOverlay({
map : map,
name : "search",
});
map.registerSource(result);
return result;
};
Helper.prototype.createDrugDbOverlay = function(map) {
var result = new DrugDbOverlay({
map : map,
......@@ -166,16 +175,6 @@ Helper.prototype.createComment = function(element) {
return result;
};
Helper.prototype.createDbOverlay = function(map) {
var result = new OverlayCollection({
map : map,
name : "overlay name: " + (this.idCounter++),
allowGeneralSearch : true