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 b7d6930d272fa64eed2186992c84fd1f46f5e86f..512f87d36bfe03628c60586ab0c52858809ad65b 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,7 +21,7 @@ var JupyterUtil = new function() { jupyterNotebook.init(); } - this.openJupyterNotebookFromTemplate = function(folder, fileName, template, dataSetId) { + this.openJupyterNotebookFromTemplate = function(folder, fileName, template, dataSetId, keepHistory) { 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 + "/"; @@ -35,20 +35,22 @@ var JupyterUtil = new function() { 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 + "'"; + var autogeneratedWithOpenBIS = jupyterNotebookJson.metadata["autogenerated_by_openbis"]; + + var setNotebookCellVariable = function(jupyterNotebookJson, key, value) { + for(var cIdx = 0; cIdx < jupyterNotebookJson.cells.length; cIdx++) { + if(jupyterNotebookJson.cells[cIdx].metadata["code_cell_id"] === key) { + jupyterNotebookJson.cells[cIdx].source[0] = key + "=" + value; + } } - //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]); + } + + if(autogeneratedWithOpenBIS) { + if(!keepHistory) { + setNotebookCellVariable(jupyterNotebookJson, "resultDatasetHistoryId", "'" + Util.guid() + "'"); } + setNotebookCellVariable(jupyterNotebookJson, "fileName", "'" + fileName + "'"); + setNotebookCellVariable(jupyterNotebookJson, "resultDatasetParents", JSON.stringify([dataSetId])); } $.ajax({ @@ -110,8 +112,11 @@ var JupyterUtil = new function() { return { "cell_type": "markdown", "metadata": {}, "source": [ text ] }; } - this.getCodeCell = function(source) { - return { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": source }; + this.getCodeCell = function(source, code_cell_id) { + if(!code_cell_id) { + code_cell_id = null; + } + return { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false, "code_cell_id" : code_cell_id }, "outputs": [], "source": source }; } this.createJupyterNotebookContent = function(dataSets, ownerEntity, fileName) { @@ -123,15 +128,15 @@ var JupyterUtil = new function() { content.push(this.getMarkdownCell("# Jupyter notebook title, modify me!\n")); content.push(this.getMarkdownCell("Variables used by other parts of this autogenerated notebook - Don't modify if you don't know what you are doing!)")); content.push(this.getMarkdownCell("Description : fileName variable, indicates the name of the document to save")); - content.push(this.getCodeCell(["fileName='" + fileName + "'"])); + content.push(this.getCodeCell(["fileName='" + fileName + "'"], "fileName")); content.push(this.getMarkdownCell("Description : resultDatasetParents variable, indicates the permIds of the parents of the result dataset")); - content.push(this.getCodeCell(["resultDatasetParents=" + JSON.stringify(dataSetIds)])); + content.push(this.getCodeCell(["resultDatasetParents=" + JSON.stringify(dataSetIds)], "resultDatasetParents")); content.push(this.getMarkdownCell("Description : history identifier, different versions of the same notebook should share the same identifier to keep the history")); - content.push(this.getCodeCell(["resultDatasetHistoryId='" + Util.guid() + "'"])); + content.push(this.getCodeCell(["resultDatasetHistoryId='" + Util.guid() + "'"], "resultDatasetHistoryId")); content.push(this.getMarkdownCell("Description : resultDatasetName variable, indicates the name of the result dataset, **to be set by the user**")); - content.push(this.getCodeCell(["resultDatasetName='Name your dataset!'"])); + content.push(this.getCodeCell(["resultDatasetName='Name your dataset!'"], "resultDatasetName")); content.push(this.getMarkdownCell("Description : resultDatasetNotes variable, indicate some notes of the result dataset, **to be set by the user**")); - content.push(this.getCodeCell(["resultDatasetNotes='Write some notes or leave empty this property!'"])); + content.push(this.getCodeCell(["resultDatasetNotes='Write some notes or leave empty this property!'"], "resultDatasetNotes")); content.push(this.getMarkdownCell("## Connect to openBIS")); content.push(this.getCodeCell([ "from pybis import Openbis\n", "o = Openbis()" ])); content.push(this.getMarkdownCell("## Datasets Information")); @@ -200,6 +205,7 @@ var JupyterUtil = new function() { return { "cells": content, "metadata": { + "autogenerated_by_openbis" : true, "kernelspec": { "display_name": "Python 3", "language": "python", 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 5895631461c1bda14cbf7d34479952cbc35d3ba4..ca1909de37a11b4a4ec417985d40a2a1758b9b3c 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, datasetCode) { - JupyterUtil.openJupyterNotebookFromTemplate(workspace, notebook, existingNotebookURL, datasetCode); + this.create = function(workspace, notebook, existingNotebookURL, datasetCode, keepHistory) { + JupyterUtil.openJupyterNotebookFromTemplate(workspace, notebook, existingNotebookURL, datasetCode, keepHistory); 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 81de70bb1ceb83706e1c9dd50ea6ba0d0826d064..35999a72ab36f639c46d3b6c27cc7f8783f1cd40 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 @@ -21,18 +21,20 @@ function JupyterCopyNotebookView(jupyterNotebookController, jupyterNotebookModel this.repaint = function() { var _this = this; var $window = $('<form>', { 'action' : 'javascript:void(0);' }); - $window.append($('<legend>').append("Use Jupyter Notebook as Template")); + var $keepHistory = FormUtil._getBooleanField("HISTORY_ID","Keep History"); + $window.append(FormUtil.getFieldForComponentWithLabel($keepHistory, "Keep History, this notebook is a continuation of the old one")); $window.append(FormUtil.getFieldForLabelWithText("Notebook", this._jupyterNotebookModel.existingNotebookURL)); - var $workspace = FormUtil._getInputField('text', null, 'workspace Name', null, true); + var $workspace = FormUtil._getInputField('text', null, 'directory Name', null, true); var $notebookName = FormUtil._getInputField('text', null, 'notebook Name', null, true); - $window.append(FormUtil.getFieldForComponentWithLabel($workspace, "Workspace")); + $window.append(FormUtil.getFieldForComponentWithLabel($workspace, "Directory Name")); $window.append(FormUtil.getFieldForComponentWithLabel($notebookName, "Notebook Name")); 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._jupyterNotebookModel.datasetCode); + var keepHistory = $($($keepHistory.children()[0]).children()[0]).prop("checked"); + _this._jupyterNotebookController.create($workspace.val(), $notebookName.val(), data, _this._jupyterNotebookModel.datasetCode, keepHistory); }); }); var $btnCancel = $('<a>', { 'class' : 'btn btn-default' }).append('Cancel'); 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 5dbe1cc07f165a453d5a751ee54be96afe063c57..04528ecf45c51d7b1d0232de8d23f89c8bd5b74e 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 @@ -86,9 +86,9 @@ function JupyterNotebookView(jupyterNotebookController, jupyterNotebookModel) { } - var $workspace = FormUtil._getInputField('text', null, 'workspace Name', null, true); + var $workspace = FormUtil._getInputField('text', null, 'directory Name', null, true); var $notebookName = FormUtil._getInputField('text', null, 'notebook Name', null, true); - $window.append(FormUtil.getFieldForComponentWithLabel($workspace, "Workspace")); + $window.append(FormUtil.getFieldForComponentWithLabel($workspace, "Directory Name")); $window.append(FormUtil.getFieldForComponentWithLabel($notebookName, "Notebook Name")); var $btnAccept = $('<input>', { 'type': 'submit', 'class' : 'btn btn-primary', 'value' : 'Accept' });