Commit 0134ec3a authored by Mikaël Salson's avatar Mikaël Salson

menu.js: Can load http(s) URLs in the file menu

It will also allow to open distant files. For instance it will be very helpful in environment
reviews to test on different files.
parent d1fc2172
Pipeline #28782 failed with stages
in 23 seconds
......@@ -40,7 +40,7 @@ function initMenu () {
type: "GET",
timeout: 5000,
crossDomain: true,
url: config.file_menu.path + config.file_menu.file[0],
url: prepend_path_if_not_web(config.file_menu.file[0], config.file_menu.path),
success: function (result) {
$('#static_file_menu').css("display", "")
var demo_file = document.getElementById("fileSelector").firstChild
......@@ -50,7 +50,8 @@ function initMenu () {
var a = document.createElement('a');
a.className = "buttonSelector"
a.onclick = function () {
m.loadDataUrl(config.file_menu.path + config.file_menu.file[i])
var url = prepend_path_if_not_web(config.file_menu.file[i], config.file_menu.path);
m.loadDataUrl(url)
}
a.appendChild(document.createTextNode(config.file_menu.file[i]))
......
......@@ -110,6 +110,20 @@ function correctIMGTPositionsForInsertions(data) {
}
}
/**
* Prepend a path before a filepath if that filepath is not a web path.
* @param file: a path to a file may be relative, absolute or web path
* @param path: a directory path
* @return file iff it is a web path (ie. starting with http or ftp)
* path + file otherwise
*/
function prepend_path_if_not_web(file, path) {
if (file.startsWith('http') || file.startsWith('ftp')) {
return file;
}
return path + file;
}
/**
* Take in parameter the JSON result of CloneDB for one clone
* Return a hash whose keys are URLs to sample sets and configs.
......
......@@ -54,6 +54,12 @@ QUnit.test("test rounding functions", function(assert) {
}
);
QUnit.test("prepend_path_if_not_web", function(assert) {
assert.equal(prepend_path_if_not_web('toto', 'tata/'), 'tata/toto');
assert.equal(prepend_path_if_not_web('toto', 'http://toto'), 'http://toto');
assert.equal(prepend_path_if_not_web('toto', 'ftp://toto'), 'ftp://toto');
});
QUnit.test("processCloneDBContents", function(assert) {
var emptyResult = [];
assert.deepEqual(processCloneDBContents(emptyResult), {'original': [],
......
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