##// END OF EJS Templates
manual rebase static/services (add session.js)
Zachary Sailer -
Show More
@@ -0,0 +1,88 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
7
8 //============================================================================
9 // Notebook
10 //============================================================================
11
12 var IPython = (function (IPython) {
13
14 var Session = function(notebook_path, Notebook){
15 this.kernel = null;
16 this.kernel_id = null;
17 this.session_id = null;
18 this.notebook_path = notebook_path;
19 this.notebook = Notebook;
20 };
21
22 Session.prototype.start = function(){
23 var that = this
24 var qs = $.param({notebook_path:this.notebook_path});
25 var url = '/api/sessions' + '?' + qs;
26 $.post(url,
27 $.proxy(this.start_kernel, that),
28 'json'
29 );
30 };
31
32 // Kernel related things
33
34 /**
35 * Start a new kernel and set it on each code cell.
36 *
37 * @method start_kernel
38 */
39 Session.prototype.start_kernel = function (json) {
40 this.session_id = json.session_id;
41 this.kernel_content = json.kernel;
42 var base_url = $('body').data('baseKernelUrl') + "api/kernels";
43 this.kernel = new IPython.Kernel(base_url, this.session_id);
44 // Now that the kernel has been created, tell the CodeCells about it.
45 this.kernel._kernel_started(this.kernel_content)
46 var ncells = this.notebook.ncells();
47 for (var i=0; i<ncells; i++) {
48 var cell = this.notebook.get_cell(i);
49 if (cell instanceof IPython.CodeCell) {
50 cell.set_kernel(this.kernel)
51 };
52 };
53
54 };
55
56 /**
57 * Prompt the user to restart the IPython kernel.
58 *
59 * @method restart_kernel
60 */
61 Session.prototype.restart_kernel = function () {
62 var that = this;
63 var dialog = $('<div/>');
64 dialog.html('Do you want to restart the current kernel? You will lose all variables defined in it.');
65 $(document).append(dialog);
66 dialog.dialog({
67 resizable: false,
68 modal: true,
69 title: "Restart kernel or continue running?",
70 closeText: '',
71 buttons : {
72 "Restart": function () {
73 that.kernel.restart();
74 $(this).dialog('close');
75 },
76 "Continue running": function () {
77 $(this).dialog('close');
78 }
79 }
80 });
81 };
82
83 IPython.Session = Session;
84
85
86 return IPython;
87
88 }(IPython));
@@ -24,15 +24,16 b' var IPython = (function (IPython) {'
24 * A Kernel Class to communicate with the Python kernel
24 * A Kernel Class to communicate with the Python kernel
25 * @Class Kernel
25 * @Class Kernel
26 */
26 */
27 var Kernel = function (base_url) {
27 var Kernel = function (base_url, session_id) {
28 this.kernel_id = null;
28 this.kernel_id = null;
29 this.session_id = session_id
29 this.shell_channel = null;
30 this.shell_channel = null;
30 this.iopub_channel = null;
31 this.iopub_channel = null;
31 this.stdin_channel = null;
32 this.stdin_channel = null;
32 this.base_url = base_url;
33 this.base_url = base_url;
33 this.running = false;
34 this.running = false;
34 this.username = "username";
35 this.username = "username";
35 this.session_id = utils.uuid();
36 this.base_session_id = utils.uuid();
36 this._msg_callbacks = {};
37 this._msg_callbacks = {};
37
38
38 if (typeof(WebSocket) !== 'undefined') {
39 if (typeof(WebSocket) !== 'undefined') {
@@ -51,7 +52,7 b' var IPython = (function (IPython) {'
51 header : {
52 header : {
52 msg_id : utils.uuid(),
53 msg_id : utils.uuid(),
53 username : this.username,
54 username : this.username,
54 session : this.session_id,
55 session : this.base_session_id,
55 msg_type : msg_type
56 msg_type : msg_type
56 },
57 },
57 metadata : {},
58 metadata : {},
@@ -72,17 +73,19 b' var IPython = (function (IPython) {'
72 * Start the Python kernel
73 * Start the Python kernel
73 * @method start
74 * @method start
74 */
75 */
75 Kernel.prototype.start = function (params) {
76 Kernel.prototype.start = function (params) {
76 var that = this;
77 var that = this;
77 if (!this.running) {
78 params = params || {};
78 var qs = $.param(params);
79 params.session = this.session_id;
79 var url = this.base_url + '?' + qs;
80 if (!this.running) {
80 $.post(url,
81 var qs = $.param(params);
81 $.proxy(that._kernel_started,that),
82 var url = this.base_url + '?' + qs;
82 'json'
83 $.post(url,
83 );
84 $.proxy(that._kernel_started,that),
84 };
85 'json'
85 };
86 );
87 };
88 };
86
89
87 /**
90 /**
88 * Restart the python kernel.
91 * Restart the python kernel.
General Comments 0
You need to be logged in to leave comments. Login now