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) {
});
};
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() {
var self = this;
return new Promise(function(resolve) {
......@@ -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) {
return this.getApiUrl({type:"overlay",
method: "getOverlayList",
......@@ -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) {
var self = this;
return new Promise(function(resolve, reject) {
......
......@@ -4,6 +4,7 @@
var Panel = require('./Panel');
var GuiConnector = require('../GuiConnector');
var logger = require('../logger');
function OverlayPanel(params) {
......@@ -127,7 +128,7 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
overlayId : overlay.getId()
}).then(function(url) {
return self.downloadFile(url);
});
}).catch(GuiConnector.alert);
};
button.innerHTML = "<span class='ui-icon ui-icon-arrowthickstop-1-s'></span>";
dataTd.appendChild(button);
......@@ -138,12 +139,9 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
if (overlay.getCreator() !== "" && overlay.getCreator() !== undefined) {
var editTd = document.createElement("td");
var editButton = document.createElement("button");
editButton.setAttribute("name", "editButton");
editButton.onclick = function() {
var content = document.createElement("div");
content.innerHTML = "test";
self.openDialog(content, {
id : overlay.getId()
});
self.openEditOverlayDialog(overlay);
};
editButton.innerHTML = "<span class='ui-icon ui-icon-document'></span>";
editTd.appendChild(editButton);
......@@ -152,6 +150,57 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
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() {
var self = this;
var user = null;
......
......@@ -202,6 +202,26 @@ Panel.prototype.createLabelText = function(value) {
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) {
var result = document.createElement("div");
if (value !== undefined) {
......@@ -283,7 +303,7 @@ Panel.prototype.getDialogDiv = function(id) {
dialogs = document.createElement("div");
dialogs.setAttribute("name", "dialogs");
this.getElement().appendChild(dialogs);
this._dialogs = [];
}
......@@ -299,8 +319,8 @@ Panel.prototype.getDialogDiv = function(id) {
dialogDiv.appendChild(contentDiv);
dialogs.appendChild(dialogDiv);
this._dialogs[id]=dialogDiv;
this._dialogs[id] = dialogDiv;
}
return dialogDiv;
};
......@@ -313,6 +333,8 @@ Panel.prototype.assignDialogOptions = function(div, params) {
div.setAttribute("name", "dialog-" + params[key]);
} else if (key === "modal") {
dialog.dialog('option', 'modal', params[key]);
} else if (key === "buttons") {
dialog.dialog('option', 'buttons', params[key]);
} else {
throw new Error("Unknown dialog param: " + key + " - " + params[key]);
}
......@@ -331,16 +353,16 @@ Panel.prototype.openDialog = function(content, options) {
var div = this.getDialogDiv(options.id);
this.assignDialogOptions(div, options);
var contentDiv = this.getElementByName(div, "content");
while (contentDiv.hasChildNodes()) {
contentDiv.removeChild(contentDiv.lastChild);
}
contentDiv.appendChild(content);
$(div).dialog();
this.assignDialogOptions(div, options);
$(div).dialog("open");
};
......
......@@ -20,6 +20,7 @@ function LayoutData(layoutId, name) {
this.setId(object.idObject);
this.setName(object.name);
this.setDirectory(object.directory);
this.setDescription(object.description);
this.setCreator(object.creator);
this.setInputDataAvailable(object.inputDataAvailable);
} else {
......@@ -61,6 +62,14 @@ LayoutData.prototype.setId = function(id) {
this.id = parseInt(id);
};
LayoutData.prototype.getDescription = function() {
return this._description;
};
LayoutData.prototype.setDescription = function(description) {
this._description = description;
};
LayoutData.prototype.getCreator = function() {
return this._creator;
};
......
......@@ -243,7 +243,7 @@ function create(params) {
var minerva = {
create : create,
ServerConnector : OriginalServerConnector,
GuiConnector : OriginalGuiConnector
GuiConnector : OriginalGuiConnector,
};
module.exports = minerva;
......@@ -14,12 +14,11 @@ var ServerConnectorMock = OriginalServerConnector;
ServerConnectorMock.init = function() {
this._customMap = null;
this._sessionData = undefined;
// add listener types
};
ServerConnectorMock.init();
ServerConnectorMock.getMaxOverlayColorInt = function() {
return 0xFF0000;
};
......@@ -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) {
var self = this;
return new Promise(function(resolve, reject) {
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) {
reject(error);
......@@ -67,7 +139,7 @@ ServerConnectorMock.sendPostRequest = function(url, params) {
}
});
} else {
var mockUrl = url+"/"+self.createGetParams(params);
var mockUrl = url + "/" + self.createGetParams(encodeParams(params));
fs.readFile(mockUrl, 'utf8', function(err, content) {
if (err) {
reject(err);
......@@ -86,8 +158,8 @@ ServerConnectorMock.getApiBaseUrl = function() {
var originalGetApiUrl = OriginalServerConnector.getApiUrl;
ServerConnectorMock.getApiUrl = function(paramObj) {
//replace '?' with '/'
//the call is done on ServerConnectorObject (so 'this' is set properly)
// replace '?' with '/'
// the call is done on ServerConnectorObject (so 'this' is set properly)
return originalGetApiUrl.call(this, paramObj).replace(/\?/g, '/');
};
......
......@@ -22,7 +22,7 @@ describe('ServerConnector', function() {
});
it('getProjectId from GET params', function() {
GuiConnector.getParams['id']="test";
GuiConnector.getParams['id'] = "test";
return ServerConnector.getProjectId().then(function(result) {
assert.equal(result, "test");
});
......@@ -77,9 +77,36 @@ describe('ServerConnector', function() {
it('getOverlaySourceDownloadUrl', function() {
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.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);
});
});
it('removeOverlay', function() {
return ServerConnector.removeOverlay({
overlayId : 17296,
});
});
it('updateOverlay', function() {
return ServerConnector.updateOverlay({
overlayId : 17296,
name : "test nam2",
description : "test desc2",
});
});
......
......@@ -45,6 +45,35 @@ describe('OverlayPanel', function() {
});
});
it('createRow', function() {
var div = helper.createOverlayTab();
var map = helper.createCustomMap();
var overlay = helper.createLayout();
overlay.setInputDataAvailable(true);
overlay.setCreator("me");
map.getModel().addLayout(overlay);
var panel = new OverlayPanel({
element : div,
customMap : map
});
var row = panel.createOverlayRow(overlay);
assert.ok(row);
var buttons = row.getElementsByTagName("button");
var openButton = null;
for (var i = 0; i < buttons.length; i++) {
var name = buttons[i].getAttribute("name");
if (name !== undefined && name.indexOf("editButton") >= 0) {
openButton = buttons[i];
}
}
assert.ok(openButton);
openButton.onclick();
});
it('download', function() {
var div = helper.createOverlayTab();
......@@ -60,18 +89,18 @@ describe('OverlayPanel', function() {
});
return panel.refresh().then(function() {
var buttons =panel.getElement().getElementsByTagName("button");
var buttons = panel.getElement().getElementsByTagName("button");
var downloadButton;
for (var i=0;i<buttons.length;i++) {
var name = buttons[i].getAttribute("name");
if (name!==undefined && name.indexOf("download-overlay")>=0) {
for (var i = 0; i < buttons.length; i++) {
var name = buttons[i].getAttribute("name");
if (name !== undefined && name.indexOf("download-overlay") >= 0) {
downloadButton = buttons[i];
}
}
assert.ok(downloadButton);
assert.notOk(panel.getLastDownloadUrl());
return downloadButton.onclick();
}).then(function(){
}).then(function() {
assert.ok(panel.getLastDownloadUrl());
});
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment