Commit 16434d54 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

simple overlay panel functionality (general overlays)

parent f2d5f8ea
......@@ -4,20 +4,28 @@
var Promise = require("bluebird");
var GuiConnector= require('../GuiConnector');
var ObjectWithListeners = require('../ObjectWithListeners');
var Panel = require('./Panel');
var logger = require('../logger');
function AbstractPanel(params) {
ObjectWithListeners.call(this, params);
Panel.call(this, params);
var self = this;
this.setPanelName(params.panelName);
this.setElement(params.element);
this.setMap(params.customMap);
if (this.getNavElement() === undefined) {
throw new Error("No nav-tabs div found in the search panel element");
}
if (this.getContentElement() === undefined) {
throw new Error("No tab-content div found in the search panel element");
}
if (this.getSearchButton() === undefined) {
throw new Error("No searchButton found in the search panel element");
}
if (this.getSearchInput() === undefined) {
throw new Error("No searchInput found in the search panel element");
}
this.setOverlayDb (self.getMap().getOverlayByName(params.panelName));
......@@ -53,24 +61,9 @@ function AbstractPanel(params) {
this._tabIdCount = 0;
}
AbstractPanel.prototype = Object.create(ObjectWithListeners.prototype);
AbstractPanel.prototype = Object.create(Panel.prototype);
AbstractPanel.prototype.constructor = AbstractPanel;
AbstractPanel.prototype.disablePanel = function(message){
this.getSearchQueryElement().style.visibility ="hidden";
this.getSearchResultsElement().style.visibility ="hidden";
var hideReasonDiv = document.createElement("div");
hideReasonDiv.className="searchPanel";
var center = document.createElement("center");
var messageDiv = document.createElement("h4");
messageDiv .innerHTML=message;
center.appendChild(messageDiv);
hideReasonDiv.appendChild(center);
this.getElement().insertBefore(hideReasonDiv, this.getSearchQueryElement());
};
AbstractPanel.prototype.setOverlayDb = function(overlayDb){
if (overlayDb === undefined) {
throw new Error("Undefined overlayDb");
......@@ -82,173 +75,6 @@ AbstractPanel.prototype.getOverlayDb = function(){
return this._overlayDb;
};
AbstractPanel.prototype. createLabel=function(value) {
var result = document.createElement("span");
result.innerHTML = value;
result.className = "searchDescriptionLabel";
return result;
};
AbstractPanel.prototype.createPostTranslationalModifications = function(label, value) {
var result = document.createElement("div");
if (value !== undefined) {
throw new Error("Not implemented");
}
return result;
};
AbstractPanel.prototype.createCandidates=function(label, value) {
var result = document.createElement("div");
if (value !== undefined) {
throw new Error("Not implemented");
}
return result;
};
AbstractPanel.prototype.createChebiTree=function(label, value) {
var result = document.createElement("div");
if (value !== undefined) {
throw new Error("Not implemented");
}
return result;
};
AbstractPanel.prototype.createSeparator=function() {
var result = document.createElement("hr");
return result;
};
AbstractPanel.prototype.createNewLine=function(count) {
var result = document.createElement("p");
if (count > 0) {
result.style.height = ((count-1) * 10) + "px";
}
return result;
};
AbstractPanel.prototype.createLink=function(url, name) {
var link = document.createElement("a");
link.href = url;
link.innerHTML = name;
link.style.textDecoration = "underline";
return link;
};
AbstractPanel.prototype.createAnnotationLink=function(element, showType) {
var name, type, hint;
if (element.title!==undefined) {
hint = element.title+" "+element.authors.join(", ")+", "+element.year+", "+ element.journal;
type = "PUBMED";
name = element.id;
} else {
name = element.name;
type = element.type;
}
var link;
if (showType) {
link = this.createLink(element.link, type + " (" + name + ")");
} else {
link = this.createLink(element.link, name);
}
if (hint!==undefined) {
var div = document.createElement("div");
div.title = hint;
div.appendChild(link);
return div;
} else {
return link;
}
};
AbstractPanel.prototype.createAnnotations=function(label, value, 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 result = document.createElement("div");
if (value !== undefined && value.length > 0) {
var self = this;
result.appendChild(self.createLabel(label));
if (!inline) {
result.appendChild(self.createNewLine());
}
for (var i = 0; i < value.length; i++) {
var element = value[i];
var link = this.createAnnotationLink(element, showType);
if (inline) {
if (i>0){
var coma = document.createElement("span");
coma.innerHTML = ", ";
result.appendChild(coma);
}
result.appendChild(link);
} else {
var row = document.createElement("div");
row.style.height = "26px";
if (i % 2 === 0) {
row.className = "annotationRowOdd";
} else {
row.className = "annotationRowEven";
}
var header = document.createElement("div");
header.style.width = "24px";
header.style.float = "left";
header.innerHTML = "[" + (i + 1) + "]";
row.appendChild(header);
var body = document.createElement("div");
body.style.float = "left";
body.appendChild(link);
row.appendChild(body);
result.appendChild(row);
}
}
}
return result;
};
AbstractPanel.prototype.setMap = function(map) {
this._map = map;
};
AbstractPanel.prototype.getMap = function() {
return this._map;
};
AbstractPanel.prototype.setPanelName = function(panelName) {
this._panelName = panelName;
};
AbstractPanel.prototype.getPanelName = function() {
return this._panelName;
};
AbstractPanel.prototype.setElement = function(element) {
if (element === undefined || element === null) {
throw new Error("DOM Element must be defined");
}
this._element = element;
if (this.getNavElement() === undefined) {
throw new Error("No nav-tabs div found in the search panel element");
}
if (this.getContentElement() === undefined) {
throw new Error("No tab-content div found in the search panel element");
}
if (this.getSearchButton() === undefined) {
throw new Error("No searchButton found in the search panel element");
}
if (this.getSearchInput() === undefined) {
throw new Error("No searchInput found in the search panel element");
}
};
AbstractPanel.prototype.getSearchQueryElement = function() {
var children = this.getElement().children;
for (var i = 0; i < children.length; i++) {
......@@ -283,23 +109,6 @@ AbstractPanel.prototype.getNavElement = function() {
}
};
AbstractPanel.prototype.getElementByName = function(element, name) {
if (element!==undefined) {
if (element.getAttribute("name") === name) {
return element;
}
var children = element.children;
for (var i=0;i<children.length;i++) {
var child = children[i];
var res = this.getElementByName(child, name);
if (res!==undefined) {
return res;
}
}
}
return undefined;
};
AbstractPanel.prototype.getSearchButton = function() {
return this.getElementByName(this.getSearchQueryElement(),"searchButton");
};
......@@ -322,10 +131,6 @@ AbstractPanel.prototype.getContentElement = function() {
}
};
AbstractPanel.prototype.getElement = function() {
return this._element;
};
AbstractPanel.prototype.clearResults = function() {
var navElement = this.getNavElement();
while (navElement.firstChild) {
......@@ -360,64 +165,6 @@ AbstractPanel.prototype.refreshSearchResults = function() {
};
AbstractPanel.prototype.createLabelText = function(value) {
var result = document.createElement("span");
if (value !== undefined) {
result.innerHTML = value;
}
return result;
};
AbstractPanel.prototype.createParamLine = function(label, value) {
var result = document.createElement("div");
if (value !== undefined) {
var self = this;
result.appendChild(self.createLabel(label));
result.appendChild(self.createLabelText(value));
result.appendChild(self.createNewLine());
}
return result;
};
AbstractPanel.prototype.createIcon = function(icon) {
var result = document.createElement("div");
if (icon !== undefined && icon !== null) {
var img = document.createElement("img");
img.src=GuiConnector.getImgPrefix()+icon;
img.style.float="left";
img.hspace="5";
result.appendChild(img);
}
return result;
};
AbstractPanel.prototype.createArrayParamLine = function(label, value) {
var result = document.createElement("div");
if (value !== undefined && value.length > 0) {
var self = this;
result.appendChild(self.createLabel(label));
result.appendChild(self.createLabelText(value.join(",")));
result.appendChild(self.createNewLine());
}
return result;
};
AbstractPanel.prototype.createSubMapLink = function(label, element) {
var self = this;
var result = document.createElement("div");
if (element !== undefined) {
var button = document.createElement("button");
button.text = element.getModelId();
button.onclick = function() {
return self.getMap().openSubmodel(element.getModelId());
};
result.appendChild(this.createLabel("Submodel: "));
result.appendChild(button);
}
return result;
};
AbstractPanel.prototype.getAutocomplete = function() {
logger.warn("Get autocomplete not implemented");
};
......@@ -518,5 +265,4 @@ AbstractPanel.prototype.createTargetRow = function(target, icon) {
return result;
};
module.exports = AbstractPanel;
......@@ -3,17 +3,17 @@
/* exported logger */
var logger = require('../logger');
var AbstractPanel = require('./AbstractPanel');
var AbstractDbPanel = require('./AbstractDbPanel');
function ChemicalPanel(params) {
params.panelName = "chemical";
AbstractPanel.call(this, params);
AbstractDbPanel.call(this, params);
if (params.disease===undefined) {
this.disablePanel("DISEASE NOT DEFINED FOR PROJECT. PLEASE, DEFINE IT IN THE ADMIN SECTION.");
}
}
ChemicalPanel.prototype = Object.create(AbstractPanel.prototype);
ChemicalPanel.prototype = Object.create(AbstractDbPanel.prototype);
ChemicalPanel.prototype.constructor = ChemicalPanel;
ChemicalPanel.prototype.createPreamble = function(chemical) {
......
......@@ -3,13 +3,13 @@
/* exported logger */
var logger = require('../logger');
var AbstractPanel = require('./AbstractPanel');
var AbstractDbPanel = require('./AbstractDbPanel');
function DrugPanel(params) {
params.panelName = "drug";
AbstractPanel.call(this, params);
AbstractDbPanel.call(this, params);
}
DrugPanel.prototype = Object.create(AbstractPanel.prototype);
DrugPanel.prototype = Object.create(AbstractDbPanel.prototype);
DrugPanel.prototype.constructor = DrugPanel;
DrugPanel.prototype.createPreamble = function(drug) {
......
......@@ -3,13 +3,13 @@
/* exported logger */
var logger = require('../logger');
var AbstractPanel = require('./AbstractPanel');
var AbstractDbPanel = require('./AbstractDbPanel');
function MiRnaPanel(params) {
params.panelName = "mirna";
AbstractPanel.call(this, params);
AbstractDbPanel.call(this, params);
}
MiRnaPanel.prototype = Object.create(AbstractPanel.prototype);
MiRnaPanel.prototype = Object.create(AbstractDbPanel.prototype);
MiRnaPanel.prototype.constructor = MiRnaPanel;
MiRnaPanel.prototype.createPreamble = function(miRna) {
......
"use strict";
/* exported logger */
var Panel = require('./Panel');
var logger = require('../logger');
function OverlayPanel(params) {
params.panelName = "overlays";
Panel.call(this, params);
var self = this;
self.setPanelName(params.panelName);
self.setElement(params.element);
self.setMap(params.customMap);
self.refresh();
}
OverlayPanel.prototype = Object.create(Panel.prototype);
OverlayPanel.prototype.constructor = OverlayPanel;
OverlayPanel.prototype.clear = function() {
var table = this.getGeneralOverlaysTabElement();
while (table.firstChild) {
table.removeChild(table.firstChild);
}
table = this.getCustomOverlaysTabElement();
while (table.firstChild) {
table.removeChild(table.firstChild);
}
};
OverlayPanel.prototype.createTableHeader = function(edit) {
var result = document.createElement("thead");
var row = document.createElement("tr");
var nameTd = document.createElement("th");
nameTd.innerHTML = "Name";
row.appendChild(nameTd);
var viewTd = document.createElement("th");
viewTd.innerHTML = "View";
row.appendChild(viewTd);
var dataTd = document.createElement("th");
dataTd.innerHTML = "Data";
row.appendChild(dataTd);
if (edit) {
var editTd = document.createElement("th");
editTd.innerHTML = "Edit";
row.appendChild(editTd);
}
result.appendChild(row);
return result;
};
OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
var self = this;
var result = document.createElement("tr");
if (checked) {
result.className = "active";
}
var nameTd = document.createElement("td");
nameTd.innerHTML = overlay.getName();
result.appendChild(nameTd);
var viewTd = document.createElement("td");
if (overlay.getInputDataAvailable()) {
var checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.checked = checked;
checkbox.onclick = function() {
if (this.checked) {
self.getMap().addSelectedLayout(overlay.getId());
} else {
self.getMap().removeSelectedLayout(overlay.getId());
}
};
viewTd.appendChild(checkbox);
} else {
var img = this.createIcon("icons/search.png");
var link = document.createElement("a");
link.href = "#";
link.onclick = function() {
self.getMap().openLayoutById(overlay.getId());
$(result).addClass('active').siblings().removeClass('active');
};
link.appendChild(img);
viewTd.appendChild(link);
}
result.appendChild(viewTd);
var dataTd = document.createElement("td");
if (overlay.getInputDataAvailable()) {
var button = document.createElement("button");
button.onclick = function() {
throw new Error("Not implemented");
};
dataTd.appendChild(button);
}
result.appendChild(dataTd);
if (overlay.getCreator() !== "" && overlay.getCreator() !== undefined) {
var editTd = document.createElement("td");
var editButton = document.createElement("button");
editButton.onclick = function() {
throw new Error("Not implemented");
};
editTd.appendChild(editButton);
result.appendChild(editTd);
}
return result;
};
OverlayPanel.prototype.refresh = function() {
var self = this;
return ServerConnector.getOverlays().then(function(customOverlays) {
var selectedOverlayIds = self.getMap().getSelectedLayouts();
var selectedOverlay = [];
for (var j = 0; j < selectedOverlayIds.length; j++) {
selectedOverlay[selectedOverlayIds[j]] = true;
}
var id = self.getMap().getGoogleMap().getMapTypeId().substring(2);
selectedOverlay[id] = true;
self.clear();
var generalOverlays = [];
var overlay;
var overlays = self.getMap().getLayouts();
for (var i = 0; i < overlays.length; i++) {
overlay = overlays[i];
if (overlay.getCreator() === undefined || overlay.getCreator() === "") {
generalOverlays.push(overlay);
}
}
var table = self.getGeneralOverlaysTabElement();
table.appendChild(self.createTableHeader());
var body = document.createElement("tbody");
table.appendChild(body);
for (i = 0; i < generalOverlays.length; i++) {
overlay = generalOverlays[i];
body.appendChild(self.createOverlayRow(overlay, selectedOverlay[overlay.getId()]));
}
table = self.getCustomOverlaysTabElement();
table.appendChild(self.createTableHeader(true));
body = document.createElement("tbody");
table.appendChild(body);
for (i = 0; i < customOverlays.length; i++) {
overlay = customOverlays[i];
body.appendChild(self.createOverlayRow(overlay, selectedOverlay[overlay.getId()]));
}
return null;
});
};
OverlayPanel.prototype.getGeneralOverlaysElement = function() {
return this.getElementByName(this.getElement(), "generalOverlays");
};
OverlayPanel.prototype.getGeneralOverlaysTabElement = function() {
return this.getElementByName(this.getElement(), "generalOverlaysTab");
};
OverlayPanel.prototype.getCustomOverlaysElement = function() {
return this.getElementByName(this.getElement(), "customOverlays");
};
OverlayPanel.prototype.getCustomOverlaysTabElement = function() {
return this.getElementByName(this.getElement(), "customOverlaysTab");