Commit 3231315b authored by Sebastian's avatar Sebastian

Update: Jio is now working, web worker not necessary anymore

parent 027d65d6
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
return storage[method_name].apply(storage, argument_list) return storage[method_name].apply(storage, argument_list)
.push(undefined, function (error) { .push(undefined, function (error) {
if ((error.target !== undefined) && (error.target.status === 401)) { if ((error.target !== undefined) && (error.target.status === 401)) {
console.log("Not Auth'ed!");
login_page = error.target.getResponseHeader('WWW-Authenticate'); login_page = error.target.getResponseHeader('WWW-Authenticate');
// Only connect to https to login // Only connect to https to login
if (regexp.test(login_page)) { if (regexp.test(login_page)) {
......
...@@ -5,14 +5,23 @@ ...@@ -5,14 +5,23 @@
(function (window, rJS) { (function (window, rJS) {
"use strict"; "use strict";
rJS(window) function toNotebookModel(obj) {
.ready(function (gadget) { console.log(obj);
console.log("Jio Contents Gadget yes yes."); return { "name": obj.value.title,
return gadget; // TODO: THIS PATH TO NOTEBOOK FILE
}) "path": "foo/bar/notebook1.ipynb",
.declareMethod('render', function (options) { //"path": "/localhost/Test-Notebook.ipynb",
console.log("Rendering jio CONTENTS"); "type": "notebook",
this.jio_allDocs({ "format": "json",
"writable": true,
"last_modified": "2013-10-02T11:29:27.616675+00:00",
"created": "2013-10-01T12:21:20.123456+00:00",
"content": null
};
}
function handleEvent(e) {
this.jio_allDocs({
query: 'portal_type: "Web JSON"', query: 'portal_type: "Web JSON"',
select_list : ['text_content', 'title', 'reference'], //, 'modification_date'], NOT WORKING select_list : ['text_content', 'title', 'reference'], //, 'modification_date'], NOT WORKING
// sort_on: [["modification_date", "descending"]], // NOT WORKING // sort_on: [["modification_date", "descending"]], // NOT WORKING
...@@ -21,11 +30,35 @@ ...@@ -21,11 +30,35 @@
.push(function(result) { .push(function(result) {
console.log("Querying Web JSON List"); console.log("Querying Web JSON List");
console.log(result.data.rows); console.log(result.data.rows);
var nbs = [];
for(var i = 0; i < result.data.rows.length; i++) {
nbs.push(toNotebookModel(result.data.rows[i]));
}
var root_dir = {"name": "",
"path": "",
"last_modified": "2017-09-06T03:33:29.781159Z",
"created": "2017-09-06T03:33:29.781159Z",
"content": nbs,
};
console.log(root_dir);
e.detail.resolve(root_dir);
}, function(err) { }, function(err) {
e.detail.reject();
console.log(err); console.log(err);
}); });
}
rJS(window)
.ready(function (gadget) {
console.log("Jio Contents Gadget yes yes.");
document.jiocontentsReady = true;
return gadget;
})
.declareMethod('render', function (options) {
}) })
.declareAcquiredMethod("jio_allDocs", "jio_allDocs"); .declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.onEvent("custom_event", handleEvent, false, true);
}(window, rJS)); }(window, rJS));
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
<div data-gadget-url="gadget_jiocontents.html" <div data-gadget-url="gadget_jiocontents.html"
data-gadget-scope="jiocontents_gadget" data-gadget-scope="jiocontents_gadget"
data-gadget-sandbox="public"></div> data-gadget-sandbox="public"
class="jiocontents_gadget"></div>
<div>Hello renderJS + Jupyter</div> <div>Hello renderJS + Jupyter</div>
......
...@@ -10,25 +10,53 @@ define(function(require) { ...@@ -10,25 +10,53 @@ define(function(require) {
var baseUrl = "nbextensions/jiocontents"; var baseUrl = "nbextensions/jiocontents";
var gadget_div = document.createElement("div"); var gadget_main_div = document.createElement("div");
gadget_div.setAttribute("data-gadget-url", baseUrl + "/gadget_jupyter_page.html"); gadget_main_div.setAttribute("data-gadget-url", baseUrl + "/gadget_jupyter_page.html");
gadget_div.setAttribute("class", "gadget-jupyter-page-container"); gadget_main_div.setAttribute("class", "gadget-jupyter-page-container");
document.body.append(gadget_div); document.body.append(gadget_main_div);
document.jiocontentsReady = false;
var s1 = document.createElement("script"); s1.type = "text/javascript"; var s1 = document.createElement("script"); s1.type = "text/javascript";
s1.onload = function() { s1.onload = function() {
console.log("loaded rsvp"); console.log("loaded rsvp");
var s2 = document.createElement("script"); s2.type = "text/javascript"; var s2 = document.createElement("script"); s2.type = "text/javascript";
s2.onload = function() { s2.onload = function() {
console.log("loaded renderjs"); console.log("loaded renderjs");
rJS.manualBootstrap(); rJS.manualBootstrap();
} };
s2.src = baseUrl + "/renderjs.js"; s2.src = baseUrl + "/renderjs.js";
document.head.append(s2); document.head.append(s2);
}; };
s1.src = baseUrl + "/rsvp.js"; s1.src = baseUrl + "/rsvp.js";
document.head.append(s1); document.head.append(s1);
/*
.then on this method to be sure the rjs-setup was completed and
.onEvent are available to receive events
*/
function waitForReadyPromise() {
if(document.jiocontentsReady) {
return Promise.resolve(); // rjs-setup is already complete
}
return new Promise(function(resolve, reject) {
var timerId = window.setInterval(function() {
if(document.jiocontentsReady) {
window.setTimeout(function() { resolve(); }, 200); // to allow for aquiredmethod to load
clearInterval(timerId);
}
}, 100); // Check every 100ms to see if rjs-setup is complete and eventlistener available
window.setTimeout(function() {
if(!document.jiocontentsReady) {
reject();
}
}, 3000) // Reject after 3sec
});
}
function getJiocontentsDiv() {
return document.querySelector(".jiocontents_gadget");
}
var Contents = function(options) { var Contents = function(options) {
/** /**
...@@ -116,15 +144,19 @@ define(function(require) { ...@@ -116,15 +144,19 @@ define(function(require) {
* content: true or false; // whether to include the content * content: true or false; // whether to include the content
*/ */
Contents.prototype.get = function (path, options) { Contents.prototype.get = function (path, options) {
console.log("GET: " + path); return waitForReadyPromise()
return new Promise(function(resolve, reject) { .then(function() {
var jioworker = return new Promise(function(resolve, reject) {
new Worker("nbextensions/jiocontents/jioworker.js"); var ev = new CustomEvent("custom_event", {
jioworker.onmessage = function(e) { detail: {
resolve(e.data); path: path,
}; resolve: resolve,
jioworker.postMessage(["get", path]); reject: reject
}); }
});
getJiocontentsDiv().dispatchEvent(ev);
});
})
} }
...@@ -274,8 +306,8 @@ define(function(require) { ...@@ -274,8 +306,8 @@ define(function(require) {
* @param {String} path The path to list notebooks in * @param {String} path The path to list notebooks in
*/ */
Contents.prototype.list_contents = function(path) { Contents.prototype.list_contents = function(path) {
return this.get(path, {type: 'directory'}); return this.get(path, {type: 'directory'});
}; };
return {'Contents': Contents}; return {'Contents': Contents};
}); });
\ No newline at end of file
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