diff --git a/jupyter-openbis-extension/static/connectionDialog.js b/jupyter-openbis-extension/static/connectionDialog.js index 700ade9865d855b0a5395d4fac7483adb157289b..40c88225a504b0971efb6bb05afcbed4a8c652da 100644 --- a/jupyter-openbis-extension/static/connectionDialog.js +++ b/jupyter-openbis-extension/static/connectionDialog.js @@ -9,7 +9,7 @@ define( var currentDownloadPath = null - function show_available_connections(env, data, conn_table, onclick_cbf) { + function show_available_connections(env, data, conn_table) { if (!currentDownloadPath) { currentDownloadPath = data.cwd } @@ -24,6 +24,15 @@ define( } tbody = table.createTBody() + + var getConnectionByName = function(name) { + for (connection of data.connections) { + if(connection.name === name) { + return connection; + } + } + } + for (connection of data.connections) { var conn = document.createElement("INPUT") conn.type = "radio" @@ -32,12 +41,9 @@ define( conn.setAttribute("url", connection.url) conn.checked = connection.name === state.connection.candidateName; - if (onclick_cbf === undefined) { - conn.onclick = function () { - state.connection.candidateName = this.value - } - } else { - conn.onclick = onclick_cbf + conn.onclick = function () { + state.connection.candidateName = this.value + state.connection.candidateDTO = getConnectionByName(state.connection.candidateName); } var row = tbody.insertRow() @@ -206,13 +212,9 @@ define( var input_fields = document.createElement("DIV") conn_table.id = "openbis_connections" - var onclick_cbf = function () { - state.connection.candidateName = this.value - } - connections.list(env) .done(function (data) { - show_available_connections(env, data, conn_table, onclick_cbf) + show_available_connections(env, data, conn_table) }) .fail(function (data) { alert(data.status) @@ -222,10 +224,12 @@ define( function onOk() { state.connection.name = state.connection.candidateName + state.connection.dto = state.connection.candidateDTO } function onCancel() { state.connection.candidateName = state.connection.name + state.connection.candidateDTO = state.connection.dto } dialog.modal({ diff --git a/jupyter-openbis-extension/static/downloadDialog.js b/jupyter-openbis-extension/static/downloadDialog.js index 4525d737edeaa38fc39a717fa2d51b7c7ab4471d..304d4a7f75b6a608b9dee59f21bba066a4fb8863 100644 --- a/jupyter-openbis-extension/static/downloadDialog.js +++ b/jupyter-openbis-extension/static/downloadDialog.js @@ -1,9 +1,10 @@ define([ "base/js/dialog", "./common", - "./state" + "./state", + "./entitySearcher" ], - function (dialog, common, state) { + function (dialog, common, state, entitySearcher) { var spinner = document.createElement("IMG") spinner.className="openbis-feedback" @@ -171,6 +172,9 @@ define([ showDataSets.appendChild(title) showDataSets.style.marginTop = '10px' + // TODO Build and replace this component + // var entityIdentifier = entitySearcher.getEntitySearcher(state) + var entityIdentifier = document.createElement("INPUT") entityIdentifier.type = "text" entityIdentifier.name = "entityIdentifier" diff --git a/jupyter-openbis-extension/static/entitySearcher.js b/jupyter-openbis-extension/static/entitySearcher.js new file mode 100644 index 0000000000000000000000000000000000000000..2c1c57044f5fc9e544226e44a016b39612e434c9 --- /dev/null +++ b/jupyter-openbis-extension/static/entitySearcher.js @@ -0,0 +1,65 @@ +define([], + function () { + return { + loadJSResorce(pathToResource, onLoad) { + var head = document.getElementsByTagName('head')[0]; + var script= document.createElement('script'); + script.type= 'text/javascript'; + var src = pathToResource; + script.src= src; + script.onreadystatechange= function () { + if (this.readyState == 'complete') onLoad(); + } + script.onload = onLoad; + + head.appendChild(script); + }, + getRequireJSV3Config(baseURL) { + return { + baseUrl : baseURL + "/openbis/resources/api/v3", + paths : { + "stjs" : "lib/stjs/js/stjs", + "underscore" : "lib/underscore/js/underscore", + "moment" : "lib/moment/js/moment" + }, + shim : { + "stjs" : { + exports : "stjs", + deps : [ "underscore" ] + }, + "underscore" : { + exports : "_" + } + } + } + }, + getEntitySearcher(state) { + var _this = this; + var connection_name = state.connection.name + if (!connection_name) { + alert('Please choose a connection') + return false + } + + if(!state.openbisService) { + var config = this.getRequireJSV3Config(state.connection.dto.url) + require.config(config) + require(['openbis'], function(openbis) { + var apiUrl = state.connection.dto.url + "/openbis/openbis/rmi-application-server-v3.json" + var v3 = new openbis(apiUrl) + v3.login(state.connection.dto.username, state.connection.dto.password) + .done(function(sessionToken) { + state.openbisService = v3 + alert('openbis v3 service login succeed for ' + apiUrl +' : trusted-cross-origin-domains is set.') + }).fail(function(result) { + alert('openbis v3 service login failed for ' + apiUrl +' : trusted-cross-origin-domains is probably not set.') + }); + }); + } + + var element = document.createElement("SPAN") + return element + } + } + } +) \ No newline at end of file diff --git a/jupyter-openbis-extension/static/state.js b/jupyter-openbis-extension/static/state.js index 70671d691bb7413b22f2248d438ded2da7c94235..2a0f35c8254ced361b30f7c9f122c8affb5b41f0 100644 --- a/jupyter-openbis-extension/static/state.js +++ b/jupyter-openbis-extension/static/state.js @@ -4,7 +4,9 @@ define([], // connection dialog connection: { name: null, - candidateName: null + dto: null, + candidateName: null, + candidateDTO: null }, // upload dialog @@ -19,7 +21,10 @@ define([], // download dialog selectedDatasets: new Set([]), entityIdentifier: '', - workingDirectory: '' + workingDirectory: '', + + // openBIS v3 connection + openBISV3 : null } } ) \ No newline at end of file