From 194782f850057c31ee9aaec1f889520f98e621b3 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 17 Sep 2019 17:11:37 +0200
Subject: [PATCH] list of copy entity types in annotators and validators is
 unified

---
 CHANGELOG                                     |  2 ++
 .../js/gui/admin/AbstractAnnotatorsDialog.js  | 28 ++++++++++++++++
 .../js/gui/admin/ChooseAnnotatorsDialog.js    | 27 ---------------
 .../js/gui/admin/ChooseValidatorsDialog.js    | 16 ++++-----
 .../gui/admin/ChooseValidatorsDialog-test.js  | 33 ++++++++-----------
 5 files changed, 50 insertions(+), 56 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index bc33dd952e..d1a240b4a5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,8 @@ minerva (14.0.0~beta.2) unstable; urgency=low
   * Bug fix: allow user to remove own comments (#931)
   * Bug fix: validation of project name length is provided (#950)
   * Bug fix: after reducing privileges on himself interface is refreshed (#948)
+  * Bug fix: list of "Copy from" elements in "Select valid annotations" dialog 
+    is shortened to used bio entity typrd (#911)
   * Bug fix: removing overlays as curator in admin panel fixed (#944)
   * Bug fix: information about deprecated column is more clear about column 
     names (#838)
diff --git a/frontend-js/src/main/js/gui/admin/AbstractAnnotatorsDialog.js b/frontend-js/src/main/js/gui/admin/AbstractAnnotatorsDialog.js
index d13c51e060..4871327e41 100644
--- a/frontend-js/src/main/js/gui/admin/AbstractAnnotatorsDialog.js
+++ b/frontend-js/src/main/js/gui/admin/AbstractAnnotatorsDialog.js
@@ -51,4 +51,32 @@ AbstractAnnotatorsDialog.prototype.getAllChildrenTypesIfNeeded = function (eleme
   return result;
 };
 
+/**
+ *
+ * @return {BioEntityTypeTreeNode[]}
+ */
+AbstractAnnotatorsDialog.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;
+};
+
+
 module.exports = AbstractAnnotatorsDialog;
diff --git a/frontend-js/src/main/js/gui/admin/ChooseAnnotatorsDialog.js b/frontend-js/src/main/js/gui/admin/ChooseAnnotatorsDialog.js
index 320eb60e67..421a9d0c06 100644
--- a/frontend-js/src/main/js/gui/admin/ChooseAnnotatorsDialog.js
+++ b/frontend-js/src/main/js/gui/admin/ChooseAnnotatorsDialog.js
@@ -416,33 +416,6 @@ 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}
diff --git a/frontend-js/src/main/js/gui/admin/ChooseValidatorsDialog.js b/frontend-js/src/main/js/gui/admin/ChooseValidatorsDialog.js
index 78cfe77450..f39b87d68d 100644
--- a/frontend-js/src/main/js/gui/admin/ChooseValidatorsDialog.js
+++ b/frontend-js/src/main/js/gui/admin/ChooseValidatorsDialog.js
@@ -21,7 +21,7 @@ var logger = require('../../logger');
  * @param {Object} params
  * @param {HTMLElement} params.element
  * @param {CustomMap} params.customMap
- * @param {Configuration} [params.configuration]
+ * @param {Configuration} params.configuration
  * @param {ServerConnector} [params.serverConnector]
  *
  * @constructor
@@ -125,16 +125,13 @@ ChooseValidatorsDialog.prototype.setElementType = function (elementType) {
     var copyFromSelect = Functions.createElement({type: "select", style: "margin:5px"});
     element.appendChild(copyFromSelect);
     var options = [], i;
-    for (i = 0; i < configuration.getElementTypes().length; i++) {
-      var type = configuration.getElementTypes()[i];
-      var name = type.className;
-      if (name.indexOf(".") > 0) {
-        name = name.substr(name.lastIndexOf(".") + 1);
-      }
+    var nodeList = self.getTypeNodeList();
+    for (i = 0; i < nodeList.length; i++) {
+      var type = nodeList[i];
       options.push(Functions.createElement({
         type: "option",
-        value: type.className,
-        content: name
+        value: type.data.className,
+        content: type.text
       }));
     }
     options.sort(function (a, b) {
@@ -143,6 +140,7 @@ ChooseValidatorsDialog.prototype.setElementType = function (elementType) {
     for (i = 0; i < options.length; i++) {
       copyFromSelect.appendChild(options[i]);
     }
+
     element.appendChild(includeChildrenCheckbox);
     element.appendChild(Functions.createElement({type: "span", content: "Apply to all in subtree"}));
 
diff --git a/frontend-js/src/test/js/gui/admin/ChooseValidatorsDialog-test.js b/frontend-js/src/test/js/gui/admin/ChooseValidatorsDialog-test.js
index d9c985baf8..947487387f 100644
--- a/frontend-js/src/test/js/gui/admin/ChooseValidatorsDialog-test.js
+++ b/frontend-js/src/test/js/gui/admin/ChooseValidatorsDialog-test.js
@@ -11,34 +11,31 @@ var Promise = require('bluebird');
 var chai = require('chai');
 var assert = chai.assert;
 
+function createDialog() {
+  return new ChooseValidatorsDialog({
+    element: testDiv,
+    customMap: null,
+    serverConnector: ServerConnector,
+    configuration: helper.getConfiguration()
+  });
+}
+
 describe('ChooseValidatorsDialog', function () {
   it('init', function () {
-    var dialog = new ChooseValidatorsDialog({
-      element: testDiv,
-      customMap: null,
-      serverConnector: ServerConnector
-    });
+    var dialog = createDialog();
     assert.equal(0, logger.getWarnings().length);
     return dialog.init();
   });
 
   it('setElementType', function () {
-    var dialog = new ChooseValidatorsDialog({
-      element: testDiv,
-      customMap: null,
-      serverConnector: ServerConnector
-    });
+    var dialog = createDialog();
     return ServerConnector.getConfiguration().then(function (configuration) {
       return dialog.setElementType(configuration.getReactionTypes()[0]);
     })
   });
 
   it('open', function () {
-    var dialog = new ChooseValidatorsDialog({
-      element: testDiv,
-      customMap: null,
-      serverConnector: ServerConnector
-    });
+    var dialog = createDialog();
     return dialog.init().then(function () {
       return dialog.open();
     }).then(function () {
@@ -52,11 +49,7 @@ describe('ChooseValidatorsDialog', function () {
     helper.loginAsAdmin();
     var originalFunction = ServerConnector.updateUserPreferences;
     var functionCalled = false;
-    var dialog = new ChooseValidatorsDialog({
-      element: testDiv,
-      customMap: null,
-      serverConnector: ServerConnector
-    });
+    var dialog = createDialog();
     return dialog.init().then(function () {
       return dialog.open();
     }).then(function () {
-- 
GitLab