Commit 3e814ee6 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

mirnas and drugs support suggested query list

parent 687aa4c6
......@@ -369,6 +369,18 @@ ServerConnector.getChemicalSuggestedQueryListUrl = function (queryParams, filter
params: filterParams
});
};
ServerConnector.getDrugSuggestedQueryListUrl = function (queryParams, filterParams) {
return this.getApiUrl({
url: this.getProjectUrl(queryParams) + "drugs/suggestedQueryList",
params: filterParams
});
};
ServerConnector.getMiRnaSuggestedQueryListUrl = function (queryParams, filterParams) {
return this.getApiUrl({
url: this.getProjectUrl(queryParams) + "miRnas/suggestedQueryList",
params: filterParams
});
};
ServerConnector.addCommentUrl = function (queryParams) {
return this.getApiUrl({
......@@ -1662,6 +1674,28 @@ ServerConnector.getChemicalSuggestedQueryList = function (projectId) {
return JSON.parse(content);
});
};
ServerConnector.getMiRnaSuggestedQueryList = function (projectId) {
var self = this;
return self.getProjectId(projectId).then(function (result) {
projectId = result;
return self.sendGetRequest(self.getMiRnaSuggestedQueryListUrl({
projectId: projectId
}));
}).then(function (content) {
return JSON.parse(content);
});
};
ServerConnector.getDrugSuggestedQueryList = function (projectId) {
var self = this;
return self.getProjectId(projectId).then(function (result) {
projectId = result;
return self.sendGetRequest(self.getDrugSuggestedQueryListUrl({
projectId: projectId
}));
}).then(function (content) {
return JSON.parse(content);
});
};
ServerConnector.getOverlayTypes = function () {
var self = this;
......
......@@ -62,4 +62,22 @@ DrugPanel.prototype.destroy = function () {
return Promise.resolve();
};
DrugPanel.prototype.getAutocomplete = function (query) {
if (this._searchAutocomplete === undefined) {
this.refreshSearchAutocomplete();
return [];
}
return this._searchAutocomplete[query];
};
DrugPanel.prototype.refreshSearchAutocomplete = function () {
var self = this;
self._searchAutocomplete = [];
return ServerConnector.getDrugSuggestedQueryList().then(function (queries) {
self._searchAutocomplete = self.computeAutocompleteDictionary(queries);
return self._searchAutocomplete;
});
};
module.exports = DrugPanel;
......@@ -62,4 +62,22 @@ MiRnaPanel.prototype.destroy = function () {
return Promise.resolve();
};
MiRnaPanel.prototype.getAutocomplete = function (query) {
if (this._searchAutocomplete === undefined) {
this.refreshSearchAutocomplete();
return [];
}
return this._searchAutocomplete[query];
};
MiRnaPanel.prototype.refreshSearchAutocomplete = function () {
var self = this;
self._searchAutocomplete = [];
return ServerConnector.getMiRnaSuggestedQueryList().then(function (queries) {
self._searchAutocomplete = self.computeAutocompleteDictionary(queries);
return self._searchAutocomplete;
});
};
module.exports = MiRnaPanel;
......@@ -10,75 +10,87 @@ var chai = require('chai');
var assert = chai.assert;
var logger = require('../../logger');
describe('DrugPanel', function() {
describe('DrugPanel', function () {
it('constructor', function() {
function createPanel() {
var map = helper.createCustomMap();
map.getModel().setId(15781);
helper.createDrugDbOverlay(map);
return new DrugPanel({
element: testDiv,
customMap: map
});
}
it('constructor', function () {
var map = helper.createCustomMap();
helper.createDrugDbOverlay(map);
new DrugPanel({
element : testDiv,
customMap : map
element: testDiv,
customMap: map
});
assert.equal(logger.getWarnings().length, 0);
});
it('create DrugPanel', function() {
it('create DrugPanel', function () {
var map = helper.createCustomMap();
helper.createDrugDbOverlay(map);
var panel = new DrugPanel({
element : testDiv,
customMap : map
element: testDiv,
customMap: map
});
assert.ok(panel.createPreamble().innerHTML.indexOf("NOT FOUND") > 0);
});
it('create DrugPanel for empty drug', function() {
it('create DrugPanel for empty drug', function () {
var map = helper.createCustomMap();
helper.createDrugDbOverlay(map);
var panel = new DrugPanel({
element : testDiv,
customMap : map
element: testDiv,
customMap: map
});
assert.ok(panel.createPreamble(new Drug()).innerHTML.indexOf("NOT FOUND") > 0);
});
it('on searchResults changed', function() {
it('on searchResults changed', function () {
var map = helper.createCustomMap();
map.getModel().setId(15781);
var drugDbOverlay = helper.createDrugDbOverlay(map);
new DrugPanel({
element : testDiv,
customMap : map
element: testDiv,
customMap: map
});
return drugDbOverlay.searchByQuery("aspirin").then(function() {
return drugDbOverlay.searchByQuery("aspirin").then(function () {
assert.equal(logger.getWarnings().length, 0);
assert.ok(testDiv.innerHTML.indexOf("Acetylsalicylic acid") >= 0);
});
});
it('searchByQuery', function() {
var map = helper.createCustomMap();
map.getModel().setId(15781);
helper.createDrugDbOverlay(map);
var panel = new DrugPanel({
element : testDiv,
customMap : map
});
it('searchByQuery', function () {
var panel = createPanel();
panel.getControlElement(PanelControlElementType.SEARCH_INPUT).value = "aspirin";
return panel.searchByQuery().then(function() {
return panel.searchByQuery().then(function () {
assert.equal(logger.getWarnings().length, 0);
assert.ok(testDiv.innerHTML.indexOf("Acetylsalicylic acid") >= 0);
});
});
it("refreshSearchAutocomplete", function () {
var panel = createPanel();
return panel.refreshSearchAutocomplete("s").then(function (data) {
assert.ok(data);
});
});
});
......@@ -10,75 +10,87 @@ var chai = require('chai');
var assert = chai.assert;
var logger = require('../../logger');
describe('MiRnaPanel', function() {
describe('MiRnaPanel', function () {
function createPanel() {
var map = helper.createCustomMap();
map.getModel().setId(15781);
helper.createMiRnaDbOverlay(map);
return new MiRnaPanel({
element: testDiv,
customMap: map
});
}
it('constructor', function() {
it('constructor', function () {
var map = helper.createCustomMap();
helper.createMiRnaDbOverlay(map);
new MiRnaPanel({
element : testDiv,
customMap : map
element: testDiv,
customMap: map
});
assert.equal(logger.getWarnings().length, 0);
});
it('create MiRnaPanel for empty', function() {
it('create MiRnaPanel for empty', function () {
var map = helper.createCustomMap();
helper.createMiRnaDbOverlay(map);
var panel = new MiRnaPanel({
element : testDiv,
customMap : map
element: testDiv,
customMap: map
});
assert.ok(panel.createPreamble().innerHTML.indexOf("NOT FOUND") > 0);
});
it('create MiRnaPanel for empty MiRna', function() {
it('create MiRnaPanel for empty MiRna', function () {
var map = helper.createCustomMap();
helper.createMiRnaDbOverlay(map);
var panel = new MiRnaPanel({
element : testDiv,
customMap : map
element: testDiv,
customMap: map
});
assert.ok(panel.createPreamble(new MiRna()).innerHTML.indexOf("NOT FOUND") > 0);
});
it('on searchResults changed', function() {
it('on searchResults changed', function () {
var map = helper.createCustomMap();
map.getModel().setId(15781);
var miRnaDbOverlay = helper.createMiRnaDbOverlay(map);
new MiRnaPanel({
element : testDiv,
customMap : map
element: testDiv,
customMap: map
});
return miRnaDbOverlay.searchByQuery("hsa-miR-125a-3p").then(function() {
return miRnaDbOverlay.searchByQuery("hsa-miR-125a-3p").then(function () {
assert.equal(logger.getWarnings().length, 0);
assert.ok(testDiv.innerHTML.indexOf("hsa-miR-125a-3p") >= 0);
});
});
it('searchByQuery', function() {
var map = helper.createCustomMap();
map.getModel().setId(15781);
helper.createMiRnaDbOverlay(map);
var panel = new MiRnaPanel({
element : testDiv,
customMap : map,
});
it('searchByQuery', function () {
var panel = createPanel();
panel.getControlElement(PanelControlElementType.SEARCH_INPUT).value = "hsa-miR-125a-3p";
return panel.searchByQuery().then(function() {
return panel.searchByQuery().then(function () {
assert.equal(logger.getWarnings().length, 0);
assert.ok(testDiv.innerHTML.indexOf("http://www.mirbase.org/cgi-bin/mirna_entry.pl?acc") >= 0);
});
});
it("refreshSearchAutocomplete", function () {
var panel = createPanel();
return panel.refreshSearchAutocomplete("s").then(function (data) {
assert.ok(data);
});
});
});
Supports Markdown
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