Commit 88226fc8 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

export tab allows to select included compartment

parent 88a3f71f
......@@ -814,7 +814,9 @@ ServerConnector.getReactions = function(params) {
ServerConnector.getAliases = function(params) {
var self = this;
var queryParams = {};
var queryParams = {
modelId : params.modelId,
};
if (params.ids === undefined) {
params.ids = []
}
......
......@@ -23,6 +23,14 @@ function ElementExportPanel(params) {
ElementExportPanel.prototype = Object.create(Panel.prototype);
ElementExportPanel.prototype.constructor = ElementExportPanel;
function compareSimple(val1, val2) {
if (val1 < val2)
return -1;
if (val1 > val2)
return 1;
return 0;
}
ElementExportPanel.prototype._createGui = function() {
};
......@@ -40,14 +48,27 @@ ElementExportPanel.prototype.init = function() {
}).then(function(statistics) {
var miriamDiv = self._createMiriamTypeDiv(statistics);
element.appendChild(miriamDiv);
new DualListbox(".minerva-multi-select", {
self.setMiriamTypesDualListbox(new DualListbox("#miriamTypeSelect", {
availableTitle : 'Available',
selectedTitle : 'Used',
addButtonText : '>',
removeButtonText : '<',
addAllButtonText : '>>',
removeAllButtonText : '<<'
});
}));
}).then(function() {
return self._createSelectIncludedCompartmentDiv();
}).then(function(selectIncludedCompartmentDiv) {
element.appendChild(selectIncludedCompartmentDiv);
self.setIncludedCompartmentsDualListbox(new DualListbox("#includedCompartmentsSelect", {
availableTitle : 'Available',
selectedTitle : 'Used',
addButtonText : '>',
removeButtonText : '<',
addAllButtonText : '>>',
removeAllButtonText : '<<'
}));
}).then(function() {
$(window).trigger('resize');
});
}
......@@ -96,18 +117,11 @@ ElementExportPanel.prototype._createMiriamTypeDiv = function(statistics) {
var selectElement = Functions.createElement({
type : "select",
className : "minerva-multi-select"
className : "minerva-multi-select",
id : "miriamTypeSelect",
});
typeDiv.appendChild(selectElement);
function compareSimple(val1, val2) {
if (val1 < val2)
return -1;
if (val1 > val2)
return 1;
return 0;
}
;
function compare(entry1, entry2) {
var result;
if ((entry1.count === 0 && entry2.count === 0) || (entry1.count !== 0 && entry2.count !== 0))
......@@ -136,6 +150,64 @@ ElementExportPanel.prototype._createMiriamTypeDiv = function(statistics) {
return typeDiv;
};
ElementExportPanel.prototype._createSelectIncludedCompartmentDiv = function() {
var i = 0;
var self = this;
var typeDiv = Functions.createElement({
type : "div",
name : "miriamSelectDiv",
});
typeDiv.appendChild(Functions.createElement({
type : "h4",
content : " Included compartment/pathways:",
}));
var compartments = [];
var models = [ self.getProject().getModel() ];
for (i = 0; i < self.getProject().getModel().getSubmodels().length; i++) {
models.push(self.getProject().getModel().getSubmodels()[i]);
}
var promises = [];
for (i = 0; i < models.length; i++) {
promises.push(models[i].getCompartments());
}
return Promise.all(promises).then(function(result) {
var addedNames = [];
for (var i = 0; i < result.length; i++) {
var modelCompartments = result[i];
for (var j = 0; j < modelCompartments.length; j++) {
if (addedNames[modelCompartments[j].getName()] === undefined) {
compartments.push(modelCompartments[j].getName());
addedNames[modelCompartments[j].getName()] = true;
}
}
}
var selectElement = Functions.createElement({
type : "select",
className : "minerva-multi-select",
id : "includedCompartmentsSelect",
});
typeDiv.appendChild(selectElement);
compartments.sort(compareSimple);
for (var i = 0; i < compartments.length; i++) {
var name = compartments[i];
var option = new Option();
option.value = name;
option.innerHTML = "<div >" + name + "</div>";
selectElement.appendChild(option);
}
return typeDiv;
});
};
ElementExportPanel.prototype._createSelectColumnDiv = function() {
var self = this;
var columnDiv = Functions.createElement({
......@@ -262,6 +334,44 @@ ElementExportPanel.prototype.getSelectedTypes = function() {
return Promise.resolve(result);
}
ElementExportPanel.prototype.setMiriamTypesDualListbox = function(dualListbox) {
this._miriamTypesDualListbox = dualListbox;
};
ElementExportPanel.prototype.getMiriamTypesDualListbox = function() {
return this._miriamTypesDualListbox;
};
ElementExportPanel.prototype.setIncludedCompartmentsDualListbox = function(dualListbox) {
this._includedCompartmentsDualListbox = dualListbox;
};
ElementExportPanel.prototype.getIncludedCompartmentsDualListbox = function() {
return this._includedCompartmentsDualListbox;
};
ElementExportPanel.prototype.getSelectedIncludedCompartmentNames = function() {
var self = this;
var list = self.getIncludedCompartmentsDualListbox().selected;
var result = [];
for (var i = 0; i < list.length; i++) {
var element = list[i];
result.push(element.dataset.id);
}
return result;
};
ElementExportPanel.prototype.getSelectedMiriamTypes = function() {
var self = this;
return ServerConnector.getConfiguration().then(function(configuration) {
var selected = self.getMiriamTypesDualListbox().selected;
var result = [];
for (var i = 0; i < selected.length; i++) {
var miriamType = configuration.getMiriamTypeByName(selected[i].dataset.id);
result.push(miriamType);
}
return result;
});
};
ElementExportPanel.prototype.getSelectedColumns = function() {
var self = this;
......
......@@ -5,6 +5,7 @@ var Promise = require("bluebird");
var logger = require('../../logger');
var Alias = require('./Alias');
var IdentifiedElement = require('./IdentifiedElement');
var LayoutData = require('./LayoutData');
var PointData = require('./PointData');
var Reaction = require('./Reaction');
......@@ -739,8 +740,22 @@ MapModel.prototype.getReactionsForElements = function(elements, complete) {
MapModel.prototype.getCompartments = function() {
var self = this;
// throw new Error("Not Implemented");
return [];
var promise = Promise.resolve();
if (self._compartments === undefined) {
promise = ServerConnector.getAliases({
columns : "id,bounds,modelId",
type : "Compartment",
modelId : self.getId(),
}).then(function(compartments) {
self._compartments = [];
for (var i = 0; i < compartments.length; i++) {
self._compartments.push(new IdentifiedElement(compartments[i]));
}
});
}
return promise.then(function() {
return self.getByIdentifiedElements(self._compartments, true);
});
};
module.exports = MapModel;
"use strict";
var ElementExportPanel = require('../../../../main/js/gui/export/ElementExportPanel');
var MiriamType = require('../../../../main/js/map/data/MiriamType');
var logger = require('../../logger');
var Helper = require('../../Helper');
var assert = require('assert');
var originalNavigator = null;
describe('ElementExportPanel', function() {
var helper;
before(function() {
helper = new Helper();
});
describe('getSelectedTypes', function() {
it('select single element', function() {
var exportObject;
......@@ -56,7 +63,7 @@ describe('ElementExportPanel', function() {
});
});
});
describe('getSelectedColumns', function() {
it('select single element', function() {
var exportObject;
......@@ -105,6 +112,50 @@ describe('ElementExportPanel', function() {
});
});
});
describe('getSelectedMiriamTypes', function() {
it('select single element', function() {
var exportObject;
var project;
return ServerConnector.getProject().then(function(result) {
project = result;
exportObject = new ElementExportPanel({
element : testDiv,
project : project
});
return exportObject.init();
}).then(function() {
var dlb = exportObject.getMiriamTypesDualListbox();
var listItem = dlb.available[0];
dlb.addSelected(listItem);
return exportObject.getSelectedMiriamTypes();
}).then(function(result) {
assert.equal(result.length, 1);
assert.ok(result[0] instanceof MiriamType);
});
});
});
describe('getSelectedIncludedCompartments', function() {
it('empty selection', function() {
helper.setUrl("http://test/?id=complex_model_with_submaps");
var exportObject;
var project;
return ServerConnector.getProject().then(function(result) {
project = result;
exportObject = new ElementExportPanel({
element : testDiv,
project : project
});
return exportObject.init();
}).then(function() {
assert.ok(exportObject.getIncludedCompartmentsDualListbox().available.length > 0);
return exportObject.getSelectedIncludedCompartmentNames();
}).then(function(result) {
assert.equal(result.length, 0);
});
});
});
});
[{"modelId":16728,"bounds":{"x":189.0,"width":291.0,"y":33.0,"height":296.0},"id":345332},{"modelId":16728,"bounds":{"x":35.0,"width":144.0,"y":45.0,"height":142.0},"id":345323}]
\ No newline at end of file
[{"symbol":null,"formerSymbols":[],"notes":"","references":[],"modelId":16728,"synonyms":[],"fullName":null,"complexId":null,"type":"Compartment","abbreviation":null,"compartmentId":null,"name":"c2","bounds":{"x":189.0,"width":291.0,"y":33.0,"height":296.0},"formula":null,"id":345332,"linkedSubmodel":null,"hierarchyVisibilityLevel":[]},{"symbol":null,"formerSymbols":[],"notes":"","references":[],"modelId":16728,"synonyms":[],"fullName":null,"complexId":null,"type":"Compartment","abbreviation":null,"compartmentId":null,"name":"c1","bounds":{"x":35.0,"width":144.0,"y":45.0,"height":142.0},"formula":null,"id":345323,"linkedSubmodel":null,"hierarchyVisibilityLevel":[]}]
\ No newline at end of file
{"reactionAnnotations":{"COG":0,"CHEBI":0,"EC":0,"TOXICOGENOMIC_CHEMICAL":0,"DRUGBANK":0,"PFAM":0,"KEGG_PATHWAY":0,"SGD":0,"CHEMBL_COMPOUND":0,"CHEMSPIDER":0,"TAXONOMY":0,"ENSEMBL":0,"PUBMED":0,"CCDS":0,"ENTREZ":0,"MI_R_BASE_MATURE_SEQUENCE":0,"PUBCHEM_SUBSTANCE":0,"WIKIDATA":0,"CAS":0,"OMIM":0,"PHARM":0,"WORM_BASE":0,"KEGG_REACTION":0,"KEGG_ORTHOLOGY":0,"CHEMBL_TARGET":0,"HMDB":0,"DRUGBANK_TARGET_V4":0,"PANTHER":0,"GO":0,"MIR_TAR_BASE_MATURE_SEQUENCE":0,"UNIPROT_ISOFORM":0,"WIKIPEDIA":0,"REACTOME":0,"HGNC":0,"UNIPROT":0,"INTERPRO":0,"WIKIPATHWAYS":0,"MESH_2012":0,"KEGG_COMPOUND":0,"MI_R_BASE_SEQUENCE":0,"UNIGENE":0,"MGD":0,"ENSEMBL_PLANTS":0,"PUBCHEM":0,"HGNC_SYMBOL":0,"REFSEQ":0,"KEGG_GENES":0,"TAIR_LOCUS":0,"UNKNOWN":0},"elementAnnotations":{"COG":0,"CHEBI":0,"EC":0,"TOXICOGENOMIC_CHEMICAL":0,"DRUGBANK":0,"PFAM":0,"KEGG_PATHWAY":0,"SGD":0,"CHEMBL_COMPOUND":0,"CHEMSPIDER":0,"TAXONOMY":0,"ENSEMBL":0,"PUBMED":0,"CCDS":0,"ENTREZ":0,"MI_R_BASE_MATURE_SEQUENCE":0,"PUBCHEM_SUBSTANCE":0,"WIKIDATA":0,"CAS":0,"OMIM":0,"PHARM":0,"WORM_BASE":0,"KEGG_REACTION":0,"KEGG_ORTHOLOGY":0,"CHEMBL_TARGET":0,"HMDB":0,"DRUGBANK_TARGET_V4":0,"PANTHER":0,"GO":0,"MIR_TAR_BASE_MATURE_SEQUENCE":0,"UNIPROT_ISOFORM":0,"WIKIPEDIA":0,"REACTOME":0,"HGNC":0,"UNIPROT":0,"INTERPRO":0,"WIKIPATHWAYS":0,"MESH_2012":0,"KEGG_COMPOUND":0,"MI_R_BASE_SEQUENCE":0,"UNIGENE":0,"MGD":0,"ENSEMBL_PLANTS":0,"PUBCHEM":0,"HGNC_SYMBOL":0,"REFSEQ":0,"KEGG_GENES":0,"TAIR_LOCUS":0,"UNKNOWN":0}}
\ No newline at end of file
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