Commit 3a3978b5 authored by Sebastian's avatar Sebastian

Add creating new notebooks is now possible. Bad reference atm

parent af0452bc
......@@ -125,6 +125,31 @@
});
}
function handleCreate(e) {
var now = new Date().toUTCString();
var jioObj = {
portal_type: "Web JSON",
parent_relative_url: "web_page_module",
title: "untitled_notebook.ipynb",
reference: "untitled notebook from " + now,
text_content: JSON.stringify(createBlankNotebook())
};
var gadget = this;
gadget.jio_post(jioObj)
.push(function(newId) {
gadget.jio_get(newId)
.push(function(result) {
e.detail.resolve(toNotebookModel(newId, result, true));
}, function(err) {
console.log(err);
e.detail.reject(err);
});
}, function(err) {
console.log(err);
e.detail.reject(err);
});
}
/*
*
* RJS Stuffs
......@@ -139,13 +164,37 @@
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_post", "jio_post")
.onEvent("get_event", handleGet, false, true)
.onEvent("save_event", handleSave, false, true)
.onEvent("create_event", handleCreate, false, true)
.declareMethod('render', function () {
console.log("Rendering!");
document.jiocontentsReady = true;
return this;
});
function createBlankNotebook() {
return {
"cells": [
{ "cell_type": "code",
"execution_count": null,
"metadata": { "collapsed": true },
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
}
},
"nbformat": 4,
"nbformat_minor": 2
};
}
}(window, rJS));
......@@ -156,8 +156,8 @@ define(function(require) {
});
getJiocontentsDiv().dispatchEvent(ev);
});
})
}
});
};
/**
......@@ -172,14 +172,22 @@ define(function(require) {
* type: model type to create ('notebook', 'file', or 'directory')
*/
Contents.prototype.new_untitled = function(path, options) {
console.log("creating new untitled");
return new Promise(function(resolve, reject) {
var jioworker =
new Worker("nbextensions/jiocontents/jioworker.js");
jioworker.onmessage = function(e) {
resolve(e.data);
};
jioworker.postMessage(["create", path]);
if(options.type !== "notebook") {
console.log("Creation of non-notebooks is not supported!");
return Promise.reject();
}
return waitForReadyPromise()
.then(function() {
return new Promise(function(resolve, reject) {
var ev = new CustomEvent("create_event", {
detail: {
path: path,
resolve: resolve,
reject: reject,
}
});
getJiocontentsDiv().dispatchEvent(ev);
});
});
};
......
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