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

updating project data

parent 12ba8ee7
No related branches found
No related tags found
2 merge requests!115Resolve "admin panel should use API",!114Resolve "admin panel should use API"
...@@ -11,6 +11,7 @@ var request = require('request'); ...@@ -11,6 +11,7 @@ var request = require('request');
var HttpStatus = require('http-status-codes'); var HttpStatus = require('http-status-codes');
var Alias = require('./map/data/Alias'); var Alias = require('./map/data/Alias');
var Annotation = require('./map/data/Annotation');
var Chemical = require('./map/data/Chemical'); var Chemical = require('./map/data/Chemical');
var Comment = require('./map/data/Comment'); var Comment = require('./map/data/Comment');
var Configuration = require('./Configuration'); var Configuration = require('./Configuration');
...@@ -619,6 +620,49 @@ ServerConnector.getProject = function(projectId) { ...@@ -619,6 +620,49 @@ ServerConnector.getProject = function(projectId) {
}); });
}; };
ServerConnector.updateProject = function(project) {
var self = this;
var queryParams = {
projectId : project.getProjectId()
};
var filterParams = {
project : {
name : project.getName(),
version : project.getVersion(),
notifyEmail : project.getNotifyEmail(),
organism : self.serialize(project.getOrganism()),
disease : self.serialize(project.getDisease()),
},
};
return self.sendPatchRequest(self.getProjectUrl(queryParams), filterParams).then(function(content) {
var downloadedProject = new Project(content);
project.update(downloadedProject);
return project;
}).then(null, function(error) {
if ((error instanceof NetworkError)) {
switch (error.statusCode) {
case HttpStatus.FORBIDDEN:
return Promise.reject(new SecurityError("Access denied."));
default:
return Promise.reject(error);
}
} else {
return Promise.reject(error);
}
});
};
ServerConnector.serialize = function(object) {
var result = {};
if (object instanceof Annotation) {
result.type = object.getType();
result.resource = object.getResource();
} else {
throw new Error("Unhandled object type: " + (typeof object));
}
return result;
};
ServerConnector.getProjects = function(reload) { ServerConnector.getProjects = function(reload) {
var self = this; var self = this;
if (self._projects.length > 0 && !reload) { if (self._projects.length > 0 && !reload) {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
/* exported logger */ /* exported logger */
var AbstractGuiElement = require('../AbstractGuiElement'); var AbstractGuiElement = require('../AbstractGuiElement');
var Annotation = require('../../map/data/Annotation');
var GuiConnector = require('../../GuiConnector'); var GuiConnector = require('../../GuiConnector');
var Functions = require('../../functions'); var Functions = require('../../functions');
...@@ -125,7 +126,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function() { ...@@ -125,7 +126,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function() {
nameRow.appendChild(new Functions.createElement({ nameRow.appendChild(new Functions.createElement({
type : "div", type : "div",
style : "display:table-cell", style : "display:table-cell",
content : "<input value='" + project.getName() + "'/>", content : "<input name='projectName' value='" + project.getName() + "'/>",
})); }));
var versionRow = new Functions.createElement({ var versionRow = new Functions.createElement({
...@@ -141,7 +142,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function() { ...@@ -141,7 +142,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function() {
versionRow.appendChild(new Functions.createElement({ versionRow.appendChild(new Functions.createElement({
type : "div", type : "div",
style : "display:table-cell", style : "display:table-cell",
content : "<input value='" + project.getVersion() + "'/>", content : "<input name='projectVersion' value='" + project.getVersion() + "'/>",
})); }));
var diseaseRow = new Functions.createElement({ var diseaseRow = new Functions.createElement({
...@@ -161,7 +162,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function() { ...@@ -161,7 +162,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function() {
diseaseRow.appendChild(new Functions.createElement({ diseaseRow.appendChild(new Functions.createElement({
type : "div", type : "div",
style : "display:table-cell", style : "display:table-cell",
content : "<input value='" + disease + "'/>", content : "<input name='projectDisease' value='" + disease + "'/>",
})); }));
var organismRow = new Functions.createElement({ var organismRow = new Functions.createElement({
...@@ -181,7 +182,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function() { ...@@ -181,7 +182,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function() {
organismRow.appendChild(new Functions.createElement({ organismRow.appendChild(new Functions.createElement({
type : "div", type : "div",
style : "display:table-cell", style : "display:table-cell",
content : "<input value='" + organism + "'/>", content : "<input name='projectOrganism' value='" + organism + "'/>",
})); }));
var emailRow = new Functions.createElement({ var emailRow = new Functions.createElement({
...@@ -201,7 +202,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function() { ...@@ -201,7 +202,7 @@ EditProjectDialog.prototype.createGeneralTabContent = function() {
emailRow.appendChild(new Functions.createElement({ emailRow.appendChild(new Functions.createElement({
type : "div", type : "div",
style : "display:table-cell", style : "display:table-cell",
content : "<input value='" + email + "'/>", content : "<input name='projectNotifyEmail' value='" + email + "'/>",
})); }));
var menuRow = Functions.createElement({ var menuRow = Functions.createElement({
...@@ -216,7 +217,9 @@ EditProjectDialog.prototype.createGeneralTabContent = function() { ...@@ -216,7 +217,9 @@ EditProjectDialog.prototype.createGeneralTabContent = function() {
name : "saveProject", name : "saveProject",
content : '<span class="ui-icon ui-icon-disk"></span>&nbsp;SAVE', content : '<span class="ui-icon ui-icon-disk"></span>&nbsp;SAVE',
onclick : function() { onclick : function() {
return self.onSaveClicked().then(null, GuiConnector.alert); return self.onSaveClicked().then(function() {
return self.close();
}, GuiConnector.alert);
}, },
}); });
var cancelButton = Functions.createElement({ var cancelButton = Functions.createElement({
...@@ -289,6 +292,30 @@ EditProjectDialog.prototype.open = function() { ...@@ -289,6 +292,30 @@ EditProjectDialog.prototype.open = function() {
$(div).dialog("open"); $(div).dialog("open");
}; };
var prepareMiriamData = function(type, resource) {
if (resource === "" || resource === undefined || resource === null) {
return null;
} else {
return new Annotation({
type : type,
resource : resource
});
}
}
EditProjectDialog.prototype.onSaveClicked = function() {
var self = this;
var project = self.getProject();
var element = self.getElement();
project.setName($("[name='projectName']", element)[0].value);
project.setVersion($("[name='projectVersion']", element)[0].value);
project.setNotifyEmail($("[name='projectNotifyEmail']", element)[0].value);
var organism = prepareMiriamData("TAXONOMY", $("[name='projectOrganism']", element)[0].value);
project.setOrganism(organism);
var disease = prepareMiriamData("MESH_2012", $("[name='projectDisease']", element)[0].value);
project.setDisease(disease);
return ServerConnector.updateProject(project);
};
EditProjectDialog.prototype.close = function() { EditProjectDialog.prototype.close = function() {
$(this.getElement()).dialog("close"); $(this.getElement()).dialog("close");
}; };
......
...@@ -45,6 +45,21 @@ describe('ServerConnector', function() { ...@@ -45,6 +45,21 @@ describe('ServerConnector', function() {
}); });
}); });
describe('updateProject', function() {
it('default', function() {
var project;
var newVersion = "2.01";
return ServerConnector.getProject().then(function(result) {
project = result;
project.setVersion(newVersion);
return ServerConnector.updateProject(project);
}).then(function(result) {
assert.ok(project === result);
assert.equal(newVersion, result.getVersion());
});
});
});
it('getModels', function() { it('getModels', function() {
return ServerConnector.getModels("sample").then(function(models) { return ServerConnector.getModels("sample").then(function(models) {
assert.equal(1, models.length); assert.equal(1, models.length);
......
...@@ -26,4 +26,21 @@ describe('EditProjectDialog', function() { ...@@ -26,4 +26,21 @@ describe('EditProjectDialog', function() {
}); });
}); });
it('onSaveClicked', function() {
var dialog;
var project;
return ServerConnector.getProject().then(function(result) {
project = result;
project.setVersion("2.01");
dialog = new EditProjectDialog({
element : testDiv,
project : project,
customMap : null,
});
return dialog.onSaveClicked();
}).then(function(result) {
assert.ok(project === result);
});
});
}); });
{"version":"2.01","disease":{"resource":"D010300","link":"http://bioportal.bioontology.org/ontologies/1351?p=terms&conceptid=D010300","id":1104479,"type":"MESH_2012"},"organism":{"resource":"1570291","link":"http://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=1570291","id":1104480,"type":"TAXONOMY"},"idObject":14898,"status":"Ok","progress":100.0,"name":"UNKNOWN DISEASE MAP","projectId":"sample","overviewImageViews":[],"topOverviewImage":null}
\ No newline at end of file
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