Show More
@@ -36,8 +36,8 var IPython = (function (IPython) { | |||
|
36 | 36 | * does not support change for now is set through this option |
|
37 | 37 | */ |
|
38 | 38 | var MenuBar = function (selector, options) { |
|
39 |
|
|
|
40 | if(options.baseProjectUrl!= undefined){ | |
|
39 | options = options || {}; | |
|
40 | if (options.baseProjectUrl !== undefined) { | |
|
41 | 41 | this._baseProjectUrl = options.baseProjectUrl; |
|
42 | 42 | } |
|
43 | 43 | this.selector = selector; |
@@ -55,7 +55,7 var IPython = (function (IPython) { | |||
|
55 | 55 | MenuBar.prototype.notebookPath = function() { |
|
56 | 56 | var path = $('body').data('notebookPath'); |
|
57 | 57 | path = decodeURIComponent(path); |
|
58 | return path | |
|
58 | return path; | |
|
59 | 59 | }; |
|
60 | 60 | |
|
61 | 61 | MenuBar.prototype.style = function () { |
@@ -77,7 +77,11 var IPython = (function (IPython) { | |||
|
77 | 77 | IPython.notebook.new_notebook(); |
|
78 | 78 | }); |
|
79 | 79 | this.element.find('#open_notebook').click(function () { |
|
80 | window.open(that.baseProjectUrl() + 'tree' + that.notebookPath()); | |
|
80 | window.open(utils.url_path_join( | |
|
81 | that.baseProjectUrl(), | |
|
82 | 'tree', | |
|
83 | that.notebookPath() | |
|
84 | )); | |
|
81 | 85 | }); |
|
82 | 86 | this.element.find('#copy_notebook').click(function () { |
|
83 | 87 | IPython.notebook.copy_notebook(); |
@@ -260,7 +264,7 var IPython = (function (IPython) { | |||
|
260 | 264 | MenuBar.prototype.update_restore_checkpoint = function(checkpoints) { |
|
261 | 265 | var ul = this.element.find("#restore_checkpoint").find("ul"); |
|
262 | 266 | ul.empty(); |
|
263 |
if (! |
|
|
267 | if (!checkpoints || checkpoints.length === 0) { | |
|
264 | 268 | ul.append( |
|
265 | 269 | $("<li/>") |
|
266 | 270 | .addClass("disabled") |
@@ -270,7 +274,7 var IPython = (function (IPython) { | |||
|
270 | 274 | ) |
|
271 | 275 | ); |
|
272 | 276 | return; |
|
273 |
} |
|
|
277 | } | |
|
274 | 278 | |
|
275 | 279 | checkpoints.map(function (checkpoint) { |
|
276 | 280 | var d = new Date(checkpoint.last_modified); |
@@ -128,8 +128,12 var IPython = (function (IPython) { | |||
|
128 | 128 | SaveWidget.prototype.update_address_bar = function(){ |
|
129 | 129 | var nbname = IPython.notebook.notebook_name; |
|
130 | 130 | var path = IPython.notebook.notebookPath(); |
|
131 |
var state = { |
|
|
132 |
window.history.replaceState(state, "", |
|
|
131 | var state = {path : utils.url_path_join(path,nbname)}; | |
|
132 | window.history.replaceState(state, "", utils.url_path_join( | |
|
133 | "/notebooks", | |
|
134 | path, | |
|
135 | nbname) | |
|
136 | ); | |
|
133 | 137 | } |
|
134 | 138 | |
|
135 | 139 |
@@ -72,18 +72,17 var IPython = (function (IPython) { | |||
|
72 | 72 | * Start the Python kernel |
|
73 | 73 | * @method start |
|
74 | 74 | */ |
|
75 |
|
|
|
76 | var that = this; | |
|
77 | params = params || {}; | |
|
78 | if (!this.running) { | |
|
79 | var qs = $.param(params); | |
|
80 | var url = this.base_url + '?' + qs; | |
|
81 | $.post(url, | |
|
82 | $.proxy(that._kernel_started,that), | |
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 | }; | |
|
75 | Kernel.prototype.start = function (params) { | |
|
76 | params = params || {}; | |
|
77 | if (!this.running) { | |
|
78 | var qs = $.param(params); | |
|
79 | var url = this.base_url + '?' + qs; | |
|
80 | $.post(url, | |
|
81 | $.proxy(this._kernel_started, this), | |
|
82 | 'json' | |
|
83 | ); | |
|
84 | }; | |
|
85 | }; | |
|
87 | 86 | |
|
88 | 87 | /** |
|
89 | 88 | * Restart the python kernel. |
@@ -95,12 +94,11 var IPython = (function (IPython) { | |||
|
95 | 94 | */ |
|
96 | 95 | Kernel.prototype.restart = function () { |
|
97 | 96 | $([IPython.events]).trigger('status_restarting.Kernel', {kernel: this}); |
|
98 | var that = this; | |
|
99 | 97 | if (this.running) { |
|
100 | 98 | this.stop_channels(); |
|
101 |
var url = this.kernel_url |
|
|
99 | var url = utils.url_path_join(this.kernel_url, "restart"); | |
|
102 | 100 | $.post(url, |
|
103 |
$.proxy(th |
|
|
101 | $.proxy(this._kernel_started, this), | |
|
104 | 102 | 'json' |
|
105 | 103 | ); |
|
106 | 104 | }; |
@@ -118,14 +116,14 var IPython = (function (IPython) { | |||
|
118 | 116 | ws_url = prot + location.host + ws_url; |
|
119 | 117 | }; |
|
120 | 118 | this.ws_url = ws_url; |
|
121 |
this.kernel_url = this.base_url |
|
|
119 | this.kernel_url = utils.url_path_join(this.base_url, this.kernel_id); | |
|
122 | 120 | this.start_channels(); |
|
123 | 121 | }; |
|
124 | 122 | |
|
125 | 123 | |
|
126 | 124 | Kernel.prototype._websocket_closed = function(ws_url, early) { |
|
127 | 125 | this.stop_channels(); |
|
128 |
$([IPython.events]).trigger('websocket_closed.Kernel', |
|
|
126 | $([IPython.events]).trigger('websocket_closed.Kernel', | |
|
129 | 127 | {ws_url: ws_url, kernel: this, early: early} |
|
130 | 128 | ); |
|
131 | 129 | }; |
@@ -1,5 +1,5 | |||
|
1 | 1 | //---------------------------------------------------------------------------- |
|
2 |
// Copyright (C) 20 |
|
|
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. |
@@ -10,45 +10,58 | |||
|
10 | 10 | //============================================================================ |
|
11 | 11 | |
|
12 | 12 | var IPython = (function (IPython) { |
|
13 | "use strict"; | |
|
13 | 14 | |
|
14 | var Session = function(notebook_name, notebook_path, Notebook){ | |
|
15 | var utils = IPython.utils; | |
|
16 | ||
|
17 | var Session = function(notebook_name, notebook_path, notebook){ | |
|
15 | 18 | this.kernel = null; |
|
16 | 19 | this.id = null; |
|
17 | 20 | this.name = notebook_name; |
|
18 | 21 | this.path = notebook_path; |
|
19 |
this.notebook = |
|
|
20 |
this._baseProjectUrl = |
|
|
22 | this.notebook = notebook; | |
|
23 | this._baseProjectUrl = notebook.baseProjectUrl(); | |
|
21 | 24 | }; |
|
22 | 25 | |
|
23 | 26 | Session.prototype.start = function() { |
|
24 | var that = this | |
|
25 | var notebook = {'notebook':{'name': this.name, 'path': this.path}} | |
|
27 | var that = this; | |
|
28 | var model = { | |
|
29 | notebook : { | |
|
30 | name : this.name, | |
|
31 | path : this.path | |
|
32 | } | |
|
33 | }; | |
|
26 | 34 | var settings = { |
|
27 | 35 | processData : false, |
|
28 | 36 | cache : false, |
|
29 | 37 | type : "POST", |
|
30 |
data: JSON.stringify( |
|
|
38 | data: JSON.stringify(model), | |
|
31 | 39 | dataType : "json", |
|
32 | 40 | success : $.proxy(this.start_kernel, that), |
|
33 | 41 | }; |
|
34 |
var url = this._baseProjectUrl |
|
|
42 | var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions'); | |
|
35 | 43 | $.ajax(url, settings); |
|
36 | 44 | }; |
|
37 | 45 | |
|
38 | 46 | Session.prototype.notebook_rename = function (name, path) { |
|
39 | 47 | this.name = name; |
|
40 | 48 | this.path = path; |
|
41 | var notebook = {'notebook':{'name':name, 'path': path}}; | |
|
49 | var model = { | |
|
50 | notebook : { | |
|
51 | name : this.name, | |
|
52 | path : this.path | |
|
53 | } | |
|
54 | }; | |
|
42 | 55 | var settings = { |
|
43 | 56 | processData : false, |
|
44 | 57 | cache : false, |
|
45 | 58 | type : "PATCH", |
|
46 |
data: JSON.stringify( |
|
|
59 | data: JSON.stringify(model), | |
|
47 | 60 | dataType : "json", |
|
48 | 61 | }; |
|
49 |
var url = this._baseProjectUrl |
|
|
62 | var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.session_id); | |
|
50 | 63 | $.ajax(url, settings); |
|
51 | } | |
|
64 | }; | |
|
52 | 65 | |
|
53 | 66 | Session.prototype.delete_session = function() { |
|
54 | 67 | var settings = { |
@@ -57,7 +70,7 var IPython = (function (IPython) { | |||
|
57 | 70 | type : "DELETE", |
|
58 | 71 | dataType : "json", |
|
59 | 72 | }; |
|
60 |
var url = this._baseProjectUrl |
|
|
73 | var url = utils.url_path_join(this._baseProjectUrl, 'api/sessions', this.session_id); | |
|
61 | 74 | $.ajax(url, settings); |
|
62 | 75 | }; |
|
63 | 76 | |
@@ -70,7 +83,7 var IPython = (function (IPython) { | |||
|
70 | 83 | Session.prototype.start_kernel = function (json) { |
|
71 | 84 | this.id = json.id; |
|
72 | 85 | this.kernel_content = json.kernel; |
|
73 |
var base_url = $('body').data('baseKernelUrl') |
|
|
86 | var base_url = utils.url_path_join($('body').data('baseKernelUrl'), "api/kernels"); | |
|
74 | 87 | this.kernel = new IPython.Kernel(base_url, this.session_id); |
|
75 | 88 | this.kernel._kernel_started(this.kernel_content); |
|
76 | 89 | }; |
@@ -90,12 +103,11 var IPython = (function (IPython) { | |||
|
90 | 103 | |
|
91 | 104 | |
|
92 | 105 | Session.prototype.kill_kernel = function() { |
|
93 |
this.kernel.kill(); |
|
|
106 | this.kernel.kill(); | |
|
94 | 107 | }; |
|
95 | 108 | |
|
96 | 109 | IPython.Session = Session; |
|
97 | 110 | |
|
98 | ||
|
99 | 111 | return IPython; |
|
100 | 112 | |
|
101 | 113 | }(IPython)); |
General Comments 0
You need to be logged in to leave comments.
Login now