diff --git a/frontend-js/src/main/js/gui/leftPanel/AbstractDbPanel.js b/frontend-js/src/main/js/gui/leftPanel/AbstractDbPanel.js index 4ac01269f335e0baedb92c2ea2a709028e9c19b6..6589ecc001536d09984f33ac5cf8066afd8b2e58 100644 --- a/frontend-js/src/main/js/gui/leftPanel/AbstractDbPanel.js +++ b/frontend-js/src/main/js/gui/leftPanel/AbstractDbPanel.js @@ -312,10 +312,12 @@ AbstractPanel.prototype.createTargetRow = function (target, icon) { descColumn.appendChild(guiUtils.createParamLine("Name: ", target.getName())); descColumn.appendChild(guiUtils.createAnnotations("Elements: ", target.getTargetParticipants(), { showType: false, - inline: true + inline: true, + groupAnnotations: false })); descColumn.appendChild(guiUtils.createAnnotations("References: ", target.getReferences(), { - showType: false + showType: false, + groupAnnotations: false })); if (submaps.length > 0) { descColumn.appendChild(guiUtils.createLabel("Available in submaps: ")); diff --git a/frontend-js/src/main/js/gui/leftPanel/ChemicalPanel.js b/frontend-js/src/main/js/gui/leftPanel/ChemicalPanel.js index de9406d698ed1966f9b4f7cd7d77443c22bf6b7a..35d60913fe28f1b620ed15f6df7d38d9914e3d4f 100644 --- a/frontend-js/src/main/js/gui/leftPanel/ChemicalPanel.js +++ b/frontend-js/src/main/js/gui/leftPanel/ChemicalPanel.js @@ -42,7 +42,7 @@ ChemicalPanel.prototype.createPreamble = function (chemical) { result.appendChild(guiUtils.createArrayParamLine("Synonyms: ", chemical.getSynonyms())); result.appendChild(guiUtils.createParamLine("Direct Evidence: ", chemical.getDirectEvidence())); result.appendChild(guiUtils - .createAnnotations("Direct Evidence Publications: ", chemical.getDirectEvidenceReferences())); + .createAnnotations("Direct Evidence Publications: ", chemical.getDirectEvidenceReferences(), {groupAnnotations: false})); result.appendChild(guiUtils.createAnnotations("Sources: ", chemical.getReferences())); result.appendChild(guiUtils.createNewLine()); } diff --git a/frontend-js/src/main/js/gui/leftPanel/DrugPanel.js b/frontend-js/src/main/js/gui/leftPanel/DrugPanel.js index b670a7842fa730157faf19d0adce4b4b84390cad..c7b0fe717e1662bcc78555a718618d6730416e83 100644 --- a/frontend-js/src/main/js/gui/leftPanel/DrugPanel.js +++ b/frontend-js/src/main/js/gui/leftPanel/DrugPanel.js @@ -11,17 +11,18 @@ var PanelControlElementType = require('../PanelControlElementType'); function DrugPanel(params) { params.panelName = "drug"; params.helpTip = '<p>source: <a target="_drugbank" href="http://www.drugbank.ca/">DrugBank</a> and ' - + '<a target="_drugbank" href="https://www.ebi.ac.uk/chembl/">ChEMBL</a></p>' - + "<p>use of drug names, synonyms and brand names is supported<p>separate multiple search by semicolon</p>"; - params.placeholder = "drug, synonym, brand name"; - + + '<a target="_drugbank" href="https://www.ebi.ac.uk/chembl/">ChEMBL</a></p>' + + "<p>use of drug names, synonyms and brand names is supported<p>separate multiple search by semicolon</p>"; + params.placeholder = "drug, synonym, brand name"; + AbstractDbPanel.call(this, params); this.getControlElement(PanelControlElementType.SEARCH_LABEL).innerHTML = "SEARCH FOR TARGETS OF:"; } + DrugPanel.prototype = Object.create(AbstractDbPanel.prototype); DrugPanel.prototype.constructor = DrugPanel; -DrugPanel.prototype.createPreamble = function(drug) { +DrugPanel.prototype.createPreamble = function (drug) { var self = this; var guiUtils = self.getGuiUtils(); var result = document.createElement("div"); @@ -33,24 +34,24 @@ DrugPanel.prototype.createPreamble = function(drug) { result.appendChild(guiUtils.createArrayParamLine("Synonyms: ", drug.getSynonyms())); result.appendChild(guiUtils.createArrayParamLine("Brand names: ", drug.getBrandNames())); result.appendChild(guiUtils.createParamLine("Blood brain barrier: ", drug.getBloodBrainBarrier())); - result.appendChild(guiUtils.createAnnotations("Sources: ", drug.getReferences())); + result.appendChild(guiUtils.createAnnotations("Sources: ", drug.getReferences(), {groupAnnotations: false})); result.appendChild(guiUtils.createNewLine()); } return result; }; -DrugPanel.prototype.createTableElement = function(target, icon) { +DrugPanel.prototype.createTableElement = function (target, icon) { return this.createTargetRow(target, icon); }; -DrugPanel.prototype.searchByQuery = function() { +DrugPanel.prototype.searchByQuery = function () { var self = this; var query = self.getControlElement(PanelControlElementType.SEARCH_INPUT).value; return self.getOverlayDb().searchByQuery(query); }; -DrugPanel.prototype.init = function() { +DrugPanel.prototype.init = function () { var query = ServerConnector.getSessionData().getDrugQuery(); if (query !== undefined) { return this.getOverlayDb().searchByEncodedQuery(query); @@ -60,7 +61,7 @@ DrugPanel.prototype.init = function() { }; DrugPanel.prototype.destroy = function () { - return Promise.resolve(); + return Promise.resolve(); }; DrugPanel.prototype.getAutocomplete = function (query) { diff --git a/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js b/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js index 42486c427e2dc0b5915e1ce7e9f6adbb7cf98b06..f0b329d370adf6b29385f67650ab0d48846a6d23 100644 --- a/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js +++ b/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js @@ -3,7 +3,7 @@ /* exported logger */ var Alias = require('../../map/data/Alias'); -var ConfigurationType= require('../../ConfigurationType'); +var ConfigurationType = require('../../ConfigurationType'); var GuiConnector = require('../../GuiConnector'); var AbstractGuiElement = require('../AbstractGuiElement'); @@ -171,52 +171,20 @@ GuiUtils.prototype.createAnnotations = function (label, value, options) { return result; }; -GuiUtils.prototype.createAnnotationList = function (annotations, options) { - var showType = true; - var inline = false; - if (options !== undefined) { - if (options.showType !== undefined) { - showType = options.showType; - } - if (options.inline !== undefined) { - inline = options.inline; - } - } - - var self = this; - var result = document.createElement("div"); - - var annotators = this.getConfiguration().getAnnotators(); - var annotatorsClassMapping = {}; - for (var i = 0; i < annotators.length; i++) { - annotatorsClassMapping[annotators[i].getClassName()] = annotators[i]; - } - - var grouppedAnnotations = {}; - for (var i = 0; i < annotations.length; i++) { - var clazz = annotations[i].getAnnotatorClassName(); - if (!(clazz in grouppedAnnotations)) grouppedAnnotations[clazz] = []; - grouppedAnnotations[clazz].push(annotations[i]) - } - - // = annotatorClasName ? annotatorsClassMapping[annotatorClasName].getName() : "Annotated by curator"; - - var cntAnnotations = 0; - - Object.keys(grouppedAnnotations).sort().forEach(function (annotatorClass) { - - // var desc = grouppedAnnotations.keys()[i]; - var groupContainer = (inline ? document.createElement("span") : document.createElement("div")); - var descContainer = (inline ? document.createElement("span") : document.createElement("div")); - - var annotatorName = annotatorClass ? annotatorsClassMapping[annotatorClass].getName() : "Annotated by curator"; +function createGroupContainer(inline, annotatorClass, annotatorsClassMapping, groupAnnotations) { + var automaticallyAnnotated = !(annotatorClass === undefined || annotatorClass === "undefined" || annotatorClass === null || annotatorClass === ""); +// var desc = grouppedAnnotations.keys()[i]; + var groupContainer = (inline ? document.createElement("span") : document.createElement("div")); + var descContainer = (inline ? document.createElement("span") : document.createElement("div")); + if (groupAnnotations) { + var annotatorName = automaticallyAnnotated ? annotatorsClassMapping[annotatorClass].getName() : "Annotated by curator"; if (inline) { descContainer.innerHTML = annotatorName + ': '; } else { descContainer.innerHTML = annotatorName; - if (annotatorClass) { + if (automaticallyAnnotated) { var annotatorDescription = annotatorsClassMapping[annotatorClass].getDescription(); if (annotatorDescription) { var tooltipContainer = Functions.createElement({ @@ -239,6 +207,57 @@ GuiUtils.prototype.createAnnotationList = function (annotations, options) { descContainer.className = "minerva-annotation-group-header"; if (!inline) groupContainer.className = "minerva-annotation-group"; groupContainer.appendChild(descContainer); + } + return groupContainer; +} + +GuiUtils.prototype.createAnnotationList = function (annotations, options) { + var showType = true; + var inline = false; + var groupAnnotations = true; + if (options !== undefined) { + if (options.showType !== undefined) { + showType = options.showType; + } + if (options.inline !== undefined) { + inline = options.inline; + } + if (options.groupAnnotations !== undefined) { + groupAnnotations = options.groupAnnotations; + } + } + + var self = this; + var result = document.createElement("div"); + + var annotators = this.getConfiguration().getAnnotators(); + var annotatorsClassMapping = {}; + var grouppedAnnotations = {}; + if (groupAnnotations) { + for (var i = 0; i < annotators.length; i++) { + annotatorsClassMapping[annotators[i].getClassName()] = annotators[i]; + } + + for (var i = 0; i < annotations.length; i++) { + var clazz = annotations[i].getAnnotatorClassName(); + if (!(clazz in grouppedAnnotations)) grouppedAnnotations[clazz] = []; + grouppedAnnotations[clazz].push(annotations[i]) + } + } else { + annotatorsClassMapping["undefined"] = { + getName: function () { + return "" + } + }; + grouppedAnnotations["undefined"] = annotations; + } + + // = annotatorClasName ? annotatorsClassMapping[annotatorClasName].getName() : "Annotated by curator"; + + var cntAnnotations = 0; + + Object.keys(grouppedAnnotations).sort().forEach(function (annotatorClass) { + var groupContainer = createGroupContainer(inline, annotatorClass, annotatorsClassMapping, groupAnnotations); if (inline) { var par = document.createElement("span"); @@ -434,7 +453,7 @@ GuiUtils.prototype.createReactionElement = function (params) { div.appendChild(self.createNewLine()); } - if (self.getConfiguration().getOption(ConfigurationType.SHOW_REACTION_TYPE).getValue().toLowerCase()==="true") { + if (self.getConfiguration().getOption(ConfigurationType.SHOW_REACTION_TYPE).getValue().toLowerCase() === "true") { div.appendChild(self.createParamLine("Type: ", reaction.getType())); } div.appendChild(self.createParamLine("Symbol: ", reaction.getSymbol())); diff --git a/frontend-js/src/test/js/gui/leftPanel/GuiUtils-test.js b/frontend-js/src/test/js/gui/leftPanel/GuiUtils-test.js index 04cf05a62215549c27bc659c429adf360f58c4b3..d8194e12f81cea7f59beb461c423734b99ee95dd 100644 --- a/frontend-js/src/test/js/gui/leftPanel/GuiUtils-test.js +++ b/frontend-js/src/test/js/gui/leftPanel/GuiUtils-test.js @@ -201,4 +201,21 @@ describe('GuiUtils', function () { button.onclick(); $(".ui-dialog-titlebar-close").click(); }); + + describe('createAnnotationList', function () { + it('default', function () { + var guiUtils = new GuiUtils(helper.getConfiguration()); + var annotation = helper.createAnnotation(); + var element = guiUtils.createAnnotationList([annotation]); + assert.ok(element.innerHTML.indexOf("Annotated by curator") >= 0); + }); + it('without annotator type separation', function () { + var guiUtils = new GuiUtils(helper.getConfiguration()); + var annotation = helper.createAnnotation(); + var element = guiUtils.createAnnotationList([annotation], {groupAnnotations: false}); + assert.equal(element.innerHTML.indexOf("Annotated by curator"), -1, "annotator type description shouldn't be visible"); + }); + }); + + }); diff --git a/frontend-js/src/test/js/helper.js b/frontend-js/src/test/js/helper.js index d14e81dc155f412edd8950a0c4e7bceb79fcbae7..3464f548066c6f0598bc544f95408c286f19cf9d 100644 --- a/frontend-js/src/test/js/helper.js +++ b/frontend-js/src/test/js/helper.js @@ -6,6 +6,7 @@ var logger = require('./logger'); var Alias = require("../../main/js/map/data/Alias"); var AbstractCustomMap = require("../../main/js/map/AbstractCustomMap"); +var Annotation = require("../../main/js/map/data/Annotation"); var ChemicalDbOverlay = require("../../main/js/map/overlay/ChemicalDbOverlay"); var Comment = require("../../main/js/map/data/Comment"); var CommentDbOverlay = require("../../main/js/map/overlay/CommentDbOverlay"); @@ -465,6 +466,14 @@ Helper.prototype.triggerJqueryEvent = function (element, eventType) { return Promise.all(promises); }; +Helper.prototype.createAnnotation = function () { + return new Annotation({ + resource: "10.1038%2Fnpjsba.2016.20", + link: "http://doi.org/10.1038%2Fnpjsba.2016.20", + id: this.idCounter++, + type: "DOI" + }); +}; Helper.EPSILON = 1e-6; diff --git a/frontend-js/src/test/js/map/window/AliasInfoWindow-test.js b/frontend-js/src/test/js/map/window/AliasInfoWindow-test.js index c97b51f8d920187b5dda9444f8885efa9090a3b4..845f2bb295ce228d34b28cf3f3111074f7891c20 100644 --- a/frontend-js/src/test/js/map/window/AliasInfoWindow-test.js +++ b/frontend-js/src/test/js/map/window/AliasInfoWindow-test.js @@ -124,9 +124,7 @@ describe('AliasInfoWindow', function () { }).then(function (data) { var overlayDiv = aliasWindow.createOverlayInfoDiv(oc, data); assert.ok(functions.isDomElement(overlayDiv)); - logger.debug(overlayDiv.innerHTML); assert.ok(overlayDiv.innerHTML.indexOf('NADH') >= 0); - }); });