Skip to content
Snippets Groups Projects

Resolve "Get drugs by target"

Merged Piotr Gawron requested to merge 163-get-drugs-by-target into master
2 files
+ 5
4
Compare changes
  • Side-by-side
  • Inline
Files
2
"use strict";
var logger = require('../../logger');
var Functions = require('../../Functions');
var Comment = require('../data/Comment');
var GuiUtils = require('../../gui/leftPanel/GuiUtils');
var IdentifiedElement = require('../data/IdentifiedElement');
var ObjectWithListeners = require('../../ObjectWithListeners');
var TargettingStructure = require('../data/TargettingStructure');
/**
* Class representing any info window in our map.
@@ -59,6 +62,8 @@ function AbstractInfoWindow(params) {
this.registerListenerType("onShow");
this.registerListenerType("onUpdate");
this.setGuiUtils(new GuiUtils());
}
AbstractInfoWindow.prototype = Object.create(ObjectWithListeners.prototype);
@@ -92,7 +97,7 @@ AbstractInfoWindow.prototype.getOverlayFullViewArray = function() {
AbstractInfoWindow.prototype.setOverlayFullView = function(overlayName, value) {
var oldVal = this._overlayFullView[overlayName];
this._overlayFullView[overlayName] = value;
this.firePropertyChangeListener("overlayFullView", overlayName + "," + oldVal, value);
return this.firePropertyChangeListener("overlayFullView", overlayName + "," + oldVal, value);
};
/**
@@ -397,7 +402,7 @@ AbstractInfoWindow.prototype.update = function() {
};
AbstractInfoWindow.prototype._createTargetInfoDiv = function(overlay, data, name) {
var abstractInfoWindowSelf = this;
var self = this;
var result = document.createElement("div");
var count = 0;
@@ -412,10 +417,9 @@ AbstractInfoWindow.prototype._createTargetInfoDiv = function(overlay, data, name
var checkbox = document.createElement("input");
checkbox.id = "checkbox-" + name + "-" + this.getElementType() + "-" + this.getElementId();
checkbox.type = "checkbox";
checkbox.checked = abstractInfoWindowSelf.isOverlayFullView(overlay.getName());
checkbox.checked = self.isOverlayFullView(overlay.getName());
var checkboxClickedFunction = function() {
abstractInfoWindowSelf.setOverlayFullView(overlay.getName(), this.checked);
return true;
return self.setOverlayFullView(overlay.getName(), this.checked).then(null, GuiConnector.alert);
};
checkbox.onclick = checkboxClickedFunction;
@@ -427,83 +431,107 @@ AbstractInfoWindow.prototype._createTargetInfoDiv = function(overlay, data, name
checkboxDiv.appendChild(description);
result.appendChild(checkboxDiv);
}
count = 0;
for ( var dataId in data) {
if (data.hasOwnProperty(dataId)) {
count++;
}
}
var table = self._createTableForTargetDiv(data, overlay);
if (count === 0 && !overlay.allowGeneralSearch() && !this.isOverlayFullView(overlay.getName())) {
result = null;
}
if (result !== null) {
result.appendChild(table);
}
return result;
};
AbstractInfoWindow.prototype._createTableForTargetDiv = function(data, overlay) {
var self = this;
var table = document.createElement("table");
table.className = "mapInfoBoxResultsTable";
var row = document.createElement("tr");
table.className = "minerva-window-drug-table";
var header = document.createElement("tr");
var headerCol = document.createElement("th");
headerCol.innerHTML = "Name";
row.appendChild(headerCol);
headerCol = document.createElement("th");
headerCol.innerHTML = "Source";
row.appendChild(headerCol);
header.appendChild(headerCol);
headerCol = document.createElement("th");
headerCol.innerHTML = "References";
row.appendChild(headerCol);
count = 0;
for ( var dataId in data) {
if (data.hasOwnProperty(dataId) && data[dataId] !== undefined && data[dataId] !== null) {
// if we have empty array, it means that we got data from server and it's
// empty
if (Object.prototype.toString.call(data[dataId]) === '[object Array]') {
continue;
} else {
count++;
}
}
}
header.appendChild(headerCol);
var cell;
if (count > 0 || abstractInfoWindowSelf.isOverlayFullView(overlay.getName())) {
table.appendChild(row);
table.appendChild(header);
var row;
for ( var searchId in data) {
if (data.hasOwnProperty(searchId) && data[searchId] !== undefined && data[searchId] !== null) {
// if we have empty array, it means that we got data from server and
// it's
// empty
if (Object.prototype.toString.call(data[searchId]) === '[object Array]') {
continue;
} else {
row = document.createElement("tr");
cell = document.createElement("td");
if (typeof data[searchId] === "string") {
cell.innerHTML = data[searchId];
} else {
cell.innerHTML = searchId;
}
var count = 0;
for ( var searchId in data) {
if (data.hasOwnProperty(searchId)) {
row.appendChild(cell);
table.appendChild(row);
count++;
}
}
}
if (count === 0) {
row = document.createElement("tr");
cell = document.createElement("td");
cell.colSpan = "3";
cell.innerHTML = "No results available";
row.appendChild(cell);
var nameContent = searchId;
var annotations = [];
if (typeof data[searchId] === "string") {
nameContent = data[searchId];
} else if (data[searchId] instanceof TargettingStructure) {
nameContent = data[searchId].getName();
var targets = data[searchId].getTargetsForIdentifiedElement(self.getIdentifiedElement());
targets.forEach(function(target) {
target.getReferences().forEach(function(reference) {
annotations.push(reference);
});
});
}
row.appendChild(Functions.createElement({
type : "td",
content : nameContent
}));
var referencesCell = Functions.createElement({
type : "td",
});
referencesCell.appendChild(self.getGuiUtils().createAnnotationList(annotations));
row.appendChild(referencesCell);
table.appendChild(row);
count++;
}
} else if (count === 0 && overlay.allowGeneralSearch()) {
}
if (self.isOverlayFullView(overlay.getName()) && count === 0) {
row = document.createElement("tr");
cell = document.createElement("td");
cell.colSpan = "3";
cell.innerHTML = "Search for available targets";
cell.colSpan = "2";
cell.innerHTML = "No results available";
row.appendChild(cell);
table.appendChild(row);
}
if (count === 0 && !overlay.allowGeneralSearch() && !this.isOverlayFullView(overlay.getName())) {
result = null;
}
if (result !== null) {
result.appendChild(table);
if (!self.isOverlayFullView(overlay.getName()) && count === 0 && overlay.allowGeneralSearch()) {
row = document.createElement("tr");
cell = document.createElement("td");
cell.colSpan = "2";
cell.innerHTML = "Search for available targets";
row.appendChild(cell);
table.appendChild(row);
}
return result;
};
return table;
}
AbstractInfoWindow.prototype.init = function() {
var self = this;
return ServerConnector.getConfiguration().then(function(configuration) {
self.getGuiUtils().setConfiguration(configuration);
});
}
AbstractInfoWindow.prototype.setGuiUtils = function(guiUtils) {
this._guiUtils = guiUtils;
}
AbstractInfoWindow.prototype.getGuiUtils = function() {
return this._guiUtils;
}
/**
* Creates and returns DOM div for chemical overlay information.
@@ -543,4 +571,13 @@ AbstractInfoWindow.prototype.getElementType = function() {
throw new Error("Not implemented");
};
AbstractInfoWindow.prototype.getIdentifiedElement = function() {
var self = this;
return new IdentifiedElement({
id : self.getElementId(),
type : self.getElementType(),
modelId : self.getCustomMap().getId()
});
};
module.exports = AbstractInfoWindow;
Loading