Show More
@@ -205,6 +205,9 b' class ContentsHandler(IPythonHandler):' | |||||
205 | self._copy(copy_from, path, name) |
|
205 | self._copy(copy_from, path, name) | |
206 | elif self.contents_manager.file_exists(name, path): |
|
206 | elif self.contents_manager.file_exists(name, path): | |
207 | self._save(model, path, name) |
|
207 | self._save(model, path, name) | |
|
208 | checkpoint = model.get('_checkpoint_after_save') | |||
|
209 | if checkpoint: | |||
|
210 | nbm.create_checkpoint(path, name) | |||
208 | else: |
|
211 | else: | |
209 | self._upload(model, path, name) |
|
212 | self._upload(model, path, name) | |
210 | else: |
|
213 | else: |
@@ -5,7 +5,7 b' define([' | |||||
5 | 'base/js/namespace', |
|
5 | 'base/js/namespace', | |
6 | 'jquery', |
|
6 | 'jquery', | |
7 | ], function(IPython, $) { |
|
7 | ], function(IPython, $) { | |
8 | var ContentManager = function() { |
|
8 | var ContentManager = function(notebook_path, base_url) { | |
9 | // Constructor |
|
9 | // Constructor | |
10 | // |
|
10 | // | |
11 | // A contentmanager handles passing file operations |
|
11 | // A contentmanager handles passing file operations | |
@@ -13,30 +13,161 b' define([' | |||||
13 | // with the normal file operations. |
|
13 | // with the normal file operations. | |
14 | // |
|
14 | // | |
15 | // Parameters: |
|
15 | // Parameters: | |
16 |
// |
|
16 | // notebook_path | |
|
17 | // base_url | |||
17 | this.version = 0.1; |
|
18 | this.version = 0.1; | |
|
19 | this.notebook_path = notebook_path; | |||
|
20 | this.base_url = base_url; | |||
18 | } |
|
21 | } | |
19 |
|
22 | |||
20 | ContentManager.prototype.new_notebook = function() { |
|
23 | ContentManager.prototype.new_notebook = function() { | |
|
24 | var path = this.notebook_path; | |||
|
25 | var base_url = this.base_url; | |||
|
26 | var settings = { | |||
|
27 | processData : false, | |||
|
28 | cache : false, | |||
|
29 | type : "POST", | |||
|
30 | dataType : "json", | |||
|
31 | async : false, | |||
|
32 | success : function (data, status, xhr){ | |||
|
33 | var notebook_name = data.name; | |||
|
34 | window.open( | |||
|
35 | utils.url_join_encode( | |||
|
36 | base_url, | |||
|
37 | 'notebooks', | |||
|
38 | path, | |||
|
39 | notebook_name | |||
|
40 | ), | |||
|
41 | '_blank' | |||
|
42 | ); | |||
|
43 | }, | |||
|
44 | error : utils.log_ajax_error, | |||
|
45 | }; | |||
|
46 | var url = utils.url_join_encode( | |||
|
47 | base_url, | |||
|
48 | 'api/notebooks', | |||
|
49 | path | |||
|
50 | ); | |||
|
51 | $.ajax(url,settings); | |||
21 | } |
|
52 | } | |
22 |
|
53 | |||
23 |
ContentManager.prototype.delete_notebook = function(n |
|
54 | ContentManager.prototype.delete_notebook = function(notebook) { | |
|
55 | var that = notebook; | |||
|
56 | var settings = { | |||
|
57 | processData : false, | |||
|
58 | cache : false, | |||
|
59 | type : "DELETE", | |||
|
60 | dataType: "json", | |||
|
61 | error : utils.log_ajax_error, | |||
|
62 | }; | |||
|
63 | var url = utils.url_join_encode( | |||
|
64 | that.base_url, | |||
|
65 | 'api/notebooks', | |||
|
66 | that.notebook_path, | |||
|
67 | that.notebook_name | |||
|
68 | ); | |||
|
69 | $.ajax(url, settings); | |||
24 | } |
|
70 | } | |
25 |
|
71 | |||
26 |
ContentManager.prototype.rename_notebook = function(n |
|
72 | ContentManager.prototype.rename_notebook = function(notebook, nbname) { | |
|
73 | var that = notebook; | |||
|
74 | if (!nbname.match(/\.ipynb$/)) { | |||
|
75 | nbname = nbname + ".ipynb"; | |||
|
76 | } | |||
|
77 | var data = {name: nbname}; | |||
|
78 | var settings = { | |||
|
79 | processData : false, | |||
|
80 | cache : false, | |||
|
81 | type : "PATCH", | |||
|
82 | data : JSON.stringify(data), | |||
|
83 | dataType: "json", | |||
|
84 | headers : {'Content-Type': 'application/json'}, | |||
|
85 | success : $.proxy(that.rename_success, this), | |||
|
86 | error : $.proxy(that.rename_error, this) | |||
|
87 | }; | |||
|
88 | this.events.trigger('rename_notebook.Notebook', data); | |||
|
89 | var url = utils.url_join_encode( | |||
|
90 | this.base_url, | |||
|
91 | 'api/notebooks', | |||
|
92 | this.notebook_path, | |||
|
93 | this.notebook_name | |||
|
94 | ); | |||
|
95 | $.ajax(url, settings); | |||
27 | } |
|
96 | } | |
28 |
|
97 | |||
29 | ContentManager.prototype.save_notebook = function(notebook, extra_settings) { |
|
98 | ContentManager.prototype.save_notebook = function(notebook, extra_settings) { | |
30 | } |
|
99 | // Create a JSON model to be sent to the server. | |
|
100 | var model = {}; | |||
|
101 | model.name = notebook.notebook_name; | |||
|
102 | model.path = notebook.notebook_path; | |||
|
103 | model.content = notebook.toJSON(); | |||
|
104 | model.content.nbformat = notebook.nbformat; | |||
|
105 | model.content.nbformat_minor = notebook.nbformat_minor; | |||
|
106 | // time the ajax call for autosave tuning purposes. | |||
|
107 | var start = new Date().getTime(); | |||
|
108 | // We do the call with settings so we can set cache to false. | |||
|
109 | var settings = { | |||
|
110 | processData : false, | |||
|
111 | cache : false, | |||
|
112 | type : "PUT", | |||
|
113 | data : JSON.stringify(model), | |||
|
114 | headers : {'Content-Type': 'application/json'}, | |||
|
115 | success : $.proxy(notebook.save_notebook_success, this, start), | |||
|
116 | error : $.proxy(notebook.save_notebook_error, this) | |||
|
117 | }; | |||
|
118 | if (extra_settings) { | |||
|
119 | for (var key in extra_settings) { | |||
|
120 | settings[key] = extra_settings[key]; | |||
|
121 | } | |||
|
122 | } | |||
|
123 | notebook.events.trigger('notebook_saving.Notebook'); | |||
|
124 | var url = utils.url_join_encode( | |||
|
125 | notebook.base_url, | |||
|
126 | 'api/notebooks', | |||
|
127 | notebook.notebook_path, | |||
|
128 | notebook.notebook_name | |||
|
129 | ); | |||
|
130 | $.ajax(url, settings); | |||
|
131 | }; | |||
|
132 | } | |||
31 |
|
133 | |||
32 | ContentManager.prototype.save_checkpoint = function() { |
|
134 | ContentManager.prototype.save_checkpoint = function() { | |
|
135 | // This is not necessary - integrated into save | |||
33 | } |
|
136 | } | |
34 |
|
137 | |||
35 | ContentManager.prototype.restore_checkpoint = function(id) { |
|
138 | ContentManager.prototype.restore_checkpoint = function(notebook, id) { | |
|
139 | that = notebook; | |||
|
140 | this.events.trigger('notebook_restoring.Notebook', checkpoint); | |||
|
141 | var url = utils.url_join_encode( | |||
|
142 | this.base_url, | |||
|
143 | 'api/notebooks', | |||
|
144 | this.notebook_path, | |||
|
145 | this.notebook_name, | |||
|
146 | 'checkpoints', | |||
|
147 | checkpoint | |||
|
148 | ); | |||
|
149 | $.post(url).done( | |||
|
150 | $.proxy(that.restore_checkpoint_success, that) | |||
|
151 | ).fail( | |||
|
152 | $.proxy(that.restore_checkpoint_error, that) | |||
|
153 | ); | |||
36 | } |
|
154 | } | |
37 |
|
155 | |||
38 | ContentManager.prototype.list_checkpoints = function() { |
|
156 | ContentManager.prototype.list_checkpoints = function(notebook) { | |
|
157 | that = notebook; | |||
|
158 | var url = utils.url_join_encode( | |||
|
159 | that.base_url, | |||
|
160 | 'api/notebooks', | |||
|
161 | that.notebook_path, | |||
|
162 | that.notebook_name, | |||
|
163 | 'checkpoints' | |||
|
164 | ); | |||
|
165 | $.get(url).done( | |||
|
166 | $.proxy(that.list_checkpoints_success, that) | |||
|
167 | ).fail( | |||
|
168 | $.proxy(that.list_checkpoints_error, that) | |||
|
169 | ); | |||
39 | } |
|
170 | } | |
40 |
|
171 | |||
41 |
|
|
172 | return ContentManager; | |
42 | }); |
|
173 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now