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