Skip to content
Snippets Groups Projects
Commit 9a7c592d authored by Swen Vermeul's avatar Swen Vermeul
Browse files

added convenient file browser

parent 5f9c53b0
No related branches found
No related tags found
No related merge requests found
......@@ -30,17 +30,18 @@ define([
spinner.src=""
}
function get_file_list(env, container) {
var url = env.notebook.base_url + 'general/filelist'
function get_file_list(env, container, path) {
var url = env.notebook.base_url + 'api/contents'
if (path !== "") {
url = url + '/' + path
}
fetch(url)
.then( function(response) {
if (response.ok) {
response.json()
.then(function(data){
var values = Object.keys(data.files)
values.sort()
state.fileCheckboxes = createSelectTable(values, container, false, state.selectedFiles)
state.fileCheckboxes = createFileTable(env, data, container, false, state.selectedFiles)
})
}
else {
......@@ -210,6 +211,80 @@ define([
return checkboxes
}
function createFileTable(env, data, container, checked, overrides) {
var table = document.createElement("TABLE")
table.className = 'table-bordered table-striped table-condensed'
table.style.width = "100%"
var body = table.createTBody()
if (data.path !== "") {
var row = body.insertRow()
row.insertCell()
var iconCell = row.insertCell()
iconCell.className = "item_icon folder_icon icon-fixed-width"
var filenameCell = row.insertCell()
filenameCell.textContent = ".."
filenameCell.style.width = "80%"
filenameCell.onclick = function(){
var elems = data.path.split('/')
elems.pop()
get_file_list(env, container, elems.join('/'))
}
var sizeCell = row.insertCell()
sizeCell.style.textAlign = "right"
sizeCell.style.width = "15%"
}
var checkboxes = []
data.content.sort( (a, b) => a.name.localeCompare(b.name, undefined, {sensitivity: 'base'}) ).forEach( file => {
var row = body.insertRow()
var checkboxCell = row.insertCell()
checkboxCell.style.width="5%"
var iconCell = row.insertCell()
var filenameCell = row.insertCell()
filenameCell.textContent = file.name
filenameCell.style.width = "100%"
if (file.type === "directory") {
iconCell.className = "item_icon folder_icon icon-fixed-width"
filenameCell.onclick = function () {
get_file_list(env, container, file.path)
}
}
else {
var checkbox = document.createElement("INPUT")
checkbox.type = "checkbox"
checkbox.value = file.path
checkbox.checked = overrides.includes(file.name) ? !checked : checked
checkboxes.push(checkbox)
checkboxCell.appendChild(checkbox)
if (file.type === "notebook") {
iconCell.className = "item_icon notebook_icon icon-fixed-width"
}
else {
iconCell.className = "item_icon file_icon icon-fixed-width"
}
filenameCell.onclick = function () {
this.parentElement.firstElementChild.firstElementChild.checked = !this.parentElement.firstElementChild.firstElementChild.checked
}
}
var sizeCell = row.insertCell()
sizeCell.textContent = file.size
sizeCell.style.textAlign = "right"
sizeCell.style.width = "15%"
})
container.innerHTML = ""
container.appendChild(table)
return checkboxes
}
return {
help: 'upload Notebook and Data to openBIS',
icon: 'fa-upload',
......@@ -252,7 +327,7 @@ define([
var fileListContainer = document.createElement("DIV")
fileListContainer.style.maxHeight="150px"
fileListContainer.style.overflow="auto"
get_file_list(env, fileListContainer)
get_file_list(env, fileListContainer, "")
var inputs = document.createElement("DIV")
inputs.style.marginTop = '10px'
......@@ -396,4 +471,4 @@ define([
}
}
}
)
\ 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