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 48f8549ba0ca5fc196b1daab0dc6da99e5709ff4..500d275fc7b91a211457fb8a540d73a754627f5b 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 @@ -185,6 +185,9 @@ <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/JupyterCopyNotebookController.js"></script> + <script type="text/javascript" src="./js/views/DataSetForm/widgets/JupyterCopyNotebookModel.js"></script> + <script type="text/javascript" src="./js/views/DataSetForm/widgets/JupyterCopyNotebookView.js"></script> <script type="text/javascript" src="./js/views/DataSetForm/widgets/ImagePreviewIconLoader.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 366e6c6cfcbdf99662fd110c629a1318e95e2900..81a0a71fccfaca5924436447bb6a60c0e23dcc47 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,6 +16,31 @@ var JupyterUtil = new function() { + this.copyNotebook = function(datasetCode, notebookURL) { + var jupyterNotebook = new JupyterCopyNotebookController(datasetCode, notebookURL); + jupyterNotebook.init(); + } + + this.openJupyterNotebookFromTemplate = function(folder, fileName, template) { + 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, + type : 'POST', + crossDomain: true, + data : template, + success : function(result) { + var win = window.open(jupyterNotebookURL + result.fileName, '_blank'); + win.focus(); + }, + error : function(result) { + alert("error: " + JSON.stringify(result)); + } + }); + } + this.createJupyterNotebookAndOpen = function(folder, fileName, dataSetIds) { fileName = fileName + ".ipynb"; var jupyterURL = profile.jupyterIntegrationServerEndpoint + "?token=" + mainController.serverFacade.openbisServer.getSession() + "&folder=" + folder + "&filename=" + fileName; @@ -26,12 +51,8 @@ var JupyterUtil = new function() { url : jupyterURL, type : 'POST', crossDomain: true, -// processData : false, -// dataType: 'json', -// contentType: 'application/json', data : JSON.stringify(newJupyterNotebook), success : function(result) { - //alert("success:" + JSON.stringify(result)); var win = window.open(jupyterNotebookURL + result.fileName, '_blank'); win.focus(); }, diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerModel.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerModel.js index 8be369b97cb4be7a285804e39f8a7a89cadfbf46..042544cb906857b70ea1e2822fcff642a0edbf2b 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerModel.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerModel.js @@ -66,6 +66,10 @@ function DataSetViewerModel(containerId, profile, entity, serverFacade, datastor this._isIconableImage = function(pathInDataSet) { return this._hasExtension(pathInDataSet, ["jpg", "jpeg", "png", "gif"]); } + + this._isJupyterNotebook = function(pathInDataSet) { + return this._hasExtension(pathInDataSet, ["ipynb"]); + } this._hasExtension = function(pathInDataSet, extensions) { var haveExtension = pathInDataSet.lastIndexOf("."); @@ -92,6 +96,15 @@ function DataSetViewerModel(containerId, profile, entity, serverFacade, datastor return directLinkComponent; } + this.getJupyterNotebookLink = function(datasetCode, datasetFile) { + if(this._isJupyterNotebook(datasetFile.pathInDataSet)) { + var notebookURL = profile.getDefaultDataStoreURL() + "/" + datasetCode + "/" + datasetFile.pathInDataSet + "?sessionID=" + mainController.serverFacade.getSession(); + var onclick = "JupyterUtil.copyNotebook(\"" + datasetCode + "\",\"" + notebookURL + "\");" + return "<span onclick='" + onclick + "' class='glyphicon glyphicon-log-in'></span>"; + } + return null; + } + this.getPreviewLink = function(datasetCode, datasetFile) { if(this._isPreviewableImage(datasetFile.pathInDataSet)) { var imageURLAsString = this.getImageUrl(datasetCode, datasetFile); diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerView.js index 69927b0b9ecaf18134824ba6678f21b4367629b3..df88d0faec549fe95187a3070f23b27082585767 100644 --- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerView.js +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/DatasetViewerView.js @@ -171,6 +171,10 @@ function DataSetViewerView(dataSetViewerController, dataSetViewerModel) { if (previewLink) { titleValue = previewLink + " " + titleValue; } + var notebookLink = _this._dataSetViewerModel.getJupyterNotebookLink(code, file); + if (profile.jupyterOpenbisEndpoint && notebookLink) { + titleValue = notebookLink + " " + titleValue; + } } results.push({ // node properties 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 new file mode 100644 index 0000000000000000000000000000000000000000..2b096a86d09091dc2f503e613c579a62f86c99da --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookController.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 JupyterCopyNotebookController(datasetCode, existingNotebookURL) { + this._jupyterNotebookModel = new JupyterCopyNotebookModel(datasetCode, existingNotebookURL); + this._jupyterNotebookView = new JupyterCopyNotebookView(this, this._jupyterNotebookModel); + + this.init = function() { + this._jupyterNotebookView.repaint(); + } + + this.create = function(workspace, notebook, existingNotebookURL) { + JupyterUtil.openJupyterNotebookFromTemplate(workspace, notebook, existingNotebookURL); + 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/JupyterCopyNotebookModel.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookModel.js new file mode 100644 index 0000000000000000000000000000000000000000..84362e021e605a6808da8b15cdd777cef240389b --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookModel.js @@ -0,0 +1,20 @@ +/* + * 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 JupyterCopyNotebookModel(datasetCode, existingNotebookURL) { + this.datasetCode = datasetCode; + this.existingNotebookURL = existingNotebookURL; +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..b55edfbc0e6496b2818f48616e755ff79609c056 --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/widgets/JupyterCopyNotebookView.js @@ -0,0 +1,56 @@ +/* + * 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 JupyterCopyNotebookView(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("Use Jupyter Notebook as Template")); + $window.append(FormUtil.getFieldForLabelWithText("Notebook", this._jupyterNotebookModel.existingNotebookURL)); + 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() { + $.get(_this._jupyterNotebookModel.existingNotebookURL, function( data ) { + _this._jupyterNotebookController.create($workspace.val(), $notebookName.val(), data); + }); + }); + 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