diff --git a/jupyter-openbis-extension/static/downloadDialog.js b/jupyter-openbis-extension/static/downloadDialog.js index 973ff5e3066bedc3a272f487cc0329f68119e48f..20dc8dfa5e7465345eefc4ac254405129c0278f3 100644 --- a/jupyter-openbis-extension/static/downloadDialog.js +++ b/jupyter-openbis-extension/static/downloadDialog.js @@ -7,15 +7,12 @@ define([ function writeMetaData(data) { var notebook = IPython.notebook - if (typeof notebook.metadata.openbis_connections === 'undefined') { - notebook.metadata.openbis_connections = {} - } - if (typeof notebook.metadata.openbis_connections[data.url] === 'undefined') { - notebook.metadata.openbis_connections[data.url] = {} + if (typeof notebook.metadata.datasets === 'undefined') { + notebook.metadata.datasets = {} } // store metadata about the downloaded files into the notebook-metadata if (data.permId) { - notebook.metadata.openbis_connections[data.url][data.permId] = { + notebook.metadata.datasets[data.permId] = { "permId": data.permId, "path": data.path, "dataStore": data.dataStore, diff --git a/jupyter-openbis-extension/static/state.js b/jupyter-openbis-extension/static/state.js index 5f96c0e5f4e14679e343463f0ff9fa71e13ec722..b63805681c87effe51d45f46042b0c2b02023416 100644 --- a/jupyter-openbis-extension/static/state.js +++ b/jupyter-openbis-extension/static/state.js @@ -7,7 +7,9 @@ define([], }, uploadDataSetType: null, uploadDataSetTypes: {}, - uploadEntityIdentifier: '' + uploadEntityIdentifier: '', + getSelectedDataSets: () => [], + getSelectedFiles: () => [] } } ) \ No newline at end of file diff --git a/jupyter-openbis-extension/static/uploadDIalog.js b/jupyter-openbis-extension/static/uploadDIalog.js index d1c678d74ffb394a920678060e3cde11b1fe9316..55e73c064a0f1660ff9579fa5565724538ed9611 100644 --- a/jupyter-openbis-extension/static/uploadDIalog.js +++ b/jupyter-openbis-extension/static/uploadDIalog.js @@ -30,6 +30,35 @@ define([ spinner.src="" } + function get_file_list(env, container) { + var url = env.notebook.base_url + 'general/filelist' + + fetch(url) + .then( function(response) { + if (response.ok) { + response.json() + .then(function(data){ + var values = Object.keys(data.files) + values.sort() + state.getSelectedFiles = createSelectTable(values, container, false) + }) + } + else { + console.error(response.status) + } + }) + } + + function get_dataset_list(env, container) { + console.log(env.notebook.metadata.datasets) + var datasets = env.notebook.metadata.datasets + if (datasets != null) { + var values = Object.keys(datasets) + values.sort() + state.getSelectedDataSets = createSelectTable(values, container, true) + } + } + function getDatasetTypes(env, connection_name, dataset_types, input_fields) { // get all DatasetTypes of a given connection @@ -127,6 +156,32 @@ define([ }) } + function createSelectTable(values, container, checked) { + + var table = document.createElement("TABLE") + table.className = 'table-bordered table-striped table-condensed' + table.style.width = "100%" + + var body = table.createTBody() + + var checkboxes = [] + values.forEach( value => { + var row = body.insertRow() + var checkbox = document.createElement("INPUT") + checkbox.type = "checkbox" + checkbox.value = value + checkbox.checked = checked + checkboxes.push(checkbox) + row.insertCell().appendChild(checkbox) + var valueCell = row.insertCell() + valueCell.textContent = value + valueCell.style.width = "100%" + }) + container.appendChild(table) + + return () => checkboxes.filter(cb => cb.checked).map(cb => cb.value) + } + return { help: 'upload Notebook and Data to openBIS', icon: 'fa-upload', @@ -161,14 +216,19 @@ define([ sampleIdentifier.style.width="100%" var ds_title = document.createElement("STRONG") - ds_title.textContent = "DataSet files" - var ds_files = document.createElement("INPUT") - ds_files.type = "text" - ds_files.placeholder = "filenames" - ds_files.name = "ds_files" - ds_files.size = "90" - ds_files.style.width="100%" - + ds_title.textContent = "DataSets" + var dataSetListContainer = document.createElement("DIV") + dataSetListContainer.style.height="150px" + dataSetListContainer.style.overflow="scroll" + get_dataset_list(env, dataSetListContainer) + + var files_title = document.createElement("STRONG") + files_title.textContent = "Files" + var fileListContainer = document.createElement("DIV") + fileListContainer.style.height="150px" + fileListContainer.style.overflow="scroll" + get_file_list(env, fileListContainer) + var inputs = document.createElement("DIV") inputs.style.marginTop = '10px' inputs.appendChild(main_error) @@ -181,7 +241,9 @@ define([ inputs.appendChild(sample_error) inputs.appendChild(sampleIdentifier) inputs.appendChild(ds_title) - inputs.appendChild(ds_files) + inputs.appendChild(dataSetListContainer) + inputs.appendChild(files_title) + inputs.appendChild(fileListContainer) var uploadDialogBox = $('<div/>').append(inputs) @@ -206,15 +268,11 @@ define([ var uploadUrl = env.notebook.base_url + 'openbis/dataset/' + connection_name var notebook = IPython.notebook + var files = state.getSelectedFiles() var re = /\/notebooks\/(.*?)$/ - var files = [] var filepath = window.location.pathname.match(re)[1] files.push(filepath) - // FIXME - //if (ds_files.val()) { - // files.push(ds_files.value) - //} - + var props = {} for (input of $('#upload-input-fields').find('input')) { props[input.name] = input.value