diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js index d2a6a4ad378385176ed3a37469d9a5deb3152e2d..60cc1dac5d7e3a1ebd2c583b2087ce2225b854c3 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js @@ -124,9 +124,9 @@ $.extend(DefaultProfile.prototype, { // jupyterhub -f jupyterhub_config.py --no-ssl // Jupyter integration config -// this.jupyterOpenbisEndpoint = "http://10.0.2.2:8888"; //Should not end with slash -// this.jupyterIntegrationServerEndpoint = "https://127.0.0.1:8123"; -// this.jupyterEndpoint = "http://127.0.0.1:8000/"; + this.jupyterOpenbisEndpoint = "http://10.0.2.2:8888"; //Should not end with slash + this.jupyterIntegrationServerEndpoint = "https://127.0.0.1:8123"; + this.jupyterEndpoint = "http://127.0.0.1:8000/"; this.forcedDisableRTF = ["FREEFORM_TABLE_STATE","NAME", "SEQUENCE"]; this.forceMonospaceFont = ["SEQUENCE"]; 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 9734331cfc95fd20a48d865bbe225e67b12941e8..6b3235ec9589384d8ae25cf6c45205a6853840a6 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 @@ -21,19 +21,49 @@ var JupyterUtil = new function() { jupyterNotebook.init(); } - this.openJupyterNotebookFromTemplate = function(folder, fileName, template) { + this.openJupyterNotebookFromTemplate = function(folder, fileName, template, dataSetId) { fileName = fileName + ".ipynb"; var jupyterURL = profile.jupyterIntegrationServerEndpoint + "?token=" + mainController.serverFacade.openbisServer.getSession() + "&folder=" + folder + "&filename=" + fileName; var jupyterNotebookURL = profile.jupyterEndpoint + "user/" + mainController.serverFacade.getUserId() + "/notebooks/" + folder + "/"; $.ajax({ - url : jupyterURL, + url : jupyterURL + "&test=True", type : 'POST', crossDomain: true, - data : template, + data : "TEST", success : function(result) { - var win = window.open(jupyterNotebookURL + result.fileName, '_blank'); - win.focus(); + fileName = result.fileName; + var jupyterNotebookJson = JSON.parse(template); + + var autogeneratedWithOpenBIS = false; + for(var cIdx = 0; cIdx < jupyterNotebookJson.cells.length; cIdx++) { + //If was autogenerated with openBIS + if(jupyterNotebookJson.cells[cIdx].source[0] === "# Mark : Autogenerated with openBIS-ELN/LIMS (System Cell, Don't delete!)") { + autogeneratedWithOpenBIS = true; + } + //Fix Name + if(autogeneratedWithOpenBIS && jupyterNotebookJson.cells[cIdx].source[0] === "# Variable - File Name (System Cell, Don't delete!)\n") { + jupyterNotebookJson.cells[cIdx].source[1] = "fileName='" + fileName + "'"; + } + //Fix Parents + if(autogeneratedWithOpenBIS && jupyterNotebookJson.cells[cIdx].source[0] === "# Variable : Parents used by the automaticaly generated result dataset (System Cell, Don't delete!)\n") { + jupyterNotebookJson.cells[cIdx].source[1] = "resultDatasetParents=" + JSON.stringify([dataSetId]); + } + } + + $.ajax({ + url : jupyterURL + "&test=False", + type : 'POST', + crossDomain: true, + data : JSON.stringify(jupyterNotebookJson), + success : function(result) { + var win = window.open(jupyterNotebookURL + result.fileName, '_blank'); + win.focus(); + }, + error : function(result) { + alert("error: " + JSON.stringify(result)); + } + }); }, error : function(result) { alert("error: " + JSON.stringify(result)); @@ -82,10 +112,43 @@ var JupyterUtil = new function() { "cell_type": "markdown", "metadata": {}, "source": [ - "# Jupyter notebook autogenerated from openBIS-ELN" + "# Jupyter notebook title, modify me!" ] } content.push(mainTitle); + var openbisCell = { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": ["# Mark : Autogenerated with openBIS-ELN/LIMS (System Cell, Don't delete!)"] + }; + content.push(openbisCell); + var fileNameCell = { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": ["# Variable - File Name (System Cell, Don't delete!)\n", + "fileName='" + fileName + "'"] + }; + content.push(fileNameCell); + var parentsCell = { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": ["# Variable : Parents used by the automaticaly generated result dataset (System Cell, Don't delete!)\n", + "resultDatasetParents=" + JSON.stringify(dataSetIds)] + }; + content.push(parentsCell); + var connectTitle = { "cell_type": "markdown", "metadata": {}, @@ -178,18 +241,19 @@ var JupyterUtil = new function() { "cell_type": "markdown", "metadata": {}, "source": [ - "### Create Result Dataset with current notebook and HTML version with the output (save the notebook first!)" + "### Result Dataset, it will hold the current notebook and HTML version with the output (press save before executing this!)" ] } content.push(saveTitle); + var createHTML = [ "from nbconvert import HTMLExporter\n", "import codecs\n", "import nbformat\n", "exporter = HTMLExporter()\n", - "output_notebook = nbformat.read('" + fileName + "', as_version=4)\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", + "codecs.open(fileName + '.html', 'w', encoding='utf-8').write(output)\n", "\n" ]; @@ -204,14 +268,13 @@ var JupyterUtil = new function() { break; } - var parents = JSON.stringify(dataSetIds); var createDataset = [ "ds_new = o.new_dataset(\n", "type='ANALYZED_DATA',\n", ownerSettings, - "parents=" + parents + ",\n", - "files = ['" + fileName + "', '" + fileName + ".html'],\n", + "parents=resultDatasetParents,\n", + "files = [fileName, fileName + '.html'],\n", "props={'name': 'Name your dataset!', 'notes': 'Write some notes or delete this property!'}\n", ")\n", "ds_new.save()" diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookController.js index 2b096a86d09091dc2f503e613c579a62f86c99da..5895631461c1bda14cbf7d34479952cbc35d3ba4 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookController.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookController.js @@ -22,8 +22,8 @@ function JupyterCopyNotebookController(datasetCode, existingNotebookURL) { this._jupyterNotebookView.repaint(); } - this.create = function(workspace, notebook, existingNotebookURL) { - JupyterUtil.openJupyterNotebookFromTemplate(workspace, notebook, existingNotebookURL); + this.create = function(workspace, notebook, existingNotebookURL, datasetCode) { + JupyterUtil.openJupyterNotebookFromTemplate(workspace, notebook, existingNotebookURL, datasetCode); Util.unblockUI(); } } \ No newline at end of file diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookView.js index b55edfbc0e6496b2818f48616e755ff79609c056..81de70bb1ceb83706e1c9dd50ea6ba0d0826d064 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookView.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookView.js @@ -32,7 +32,7 @@ function JupyterCopyNotebookView(jupyterNotebookController, jupyterNotebookModel var $btnAccept = $('<input>', { 'type': 'submit', 'class' : 'btn btn-primary', 'value' : 'Accept' }); $window.submit(function() { $.get(_this._jupyterNotebookModel.existingNotebookURL, function( data ) { - _this._jupyterNotebookController.create($workspace.val(), $notebookName.val(), data); + _this._jupyterNotebookController.create($workspace.val(), $notebookName.val(), data, _this._jupyterNotebookModel.datasetCode); }); }); var $btnCancel = $('<a>', { 'class' : 'btn btn-default' }).append('Cancel');