diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/JupyterUtil.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/JupyterUtil.js index 81a0a71fccfaca5924436447bb6a60c0e23dcc47..460044b98aefcc5705d0411df10e684f0a7f97c7 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/JupyterUtil.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/JupyterUtil.js @@ -41,10 +41,10 @@ var JupyterUtil = new function() { }); } - this.createJupyterNotebookAndOpen = function(folder, fileName, dataSetIds) { + this.createJupyterNotebookAndOpen = function(folder, fileName, dataSetIds, ownerEntity) { fileName = fileName + ".ipynb"; var jupyterURL = profile.jupyterIntegrationServerEndpoint + "?token=" + mainController.serverFacade.openbisServer.getSession() + "&folder=" + folder + "&filename=" + fileName; - var newJupyterNotebook = this.createJupyterNotebookContent(dataSetIds); + var newJupyterNotebook = this.createJupyterNotebookContent(dataSetIds, ownerEntity, fileName); var jupyterNotebookURL = profile.jupyterEndpoint + "user/" + mainController.serverFacade.getUserId() + "/notebooks/" + folder + "/"; $.ajax({ @@ -62,8 +62,24 @@ var JupyterUtil = new function() { }); } - this.createJupyterNotebookContent = function(dataSetIds) { + this.createJupyterNotebookContent = function(dataSetIds, ownerEntity, fileName) { var content = []; + var mainTitle = { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Jupyter notebook autogenerated from openBIS-ELN" + ] + } + content.push(mainTitle); + var connectTitle = { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Connect to openBIS" + ] + } + content.push(connectTitle); var initializeOpenbisConnection = { "cell_type": "code", "execution_count": null, @@ -72,15 +88,22 @@ var JupyterUtil = new function() { }, "outputs": [], "source": [ - "#Initialize Openbis API\n", "from pybis import Openbis\n", "o = Openbis(url='" + profile.jupyterOpenbisEndpoint + "', verify_certificates=False)" ] }; content.push(initializeOpenbisConnection); + var datasetsInfoTitle = { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Datasets Information" + ] + } + content.push(datasetsInfoTitle); for(var cIdx = 0; cIdx < dataSetIds.length; cIdx++) { - var loadDataset = { + var datasetInfo = { "cell_type": "code", "execution_count": null, "metadata": { @@ -88,11 +111,82 @@ var JupyterUtil = new function() { }, "outputs": [], "source": [ - "ds = o.get_dataset('" + dataSetIds[cIdx]+ "')" + "ds" + cIdx + " = o.get_dataset('" + dataSetIds[cIdx]+ "')\n", + "ds" + cIdx + ".attrs" ] }; - content.push(loadDataset); + content.push(datasetInfo); + } + + var datasetsDownloadTitle = { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Datasets Download" + ] + } + content.push(datasetsDownloadTitle); + for(var cIdx = 0; cIdx < dataSetIds.length; cIdx++) { + var datasetDownload = { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "ds" + cIdx + ".data['dataStore']['downloadUrl'] = '" + profile.jupyterDSSEndpoint + "'\n", + "ds" + cIdx + ".download(files=ds" + cIdx + ".file_list, destination='./', wait_until_finished=True)", + ] + }; + content.push(datasetDownload); + } + + var notebookProcessTitle = { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Process your data here" + ] + } + content.push(notebookProcessTitle); + var notebookProcess = { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] + }; + content.push(notebookProcess); + + var saveHTMLTitle = { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Save Notebook as HTML (save it first!)" + ] } + content.push(saveHTMLTitle); + var saveHTML = { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "from nbconvert import HTMLExporter\n", + "import codecs\n", + "import nbformat\n", + "exporter = HTMLExporter()\n", + "output_notebook = nbformat.read('" + fileName + "', as_version=4)\n", + "output, resources = exporter.from_notebook_node(output_notebook)\n", + "codecs.open('" + fileName + ".html', 'w', encoding='utf-8').write(output)\n", + ] + }; + content.push(saveHTML); return { "cells": content, diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookView.js index b9c27b39fe814ad135180ba119a8a14f43438549..d616417f9db8e6eb1db7b72dac63b08f2d7ba99a 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookView.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookView.js @@ -79,7 +79,7 @@ function JupyterNotebookView(jupyterNotebookController, jupyterNotebookModel) { var selectedOwner = ownerSearchDropdown.getSelected(); var notebookOwner = selectedOwner[0]; - _this._jupyterNotebookController.create($workspace.val(), $notebookName.val(), notebookDatasets); + _this._jupyterNotebookController.create($workspace.val(), $notebookName.val(), notebookDatasets, notebookOwner); }); var $btnCancel = $('<a>', { 'class' : 'btn btn-default' }).append('Cancel'); $btnCancel.click(function() {