From 9493a6dcd4e572a71f53789565a1c84c542be5f1 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 24 Jul 2018 11:01:20 +0200
Subject: [PATCH] jsdoc improved

---
 frontend-js/src/main/js/Configuration.js      | 52 ++++++++++++++
 .../src/main/js/gui/admin/AddProjectDialog.js |  3 +-
 .../js/gui/admin/ChooseValidatorsDialog.js    | 67 ++++++++++++++++---
 .../gui/admin/ChooseValidatorsDialog-test.js  |  6 +-
 4 files changed, 115 insertions(+), 13 deletions(-)

diff --git a/frontend-js/src/main/js/Configuration.js b/frontend-js/src/main/js/Configuration.js
index beadc52c9e..df5d61bea4 100644
--- a/frontend-js/src/main/js/Configuration.js
+++ b/frontend-js/src/main/js/Configuration.js
@@ -12,6 +12,27 @@ var MiriamType = require('./map/data/MiriamType');
 var PrivilegeType = require('./map/data/PrivilegeType');
 var ModificationStateType = require('./map/data/ModificationStateType');
 
+/**
+ * @typedef {Object} BioEntityType
+ * @property {string} className - string identifying java class
+ * @property {string} name - common name of element
+ * @property {string} parentClass - string identifying parent java class
+ */
+
+/**
+ * @typedef {Object} BioEntityTypeTreeNode
+ * @property {string} text - string description of node
+ * @property {BioEntityTypeTreeNode[]} children - set if children types
+ * @property {BioEntityType} data - metadata of the type
+ *
+ */
+
+
+/**
+ *
+ * @param {Object|Configuration} json
+ * @constructor
+ */
 function Configuration(json) {
   var self = this;
 
@@ -66,23 +87,50 @@ function Configuration(json) {
   }
 }
 
+/**
+ *
+ * @param {string} version
+ */
 Configuration.prototype.setVersion = function (version) {
   this._version = version;
 };
+
+/**
+ *
+ * @returns {string}
+ */
 Configuration.prototype.getVersion = function () {
   return this._version;
 };
 
+/**
+ *
+ * @param {string} buildDate
+ */
 Configuration.prototype.setBuildDate = function (buildDate) {
   this._buildDate = buildDate;
 };
+
+/**
+ *
+ * @returns {string}
+ */
 Configuration.prototype.getBuildDate = function () {
   return this._buildDate;
 };
 
+/**
+ *
+ * @param {string} gitHash
+ */
 Configuration.prototype.setGitHash = function (gitHash) {
   this._gitHash = gitHash;
 };
+
+/**
+ *
+ * @returns {string}
+ */
 Configuration.prototype.getGitHash = function () {
   return this._gitHash;
 };
@@ -410,6 +458,10 @@ Configuration.prototype.update = function (original) {
   }
 };
 
+/**
+ *
+ * @returns {BioEntityTypeTreeNode}
+ */
 Configuration.prototype.getElementTypeTree = function () {
   var elementTypes = this.getElementTypes();
   var reactionTypes = this.getReactionTypes();
diff --git a/frontend-js/src/main/js/gui/admin/AddProjectDialog.js b/frontend-js/src/main/js/gui/admin/AddProjectDialog.js
index a436197c2a..72177296be 100644
--- a/frontend-js/src/main/js/gui/admin/AddProjectDialog.js
+++ b/frontend-js/src/main/js/gui/admin/AddProjectDialog.js
@@ -147,7 +147,8 @@ AddProjectDialog.prototype.showValidatorsDialog = function () {
   if (self._validatorsDialog === undefined) {
     self._validatorsDialog = new ChooseValidatorsDialog({
       element: Functions.createElement({type: "div"}),
-      customMap: null
+      customMap: null,
+      serverConnector: self.getServerConnector()
     });
     promise = self._validatorsDialog.init();
   } else {
diff --git a/frontend-js/src/main/js/gui/admin/ChooseValidatorsDialog.js b/frontend-js/src/main/js/gui/admin/ChooseValidatorsDialog.js
index 1241d1c4e0..2bea97c6de 100644
--- a/frontend-js/src/main/js/gui/admin/ChooseValidatorsDialog.js
+++ b/frontend-js/src/main/js/gui/admin/ChooseValidatorsDialog.js
@@ -3,16 +3,28 @@
 /* exported logger */
 
 var AbstractGuiElement = require('../AbstractGuiElement');
-var DualListbox = require('dual-listbox').DualListbox;
 var GuiConnector = require("../../GuiConnector");
 var UserPreferences = require("../../map/data/UserPreferences");
 var MultiCheckboxList = require("multi-checkbox-list");
 
 var Functions = require('../../Functions');
+// noinspection JSUnusedLocalSymbols
 var logger = require('../../logger');
 
-var Promise = require("bluebird");
-
+/**
+ *
+ /**
+ *
+ * @param {Object} params
+ * @param {HTMLElement} params.element
+ * @param {CustomMap} params.customMap
+ * @param {Configuration} [params.configuration]
+ * @param {ServerConnector} [params.serverConnector]
+ *
+ * @constructor
+ *
+ * @extends AbstractGuiElement
+ */
 function ChooseValidatorsDialog(params) {
   AbstractGuiElement.call(this, params);
   var self = this;
@@ -22,6 +34,9 @@ function ChooseValidatorsDialog(params) {
 ChooseValidatorsDialog.prototype = Object.create(AbstractGuiElement.prototype);
 ChooseValidatorsDialog.prototype.constructor = ChooseValidatorsDialog;
 
+/**
+ *
+ */
 ChooseValidatorsDialog.prototype.createGui = function () {
   var self = this;
   var content = Functions.createElement({
@@ -45,14 +60,19 @@ ChooseValidatorsDialog.prototype.createGui = function () {
   self.getElement().appendChild(content);
 };
 
+/**
+ *
+ * @param {BioEntityType} elementType
+ * @returns {Promise}
+ */
 ChooseValidatorsDialog.prototype.setElementType = function (elementType) {
   var self = this;
 
   var configuration;
 
-  return ServerConnector.getConfiguration().then(function (result) {
+  return self.getServerConnector().getConfiguration().then(function (result) {
     configuration = result;
-    return ServerConnector.getLoggedUser();
+    return self.getServerConnector().getLoggedUser();
   }).then(function (user) {
     var element = $("[name='annotatorListBox']", self.getElement())[0];
     Functions.removeChildren(element);
@@ -74,6 +94,13 @@ ChooseValidatorsDialog.prototype.setElementType = function (elementType) {
 
 };
 
+/**
+ *
+ * @param {User} user
+ * @param {Configuration} configuration
+ * @param {BioEntityType} elementType
+ * @param {HTMLElement} validAnnotationSelect
+ */
 ChooseValidatorsDialog.prototype.createValidAnnotationsDualListBox = function (user, configuration, elementType, validAnnotationSelect) {
 
   var miriamTypes = configuration.getMiriamTypes();
@@ -87,7 +114,6 @@ ChooseValidatorsDialog.prototype.createValidAnnotationsDualListBox = function (u
     var miriamType = miriamTypes[i];
     var entry = {name: miriamType.getCommonName(), value: miriamType.getName(), selected: false};
 
-    var selected = false;
     for (var j = 0; j < validAnnotations.length; j++) {
       if (miriamType.getName() === validAnnotations[j]) {
         entry.selected = true;
@@ -125,7 +151,10 @@ ChooseValidatorsDialog.prototype.createValidAnnotationsDualListBox = function (u
     var elementAnnotators = {};
     elementAnnotators[elementType.className] = validAnnotations;
     data.setElementValidAnnotations(elementAnnotators);
-    return ServerConnector.updateUserPreferences({user: user, preferences: data}).then(null, GuiConnector.alert);
+    return self.getServerConnector().updateUserPreferences({
+      user: user,
+      preferences: data
+    }).catch(GuiConnector.alert);
   };
 
   checkboxList.addListener("select", function (element) {
@@ -137,6 +166,14 @@ ChooseValidatorsDialog.prototype.createValidAnnotationsDualListBox = function (u
 
 };
 
+/**
+ *
+ * @param {User} user
+ * @param {Configuration} configuration
+ * @param {BioEntityType} elementType
+ * @param {HTMLElement} verifyAnnotationSelect
+ */
+
 ChooseValidatorsDialog.prototype.createVerifyAnnotationsDualListBox = function (user, configuration, elementType, verifyAnnotationSelect) {
   var requiredAnnotationsData = user.getPreferences().getElementRequiredAnnotations(elementType.className);
 
@@ -154,7 +191,7 @@ ChooseValidatorsDialog.prototype.createVerifyAnnotationsDualListBox = function (
         "annotation-list": requiredAnnotationsData.list
       };
       data.setElementRequiredAnnotations(elementRequiredAnnotations);
-      return ServerConnector.updateUserPreferences({user: user, preferences: data}).then(null, GuiConnector.alert);
+      return self.getServerConnector().updateUserPreferences({user: user, preferences: data}).catch(GuiConnector.alert);
     }
   });
   checkbox.checked = requiredAnnotationsData.requiredAtLeastOnce;
@@ -215,7 +252,7 @@ ChooseValidatorsDialog.prototype.createVerifyAnnotationsDualListBox = function (
       "annotation-list": requiredAnnotationsData.list
     };
     data.setElementRequiredAnnotations(elementRequiredAnnotations);
-    return ServerConnector.updateUserPreferences({user: user, preferences: data}).then(null, GuiConnector.alert);
+    return self.getServerConnector().updateUserPreferences({user: user, preferences: data}).catch(GuiConnector.alert);
   };
 
   checkboxList.addListener("select", function (element) {
@@ -227,9 +264,13 @@ ChooseValidatorsDialog.prototype.createVerifyAnnotationsDualListBox = function (
 
 };
 
+/**
+ *
+ * @returns {Promise}
+ */
 ChooseValidatorsDialog.prototype.init = function () {
   var self = this;
-  return ServerConnector.getConfiguration().then(function (configuration) {
+  return self.getServerConnector().getConfiguration().then(function (configuration) {
 
     var treeData = configuration.getElementTypeTree();
 
@@ -248,10 +289,16 @@ ChooseValidatorsDialog.prototype.init = function () {
   });
 };
 
+/**
+ *
+ */
 ChooseValidatorsDialog.prototype.destroy = function () {
   $(this.getElement()).dialog("destroy");
 };
 
+/**
+ *
+ */
 ChooseValidatorsDialog.prototype.open = function () {
   var self = this;
   var div = self.getElement();
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 b92f7df9a5..e148b7bb06 100644
--- a/frontend-js/src/test/js/gui/admin/ChooseValidatorsDialog-test.js
+++ b/frontend-js/src/test/js/gui/admin/ChooseValidatorsDialog-test.js
@@ -13,7 +13,8 @@ describe('ChooseValidatorsDialog', function () {
   it('init', function () {
     var dialog = new ChooseValidatorsDialog({
       element: testDiv,
-      customMap: null
+      customMap: null,
+      serverConnector: ServerConnector
     });
     assert.equal(0, logger.getWarnings().length);
     return dialog.init();
@@ -22,7 +23,8 @@ describe('ChooseValidatorsDialog', function () {
   it('setElementType', function () {
     var dialog = new ChooseValidatorsDialog({
       element: testDiv,
-      customMap: null
+      customMap: null,
+      serverConnector: ServerConnector
     });
     return ServerConnector.getConfiguration().then(function (configuration) {
       return dialog.setElementType(configuration.getReactionTypes()[0]);
-- 
GitLab