diff --git a/jupyter-openbis-extension/dataset.py b/jupyter-openbis-extension/dataset.py index 91c6a89488dead78c42bef4fba4292b6122bfdf3..c92ef4d5c5e442cb23b6031f7a4452b0f4e9deae 100644 --- a/jupyter-openbis-extension/dataset.py +++ b/jupyter-openbis-extension/dataset.py @@ -69,6 +69,15 @@ class DataSetDownloadHandler(IPythonHandler): class DataSetTypesHandler(IPythonHandler): def get(self, **params): """Handle a request to /openbis/datasetTypes/connection_name + This meta-metadata is used in the dataset upload dialog (uploadDialog.js) + to check data directly in the UI + + Returns all datasetTypes of a given connection + - with all assigned properties + - with some details about the property types + - with the vocabulary, if exists + + The result will be cached, as it is a costly operation with many fetches """ try: @@ -80,26 +89,44 @@ class DataSetTypesHandler(IPythonHandler): }) return + if getattr(conn, 'dataset_types', False): + self.write({ + "dataSetTypes": conn.dataset_types + }) + return + try: dataset_types = conn.openbis.get_dataset_types() - dts = dataset_types.df.to_dict(orient='records') - - # get property assignments for every dataset-type - # and add it to the dataset collection - for dt in dts: - dataset_type = conn.openbis.get_dataset_type(dt['code']) - pa = dataset_type.get_propertyAssignments(including_vocabulary=True) - pa_dicts = pa.to_dict(orient='records') - for pa_dict in pa_dicts: - if pa_dict['dataType'] == 'CONTROLLEDVOCABULARY': - terms = conn.openbis.get_terms(pa_dict['vocabulary']['code']) - pa_dict['terms'] = terms.df[['code','label','description','official','ordinal']].to_dict(orient='records') - dt['propertyAssignments'] = pa_dicts + # get all dataset types + ds_type_dicts = [] + for dt in conn.openbis.get_dataset_types(): + dt_dict = dt.attrs.all() + # get property assignments for every dataset-type + # and add them in the key «propertyAssignments» + pas = dt.get_property_assignments() + pa_dicts = pas.df[['propertyType','mandatory','ordinal','section']].to_dict(orient='records') + dt_dict['propertyAssignments'] = pa_dicts + + for pa_dict in pa_dicts: + # add a few more attributes to the property assignments + pt = conn.openbis.get_property_type(pa_dict['propertyType']) + pa_dict['code'] = pt.code + pa_dict['label'] = pt.label + pa_dict['description'] = pt.description + pa_dict['dataType'] = pt.dataType + # add vocabulary, if exists, as key «terms» + if pt.dataType == 'CONTROLLEDVOCABULARY': + terms = conn.openbis.get_terms(pt.vocabulary) + terms_dict = terms.df[['code','label','description','official','ordinal']].to_dict(orient='records') + pa_dict['terms'] = terms_dict + + ds_type_dicts.append(dt_dict) self.write({ - "dataSetTypes": dts + "dataSetTypes": ds_type_dicts }) + conn.dataset_types = ds_type_dicts return except Exception as e: diff --git a/jupyter-openbis-extension/static/connectionDialog.js b/jupyter-openbis-extension/static/connectionDialog.js index 40c88225a504b0971efb6bb05afcbed4a8c652da..c8aeb70cc07d5a9e694aef1532215c218836160c 100644 --- a/jupyter-openbis-extension/static/connectionDialog.js +++ b/jupyter-openbis-extension/static/connectionDialog.js @@ -193,6 +193,38 @@ define( conn_table.innerHTML = "" table_title = document.createElement("STRONG") table_title.textContent = "Please choose a connection" + + let working_dir_title = document.createElement("STRONG") + working_dir_title.textContent = "Your working directory " + let working_dir_in = document.createElement("INPUT") + working_dir_in.type = "text" + working_dir_in.name = "working_dir" + working_dir_in.autocomplete = "on" + working_dir_in.style.width = "100%" + + + // calculate the default working directory + // by combining the notebook_dir (from the jupyter configuration) and the relative notebook_path + let re = new RegExp(env.notebook.notebook_name+"$") + rel_path = env.notebook.notebook_path.replace(re, "") + let default_working_dir = "" + if (data.notebook_dir.endsWith('/')) { + default_working_dir = data.notebook_dir + rel_path + } + else { + default_working_dir = data.notebook_dir + "/" + rel_path + } + + working_dir_in.value = state.working_dir ? state.working_dir : default_working_dir + state.working_dir_element = working_dir_in + + let working_dir_reset = document.createElement("A") + working_dir_reset.className = "btn" + working_dir_reset.innerText = "reset to default" + working_dir_reset.onclick = function() { + working_dir_in.value = default_working_dir + } + conn_table.appendChild(table_title) conn_table.appendChild(table) } @@ -250,4 +282,4 @@ define( } } } -) \ No newline at end of file +)