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