Commit 5ba10fcd authored by Piotr Gawron's avatar Piotr Gawron
Browse files

visualization of comments fixed (when clicking on marker)

parent 794bf0f4
......@@ -8,6 +8,7 @@ var request = require('request');
var Alias = require('./map/data/Alias');
var Comment = require('./map/data/Comment');
var ConfigurationType = require('./ConfigurationType');
var IdentifiedElement= require('./map/data/IdentifiedElement');
var LayoutAlias = require('./map/data/LayoutAlias');
......@@ -744,7 +745,9 @@ ServerConnector.createGetParams = function(params) {
var result = "";
for (var i = 0; i < sorted.length; i++) {
result+= sorted[i] + "="+params[sorted[i]]+"&";
if (params[sorted[i]]!==undefined) {
result+= sorted[i] + "="+params[sorted[i]]+"&";
}
}
return result;
};
......@@ -789,7 +792,8 @@ ServerConnector.getOverlaysUrl = function(projectId, token) {
};
ServerConnector.getCommentsUrl = function(params) {
var id = this.idsToString(params.ids);
var elementId = params.elementId;
var elementType = params.elementType;
var columns = this.columnsToString(params.columns);
var projectId = params.projectId;
var token = params.token;
......@@ -799,7 +803,8 @@ ServerConnector.getCommentsUrl = function(params) {
params: {
projectId: projectId,
columns: columns,
id: id,
elementId: elementId,
elementType: elementType,
token: token},
});
};
......@@ -1093,19 +1098,24 @@ ServerConnector.getAliases = function(aliasIds, projectId, columns) {
};
ServerConnector.getLightComments = function(params) {
params.columns = [ "id","elementId", "modelId", "type", "icon" ];
return this.getComments(params);
};
ServerConnector.getComments = function(params) {
var self = this;
var projectId;
return new Promise(function(resolve, reject) {
return self.getProjectId(params.projectId).then(function(result) {
projectId = result;
params.projectId=result;
return self.getToken();
}).then(function(token) {
return self.readFile(self.getCommentsUrl({ids:params.ids, projectId:projectId, token:token, columns:params.columns}));
params.token=token;
return self.readFile(self.getCommentsUrl(params));
}).then(function(content) {
var array=JSON.parse(content);
var result = [];
for (var i = 0; i < array.length; i++) {
result.push(new IdentifiedElement(array[i]));
result.push(new Comment(array[i]));
}
resolve(result);
}).catch(function(exception){
......
......@@ -1358,7 +1358,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
overlayCollection = overlayCollection.overlayCollection;
}
var elements = overlayCollection.elements;
var elements = overlayCollection.getIdentifiedElements();
var boundsArray = [];
boundsArray[this.getId()] = new google.maps.LatLngBounds();
......@@ -1372,7 +1372,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
elements,
function(element) {
var model = self.getSubmodelById(element.modelId);
if (element.type === "ALIAS") {
if (element.getType() === "ALIAS") {
if (overlayCollection.aliasMarkers[element.getId()] !== undefined) {
logger.warn("More than one marker in " + overlayCollection.name + " for alias " + element.getId()
+ ". Skipping duplicates.");
......@@ -1387,7 +1387,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
return aliasMarker;
});
}
} else if (element.type === "REACTION") {
} else if (element.getType() === "REACTION") {
return model.getModel().getReactionById(element.getId()).then(function(reactionData) {
var marker = null;
var icon = element.getIcon();
......@@ -1409,7 +1409,7 @@ CustomMap.prototype.renderOverlayCollection = function(overlayCollection, fitBou
boundsArray[element.getModelId()].extend(bounds.getSouthWest());
return marker;
});
} else if (element.type === "POINT") {
} else if (element.getType() === "POINT") {
var pointData = model.getModel().getPointDataByPoint(element.getPoint());
var pointMarker = new PointMarker(pointData, element.icon, model);
overlayCollection.pointMarkers[pointData.getId()] = pointMarker;
......@@ -1518,6 +1518,7 @@ CustomMap.prototype.openInfoWindowForMarker = function(marker) {
* element for which we want to have detailed information
*/
CustomMap.prototype.retrieveOverlayDetailDataForElement = function(element, general) {
var promises = [];
if (general === undefined) {
logger.warn("general param is undefined!");
general = [];
......@@ -1533,13 +1534,18 @@ CustomMap.prototype.retrieveOverlayDetailDataForElement = function(element, gene
}
generalRequest = generalRequest || !overlay.allowSearchById();
if (overlay.allowGeneralSearch() || overlay.allowSearchById()) {
if (overlay.isMissingDetailData(element, generalRequest)) {
ServerConnector.sendOverlayDetailDataRequest(overlayName, element, generalRequest);
if (overlay.constructor.name === "OverlayCollection") {
if (overlay.allowGeneralSearch() || overlay.allowSearchById()) {
if (overlay.isMissingDetailData(element, generalRequest)) {
ServerConnector.sendOverlayDetailDataRequest(overlayName, element, generalRequest);
}
}
} else {
promises.push(overlay.getDetailDataByIdentifiedElement(element, generalRequest));
}
}
}
return Promise.all(promises);
};
/**
......@@ -1614,7 +1620,8 @@ CustomMap.prototype.getOverlayDataForIdentifiedElement = function(identifiedElem
logger.warn("general parameter must be defined");
general = [];
}
var result = [];
var promises = [];
var overlays = [];
for ( var overlayName in this.overlayCollections) {
if (this.overlayCollections.hasOwnProperty(overlayName)) {
var overlay = this.overlayCollections[overlayName];
......@@ -1624,14 +1631,20 @@ CustomMap.prototype.getOverlayDataForIdentifiedElement = function(identifiedElem
logger.warn("General flag for overlay: " + overlay.getName() + " is not defined, assuming false");
generalFlag = false;
}
result.push({
overlay : overlay,
data : overlay.getDetailDataByIdentifiedElement(identifiedElement, !overlay.allowSearchById() || generalFlag)
});
overlays.push(overlay);
promises.push(overlay.getDetailDataByIdentifiedElement(identifiedElement, !overlay.allowSearchById() || generalFlag));
}
}
}
return result;
return new Promise(function(resolve,reject){
Promise.all(promises).then(function(values){
var result = [];
for (var i=0;i<values.length;i++){
result.push({overlay:overlays[i], data:values[i]});
}
resolve(result);
}).catch(reject);
});
};
/**
......
"use strict";
var IdentifiedElement = require('./IdentifiedElement');
function Comment(javaObject) {
this.setIdentifiedElement(new IdentifiedElement({
id : javaObject.elementId,
type : javaObject.type,
modelId : javaObject.modelId,
icon : javaObject.icon,
}));
this.setId(javaObject.id);
if (javaObject.title !== undefined) {
this.setPinned(javaObject.pinned);
this.setCoordinates(javaObject.coord);
this.setRemoved(javaObject.removed);
this.setTitle(javaObject.title);
this.setContent(javaObject.content);
}
}
Comment.prototype.setIdentifiedElement = function(ie) {
this._ie = ie;
};
Comment.prototype.getIdentifiedElement = function() {
return this._ie;
};
Comment.prototype.setPinned = function(pinned) {
this._pinned = (pinned === true);
};
Comment.prototype.setCoordinates = function(coordinates) {
this._coordinates = new google.maps.Point(coordinates.x, coordinates.y);
};
Comment.prototype.setRemoved = function(removed) {
this._removed = (removed === true);
};
Comment.prototype.setId = function(id) {
this._id = id;
};
Comment.prototype.setTitle = function(title) {
this._title = title;
};
Comment.prototype.setContent = function(content) {
this._content = content;
};
Comment.prototype.isPinned = function() {
return this._pinned;
};
Comment.prototype.getCoordinates = function() {
return this._coordinates;
};
Comment.prototype.isRemoved = function() {
return this._removed;
};
Comment.prototype.getId = function() {
return this._id;
};
Comment.prototype.getTitle = function() {
return this._title;
};
Comment.prototype.getContent = function() {
return this._content;
};
module.exports = Comment;
......@@ -98,7 +98,6 @@ IdentifiedElement.prototype.getId = function() {
};
IdentifiedElement.prototype.setId = function(id) {
// some elements are identfied by id that is not a number (like point on the
// map)
if (!isNaN(id)) {
......
......@@ -14,7 +14,7 @@ function PointData(javaObject, modelId) {
var y = parseFloat(tmp[1]).toFixed(2);
this._point = new google.maps.Point(x, y);
}
this._id = "(" + this._point.x + ", " + this._point.y + ")";
this._id = "(" + this._point.x + "," + this._point.y + ")";
this._modelId = modelId;
}
......
......@@ -17,12 +17,8 @@ CommentDbOverlay.prototype.refresh = function() {
var self = this;
return new Promise(function(resolve, reject) {
ServerConnector.getLightComments({
columns : [ "id", "modelId", "type", "icon" ]
}).then(function(comments) {
self.elements = [];
for (var i = 0; i < comments.length; i++) {
self.elements.push(new IdentifiedElement(comments[i]));
}
self.elements = comments;
resolve(self.elements);
}).catch(reject);
});
......@@ -33,5 +29,27 @@ CommentDbOverlay.prototype.clear = function() {
return new Promise.resolve();
};
CommentDbOverlay.prototype._getDetailArrayByIdentifiedElement = function(element) {
var self = this;
var elementKey = element.getId() + "," + element.getType() + "," + element.getModelId();
if (this._detailDataByIdentifiedElement[elementKey] !== undefined) {
return Promise.resolve(this._detailDataByIdentifiedElement[elementKey]);
} else {
return ServerConnector.getComments({elementId: element.getId(), elementType: element.getType()}).then(function(comments){
self._detailDataByIdentifiedElement[elementKey] = comments;
return comments;
});
}
};
CommentDbOverlay.prototype.getIdentifiedElements = function(){
var result = [];
for (var i=0;i<this.elements.length;i++) {
result.push(this.elements[i].getIdentifiedElement());
}
return result;
}
module.exports = CommentDbOverlay;
......@@ -236,4 +236,8 @@ OverlayCollection.prototype.setAllowGeneralSearch = function(allowGeneralSearch)
}
};
OverlayCollection.prototype.getIdentifiedElements = function(){
return this.elements;
}
module.exports = OverlayCollection;
......@@ -2,6 +2,7 @@
var logger = require('../../logger');
var Comment = require('../data/Comment');
var IdentifiedElement = require('../data/IdentifiedElement');
var AbstractMarker = require('../marker/AbstractMarker');
var ObjectWithListeners = require('../../ObjectWithListeners');
......@@ -122,7 +123,6 @@ AbstractInfoWindow.prototype.open = function() {
logger.warn("Cannot open window.");
return;
}
this.update();
this.googleInfowindow.open(this.getCustomMap().getGoogleMap(), this.getGoogleMarker());
this.callListeners("onShow");
......@@ -160,28 +160,29 @@ AbstractInfoWindow.prototype.getContent = function() {
* @returns string representing div for given overlay data
*/
AbstractInfoWindow.prototype.createOverlayInfoDiv = function(overlay, data) {
if (this.alias !== undefined) {
if (this.alias.getType() !== undefined) {
var alias = this.alias;
if (alias !== undefined) {
if (alias.getType() !== undefined) {
if (overlay.name === "drug") {
if (this.alias.getType().toUpperCase() === "RNA" || //
this.alias.getType().toUpperCase() === "PROTEIN" || //
this.alias.getType().toUpperCase() === "GENE") {
if (alias.getType().toUpperCase() === "RNA" || //
alias.getType().toUpperCase() === "PROTEIN" || //
alias.getType().toUpperCase() === "GENE") {
return this._createDrugInfoDiv(overlay, data);
} else {
return null;
}
} else if (overlay.name === "chemical") {
if (this.alias.getType().toUpperCase() === "RNA" || //
this.alias.getType().toUpperCase() === "PROTEIN" || //
this.alias.getType().toUpperCase() === "GENE") {
alias.getType().toUpperCase() === "PROTEIN" || //
alias.getType().toUpperCase() === "GENE") {
return this._createChemicalInfoDiv(overlay, data);
} else {
return null;
}
} else if (overlay.name === "mirna") {
if (this.alias.getType().toUpperCase() === "RNA" || //
this.alias.getType().toUpperCase() === "PROTEIN" || //
this.alias.getType().toUpperCase() === "GENE") {
if (alias.getType().toUpperCase() === "RNA" || //
alias.getType().toUpperCase() === "PROTEIN" || //
alias.getType().toUpperCase() === "GENE") {
return this._createMiRnaInfoDiv(overlay, data);
} else {
return null;
......@@ -194,14 +195,14 @@ AbstractInfoWindow.prototype.createOverlayInfoDiv = function(overlay, data) {
return this._createDefaultInfoDiv(overlay, data);
}
} else {
logger.warn("Cannot customize info window. Alias type is unknown: ", this.alias.getType());
return null;
logger.debug(alias)
throw new Error("Cannot customize info window. Alias type is unknown ");
}
} else {
if (overlay.name === "comment") {
if (overlay.getName() === "comment") {
return this._createCommentInfoDiv(overlay, data);
} else {
logger.debug("Cannot customize info window. Alias not defined.");
logger.debug("Cannot customize info window. Alias not defined. Overlay: " + overlay.getName());
return null;
}
}
......@@ -235,17 +236,20 @@ AbstractInfoWindow.prototype._createCommentInfoDiv = function(overlay, data) {
titleElement.innerHTML = "Comments";
result.appendChild(titleElement);
for (var i = 0; i < data.length; i++) {
if (typeof data[i].commentId !== "undefined" && typeof data[i].commentContent !== "undefined") {
result.appendChild(document.createElement("hr"));
var commentId = document.createElement("div");
commentId.innerHTML = '#' + data[i].commentId;
result.appendChild(commentId);
result.appendChild(document.createElement("br"));
var commentContent = document.createElement("div");
commentContent.innerHTML = '#' + data[i].commentContent;
result.appendChild(commentContent);
var comment = data[i];
if (comment instanceof Comment) {
if (!comment.isRemoved() && comment.isPinned()) {
result.appendChild(document.createElement("hr"));
var commentId = document.createElement("div");
commentId.innerHTML = '#' + comment.getId();
result.appendChild(commentId);
result.appendChild(document.createElement("br"));
var commentContent = document.createElement("div");
commentContent.innerHTML = comment.getContent();
result.appendChild(commentContent);
}
} else {
throw new Error("Invalid comment data: ", data[i]);
throw new Error("Invalid comment data: " + comment);
}
}
......@@ -317,7 +321,7 @@ AbstractInfoWindow.prototype.getCustomMap = function() {
};
AbstractInfoWindow.prototype.setCustomMap = function(map) {
if (map===undefined) {
if (map === undefined) {
throw new Error("Map must be defined");
}
this.customMap = map;
......@@ -365,19 +369,18 @@ AbstractInfoWindow.prototype._updateContent = function() {
* {@link OverlayCollection} for this window
*/
AbstractInfoWindow.prototype.createOverlaysDiv = function() {
var overlayData = this.getOverlaysData(this.getOverlayFullViewArray());
if (overlayData === undefined || overlayData === null) {
return null;
}
var self = this;
var result = document.createElement("div");
for (var i = 0; i < overlayData.length; i++) {
var overlay = overlayData[i].overlay;
var data = overlayData[i].data;
var overlayInfo = this.createOverlayInfoDiv(overlay, data);
if (overlayInfo !== null) {
result.appendChild(overlayInfo);
this.getOverlaysData(self.getOverlayFullViewArray()).then(function(overlayData) {
for (var i = 0; i < overlayData.length; i++) {
var overlay = overlayData[i].overlay;
var data = overlayData[i].data;
var overlayInfo = self.createOverlayInfoDiv(overlay, data);
if (overlayInfo !== null) {
result.appendChild(overlayInfo);
}
}
}
});
return result;
};
......
......@@ -12,23 +12,33 @@ var pileup = require('pileup');
/**
* Class representing info window that should be opened when clicking on alias.
*/
function AliasInfoWindow(alias, map) {
function AliasInfoWindow(alias, map, onloadFun) {
// call super constructor
AbstractInfoWindow.call(this, alias, map);
if (alias instanceof AliasMarker) {
this.setAlias(alias.getAliasData());
map = alias.getCustomMap();
} else {
this.setAlias(alias);
}
var point = new google.maps.Point(this.alias.x + this.alias.width / 2, this.alias.y + this.alias.height / 2);
var self = this;
var alias = this.getAlias();
var point = new google.maps.Point(alias.x + alias.width / 2, alias.y + alias.height / 2);
var latLng = this.customMap.fromPointToLatLng(point);
this.googleInfowindow = new google.maps.InfoWindow({
content : this.content,
position : latLng
});
this.update(alias);
map.getSubmodelById(alias.getModelId()).getModel().getAliasById(alias.getId(), true).then(function(alias) {
self.update(alias);
if (onloadFun!==undefined) {
onloadFun();
}
});
this.open();
}
......@@ -152,11 +162,11 @@ AliasInfoWindow.prototype.createContentDiv = function() {
result.appendChild(layoutsDiv);
self.getCustomMap().getAliasVisibleLayoutsData(this.alias.getId()).then(function(layoutAliases){
self.getCustomMap().getAliasVisibleLayoutsData(this.alias.getId()).then(function(layoutAliases) {
self.layoutAliases = layoutAliases;
return self.getCustomMap().getVisibleLayoutNames();
}).then(function(layoutNames){
self.layoutNames = layoutNames;
}).then(function(layoutNames) {
self.layoutNames = layoutNames;
var chartDiv = self.createChartDiv();
if (chartDiv !== null) {
layoutsDiv.appendChild(chartDiv);
......@@ -167,8 +177,6 @@ AliasInfoWindow.prototype.createContentDiv = function() {
}
});
return result;
} else {
return this.createWaitingContentDiv();
......@@ -181,11 +189,7 @@ AliasInfoWindow.prototype.createContentDiv = function() {
* @returns array with data from {@link OverlayCollection}
*/
AliasInfoWindow.prototype.getOverlaysData = function(general) {
if (this.alias !== undefined && this.alias !== null) {
return this.getCustomMap().getTopMap().getOverlayDataForAlias(this.alias, general);
} else {
return null;
}
return this.getCustomMap().getTopMap().getOverlayDataForAlias(this.getAlias(), general);
};
/**
......
......@@ -15,17 +15,13 @@ function PointInfoWindow(pointMarker, map) {
this.pointData = pointMarker;
}
if (this.pointData !== undefined) {
var point = this.pointData.getPoint();
var latLng = this.getCustomMap().fromPointToLatLng(point);
this.googleInfowindow = new google.maps.InfoWindow({
content : this.content,
position : latLng
});
this.googleInfowindow.open(this.getCustomMap().getGoogleMap(), this.getGoogleMarker());
} else {
logger.warn("Opening window without alias specified");
}
var point = this.pointData.getPoint();
var latLng = this.getCustomMap().fromPointToLatLng(point);
this.googleInfowindow = new google.maps.InfoWindow({
content : this.content,
position : latLng
});
this.googleInfowindow.open(this.getCustomMap().getGoogleMap(), this.getGoogleMarker());
this.update();
}
......@@ -41,8 +37,8 @@ PointInfoWindow.prototype.createContentDiv = function() {
return result;
};
PointInfoWindow.prototype.getOverlaysData = function() {
return this.getCustomMap().getTopMap().getOverlayDataForPoint(this.pointData);
PointInfoWindow.prototype.getOverlaysData = function(general) {
return this.getCustomMap().getTopMap().getOverlayDataForPoint(this.pointData, general);
};
/**
......
......@@ -59,11 +59,7 @@ ReactionInfoWindow.prototype.createContentDiv = function() {
* @returns array with data from {@link OverlayCollection}
*/
ReactionInfoWindow.prototype.getOverlaysData = function(general) {
if (this._reactionData !== null) {
return this.getCustomMap().getTopMap().getOverlayDataForReaction(this._reactionData, general);
} else {
return null;
}
return this.getCustomMap().getTopMap().getOverlayDataForReaction(this.getReactionData(), general);
};
ReactionInfoWindow.prototype.getReactionData = function() {
......