Commit 99ea49b2 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

first working chemical panel

parent 9692e35e
......@@ -8,6 +8,7 @@ var request = require('request');
var Alias = require('./map/data/Alias');
var Chemical = require('./map/data/Chemical');
var Comment = require('./map/data/Comment');
var Drug = require('./map/data/Drug');
var ConfigurationType = require('./ConfigurationType');
......@@ -180,43 +181,6 @@ ServerConnector.clearDataMiningOverlay = function() {
_clearMissingConnectionOverlayCollection();
};
ServerConnector.registerChemicalOverlay = function() {
_registerChemicalOverlayCollection([ {
name : "overlayName",
value : ServerConnector.CHEMICAL_OVERLAY_NAME,
} ]);
};
ServerConnector.requestChemicalDetailDataFunction = function(identfiedElement, id) {
_requestChemicalDetailDataFunction([ {
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.
*/
ServerConnector.refreshChemicalOverlay = function() {
_refreshChemicalOverlayCollection();
};
/**
* Clear data related to 'chemical' overlay.
*/
ServerConnector.clearChemicalOverlay = function() {
_clearChemicalOverlayCollection();
};
/**
* Clear data related to 'data mining' overlay.
*/
......@@ -273,16 +237,6 @@ ServerConnector._overlayMethods[ServerConnector.DATA_MINING_OVERLAY_NAME] = {
clearFunction : ServerConnector.clearDataMiningOverlay,
};
/**
* Define pack of methods for 'chemical' overlay.
*/
ServerConnector._overlayMethods[ServerConnector.CHEMICAL_OVERLAY_NAME] = {
initFunction : ServerConnector.registerChemicalOverlay,
refreshFunction : ServerConnector.refreshChemicalOverlay,
clearFunction : ServerConnector.clearChemicalOverlay,
requestDetailDataFunction : ServerConnector.requestChemicalDetailDataFunction,
};
ServerConnector._overlayMethods[ServerConnector.MI_RNA_OVERLAY_NAME] = {
initFunction : ServerConnector.registerMiRnaOverlay,
refreshFunction : ServerConnector.refreshMiRnaOverlay,
......@@ -299,7 +253,7 @@ ServerConnector.sendClearRequest = function(overlayName) {
} else {
logger.warn("Clear function for " + overlayName + " doesn't exist");
}
} else if (overlayName==="search" || overlayName==="comment" || overlayName ==="drug"){
} else if (overlayName==="search" || overlayName==="comment" || overlayName ==="drug"|| overlayName ==="chemical"){
logger.warn("Send clear request for overlay that doesn't support it: "+overlayName);
} else {
throw new Error("[Clear function] Unknown overlay: ", overlayName);
......@@ -1071,7 +1025,7 @@ ServerConnector.getChemicalsByQuery = function(params) {
var array=JSON.parse(content);
var result = [];
for (var i = 0; i < array.length; i++) {
result.push(new Drug(array[i]));
result.push(new Chemical(array[i]));
}
resolve(result);
}).catch(function(exception){
......
......@@ -461,4 +461,40 @@ AbstractPanel.prototype.addResultTab = function(query, elements) {
}
};
AbstractPanel.prototype.createTargetRow = function(target, icon) {
var self = this;
var result = document.createElement("tr");
var iconColumn = document.createElement("td");
iconColumn.style.width = "20px";
iconColumn.style.verticalAlign = "middle";
iconColumn.style.textAlign = "center";
result.appendChild(iconColumn);
if (target.getTargetElements().length > 0) {
iconColumn.appendChild(self.createIcon(icon));
var checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.checked = target.isVisible();
checkbox.onclick = function() {
target.setIsVisible(!target.isVisible());
self.getOverlayDb().callListeners("onTargetVisibilityChange");
};
iconColumn.appendChild(checkbox);
}
var descColumn = document.createElement("td");
result.appendChild(descColumn);
descColumn.appendChild(self.createParamLine("Name: ", target.getName()));
descColumn.appendChild(self.createAnnotations("Elements: ", target.getTargetParticipants(), {
showType : false,
inline : true
}));
descColumn.appendChild(self.createAnnotations("References: ", target.getReferences(), {
showType : false,
}));
return result;
};
module.exports = AbstractPanel;
"use strict";
/* exported logger */
var logger = require('../logger');
var AbstractPanel = require('./AbstractPanel');
function ChemicalPanel(params) {
params.panelName = "chemical";
AbstractPanel.call(this, params);
}
ChemicalPanel.prototype = Object.create(AbstractPanel.prototype);
ChemicalPanel.prototype.constructor = ChemicalPanel;
ChemicalPanel.prototype.createPreamble = function(chemical) {
var self = this;
var result = document.createElement("div");
if (chemical === undefined || chemical.getName() === undefined) {
result.appendChild(self.createLabel("NOT FOUND"));
} else {
result.appendChild(self.createParamLine("Chemical: ", chemical.getName()));
result.appendChild(self.createParamLine("Description: ", chemical.getDescription()));
result.appendChild(self.createArrayParamLine("Synonyms: ", chemical.getSynonyms()));
result.appendChild(self.createParamLine("Direct Evidence: ", chemical.getDirectEvidence()));
result.appendChild(self.createAnnotations("Directe Evidence Publications: ", chemical.getDirectEvidenceReferences()));
result.appendChild(self.createAnnotations("Sources: ", chemical.getReferences()));
result.appendChild(self.createNewLine());
}
return result;
};
ChemicalPanel.prototype.createTableElement = function(target, icon) {
return this.createTargetRow(target, icon);
};
ChemicalPanel.prototype.searchByQuery = function() {
var self = this;
var query = self.getSearchInput().value;
return self.getOverlayDb().searchByQuery(query);
};
module.exports = ChemicalPanel;
......@@ -31,41 +31,9 @@ DrugPanel.prototype.createPreamble = function(drug) {
};
DrugPanel.prototype.createTableElement = function(target, icon) {
var self = this;
var result = document.createElement("tr");
var iconColumn = document.createElement("td");
iconColumn.style.width = "20px";
iconColumn.style.verticalAlign = "middle";
iconColumn.style.textAlign = "center";
result.appendChild(iconColumn);
if (target.getTargetElements().length > 0) {
iconColumn.appendChild(self.createIcon(icon));
var checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.checked = target.isVisible();
checkbox.onclick = function() {
target.setIsVisible(!target.isVisible());
self.getOverlayDb().callListeners("onTargetVisibilityChange");
};
iconColumn.appendChild(checkbox);
}
var descColumn = document.createElement("td");
result.appendChild(descColumn);
descColumn.appendChild(self.createParamLine("Name: ", target.getName()));
descColumn.appendChild(self.createAnnotations("Elements: ", target.getTargetParticipants(), {
showType : false,
inline : true
}));
descColumn.appendChild(self.createAnnotations("References: ", target.getReferences(), {
showType : false,
}));
return result;
return this.createTargetRow(target, icon);
};
DrugPanel.prototype.searchByQuery = function() {
var self = this;
var query = self.getSearchInput().value;
......
......@@ -10,7 +10,7 @@ var AliasMarker = require('./marker/AliasMarker');
var CommentDialog = require('../gui/CommentDialog');
var ControlType = require('./ControlType');
var CustomMapOptions = require('./CustomMapOptions');
var DrugDbCollection = require('./overlay/DrugDbOverlay');
var CommentDbCollection = require('./overlay/CommentDbOverlay');
var IdentifiedElement = require('./data/IdentifiedElement');
var OverlayCollection = require('./overlay/OverlayCollection');
var PointMarker = require('./marker/PointMarker');
......@@ -206,7 +206,7 @@ CustomMap.prototype.refreshOverlays = function() {
for ( var overlayName in this.overlayCollections) {
if (this.overlayCollections.hasOwnProperty(overlayName)) {
var collection = this.overlayCollections[overlayName];
if (!(collection instanceof SearchDbCollection)&&!(collection instanceof DrugDbCollection)) {
if ((collection instanceof CommentDbCollection) || (collection.constructor.name==="OverlayCollection")) {
promises.push(collection.refresh());
}
}
......@@ -439,7 +439,7 @@ CustomMap.prototype.registerSource = function(overlayCollection) {
return self.updateOverlayCollection(overlayCollection, false);
});
}
if (overlayCollection.getName() === "drug") {
if (overlayCollection.getName() === "drug" || overlayCollection.getName() === "chemical") {
overlayCollection.addListener("onSearch", function() {
return self.updateOverlayCollection(overlayCollection, false);
});
......
"use strict";
var Target = require("./Target");
function Chemical(javaObject) {
if (javaObject !== undefined) {
this.setName(javaObject.name);
this.setReferences(javaObject.references);
this.setDescription(javaObject.description);
this.setSynonyms(javaObject.synonyms);
this.setId(javaObject.id);
this.setTargets(javaObject.targets);
this.setDirectEvidence(javaObject.directEvidence);
this.setDirectEvidenceReferences(javaObject.directEvidenceReferences);
}
}
Chemical.prototype.setDirectEvidence = function(directeEvidence) {
this._directeEvidence = directeEvidence;
};
Chemical.prototype.getDirectEvidence = function() {
return this._directeEvidence;
};
Chemical.prototype.setDirectEvidenceReferences = function(directeEvidenceReferences) {
this._directeEvidenceReferences = directeEvidenceReferences;
};
Chemical.prototype.getDirectEvidenceReferences = function() {
return this._directEvidenceReferences;
};
Chemical.prototype.setBrandNames = function(brandNames) {
this._brandNames = brandNames;
};
Chemical.prototype.getBrandNames = function() {
return this._brandNames;
};
Chemical.prototype.setReferences = function(references) {
this._references = references;
};
Chemical.prototype.getReferences = function() {
return this._references;
};
Chemical.prototype.setSynonyms = function(synonyms) {
this._synonyms = synonyms;
};
Chemical.prototype.getSynonyms = function() {
return this._synonyms;
};
Chemical.prototype.setName = function(name) {
this._name = name;
};
Chemical.prototype.getName = function() {
return this._name;
};
Chemical.prototype.setId = function(id) {
this._id = id;
};
Chemical.prototype.getId = function() {
return this._id;
};
Chemical.prototype.setDescription = function(description) {
this._description = description;
};
Chemical.prototype.getDescription = function() {
return this._description;
};
Chemical.prototype.setTargets = function(targets) {
this._targets = [];
for (var i = 0; i < targets.length; i++) {
this._targets.push(new Target(targets[i]));
}
};
Chemical.prototype.getTargets = function() {
return this._targets;
};
Chemical.prototype.setBloodBrainBarrier = function(bloodBrainBarrier) {
this._bloodBrainBarrier = bloodBrainBarrier;
};
Chemical.prototype.getBloodBrainBarrier = function() {
return this._bloodBrainBarrier;
};
module.exports = Chemical;
......@@ -3,6 +3,8 @@
var functions = require('./Functions');
var AbstractDbOverlay = require('./map/overlay/AbstractDbOverlay');
var ChemicalDbOverlay = require('./map/overlay/ChemicalDbOverlay');
var ChemicalPanel = require('./gui/ChemicalPanel');
var CommentDbOverlay = require('./map/overlay/CommentDbOverlay');
var ControlType = require('./map/ControlType');
var CustomMap = require('./map/CustomMap');
......@@ -120,6 +122,13 @@ function create(params) {
element : document.getElementById("drugTab"),
customMap : result
});
} else if (collectionParams.name === "chemical") {
collection = new ChemicalDbOverlay(collectionParams);
result.registerSource(collection);
new ChemicalPanel({
element : document.getElementById("chemicalTab"),
customMap : result
});
} else {
collection = new OverlayCollection(collectionParams);
result.registerSource(collection);
......
"use strict";
var Helper = require('../helper');
require("../mocha-config.js");
var Chemical = require('../../../main/js/map/data/Chemical');
var ChemicalPanel = require('../../../main/js/gui/ChemicalPanel');
var chai = require('chai');
var assert = chai.assert;
var logger = require('../logger');
describe('ChemicalPanel', function() {
var helper;
before(function() {
helper = new Helper();
});
it('contructor', function() {
var div = helper.createChemicalTab();
var map = helper.createCustomMap();
helper.createChemicalDbOverlay(map);
new ChemicalPanel({
element : div,
customMap : map
});
assert.equal(logger.getWarnings().length, 0);
});
it('createChemicaleader for empty', function() {
var div = helper.createChemicalTab();
var map = helper.createCustomMap();
helper.createChemicalDbOverlay(map);
var panel = new ChemicalPanel({
element : div,
customMap : map
});
assert.ok(panel.createPreamble().innerHTML.indexOf("NOT FOUND") > 0);
});
it('createChemicaleader for empty', function() {
var div = helper.createChemicalTab();
var map = helper.createCustomMap();
helper.createChemicalDbOverlay(map);
var panel = new ChemicalPanel({
element : div,
customMap : map
});
assert.ok(panel.createPreamble(new Chemical()).innerHTML.indexOf("NOT FOUND") > 0);
});
it('on searchResults changed', function() {
var div = helper.createChemicalTab();
var map = helper.createCustomMap();
map.getModel().setId(15781);
var chemicalDbOverlay = helper.createChemicalDbOverlay(map);
new ChemicalPanel({
element : div,
customMap : map
});
return chemicalDbOverlay.searchByQuery("rotenone").then(function() {
assert.equal(logger.getWarnings().length, 0);
assert.ok(div.innerHTML.indexOf("marker/mechanism") >= 0);
});
});
it('searchByQuery', function() {
var div = helper.createChemicalTab();
var map = helper.createCustomMap();
map.getModel().setId(15781);
helper.createChemicalDbOverlay(map);
var panel = new ChemicalPanel({
element : div,
customMap : map
});
panel.getSearchInput().value = "rotenone";
return panel.searchByQuery().then(function() {
assert.equal(logger.getWarnings().length, 0);
assert.ok(div.innerHTML.indexOf("Rotenone ") >= 0);
});
});
});
......@@ -32,6 +32,10 @@ Helper.prototype.createDrugTab = function() {
return this.createPanelTab("drugTab");
};
Helper.prototype.createChemicalTab = function() {
return this.createPanelTab("chemicalTab");
};
Helper.prototype.createPanelTab = function(id) {
var result = document.createElement("div");
result.id = id;
......
......@@ -23,11 +23,15 @@ describe('minerva global', function() {
global.drugTab = helper.createDrugTab();
document.body.appendChild(global.drugTab);
global.chemicalTab = helper.createChemicalTab();
document.body.appendChild(global.chemicalTab);
});
afterEach(function() {
document.body.removeChild(global.searchTab);
document.body.removeChild(global.drugTab);
document.body.removeChild(global.chemicalTab);
});
it('create', function() {
......@@ -149,6 +153,20 @@ describe('minerva global', function() {
});
});
it('create with chemical overlay', function() {
var project = helper.createProject();
project.getModel().setId(15781);
var options = helper.createOptions(project);
options.dataCollections.push({
name : "chemical"
});
return minerva.create(options).then(function(result) {
assert.ok(result);
});
});
it('create with search overlay and GET search param', function() {
GuiConnector.getParams["search"] = "s1";
......
......@@ -207,9 +207,8 @@ public class ChemicalRestImpl {
columnsSet.add("description");
columnsSet.add("synonyms");
columnsSet.add("id");
columnsSet.add("directevidencereferences");
columnsSet.add("description");
columnsSet.add("directevidence");
columnsSet.add("directEvidenceReferences");
columnsSet.add("directEvidence");
columnsSet.add("targets");
} else {
for (String str : columns.split(",")) {
......
......@@ -195,7 +195,7 @@ public class ChemicalService implements IChemicalService {
throw new InvalidArgumentException("diseaseID cannot be null");
}
if (name == null || name.isEmpty()) {
throw new InvalidArgumentException("name cannot be null");
return null;
}
MiriamData id = null;
List<Chemical> result = new ArrayList<Chemical>();
......
......@@ -6,132 +6,39 @@
xmlns:cc="http://java.sun.com/jsf/composite/pfcomp"
xmlns:p="http://primefaces.org/ui">
<h:outputStylesheet library="css" name="chemical.css" />
<h:outputStylesheet library="css" name="global.css" />
<div id="chemicalTab">
<div name="searchQuery" class="searchPanel">
<table cellpadding="4" style="width:100%">
<tbody>
<tr>
<td>FIND TARGETS:</td>
</tr>
<tr>
<td>
<input name="searchInput" class="input-field typeahead" autocomplete="off"/>
</td>
<td>
<a name="searchButton" href="#">
<img src="resources/images/icons/search.png"/>
</a>
</td>
</tr>
</tbody>
</table>
</div>
<div name="searchResults" class="tabbable boxed parentTabs">
<ul class="nav nav-tabs">
<li class="active"><a href="#set1"/></li>
</ul>
<div class="tab-content">
<div class="tab-pane fade active in" id="set1">
</div>
</div>
</div>
</div>
<h:form id="chemicalForm" class="chemicalPanel">
<h:panelGrid id="chemicalSearchComponent" columns="2" cellpadding="4"
style="width:100%;" disabled="true"