From f7ccdd7c74433690dcfe63b87ace7eb6081f32fc Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 2 Nov 2017 16:08:38 -0400 Subject: [PATCH] Fix jupyter javascript; this all needs a ton of disentanglement and standardization. --- .../galaxy.interactive_environments.js | 17 ++++++++-------- .../jupyter/static/js/jupyter.js | 20 ++++++++++--------- .../jupyter/templates/jupyter.mako | 4 +++- .../galaxy.interactive_environments.js.map | 2 +- .../galaxy.interactive_environments.js | 2 +- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/client/galaxy/scripts/galaxy.interactive_environments.js b/client/galaxy/scripts/galaxy.interactive_environments.js index d1d6d602c19..3ca46341f10 100644 --- a/client/galaxy/scripts/galaxy.interactive_environments.js +++ b/client/galaxy/scripts/galaxy.interactive_environments.js @@ -1,29 +1,30 @@ /** * Internal function to remove content from the main area and add the notebook. * Not idempotent + * TODO: This isn't just internal, some notebooks are calling it? */ -function append_notebook(url) { +export function append_notebook(url) { clear_main_area(); $("#main").append( `` ); } -function clear_main_area() { +export function clear_main_area() { $("#spinner").remove(); $("#main") .children() .remove(); } -function display_spinner() { +export function display_spinner() { $("#main").append( `` ); } /* Create a spin_state object used by spin() and spin_again() */ -function make_spin_state( +export function make_spin_state( type, ajax_timeout_init, ajax_timeout_max, @@ -51,7 +52,7 @@ function make_spin_state( } /* Log/display an error when spinning fails. */ -function spin_error(console_msg, user_msg, clear) { +export function spin_error(console_msg, user_msg, clear) { console.log(console_msg); if (clear) clear_main_area(); if (typeof user_msg == "string") { @@ -84,7 +85,7 @@ function spin_again(spin_state) { * returns `true`, the condition is considered "resolved" and spinning stops. Otherwise, continue spinning, increasing * AJAX timeouts and/or sleep values as configured in the spin_state. */ -function spin( +export function spin( url, bool_response, success_callback, @@ -201,7 +202,7 @@ function spin_until( * @param {String} callback: function to call once successfully connected. * */ -function test_ie_availability(url, success_callback) { +export function test_ie_availability(url, success_callback) { var messages = { success: "IE connection succeeded, returning", waiting: @@ -222,7 +223,7 @@ function test_ie_availability(url, success_callback) { * @param {String} callback: function to call once successfully connected. * */ -export default function load_when_ready(url, success_callback) { +export function load_when_ready(url, success_callback) { var messages = { success: "Galaxy reports IE container ready, returning", not_ready: diff --git a/config/plugins/interactive_environments/jupyter/static/js/jupyter.js b/config/plugins/interactive_environments/jupyter/static/js/jupyter.js index d4407d1a712..061aed4bf02 100644 --- a/config/plugins/interactive_environments/jupyter/static/js/jupyter.js +++ b/config/plugins/interactive_environments/jupyter/static/js/jupyter.js @@ -1,3 +1,5 @@ +var IES = window.IES; + function message_failed_auth(password){ toastr.info( "Automatic authorization failed. You can manually login with:
" + password + "
More details ...", @@ -36,7 +38,7 @@ function message_no_auth(){ function load_notebook(password, notebook_login_url, notebook_access_url){ // Test notebook_login_url for accessibility, executing the login+load function whenever // we've successfully connected to the IE. - test_ie_availability(notebook_login_url, function(){ + IES.test_ie_availability(notebook_login_url, function(){ _handle_notebook_loading(password, notebook_login_url, notebook_access_url); keep_alive(); }); @@ -53,10 +55,10 @@ function keep_alive(){ var count_max = 60; // we sleep 15 seconds between requests and the default timeout for the Jupyter container is 120 seconds, so start // with a pretty high ajax timeout. sleep starts low because we want to get the warning up pretty quickly - var spin_state = make_spin_state("IE keepalive", 8000, 16000, 2000, 5000, 15000, 5000, false); + var spin_state = IES.make_spin_state("IE keepalive", 8000, 16000, 2000, 5000, 15000, 5000, false); var success = function(){ console.log("IE keepalive request succeeded"); - toastr.clear() + toastr.clear(); if(spin_state.count >= warn_at){ toastr.clear(); toastr.success( @@ -81,12 +83,12 @@ function keep_alive(){ ); return false; // keep spinning }else if(spin_state.count >= count_max){ - spin_error("IE keepalive failure limit reached", "Lost connection to interactive environment, contact your administrator", false); + IES.spin_error("IE keepalive failure limit reached", "Lost connection to interactive environment, contact your administrator", false); return true; // stop spinning } } console.log("IE keepalive worker starting"); - spin(notebook_access_url, false, success, timeout_error, timeout_error, spin_state); + IES.spin(notebook_access_url, false, success, timeout_error, timeout_error, spin_state); } @@ -109,17 +111,17 @@ function _handle_notebook_loading(password, notebook_login_url, notebook_access_ }, // If that is successful, load the notebook success: function(){ - append_notebook(notebook_access_url); + IES.append_notebook(notebook_access_url); }, error: function(jqxhr, status, error){ if(ie_password_auth){ // Failure happens due to CORS message_failed_auth(password); - append_notebook(notebook_access_url); + IES.append_notebook(notebook_access_url); }else{ message_failed_connection(); // Do we want to try and load the notebook anyway? Just in case? - append_notebook(notebook_access_url); + IES.append_notebook(notebook_access_url); } } }); @@ -127,6 +129,6 @@ function _handle_notebook_loading(password, notebook_login_url, notebook_access_ else { // Not using password auth, just embed it to avoid content-origin issues. message_no_auth(); - append_notebook(notebook_access_url); + IES.append_notebook(notebook_access_url); } } diff --git a/config/plugins/interactive_environments/jupyter/templates/jupyter.mako b/config/plugins/interactive_environments/jupyter/templates/jupyter.mako index 420a990c326..623f9d3498a 100644 --- a/config/plugins/interactive_environments/jupyter/templates/jupyter.mako +++ b/config/plugins/interactive_environments/jupyter/templates/jupyter.mako @@ -61,7 +61,9 @@ ${ ie.plugin_require_config() } // Load notebook requirejs(['galaxy.interactive_environments', 'plugin/jupyter'], function(IES){ - IES.default(ie_readiness_url, function(){ + // This global is not awesome, get rid of it when possible (when IES are a part of the build process) + window.IES = IES; + IES.load_when_ready(ie_readiness_url, function(){ load_notebook(ie_password, notebook_login_url, notebook_access_url); }); }); diff --git a/static/maps/galaxy.interactive_environments.js.map b/static/maps/galaxy.interactive_environments.js.map index 482e0a272fe..3d39b702575 100644 --- a/static/maps/galaxy.interactive_environments.js.map +++ b/static/maps/galaxy.interactive_environments.js.map @@ -1 +1 @@ -{"version":3,"sources":["galaxy.interactive_environments.js"],"names":["clear_main_area","$","children","remove","append","galaxy_root","make_spin_state","type","ajax_timeout_init","ajax_timeout","ajax_timeout_max","ajax_timeout_step","sleep","sleep_max","timeOut","count","user_msg","spin_error","console","console_msg","sleep_init","sleep_step","toastr","log_attempts","clear","log","spin_again","spin_state","url","spinner","ajax_params","window","setTimeout","spin","error","bool_response","success_callback","error_callback","xhrFields","withCredentials","success","data","status","jqxhr","messages","display_spinner","info","tapToDismiss","ajax","wrapped_success","message_once","closeButton","extendedTimeOut","timeout_error","not_ready","warning","load_when_ready","waiting","wait_warn","test_ie_availability","spin_until","unknown_response"],"mappings":"8EAIA,SAAAA,IACIA,EAAAA,YAAAA,SACAC,EAAAA,SAGHC,WAMQC,SAFLF,SAAAA,IAGHA,EAAA,SAAAG,OAAA,0BAIiCC,YAJjC,wGAQD,SAAAC,EACAC,EAUIC,EACID,EACAE,EAEAC,EAEAC,EAEAC,EACAC,GAgBIC,OAbJC,UAAO,IAAAR,EAAAA,EAAA,WAZHE,kBAcR,IAAAD,EAAAA,EAAA,IACHE,sBAVuC,IAArBA,EAAmCA,EAAmB,KAYzEC,uBACiCK,IAAxBC,EAAyCN,EAAA,IAC9CO,WAAA,IAAYC,EAAZC,EAAA,IACAP,eAAWb,IAAAA,EAAAA,EAAAA,IACXqB,gBAAiC,IAA7BA,EAA6BA,EAAA,IAC7BC,kBAAA,IAAAC,GAAAA,EACAD,MAAAA,GAMH,SAAAL,EAAAE,EAAAH,EAAAQ,GACJN,QAAAO,IAAAN,GAVOK,GAAOxB,IAYf,iBAAAgB,IACAM,OAASI,QACLJ,OAAIK,MAAAA,EAAmBA,SACnBA,aAAWf,EACdE,QAAA,EACGa,gBAAWJ,EACXL,cACOS,KANf,SAASD,EAAWC,GACZA,EAAWf,MAAQe,EAAWd,YAC9Bc,EAAWf,OAASe,EAAWN,YAgBvCM,EACIC,cAOAV,QAAIW,IACAF,EAAIG,KADR,YACsBH,EAAAZ,MADtB,oBACsBY,EAAAlB,aADtB,eACsBkB,EAAAf,MACdgB,IAFR,KAGmBG,OAAAC,WAFGL,EAAAE,QAAAF,EAAAf,OAYb,SAAAqB,EACDC,EACIC,EACIC,EACIT,EACHU,EACDV,GAGH,IAAAE,EAAA,WACGF,IAAAA,GACAC,IAAAA,EAEHU,WACJC,iBAAA,GAELhC,KAAI4B,MACJlC,QAAO6B,EAAP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hBc,SAAyBC,EAAKQ,GAezCwB,EAAWhC,GAAK,GAbZY,QAAS,+CACTc,UACI,+FACJO,iBACI,oHACJJ,QACI,+FACJC,UACI,kLACJxB,MACI,wJAGwBE,EADf9B,EAAgB","file":"../scripts/galaxy.interactive_environments.js","sourcesContent":["/**\n * Internal function to remove content from the main area and add the notebook.\n * Not idempotent\n */\nfunction append_notebook(url) {\n clear_main_area();\n $(\"#main\").append(\n ``\n );\n}\n\nfunction clear_main_area() {\n $(\"#spinner\").remove();\n $(\"#main\")\n .children()\n .remove();\n}\n\nfunction display_spinner() {\n $(\"#main\").append(\n ``\n );\n}\n\n/* Create a spin_state object used by spin() and spin_again() */\nfunction make_spin_state(\n type,\n ajax_timeout_init,\n ajax_timeout_max,\n ajax_timeout_step,\n sleep_init,\n sleep_max,\n sleep_step,\n log_attempts\n) {\n var s = {\n type: typeof type !== \"undefined\" ? type : \"GIE spin\",\n ajax_timeout:\n typeof ajax_timeout_init !== \"undefined\" ? ajax_timeout_init : 2000,\n ajax_timeout_max:\n typeof ajax_timeout_max !== \"undefined\" ? ajax_timeout_max : 16000,\n ajax_timeout_step:\n typeof ajax_timeout_step !== \"undefined\" ? ajax_timeout_step : 500,\n sleep: typeof sleep_init !== \"undefined\" ? sleep_init : 500,\n sleep_max: typeof sleep_max !== \"undefined\" ? sleep_max : 8000,\n sleep_step: typeof sleep_step !== \"undefined\" ? sleep_step : 100,\n log_attempts: typeof log_attempts !== \"undefined\" ? log_attempts : true,\n count: 0\n };\n return s;\n}\n\n/* Log/display an error when spinning fails. */\nfunction spin_error(console_msg, user_msg, clear) {\n console.log(console_msg);\n if (clear) clear_main_area();\n if (typeof user_msg == \"string\") {\n toastr.clear();\n toastr.error(user_msg, \"Error\", {\n closeButton: true,\n timeOut: 0,\n extendedTimeOut: 0,\n tapToDismiss: false\n });\n }\n}\n\n/* Increase sleep time and spin again. */\nfunction spin_again(spin_state) {\n if (spin_state.sleep < spin_state.sleep_max) {\n spin_state.sleep += spin_state.sleep_step;\n }\n if (spin_state.log_attempts) {\n console.log(\n `${spin_state.type} request ${spin_state.count} request timeout ${spin_state.ajax_timeout}ms sleeping ${spin_state.sleep /\n 1000}s`\n );\n }\n window.setTimeout(spin_state.spinner, spin_state.sleep);\n}\n\n/*\n * Spin on a URL as long as it times out, otherwise, call the provided success or error callback. If the callback\n * returns `true`, the condition is considered \"resolved\" and spinning stops. Otherwise, continue spinning, increasing\n * AJAX timeouts and/or sleep values as configured in the spin_state.\n */\nfunction spin(\n url,\n bool_response,\n success_callback,\n timeout_callback,\n error_callback,\n spin_state\n) {\n var spinner = () => {\n var ajax_params = {\n url: url,\n xhrFields: {\n withCredentials: true\n },\n type: \"GET\",\n timeout: spin_state.ajax_timeout,\n success: function(data, status, jqxhr) {\n if (!success_callback(data, status, jqxhr)) {\n spin_state.count++;\n spin_again(spin_state);\n }\n },\n error: function(jqxhr, status, error) {\n if (status == \"timeout\") {\n if (spin_state.ajax_timeout < spin_state.ajax_timeout_max) {\n spin_state.ajax_timeout += spin_state.ajax_timeout_step;\n }\n spin_state.count++;\n if (!timeout_callback(jqxhr, status, error))\n spin_again(spin_state);\n } else {\n spin_state.count++;\n if (!error_callback(jqxhr, status, error))\n spin_again(spin_state);\n }\n }\n };\n if (bool_response) ajax_params[\"dataType\"] = \"json\";\n $.ajax(ajax_params);\n };\n console.log(`Setting up new spinner for ${spin_state.type} on ${url}`);\n spin_state.spinner = spinner;\n window.setTimeout(spinner, spin_state.sleep);\n}\n\n/*\n * Spin on a URL forever until there is an acceptable response. \n * @param {String} url: URL to test response of. Must return a 200 (302->200 is OK).\n * @param {Boolean} bool_response: If set to `true`, do not stop spinning until the response is `true`. Otherwise, stop\n * as soon as a successful response is received.\n */\nfunction spin_until(\n url,\n bool_response,\n messages,\n success_callback,\n spin_state\n) {\n var warn_at = 40; // ~2 mins\n var message_once = (message, spin_state) => {\n if (spin_state.count == 1) {\n display_spinner();\n toastr.info(message, null, {\n closeButton: true,\n timeOut: 0,\n extendedTimeOut: 0,\n tapToDismiss: false\n });\n }\n };\n var wrapped_success = data => {\n if (!bool_response || (bool_response && data == true)) {\n console.log(messages[\"success\"]);\n clear_main_area();\n toastr.clear();\n success_callback();\n } else if (bool_response && data == false) {\n message_once(messages[\"not_ready\"], spin_state);\n return false; // keep spinning\n } else {\n spin_error(\n `Invalid response to ${spin_state.type} request`,\n messages[\"invalid_response\"],\n true\n );\n }\n return true; // stop spinning\n };\n var timeout_error = (jqxhr, status, error) => {\n message_once(messages[\"waiting\"], spin_state);\n if (spin_state.count == warn_at) {\n toastr.warning(messages[\"wait_warn\"], \"Warning\", {\n closeButton: true,\n timeOut: 0,\n extendedTimeOut: 0,\n tapToDismiss: false\n });\n }\n return false; // keep spinning\n };\n spin(\n url,\n bool_response,\n wrapped_success,\n timeout_error,\n timeout_error,\n spin_state\n );\n}\n\n/**\n * Test availability of a URL, and call a callback when done.\n * http://stackoverflow.com/q/25390206/347368\n * @param {String} url: URL to test availability of. Must return a 200 (302->200 is OK).\n * @param {String} callback: function to call once successfully connected.\n *\n */\nfunction test_ie_availability(url, success_callback) {\n var messages = {\n success: \"IE connection succeeded, returning\",\n waiting:\n \"Interactive environment container is running, attempting to connect to the IE. Please wait...\",\n wait_warn:\n \"It is taking an usually long time to connect to the interactive environment. Attempts will continue but you may want to report this condition to a Galaxy administrator if it does not succeed soon.\",\n error:\n \"An error was encountered while attempting to connect to the interactive environment, contact your administrator.\"\n };\n var spin_state = make_spin_state(\"IE availability\");\n spin_until(url, false, messages, success_callback, spin_state);\n}\n\n/**\n * Test a boolean (json) response from a URL, and call a callback when done.\n * http://stackoverflow.com/q/25390206/347368\n * @param {String} url: URL to test response of. Must return a 200 (302->200 is OK) and either `true` or `false`.\n * @param {String} callback: function to call once successfully connected.\n *\n */\nexport default function load_when_ready(url, success_callback) {\n var messages = {\n success: \"Galaxy reports IE container ready, returning\",\n not_ready:\n \"Galaxy is launching a container in which to run this interactive environment. Please wait...\",\n unknown_response:\n \"Galaxy failed to launch a container in which to run this interactive environment, contact a Galaxy administrator.\",\n waiting:\n \"Galaxy is launching a container in which to run this interactive environment. Please wait...\",\n wait_warn:\n \"It is taking an usually long time to start a container. Attempts will continue but you may want to report this condition to a Galaxy administrator if it does not succeed soon.\",\n error:\n \"Galaxy encountered an error while attempting to determine the readiness of this interactive environment's container, contact a Galaxy administrator.\"\n };\n var spin_state = make_spin_state(\"IE container readiness\");\n spin_until(url, true, messages, success_callback, spin_state);\n}\n"]} \ No newline at end of file +{"version":3,"sources":["galaxy.interactive_environments.js"],"names":["test_ie_availability","$","load_when_ready","children","remove","append_notebook","clear_main_area","galaxy_root","make_spin_state","type","ajax_timeout_init","ajax_timeout_max","sleep_init","sleep_max","sleep_step","log_attempts","ajax_timeout","ajax_timeout_step","sleep","count","toastr","console_msg","user_msg","clear","closeButton","timeOut","extendedTimeOut","tapToDismiss","spin_again","spin_state","console","log","window","setTimeout","spinner","timeout","success","success_callback","error","ajax_params","url","withCredentials","jqxhr","error_callback","status","timeout_callback","message_once","message","ajax","messages","spin_error","display_spinner","timeout_error","wait_warn","spin_until","spin","bool_response","data","not_ready","unknown_response","waiting"],"mappings":"8EAYO,SAgMSA,IA/LZC,EAAE,YAoNUC,SAjOhBD,EAAA,SAeSE,WACAC,SAXF,SAASC,IACZC,EAAAA,SAAAA,OAAAA,0BACAC,YADAD,wGAQAL,SAAEO,EAGLC,EAWGC,EATGC,EACHV,EAGHW,EASGC,EAPJC,EACOC,GA4BA,OAhBCC,UACI,IADJA,EACWN,EAAP,WACJC,kBAGWM,IADXA,EACIP,EAA2CO,IAC/CC,sBACW,IAAXL,EAAgCF,EAA0B,KAC1DG,uBACqBC,IAArBA,EAAsCE,EAAcF,IACpDI,WAAO,IAAAP,EAAAA,EAAA,IAZHC,eAAR,IAAAA,EAAAA,EAAA,IAcAC,gBAAA,IAAAA,EAAAA,EAAA,IACHC,kBAAA,IAAAA,GAAAA,EAHOI,MAAO,GAUPC,SAAAA,EAAAC,EAAAC,EAAAC,G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BAAe6B,EACXzB,cAAAA,MA8BR6B,EACI,SAAAX,EAAAE,EAAAN,GAzBJ,OA0BAA,EACIW,EAAA,QAAApB,GA7CAqB,IAsCRrB,EAAAV,OASIU,OAAAA,QAAarB,EAAAA,UAAgB,WACjC8C,aAAA,EACH7B,QAAA,EAnCeC,gBAAiB,EAqCjCC,cAAA,KAjCe,GAEX4B,EACIf,EAqCDgB,EA/CK,SAAAC,GAMH,IAAAD,GAAAA,GAAA,GAAAC,EACD3B,QAAOC,IAAPkB,EAAA,SAVJ3C,IAYAiD,OAEIC,QAMPnB,QAhCc,CAAA,GAAImB,GAAyB,GAARC,EAExB,OAgCZX,EAAAG,EAAA,UAAApB,IAhCmB,EAEPqB,EAAAA,uBAC2BrB,EAAWpB,KADtC,WAEIwC,EAAA,kBACA,GAoCRb,OAAAA,GAqBAA,EACAsB,EAEAC,sDAjOQtD,gBAAT,SAAyBmC,GAC5BlC,IACAL,EAAE,SAKUK,OALZ,uHAC2HkC,EAD3H,kBAqMYxC,gBAAAA,IAvMAK,gBAAAA,IASVG,gBAAAA,IA4CEY,WAAAA,IA2CIX,KAAAA,IAuGIT,qBAAT,SAA8BwC,EAAKH,GAWtCiB,EAAWd,GAAK,GATZJ,QAAS,qCACTwB,QACI,gGACJP,UACI,uMACJf,MACI,oHAGyBD,EADhB7B,EAAgB,uBAWrBN,gBAAT,SAAyBsC,EAAKH,GAejCiB,EAAWd,GAAK,GAbZJ,QAAS,+CACTsB,UACI,+FACJC,iBACI,oHACJC,QACI,+FACJP,UACI,kLACJf,MACI,wJAGwBD,EADf7B,EAAgB","file":"../scripts/galaxy.interactive_environments.js","sourcesContent":["/**\n * Internal function to remove content from the main area and add the notebook.\n * Not idempotent\n * TODO: This isn't just internal, some notebooks are calling it?\n */\nexport function append_notebook(url) {\n clear_main_area();\n $(\"#main\").append(\n ``\n );\n}\n\nexport function clear_main_area() {\n $(\"#spinner\").remove();\n $(\"#main\")\n .children()\n .remove();\n}\n\nexport function display_spinner() {\n $(\"#main\").append(\n ``\n );\n}\n\n/* Create a spin_state object used by spin() and spin_again() */\nexport function make_spin_state(\n type,\n ajax_timeout_init,\n ajax_timeout_max,\n ajax_timeout_step,\n sleep_init,\n sleep_max,\n sleep_step,\n log_attempts\n) {\n var s = {\n type: typeof type !== \"undefined\" ? type : \"GIE spin\",\n ajax_timeout:\n typeof ajax_timeout_init !== \"undefined\" ? ajax_timeout_init : 2000,\n ajax_timeout_max:\n typeof ajax_timeout_max !== \"undefined\" ? ajax_timeout_max : 16000,\n ajax_timeout_step:\n typeof ajax_timeout_step !== \"undefined\" ? ajax_timeout_step : 500,\n sleep: typeof sleep_init !== \"undefined\" ? sleep_init : 500,\n sleep_max: typeof sleep_max !== \"undefined\" ? sleep_max : 8000,\n sleep_step: typeof sleep_step !== \"undefined\" ? sleep_step : 100,\n log_attempts: typeof log_attempts !== \"undefined\" ? log_attempts : true,\n count: 0\n };\n return s;\n}\n\n/* Log/display an error when spinning fails. */\nexport function spin_error(console_msg, user_msg, clear) {\n console.log(console_msg);\n if (clear) clear_main_area();\n if (typeof user_msg == \"string\") {\n toastr.clear();\n toastr.error(user_msg, \"Error\", {\n closeButton: true,\n timeOut: 0,\n extendedTimeOut: 0,\n tapToDismiss: false\n });\n }\n}\n\n/* Increase sleep time and spin again. */\nfunction spin_again(spin_state) {\n if (spin_state.sleep < spin_state.sleep_max) {\n spin_state.sleep += spin_state.sleep_step;\n }\n if (spin_state.log_attempts) {\n console.log(\n `${spin_state.type} request ${spin_state.count} request timeout ${spin_state.ajax_timeout}ms sleeping ${spin_state.sleep /\n 1000}s`\n );\n }\n window.setTimeout(spin_state.spinner, spin_state.sleep);\n}\n\n/*\n * Spin on a URL as long as it times out, otherwise, call the provided success or error callback. If the callback\n * returns `true`, the condition is considered \"resolved\" and spinning stops. Otherwise, continue spinning, increasing\n * AJAX timeouts and/or sleep values as configured in the spin_state.\n */\nexport function spin(\n url,\n bool_response,\n success_callback,\n timeout_callback,\n error_callback,\n spin_state\n) {\n var spinner = () => {\n var ajax_params = {\n url: url,\n xhrFields: {\n withCredentials: true\n },\n type: \"GET\",\n timeout: spin_state.ajax_timeout,\n success: function(data, status, jqxhr) {\n if (!success_callback(data, status, jqxhr)) {\n spin_state.count++;\n spin_again(spin_state);\n }\n },\n error: function(jqxhr, status, error) {\n if (status == \"timeout\") {\n if (spin_state.ajax_timeout < spin_state.ajax_timeout_max) {\n spin_state.ajax_timeout += spin_state.ajax_timeout_step;\n }\n spin_state.count++;\n if (!timeout_callback(jqxhr, status, error))\n spin_again(spin_state);\n } else {\n spin_state.count++;\n if (!error_callback(jqxhr, status, error))\n spin_again(spin_state);\n }\n }\n };\n if (bool_response) ajax_params[\"dataType\"] = \"json\";\n $.ajax(ajax_params);\n };\n console.log(`Setting up new spinner for ${spin_state.type} on ${url}`);\n spin_state.spinner = spinner;\n window.setTimeout(spinner, spin_state.sleep);\n}\n\n/*\n * Spin on a URL forever until there is an acceptable response. \n * @param {String} url: URL to test response of. Must return a 200 (302->200 is OK).\n * @param {Boolean} bool_response: If set to `true`, do not stop spinning until the response is `true`. Otherwise, stop\n * as soon as a successful response is received.\n */\nfunction spin_until(\n url,\n bool_response,\n messages,\n success_callback,\n spin_state\n) {\n var warn_at = 40; // ~2 mins\n var message_once = (message, spin_state) => {\n if (spin_state.count == 1) {\n display_spinner();\n toastr.info(message, null, {\n closeButton: true,\n timeOut: 0,\n extendedTimeOut: 0,\n tapToDismiss: false\n });\n }\n };\n var wrapped_success = data => {\n if (!bool_response || (bool_response && data == true)) {\n console.log(messages[\"success\"]);\n clear_main_area();\n toastr.clear();\n success_callback();\n } else if (bool_response && data == false) {\n message_once(messages[\"not_ready\"], spin_state);\n return false; // keep spinning\n } else {\n spin_error(\n `Invalid response to ${spin_state.type} request`,\n messages[\"invalid_response\"],\n true\n );\n }\n return true; // stop spinning\n };\n var timeout_error = (jqxhr, status, error) => {\n message_once(messages[\"waiting\"], spin_state);\n if (spin_state.count == warn_at) {\n toastr.warning(messages[\"wait_warn\"], \"Warning\", {\n closeButton: true,\n timeOut: 0,\n extendedTimeOut: 0,\n tapToDismiss: false\n });\n }\n return false; // keep spinning\n };\n spin(\n url,\n bool_response,\n wrapped_success,\n timeout_error,\n timeout_error,\n spin_state\n );\n}\n\n/**\n * Test availability of a URL, and call a callback when done.\n * http://stackoverflow.com/q/25390206/347368\n * @param {String} url: URL to test availability of. Must return a 200 (302->200 is OK).\n * @param {String} callback: function to call once successfully connected.\n *\n */\nexport function test_ie_availability(url, success_callback) {\n var messages = {\n success: \"IE connection succeeded, returning\",\n waiting:\n \"Interactive environment container is running, attempting to connect to the IE. Please wait...\",\n wait_warn:\n \"It is taking an usually long time to connect to the interactive environment. Attempts will continue but you may want to report this condition to a Galaxy administrator if it does not succeed soon.\",\n error:\n \"An error was encountered while attempting to connect to the interactive environment, contact your administrator.\"\n };\n var spin_state = make_spin_state(\"IE availability\");\n spin_until(url, false, messages, success_callback, spin_state);\n}\n\n/**\n * Test a boolean (json) response from a URL, and call a callback when done.\n * http://stackoverflow.com/q/25390206/347368\n * @param {String} url: URL to test response of. Must return a 200 (302->200 is OK) and either `true` or `false`.\n * @param {String} callback: function to call once successfully connected.\n *\n */\nexport function load_when_ready(url, success_callback) {\n var messages = {\n success: \"Galaxy reports IE container ready, returning\",\n not_ready:\n \"Galaxy is launching a container in which to run this interactive environment. Please wait...\",\n unknown_response:\n \"Galaxy failed to launch a container in which to run this interactive environment, contact a Galaxy administrator.\",\n waiting:\n \"Galaxy is launching a container in which to run this interactive environment. Please wait...\",\n wait_warn:\n \"It is taking an usually long time to start a container. Attempts will continue but you may want to report this condition to a Galaxy administrator if it does not succeed soon.\",\n error:\n \"Galaxy encountered an error while attempting to determine the readiness of this interactive environment's container, contact a Galaxy administrator.\"\n };\n var spin_state = make_spin_state(\"IE container readiness\");\n spin_until(url, true, messages, success_callback, spin_state);\n}\n"]} \ No newline at end of file diff --git a/static/scripts/galaxy.interactive_environments.js b/static/scripts/galaxy.interactive_environments.js index 21ab26ceff2..23e2730b6ec 100644 --- a/static/scripts/galaxy.interactive_environments.js +++ b/static/scripts/galaxy.interactive_environments.js @@ -1,2 +1,2 @@ -define("galaxy.interactive_environments",["exports"],function(t){"use strict";function e(){$("#spinner").remove(),$("#main").children().remove()}function n(){$("#main").append('')}function i(t,e,n,i,o,a,s,r){return{type:void 0!==t?t:"GIE spin",ajax_timeout:void 0!==e?e:2e3,ajax_timeout_max:void 0!==n?n:16e3,ajax_timeout_step:void 0!==i?i:500,sleep:void 0!==o?o:500,sleep_max:void 0!==a?a:8e3,sleep_step:void 0!==s?s:100,log_attempts:void 0===r||r,count:0}}function o(t,n,i){console.log(t),i&&e(),"string"==typeof n&&(toastr.clear(),toastr.error(n,"Error",{closeButton:!0,timeOut:0,extendedTimeOut:0,tapToDismiss:!1}))}function a(t){t.sleep')}function i(t,e,n,i,o,a,r,s){return{type:void 0!==t?t:"GIE spin",ajax_timeout:void 0!==e?e:2e3,ajax_timeout_max:void 0!==n?n:16e3,ajax_timeout_step:void 0!==i?i:500,sleep:void 0!==o?o:500,sleep_max:void 0!==a?a:8e3,sleep_step:void 0!==r?r:100,log_attempts:void 0===s||s,count:0}}function o(t,n,i){console.log(t),i&&e(),"string"==typeof n&&(toastr.clear(),toastr.error(n,"Error",{closeButton:!0,timeOut:0,extendedTimeOut:0,tapToDismiss:!1}))}function a(t){t.sleep')},t.clear_main_area=e,t.display_spinner=n,t.make_spin_state=i,t.spin_error=o,t.spin=r,t.test_ie_availability=function(t,e){s(t,!1,{success:"IE connection succeeded, returning",waiting:"Interactive environment container is running, attempting to connect to the IE. Please wait...",wait_warn:"It is taking an usually long time to connect to the interactive environment. Attempts will continue but you may want to report this condition to a Galaxy administrator if it does not succeed soon.",error:"An error was encountered while attempting to connect to the interactive environment, contact your administrator."},e,i("IE availability"))},t.load_when_ready=function(t,e){s(t,!0,{success:"Galaxy reports IE container ready, returning",not_ready:"Galaxy is launching a container in which to run this interactive environment. Please wait...",unknown_response:"Galaxy failed to launch a container in which to run this interactive environment, contact a Galaxy administrator.",waiting:"Galaxy is launching a container in which to run this interactive environment. Please wait...",wait_warn:"It is taking an usually long time to start a container. Attempts will continue but you may want to report this condition to a Galaxy administrator if it does not succeed soon.",error:"Galaxy encountered an error while attempting to determine the readiness of this interactive environment's container, contact a Galaxy administrator."},e,i("IE container readiness"))}}); //# sourceMappingURL=../maps/galaxy.interactive_environments.js.map