Commit e97639c2 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

downloading of overlays added

parent 09848158
......@@ -404,6 +404,20 @@ ServerConnector.getMiRnasByQueryUrl = function(params) {
token: token},
});
};
ServerConnector.getOverlaySourceUrl = function(params) {
var overlayId = params.overlayId;
var projectId = params.projectId;
var token = params.token;
return this.getApiUrl({type:"overlay",
method:"getOverlaySource",
params: {
overlayId: overlayId,
projectId: projectId,
token: token},
});
};
ServerConnector.getMiRnasByTargetUrl = function(params) {
var query = params.query;
......@@ -825,6 +839,23 @@ ServerConnector.getChemicalsByQuery = function(params) {
});
};
ServerConnector.getOverlaySourceDownloadUrl = 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;
resolve(self.getOverlaySourceUrl(params));
}).catch(function(exception){
reject(exception);
});
});
};
ServerConnector.getDrugNamesByTarget = function(params) {
var self = this;
params.columns = ["name"];
......@@ -933,4 +964,6 @@ ServerConnector.getSuggestedQueryList = function(projectId) {
});
};
module.exports = ServerConnector;
......@@ -121,9 +121,15 @@ OverlayPanel.prototype.createOverlayRow = function(overlay, checked) {
var dataTd = document.createElement("td");
if (overlay.getInputDataAvailable()) {
var button = document.createElement("button");
button.setAttribute("name", "download-overlay-" + overlay.getId());
button.onclick = function() {
throw new Error("Not implemented");
return ServerConnector.getOverlaySourceDownloadUrl({
overlayId : overlay.getId()
}).then(function(url) {
return self.downloadFile(url);
});
};
button.innerHTML = "<span class='ui-icon ui-icon-arrowthickstop-1-s'></span>";
dataTd.appendChild(button);
}
......
......@@ -15,6 +15,10 @@ function Panel(params) {
self.setPanelName(params.panelName);
self.setElement(params.element);
self.setMap(params.customMap);
if (self.getHiddenIFrame() === undefined) {
self.addHiddenIFrame();
}
}
Panel.prototype = Object.create(ObjectWithListeners.prototype);
......@@ -249,16 +253,37 @@ Panel.prototype.createSubMapLink = function(label, element) {
return result;
};
Panel.prototype.getHiddenIFrame = function() {
return this.getElementByName(this.getElement(), "hidden-download-iframe");
};
Panel.prototype.downloadFile = function(url) {
this.getHiddenIFrame().src = url;
};
Panel.prototype.addHiddenIFrame = function() {
var iframe = document.createElement("iframe");
iframe.setAttribute("name", "hidden-download-iframe");
iframe.style.display = "none";
this.getElement().appendChild(iframe);
};
Panel.prototype.getLastDownloadUrl = function() {
return this.getHiddenIFrame().src;
};
Panel.prototype.getElementByName = function(element, name) {
if (element!==undefined) {
if (element !== undefined) {
if (element.getAttribute("name") === name) {
return element;
}
var children = element.children;
for (var i=0;i<children.length;i++) {
for (var i = 0; i < children.length; i++) {
var child = children[i];
var res = this.getElementByName(child, name);
if (res!==undefined) {
if (res !== undefined) {
return res;
}
}
......@@ -266,5 +291,4 @@ Panel.prototype.getElementByName = function(element, name) {
return undefined;
};
module.exports = Panel;
......@@ -75,4 +75,12 @@ describe('ServerConnector', function() {
assert.equal(str, "1,2,3,6,7,8,9");
});
it('getOverlaySourceDownloadUrl', function() {
var id = 123;
return ServerConnector.getOverlaySourceDownloadUrl({overlayId:id}).then(function(url){
assert.ok(url);
assert.ok(url.indexOf(id)>=0);
});
});
});
......@@ -45,4 +45,35 @@ describe('OverlayPanel', function() {
});
});
it('download', function() {
var div = helper.createOverlayTab();
var map = helper.createCustomMap();
var overlay = helper.createLayout();
overlay.setInputDataAvailable(true);
map.getModel().addLayout(overlay);
var panel = new OverlayPanel({
element : div,
customMap : map
});
return panel.refresh().then(function() {
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) {
downloadButton = buttons[i];
}
}
assert.ok(downloadButton);
assert.notOk(panel.getLastDownloadUrl());
return downloadButton.onclick();
}).then(function(){
assert.ok(panel.getLastDownloadUrl());
});
});
});
......@@ -41,9 +41,13 @@ public class OverlayController extends BaseController {
@RequestParam(value = "overlayId") String overlayId) throws SecurityException, QueryException {
FileEntry file = overlayController.getOverlaySource(token, projectId, overlayId);
MediaType type = MediaType.TEXT_PLAIN;
if (file.getOriginalFileName().endsWith("xml")) {
type = MediaType.APPLICATION_XML;
}
return ResponseEntity
.ok().contentLength(file.getFileContent().length).contentType(MediaType.APPLICATION_XML)
.header("Content-Disposition", "attachment; filename=somefile.xml").body(file.getFileContent());
.ok().contentLength(file.getFileContent().length).contentType(type).header("Content-Disposition", "attachment; filename=" + file.getOriginalFileName())
.body(file.getFileContent());
}
@RequestMapping(value = "/getOverlayElements", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
......
......@@ -141,6 +141,8 @@ public class OverlayRestImpl {
if (layout == null) {
throw new QueryException("Invalid overlay id");
}
//lazy initialization issue
layout.getInputData().getFileContent();
return layout.getInputData();
} catch (NumberFormatException e) {
throw new QueryException("Invalid overlay id");
......
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