Show More
@@ -1,26 +1,48 b'' | |||
|
1 | 1 | //---------------------------------------------------------------------------- |
|
2 | 2 | // Copyright (C) 2014 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 | // Running Kernels List |
|
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 | var KernelList = function (selector, options) { |
|
17 | IPython.NotebookList.call(this, selector, options); | |
|
18 | IPython.NotebookList.call(this, selector, options, 'running'); | |
|
18 | 19 | }; |
|
19 | 20 | |
|
20 | KernelList.prototype = IPython.NotebookList.prototype; | |
|
21 | KernelList.prototype = Object.create(IPython.NotebookList.prototype); | |
|
21 | 22 | |
|
23 | KernelList.prototype.sessions_loaded = function (d) { | |
|
24 | // clear out the previous list | |
|
25 | this.clear_list(); | |
|
26 | var len = d.length; | |
|
27 | var item; | |
|
28 | for (var i=0; i < d.length; i++) { | |
|
29 | var path = utils.url_path_join(d[i].notebook.path, d[i].notebook.name); | |
|
30 | var name = d[i].name; | |
|
31 | item = this.new_notebook_item(i); | |
|
32 | this.add_link(path, path, item); | |
|
33 | this.sessions[path] = d[i].id; | |
|
34 | this.add_shutdown_button(item,this.sessions[path]); | |
|
35 | } | |
|
36 | ||
|
37 | if (len > 0) { | |
|
38 | $('#' + this.element_name + '_list_header').hide(); | |
|
39 | } else { | |
|
40 | $('#' + this.element_name + '_list_header').show(); | |
|
41 | } | |
|
42 | } | |
|
43 | ||
|
22 | 44 | IPython.KernelList = KernelList; |
|
23 | 45 | |
|
24 | 46 | return IPython; |
|
25 | 47 | |
|
26 | 48 | }(IPython)); |
@@ -1,90 +1,92 b'' | |||
|
1 | 1 | //---------------------------------------------------------------------------- |
|
2 | 2 | // Copyright (C) 2008-2011 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 | // On document ready |
|
10 | 10 | //============================================================================ |
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | $(document).ready(function () { |
|
14 | 14 | |
|
15 | 15 | IPython.page = new IPython.Page(); |
|
16 | 16 | |
|
17 | 17 | $('#new_notebook').button().click(function (e) { |
|
18 | 18 | IPython.notebook_list.new_notebook() |
|
19 | 19 | }); |
|
20 | 20 | |
|
21 | 21 | var opts = { |
|
22 | 22 | base_url : IPython.utils.get_body_data("baseUrl"), |
|
23 | 23 | notebook_path : IPython.utils.get_body_data("notebookPath"), |
|
24 | 24 | }; |
|
25 | 25 | IPython.notebook_list = new IPython.NotebookList('#notebook_list', opts); |
|
26 | 26 | IPython.cluster_list = new IPython.ClusterList('#cluster_list', opts); |
|
27 |
IPython.kernel_list = new IPython.KernelList('# |
|
|
27 | IPython.kernel_list = new IPython.KernelList('#running_list', opts); | |
|
28 | 28 | IPython.login_widget = new IPython.LoginWidget('#login_widget', opts); |
|
29 | 29 | |
|
30 | 30 | var interval_id=0; |
|
31 | 31 | // auto refresh every xx secondes, no need to be fast, |
|
32 | 32 | // update is done at least when page get focus |
|
33 | 33 | var time_refresh = 60; // in sec |
|
34 | 34 | |
|
35 | 35 | var enable_autorefresh = function(){ |
|
36 | 36 | //refresh immediately , then start interval |
|
37 | 37 | if($('.upload_button').length == 0) |
|
38 | 38 | { |
|
39 | 39 | IPython.notebook_list.load_sessions(); |
|
40 | IPython.kernel_list.load_sessions(); | |
|
40 | 41 | IPython.cluster_list.load_list(); |
|
41 | 42 | } |
|
42 | 43 | if (!interval_id){ |
|
43 | 44 | interval_id = setInterval(function(){ |
|
44 | 45 | if($('.upload_button').length == 0) |
|
45 | 46 | { |
|
46 | 47 | IPython.notebook_list.load_sessions(); |
|
48 | IPython.kernel_list.load_sessions(); | |
|
47 | 49 | IPython.cluster_list.load_list(); |
|
48 | 50 | } |
|
49 | 51 | }, time_refresh*1000); |
|
50 | 52 | } |
|
51 | 53 | } |
|
52 | 54 | |
|
53 | 55 | var disable_autorefresh = function(){ |
|
54 | 56 | clearInterval(interval_id); |
|
55 | 57 | interval_id = 0; |
|
56 | 58 | } |
|
57 | 59 | |
|
58 | 60 | // stop autorefresh when page lose focus |
|
59 | 61 | $(window).blur(function() { |
|
60 | 62 | disable_autorefresh(); |
|
61 | 63 | }) |
|
62 | 64 | |
|
63 | 65 | //re-enable when page get focus back |
|
64 | 66 | $(window).focus(function() { |
|
65 | 67 | enable_autorefresh(); |
|
66 | 68 | }); |
|
67 | 69 | |
|
68 | 70 | // finally start it, it will refresh immediately |
|
69 | 71 | enable_autorefresh(); |
|
70 | 72 | |
|
71 | 73 | IPython.page.show(); |
|
72 | 74 | |
|
73 | 75 | // bound the upload method to the on change of the file select list |
|
74 | 76 | $("#alternate_upload").change(function (event){ |
|
75 | 77 | IPython.notebook_list.handelFilesUpload(event,'form'); |
|
76 | 78 | }); |
|
77 | 79 | |
|
78 | 80 | // set hash on tab click |
|
79 | 81 | $("#tabs").find("a").click(function() { |
|
80 | 82 | window.location.hash = $(this).attr("href"); |
|
81 | 83 | }) |
|
82 | 84 | |
|
83 | 85 | // load tab if url hash |
|
84 | 86 | if (window.location.hash) { |
|
85 | 87 | $("#tabs").find("a[href=" + window.location.hash + "]").click(); |
|
86 | 88 | } |
|
87 | 89 | |
|
88 | 90 | |
|
89 | 91 | }); |
|
90 | 92 |
@@ -1,431 +1,433 b'' | |||
|
1 | 1 | //---------------------------------------------------------------------------- |
|
2 | 2 | // Copyright (C) 2011 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 | // NotebookList |
|
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 | var NotebookList = function (selector, options) { | |
|
17 | var NotebookList = function (selector, options, element_name) { | |
|
18 | // allow code re-use by just changing element_name in kernellist.js | |
|
19 | this.element_name = element_name || 'notebook'; | |
|
18 | 20 | this.selector = selector; |
|
19 | 21 | if (this.selector !== undefined) { |
|
20 | 22 | this.element = $(selector); |
|
21 | 23 | this.style(); |
|
22 | 24 | this.bind_events(); |
|
23 | 25 | } |
|
24 | 26 | this.notebooks_list = []; |
|
25 | 27 | this.sessions = {}; |
|
26 | 28 | this.base_url = options.base_url || utils.get_body_data("baseUrl"); |
|
27 | 29 | this.notebook_path = options.notebook_path || utils.get_body_data("notebookPath"); |
|
28 | 30 | }; |
|
29 | 31 | |
|
30 | 32 | NotebookList.prototype.style = function () { |
|
31 |
$('# |
|
|
33 | $('#' + this.element_name + '_toolbar').addClass('list_toolbar'); | |
|
32 | 34 | $('#drag_info').addClass('toolbar_info'); |
|
33 |
$('# |
|
|
34 |
$('# |
|
|
35 | $('#' + this.element_name + '_buttons').addClass('toolbar_buttons'); | |
|
36 | $('#' + this.element_name + '_list_header').addClass('list_header'); | |
|
35 | 37 | this.element.addClass("list_container"); |
|
36 | 38 | }; |
|
37 | 39 | |
|
38 | 40 | |
|
39 | 41 | NotebookList.prototype.bind_events = function () { |
|
40 | 42 | var that = this; |
|
41 | 43 | $('#refresh_notebook_list').click(function () { |
|
42 | 44 | that.load_list(); |
|
43 | 45 | }); |
|
44 | 46 | this.element.bind('dragover', function () { |
|
45 | 47 | return false; |
|
46 | 48 | }); |
|
47 | 49 | this.element.bind('drop', function(event){ |
|
48 | 50 | that.handelFilesUpload(event,'drop'); |
|
49 | 51 | return false; |
|
50 | 52 | }); |
|
51 | 53 | }; |
|
52 | 54 | |
|
53 | 55 | NotebookList.prototype.handelFilesUpload = function(event, dropOrForm) { |
|
54 | 56 | var that = this; |
|
55 | 57 | var files; |
|
56 | 58 | if(dropOrForm =='drop'){ |
|
57 | 59 | files = event.originalEvent.dataTransfer.files; |
|
58 | 60 | } else |
|
59 | 61 | { |
|
60 | 62 | files = event.originalEvent.target.files; |
|
61 | 63 | } |
|
62 | 64 | for (var i = 0; i < files.length; i++) { |
|
63 | 65 | var f = files[i]; |
|
64 | 66 | var reader = new FileReader(); |
|
65 | 67 | reader.readAsText(f); |
|
66 | 68 | var name_and_ext = utils.splitext(f.name); |
|
67 | 69 | var file_ext = name_and_ext[1]; |
|
68 | 70 | if (file_ext === '.ipynb') { |
|
69 | 71 | var item = that.new_notebook_item(0); |
|
70 | 72 | that.add_name_input(f.name, item); |
|
71 | 73 | // Store the notebook item in the reader so we can use it later |
|
72 | 74 | // to know which item it belongs to. |
|
73 | 75 | $(reader).data('item', item); |
|
74 | 76 | reader.onload = function (event) { |
|
75 | 77 | var nbitem = $(event.target).data('item'); |
|
76 | 78 | that.add_notebook_data(event.target.result, nbitem); |
|
77 | 79 | that.add_upload_button(nbitem); |
|
78 | 80 | }; |
|
79 | 81 | } else { |
|
80 | 82 | var dialog = 'Uploaded notebooks must be .ipynb files'; |
|
81 | 83 | IPython.dialog.modal({ |
|
82 | 84 | title : 'Invalid file type', |
|
83 | 85 | body : dialog, |
|
84 | 86 | buttons : {'OK' : {'class' : 'btn-primary'}} |
|
85 | 87 | }); |
|
86 | 88 | } |
|
87 | 89 | } |
|
88 | 90 | // Replace the file input form wth a clone of itself. This is required to |
|
89 | 91 | // reset the form. Otherwise, if you upload a file, delete it and try to |
|
90 | 92 | // upload it again, the changed event won't fire. |
|
91 | 93 | var form = $('input.fileinput'); |
|
92 | 94 | form.replaceWith(form.clone(true)); |
|
93 | 95 | return false; |
|
94 | 96 | }; |
|
95 | 97 | |
|
96 | 98 | NotebookList.prototype.clear_list = function () { |
|
97 | 99 | this.element.children('.list_item').remove(); |
|
98 | 100 | }; |
|
99 | 101 | |
|
100 | 102 | NotebookList.prototype.load_sessions = function(){ |
|
101 | 103 | var that = this; |
|
102 | 104 | var settings = { |
|
103 | 105 | processData : false, |
|
104 | 106 | cache : false, |
|
105 | 107 | type : "GET", |
|
106 | 108 | dataType : "json", |
|
107 | 109 | success : $.proxy(that.sessions_loaded, this) |
|
108 | 110 | }; |
|
109 | 111 | var url = utils.url_join_encode(this.base_url, 'api/sessions'); |
|
110 | 112 | $.ajax(url,settings); |
|
111 | 113 | }; |
|
112 | 114 | |
|
113 | 115 | |
|
114 | 116 | NotebookList.prototype.sessions_loaded = function(data){ |
|
115 | 117 | this.sessions = {}; |
|
116 | 118 | var len = data.length; |
|
117 | 119 | if (len > 0) { |
|
118 | 120 | for (var i=0; i<len; i++) { |
|
119 | 121 | var nb_path; |
|
120 | 122 | if (!data[i].notebook.path) { |
|
121 | 123 | nb_path = data[i].notebook.name; |
|
122 | 124 | } |
|
123 | 125 | else { |
|
124 | 126 | nb_path = utils.url_path_join( |
|
125 | 127 | data[i].notebook.path, |
|
126 | 128 | data[i].notebook.name |
|
127 | 129 | ); |
|
128 | 130 | } |
|
129 | 131 | this.sessions[nb_path] = data[i].id; |
|
130 | 132 | } |
|
131 | 133 | } |
|
132 | 134 | this.load_list(); |
|
133 | 135 | }; |
|
134 | 136 | |
|
135 | 137 | NotebookList.prototype.load_list = function () { |
|
136 | 138 | var that = this; |
|
137 | 139 | var settings = { |
|
138 | 140 | processData : false, |
|
139 | 141 | cache : false, |
|
140 | 142 | type : "GET", |
|
141 | 143 | dataType : "json", |
|
142 | 144 | success : $.proxy(this.list_loaded, this), |
|
143 | 145 | error : $.proxy( function(){ |
|
144 | 146 | that.list_loaded([], null, null, {msg:"Error connecting to server."}); |
|
145 | 147 | },this) |
|
146 | 148 | }; |
|
147 | 149 | |
|
148 | 150 | var url = utils.url_join_encode( |
|
149 | 151 | this.base_url, |
|
150 | 152 | 'api', |
|
151 | 153 | 'notebooks', |
|
152 | 154 | this.notebook_path |
|
153 | 155 | ); |
|
154 | 156 | $.ajax(url, settings); |
|
155 | 157 | }; |
|
156 | 158 | |
|
157 | 159 | |
|
158 | 160 | NotebookList.prototype.list_loaded = function (data, status, xhr, param) { |
|
159 | 161 | var message = 'Notebook list empty.'; |
|
160 | 162 | if (param !== undefined && param.msg) { |
|
161 | 163 | message = param.msg; |
|
162 | 164 | } |
|
163 | 165 | var item = null; |
|
164 | 166 | var len = data.length; |
|
165 | 167 | this.clear_list(); |
|
166 | 168 | if (len === 0) { |
|
167 | 169 | item = this.new_notebook_item(0); |
|
168 | 170 | var span12 = item.children().first(); |
|
169 | 171 | span12.empty(); |
|
170 | 172 | span12.append($('<div style="margin:auto;text-align:center;color:grey"/>').text(message)); |
|
171 | 173 | } |
|
172 | 174 | var path = this.notebook_path; |
|
173 | 175 | var offset = 0; |
|
174 | 176 | if (path !== '') { |
|
175 | 177 | item = this.new_notebook_item(0); |
|
176 | 178 | this.add_dir(path, '..', item); |
|
177 | 179 | offset = 1; |
|
178 | 180 | } |
|
179 | 181 | for (var i=0; i<len; i++) { |
|
180 | 182 | if (data[i].type === 'directory') { |
|
181 | 183 | var name = data[i].name; |
|
182 | 184 | item = this.new_notebook_item(i+offset); |
|
183 | 185 | this.add_dir(path, name, item); |
|
184 | 186 | } else { |
|
185 | 187 | var name = data[i].name; |
|
186 | 188 | item = this.new_notebook_item(i+offset); |
|
187 | 189 | this.add_link(path, name, item); |
|
188 | 190 | name = utils.url_path_join(path, name); |
|
189 | 191 | if(this.sessions[name] === undefined){ |
|
190 | 192 | this.add_delete_button(item); |
|
191 | 193 | } else { |
|
192 | 194 | this.add_shutdown_button(item,this.sessions[name]); |
|
193 | 195 | } |
|
194 | 196 | } |
|
195 | 197 | } |
|
196 | 198 | }; |
|
197 | 199 | |
|
198 | 200 | |
|
199 | 201 | NotebookList.prototype.new_notebook_item = function (index) { |
|
200 | 202 | var item = $('<div/>').addClass("list_item").addClass("row-fluid"); |
|
201 | 203 | // item.addClass('list_item ui-widget ui-widget-content ui-helper-clearfix'); |
|
202 | 204 | // item.css('border-top-style','none'); |
|
203 | 205 | item.append($("<div/>").addClass("span12").append( |
|
204 | 206 | $('<i/>').addClass('item_icon') |
|
205 | 207 | ).append( |
|
206 | 208 | $("<a/>").addClass("item_link").append( |
|
207 | 209 | $("<span/>").addClass("item_name") |
|
208 | 210 | ) |
|
209 | 211 | ).append( |
|
210 | 212 | $('<div/>').addClass("item_buttons btn-group pull-right") |
|
211 | 213 | )); |
|
212 | 214 | |
|
213 | 215 | if (index === -1) { |
|
214 | 216 | this.element.append(item); |
|
215 | 217 | } else { |
|
216 | 218 | this.element.children().eq(index).after(item); |
|
217 | 219 | } |
|
218 | 220 | return item; |
|
219 | 221 | }; |
|
220 | 222 | |
|
221 | 223 | |
|
222 | 224 | NotebookList.prototype.add_dir = function (path, name, item) { |
|
223 | 225 | item.data('name', name); |
|
224 | 226 | item.data('path', path); |
|
225 | 227 | item.find(".item_name").text(name); |
|
226 | 228 | item.find(".item_icon").addClass('icon-folder-open'); |
|
227 | 229 | item.find("a.item_link") |
|
228 | 230 | .attr('href', |
|
229 | 231 | utils.url_join_encode( |
|
230 | 232 | this.base_url, |
|
231 | 233 | "tree", |
|
232 | 234 | path, |
|
233 | 235 | name |
|
234 | 236 | ) |
|
235 | 237 | ); |
|
236 | 238 | }; |
|
237 | 239 | |
|
238 | 240 | |
|
239 | 241 | NotebookList.prototype.add_link = function (path, nbname, item) { |
|
240 | 242 | item.data('nbname', nbname); |
|
241 | 243 | item.data('path', path); |
|
242 | 244 | item.find(".item_name").text(nbname); |
|
243 | 245 | item.find(".item_icon").addClass('icon-book'); |
|
244 | 246 | item.find("a.item_link") |
|
245 | 247 | .attr('href', |
|
246 | 248 | utils.url_join_encode( |
|
247 | 249 | this.base_url, |
|
248 | 250 | "notebooks", |
|
249 | 251 | path, |
|
250 | 252 | nbname |
|
251 | 253 | ) |
|
252 | 254 | ).attr('target','_blank'); |
|
253 | 255 | }; |
|
254 | 256 | |
|
255 | 257 | |
|
256 | 258 | NotebookList.prototype.add_name_input = function (nbname, item) { |
|
257 | 259 | item.data('nbname', nbname); |
|
258 | 260 | item.find(".item_icon").addClass('icon-book'); |
|
259 | 261 | item.find(".item_name").empty().append( |
|
260 | 262 | $('<input/>') |
|
261 | 263 | .addClass("nbname_input") |
|
262 | 264 | .attr('value', utils.splitext(nbname)[0]) |
|
263 | 265 | .attr('size', '30') |
|
264 | 266 | .attr('type', 'text') |
|
265 | 267 | ); |
|
266 | 268 | }; |
|
267 | 269 | |
|
268 | 270 | |
|
269 | 271 | NotebookList.prototype.add_notebook_data = function (data, item) { |
|
270 | 272 | item.data('nbdata', data); |
|
271 | 273 | }; |
|
272 | 274 | |
|
273 | 275 | |
|
274 | 276 | NotebookList.prototype.add_shutdown_button = function (item, session) { |
|
275 | 277 | var that = this; |
|
276 | 278 | var shutdown_button = $("<button/>").text("Shutdown").addClass("btn btn-mini btn-danger"). |
|
277 | 279 | click(function (e) { |
|
278 | 280 | var settings = { |
|
279 | 281 | processData : false, |
|
280 | 282 | cache : false, |
|
281 | 283 | type : "DELETE", |
|
282 | 284 | dataType : "json", |
|
283 | 285 | success : function () { |
|
284 | 286 | that.load_sessions(); |
|
285 | 287 | } |
|
286 | 288 | }; |
|
287 | 289 | var url = utils.url_join_encode( |
|
288 | 290 | that.base_url, |
|
289 | 291 | 'api/sessions', |
|
290 | 292 | session |
|
291 | 293 | ); |
|
292 | 294 | $.ajax(url, settings); |
|
293 | 295 | return false; |
|
294 | 296 | }); |
|
295 | 297 | // var new_buttons = item.find('a'); // shutdown_button; |
|
296 | 298 | item.find(".item_buttons").text("").append(shutdown_button); |
|
297 | 299 | }; |
|
298 | 300 | |
|
299 | 301 | NotebookList.prototype.add_delete_button = function (item) { |
|
300 | 302 | var new_buttons = $('<span/>').addClass("btn-group pull-right"); |
|
301 | 303 | var notebooklist = this; |
|
302 | 304 | var delete_button = $("<button/>").text("Delete").addClass("btn btn-mini"). |
|
303 | 305 | click(function (e) { |
|
304 | 306 | // $(this) is the button that was clicked. |
|
305 | 307 | var that = $(this); |
|
306 | 308 | // We use the nbname and notebook_id from the parent notebook_item element's |
|
307 | 309 | // data because the outer scopes values change as we iterate through the loop. |
|
308 | 310 | var parent_item = that.parents('div.list_item'); |
|
309 | 311 | var nbname = parent_item.data('nbname'); |
|
310 | 312 | var message = 'Are you sure you want to permanently delete the notebook: ' + nbname + '?'; |
|
311 | 313 | IPython.dialog.modal({ |
|
312 | 314 | title : "Delete notebook", |
|
313 | 315 | body : message, |
|
314 | 316 | buttons : { |
|
315 | 317 | Delete : { |
|
316 | 318 | class: "btn-danger", |
|
317 | 319 | click: function() { |
|
318 | 320 | var settings = { |
|
319 | 321 | processData : false, |
|
320 | 322 | cache : false, |
|
321 | 323 | type : "DELETE", |
|
322 | 324 | dataType : "json", |
|
323 | 325 | success : function (data, status, xhr) { |
|
324 | 326 | parent_item.remove(); |
|
325 | 327 | } |
|
326 | 328 | }; |
|
327 | 329 | var url = utils.url_join_encode( |
|
328 | 330 | notebooklist.base_url, |
|
329 | 331 | 'api/notebooks', |
|
330 | 332 | notebooklist.notebook_path, |
|
331 | 333 | nbname |
|
332 | 334 | ); |
|
333 | 335 | $.ajax(url, settings); |
|
334 | 336 | } |
|
335 | 337 | }, |
|
336 | 338 | Cancel : {} |
|
337 | 339 | } |
|
338 | 340 | }); |
|
339 | 341 | return false; |
|
340 | 342 | }); |
|
341 | 343 | item.find(".item_buttons").text("").append(delete_button); |
|
342 | 344 | }; |
|
343 | 345 | |
|
344 | 346 | |
|
345 | 347 | NotebookList.prototype.add_upload_button = function (item) { |
|
346 | 348 | var that = this; |
|
347 | 349 | var upload_button = $('<button/>').text("Upload") |
|
348 | 350 | .addClass('btn btn-primary btn-mini upload_button') |
|
349 | 351 | .click(function (e) { |
|
350 | 352 | var nbname = item.find('.item_name > input').val(); |
|
351 | 353 | if (nbname.slice(nbname.length-6, nbname.length) != ".ipynb") { |
|
352 | 354 | nbname = nbname + ".ipynb"; |
|
353 | 355 | } |
|
354 | 356 | var path = that.notebook_path; |
|
355 | 357 | var nbdata = item.data('nbdata'); |
|
356 | 358 | var content_type = 'application/json'; |
|
357 | 359 | var model = { |
|
358 | 360 | content : JSON.parse(nbdata), |
|
359 | 361 | }; |
|
360 | 362 | var settings = { |
|
361 | 363 | processData : false, |
|
362 | 364 | cache : false, |
|
363 | 365 | type : 'PUT', |
|
364 | 366 | dataType : 'json', |
|
365 | 367 | data : JSON.stringify(model), |
|
366 | 368 | headers : {'Content-Type': content_type}, |
|
367 | 369 | success : function (data, status, xhr) { |
|
368 | 370 | that.add_link(path, nbname, item); |
|
369 | 371 | that.add_delete_button(item); |
|
370 | 372 | }, |
|
371 | 373 | error : function (data, status, xhr) { |
|
372 | 374 | console.log(data, status); |
|
373 | 375 | } |
|
374 | 376 | }; |
|
375 | 377 | |
|
376 | 378 | var url = utils.url_join_encode( |
|
377 | 379 | that.base_url, |
|
378 | 380 | 'api/notebooks', |
|
379 | 381 | that.notebook_path, |
|
380 | 382 | nbname |
|
381 | 383 | ); |
|
382 | 384 | $.ajax(url, settings); |
|
383 | 385 | return false; |
|
384 | 386 | }); |
|
385 | 387 | var cancel_button = $('<button/>').text("Cancel") |
|
386 | 388 | .addClass("btn btn-mini") |
|
387 | 389 | .click(function (e) { |
|
388 | 390 | console.log('cancel click'); |
|
389 | 391 | item.remove(); |
|
390 | 392 | return false; |
|
391 | 393 | }); |
|
392 | 394 | item.find(".item_buttons").empty() |
|
393 | 395 | .append(upload_button) |
|
394 | 396 | .append(cancel_button); |
|
395 | 397 | }; |
|
396 | 398 | |
|
397 | 399 | |
|
398 | 400 | NotebookList.prototype.new_notebook = function(){ |
|
399 | 401 | var path = this.notebook_path; |
|
400 | 402 | var base_url = this.base_url; |
|
401 | 403 | var settings = { |
|
402 | 404 | processData : false, |
|
403 | 405 | cache : false, |
|
404 | 406 | type : "POST", |
|
405 | 407 | dataType : "json", |
|
406 | 408 | async : false, |
|
407 | 409 | success : function (data, status, xhr) { |
|
408 | 410 | var notebook_name = data.name; |
|
409 | 411 | window.open( |
|
410 | 412 | utils.url_join_encode( |
|
411 | 413 | base_url, |
|
412 | 414 | 'notebooks', |
|
413 | 415 | path, |
|
414 | 416 | notebook_name), |
|
415 | 417 | '_blank' |
|
416 | 418 | ); |
|
417 | 419 | } |
|
418 | 420 | }; |
|
419 | 421 | var url = utils.url_join_encode( |
|
420 | 422 | base_url, |
|
421 | 423 | 'api/notebooks', |
|
422 | 424 | path |
|
423 | 425 | ); |
|
424 | 426 | $.ajax(url, settings); |
|
425 | 427 | }; |
|
426 | 428 | |
|
427 | 429 | IPython.NotebookList = NotebookList; |
|
428 | 430 | |
|
429 | 431 | return IPython; |
|
430 | 432 | |
|
431 | 433 | }(IPython)); |
@@ -1,120 +1,122 b'' | |||
|
1 | 1 | {% extends "page.html" %} |
|
2 | 2 | |
|
3 | 3 | {% block title %}{{page_title}}{% endblock %} |
|
4 | 4 | |
|
5 | 5 | |
|
6 | 6 | {% block stylesheet %} |
|
7 | 7 | {{super()}} |
|
8 | 8 | <link rel="stylesheet" href="{{ static_url("tree/css/override.css") }}" type="text/css" /> |
|
9 | 9 | {% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block params %} |
|
12 | 12 | |
|
13 | 13 | data-project="{{project}}" |
|
14 | 14 | data-base-url="{{base_url}}" |
|
15 | 15 | data-notebook-path="{{notebook_path}}" |
|
16 | 16 | data-base-kernel-url="{{base_kernel_url}}" |
|
17 | 17 | |
|
18 | 18 | {% endblock %} |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | {% block site %} |
|
22 | 22 | |
|
23 | 23 | <div id="ipython-main-app" class="container"> |
|
24 | 24 | |
|
25 | 25 | <div id="tab_content" class="tabbable"> |
|
26 | 26 | <ul id="tabs" class="nav nav-tabs"> |
|
27 | 27 | <li class="active"><a href="#notebooks" data-toggle="tab">Notebooks</a></li> |
|
28 | 28 | <li><a href="#running" data-toggle="tab">Running</a></li> |
|
29 | 29 | <li><a href="#clusters" data-toggle="tab">Clusters</a></li> |
|
30 | 30 | </ul> |
|
31 | 31 | |
|
32 | 32 | <div class="tab-content"> |
|
33 | 33 | <div id="notebooks" class="tab-pane active"> |
|
34 | 34 | <div id="notebook_toolbar" class="row-fluid"> |
|
35 | 35 | <div class="span8"> |
|
36 | 36 | <form id='alternate_upload' class='alternate_upload' > |
|
37 | 37 | <span id="drag_info" style="position:absolute" > |
|
38 | 38 | To import a notebook, drag the file onto the listing below or <strong>click here</strong>. |
|
39 | 39 | </span> |
|
40 | 40 | <input type="file" name="datafile" class="fileinput" multiple='multiple'> |
|
41 | 41 | </form> |
|
42 | 42 | </div> |
|
43 | 43 | <div class="span4 clearfix"> |
|
44 | 44 | <span id="notebook_buttons" class="pull-right"> |
|
45 | 45 | <button id="new_notebook" title="Create new notebook" class="btn btn-small">New Notebook</button> |
|
46 | 46 | <button id="refresh_notebook_list" title="Refresh notebook list" class="btn btn-small"><i class="icon-refresh"></i></button> |
|
47 | 47 | </span> |
|
48 | 48 | </div> |
|
49 | 49 | </div> |
|
50 | 50 | |
|
51 | 51 | <div id="notebook_list"> |
|
52 | 52 | <div id="notebook_list_header" class="row-fluid list_header"> |
|
53 | 53 | <div id="project_name"> |
|
54 | 54 | <ul class="breadcrumb"> |
|
55 | 55 | <li><a href="{{breadcrumbs[0][0]}}"><i class="icon-home"></i></a><span>/</span></li> |
|
56 | 56 | {% for crumb in breadcrumbs[1:] %} |
|
57 | 57 | <li><a href="{{crumb[0]}}">{{crumb[1]}}</a> <span>/</span></li> |
|
58 | 58 | {% endfor %} |
|
59 | 59 | </ul> |
|
60 | 60 | </div> |
|
61 | 61 | </div> |
|
62 | 62 | </div> |
|
63 | 63 | </div> |
|
64 | 64 | |
|
65 | 65 | <div id="running" class="tab-pane"> |
|
66 | 66 | |
|
67 | 67 | <div id="running_toolbar" class="row-fluid"> |
|
68 | 68 | <div class="span8"> |
|
69 | 69 | <span id="running_list_info">Currently running IPython notebooks</span> |
|
70 | 70 | </div> |
|
71 | 71 | <div class="span4" class="clearfix"> |
|
72 | 72 | <span id="running_buttons" class="pull-right"> |
|
73 |
<button id="refresh_running_list" title="Refresh |
|
|
73 | <button id="refresh_running_list" title="Refresh running list" class="btn btn-small"><i class="icon-refresh"></i></button> | |
|
74 | 74 | </span> |
|
75 | 75 | </div> |
|
76 | 76 | </div> |
|
77 | 77 | |
|
78 | 78 | <div id="running_list"> |
|
79 | <div id="running_list_header" class="row-fluid list_header"> | |
|
80 | </div> | |
|
79 | <div id="running_list_header" class="row-fluid list_header" style='display:none'> | |
|
80 | <div> There are no actively running kernels </div> | |
|
81 | <!-- damn it, I seem to need this stupid placeholder, otherwise items don't get added to the list --> | |
|
82 | </div> | |
|
81 | 83 | </div> |
|
82 | 84 | </div> |
|
83 | 85 | |
|
84 | 86 | <div id="clusters" class="tab-pane"> |
|
85 | 87 | |
|
86 | 88 | <div id="cluster_toolbar" class="row-fluid"> |
|
87 | 89 | <div class="span8"> |
|
88 | 90 | <span id="cluster_list_info">IPython parallel computing clusters</span> |
|
89 | 91 | </div> |
|
90 | 92 | <div class="span4" class="clearfix"> |
|
91 | 93 | <span id="cluster_buttons" class="pull-right"> |
|
92 | 94 | <button id="refresh_cluster_list" title="Refresh cluster list" class="btn btn-small"><i class="icon-refresh"></i></button> |
|
93 | 95 | </span> |
|
94 | 96 | </div> |
|
95 | 97 | </div> |
|
96 | 98 | |
|
97 | 99 | <div id="cluster_list"> |
|
98 | 100 | <div id="cluster_list_header" class="row-fluid list_header"> |
|
99 | 101 | <div class="profile_col span4">profile</div> |
|
100 | 102 | <div class="status_col span3">status</div> |
|
101 | 103 | <div class="engines_col span3" title="Enter the number of engines to start or empty for default"># of engines</div> |
|
102 | 104 | <div class="action_col span2">action</div> |
|
103 | 105 | </div> |
|
104 | 106 | </div> |
|
105 | 107 | </div> |
|
106 | 108 | </div> |
|
107 | 109 | |
|
108 | 110 | </div> |
|
109 | 111 | |
|
110 | 112 | {% endblock %} |
|
111 | 113 | |
|
112 | 114 | {% block script %} |
|
113 | 115 | {{super()}} |
|
114 | 116 | <script src="{{ static_url("base/js/utils.js") }}" type="text/javascript" charset="utf-8"></script> |
|
115 | 117 | <script src="{{static_url("base/js/dialog.js") }}" type="text/javascript" charset="utf-8"></script> |
|
116 | 118 | <script src="{{static_url("tree/js/notebooklist.js") }}" type="text/javascript" charset="utf-8"></script> |
|
117 | 119 | <script src="{{static_url("tree/js/kernellist.js") }}" type="text/javascript" charset="utf-8"></script> |
|
118 | 120 | <script src="{{static_url("tree/js/clusterlist.js") }}" type="text/javascript" charset="utf-8"></script> |
|
119 | 121 | <script src="{{static_url("tree/js/main.js") }}" type="text/javascript" charset="utf-8"></script> |
|
120 | 122 | {% endblock %} |
General Comments 0
You need to be logged in to leave comments.
Login now