Commit 712b0ce5 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

comments are retrevied via api

parent 9ff0edc6
......@@ -6,13 +6,14 @@ var logger = require('./logger');
var request = require('request');
var ConfigurationType = require('./ConfigurationType');
var LayoutData = require('./map/data/LayoutData');
var Project = require('./map/data/Project');
var Alias = require('./map/data/Alias');
var ConfigurationType = require('./ConfigurationType');
var IdentifiedElement= require('./map/data/IdentifiedElement');
var LayoutAlias = require('./map/data/LayoutAlias');
var LayoutData = require('./map/data/LayoutData');
var LayoutReaction = require('./map/data/LayoutReaction');
var Project = require('./map/data/Project');
var Reaction = require('./map/data/Reaction');
/**
......@@ -176,14 +177,6 @@ ServerConnector.setDrugQuery = function(value) {
document.getElementById(ServerConnector.formIdentifier + ':drugParam').value = "" + value;
};
/**
* Sets comment query that will be handled by server.
*/
ServerConnector.setCommentQuery = function(value) {
logger.error("ServerConnector.setCommentQuery: Not implemented");
document.getElementById(ServerConnector.formIdentifier + ':commentParam').value = "" + value;
};
/**
* Sets selected polygon. This might be in futer used oto extract/analyze data
* in the polygon by the server side.
......@@ -201,16 +194,6 @@ ServerConnector.setExportModelId = function(value) {
document.getElementById(ServerConnector.formIdentifier + ':exportModelId').value = "" + value;
};
/**
* Sets flag marking if the comments are visible or not.
*/
ServerConnector.setShowComments = function(value) {
_setShowComments([ {
name : 'showComments',
value : value
} ]);
};
/**
* Search for similar data mining entries on the map.
*/
......@@ -232,10 +215,10 @@ ServerConnector.sendRefreshRequest = function(overlayName) {
if (refreshFunction !== undefined) {
refreshFunction();
} else {
logger.warn("Refresh function for " + overlayName + " doesn't exist");
throw new Error("Refresh function for " + overlayName + " doesn't exist");
}
} else {
logger.warn("[Refresh function] Unknown overlay: ", overlayName);
throw new Error("[Refresh function] Unknown overlay: ", overlayName);
}
};
......@@ -299,11 +282,6 @@ ServerConnector.DRUG_OVERLAY_NAME = 'drug';
*/
ServerConnector.CHEMICAL_OVERLAY_NAME = 'chemical';
/**
* Name of the overlay for 'comment' overlay.
*/
ServerConnector.COMMENT_OVERLAY_NAME = 'comment';
/**
* Name of the overlay for 'mirna' overlay.
*/
......@@ -383,21 +361,6 @@ ServerConnector.requestDrugDetailDataFunction = function(identfiedElement, id) {
value : identfiedElement.getType(),
} ]);
};
ServerConnector.requestCommentDetailDataFunction = function(identfiedElement, id) {
_requestCommentDetailDataFunction([ {
name : "searchResultIdentifier",
value : id,
}, {
name : "objectIdentifier",
value : identfiedElement.getId(),
}, {
name : "modelIdentifier",
value : identfiedElement.getModelId(),
}, {
name : "type",
value : identfiedElement.getType(),
} ]);
};
/**
* Sends request to the server to refresh data in 'drug' overlay.
......@@ -450,30 +413,6 @@ ServerConnector.clearChemicalOverlay = function() {
_clearChemicalOverlayCollection();
};
/**
* Register 'comment' overlay on the server.
*/
ServerConnector.registerCommentOverlay = function() {
_registerCommentOverlayCollection([ {
name : "overlayName",
value : ServerConnector.COMMENT_OVERLAY_NAME,
} ]);
};
/**
* Sends request to the server to refresh data in 'comment' overlay.
*/
ServerConnector.refreshCommentOverlay = function() {
_refreshCommentOverlayCollection();
};
/**
* Clear data related to 'comment' overlay.
*/
ServerConnector.clearCommentOverlay = function() {
_clearCommentOverlayCollection();
};
/**
* Clear data related to 'data mining' overlay.
*/
......@@ -559,16 +498,6 @@ ServerConnector._overlayMethods[ServerConnector.CHEMICAL_OVERLAY_NAME] = {
requestDetailDataFunction : ServerConnector.requestChemicalDetailDataFunction,
};
/**
* Define pack of methods for 'comment' overlay.
*/
ServerConnector._overlayMethods[ServerConnector.COMMENT_OVERLAY_NAME] = {
initFunction : ServerConnector.registerCommentOverlay,
refreshFunction : ServerConnector.refreshCommentOverlay,
clearFunction : ServerConnector.clearCommentOverlay,
requestDetailDataFunction : ServerConnector.requestCommentDetailDataFunction,
};
ServerConnector._overlayMethods[ServerConnector.MI_RNA_OVERLAY_NAME] = {
initFunction : ServerConnector.registerMiRnaOverlay,
refreshFunction : ServerConnector.refreshMiRnaOverlay,
......@@ -689,19 +618,6 @@ ServerConnector.searchByCoord = function(modelId, latLngCoordinates) {
} ]);
};
ServerConnector.requestUpdateCommentList = function(modelId, latLngCoordinates) {
_updateCommentList([ {
name : 'submodelId',
value : modelId
}, {
name : 'latCoord',
value : latLngCoordinates.lat()
}, {
name : 'lngCoord',
value : latLngCoordinates.lng()
} ]);
};
ServerConnector.sendReferenceGenomeDetailRequest = function(type, version) {
logger.debug("Send request", type, version);
_sendReferenceGenomeDetailRequest([ {
......@@ -844,6 +760,24 @@ ServerConnector.getOverlaysUrl = function(projectId, token) {
});
};
ServerConnector.getCommentsUrl = function(params) {
var id = this.idsToString(params.ids);
var columns = this.columnsToString(params.columns);
var projectId = params.projectId;
var token = params.token;
return this.getApiUrl({type:"comment",
method: "getCommentList",
params: {
projectId: projectId,
columns: columns,
id: id,
token: token},
});
};
ServerConnector.getOverlayByIdUrl = function(overlayId, projectId, token) {
return this.getApiUrl({type:"overlay",
method: "getOverlayById",
......@@ -868,11 +802,13 @@ ServerConnector.getOverlayElementsUrl = function(overlayId, projectId, token) {
ServerConnector.idsToString = function (ids) {
var result = "";
for (var i = 0; i < ids.length; i++) {
if (result !== "") {
result = result + "," + ids[i];
} else {
result = ids[i];
if (ids!==undefined) {
for (var i = 0; i < ids.length; i++) {
if (result !== "") {
result = result + "," + ids[i];
} else {
result = ids[i];
}
}
}
return result;
......@@ -1106,6 +1042,28 @@ ServerConnector.getAliases = function(aliasIds, projectId, columns) {
});
};
ServerConnector.getLightComments = function(params) {
var self = this;
var projectId;
return new Promise(function(resolve, reject) {
return self.getProjectId(params.projectId).then(function(result) {
projectId = result;
return self.getToken();
}).then(function(token) {
return self.readFile(self.getCommentsUrl({ids:params.ids, projectId:projectId, token:token, columns:params.columns}));
}).then(function(content) {
var array=JSON.parse(content);
var result = [];
for (var i = 0; i < array.length; i++) {
result.push(new IdentifiedElement(array[i]));
}
resolve(result);
}).catch(function(exception){
reject(exception);
});
});
};
ServerConnector.getLightAliases = function(aliasIds, projectId) {
return this.getAliases(aliasIds,projectId,"id,bounds,modelId");
};
......
......@@ -197,12 +197,14 @@ CustomMap.prototype.clearOverlays = function() {
};
CustomMap.prototype.refreshOverlays = function() {
var promises = [];
for ( var overlayName in this.overlayCollections) {
if (this.overlayCollections.hasOwnProperty(overlayName)) {
var collection = this.overlayCollections[overlayName];
collection.refresh();
promises.push(collection.refresh());
}
}
return Promise.all(promises);
};
/**
......
......@@ -32,7 +32,11 @@ function IdentifiedElement(javaObject) {
this.type = "POINT";
} else {
// identifier of the object to visualize
this.setId(javaObject.objectId);
if (javaObject.objectId === undefined) {
this.setId(javaObject.id);
} else {
this.setId(javaObject.objectId);
}
// which marker should be used to show this object
this.icon = javaObject.icon;
// on which model the element is located
......
"use strict";
var OverlayCollection = require('./OverlayCollection');
var IdentifiedElement = require('../data/IdentifiedElement');
var logger = require('../../logger');
function CommentDbOverlay(params) {
// call super constructor
OverlayCollection.call(this, params);
}
CommentDbOverlay.prototype = Object.create(OverlayCollection.prototype);
CommentDbOverlay.prototype.constructor = CommentDbOverlay;
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]));
}
return self.getMap().updateOverlayCollection(self);
}).then(function() {
resolve(self.elements);
}).catch(reject);
});
};
module.exports = CommentDbOverlay;
......@@ -2,6 +2,7 @@
var functions = require('./Functions');
var CommentDbOverlay = require('./map/overlay/CommentDbOverlay');
var CustomMap = require('./map/CustomMap');
var OverlayCollection = require('./map/overlay/OverlayCollection');
......@@ -65,63 +66,73 @@ function create(params) {
for (var i = 0; i < params.dataCollections.length; i++) {
var collectionParams = params.dataCollections[i];
collectionParams.map = result;
ServerConnector.addOverlayCollection(new OverlayCollection(collectionParams));
var collection = null;
if (collectionParams.name === "comment") {
collection = new CommentDbOverlay(collectionParams);
} else {
collection = new OverlayCollection(collectionParams);
}
ServerConnector.addOverlayCollection(collection);
}
result.refreshOverlays();
} else {
logger.warn("No overlay collection defined");
}
if (GuiConnector.getParams["search"] !== undefined) {
GuiConnector.search(GuiConnector.getParams["search"]);
}
return new Promise(function(resolve, reject) {
result.refreshOverlays().then(function() {
if (GuiConnector.getParams["search"] !== undefined) {
GuiConnector.search(GuiConnector.getParams["search"]);
}
if (GuiConnector.getParams["comments"] === "on") {
document.getElementById('comment_checkbox').click();
}
if (GuiConnector.getParams["layout"] !== undefined) {
var layouts = params.project.getModel().getLayouts();
var found = false;
for (var j = 0; j < layouts.length; j++) {
var layout = layouts[j];
if (layout.getName() === GuiConnector.getParams["layout"]) {
found = true;
if (layout.getInputDataAvailable()) {
result.addSelectedLayout(layout.getId(), layout.getName());
} else {
result.openLayoutByName(layout.getName());
if (GuiConnector.getParams["comments"] === "on") {
document.getElementById('comment_checkbox').click();
}
if (GuiConnector.getParams["layout"] !== undefined) {
var layouts = params.project.getModel().getLayouts();
var found = false;
for (var j = 0; j < layouts.length; j++) {
var layout = layouts[j];
if (layout.getName() === GuiConnector.getParams["layout"]) {
found = true;
if (layout.getInputDataAvailable()) {
result.addSelectedLayout(layout.getId(), layout.getName());
} else {
result.openLayoutByName(layout.getName());
}
}
}
}
}
}
// when I try to hide legend from the beginning or in the same thread it's
// hidden forever... ;/
setTimeout(function() {
GuiConnector.hideLegend();
var submodelId = GuiConnector.getParams["submap"];
if (submodelId !== undefined) {
ServerConnector.createSubmodelDialog(submodelId);
// for some reason the call above is not sync (even though it's required)
var waitingForResponse = setInterval(function() {
if (GuiConnector.getJsPopupForSubmodelId(submodelId) !== undefined) {
GuiConnector.openDialog(submodelId);
clearInterval(waitingForResponse);
if (GuiConnector.getParams["zoom"] !== undefined) {
result.setZoom(submodelId, parseInt(GuiConnector.getParams["zoom"]));
}
if (GuiConnector.getParams["x"] !== undefined && GuiConnector.getParams["y"] !== undefined) {
var x = GuiConnector.getParams["x"];
var y = GuiConnector.getParams["y"];
var point = new google.maps.Point(x, y);
result.setCenter(submodelId, point);
}
// when I try to hide legend from the beginning or in the same thread it's
// hidden forever... ;/
setTimeout(function() {
GuiConnector.hideLegend();
var submodelId = GuiConnector.getParams["submap"];
if (submodelId !== undefined) {
ServerConnector.createSubmodelDialog(submodelId);
// for some reason the call above is not sync (even though it's
// required)
var waitingForResponse = setInterval(function() {
if (GuiConnector.getJsPopupForSubmodelId(submodelId) !== undefined) {
GuiConnector.openDialog(submodelId);
clearInterval(waitingForResponse);
if (GuiConnector.getParams["zoom"] !== undefined) {
result.setZoom(submodelId, parseInt(GuiConnector.getParams["zoom"]));
}
if (GuiConnector.getParams["x"] !== undefined && GuiConnector.getParams["y"] !== undefined) {
var x = GuiConnector.getParams["x"];
var y = GuiConnector.getParams["y"];
var point = new google.maps.Point(x, y);
result.setCenter(submodelId, point);
}
}
}, 100);
}
}, 100);
}
}, 0);
}, 0);
resolve(result);
}).catch(reject);
});
return result;
}
var minerva = {
......
......@@ -20,9 +20,10 @@ describe('minerva global', function() {
it('create', function() {
var options = helper.createOptions();
var result = minerva.create(options);
assert.ok(result);
assert.equal(logger.getWarnings().length, 1);
return minerva.create(options).then(function(result) {
assert.ok(result);
assert.equal(logger.getWarnings().length, 1);
});
});
it('create with layout', function() {
......@@ -47,12 +48,13 @@ describe('minerva global', function() {
} ],
};
var result = minerva.create(options);
assert.ok(result);
// input file is not available so it's the background
assert.equal(result.getSelectedLayouts().length, 0);
assert.equal(ServerConnector.getSelectedLayout(), "cv" + layoutId);
assert.equal(logger.getWarnings().length, 1);
return minerva.create(options).then(function(result) {
assert.ok(result);
// input file is not available so it's the background
assert.equal(result.getSelectedLayouts().length, 0);
assert.equal(ServerConnector.getSelectedLayout(), "cv" + layoutId);
assert.equal(logger.getWarnings().length, 1);
});
});
it('create with layout 2', function() {
......@@ -62,7 +64,7 @@ describe('minerva global', function() {
var layout = helper.createLayout();
layout.setInputDataAvailable(true);
//disable upload of the data from server
// disable upload of the data from server
layout.setInitialized(true);
var layoutName = layout.getName();
......@@ -78,10 +80,29 @@ describe('minerva global', function() {
} ],
};
var result = minerva.create(options);
assert.ok(result);
// input file is available so it's not the background file but overlay
assert.equal(result.getSelectedLayouts().length, 1);
assert.equal(logger.getWarnings().length, 1);
return minerva.create(options).then(function(result) {
assert.ok(result);
// input file is available so it's not the background file but overlay
assert.equal(result.getSelectedLayouts().length, 1);
assert.equal(logger.getWarnings().length, 1);
});
});
it('create with comment overlay', function() {
var project = helper.createProject();
project.getModel().setId(15781);
var map = helper.createGoogleMap();
var options = {
map : map,
project : project,
dataCollections : [ {
name : "comment"
} ],
};
return minerva.create(options).then(function(result) {
assert.ok(result);
});
});
});
[{"modelId":15781,"icon":"icons/comment.png","id":"Point2D.Double[241.00605157081114, 372.34797385543044]","type":"POINT"},{"modelId":15781,"icon":"icons/comment.png","id":"Point2D.Double[643.9579684828551, 144.0935652248765]","type":"POINT"}]
\ No newline at end of file
Supports Markdown
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