session.js
96 lines
| 2.9 KiB
| application/javascript
|
JavascriptLexer
|
r12987 | //---------------------------------------------------------------------------- | ||
// Copyright (C) 2008-2011 The IPython Development Team | ||||
// | ||||
// Distributed under the terms of the BSD License. The full license is in | ||||
// the file COPYING, distributed as part of this software. | ||||
//---------------------------------------------------------------------------- | ||||
//============================================================================ | ||||
// Notebook | ||||
//============================================================================ | ||||
var IPython = (function (IPython) { | ||||
var Session = function(notebook_path, Notebook){ | ||||
this.kernel = null; | ||||
this.kernel_id = null; | ||||
this.session_id = null; | ||||
this.notebook_path = notebook_path; | ||||
this.notebook = Notebook; | ||||
|
r12995 | this._baseProjectUrl = Notebook.baseProjectUrl() | ||
|
r12987 | }; | ||
Session.prototype.start = function(){ | ||||
var that = this | ||||
var qs = $.param({notebook_path:this.notebook_path}); | ||||
var url = '/api/sessions' + '?' + qs; | ||||
$.post(url, | ||||
$.proxy(this.start_kernel, that), | ||||
'json' | ||||
); | ||||
}; | ||||
|
r12997 | Session.prototype.notebook_rename = function (notebook_path) { | ||
this.notebook_path = notebook_path; | ||||
var settings = { | ||||
processData : false, | ||||
cache : false, | ||||
type : "PATCH", | ||||
data: notebook_path, | ||||
dataType : "json", | ||||
}; | ||||
var url = this._baseProjectUrl + 'api/sessions/' + this.session_id; | ||||
$.ajax(url, settings); | ||||
} | ||||
Session.prototype.delete_session = function() { | ||||
var settings = { | ||||
processData : false, | ||||
cache : false, | ||||
type : "DELETE", | ||||
dataType : "json", | ||||
}; | ||||
var url = this._baseProjectUrl + 'api/sessions/' + this.session_id; | ||||
$.ajax(url, settings); | ||||
}; | ||||
|
r12987 | // Kernel related things | ||
/** | ||||
* Start a new kernel and set it on each code cell. | ||||
* | ||||
* @method start_kernel | ||||
*/ | ||||
Session.prototype.start_kernel = function (json) { | ||||
|
r13015 | this.session_id = json.id; | ||
|
r12987 | this.kernel_content = json.kernel; | ||
var base_url = $('body').data('baseKernelUrl') + "api/kernels"; | ||||
this.kernel = new IPython.Kernel(base_url, this.session_id); | ||||
// Now that the kernel has been created, tell the CodeCells about it. | ||||
|
r12999 | this.kernel._kernel_started(this.kernel_content); | ||
|
r12987 | }; | ||
/** | ||||
* Prompt the user to restart the IPython kernel. | ||||
* | ||||
* @method restart_kernel | ||||
*/ | ||||
Session.prototype.restart_kernel = function () { | ||||
|
r12994 | this.kernel.restart(); | ||
|
r12987 | }; | ||
|
r12994 | Session.prototype.interrupt_kernel = function() { | ||
this.kernel.interrupt(); | ||||
|
r12995 | }; | ||
Session.prototype.kill_kernel = function() { | ||||
this.kernel.kill(); | ||||
}; | ||||
|
r12994 | |||
|
r12987 | IPython.Session = Session; | ||
return IPython; | ||||
}(IPython)); | ||||