Commit 84dbb4f2 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

selection of export column type added

parent 9c465805
......@@ -8,6 +8,8 @@ var GuiConnector = require('../../GuiConnector');
var logger = require('../../logger');
var Functions = require('../../Functions');
var Promise = require("bluebird");
function ElementExportPanel(params) {
params.panelName = "elementExport";
params.scrollable = true;
......@@ -30,6 +32,7 @@ ElementExportPanel.prototype.init = function() {
return ServerConnector.getConfiguration().then(function(configuration) {
var typeDiv = self._createSelectTypeDiv(configuration.getElementTypes());
element.appendChild(typeDiv);
element.appendChild(self._createSelectColumnDiv());
});
}
......@@ -63,20 +66,159 @@ ElementExportPanel.prototype._createSelectTypeDiv = function(elementTypes) {
return typeDiv;
}
ElementExportPanel.prototype._createSelectColumnDiv = function() {
var self = this;
var columnDiv = Functions.createElement({
type : "div",
name : "columnSelectDiv",
});
columnDiv.appendChild(Functions.createElement({
type : "h4",
content : " COLUMN:",
}));
var choicesContainer = Functions.createElement({
type : "ul",
className : "minerva-checkbox-grid"
});
var columnTypes = self.getAllColumns();
columnDiv.appendChild(choicesContainer);
for (var i = 0; i < columnTypes.length; i++) {
var columnType = columnTypes[i];
var row = Functions.createElement({
type : "li",
content : "<div class=\"checkbox\"><label> <input type=\"checkbox\" name=\"column_" + columnType.columnName
+ "\" value=\"" + columnType.columnName + "\" />" + columnType.name + "</label></div>"
});
choicesContainer.appendChild(row);
}
choicesContainer.appendChild(Functions.createElement({
type : "li",
content : "<div class=\"checkbox\"><label> <input type=\"checkbox\" name=\"ALL\" value=\"ALL\" />ALL</label></div>"
}));
return columnDiv;
}
ElementExportPanel.prototype.getAllColumns = function() {
return [ {
"columnName" : "id",
"method" : "getId",
"name" : "Id",
}, {
"columnName" : "name",
"method" : "getName",
"name" : "Name",
}, {
"columnName" : "description",
"method" : "getDescription",
"name" : "Description",
}, {
"columnName" : "modelId",
"method" : "getModelId",
"name" : "Model",
}, {
"columnName" : "type",
"method" : "getType",
"name" : "Type",
}, {
"columnName" : "complexId",
"method" : "getComplexId",
"name" : "Complex",
}, {
"columnName" : "compartmentId",
"method" : "getCompartmentId",
"name" : "Compartment",
}, {
"columnName" : "charge",
"method" : "getCharge",
"name" : "Charge",
}, {
"columnName" : "symbol",
"method" : "getSymbol",
"name" : "Symbol",
}, {
"columnName" : "fullName",
"method" : "getFullName",
"name" : "Full name",
}, {
"columnName" : "abbreviation",
"method" : "getAbbreviation",
"name" : "Abbreviation",
}, {
"columnName" : "formula",
"method" : "getFormula",
"name" : "Formula",
}, {
"columnName" : "synonyms",
"method" : "getSynonyms",
"name" : "Synonyms",
}, {
"columnName" : "formerSymbols",
"method" : "getFormerSymbols",
"name" : "Former symbols",
}, {
"columnName" : "references",
"method" : "getReferences",
"name" : "References",
}, {
"columnName" : "linkedSubmodelId",
"method" : "getLinkedSubmodelId",
"name" : "Linked submodel",
}, {
"columnName" : "elementId",
"method" : "getElementId",
"name" : "Element external id",
}, ];
};
ElementExportPanel.prototype.getSelectedTypes = function() {
var self = this;
var div = $("div[name='typeSelectDiv']", $(self.getElement()))[0];
var result = [];
var selectedAll = false
$(":checked", $(div)).each(function(index, element) {
if (element.value === "ALL") {
return ServerConnector.getConfiguration().then(function(configuration) {
return configuration.getElementTypes();
});
selectedAll = true;
}
result.push(element.value);
});
return result;
if (selectedAll) {
return ServerConnector.getConfiguration().then(function(configuration) {
return configuration.getElementTypes();
});
}
return Promise.resolve(result);
}
ElementExportPanel.prototype.getSelectedColumns = function() {
var self = this;
var div = $("div[name='columnSelectDiv']", $(self.getElement()))[0];
var selectedColumnMap = [];
var selectedAll = false
$(":checked", $(div)).each(function(index, element) {
if (element.value === "ALL") {
selectedAll = true;
}
selectedColumnMap[element.value] = true;
});
var columnTypes = self.getAllColumns();
if (selectedAll) {
return Promise.resolve(columnTypes);
}
var result = [];
for (var i = 0; i < columnTypes.length; i++) {
var columnType = columnTypes[i];
if (selectedColumnMap[columnType.columnName] === true) {
result.push(columnType);
}
}
return Promise.resolve(result);
}
module.exports = ElementExportPanel;
......@@ -9,7 +9,7 @@ var originalNavigator = null;
describe('ElementExportPanel', function() {
describe('getSelectedTypes', function() {
it('sleect single element', function() {
it('select single element', function() {
var exportObject;
var project;
return ServerConnector.getProject().then(function(result) {
......@@ -52,9 +52,59 @@ describe('ElementExportPanel', function() {
});
return exportObject.getSelectedTypes();
}).then(function(selectedTypes) {
assert.deepEqual([ "Degraded" ], selectedTypes);
assert.deepEqual(elementTypes, selectedTypes);
});
});
});
describe('getSelectedColumns', 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() {
$("input[name='column_name']", $(testDiv)).each(function(index, element) {
element.checked = true;
});
return exportObject.getSelectedColumns();
}).then(function(selectedTypes) {
assert.equal([ "name" ], selectedTypes[0].columnName);
});
});
it('select all', function() {
var exportObject;
var project;
var elementTypes;
return ServerConnector.getConfiguration().then(function(configuration) {
elementTypes = configuration.getElementTypes();
return ServerConnector.getProject();
}).then(function(result) {
project = result;
exportObject = new ElementExportPanel({
element : testDiv,
project : project
});
return exportObject.init();
}).then(function() {
$("input[name='column_name']", $(testDiv)).each(function(index, element) {
element.checked = true;
});
$("input[name='ALL']", $(testDiv)).each(function(index, element) {
element.checked = true;
});
return exportObject.getSelectedColumns();
}).then(function(selectedTypes) {
assert.deepEqual(exportObject.getAllColumns(), selectedTypes);
});
});
});
});
......@@ -2,5 +2,4 @@ eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
......@@ -41,6 +41,12 @@ table.mapInfoBoxResultsTable, table.mapInfoBoxResultsTable th, table.mapInfoBoxR
margin-bottom: 2px;
}
.minerva-checkbox-grid:after {
content: '';
display: block;
clear: both;
}
.mapChartNameDiv {
width: 150px;
......
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