Commit 3461589e authored by Piotr Gawron's avatar Piotr Gawron
Browse files

list of element types is sorted

parent 4bd09968
......@@ -8,6 +8,8 @@ minerva (12.3.0~alpha.0) unstable; urgency=low
* Small improvement: New comment dialog does not contain content of previous
comment dialog (#680)
* Small improvement: Left logo is configurable (#731)
* Small improvement: list of element types in choose annotator dialog is
sorted (#758)
* Small improvement: Plugin API provides list of overview images (#702)
* Small improvement: Plugin API allows to show/hide overview images (#702)
* Small improvement: Plugin API allows to trigger search on the map (#702)
......
......@@ -7,7 +7,6 @@ var Annotator = require("../../map/data/Annotator");
var AnnotatorParameter = require("../../map/data/AnnotatorParameter");
var GuiConnector = require("../../GuiConnector");
var MultiCheckboxList = require("multi-checkbox-list");
var UserPreferences = require("../../map/data/UserPreferences");
var Functions = require('../../Functions');
var Promise = require('bluebird');
......@@ -402,6 +401,33 @@ ChooseAnnotatorsDialog.prototype.createAnnotatorsParams = function (selectedAnno
};
/**
*
* @return {BioEntityTypeTreeNode[]}
*/
ChooseAnnotatorsDialog.prototype.getTypeNodeList = function () {
var types = [];
var treeData = this.getConfiguration().getElementTypeTree();
var queue = [treeData];
while (queue.length > 0) {
var node = queue.shift();
if (node.children !== undefined && node.children.length > 0) {
for (var i = 0; i < node.children.length; i++) {
queue.push(node.children[i]);
}
} else {
types.push(node);
}
}
types.sort(function (a, b) {
return a.text.localeCompare(b.text);
});
return types;
};
/**
*
* @returns {Promise}
......@@ -412,22 +438,7 @@ ChooseAnnotatorsDialog.prototype.init = function () {
var configuration = self.getConfiguration();
var treeData = configuration.getElementTypeTree();
var types = [];
var queue = [treeData];
var i;
while (queue.length > 0) {
var node = queue.shift();
if (node.children !== undefined && node.children.length > 0) {
for (i = 0; i < node.children.length; i++) {
queue.push(node.children[i]);
}
} else {
types.push(node);
}
}
var types = self.getTypeNodeList();
var element = $('[name="elementList"]', self.getElement())[0];
var select = Functions.createElement({
......@@ -445,7 +456,7 @@ ChooseAnnotatorsDialog.prototype.init = function () {
}
});
select.size = 15;
for (i = 0; i < types.length; i++) {
for (var i = 0; i < types.length; i++) {
var type = types[i];
var option = Functions.createElement({
type: "option",
......@@ -482,9 +493,6 @@ ChooseAnnotatorsDialog.prototype.init = function () {
annotator = annotators[i];
}
}
if (annotatorClassName === undefined) {
throw new Error("Annotator is not used by user: " + div.innerHTML);
}
return self.createAnnotatorsParams(annotator);
}).catch(GuiConnector.alert);
});
......
......@@ -29,6 +29,15 @@ describe('ChooseAnnotatorsDialog', function () {
return dialog.init();
});
it('getTypeNodeList sorted', function () {
var dialog = createDialog();
var types = dialog.getTypeNodeList();
for (var i = 1; i < types.length; i++) {
assert.ok(types[i - 1].text.localeCompare(types[i].text) <= 0, types[i - 1].text + " and " + types[i].text + " are not sorted alphabetically");
}
});
it('setElementType', function () {
var dialog = createDialog();
var configuration = helper.getConfiguration();
......
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