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