Commit 8709e869 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

modifying and removing overlays

parent 754b1808
...@@ -119,6 +119,34 @@ ServerConnector.sendPostRequest = function(url, params) { ...@@ -119,6 +119,34 @@ ServerConnector.sendPostRequest = function(url, params) {
}); });
}; };
ServerConnector.sendPutRequest = function(url, params) {
return new Promise(function(resolve, reject) {
request.put({url:url, form:params}, function(error, response, body) {
if (error) {
reject(error);
} else if (response.statusCode !== 200) {
reject(response);
} else {
resolve(body);
}
});
});
};
ServerConnector.sendDeleteRequest = function(url, params) {
return new Promise(function(resolve, reject) {
request.del({url:url, form:params}, function(error, response, body) {
if (error) {
reject(error);
} else if (response.statusCode !== 200) {
reject(response);
} else {
resolve(body);
}
});
});
};
ServerConnector.getToken = function() { ServerConnector.getToken = function() {
var self = this; var self = this;
return new Promise(function(resolve) { return new Promise(function(resolve) {
...@@ -202,6 +230,24 @@ ServerConnector.addCommentUrl = function() { ...@@ -202,6 +230,24 @@ ServerConnector.addCommentUrl = function() {
}); });
}; };
ServerConnector.addOverlayUrl = function() {
return this.getApiUrl({type:"overlay",
method: "addOverlay",
});
};
ServerConnector.updateOverlayUrl = function() {
return this.getApiUrl({type:"overlay",
method: "updateOverlay",
});
};
ServerConnector.deleteOverlayUrl = function() {
return this.getApiUrl({type:"overlay",
method: "removeOverlay",
});
};
ServerConnector.getOverlaysUrl = function(projectId, token) { ServerConnector.getOverlaysUrl = function(projectId, token) {
return this.getApiUrl({type:"overlay", return this.getApiUrl({type:"overlay",
method: "getOverlayList", method: "getOverlayList",
...@@ -948,6 +994,72 @@ ServerConnector.addComment = function(params) { ...@@ -948,6 +994,72 @@ ServerConnector.addComment = function(params) {
}); });
}; };
ServerConnector.addOverlay= function(params) {
var self = this;
return new Promise(function(resolve, reject) {
return self.getProjectId(params.projectId).then(function(result) {
params.projectId = result;
return self.getToken();
}).then(function(token) {
params.token = token;
return self.sendPostRequest(self.addOverlayUrl(),params);
}).then(function(content) {
var response=JSON.parse(content);
if (response.status==="OK") {
resolve(response.overlayId);
} else {
reject(response);
}
}).catch(function(exception){
reject(exception);
});
});
};
ServerConnector.updateOverlay= function(params) {
var self = this;
return new Promise(function(resolve, reject) {
return self.getProjectId(params.projectId).then(function(result) {
params.projectId = result;
return self.getToken();
}).then(function(token) {
params.token = token;
return self.sendPostRequest(self.updateOverlayUrl(),params);
}).then(function(content) {
var response=JSON.parse(content);
if (response.status==="OK") {
resolve();
} else {
reject(response.reason);
}
}).catch(function(exception){
reject(exception);
});
});
};
ServerConnector.removeOverlay= function(params) {
var self = this;
return new Promise(function(resolve, reject) {
return self.getProjectId(params.projectId).then(function(result) {
params.projectId = result;
return self.getToken();
}).then(function(token) {
params.token = token;
return self.sendPostRequest(self.deleteOverlayUrl(),params);
}).then(function(content) {
var response=JSON.parse(content);
if (response.status==="OK") {
resolve();
} else {
reject(response);
}
}).catch(function(exception){
reject(exception);
});
});
};
ServerConnector.getSuggestedQueryList = function(projectId) { ServerConnector.getSuggestedQueryList = function(projectId) {
var self = this; var self = this;
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
var Panel = require('./Panel'); var Panel = require('./Panel');
var GuiConnector = require('../GuiConnector');
var logger = require('../logger'); var logger = require('../logger');
function OverlayPanel(params) { function OverlayPanel(params) {
...@@ -127,7 +128,7 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) { ...@@ -127,7 +128,7 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
overlayId : overlay.getId() overlayId : overlay.getId()
}).then(function(url) { }).then(function(url) {
return self.downloadFile(url); return self.downloadFile(url);
}); }).catch(GuiConnector.alert);
}; };
button.innerHTML = "<span class='ui-icon ui-icon-arrowthickstop-1-s'></span>"; button.innerHTML = "<span class='ui-icon ui-icon-arrowthickstop-1-s'></span>";
dataTd.appendChild(button); dataTd.appendChild(button);
...@@ -138,12 +139,9 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) { ...@@ -138,12 +139,9 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
if (overlay.getCreator() !== "" && overlay.getCreator() !== undefined) { if (overlay.getCreator() !== "" && overlay.getCreator() !== undefined) {
var editTd = document.createElement("td"); var editTd = document.createElement("td");
var editButton = document.createElement("button"); var editButton = document.createElement("button");
editButton.setAttribute("name", "editButton");
editButton.onclick = function() { editButton.onclick = function() {
var content = document.createElement("div"); self.openEditOverlayDialog(overlay);
content.innerHTML = "test";
self.openDialog(content, {
id : overlay.getId()
});
}; };
editButton.innerHTML = "<span class='ui-icon ui-icon-document'></span>"; editButton.innerHTML = "<span class='ui-icon ui-icon-document'></span>";
editTd.appendChild(editButton); editTd.appendChild(editButton);
...@@ -152,6 +150,57 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) { ...@@ -152,6 +150,57 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
return result; return result;
}; };
OverlayPanel.prototype.openEditOverlayDialog = function(overlay) {
var self = this;
var content = document.createElement("fieldset");
content.appendChild(self.createLabel("Name"));
var nameInput = self.createInputText(overlay.getName());
content.appendChild(nameInput);
content.appendChild(self.createLabel("Description"));
var descriptionInput = self.createTextArea(overlay.getDescription());
content.appendChild(descriptionInput);
var buttons = [ {
text : "SAVE",
click : function() {
var windowSelf = this;
return ServerConnector.updateOverlay({
overlayId : overlay.id,
name : nameInput.value,
description : descriptionInput.value
}).then(function() {
return self.refresh();
}).then(function() {
$(windowSelf).dialog("close");
}).catch(GuiConnector.alert);
}
}, {
text : "REMOVE",
click : function() {
self.getMap().removeSelectedLayout(overlay.getId());
var windowSelf = this;
return ServerConnector.removeOverlay({
overlayId : overlay.getId()
}).then(function() {
return self.refresh();
}).then(function() {
$(windowSelf).dialog("close");
}).catch(GuiConnector.alert);
}
}, {
text : "CANCEL",
click : function() {
$(this).dialog("close");
}
} ];
self.openDialog(content, {
id : overlay.getId(),
buttons : buttons,
});
};
OverlayPanel.prototype.refresh = function() { OverlayPanel.prototype.refresh = function() {
var self = this; var self = this;
var user = null; var user = null;
......
...@@ -202,6 +202,26 @@ Panel.prototype.createLabelText = function(value) { ...@@ -202,6 +202,26 @@ Panel.prototype.createLabelText = function(value) {
return result; return result;
}; };
Panel.prototype.createInputText = function(value) {
var result = document.createElement("input");
result.setAttribute('type', 'text');
if (value !== undefined) {
result.setAttribute('value', value);
}
return result;
};
Panel.prototype.createTextArea = function(value) {
var result = document.createElement("textarea");
if (value !== undefined) {
result.setAttribute('value', value);
result.innerHTML = value;
}
return result;
};
Panel.prototype.createParamLine = function(label, value) { Panel.prototype.createParamLine = function(label, value) {
var result = document.createElement("div"); var result = document.createElement("div");
if (value !== undefined) { if (value !== undefined) {
...@@ -283,7 +303,7 @@ Panel.prototype.getDialogDiv = function(id) { ...@@ -283,7 +303,7 @@ Panel.prototype.getDialogDiv = function(id) {
dialogs = document.createElement("div"); dialogs = document.createElement("div");
dialogs.setAttribute("name", "dialogs"); dialogs.setAttribute("name", "dialogs");
this.getElement().appendChild(dialogs); this.getElement().appendChild(dialogs);
this._dialogs = []; this._dialogs = [];
} }
...@@ -299,8 +319,8 @@ Panel.prototype.getDialogDiv = function(id) { ...@@ -299,8 +319,8 @@ Panel.prototype.getDialogDiv = function(id) {
dialogDiv.appendChild(contentDiv); dialogDiv.appendChild(contentDiv);
dialogs.appendChild(dialogDiv); dialogs.appendChild(dialogDiv);
this._dialogs[id]=dialogDiv; this._dialogs[id] = dialogDiv;
} }
return dialogDiv; return dialogDiv;
}; };
...@@ -313,6 +333,8 @@ Panel.prototype.assignDialogOptions = function(div, params) { ...@@ -313,6 +333,8 @@ Panel.prototype.assignDialogOptions = function(div, params) {
div.setAttribute("name", "dialog-" + params[key]); div.setAttribute("name", "dialog-" + params[key]);
} else if (key === "modal") { } else if (key === "modal") {
dialog.dialog('option', 'modal', params[key]); dialog.dialog('option', 'modal', params[key]);
} else if (key === "buttons") {
dialog.dialog('option', 'buttons', params[key]);
} else { } else {
throw new Error("Unknown dialog param: " + key + " - " + params[key]); throw new Error("Unknown dialog param: " + key + " - " + params[key]);
} }
...@@ -331,16 +353,16 @@ Panel.prototype.openDialog = function(content, options) { ...@@ -331,16 +353,16 @@ Panel.prototype.openDialog = function(content, options) {
var div = this.getDialogDiv(options.id); var div = this.getDialogDiv(options.id);
this.assignDialogOptions(div, options);
var contentDiv = this.getElementByName(div, "content"); var contentDiv = this.getElementByName(div, "content");
while (contentDiv.hasChildNodes()) { while (contentDiv.hasChildNodes()) {
contentDiv.removeChild(contentDiv.lastChild); contentDiv.removeChild(contentDiv.lastChild);
} }
contentDiv.appendChild(content); contentDiv.appendChild(content);
$(div).dialog(); $(div).dialog();
this.assignDialogOptions(div, options);
$(div).dialog("open"); $(div).dialog("open");
}; };
......
...@@ -20,6 +20,7 @@ function LayoutData(layoutId, name) { ...@@ -20,6 +20,7 @@ function LayoutData(layoutId, name) {
this.setId(object.idObject); this.setId(object.idObject);
this.setName(object.name); this.setName(object.name);
this.setDirectory(object.directory); this.setDirectory(object.directory);
this.setDescription(object.description);
this.setCreator(object.creator); this.setCreator(object.creator);
this.setInputDataAvailable(object.inputDataAvailable); this.setInputDataAvailable(object.inputDataAvailable);
} else { } else {
...@@ -61,6 +62,14 @@ LayoutData.prototype.setId = function(id) { ...@@ -61,6 +62,14 @@ LayoutData.prototype.setId = function(id) {
this.id = parseInt(id); this.id = parseInt(id);
}; };
LayoutData.prototype.getDescription = function() {
return this._description;
};
LayoutData.prototype.setDescription = function(description) {
this._description = description;
};
LayoutData.prototype.getCreator = function() { LayoutData.prototype.getCreator = function() {
return this._creator; return this._creator;
}; };
......
...@@ -243,7 +243,7 @@ function create(params) { ...@@ -243,7 +243,7 @@ function create(params) {
var minerva = { var minerva = {
create : create, create : create,
ServerConnector : OriginalServerConnector, ServerConnector : OriginalServerConnector,
GuiConnector : OriginalGuiConnector GuiConnector : OriginalGuiConnector,
}; };
module.exports = minerva; module.exports = minerva;
...@@ -14,12 +14,11 @@ var ServerConnectorMock = OriginalServerConnector; ...@@ -14,12 +14,11 @@ var ServerConnectorMock = OriginalServerConnector;
ServerConnectorMock.init = function() { ServerConnectorMock.init = function() {
this._customMap = null; this._customMap = null;
this._sessionData = undefined; this._sessionData = undefined;
// add listener types // add listener types
}; };
ServerConnectorMock.init(); ServerConnectorMock.init();
ServerConnectorMock.getMaxOverlayColorInt = function() { ServerConnectorMock.getMaxOverlayColorInt = function() {
return 0xFF0000; return 0xFF0000;
}; };
...@@ -52,11 +51,84 @@ ServerConnectorMock.readFile = function(url) { ...@@ -52,11 +51,84 @@ ServerConnectorMock.readFile = function(url) {
}); });
}; };
function encodeParams(params) {
var result = {};
for ( var key in params) {
if (params.hasOwnProperty(key)) {
result[key] = encodeURIComponent(params[key]);
}
}
return result;
}
ServerConnectorMock.sendPostRequest = function(url, params) { ServerConnectorMock.sendPostRequest = function(url, params) {
var self = this; var self = this;
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
if (url.indexOf("http") === 0) { if (url.indexOf("http") === 0) {
request.post({url:url, form:params}, function(error, response, body) { request.post({
url : url,
form : params
}, function(error, response, body) {
if (error) {
reject(error);
} else if (response.statusCode !== 200) {
reject(response);
} else {
resolve(body);
}
});
} else {
var mockUrl = url + "/" + self.createGetParams(encodeParams(params));
fs.readFile(mockUrl, 'utf8', function(err, content) {
if (err) {
reject(err);
} else {
resolve(content);
}
});
}
});
};
ServerConnectorMock.sendPutRequest = function(url, params) {
var self = this;
return new Promise(function(resolve, reject) {
if (url.indexOf("http") === 0) {
request.put({
url : url,
form : params
}, function(error, response, body) {
if (error) {
reject(error);
} else if (response.statusCode !== 200) {
reject(response);
} else {
resolve(body);
}
});
} else {
var mockUrl = url + "/" + self.createGetParams(encodeParams(params));
fs.readFile(mockUrl, 'utf8', function(err, content) {
if (err) {
reject(err);
} else {
resolve(content);
}
});
}
});
};
ServerConnectorMock.sendDeleteRequest = function(url, params) {
var self = this;
return new Promise(function(resolve, reject) {
if (url.indexOf("http") === 0) {
request.delete({
url : url,
form : params
}, function(error, response, body) {
if (error) { if (error) {
reject(error); reject(error);
...@@ -67,7 +139,7 @@ ServerConnectorMock.sendPostRequest = function(url, params) { ...@@ -67,7 +139,7 @@ ServerConnectorMock.sendPostRequest = function(url, params) {
} }
}); });
} else { } else {
var mockUrl = url+"/"+self.createGetParams(params); var mockUrl = url + "/" + self.createGetParams(encodeParams(params));
fs.readFile(mockUrl, 'utf8', function(err, content) { fs.readFile(mockUrl, 'utf8', function(err, content) {
if (err) { if (err) {
reject(err); reject(err);
...@@ -86,8 +158,8 @@ ServerConnectorMock.getApiBaseUrl = function() { ...@@ -86,8 +158,8 @@ ServerConnectorMock.getApiBaseUrl = function() {
var originalGetApiUrl = OriginalServerConnector.getApiUrl; var originalGetApiUrl = OriginalServerConnector.getApiUrl;
ServerConnectorMock.getApiUrl = function(paramObj) { ServerConnectorMock.getApiUrl = function(paramObj) {
//replace '?' with '/' // replace '?' with '/'
//the call is done on ServerConnectorObject (so 'this' is set properly) // the call is done on ServerConnectorObject (so 'this' is set properly)
return originalGetApiUrl.call(this, paramObj).replace(/\?/g, '/'); return originalGetApiUrl.call(this, paramObj).replace(/\?/g, '/');
}; };
......
...@@ -22,7 +22,7 @@ describe('ServerConnector', function() { ...@@ -22,7 +22,7 @@ describe('ServerConnector', function() {
}); });
it('getProjectId from GET params', function() { it('getProjectId from GET params', function() {
GuiConnector.getParams['id']="test"; GuiConnector.getParams['id'] = "test";
return ServerConnector.getProjectId().then(function(result) { return ServerConnector.getProjectId().then(function(result) {
assert.equal(result, "test"); assert.equal(result, "test");
}); });
...@@ -77,9 +77,36 @@ describe('ServerConnector', function() { ...@@ -77,9 +77,36 @@ describe('ServerConnector', function() {
it('getOverlaySourceDownloadUrl', function() { it('getOverlaySourceDownloadUrl', function() {
var id = 123; var id = 123;
return ServerConnector.getOverlaySourceDownloadUrl({overlayId:id}).then(function(url){ return ServerConnector.getOverlaySourceDownloadUrl({
overlayId : id
}).then(function(url) {
assert.ok(url); assert.ok(url);
assert.ok(url.indexOf(id)>=0); assert.ok(url.indexOf(id) >= 0);
});
});
it('addOverlay', function() {
return ServerConnector.addOverlay({
name : "test nam",
description : "test desc",
content : "name color\nCAPN1 #00FF00\nPARK7 #AC0000\nL-cysteine #0000AC\nglutathione #005050\n",
filename : "test.txt"
}).then(function(overlayId) {
assert.ok(overlayId);