##// END OF EJS Templates
manual rebase static/tree/
Zachary Sailer -
Show More
@@ -13,9 +13,17 b''
13 $(document).ready(function () {
13 $(document).ready(function () {
14
14
15 IPython.page = new IPython.Page();
15 IPython.page = new IPython.Page();
16 $('#new_notebook').click(function (e) {
16
17 window.open($('body').data('baseProjectUrl')+'new');
17 if ($('body').data('notebookPath') == "") {
18 });
18 $('#new_notebook').button().click(function (e) {
19 window.open($('body').data('baseProjectUrl')+'notebooks/'+'new');
20 });
21 }
22 else {
23 $('#new_notebook').button().click(function (e) {
24 window.open($('body').data('baseProjectUrl')+'notebooks/'+$('body').data('notebookPath') + '/new');
25 });
26 }
19
27
20 IPython.notebook_list = new IPython.NotebookList('#notebook_list');
28 IPython.notebook_list = new IPython.NotebookList('#notebook_list');
21 IPython.cluster_list = new IPython.ClusterList('#cluster_list');
29 IPython.cluster_list = new IPython.ClusterList('#cluster_list');
@@ -30,14 +38,14 b' $(document).ready(function () {'
30 //refresh immediately , then start interval
38 //refresh immediately , then start interval
31 if($('.upload_button').length == 0)
39 if($('.upload_button').length == 0)
32 {
40 {
33 IPython.notebook_list.load_list();
41 IPython.notebook_list.load_sessions();
34 IPython.cluster_list.load_list();
42 IPython.cluster_list.load_list();
35 }
43 }
36 if (!interval_id){
44 if (!interval_id){
37 interval_id = setInterval(function(){
45 interval_id = setInterval(function(){
38 if($('.upload_button').length == 0)
46 if($('.upload_button').length == 0)
39 {
47 {
40 IPython.notebook_list.load_list();
48 IPython.notebook_list.load_sessions();
41 IPython.cluster_list.load_list();
49 IPython.cluster_list.load_list();
42 }
50 }
43 }, time_refresh*1000);
51 }, time_refresh*1000);
@@ -18,10 +18,28 b' var IPython = (function (IPython) {'
18 this.style();
18 this.style();
19 this.bind_events();
19 this.bind_events();
20 }
20 }
21 this.notebooks_list = new Array();
22 this.sessions = new Object();
21 };
23 };
22
24
23 NotebookList.prototype.baseProjectUrl = function () {
25 NotebookList.prototype.baseProjectUrl = function () {
24 return $('body').data('baseProjectUrl')
26 return $('body').data('baseProjectUrl');
27 };
28
29 NotebookList.prototype.notebookPath = function() {
30 var path = $('body').data('notebookPath');
31 if (path != "") {
32 if (path[path.length-1] != '/') {
33 path = path.substring(0,path.length);
34 };
35 return path;
36 } else {
37 return path;
38 };
39 };
40
41 NotebookList.prototype.url_name = function(name){
42 return encodeURIComponent(name);
25 };
43 };
26
44
27 NotebookList.prototype.style = function () {
45 NotebookList.prototype.style = function () {
@@ -84,6 +102,35 b' var IPython = (function (IPython) {'
84 this.element.children('.list_item').remove();
102 this.element.children('.list_item').remove();
85 };
103 };
86
104
105 NotebookList.prototype.load_sessions = function(){
106 var settings = {
107 processData : false,
108 cache : false,
109 type : "GET",
110 dataType : "json",
111 success : $.proxy(this.sessions_loaded, this)
112 };
113 var url = this.baseProjectUrl() + 'api/sessions';
114 $.ajax(url,settings);
115 };
116
117
118 NotebookList.prototype.sessions_loaded = function(data){
119 this.sessions=new Object();
120 var len = data.length;
121 if (len != 0) {
122 for (var i=0; i<len; i++) {
123 if (data[i]['notebook_path']==null) {
124 nb_path = data[i]['notebook_name'];
125 }
126 else {
127 nb_path = data[i]['notebook_path'] + data[i]['notebook_name'];
128 }
129 this.sessions[nb_path]= data[i]['session_id'];
130 }
131 };
132 this.load_list();
133 };
87
134
88 NotebookList.prototype.load_list = function () {
135 NotebookList.prototype.load_list = function () {
89 var that = this;
136 var that = this;
@@ -98,7 +145,7 b' var IPython = (function (IPython) {'
98 },this)
145 },this)
99 };
146 };
100
147
101 var url = this.baseProjectUrl() + 'notebooks';
148 var url = this.baseProjectUrl() + 'api/notebooks/' + this.notebookPath();
102 $.ajax(url, settings);
149 $.ajax(url, settings);
103 };
150 };
104
151
@@ -110,7 +157,6 b' var IPython = (function (IPython) {'
110 }
157 }
111 var len = data.length;
158 var len = data.length;
112 this.clear_list();
159 this.clear_list();
113
114 if(len == 0)
160 if(len == 0)
115 {
161 {
116 $(this.new_notebook_item(0))
162 $(this.new_notebook_item(0))
@@ -119,18 +165,17 b' var IPython = (function (IPython) {'
119 .text(message)
165 .text(message)
120 )
166 )
121 }
167 }
122
123 for (var i=0; i<len; i++) {
168 for (var i=0; i<len; i++) {
124 var notebook_id = data[i].notebook_id;
169 var name = data[i].notebook_name;
125 var nbname = data[i].name;
170 var path = this.notebookPath();
126 var kernel = data[i].kernel_id;
171 var nbname = name.split(".")[0];
127 var item = this.new_notebook_item(i);
172 var item = this.new_notebook_item(i);
128 this.add_link(notebook_id, nbname, item);
173 this.add_link(path, nbname, item);
129 // hide delete buttons when readonly
174 name = this.notebookPath() + name;
130 if(kernel == null){
175 if(this.sessions[name] == undefined){
131 this.add_delete_button(item);
176 this.add_delete_button(item);
132 } else {
177 } else {
133 this.add_shutdown_button(item,kernel);
178 this.add_shutdown_button(item,this.sessions[name]);
134 }
179 }
135 };
180 };
136 };
181 };
@@ -157,12 +202,12 b' var IPython = (function (IPython) {'
157 };
202 };
158
203
159
204
160 NotebookList.prototype.add_link = function (notebook_id, nbname, item) {
205 NotebookList.prototype.add_link = function (path, nbname, item) {
161 item.data('nbname', nbname);
206 item.data('nbname', nbname);
162 item.data('notebook_id', notebook_id);
207 item.data('path', path);
163 item.find(".item_name").text(nbname);
208 item.find(".item_name").text(nbname);
164 item.find("a.item_link")
209 item.find("a.item_link")
165 .attr('href', this.baseProjectUrl()+notebook_id)
210 .attr('href', this.baseProjectUrl() + "notebooks/" + this.notebookPath() + nbname + ".ipynb")
166 .attr('target','_blank');
211 .attr('target','_blank');
167 };
212 };
168
213
@@ -184,7 +229,7 b' var IPython = (function (IPython) {'
184 };
229 };
185
230
186
231
187 NotebookList.prototype.add_shutdown_button = function (item, kernel) {
232 NotebookList.prototype.add_shutdown_button = function (item, session) {
188 var that = this;
233 var that = this;
189 var shutdown_button = $("<button/>").text("Shutdown").addClass("btn btn-mini").
234 var shutdown_button = $("<button/>").text("Shutdown").addClass("btn btn-mini").
190 click(function (e) {
235 click(function (e) {
@@ -194,10 +239,10 b' var IPython = (function (IPython) {'
194 type : "DELETE",
239 type : "DELETE",
195 dataType : "json",
240 dataType : "json",
196 success : function (data, status, xhr) {
241 success : function (data, status, xhr) {
197 that.load_list();
242 that.load_sessions();
198 }
243 }
199 };
244 };
200 var url = that.baseProjectUrl() + 'kernels/'+kernel;
245 var url = that.baseProjectUrl() + 'api/sessions/' + session;
201 $.ajax(url, settings);
246 $.ajax(url, settings);
202 return false;
247 return false;
203 });
248 });
@@ -216,7 +261,6 b' var IPython = (function (IPython) {'
216 // data because the outer scopes values change as we iterate through the loop.
261 // data because the outer scopes values change as we iterate through the loop.
217 var parent_item = that.parents('div.list_item');
262 var parent_item = that.parents('div.list_item');
218 var nbname = parent_item.data('nbname');
263 var nbname = parent_item.data('nbname');
219 var notebook_id = parent_item.data('notebook_id');
220 var message = 'Are you sure you want to permanently delete the notebook: ' + nbname + '?';
264 var message = 'Are you sure you want to permanently delete the notebook: ' + nbname + '?';
221 IPython.dialog.modal({
265 IPython.dialog.modal({
222 title : "Delete notebook",
266 title : "Delete notebook",
@@ -234,7 +278,12 b' var IPython = (function (IPython) {'
234 parent_item.remove();
278 parent_item.remove();
235 }
279 }
236 };
280 };
237 var url = notebooklist.baseProjectUrl() + 'notebooks/' + notebook_id;
281 if (notebooklist.notebookPath() == "") {
282 var url = notebooklist.baseProjectUrl() + 'api/notebooks/' + nbname;
283 }
284 else {
285 var url = notebooklist.baseProjectUrl() + 'api/notebooks/' + notebooklist.notebookPath() + nbname;
286 }
238 $.ajax(url, settings);
287 $.ajax(url, settings);
239 }
288 }
240 },
289 },
General Comments 0
You need to be logged in to leave comments. Login now