Show More
@@ -1,117 +1,118 b'' | |||
|
1 | 1 | //---------------------------------------------------------------------------- |
|
2 | 2 | // Copyright (C) 2013 The IPython Development Team |
|
3 | 3 | // |
|
4 | 4 | // Distributed under the terms of the BSD License. The full license is in |
|
5 | 5 | // the file COPYING, distributed as part of this software. |
|
6 | 6 | //---------------------------------------------------------------------------- |
|
7 | 7 | |
|
8 | 8 | //============================================================================ |
|
9 | 9 | // Notebook |
|
10 | 10 | //============================================================================ |
|
11 | 11 | |
|
12 | 12 | var IPython = (function (IPython) { |
|
13 | 13 | "use strict"; |
|
14 | 14 | |
|
15 | 15 | var utils = IPython.utils; |
|
16 | 16 | |
|
17 | 17 | var Session = function(notebook_name, notebook_path, notebook){ |
|
18 | 18 | this.kernel = null; |
|
19 | 19 | this.id = null; |
|
20 | 20 | this.name = notebook_name; |
|
21 | 21 | this.path = notebook_path; |
|
22 | 22 | this.notebook = notebook; |
|
23 | 23 | this._baseProjectUrl = notebook.baseProjectUrl(); |
|
24 | 24 | }; |
|
25 | 25 | |
|
26 | 26 | Session.prototype.start = function(callback) { |
|
27 | 27 | var that = this; |
|
28 | 28 | var model = { |
|
29 | 29 | notebook : { |
|
30 | 30 | name : this.name, |
|
31 | 31 | path : this.path |
|
32 | 32 | } |
|
33 | 33 | }; |
|
34 | 34 | var settings = { |
|
35 | 35 | processData : false, |
|
36 | 36 | cache : false, |
|
37 | 37 | type : "POST", |
|
38 | 38 | data: JSON.stringify(model), |
|
39 | 39 | dataType : "json", |
|
40 | 40 | success : function (data, status, xhr) { |
|
41 | 41 | that._handle_start_success(data); |
|
42 | 42 | if (callback) { |
|
43 | 43 | callback(data, status, xhr); |
|
44 | 44 | } |
|
45 | 45 | }, |
|
46 | 46 | }; |
|
47 | 47 | var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions'); |
|
48 | 48 | $.ajax(url, settings); |
|
49 | 49 | }; |
|
50 | 50 | |
|
51 | 51 | Session.prototype.rename_notebook = function (name, path) { |
|
52 | 52 | this.name = name; |
|
53 | 53 | this.path = path; |
|
54 | 54 | var model = { |
|
55 | 55 | notebook : { |
|
56 | 56 | name : this.name, |
|
57 | 57 | path : this.path |
|
58 | 58 | } |
|
59 | 59 | }; |
|
60 | 60 | var settings = { |
|
61 | 61 | processData : false, |
|
62 | 62 | cache : false, |
|
63 | 63 | type : "PATCH", |
|
64 | 64 | data: JSON.stringify(model), |
|
65 | 65 | dataType : "json", |
|
66 | 66 | }; |
|
67 | 67 | var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.id); |
|
68 | 68 | $.ajax(url, settings); |
|
69 | 69 | }; |
|
70 | 70 | |
|
71 | 71 | Session.prototype.delete = function() { |
|
72 | 72 | var settings = { |
|
73 | 73 | processData : false, |
|
74 | 74 | cache : false, |
|
75 | 75 | type : "DELETE", |
|
76 | 76 | dataType : "json", |
|
77 | 77 | }; |
|
78 | this.kernel.running = false; | |
|
78 | 79 | var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.id); |
|
79 | 80 | $.ajax(url, settings); |
|
80 | 81 | }; |
|
81 | 82 | |
|
82 | 83 | // Kernel related things |
|
83 | 84 | /** |
|
84 | 85 | * Create the Kernel object associated with this Session. |
|
85 | 86 | * |
|
86 | 87 | * @method _handle_start_success |
|
87 | 88 | */ |
|
88 | 89 | Session.prototype._handle_start_success = function (data, status, xhr) { |
|
89 | 90 | this.id = data.id; |
|
90 | 91 | var base_url = utils.url_path_join($('body').data('baseKernelUrl'), "api/kernels"); |
|
91 | 92 | this.kernel = new IPython.Kernel(base_url); |
|
92 | 93 | this.kernel._kernel_started(data.kernel); |
|
93 | 94 | }; |
|
94 | 95 | |
|
95 | 96 | /** |
|
96 | 97 | * Prompt the user to restart the IPython kernel. |
|
97 | 98 | * |
|
98 | 99 | * @method restart_kernel |
|
99 | 100 | */ |
|
100 | 101 | Session.prototype.restart_kernel = function () { |
|
101 | 102 | this.kernel.restart(); |
|
102 | 103 | }; |
|
103 | 104 | |
|
104 | 105 | Session.prototype.interrupt_kernel = function() { |
|
105 | 106 | this.kernel.interrupt(); |
|
106 | 107 | }; |
|
107 | 108 | |
|
108 | 109 | |
|
109 | 110 | Session.prototype.kill_kernel = function() { |
|
110 | 111 | this.kernel.kill(); |
|
111 | 112 | }; |
|
112 | 113 | |
|
113 | 114 | IPython.Session = Session; |
|
114 | 115 | |
|
115 | 116 | return IPython; |
|
116 | 117 | |
|
117 | 118 | }(IPython)); |
General Comments 0
You need to be logged in to leave comments.
Login now