Commit 610d62b7 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

fronted adapted for the new rest api responses regarding annotators

parent 8f74234f
......@@ -3548,9 +3548,9 @@
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"multi-checkbox-list": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/multi-checkbox-list/-/multi-checkbox-list-0.2.0.tgz",
"integrity": "sha512-b1HVb8XqCNtC2OAu2AVgs/eaNnMS9Zudv61Nsi3OR9527P5c5IfwGbCzgLyBHiT0pHeL7Kpk6V+6bQYM8sYaTg=="
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/multi-checkbox-list/-/multi-checkbox-list-0.3.1.tgz",
"integrity": "sha512-EIPqI+PLsexsTMs1OfUvN89zYpWp7I7rqWD5+wMVJgUutPZSt31l3iYnIr79QnBbIu/P5uvZFNU4Iwd6Mzxy4w=="
},
"nave": {
"version": "0.5.3",
......
......@@ -49,7 +49,7 @@
"jstree": "^3.3.5",
"jszip": "^3.1.5",
"log4js": "0.6.38",
"multi-checkbox-list": "^0.2.0",
"multi-checkbox-list": "^0.3.1",
"openlayers": "^4.6.5",
"pileup": "^0.6.9",
"request": "^2.88.0",
......
......@@ -1276,7 +1276,11 @@ ServerConnector.getUser = function (login) {
columns: ["id", "login", "name", "surname", "email", "minColor", "maxColor", "neutralColor", "simpleColor", "removed", "privileges", "preferences", "termsOfUseConsent"]
};
return self.sendGetRequest(self.getUserUrl(queryParams, filterParams)).then(function (content) {
var configuration;
return self.getConfiguration().then(function (result) {
configuration = result;
return self.sendGetRequest(self.getUserUrl(queryParams, filterParams));
}).then(function (content) {
var obj = JSON.parse(content);
var user = new User(obj);
if (self._usersByLogin[user.getLogin()] instanceof User) {
......
......@@ -176,7 +176,7 @@ AddPluginDialog.prototype.onValidateClicked = function () {
}).then(function (plugins) {
for (var i = 0; i < plugins.length; i++) {
var pluginData = plugins[i];
if (pluginData.getUrls().indexOf(url) >= 0) {
if (pluginData.getUrls().indexOf(url) >= 0 && pluginData.isPublic()) {
throw new ValidationError("Plugin is already registered");
}
}
......
......@@ -800,7 +800,7 @@ AddProjectDialog.prototype.bindProjectUploadPreferences = function (user, type,
element.change(function () {
var data = new UserPreferences();
data.getProjectUpload()[type] = element.is(":checked");
return ServerConnector.updateUserPreferences({user: user, preferences: data}).then(null, GuiConnector.alert);
return ServerConnector.updateUserPreferences({user: user, preferences: data}).catch(GuiConnector.alert);
});
};
......
......@@ -8,6 +8,7 @@ var MultiCheckboxList = require("multi-checkbox-list");
var UserPreferences = require("../../map/data/UserPreferences");
var Functions = require('../../Functions');
var Promise = require('bluebird');
// noinspection JSUnusedLocalSymbols
var logger = require('../../logger');
......@@ -59,31 +60,31 @@ ChooseAnnotatorsDialog.prototype.createGui = function () {
self.getElement().appendChild(content);
};
/**
*
* @param {HTMLElement} element
* @param {User} user
* @returns {Promise}
*/
function onChangeParameterValue(element, user) {
var name = $(element).siblings(".minerva-annotator-param-name")[0].childNodes[0].nodeValue;
var annotatorClassName = $(element).parent().parent().attr('name');
var data = new UserPreferences();
var annotatorsParams = {};
annotatorsParams[annotatorClassName] = {};
if (element.type == 'checkbox') annotatorsParams[annotatorClassName][name] = element.checked.toString();
else annotatorsParams[annotatorClassName][name] = element.value;
data.setAnnotatorsParameters(annotatorsParams);
return ServerConnector.updateUserPreferences({user: user, preferences: data}).then(null, GuiConnector.alert);
}
// /**
// *
// * @param {HTMLInputElement} element
// * @param {User} user
// * @returns {Promise}
// */
// function onChangeParameterValue(element, user) {
// var name = $(element).siblings(".minerva-annotator-param-name")[0].childNodes[0].nodeValue;
// var annotatorClassName = $(element).parent().parent().attr('name');
//
// var data = new UserPreferences();
//
// var annotatorsParams = {};
// annotatorsParams[annotatorClassName] = {};
// if (element.type === 'checkbox') annotatorsParams[annotatorClassName][name] = element.checked.toString();
// else annotatorsParams[annotatorClassName][name] = element.value;
// data.setAnnotatorsParameters(annotatorsParams);
//
// return ServerConnector.updateUserPreferences({user: user, preferences: data}).then(null, GuiConnector.alert);
// }
/**
*
* @param {BioEntityType[][]} elementTypes
* @param {string[]} selectedAnnotators
* @param {BioEntityType[]} elementTypes
* @param {Annotator[]} selectedAnnotators
* @returns {Promise}
*/
ChooseAnnotatorsDialog.prototype.saveAnnotatorsInfo = function (elementTypes, selectedAnnotators) {
......@@ -120,7 +121,7 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
return ServerConnector.getLoggedUser().then(function (user) {
var element = $("[name='annotatorListBox']", self.getElement())[0];
var annotatorsParams = $(".minerva-annotators-params", self.getElement())[0];
// var annotatorsParams = $(".minerva-annotators-params", self.getElement())[0];
Functions.removeChildren(element);
var selectElement = Functions.createElement({
......@@ -186,7 +187,7 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
var annotator = annotators[i];
var entry = {name: annotator.getName(), value: annotator.getClassName(), selected: false};
for (var j = 0; j < selectedAnnotators.length; j++) {
if (annotator.getName() === selectedAnnotators[j]) {
if (annotator.getClassName() === selectedAnnotators[j].getClassName()) {
entry.selected = true;
}
}
......@@ -199,25 +200,32 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
selectedList: true
});
var changeSelection = function (elementId, selected) {
return Promise.resolve().then(function () {
var annotators = configuration.getElementAnnotators();
var annotator;
for (var i = 0; i < annotators.length; i++) {
if (elementId === annotators[i].getClassName()) {
annotator = annotators[i];
var annotators = configuration.getElementAnnotators();
var annotator;
for (var i = 0; i < annotators.length; i++) {
if (elementId === annotators[i].getClassName()) {
annotator = annotators[i];
}
}
}
if (selected) {
selectedAnnotators.push(annotator.getName());
} else {
var index = selectedAnnotators.indexOf(annotator.getName());
if (index > -1) {
selectedAnnotators.splice(index, 1);
if (selected) {
selectedAnnotators.push(annotator);
} else {
var index = -1;
for (var j = 0; j < selectedAnnotators.length; j++) {
if (selectedAnnotators[j].getClassName() === annotator.getClassName()) {
index = j;
}
}
if (index > -1) {
selectedAnnotators.splice(index, 1);
}
}
}
createAnnotatorsParams();
var includeChildren = includeChildrenCheckbox.checked;
return self.saveAnnotatorsInfo(self.getAllChildrenTypesIfNeeded(elementType, includeChildren), selectedAnnotators);
createAnnotatorsParams();
var includeChildren = includeChildrenCheckbox.checked;
return self.saveAnnotatorsInfo(self.getAllChildrenTypesIfNeeded(elementType, includeChildren), selectedAnnotators);
}).catch(GuiConnector.alert);
};
includeChildrenCheckbox.onchange = function () {
var includeChildren = includeChildrenCheckbox.checked;
......@@ -233,110 +241,110 @@ ChooseAnnotatorsDialog.prototype.setElementType = function (elementType) {
function createAnnotatorsParams() {
var existingAnnotatorsParameters = user.getPreferences().getAnnotatorsParameters();
Functions.removeChildren(annotatorsParams);
for (var i = 0; i < annotators.length; i++) {
var annotator = annotators[i];
for (var j = 0; j < selectedAnnotators.length; j++) {
if (annotator.getName() === selectedAnnotators[j]) {
var paramsDefs = annotator.getParametersDefinitions();
if (paramsDefs.length > 0) {
annotatorsParams.appendChild(Functions.createElement({
type: "div",
className: "minerva-annotators-params-header",
content: '<div>Available parameters</div>'
}));
var annotatorParams = Functions.createElement({
type: "div",
className: "minerva-annotator-params",
name: annotator.getClassName()
});
annotatorParams.appendChild(Functions.createElement({
type: "div",
className: "minerva-annotator-params-header",
content: annotator.getName()
}));
for (var k = 0; k < paramsDefs.length; k++) {
var param = paramsDefs[k];
var paramElement = Functions.createElement({
type: "div",
className: "minerva-annotator-param"
});
var paramName = Functions.createElement({
type: "div",
className: "minerva-annotator-param-name",
content: param.name
});
var tooltipContainer = Functions.createElement({
type: "span"
});
tooltipContainer.appendChild(Functions.createElement({
type: "span",
className: "glyphicon glyphicon-question-sign tooltip-icon"
}));
tooltipContainer.appendChild(Functions.createElement({
type: "span",
className: "annotator-tooltip",
content: param.description
}));
paramName.appendChild(tooltipContainer);
paramElement.appendChild(paramName);
var paramValue;
var existingParamValue;
if (existingAnnotatorsParameters[annotator.getClassName()]) {
existingParamValue = existingAnnotatorsParameters[annotator.getClassName()][param.name]
}
if (param.type.indexOf("String") >= 0) {
paramValue = Functions.createElement({
type: "textarea",
onchange: function () {
return onChangeParameterValue(this, user);
}
});
if (existingParamValue) paramValue.value = existingParamValue;
} else if (param.type.indexOf("Integer") >= 0) {
paramValue = Functions.createElement({
type: "input",
inputType: "number",
onchange: function () {
return onChangeParameterValue(this, user);
}
});
if (existingParamValue) paramValue.value = existingParamValue;
} else if (param.type.indexOf("Boolean") >= 0) {
paramValue = Functions.createElement({
type: "input",
inputType: "checkbox",
onchange: function () {
return onChangeParameterValue(this, user);
}
});
paramValue.checked = (existingParamValue && existingParamValue === 'true');
} else {
throw new Error("Unknown annotator parameter type");
}
paramElement.appendChild(paramValue);
annotatorParams.appendChild(paramElement);
}
annotatorsParams.appendChild(annotatorParams);
}
}
}
}
//
// var existingAnnotatorsParameters = user.getPreferences().getAnnotatorsParameters();
//
// Functions.removeChildren(annotatorsParams);
// for (var i = 0; i < annotators.length; i++) {
// var annotator = annotators[i];
// for (var j = 0; j < selectedAnnotators.length; j++) {
// if (annotator.getName() === selectedAnnotators[j]) {
// var paramsDefs = annotator.getParametersDefinitions();
// if (paramsDefs.length > 0) {
//
// annotatorsParams.appendChild(Functions.createElement({
// type: "div",
// className: "minerva-annotators-params-header",
// content: '<div>Available parameters</div>'
// }));
//
// var annotatorParams = Functions.createElement({
// type: "div",
// className: "minerva-annotator-params",
// name: annotator.getClassName()
// });
//
// annotatorParams.appendChild(Functions.createElement({
// type: "div",
// className: "minerva-annotator-params-header",
// content: annotator.getName()
// }));
//
// for (var k = 0; k < paramsDefs.length; k++) {
// var param = paramsDefs[k];
// var paramElement = Functions.createElement({
// type: "div",
// className: "minerva-annotator-param"
// });
//
// var paramName = Functions.createElement({
// type: "div",
// className: "minerva-annotator-param-name",
// content: param.name
// });
//
// var tooltipContainer = Functions.createElement({
// type: "span"
// });
// tooltipContainer.appendChild(Functions.createElement({
// type: "span",
// className: "glyphicon glyphicon-question-sign tooltip-icon"
// }));
// tooltipContainer.appendChild(Functions.createElement({
// type: "span",
// className: "annotator-tooltip",
// content: param.description
// }));
//
// paramName.appendChild(tooltipContainer);
// paramElement.appendChild(paramName);
//
// var paramValue;
//
// var existingParamValue;
// if (existingAnnotatorsParameters[annotator.getClassName()]) {
// existingParamValue = existingAnnotatorsParameters[annotator.getClassName()][param.name]
// }
//
// if (param.type.indexOf("String") >= 0) {
// paramValue = Functions.createElement({
// type: "textarea",
// onchange: function () {
// return onChangeParameterValue(this, user);
// }
// });
// if (existingParamValue) paramValue.value = existingParamValue;
// } else if (param.type.indexOf("Integer") >= 0) {
// paramValue = Functions.createElement({
// type: "input",
// inputType: "number",
// onchange: function () {
// return onChangeParameterValue(this, user);
// }
// });
// if (existingParamValue) paramValue.value = existingParamValue;
// } else if (param.type.indexOf("Boolean") >= 0) {
// paramValue = Functions.createElement({
// type: "input",
// inputType: "checkbox",
// onchange: function () {
// return onChangeParameterValue(this, user);
// }
// });
// paramValue.checked = (existingParamValue && existingParamValue === 'true');
// } else {
// throw new Error("Unknown annotator parameter type");
// }
//
// paramElement.appendChild(paramValue);
// annotatorParams.appendChild(paramElement);
// }
//
// annotatorsParams.appendChild(annotatorParams);
// }
// }
// }
// }
}
createAnnotatorsParams();
......
......@@ -2,7 +2,7 @@
/* exported logger */
var Article = require("./Article");
var AnnotatorParameter = require("./AnnotatorParameter");
var logger = require('../../logger');
......@@ -12,21 +12,21 @@ var logger = require('../../logger');
* @property {string[]} elementClassNames
* @property {string} name
* @property {string} description
* @property {AnnotatorParameterDefinition[]} parametersDefinitions
* @property {AnnotatorParameterDefinition[]} parameters
* @property {string} url
*/
/**
* @typedef {Object} AnnotatorParameterDefinition
* @property {string} description
* @property {string} name
* @property {string} type
* @typedef {Object} AnnotatorDataOptions
* @property {string} annotatorClass
* @property {number} order
* @property {AnnotatorParameterDefinition[]} parameters
*/
/**
*
* @param {Annotator|AnnotatorOptions} javaObject
* @param {Configuration} configuration
* @param {Annotator|AnnotatorOptions|AnnotatorDataOptions} javaObject
* @param {Configuration} [configuration]
* @constructor
*/
function Annotator(javaObject, configuration) {
......@@ -39,11 +39,15 @@ function Annotator(javaObject, configuration) {
self.setParametersDefinitions(javaObject.getParametersDefinitions());
self.setUrl(javaObject.getUrl());
} else {
self.setClassName(javaObject.className);
if (javaObject.className === undefined) {
self.setClassName(javaObject.annotatorClass);
} else {
self.setClassName(javaObject.className);
}
self.setElementTypes(javaObject.elementClassNames, configuration);
self.setName(javaObject.name);
self.setDescription(javaObject.description);
self.setParametersDefinitions(javaObject.parametersDefinitions);
self.setParametersDefinitions(javaObject.parameters);
self.setUrl(javaObject.url);
}
}
......@@ -125,7 +129,10 @@ Annotator.prototype.getParametersDefinitions = function () {
* @param {AnnotatorParameterDefinition[]} parametersDefinitions
*/
Annotator.prototype.setParametersDefinitions = function (parametersDefinitions) {
this._parametersDefinitions = parametersDefinitions;
this._parametersDefinitions = [];
for (var i = 0; i < parametersDefinitions.length; i++) {
this._parametersDefinitions.push(new AnnotatorParameter(parametersDefinitions[i]));
}
};
/**
......@@ -135,6 +142,9 @@ Annotator.prototype.setParametersDefinitions = function (parametersDefinitions)
*/
Annotator.prototype.setElementTypes = function (elementTypesClassNames, configuration) {
this._elementTypes = [];
if (elementTypesClassNames === undefined || elementTypesClassNames.length === 0) {
return;
}
var typeByClassName = {};
var types = configuration.getElementTypes();
var i, type;
......@@ -166,5 +176,21 @@ Annotator.prototype.getElementTypes = function () {
return this._elementTypes;
};
/**
*
* @return {Object}
*/
Annotator.prototype.toExport = function () {
var self = this;
var parameters = [];
for (var i = 0; i < this._parametersDefinitions.length; i++) {
parameters.push(this._parametersDefinitions[i].toExport());
}
return {
"annotatorClass": self.getClassName(),
"parameters": parameters
};
};
module.exports = Annotator;
"use strict";
/**
* @typedef {Object} AnnotatorParameterDefinition
* @property {string} type
* @property {number} order
* @property {string} [annotation_type]
* @property {string} [field]
* @property {string} [description]
* @property {string} [name]
* @property {string} [value]
*/
/**
*
* @param {AnnotatorParameter|AnnotatorParameterDefinition} javaObject
* @constructor
*/
function AnnotatorParameter(javaObject) {
var self = this;
if (javaObject instanceof AnnotatorParameter) {
self.setType(javaObject.getType());
self.setOrder(javaObject.getOrder());
self.setAnnotationType(javaObject.getAnnotationType());
self.setField(javaObject.getField());
self.setDescription(javaObject.getDescription());
self.setName(javaObject.getName());
self.setValue(javaObject.getValue());
} else {
self.setType(javaObject.type);
self.setOrder(javaObject.order);
self.setAnnotationType(javaObject.annotation_type);
self.setField(javaObject.field);
self.setDescription(javaObject.description);
self.setName(javaObject.name);
self.setValue(javaObject.value);
}
}
/**
*
* @returns {string}
*/
AnnotatorParameter.prototype.getType = function () {
return this._type;
};
/**
*
* @param {string} type
*/
AnnotatorParameter.prototype.setType = function (type) {
this._type = type;
};
/**
*
* @returns {number}
*/
AnnotatorParameter.prototype.getOrder = function () {
return this._order;
};
/**
*
* @param {number} order
*/
AnnotatorParameter.prototype.setOrder = function (order) {
this._order = order;
};
/**
*
* @returns {string}
*/
AnnotatorParameter.prototype.getName = function () {
return this._name;
};
/**
*
* @param {string} name