Skip to content
Snippets Groups Projects
Commit d7b583a3 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

user preferences are processed on client side

parent 6a54f19f
No related branches found
No related tags found
2 merge requests!115Resolve "admin panel should use API",!114Resolve "admin panel should use API"
<component name="ProjectDictionaryState">
<dictionary name="piotr.gawron">
<words>
<w>mailto</w>
</words>
</dictionary>
</component>
\ No newline at end of file
"use strict";
/* exported logger */
var logger = require('../../logger');
function UserPreferences(javaObject) {
if (javaObject !== undefined) {
this.setProjectUpload(javaObject["project-upload"]);
this.setElementAnnotators(javaObject["element-annotators"]);
this.setElementRequiredAnnotations(javaObject["element-required-annotations"]);
this.setElementValidAnnotations(javaObject["element-valid-annotations"]);
} else {
this._projectUpload = {};
this._elementAnnotators = {};
this._elementRequiredAnnotations = {};
this._elementValidAnnotations = {};
}
}
UserPreferences.prototype.setProjectUpload = function (projectUpload) {
this._projectUpload = {
autoResize: projectUpload["auto-resize"],
validateMiriam: projectUpload["validate-miriam"],
annotateModel: projectUpload["annotate-model"],
cacheData: projectUpload["cache-data"],
semanticZooming: projectUpload["semantic-zooming"],
sbgn: projectUpload["sbgn"]
};
};
UserPreferences.prototype.getProjectUpload = function () {
return this._projectUpload;
};
UserPreferences.prototype.setElementAnnotators = function (elementAnnotators) {
this._elementAnnotators = elementAnnotators;
};
UserPreferences.prototype.getElementAnnotators = function (className) {
return this._elementAnnotators[className];
};
UserPreferences.prototype.setElementRequiredAnnotations = function (elementRequiredAnnotations) {
this._elementRequiredAnnotations = {};
for (var key in elementRequiredAnnotations) {
if (elementRequiredAnnotations.hasOwnProperty(key)) {
var data = elementRequiredAnnotations[key];
this._elementRequiredAnnotations[key] = {
requiredAtLeastOnce: data["require-at-least-one"],
list: data["annotation-list"]
};
}
}
};
UserPreferences.prototype.getElementRequiredAnnotations = function (className) {
return this._elementRequiredAnnotations[className];
};
UserPreferences.prototype.setElementValidAnnotations = function (elementValidAnnotations) {
this._elementValidAnnotations = elementValidAnnotations;
};
UserPreferences.prototype.getElementValidAnnotations = function (className) {
return this._elementValidAnnotations[className];
};
module.exports = UserPreferences;
......@@ -25,6 +25,7 @@ var SearchDbOverlay = require("../../main/js/map/overlay/SearchDbOverlay");
var User = require("../../main/js/map/data/User");
var Cookies = require('js-cookie');
var fs = require('fs');
var GuiConnector = require('../../main/js/GuiConnector');
......@@ -37,10 +38,10 @@ function Helper(configuration) {
this.EPSILON = Helper.EPSILON;
}
Helper.prototype.setConfiguration = function (configuration) {
Helper.prototype.setConfiguration = function(configuration) {
this._configuration = configuration;
};
Helper.prototype.getConfiguration = function () {
Helper.prototype.getConfiguration = function() {
return this._configuration;
};
......@@ -143,7 +144,7 @@ Helper.prototype.createComment = function (element) {
return result;
};
Helper.prototype.createProject = function() {
Helper.prototype.createProject = function () {
var result = new Project();
result.setProjectId("testId");
result.setId(this.idCounter++);
......@@ -151,17 +152,17 @@ Helper.prototype.createProject = function() {
return result;
};
Helper.prototype.createUser = function() {
Helper.prototype.createUser = function () {
var result = new User({
login : "test_login",
id : this.idCounter++,
name : "some name",
surname : "surname",
login: "test_login",
id: this.idCounter++,
name: "some name",
surname: "surname",
});
return result;
};
Helper.prototype.createAlias = function(map) {
Helper.prototype.createAlias = function (map) {
var mapId;
if (map === undefined) {
mapId = this.idCounter++;
......@@ -169,15 +170,15 @@ Helper.prototype.createAlias = function(map) {
mapId = map.getId();
}
var result = new Alias({
idObject : this.idCounter++,
name : "Test element",
type : "RNA",
modelId : mapId,
bounds : {
x : 10.0,
y : 20.0,
width : 30.0,
height : 40.0,
idObject: this.idCounter++,
name: "Test element",
type: "RNA",
modelId: mapId,
bounds: {
x: 10.0,
y: 20.0,
width: 30.0,
height: 40.0,
},
references: [],
});
......@@ -198,10 +199,10 @@ Helper.prototype.createLayoutAlias = function (alias) {
modelId = this.idCounter++;
}
var result = new LayoutAlias({
idObject : id,
value : 0.2,
color : {
a : 23
idObject: id,
value: 0.2,
color: {
a: 23
},
modelId: modelId,
geneVariations: [{}]
......@@ -386,6 +387,18 @@ Helper.prototype.setUrl = function (url) {
GuiConnector.init();
};
Helper.prototype.readFile = function (filename) {
return new Promise(function (resolve, reject) {
fs.readFile(filename, 'utf8', function (err, content) {
if (err) {
reject(err);
} else {
resolve(content);
}
});
});
};
Helper.EPSILON = 1e-6;
module.exports = Helper;
"use strict";
require("../../mocha-config")
/* exported logger */
var UserPreferences = require('../../../../main/js/map/data/UserPreferences');
var logger = require('../../logger');
var chai = require('chai');
var assert = chai.assert;
var fs = require('fs');
var Promise = require('fs');
describe('UserPreferences', function () {
it("constructor", function () {
return helper.readFile("testFiles/preferences.json").then(function (content) {
var object = new UserPreferences(JSON.parse(content));
assert.ok(object);
assert.notOk(object.getProjectUpload().autoResize);
assert.ok(object.getProjectUpload().cacheData);
assert.ok(object.getElementAnnotators("lcsb.mapviewer.model.map.species.Protein").length > 0);
assert.ok(object.getElementValidAnnotations("lcsb.mapviewer.model.map.species.Protein").length > 0);
assert.ok(object.getElementRequiredAnnotations("lcsb.mapviewer.model.map.species.Protein").requiredAtLeastOnce);
assert.ok(object.getElementRequiredAnnotations("lcsb.mapviewer.model.map.species.Protein").list.length > 0);
})
});
});
This diff is collapsed.
......@@ -4,3 +4,10 @@ alter table user_annotation_schema_table add column autoresizemap boolean defaul
alter table user_annotation_schema_table add column cachedata boolean default true;
alter table user_annotation_schema_table add column semanticzooming boolean default false;
alter table class_required_annotation_table RENAME column requireatlestoneannotation to requireatleastoneannotation;
-- rename config annotation class name
update class_annotator_table set classname ='lcsb.mapviewer.model.map.BioEntity' where classname ='lcsb.mapviewer.model.map.AnnotatedObject';
update class_required_annotation_table set classname ='lcsb.mapviewer.model.map.BioEntity' where classname ='lcsb.mapviewer.model.map.AnnotatedObject';
update class_valid_annotation_table set classname ='lcsb.mapviewer.model.map.BioEntity' where classname ='lcsb.mapviewer.model.map.AnnotatedObject';
......@@ -128,7 +128,7 @@ public class UserRestImpl extends BaseRestImpl {
private Map<String, Object> prepareValidAnnotations(List<UserClassValidAnnotations> classValidAnnotators) {
Map<String, Object> result = new HashMap<>();
for (UserClassValidAnnotations userClassAnnotators : classValidAnnotators) {
result.put(userClassAnnotators.getClassName(), userClassAnnotators.getValidMiriamTypes());
result.put(userClassAnnotators.getClassName(), new ArrayList<>(userClassAnnotators.getValidMiriamTypes()));
}
return result;
}
......@@ -158,7 +158,12 @@ public class UserRestImpl extends BaseRestImpl {
for (UserClassRequiredAnnotations requiredAnnotations : classRequiredAnnotators) {
Map<String, Object> row = new HashMap<>();
row.put("require-at-least-one", requiredAnnotations.getRequireAtLeastOneAnnotation());
row.put("annotation-list", requiredAnnotations.getRequiredMiriamTypes());
List<String> miriamTypes = new ArrayList<>();
for (MiriamType mt : requiredAnnotations.getRequiredMiriamTypes()) {
miriamTypes.add(mt.name());
}
row.put("annotation-list", miriamTypes);
result.put(requiredAnnotations.getClassName(), row);
}
return result;
......@@ -200,7 +205,7 @@ public class UserRestImpl extends BaseRestImpl {
private Map<String, Object> prepareElementAnnotators(List<UserClassAnnotators> classAnnotators) {
Map<String, Object> result = new HashMap<>();
for (UserClassAnnotators userClassAnnotators : classAnnotators) {
result.put(userClassAnnotators.getClassName(), userClassAnnotators.getAnnotators());
result.put(userClassAnnotators.getClassName(), new ArrayList<>(userClassAnnotators.getAnnotators()));
}
return result;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment