Commit 9692e35e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

abstractPanel contains more common functionalities for panels

parent 2cfe6a53
......@@ -15,6 +15,7 @@ function AbstractPanel(params) {
var self = this;
this.setPanelName(params.panelName);
this.setElement(params.element);
this.setMap(params.customMap);
......@@ -198,6 +199,14 @@ 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");
......@@ -395,6 +404,61 @@ AbstractPanel.prototype.searchByQuery = function() {
throw new Error("searchByQuery is not implemnted");
};
AbstractPanel.prototype.addResultTab = function(query, elements) {
var name = JSON.parse(query).query;
var tabId = this.getPanelName() + "Tab_" + this._tabIdCount;
this._tabIdCount++;
var navElement = this.getNavElement();
var contentElement = this.getContentElement();
var navClass = '';
var contentClass = 'tab-pane';
if (navElement.children.length === 0) {
navClass = "active";
contentClass = "tab-pane active";
}
var navLi = document.createElement("li");
navLi.className = navClass;
var navLink = document.createElement("a");
navLink.href = "#" + tabId;
if (name !== undefined) {
if (name.length > 12) {
name = name.substring(0, 10) + "...";
}
navLink.innerHTML = name;
}
navLink.onclick = function() {
$(this).tab('show');
};
navLi.appendChild(navLink);
if (query.name !== undefined) {
navLink.innerHTML = query.name;
}
navElement.appendChild(navLi);
var contentDiv = document.createElement("div");
contentDiv.className = "pre-scrollable " + contentClass;
contentDiv.style.height = "100%";
contentDiv.id = tabId;
contentElement.appendChild(contentDiv);
contentDiv.appendChild(this.createPreamble(elements.element));
var tableDiv = document.createElement("table");
tableDiv.className = "table table-bordered";
contentDiv.appendChild(tableDiv);
var tableBody = document.createElement("tbody");
tableDiv.appendChild(tableBody);
for (var i = 0; i < elements.length; i++) {
var element = elements[i].element;
var icon = elements[i].icon;
tableBody.appendChild(this.createTableElement(element, icon));
}
};
module.exports = AbstractPanel;
......@@ -12,7 +12,7 @@ function DrugPanel(params) {
DrugPanel.prototype = Object.create(AbstractPanel.prototype);
DrugPanel.prototype.constructor = DrugPanel;
DrugPanel.prototype.createDrugHeader = function(drug) {
DrugPanel.prototype.createPreamble = function(drug) {
var self = this;
var result = document.createElement("div");
if (drug === undefined || drug.getName() === undefined) {
......@@ -30,7 +30,7 @@ DrugPanel.prototype.createDrugHeader = function(drug) {
return result;
};
DrugPanel.prototype.createTargetElement = function(target, icon) {
DrugPanel.prototype.createTableElement = function(target, icon) {
var self = this;
var result = document.createElement("tr");
var iconColumn = document.createElement("td");
......@@ -65,62 +65,6 @@ DrugPanel.prototype.createTargetElement = function(target, icon) {
return result;
};
DrugPanel.prototype.addResultTab = function(query, elements) {
var name = JSON.parse(query).query;
var tabId = "searchTab_" + this._tabIdCount;
this._tabIdCount++;
var navElement = this.getNavElement();
var contentElement = this.getContentElement();
var navClass = '';
var contentClass = 'tab-pane';
if (navElement.children.length === 0) {
navClass = "active";
contentClass = "tab-pane active";
}
var navLi = document.createElement("li");
navLi.className = navClass;
var navLink = document.createElement("a");
navLink.href = "#" + tabId;
if (name !== undefined) {
if (name.length > 12) {
name = name.substring(0, 10) + "...";
}
navLink.innerHTML = name;
}
navLink.onclick = function() {
$(this).tab('show');
};
navLi.appendChild(navLink);
if (query.name !== undefined) {
navLink.innerHTML = query.name;
}
navElement.appendChild(navLi);
var contentDiv = document.createElement("div");
contentDiv.className = "pre-scrollable " + contentClass;
contentDiv.style.height = "100%";
contentDiv.id = tabId;
contentElement.appendChild(contentDiv);
contentDiv.appendChild(this.createDrugHeader(elements.element));
var tableDiv = document.createElement("table");
tableDiv.className = "table table-bordered";
contentDiv.appendChild(tableDiv);
var tableBody = document.createElement("tbody");
tableDiv.appendChild(tableBody);
for (var i = 0; i < elements.length; i++) {
var element = elements[i].target;
var icon = elements[i].icon;
tableBody.appendChild(this.createTargetElement(element, icon));
}
};
DrugPanel.prototype.searchByQuery = function() {
var self = this;
......
"use strict";
/* exported logger*/
/* exported logger */
var AbstractPanel = require('./AbstractPanel');
var Alias = require('../map/data/Alias');
......@@ -23,63 +23,18 @@ SearchPanel.prototype.getSearchPerfectMatch = function() {
return this.getElementByName(this.getSearchQueryElement(), "searchPerfectMatch");
};
SearchPanel.prototype.addResultTab = function(query, elements) {
var name = JSON.parse(query).query;
var tabId = "searchTab_" + this._tabIdCount;
this._tabIdCount++;
var navElement = this.getNavElement();
var contentElement = this.getContentElement();
var navClass = '';
var contentClass = 'tab-pane';
if (navElement.children.length === 0) {
navClass = "active";
contentClass = "tab-pane active";
SearchPanel.prototype.createTableElement = function(element, icon) {
if (element instanceof Alias) {
return this.createAliasElement(element, icon);
} else if (element instanceof Reaction) {
return this.createReactionElement(element);
} else {
throw new Error("Unknown element type: " + element.constructor.name);
}
}
var navLi = document.createElement("li");
navLi.className = navClass;
var navLink = document.createElement("a");
navLink.href = "#" + tabId;
if (name !== undefined) {
if (name.length > 12) {
name = name.substring(0, 10) + "...";
}
navLink.innerHTML = name;
}
navLink.onclick = function() {
$(this).tab('show');
};
navLi.appendChild(navLink);
if (query.name !== undefined) {
navLink.innerHTML = query.name;
}
navElement.appendChild(navLi);
var contentDiv = document.createElement("div");
contentDiv.className = "pre-scrollable " + contentClass;
contentDiv.style.height = "100%";
contentDiv.id = tabId;
contentElement.appendChild(contentDiv);
var tableDiv = document.createElement("table");
tableDiv.className = "result-table";
contentDiv.appendChild(tableDiv);
for (var i = 0; i < elements.length; i++) {
var element = elements[i].element;
var icon = elements[i].icon;
if (element instanceof Alias) {
tableDiv.appendChild(this.createAliasElement(element, icon));
} else if (element instanceof Reaction) {
tableDiv.appendChild(this.createReactionElement(element));
} else {
throw new Error("Unknown element type: " + element.constructor.name);
}
}
SearchPanel.prototype.createPreamble = function(reaction) {
return document.createElement("div");
};
SearchPanel.prototype.createReactionElement = function(reaction) {
......@@ -197,5 +152,4 @@ SearchPanel.prototype.getAutocomplete = function(query) {
return this.getMap().getSearchAutocomplete(query);
};
module.exports = SearchPanel;
......@@ -48,7 +48,7 @@ AbstractTargettingDbOverlay.prototype.getElementsByQuery = function(query) {
if (target.getTargetElements().length===0) {
icon = null;
}
result.push({target:target, icon:icon});
result.push({element:target, icon:icon});
}
}
resolve(result);
......
......@@ -2,7 +2,6 @@
var logger = require('../../logger');
var IdentifiedElement = require('../data/IdentifiedElement');
var ObjectWithListeners = require('../../ObjectWithListeners');
......
"use strict";
var logger = require('../../logger');
var Promise = require("bluebird");
var AbstractDbOverlay = require('./AbstractDbOverlay');
......
......@@ -43,7 +43,7 @@ describe('DrugPanel', function() {
customMap : map
});
assert.ok(panel.createDrugHeader().innerHTML.indexOf("NOT FOUND") > 0);
assert.ok(panel.createPreamble().innerHTML.indexOf("NOT FOUND") > 0);
});
it('createDrugeader for empty', function() {
......@@ -57,7 +57,7 @@ describe('DrugPanel', function() {
customMap : map
});
assert.ok(panel.createDrugHeader(new Drug()).innerHTML.indexOf("NOT FOUND") > 0);
assert.ok(panel.createPreamble(new Drug()).innerHTML.indexOf("NOT FOUND") > 0);
});
it('on searchResults changed', function() {
......
Markdown is supported
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