From 0b0469997e7e8578536424fecd1564403e09d971 Mon Sep 17 00:00:00 2001 From: juanf <juanf> Date: Thu, 24 Aug 2017 14:18:28 +0000 Subject: [PATCH] SSDM-4223 : Jupyter integration, pop up to select datasets, workspace, notebook, etc.. ongoing work SVN: 38662 --- .../1/as/webapps/eln-lims/html/index.html | 5 ++ .../eln-lims/html/js/util/JupyterUtil.js | 6 +- .../webapps/eln-lims/html/js/util/TreeUtil.js | 6 +- .../js/views/DataSetForm/DataSetFormView.js | 4 +- .../widgets/JupyterNotebookController.js | 29 ++++++++ .../widgets/JupyterNotebookModel.js | 19 +++++ .../widgets/JupyterNotebookView.js | 73 +++++++++++++++++++ 7 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookController.js create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookModel.js create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookView.js diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html index f2169fa3a2f..48f8549ba0c 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html @@ -181,6 +181,11 @@ <script type="text/javascript" src="./js/views/DataSetForm/widgets/DatasetViewerController.js"></script> <script type="text/javascript" src="./js/views/DataSetForm/widgets/DatasetViewerModel.js"></script> <script type="text/javascript" src="./js/views/DataSetForm/widgets/DatasetViewerView.js"></script> + + <script type="text/javascript" src="./js/views/DataSetForm/widgets/JupyterNotebookController.js"></script> + <script type="text/javascript" src="./js/views/DataSetForm/widgets/JupyterNotebookModel.js"></script> + <script type="text/javascript" src="./js/views/DataSetForm/widgets/JupyterNotebookView.js"></script> + <script type="text/javascript" src="./js/views/DataSetForm/widgets/ImagePreviewIconLoader.js"></script> <script type="text/javascript" src="./js/views/SideMenu/SideMenuWidgetController.js"></script> 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 00ebadd6186..366e6c6cfcb 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 @@ -16,9 +16,8 @@ var JupyterUtil = new function() { - this.createJupyterNotebookAndOpen = function(dataSetIds) { - var folder = "openbis"; - var fileName = dataSetIds[0] + ".ipynb"; + this.createJupyterNotebookAndOpen = function(folder, fileName, dataSetIds) { + fileName = fileName + ".ipynb"; var jupyterURL = profile.jupyterIntegrationServerEndpoint + "?token=" + mainController.serverFacade.openbisServer.getSession() + "&folder=" + folder + "&filename=" + fileName; var newJupyterNotebook = this.createJupyterNotebookContent(dataSetIds); var jupyterNotebookURL = profile.jupyterEndpoint + "user/" + mainController.serverFacade.getUserId() + "/notebooks/" + folder + "/"; @@ -53,6 +52,7 @@ var JupyterUtil = new function() { "outputs": [], "source": [ "#Initialize Openbis API\n", + "from pybis import Openbis\n", "o = Openbis(url='" + profile.jupyterOpenbisEndpoint + "', verify_certificates=False)" ] }; diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/TreeUtil.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/TreeUtil.js index 73ce45f0eca..9c465fd4a1e 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/TreeUtil.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/TreeUtil.js @@ -15,9 +15,13 @@ */ var TreeUtil = new function() { + this.getCompleteTree = function($treeContainer) { var treeModel = [{ title : "/", entityType: "ROOT", key : "/", folder : true, lazy : true }]; - + return this.getTreeFromModel($treeContainer, treeModel); + } + + this.getTreeFromModel = function($treeContainer, treeModel) { var glyph_opts = { map: { doc: "glyphicon glyphicon-file", diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js index 7be60ab0b6c..6276ade8aee 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js @@ -95,7 +95,9 @@ function DataSetFormView(dataSetFormController, dataSetFormModel) { //Jupyter Button if(profile.jupyterIntegrationServerEndpoint) { var $jupyterBtn = FormUtil.getButtonWithIcon("glyphicon-log-in", function () { - JupyterUtil.createJupyterNotebookAndOpen([_this._dataSetFormModel.dataSet.code]); + var jupyterNotebook = new JupyterNotebookController(_this._dataSetFormModel.dataSet); + jupyterNotebook.init(); + // JupyterUtil.createJupyterNotebookAndOpen([_this._dataSetFormModel.dataSet.code]); }); toolbarModel.push({ component : $jupyterBtn, tooltip: "Create Jupyter notebook" }); } diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookController.js new file mode 100644 index 00000000000..3b72c0b195c --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookController.js @@ -0,0 +1,29 @@ +/* + * Copyright 2014 ETH Zuerich, Scientific IT Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function JupyterNotebookController(entity) { + this._jupyterNotebookModel = new JupyterNotebookModel(entity); + this._jupyterNotebookView = new JupyterNotebookView(this, this._jupyterNotebookModel); + + this.init = function() { + this._jupyterNotebookView.repaint(); + } + + this.create = function(workspace, notebook, datasets) { + JupyterUtil.createJupyterNotebookAndOpen(workspace, notebook, datasets); + 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/JupyterNotebookModel.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookModel.js new file mode 100644 index 00000000000..d18c58734ac --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookModel.js @@ -0,0 +1,19 @@ +/* + * Copyright 2014 ETH Zuerich, Scientific IT Services + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function JupyterNotebookModel(entity) { + this.entity = entity; +} \ 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/JupyterNotebookView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookView.js new file mode 100644 index 00000000000..81fccfedb93 --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterNotebookView.js @@ -0,0 +1,73 @@ +/* + * Copyright 2014 ETH Zuerich, Scientific IT Services + * + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function JupyterNotebookView(jupyterNotebookController, jupyterNotebookModel) { + this._jupyterNotebookController = jupyterNotebookController; + this._jupyterNotebookModel = jupyterNotebookModel; + + this.repaint = function() { + var _this = this; + var $window = $('<form>', { 'action' : 'javascript:void(0);' }); + + $window.append($('<legend>').append("Create Jupyter Notebook")); + var $treeContainer = $('<div>'); + $window.append(FormUtil.getFieldForLabelWithText("Included Datasets (*) ", "")); + $window.append($treeContainer); + var treeEntityModel = { title : Util.getDisplayNameForEntity(this._jupyterNotebookModel.entity), entityType: "DATASET", key : this._jupyterNotebookModel.entity.code, folder : false, lazy : false, icon : "fa fa-database" }; + var tree = TreeUtil.getTreeFromModel($treeContainer, [treeEntityModel]); + + + var $workspace = FormUtil._getInputField('text', null, 'workspace Name', null, true); + var $notebookName = FormUtil._getInputField('text', null, 'notebook Name', null, true); + $window.append(FormUtil.getFieldForComponentWithLabel($workspace, "Workspace")); + $window.append(FormUtil.getFieldForComponentWithLabel($notebookName, "Notebook Name")); + + var $btnAccept = $('<input>', { 'type': 'submit', 'class' : 'btn btn-primary', 'value' : 'Accept' }); + $window.submit(function() { + var selectedNodes = $(tree).fancytree('getTree').getSelectedNodes(); + var notebookDatasets = []; + for(var eIdx = 0; eIdx < selectedNodes.length; eIdx++) { + var node = selectedNodes[eIdx]; + if(node.data.entityType === "DATASET") { + notebookDatasets.push(node.key); + } + } + if(notebookDatasets.length > 0) { + _this._jupyterNotebookController.create($workspace.val(), $notebookName.val(), notebookDatasets); + } else { + Util.showError("Select at least one dataset.", function() {}, true); + } + + }); + var $btnCancel = $('<a>', { 'class' : 'btn btn-default' }).append('Cancel'); + $btnCancel.click(function() { + Util.unblockUI(); + }); + + $window.append($btnAccept).append(' ').append($btnCancel); + + var css = { + 'text-align' : 'left', + 'top' : '15%', + 'width' : '70%', + 'left' : '15%', + 'right' : '20%', + 'overflow' : 'hidden' + }; + + Util.blockUI($window, css); + } +} \ No newline at end of file -- GitLab