Show More
@@ -366,6 +366,21 IPython.utils = (function (IPython) { | |||||
366 | return Math.floor(points*pixel_per_point); |
|
366 | return Math.floor(points*pixel_per_point); | |
367 | }; |
|
367 | }; | |
368 |
|
368 | |||
|
369 | ||||
|
370 | var url_path_join = function () { | |||
|
371 | // join a sequence of url components with '/' | |||
|
372 | var url = ''; | |||
|
373 | for (var i = 0; i < arguments.length; i++) { | |||
|
374 | if (url.length > 0 && url[url.length-1] != '/') { | |||
|
375 | url = url + '/' + arguments[i]; | |||
|
376 | } else { | |||
|
377 | url = url + arguments[i]; | |||
|
378 | } | |||
|
379 | } | |||
|
380 | return url; | |||
|
381 | }; | |||
|
382 | ||||
|
383 | ||||
369 | // http://stackoverflow.com/questions/2400935/browser-detection-in-javascript |
|
384 | // http://stackoverflow.com/questions/2400935/browser-detection-in-javascript | |
370 | var browser = (function() { |
|
385 | var browser = (function() { | |
371 | var N= navigator.appName, ua= navigator.userAgent, tem; |
|
386 | var N= navigator.appName, ua= navigator.userAgent, tem; | |
@@ -384,7 +399,8 IPython.utils = (function (IPython) { | |||||
384 | fixCarriageReturn : fixCarriageReturn, |
|
399 | fixCarriageReturn : fixCarriageReturn, | |
385 | autoLinkUrls : autoLinkUrls, |
|
400 | autoLinkUrls : autoLinkUrls, | |
386 | points_to_pixels : points_to_pixels, |
|
401 | points_to_pixels : points_to_pixels, | |
387 | browser : browser |
|
402 | url_path_join : url_path_join, | |
|
403 | browser : browser | |||
388 | }; |
|
404 | }; | |
389 |
|
405 | |||
390 | }(IPython)); |
|
406 | }(IPython)); |
@@ -1,5 +1,5 | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 |
// Copyright (C) 20 |
|
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. | |
@@ -1683,7 +1683,12 var IPython = (function (IPython) { | |||||
1683 | error : $.proxy(this.save_notebook_error, this) |
|
1683 | error : $.proxy(this.save_notebook_error, this) | |
1684 | }; |
|
1684 | }; | |
1685 | $([IPython.events]).trigger('notebook_saving.Notebook'); |
|
1685 | $([IPython.events]).trigger('notebook_saving.Notebook'); | |
1686 | var url = this.baseProjectUrl() + 'api/notebooks' + this.notebookPath()+ this.notebook_name; |
|
1686 | var url = utils.url_path_join( | |
|
1687 | this.baseProjectUrl(), | |||
|
1688 | 'api/notebooks', | |||
|
1689 | this.notebookPath(), | |||
|
1690 | this.notebook_name | |||
|
1691 | ); | |||
1687 | $.ajax(url, settings); |
|
1692 | $.ajax(url, settings); | |
1688 | }; |
|
1693 | }; | |
1689 |
|
1694 | |||
@@ -1747,7 +1752,15 var IPython = (function (IPython) { | |||||
1747 | dataType : "json", |
|
1752 | dataType : "json", | |
1748 | success:$.proxy(function (data, status, xhr){ |
|
1753 | success:$.proxy(function (data, status, xhr){ | |
1749 | var notebook_name = data.name; |
|
1754 | var notebook_name = data.name; | |
1750 | window.open(this.baseProjectUrl() +'notebooks' + this.notebookPath()+ notebook_name, '_blank'); |
|
1755 | window.open( | |
|
1756 | utils.url_path_join( | |||
|
1757 | this.baseProjectUrl(), | |||
|
1758 | 'notebooks', | |||
|
1759 | this.notebookPath(), | |||
|
1760 | notebook_name | |||
|
1761 | ), | |||
|
1762 | '_blank' | |||
|
1763 | ); | |||
1751 | }, this) |
|
1764 | }, this) | |
1752 | }; |
|
1765 | }; | |
1753 | var url = this.baseProjectUrl() + 'api/notebooks' + path; |
|
1766 | var url = this.baseProjectUrl() + 'api/notebooks' + path; | |
@@ -1766,10 +1779,19 var IPython = (function (IPython) { | |||||
1766 | dataType : "json", |
|
1779 | dataType : "json", | |
1767 | success:$.proxy(function (data, status, xhr){ |
|
1780 | success:$.proxy(function (data, status, xhr){ | |
1768 | notebook_name = data.name; |
|
1781 | notebook_name = data.name; | |
1769 | window.open(this._baseProjectUrl +'notebooks' + this.notebookPath()+ notebook_name); |
|
1782 | window.open(utils.url_path_join( | |
|
1783 | this._baseProjectUrl, | |||
|
1784 | 'notebooks', | |||
|
1785 | this.notebookPath(), | |||
|
1786 | notebook_name | |||
|
1787 | )); | |||
1770 | }, this) |
|
1788 | }, this) | |
1771 | }; |
|
1789 | }; | |
1772 | var url = this._baseProjectUrl + 'notebooks' + path; |
|
1790 | var url = utils.url_path_join( | |
|
1791 | this._baseProjectUrl, | |||
|
1792 | 'notebooks', | |||
|
1793 | path | |||
|
1794 | ); | |||
1773 | $.ajax(url,settings); |
|
1795 | $.ajax(url,settings); | |
1774 | }; |
|
1796 | }; | |
1775 |
|
1797 | |||
@@ -1788,7 +1810,12 var IPython = (function (IPython) { | |||||
1788 | error : $.proxy(that.rename_error, this) |
|
1810 | error : $.proxy(that.rename_error, this) | |
1789 | }; |
|
1811 | }; | |
1790 | $([IPython.events]).trigger('notebook_rename.Notebook'); |
|
1812 | $([IPython.events]).trigger('notebook_rename.Notebook'); | |
1791 | var url = this.baseProjectUrl() + 'api/notebooks' + this.notebookPath()+ this.notebook_name; |
|
1813 | var url = utils.url_path_join( | |
|
1814 | this.baseProjectUrl(), | |||
|
1815 | 'api/notebooks', | |||
|
1816 | this.notebookPath(), | |||
|
1817 | this.notebook_name | |||
|
1818 | ); | |||
1792 | $.ajax(url, settings); |
|
1819 | $.ajax(url, settings); | |
1793 | }; |
|
1820 | }; | |
1794 |
|
1821 | |||
@@ -1837,22 +1864,27 var IPython = (function (IPython) { | |||||
1837 | * @method load_notebook |
|
1864 | * @method load_notebook | |
1838 | * @param {String} notebook_naem and path A notebook to load |
|
1865 | * @param {String} notebook_naem and path A notebook to load | |
1839 | */ |
|
1866 | */ | |
1840 |
|
|
1867 | Notebook.prototype.load_notebook = function (notebook_name, notebook_path) { | |
1841 |
|
|
1868 | var that = this; | |
1842 |
|
|
1869 | this.notebook_name = notebook_name; | |
1843 |
|
|
1870 | this.notebook_path = notebook_path; | |
1844 |
|
|
1871 | // We do the call with settings so we can set cache to false. | |
1845 |
|
|
1872 | var settings = { | |
1846 |
|
|
1873 | processData : false, | |
1847 |
|
|
1874 | cache : false, | |
1848 |
|
|
1875 | type : "GET", | |
1849 |
|
|
1876 | dataType : "json", | |
1850 |
|
|
1877 | success : $.proxy(this.load_notebook_success,this), | |
1851 |
|
|
1878 | error : $.proxy(this.load_notebook_error,this), | |
1852 |
|
|
1879 | }; | |
1853 |
|
|
1880 | $([IPython.events]).trigger('notebook_loading.Notebook'); | |
1854 | var url = this.baseProjectUrl() + 'api/notebooks' + this.notebookPath() + this.notebook_name; |
|
1881 | var url = utils.url_path_join( | |
1855 | $.ajax(url, settings); |
|
1882 | this._baseProjectUrl, | |
|
1883 | 'api/notebooks', | |||
|
1884 | this.notebookPath(), | |||
|
1885 | this.notebook_name | |||
|
1886 | ); | |||
|
1887 | $.ajax(url, settings); | |||
1856 | }; |
|
1888 | }; | |
1857 |
|
1889 | |||
1858 | /** |
|
1890 | /** | |
@@ -1983,14 +2015,20 var IPython = (function (IPython) { | |||||
1983 | * |
|
2015 | * | |
1984 | * @method list_checkpoints |
|
2016 | * @method list_checkpoints | |
1985 | */ |
|
2017 | */ | |
1986 |
|
|
2018 | Notebook.prototype.list_checkpoints = function () { | |
1987 | var url = this.baseProjectUrl() + 'api/notebooks' + this.notebookPath() + this.notebook_name + '/checkpoints'; |
|
2019 | var url = utils.url_path_join( | |
1988 | $.get(url).done( |
|
2020 | this.baseProjectUrl(), | |
1989 | $.proxy(this.list_checkpoints_success, this) |
|
2021 | 'api/notebooks', | |
1990 | ).fail( |
|
2022 | this.notebookPath(), | |
1991 | $.proxy(this.list_checkpoints_error, this) |
|
2023 | this.notebook_name, | |
1992 | ); |
|
2024 | 'checkpoints' | |
1993 |
|
|
2025 | ); | |
|
2026 | $.get(url).done( | |||
|
2027 | $.proxy(this.list_checkpoints_success, this) | |||
|
2028 | ).fail( | |||
|
2029 | $.proxy(this.list_checkpoints_error, this) | |||
|
2030 | ); | |||
|
2031 | }; | |||
1994 |
|
2032 | |||
1995 | /** |
|
2033 | /** | |
1996 | * Success callback for listing checkpoints. |
|
2034 | * Success callback for listing checkpoints. | |
@@ -2028,14 +2066,20 var IPython = (function (IPython) { | |||||
2028 | * |
|
2066 | * | |
2029 | * @method create_checkpoint |
|
2067 | * @method create_checkpoint | |
2030 | */ |
|
2068 | */ | |
2031 |
|
|
2069 | Notebook.prototype.create_checkpoint = function () { | |
2032 | var url = this.baseProjectUrl() + 'api/notebooks' + this.notebookPath() + this.notebook_name + '/checkpoints'; |
|
2070 | var url = utils.url_path_join( | |
2033 | $.post(url).done( |
|
2071 | this.baseProjectUrl(), | |
2034 | $.proxy(this.create_checkpoint_success, this) |
|
2072 | 'api/notebooks', | |
2035 | ).fail( |
|
2073 | this.notebookPath(), | |
2036 | $.proxy(this.create_checkpoint_error, this) |
|
2074 | this.notebook_name, | |
2037 | ); |
|
2075 | 'checkpoints' | |
2038 |
|
|
2076 | ); | |
|
2077 | $.post(url).done( | |||
|
2078 | $.proxy(this.create_checkpoint_success, this) | |||
|
2079 | ).fail( | |||
|
2080 | $.proxy(this.create_checkpoint_error, this) | |||
|
2081 | ); | |||
|
2082 | }; | |||
2039 |
|
2083 | |||
2040 | /** |
|
2084 | /** | |
2041 | * Success callback for creating a checkpoint. |
|
2085 | * Success callback for creating a checkpoint. | |
@@ -2110,7 +2154,14 var IPython = (function (IPython) { | |||||
2110 | */ |
|
2154 | */ | |
2111 | Notebook.prototype.restore_checkpoint = function (checkpoint) { |
|
2155 | Notebook.prototype.restore_checkpoint = function (checkpoint) { | |
2112 | $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint); |
|
2156 | $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint); | |
2113 | var url = this.baseProjectUrl() + 'api/notebooks' + this.notebookPath() + this.notebook_name + '/checkpoints/' + checkpoint; |
|
2157 | var url = utils.url_path_join( | |
|
2158 | this.baseProjectUrl(), | |||
|
2159 | 'api/notebooks', | |||
|
2160 | this.notebookPath(), | |||
|
2161 | this.notebook_name, | |||
|
2162 | 'checkpoints', | |||
|
2163 | checkpoint | |||
|
2164 | ); | |||
2114 | $.post(url).done( |
|
2165 | $.post(url).done( | |
2115 | $.proxy(this.restore_checkpoint_success, this) |
|
2166 | $.proxy(this.restore_checkpoint_success, this) | |
2116 | ).fail( |
|
2167 | ).fail( | |
@@ -2151,7 +2202,14 var IPython = (function (IPython) { | |||||
2151 | */ |
|
2202 | */ | |
2152 | Notebook.prototype.delete_checkpoint = function (checkpoint) { |
|
2203 | Notebook.prototype.delete_checkpoint = function (checkpoint) { | |
2153 | $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint); |
|
2204 | $([IPython.events]).trigger('notebook_restoring.Notebook', checkpoint); | |
2154 | var url = this.baseProjectUrl() + 'api/notebooks' + this.notebookPath() + this.notebook_name + '/checkpoints/' + checkpoint; |
|
2205 | var url = utils.url_path_join( | |
|
2206 | this.baseProjectUrl(), | |||
|
2207 | 'api/notebooks', | |||
|
2208 | this.notebookPath(), | |||
|
2209 | this.notebook_name, | |||
|
2210 | 'checkpoints', | |||
|
2211 | checkpoint | |||
|
2212 | ); | |||
2155 | $.ajax(url, { |
|
2213 | $.ajax(url, { | |
2156 | type: 'DELETE', |
|
2214 | type: 'DELETE', | |
2157 | success: $.proxy(this.delete_checkpoint_success, this), |
|
2215 | success: $.proxy(this.delete_checkpoint_success, this), |
@@ -1,5 +1,5 | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 |
// Copyright (C) 20 |
|
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. | |
@@ -10,6 +10,9 | |||||
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | var IPython = (function (IPython) { |
|
12 | var IPython = (function (IPython) { | |
|
13 | "use strict"; | |||
|
14 | ||||
|
15 | var utils = IPython.utils; | |||
13 |
|
16 | |||
14 | var ClusterList = function (selector) { |
|
17 | var ClusterList = function (selector) { | |
15 | this.selector = selector; |
|
18 | this.selector = selector; | |
@@ -48,14 +51,14 var IPython = (function (IPython) { | |||||
48 | dataType : "json", |
|
51 | dataType : "json", | |
49 | success : $.proxy(this.load_list_success, this) |
|
52 | success : $.proxy(this.load_list_success, this) | |
50 | }; |
|
53 | }; | |
51 |
var url = this.baseProjectUrl() |
|
54 | var url = utils.url_path_join(this.baseProjectUrl(), 'clusters'); | |
52 | $.ajax(url, settings); |
|
55 | $.ajax(url, settings); | |
53 | }; |
|
56 | }; | |
54 |
|
57 | |||
55 |
|
58 | |||
56 | ClusterList.prototype.clear_list = function () { |
|
59 | ClusterList.prototype.clear_list = function () { | |
57 | this.element.children('.list_item').remove(); |
|
60 | this.element.children('.list_item').remove(); | |
58 | } |
|
61 | }; | |
59 |
|
62 | |||
60 | ClusterList.prototype.load_list_success = function (data, status, xhr) { |
|
63 | ClusterList.prototype.load_list_success = function (data, status, xhr) { | |
61 | this.clear_list(); |
|
64 | this.clear_list(); | |
@@ -66,7 +69,7 var IPython = (function (IPython) { | |||||
66 | item.update_state(data[i]); |
|
69 | item.update_state(data[i]); | |
67 | element.data('item', item); |
|
70 | element.data('item', item); | |
68 | this.element.append(element); |
|
71 | this.element.append(element); | |
69 |
} |
|
72 | } | |
70 | }; |
|
73 | }; | |
71 |
|
74 | |||
72 |
|
75 | |||
@@ -81,10 +84,9 var IPython = (function (IPython) { | |||||
81 | }; |
|
84 | }; | |
82 |
|
85 | |||
83 |
|
86 | |||
84 |
|
||||
85 | ClusterItem.prototype.style = function () { |
|
87 | ClusterItem.prototype.style = function () { | |
86 | this.element.addClass('list_item').addClass("row-fluid"); |
|
88 | this.element.addClass('list_item').addClass("row-fluid"); | |
87 | } |
|
89 | }; | |
88 |
|
90 | |||
89 | ClusterItem.prototype.update_state = function (data) { |
|
91 | ClusterItem.prototype.update_state = function (data) { | |
90 | this.data = data; |
|
92 | this.data = data; | |
@@ -92,9 +94,8 var IPython = (function (IPython) { | |||||
92 | this.state_running(); |
|
94 | this.state_running(); | |
93 | } else if (data.status === 'stopped') { |
|
95 | } else if (data.status === 'stopped') { | |
94 | this.state_stopped(); |
|
96 | this.state_stopped(); | |
95 |
} |
|
97 | } | |
96 |
|
98 | }; | ||
97 | } |
|
|||
98 |
|
99 | |||
99 |
|
100 | |||
100 | ClusterItem.prototype.state_stopped = function () { |
|
101 | ClusterItem.prototype.state_stopped = function () { | |
@@ -132,13 +133,18 var IPython = (function (IPython) { | |||||
132 | that.update_state(data); |
|
133 | that.update_state(data); | |
133 | }, |
|
134 | }, | |
134 | error : function (data, status, xhr) { |
|
135 | error : function (data, status, xhr) { | |
135 | status_col.html("error starting cluster") |
|
136 | status_col.html("error starting cluster"); | |
136 | } |
|
137 | } | |
137 | }; |
|
138 | }; | |
138 | status_col.html('starting'); |
|
139 | status_col.html('starting'); | |
139 | var url = that.baseProjectUrl() + 'clusters/' + that.data.profile + '/start'; |
|
140 | var url = utils.url_path_join( | |
|
141 | that.baseProjectUrl(), | |||
|
142 | 'clusters', | |||
|
143 | that.data.profile, | |||
|
144 | 'start' | |||
|
145 | ); | |||
140 | $.ajax(url, settings); |
|
146 | $.ajax(url, settings); | |
141 |
} |
|
147 | } | |
142 | }); |
|
148 | }); | |
143 | }; |
|
149 | }; | |
144 |
|
150 | |||
@@ -169,11 +175,16 var IPython = (function (IPython) { | |||||
169 | }, |
|
175 | }, | |
170 | error : function (data, status, xhr) { |
|
176 | error : function (data, status, xhr) { | |
171 | console.log('error',data); |
|
177 | console.log('error',data); | |
172 | status_col.html("error stopping cluster") |
|
178 | status_col.html("error stopping cluster"); | |
173 | } |
|
179 | } | |
174 | }; |
|
180 | }; | |
175 | status_col.html('stopping') |
|
181 | status_col.html('stopping'); | |
176 | var url = that.baseProjectUrl() + 'clusters/' + that.data.profile + '/stop'; |
|
182 | var url = utils.url_path_join( | |
|
183 | that.baseProjectUrl(), | |||
|
184 | 'clusters', | |||
|
185 | that.data.profile, | |||
|
186 | 'stop' | |||
|
187 | ); | |||
177 | $.ajax(url, settings); |
|
188 | $.ajax(url, settings); | |
178 | }); |
|
189 | }); | |
179 | }; |
|
190 | }; |
@@ -1,5 +1,5 | |||||
1 | //---------------------------------------------------------------------------- |
|
1 | //---------------------------------------------------------------------------- | |
2 |
// Copyright (C) 20 |
|
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. | |
@@ -10,6 +10,9 | |||||
10 | //============================================================================ |
|
10 | //============================================================================ | |
11 |
|
11 | |||
12 | var IPython = (function (IPython) { |
|
12 | var IPython = (function (IPython) { | |
|
13 | "use strict"; | |||
|
14 | ||||
|
15 | var utils = IPython.utils; | |||
13 |
|
16 | |||
14 | var NotebookList = function (selector) { |
|
17 | var NotebookList = function (selector) { | |
15 | this.selector = selector; |
|
18 | this.selector = selector; | |
@@ -18,8 +21,8 var IPython = (function (IPython) { | |||||
18 | this.style(); |
|
21 | this.style(); | |
19 | this.bind_events(); |
|
22 | this.bind_events(); | |
20 | } |
|
23 | } | |
21 |
this.notebooks_list = |
|
24 | this.notebooks_list = []; | |
22 |
this.sessions = |
|
25 | this.sessions = {}; | |
23 | }; |
|
26 | }; | |
24 |
|
27 | |||
25 | NotebookList.prototype.baseProjectUrl = function () { |
|
28 | NotebookList.prototype.baseProjectUrl = function () { | |
@@ -27,15 +30,9 var IPython = (function (IPython) { | |||||
27 | }; |
|
30 | }; | |
28 |
|
31 | |||
29 | NotebookList.prototype.notebookPath = function() { |
|
32 | NotebookList.prototype.notebookPath = function() { | |
30 |
|
|
33 | return $('body').data('notebookPath'); | |
31 | path = decodeURIComponent(path); |
|
|||
32 | return path; |
|
|||
33 | }; |
|
34 | }; | |
34 |
|
35 | |||
35 | NotebookList.prototype.url_name = function(name){ |
|
|||
36 | return encodeURIComponent(name); |
|
|||
37 | }; |
|
|||
38 |
|
||||
39 | NotebookList.prototype.style = function () { |
|
36 | NotebookList.prototype.style = function () { | |
40 | $('#notebook_toolbar').addClass('list_toolbar'); |
|
37 | $('#notebook_toolbar').addClass('list_toolbar'); | |
41 | $('#drag_info').addClass('toolbar_info'); |
|
38 | $('#drag_info').addClass('toolbar_info'); | |
@@ -66,15 +63,16 var IPython = (function (IPython) { | |||||
66 | files = event.originalEvent.dataTransfer.files; |
|
63 | files = event.originalEvent.dataTransfer.files; | |
67 | } else |
|
64 | } else | |
68 | { |
|
65 | { | |
69 | files = event.originalEvent.target.files |
|
66 | files = event.originalEvent.target.files; | |
70 | } |
|
67 | } | |
71 |
for (var i = 0 |
|
68 | for (var i = 0; i < files.length; i++) { | |
|
69 | var f = files[i]; | |||
72 | var reader = new FileReader(); |
|
70 | var reader = new FileReader(); | |
73 | reader.readAsText(f); |
|
71 | reader.readAsText(f); | |
74 | var fname = f.name.split('.'); |
|
72 | var fname = f.name.split('.'); | |
75 | var nbname = fname.slice(0,-1).join('.'); |
|
73 | var nbname = fname.slice(0,-1).join('.'); | |
76 | var nbformat = fname.slice(-1)[0]; |
|
74 | var nbformat = fname.slice(-1)[0]; | |
77 |
if (nbformat === 'ipynb') {nbformat = 'json';} |
|
75 | if (nbformat === 'ipynb') {nbformat = 'json';} | |
78 | if (nbformat === 'py' || nbformat === 'json') { |
|
76 | if (nbformat === 'py' || nbformat === 'json') { | |
79 | var item = that.new_notebook_item(0); |
|
77 | var item = that.new_notebook_item(0); | |
80 | that.add_name_input(nbname, item); |
|
78 | that.add_name_input(nbname, item); | |
@@ -87,10 +85,10 var IPython = (function (IPython) { | |||||
87 | that.add_notebook_data(event.target.result, nbitem); |
|
85 | that.add_notebook_data(event.target.result, nbitem); | |
88 | that.add_upload_button(nbitem); |
|
86 | that.add_upload_button(nbitem); | |
89 | }; |
|
87 | }; | |
90 |
} |
|
88 | } | |
91 | } |
|
89 | } | |
92 | return false; |
|
90 | return false; | |
93 |
|
|
91 | }; | |
94 |
|
92 | |||
95 | NotebookList.prototype.clear_list = function () { |
|
93 | NotebookList.prototype.clear_list = function () { | |
96 | this.element.children('.list_item').remove(); |
|
94 | this.element.children('.list_item').remove(); | |
@@ -111,20 +109,22 var IPython = (function (IPython) { | |||||
111 |
|
109 | |||
112 |
|
110 | |||
113 | NotebookList.prototype.sessions_loaded = function(data){ |
|
111 | NotebookList.prototype.sessions_loaded = function(data){ | |
114 |
this.sessions = |
|
112 | this.sessions = {}; | |
115 | console.log(data) |
|
|||
116 | var len = data.length; |
|
113 | var len = data.length; | |
117 |
if (len |
|
114 | if (len > 0) { | |
118 | for (var i=0; i<len; i++) { |
|
115 | for (var i=0; i<len; i++) { | |
119 |
if (data[i] |
|
116 | if (!data[i].notebook.path) { | |
120 |
nb_path = data[i] |
|
117 | nb_path = data[i].notebook.name; | |
121 | } |
|
118 | } | |
122 | else { |
|
119 | else { | |
123 | nb_path = data[i]['notebook']['path'] + data[i]['notebook']['name']; |
|
120 | nb_path = utils.url_path_join( | |
|
121 | data[i].notebook.path, | |||
|
122 | data[i].notebook.name | |||
|
123 | ); | |||
124 | } |
|
124 | } | |
125 |
this.sessions[nb_path]= data[i] |
|
125 | this.sessions[nb_path] = data[i].id; | |
126 | } |
|
126 | } | |
127 |
} |
|
127 | } | |
128 | this.load_list(); |
|
128 | this.load_list(); | |
129 | }; |
|
129 | }; | |
130 |
|
130 | |||
@@ -141,7 +141,12 var IPython = (function (IPython) { | |||||
141 | },this) |
|
141 | },this) | |
142 | }; |
|
142 | }; | |
143 |
|
143 | |||
144 | var url = this.baseProjectUrl() + 'api/notebooks' + this.notebookPath(); |
|
144 | var url = utils.url_path_join( | |
|
145 | this.baseProjectUrl(), | |||
|
146 | 'api', | |||
|
147 | 'notebooks', | |||
|
148 | this.notebookPath() | |||
|
149 | ); | |||
145 | $.ajax(url, settings); |
|
150 | $.ajax(url, settings); | |
146 | }; |
|
151 | }; | |
147 |
|
152 | |||
@@ -149,17 +154,16 var IPython = (function (IPython) { | |||||
149 | NotebookList.prototype.list_loaded = function (data, status, xhr, param) { |
|
154 | NotebookList.prototype.list_loaded = function (data, status, xhr, param) { | |
150 | var message = 'Notebook list empty.'; |
|
155 | var message = 'Notebook list empty.'; | |
151 | if (param !== undefined && param.msg) { |
|
156 | if (param !== undefined && param.msg) { | |
152 |
|
|
157 | message = param.msg; | |
153 | } |
|
158 | } | |
154 | var len = data.length; |
|
159 | var len = data.length; | |
155 | this.clear_list(); |
|
160 | this.clear_list(); | |
156 | if(len == 0) |
|
161 | if (len === 0) { | |
157 | { |
|
|||
158 | $(this.new_notebook_item(0)) |
|
162 | $(this.new_notebook_item(0)) | |
159 | .append( |
|
163 | .append( | |
160 | $('<div style="margin:auto;text-align:center;color:grey"/>') |
|
164 | $('<div style="margin:auto;text-align:center;color:grey"/>') | |
161 | .text(message) |
|
165 | .text(message) | |
162 |
|
|
166 | ); | |
163 | } |
|
167 | } | |
164 | for (var i=0; i<len; i++) { |
|
168 | for (var i=0; i<len; i++) { | |
165 | var name = data[i].name; |
|
169 | var name = data[i].name; | |
@@ -168,12 +172,12 var IPython = (function (IPython) { | |||||
168 | var item = this.new_notebook_item(i); |
|
172 | var item = this.new_notebook_item(i); | |
169 | this.add_link(path, nbname, item); |
|
173 | this.add_link(path, nbname, item); | |
170 | name = this.notebookPath() + name; |
|
174 | name = this.notebookPath() + name; | |
171 | if(this.sessions[name] == undefined){ |
|
175 | if(this.sessions[name] === undefined){ | |
172 | this.add_delete_button(item); |
|
176 | this.add_delete_button(item); | |
173 | } else { |
|
177 | } else { | |
174 | this.add_shutdown_button(item,this.sessions[name]); |
|
178 | this.add_shutdown_button(item,this.sessions[name]); | |
175 | } |
|
179 | } | |
176 |
} |
|
180 | } | |
177 | }; |
|
181 | }; | |
178 |
|
182 | |||
179 |
|
183 | |||
@@ -203,8 +207,14 var IPython = (function (IPython) { | |||||
203 | item.data('path', path); |
|
207 | item.data('path', path); | |
204 | item.find(".item_name").text(nbname); |
|
208 | item.find(".item_name").text(nbname); | |
205 | item.find("a.item_link") |
|
209 | item.find("a.item_link") | |
206 | .attr('href', this.baseProjectUrl() + "notebooks" + this.notebookPath() + nbname + ".ipynb") |
|
210 | .attr('href', | |
207 | .attr('target','_blank'); |
|
211 | utils.url_path_join( | |
|
212 | this.baseProjectUrl(), | |||
|
213 | "notebooks", | |||
|
214 | this.notebookPath(), | |||
|
215 | nbname + ".ipynb" | |||
|
216 | ) | |||
|
217 | ).attr('target','_blank'); | |||
208 | }; |
|
218 | }; | |
209 |
|
219 | |||
210 |
|
220 | |||
@@ -238,7 +248,11 var IPython = (function (IPython) { | |||||
238 | that.load_sessions(); |
|
248 | that.load_sessions(); | |
239 | } |
|
249 | } | |
240 | }; |
|
250 | }; | |
241 | var url = that.baseProjectUrl() + 'api/sessions/' + session; |
|
251 | var url = utils.url_path_join( | |
|
252 | that.baseProjectUrl(), | |||
|
253 | 'api/sessions', | |||
|
254 | session | |||
|
255 | ); | |||
242 | $.ajax(url, settings); |
|
256 | $.ajax(url, settings); | |
243 | return false; |
|
257 | return false; | |
244 | }); |
|
258 | }); | |
@@ -274,7 +288,12 var IPython = (function (IPython) { | |||||
274 | parent_item.remove(); |
|
288 | parent_item.remove(); | |
275 | } |
|
289 | } | |
276 | }; |
|
290 | }; | |
277 | var url = notebooklist.baseProjectUrl() + 'api/notebooks' + notebooklist.notebookPath() + nbname + '.ipynb'; |
|
291 | var url = utils.url_path_join( | |
|
292 | notebooklist.baseProjectUrl(), | |||
|
293 | 'api/notebooks', | |||
|
294 | notebooklist.notebookPath(), | |||
|
295 | nbname + '.ipynb' | |||
|
296 | ); | |||
278 | $.ajax(url, settings); |
|
297 | $.ajax(url, settings); | |
279 | } |
|
298 | } | |
280 | }, |
|
299 | }, | |
@@ -300,7 +319,7 var IPython = (function (IPython) { | |||||
300 | content_type = 'application/json'; |
|
319 | content_type = 'application/json'; | |
301 | } else if (nbformat === 'py') { |
|
320 | } else if (nbformat === 'py') { | |
302 | content_type = 'application/x-python'; |
|
321 | content_type = 'application/x-python'; | |
303 |
} |
|
322 | } | |
304 | var settings = { |
|
323 | var settings = { | |
305 | processData : false, |
|
324 | processData : false, | |
306 | cache : false, |
|
325 | cache : false, | |
@@ -315,7 +334,10 var IPython = (function (IPython) { | |||||
315 | }; |
|
334 | }; | |
316 |
|
335 | |||
317 | var qs = $.param({name:nbname, format:nbformat}); |
|
336 | var qs = $.param({name:nbname, format:nbformat}); | |
318 | var url = that.baseProjectUrl() + 'notebooks?' + qs; |
|
337 | var url = utils.url_path_join( | |
|
338 | that.baseProjectUrl(), | |||
|
339 | 'notebooks?' + qs | |||
|
340 | ); | |||
319 | $.ajax(url, settings); |
|
341 | $.ajax(url, settings); | |
320 | return false; |
|
342 | return false; | |
321 | }); |
|
343 | }); | |
@@ -340,12 +362,23 var IPython = (function (IPython) { | |||||
340 | type : "POST", |
|
362 | type : "POST", | |
341 | dataType : "json", |
|
363 | dataType : "json", | |
342 | success:$.proxy(function (data, status, xhr){ |
|
364 | success:$.proxy(function (data, status, xhr){ | |
343 | notebook_name = data.name; |
|
365 | var notebook_name = data.name; | |
344 | window.open(this.baseProjectUrl() +'notebooks' + this.notebookPath()+ notebook_name, '_blank'); |
|
366 | window.open( | |
|
367 | utils.url_path_join( | |||
|
368 | this.baseProjectUrl(), | |||
|
369 | 'notebooks', | |||
|
370 | this.notebookPath(), | |||
|
371 | notebook_name), | |||
|
372 | '_blank' | |||
|
373 | ); | |||
345 | }, this) |
|
374 | }, this) | |
346 | }; |
|
375 | }; | |
347 | var url = this.baseProjectUrl() + 'api/notebooks' + path; |
|
376 | var url = utils.url_path_join( | |
348 | $.ajax(url,settings); |
|
377 | this.baseProjectUrl(), | |
|
378 | 'api/notebooks', | |||
|
379 | path | |||
|
380 | ); | |||
|
381 | $.ajax(url, settings); | |||
349 | }; |
|
382 | }; | |
350 |
|
383 | |||
351 | IPython.NotebookList = NotebookList; |
|
384 | IPython.NotebookList = NotebookList; |
General Comments 0
You need to be logged in to leave comments.
Login now