Commit c958d902 authored by Romain Casati's avatar Romain Casati
Browse files

Using requirejs loading system.

parent 297d16c7
......@@ -88,7 +88,7 @@ window.mathjax_url = "static/components/MathJax/MathJax.js";
"jquery-ui": {
deps: ["jquery"],
exports: "$"
}
},
},
waitSeconds: 30,
});
......@@ -576,10 +576,6 @@ dir="ltr">
_remove_token_from_url();
</script>
<script type="text/javascript" src="static/basthon-kernel/basthon.min.js"></script>
<script type="text/javascript" src="static/basthon-kernel/basthon_goodies.min.js"></script>
<script type="text/javascript" src="gui.js"></script>
</body>
</html>
......@@ -17,7 +17,8 @@
define([
'base/js/i18n',
], function(i18n){
'./basthon_gui',
], function(i18n, basthonGUI){
"use strict";
var warn_bad_name = function(name){
......
"use strict";
/**
* Basthon part of the notebook GUI.
*/
window.basthonGUI = (function () {
define([
'basthon-kernel/basthon',
'basthon-kernel/basthon_goodies',
'base/js/dialog'],
function(Basthon, BasthonGoodies, dialog) {
"use strict";
let that = {};
/**
* Initialise the GUI (Basthon part).
*/
that.init = async function () {
await Basthon.Goodies.showLoader("Chargement de Basthon-Notebook...", false);
window.Basthon = Basthon;
await BasthonGoodies.showLoader("Chargement de Basthon-Notebook...", false);
// silent requirejs errors
requirejs.onError = console.log;
that.notebook = Jupyter.notebook;
......@@ -31,20 +39,20 @@ window.basthonGUI = (function () {
we open a new notebook
(see kernelselector.js).
*/
Basthon.Goodies.setLoaderText("Chargement du contenu du notebook...");
BasthonGoodies.setLoaderText("Chargement du contenu du notebook...");
if( !window.basthonEmptyNotebook && !await that.loadFromQS() ) {
that.notebook.loadFromStorage();
}
Basthon.Goodies.setLoaderText("Chargement des fichiers auxiliaires...");
BasthonGoodies.setLoaderText("Chargement des fichiers auxiliaires...");
// loading aux files from URL
await that.loadURLAux();
Basthon.Goodies.setLoaderText("Chargement des modules annexes...");
BasthonGoodies.setLoaderText("Chargement des modules annexes...");
// loading modules from URL
await that.loadURLModules();
Basthon.Goodies.hideLoader();
BasthonGoodies.hideLoader();
/* saving to storage on multiple events */
for( let event of ['execute.CodeCell',
......@@ -64,7 +72,7 @@ window.basthonGUI = (function () {
// ignoring requirejs error
if( error.filename && error.filename.split('/').pop() === 'require.js' ) return ;
const message = error.message || error.reason.message || error;
Jupyter.dialog.modal({
dialog.modal({
notebook: that.notebook,
keyboard_manager: that.notebook.keyboard_manager,
title : "Erreur",
......@@ -76,7 +84,7 @@ window.basthonGUI = (function () {
},
});
// In case of error, force loader hiding.
Basthon.Goodies.hideLoader();
BasthonGoodies.hideLoader();
}
/* all errors redirected to notification system */
window.addEventListener('error', onerror);
......@@ -106,7 +114,7 @@ window.basthonGUI = (function () {
try {
ipynb = await Basthon.xhr({url: fileURL,
method: 'GET'});
} catch {
} catch (error) {
throw {message: "Le chargement du notebook " + fileURL
+ " a échoué.",
name: 'LoadingException'};
......@@ -215,6 +223,19 @@ window.basthonGUI = (function () {
anchor.click();
document.body.removeChild(anchor);
};
/**
* Converting notebook to URL to later access the notebook content.
*/
that.notebookToURL = function (key="ipynb") {
let ipynb = JSON.stringify(that.notebook.toIpynb());
const url = new URL(window.location.href);
url.hash = "";
url.searchParams.delete("from"); // take care of collapsing params
ipynb = encodeURIComponent(ipynb).replace(/\(/g, '%28').replace(/\)/g, '%29');
url.searchParams.set(key, ipynb);
return url.href;
};
/**
* Sharing notebook via URL.
......@@ -227,8 +248,9 @@ Un lien vers la page de Basthon avec le contenu actuel du notebook a été cré
<i class="fa fa-exclamation-circle"></i> Attention, partager un script trop long peut ne pas fonctionner avec certains navigateurs.
`);
that.events.trigger('before_share.Notebook');
const url = that.notebook.toURL(key);
Jupyter.dialog.modal({
const url = that.notebookToURL(key);
dialog.modal({
notebook: that.notebook,
keyboard_manager: that.notebook.keyboard_manager,
title : "Partager ce notebook",
......@@ -314,7 +336,7 @@ Un lien vers la page de Basthon avec le contenu actuel du notebook a été cré
that.openPythonFile = async function (file) {
const msg = $("<div>").html(
"Que faire de " + file.name + " ?");
Jupyter.dialog.modal({
dialog.modal({
notebook: that.notebook,
keyboard_manager: that.notebook.keyboard_manager,
title : "Que faire du fichier ?",
......@@ -343,7 +365,7 @@ Un lien vers la page de Basthon avec le contenu actuel du notebook a été cré
await Basthon.putRessource(file.name, event.target.result);
const msg = $("<div>").html(
file.name + " est maintenant utilisable depuis Python");
Jupyter.dialog.modal({
dialog.modal({
notebook: that.notebook,
keyboard_manager: that.notebook.keyboard_manager,
title : "Fichier utilisable depuis Python",
......@@ -392,6 +414,4 @@ Un lien vers la page de Basthon avec le contenu actuel du notebook a été cré
};
return that;
})();
window.basthonGUI.init();
});
......@@ -52,7 +52,8 @@ requirejs([
'notebook/js/about',
'notebook/js/searchandreplace',
'notebook/js/clipboard',
'bidi/bidi'
'bidi/bidi',
'notebook/js/basthon_gui',
], function(
$,
contents_service,
......@@ -78,10 +79,13 @@ requirejs([
about,
searchandreplace,
clipboard,
bidi
bidi,
basthonGUI,
) {
"use strict";
basthonGUI.init();
// Pull typeahead from the global jquery object
var typeahead = $.typeahead;
......
......@@ -10,7 +10,8 @@ define([
'./celltoolbar',
'./tour',
'moment',
], function($, IPython, dialog, utils, i18n, celltoolbar, tour, moment) {
'./basthon_gui',
], function($, IPython, dialog, utils, i18n, celltoolbar, tour, moment, basthonGUI) {
"use strict";
var MenuBar = function (selector, options) {
......
......@@ -60,7 +60,7 @@ define([
tags_celltoolbar,
scrollmanager,
commandpalette,
shortcuteditor
shortcuteditor,
) {
var ShortcutEditor = shortcuteditor.ShortcutEditor;
......@@ -3021,18 +3021,6 @@ define([
content: this.toJSON()};
};
/** [Basthon]
* Converting notebook to URL to later access the notebook content.
*/
Notebook.prototype.toURL = function (key="ipynb") {
const component = JSON.stringify(this.toIpynb());
const url = new URL(window.location.href);
url.hash = "";
url.searchParams.delete("from"); // take care of collapsing params
url.searchParams.set(key, encodeURIComponent(component).replace(/\(/g, '%28').replace(/\)/g, '%29'));
return url.href;
};
/** [Basthon]
* Saving the notebook to local storage.
*/
......
define([], function() {
define(["basthon-kernel/basthon"], function(Basthon) {
"use strict";
let CLOSED = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment