From 9a7c592d0b82f519ed4328e6206a7a935a4b7484 Mon Sep 17 00:00:00 2001 From: vermeul <swen@ethz.ch> Date: Fri, 28 Jun 2019 01:05:49 +0200 Subject: [PATCH] added convenient file browser --- .../static/uploadDialog.js | 91 +++++++++++++++++-- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/jupyter-openbis-extension/static/uploadDialog.js b/jupyter-openbis-extension/static/uploadDialog.js index 11cc7f6..d437deb 100644 --- a/jupyter-openbis-extension/static/uploadDialog.js +++ b/jupyter-openbis-extension/static/uploadDialog.js @@ -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 +) -- GitLab