Skip to content
Snippets Groups Projects
Commit eac971cc authored by juanf's avatar juanf
Browse files

SSDM-4223 : Existing Jupyter notebooks in datasets can be reopened

SVN: 38677
parent 4b7b28cf
No related branches found
No related tags found
No related merge requests found
Showing
with 150 additions and 4 deletions
...@@ -185,6 +185,9 @@ ...@@ -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/JupyterNotebookController.js"></script>
<script type="text/javascript" src="./js/views/DataSetForm/widgets/JupyterNotebookModel.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/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> <script type="text/javascript" src="./js/views/DataSetForm/widgets/ImagePreviewIconLoader.js"></script>
......
...@@ -16,6 +16,31 @@ ...@@ -16,6 +16,31 @@
var JupyterUtil = new function() { 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) { this.createJupyterNotebookAndOpen = function(folder, fileName, dataSetIds) {
fileName = fileName + ".ipynb"; fileName = fileName + ".ipynb";
var jupyterURL = profile.jupyterIntegrationServerEndpoint + "?token=" + mainController.serverFacade.openbisServer.getSession() + "&folder=" + folder + "&filename=" + fileName; var jupyterURL = profile.jupyterIntegrationServerEndpoint + "?token=" + mainController.serverFacade.openbisServer.getSession() + "&folder=" + folder + "&filename=" + fileName;
...@@ -26,12 +51,8 @@ var JupyterUtil = new function() { ...@@ -26,12 +51,8 @@ var JupyterUtil = new function() {
url : jupyterURL, url : jupyterURL,
type : 'POST', type : 'POST',
crossDomain: true, crossDomain: true,
// processData : false,
// dataType: 'json',
// contentType: 'application/json',
data : JSON.stringify(newJupyterNotebook), data : JSON.stringify(newJupyterNotebook),
success : function(result) { success : function(result) {
//alert("success:" + JSON.stringify(result));
var win = window.open(jupyterNotebookURL + result.fileName, '_blank'); var win = window.open(jupyterNotebookURL + result.fileName, '_blank');
win.focus(); win.focus();
}, },
......
...@@ -66,6 +66,10 @@ function DataSetViewerModel(containerId, profile, entity, serverFacade, datastor ...@@ -66,6 +66,10 @@ function DataSetViewerModel(containerId, profile, entity, serverFacade, datastor
this._isIconableImage = function(pathInDataSet) { this._isIconableImage = function(pathInDataSet) {
return this._hasExtension(pathInDataSet, ["jpg", "jpeg", "png", "gif"]); return this._hasExtension(pathInDataSet, ["jpg", "jpeg", "png", "gif"]);
} }
this._isJupyterNotebook = function(pathInDataSet) {
return this._hasExtension(pathInDataSet, ["ipynb"]);
}
this._hasExtension = function(pathInDataSet, extensions) { this._hasExtension = function(pathInDataSet, extensions) {
var haveExtension = pathInDataSet.lastIndexOf("."); var haveExtension = pathInDataSet.lastIndexOf(".");
...@@ -92,6 +96,15 @@ function DataSetViewerModel(containerId, profile, entity, serverFacade, datastor ...@@ -92,6 +96,15 @@ function DataSetViewerModel(containerId, profile, entity, serverFacade, datastor
return directLinkComponent; 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) { this.getPreviewLink = function(datasetCode, datasetFile) {
if(this._isPreviewableImage(datasetFile.pathInDataSet)) { if(this._isPreviewableImage(datasetFile.pathInDataSet)) {
var imageURLAsString = this.getImageUrl(datasetCode, datasetFile); var imageURLAsString = this.getImageUrl(datasetCode, datasetFile);
......
...@@ -171,6 +171,10 @@ function DataSetViewerView(dataSetViewerController, dataSetViewerModel) { ...@@ -171,6 +171,10 @@ function DataSetViewerView(dataSetViewerController, dataSetViewerModel) {
if (previewLink) { if (previewLink) {
titleValue = previewLink + " " + titleValue; titleValue = previewLink + " " + titleValue;
} }
var notebookLink = _this._dataSetViewerModel.getJupyterNotebookLink(code, file);
if (profile.jupyterOpenbisEndpoint && notebookLink) {
titleValue = notebookLink + " " + titleValue;
}
} }
results.push({ results.push({
// node properties // node properties
......
/*
* 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
/*
* 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
/*
* 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('&nbsp;').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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment