##// END OF EJS Templates
Cells shouldn't know about Sessions
MinRK -
Show More
@@ -60,8 +60,8 b' var IPython = (function (IPython) {'
60 * @param {object|undefined} [options]
60 * @param {object|undefined} [options]
61 * @param [options.cm_config] {object} config to pass to CodeMirror
61 * @param [options.cm_config] {object} config to pass to CodeMirror
62 */
62 */
63 var CodeCell = function (session, options) {
63 var CodeCell = function (kernel, options) {
64 this.session = session || null;
64 this.kernel = kernel || null;
65 this.code_mirror = null;
65 this.code_mirror = null;
66 this.input_prompt_number = null;
66 this.input_prompt_number = null;
67 this.collapsed = false;
67 this.collapsed = false;
@@ -231,8 +231,8 b' var IPython = (function (IPython) {'
231
231
232 // Kernel related calls.
232 // Kernel related calls.
233
233
234 CodeCell.prototype.set_session = function (session) {
234 CodeCell.prototype.set_kernel = function (kernel) {
235 this.session = session;
235 this.kernel = kernel;
236 }
236 }
237
237
238 /**
238 /**
@@ -250,7 +250,7 b' var IPython = (function (IPython) {'
250 'set_next_input': $.proxy(this._handle_set_next_input, this),
250 'set_next_input': $.proxy(this._handle_set_next_input, this),
251 'input_request': $.proxy(this._handle_input_request, this)
251 'input_request': $.proxy(this._handle_input_request, this)
252 };
252 };
253 this.last_msg_id = this.session.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true});
253 this.last_msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true});
254 };
254 };
255
255
256 /**
256 /**
@@ -153,7 +153,7 b' var IPython = (function (IPython) {'
153 var callbacks = {
153 var callbacks = {
154 'complete_reply': $.proxy(this.finish_completing, this)
154 'complete_reply': $.proxy(this.finish_completing, this)
155 };
155 };
156 this.cell.session.kernel.complete(line, cur.ch, callbacks);
156 this.cell.kernel.complete(line, cur.ch, callbacks);
157 }
157 }
158 };
158 };
159
159
@@ -33,6 +33,7 b' var IPython = (function (IPython) {'
33 this.element.data("notebook", this);
33 this.element.data("notebook", this);
34 this.next_prompt_number = 1;
34 this.next_prompt_number = 1;
35 this.session = null;
35 this.session = null;
36 this.kernel = null;
36 this.clipboard = null;
37 this.clipboard = null;
37 this.undelete_backup = null;
38 this.undelete_backup = null;
38 this.undelete_index = null;
39 this.undelete_index = null;
@@ -797,7 +798,7 b' var IPython = (function (IPython) {'
797
798
798 if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) {
799 if (ncells === 0 || this.is_valid_cell_index(index) || index === ncells) {
799 if (type === 'code') {
800 if (type === 'code') {
800 cell = new IPython.CodeCell(this.session);
801 cell = new IPython.CodeCell(this.kernel);
801 cell.set_input_prompt();
802 cell.set_input_prompt();
802 } else if (type === 'markdown') {
803 } else if (type === 'markdown') {
803 cell = new IPython.MarkdownCell();
804 cell = new IPython.MarkdownCell();
@@ -1390,21 +1391,21 b' var IPython = (function (IPython) {'
1390 */
1391 */
1391 Notebook.prototype.start_session = function () {
1392 Notebook.prototype.start_session = function () {
1392 this.session = new IPython.Session(this.notebook_name, this.notebook_path, this);
1393 this.session = new IPython.Session(this.notebook_name, this.notebook_path, this);
1393 this.session.start();
1394 this.session.start($.proxy(this._session_started, this));
1394 this.link_cells_to_session();
1395 };
1395 };
1396
1396
1397
1397
1398 /**
1398 /**
1399 * Once a session is started, link the code cells to the session
1399 * Once a session is started, link the code cells to the kernel
1400 *
1400 *
1401 */
1401 */
1402 Notebook.prototype.link_cells_to_session= function(){
1402 Notebook.prototype._session_started = function(){
1403 this.kernel = this.session.kernel;
1403 var ncells = this.ncells();
1404 var ncells = this.ncells();
1404 for (var i=0; i<ncells; i++) {
1405 for (var i=0; i<ncells; i++) {
1405 var cell = this.get_cell(i);
1406 var cell = this.get_cell(i);
1406 if (cell instanceof IPython.CodeCell) {
1407 if (cell instanceof IPython.CodeCell) {
1407 cell.set_session(this.session);
1408 cell.set_kernel(this.session.kernel);
1408 };
1409 };
1409 };
1410 };
1410 };
1411 };
@@ -1806,21 +1807,20 b' var IPython = (function (IPython) {'
1806 $.ajax(url,settings);
1807 $.ajax(url,settings);
1807 };
1808 };
1808
1809
1809 Notebook.prototype.notebook_rename = function (nbname) {
1810 Notebook.prototype.rename = function (nbname) {
1810 var that = this;
1811 var that = this;
1811 var new_name = nbname + '.ipynb'
1812 var data = {name: nbname + '.ipynb'};
1812 var name = {'name': new_name};
1813 var settings = {
1813 var settings = {
1814 processData : false,
1814 processData : false,
1815 cache : false,
1815 cache : false,
1816 type : "PATCH",
1816 type : "PATCH",
1817 data : JSON.stringify(name),
1817 data : JSON.stringify(data),
1818 dataType: "json",
1818 dataType: "json",
1819 headers : {'Content-Type': 'application/json'},
1819 headers : {'Content-Type': 'application/json'},
1820 success : $.proxy(that.rename_success, this),
1820 success : $.proxy(that.rename_success, this),
1821 error : $.proxy(that.rename_error, this)
1821 error : $.proxy(that.rename_error, this)
1822 };
1822 };
1823 $([IPython.events]).trigger('notebook_rename.Notebook');
1823 $([IPython.events]).trigger('rename_notebook.Notebook', data);
1824 var url = utils.url_path_join(
1824 var url = utils.url_path_join(
1825 this.baseProjectUrl(),
1825 this.baseProjectUrl(),
1826 'api/notebooks',
1826 'api/notebooks',
@@ -1835,8 +1835,8 b' var IPython = (function (IPython) {'
1835 this.notebook_name = json.name
1835 this.notebook_name = json.name
1836 var name = this.notebook_name
1836 var name = this.notebook_name
1837 var path = json.path
1837 var path = json.path
1838 this.session.notebook_rename(name, path);
1838 this.session.rename_notebook(name, path);
1839 $([IPython.events]).trigger('notebook_renamed.Notebook');
1839 $([IPython.events]).trigger('notebook_renamed.Notebook', json);
1840 }
1840 }
1841
1841
1842 Notebook.prototype.rename_error = function (json, status, xhr) {
1842 Notebook.prototype.rename_error = function (json, status, xhr) {
@@ -95,7 +95,7 b' var IPython = (function (IPython) {'
95 );
95 );
96 return false;
96 return false;
97 } else {
97 } else {
98 IPython.notebook.notebook_rename(new_name);
98 IPython.notebook.rename(new_name);
99 }
99 }
100 }}
100 }}
101 },
101 },
@@ -128,7 +128,7 b' var IPython = (function (IPython) {'
128 // reexecute last call in pager by appending ? to show back in pager
128 // reexecute last call in pager by appending ? to show back in pager
129 var that = this;
129 var that = this;
130 var empty = function () {};
130 var empty = function () {};
131 cell.session.kernel.execute(
131 cell.kernel.execute(
132 that.name + '?', {
132 that.name + '?', {
133 'execute_reply': empty,
133 'execute_reply': empty,
134 'output': empty,
134 'output': empty,
@@ -226,7 +226,7 b' var IPython = (function (IPython) {'
226 'object_info_reply': $.proxy(this._show, this)
226 'object_info_reply': $.proxy(this._show, this)
227 }
227 }
228 var oir_token = this.extract_oir_token(line);
228 var oir_token = this.extract_oir_token(line);
229 var msg_id = cell.session.kernel.object_info_request(oir_token, callbacks);
229 var msg_id = cell.kernel.object_info_request(oir_token, callbacks);
230 }
230 }
231
231
232 // make an imediate completion request
232 // make an imediate completion request
@@ -23,7 +23,7 b' var IPython = (function (IPython) {'
23 this._baseProjectUrl = notebook.baseProjectUrl();
23 this._baseProjectUrl = notebook.baseProjectUrl();
24 };
24 };
25
25
26 Session.prototype.start = function() {
26 Session.prototype.start = function(callback) {
27 var that = this;
27 var that = this;
28 var model = {
28 var model = {
29 notebook : {
29 notebook : {
@@ -37,13 +37,18 b' var IPython = (function (IPython) {'
37 type : "POST",
37 type : "POST",
38 data: JSON.stringify(model),
38 data: JSON.stringify(model),
39 dataType : "json",
39 dataType : "json",
40 success : $.proxy(this.start_kernel, that),
40 success : function (data, status, xhr) {
41 that._handle_start_success(data);
42 if (callback) {
43 callback(data, status, xhr);
44 }
45 },
41 };
46 };
42 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions');
47 var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions');
43 $.ajax(url, settings);
48 $.ajax(url, settings);
44 };
49 };
45
50
46 Session.prototype.notebook_rename = function (name, path) {
51 Session.prototype.rename_notebook = function (name, path) {
47 this.name = name;
52 this.name = name;
48 this.path = path;
53 this.path = path;
49 var model = {
54 var model = {
@@ -63,7 +68,7 b' var IPython = (function (IPython) {'
63 $.ajax(url, settings);
68 $.ajax(url, settings);
64 };
69 };
65
70
66 Session.prototype.delete_session = function() {
71 Session.prototype.delete = function() {
67 var settings = {
72 var settings = {
68 processData : false,
73 processData : false,
69 cache : false,
74 cache : false,
@@ -76,16 +81,15 b' var IPython = (function (IPython) {'
76
81
77 // Kernel related things
82 // Kernel related things
78 /**
83 /**
79 * Start a new kernel and set it on each code cell.
84 * Create the Kernel object associated with this Session.
80 *
85 *
81 * @method start_kernel
86 * @method _handle_start_success
82 */
87 */
83 Session.prototype.start_kernel = function (json) {
88 Session.prototype._handle_start_success = function (data, status, xhr) {
84 this.id = json.id;
89 this.id = data.id;
85 this.kernel_content = json.kernel;
86 var base_url = utils.url_path_join($('body').data('baseKernelUrl'), "api/kernels");
90 var base_url = utils.url_path_join($('body').data('baseKernelUrl'), "api/kernels");
87 this.kernel = new IPython.Kernel(base_url, this.session_id);
91 this.kernel = new IPython.Kernel(base_url);
88 this.kernel._kernel_started(this.kernel_content);
92 this.kernel._kernel_started(data.kernel);
89 };
93 };
90
94
91 /**
95 /**
General Comments 0
You need to be logged in to leave comments. Login now