Commit 0b776b6b authored by Sebastian's avatar Sebastian

Add: Getting list from ERP5, getting notebook JSON loaded into page (buggy)

parent 3231315b
...@@ -5,60 +5,104 @@ ...@@ -5,60 +5,104 @@
(function (window, rJS) { (function (window, rJS) {
"use strict"; "use strict";
function toNotebookModel(obj) { /*
console.log(obj); Next two functions deal with a weird issue of unlin-ed strings, ie. list
return { "name": obj.value.title, of strings instead a single joined string. See
// TODO: THIS PATH TO NOTEBOOK FILE https://github.com/jupyter/jupyter-drive/blob/master/jupyterdrive/gdrive/notebook_model.js#L45
"path": "foo/bar/notebook1.ipynb", */
//"path": "/localhost/Test-Notebook.ipynb", function unsplit_lines(multiline_string) {
"type": "notebook", if (Array.isArray(multiline_string)) {
"format": "json", return multiline_string.join('');
"writable": true, } else {
"last_modified": "2013-10-02T11:29:27.616675+00:00", return multiline_string;
"created": "2013-10-01T12:21:20.123456+00:00", }
"content": null }
};
function transform_notebook(notebook, transform_fn) {
if (!notebook['cells']) {
return null;
}
notebook['cells'].forEach(function (cell) {
if (cell['source']) {
cell['source'] = transform_fn(cell['source']);
}
if (cell['outputs']) {
cell['outputs'].forEach(function (output) {
if (output['data']) {
output['data'] = transform_fn(output['data']);
}
});
}
});
}
function toNotebookModel(id, obj, keepContent) {
//console.log(obj.value.text_content);
var cont = null;
if(keepContent) {
cont = JSON.parse(obj.text_content);
transform_notebook(cont, unsplit_lines);
cont.metadata = cont.metadata || {};
}
var nbobj = { "name": obj.title,
"path": id,
"type": "notebook",
"format": "json",
"writable": true,
"mimetype": "application/ipynb",
"content": cont,
//"content": keepContent ? obj.text_content : null
};
return nbobj;
} }
function handleEvent(e) { function handleEvent(e) {
this.jio_allDocs({ if(e.detail.path === "") {
query: 'portal_type: "Web JSON"', this.jio_allDocs({
select_list : ['text_content', 'title', 'reference'], //, 'modification_date'], NOT WORKING query: 'portal_type: "Web JSON"',
// sort_on: [["modification_date", "descending"]], // NOT WORKING select_list : ['text_content', 'title', 'reference'], //, 'modification_date'], NOT WORKING
limit: [0, 5] // sort_on: [["modification_date", "descending"]], // NOT WORKING
}) limit: [0, 5]
})
.push(function(result) {
var nbs = [];
for(var i = 0; i < result.data.rows.length; i++) {
nbs.push(toNotebookModel(result.data.rows[i].id, result.data.rows[i].value, false));
}
var root_dir = {"name": "",
"path": "",
"last_modified": "2017-09-06T03:33:29.781159Z",
"created": "2017-09-06T03:33:29.781159Z",
"content": nbs,
};
e.detail.resolve(root_dir);
}, function(err) {
e.detail.reject();
console.log(err);
});
} else {
this.jio_get(e.detail.path)
.push(function(result) { .push(function(result) {
console.log("Querying Web JSON List"); e.detail.resolve(toNotebookModel(e.detail.path, result, true));
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) rJS(window)
.ready(function (gadget) { .ready(function (gadget) {
console.log("Jio Contents Gadget yes yes."); console.log("Jio Contents Gadget yes yes.");
document.jiocontentsReady = true;
return gadget; return gadget;
})
.declareMethod('render', function (options) {
}) })
.declareAcquiredMethod("jio_allDocs", "jio_allDocs") .declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.onEvent("custom_event", handleEvent, false, true); .declareAcquiredMethod("jio_get", "jio_get")
.onEvent("custom_event", handleEvent, false, true)
.declareMethod('render', function () {
console.log("Rendering!");
document.jiocontentsReady = true;
return this;
});
}(window, rJS)); }(window, rJS));
...@@ -99,7 +99,7 @@ ...@@ -99,7 +99,7 @@
return gadget.getDeclaredGadget("jiocontents_gadget"); return gadget.getDeclaredGadget("jiocontents_gadget");
}) })
.push(function(jiocontents_gadget) { .push(function(jiocontents_gadget) {
jiocontents_gadget.render({}); jiocontents_gadget.render();
}); });
}) })
.allowPublicAcquisition("getSetting", function (argument_list) { .allowPublicAcquisition("getSetting", function (argument_list) {
......
...@@ -8,7 +8,7 @@ define(function(require) { ...@@ -8,7 +8,7 @@ define(function(require) {
var utils = require('base/js/utils'); var utils = require('base/js/utils');
var baseUrl = "nbextensions/jiocontents"; var baseUrl = "/nbextensions/jiocontents";
var gadget_main_div = document.createElement("div"); var gadget_main_div = document.createElement("div");
gadget_main_div.setAttribute("data-gadget-url", baseUrl + "/gadget_jupyter_page.html"); gadget_main_div.setAttribute("data-gadget-url", baseUrl + "/gadget_jupyter_page.html");
...@@ -42,7 +42,7 @@ define(function(require) { ...@@ -42,7 +42,7 @@ define(function(require) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var timerId = window.setInterval(function() { var timerId = window.setInterval(function() {
if(document.jiocontentsReady) { if(document.jiocontentsReady) {
window.setTimeout(function() { resolve(); }, 200); // to allow for aquiredmethod to load resolve();
clearInterval(timerId); clearInterval(timerId);
} }
}, 100); // Check every 100ms to see if rjs-setup is complete and eventlistener available }, 100); // Check every 100ms to see if rjs-setup is complete and eventlistener available
......
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