Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 609c814

Browse files
committed
add Revert to the menu bar
1 parent 92341f3 commit 609c814

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

IPython/frontend/html/notebook/static/js/menubar.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ var IPython = (function (IPython) {
8787
this.element.find('#save_checkpoint').click(function () {
8888
IPython.notebook.save_checkpoint();
8989
});
90+
this.element.find('#restore_checkpoint').click(function () {
91+
});
9092
this.element.find('#download_ipynb').click(function () {
9193
var notebook_id = IPython.notebook.get_notebook_id();
9294
var url = that.baseProjectUrl() + 'notebooks/' +
@@ -221,8 +223,34 @@ var IPython = (function (IPython) {
221223
this.element.find('#keyboard_shortcuts').click(function () {
222224
IPython.quick_help.show_keyboard_shortcuts();
223225
});
226+
227+
this.update_restore_checkpoint(null);
228+
229+
$([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
230+
that.update_restore_checkpoint(data);
231+
});
232+
233+
$([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
234+
that.update_restore_checkpoint(data);
235+
});
224236
};
225237

238+
MenuBar.prototype.update_restore_checkpoint = function(checkpoint) {
239+
if (!checkpoint) {
240+
this.element.find("#restore_checkpoint")
241+
.addClass('ui-state-disabled')
242+
.off('click')
243+
.find('a').text("Revert");
244+
return;
245+
};
246+
var d = new Date(checkpoint.last_modified);
247+
this.element.find("#restore_checkpoint")
248+
.removeClass('ui-state-disabled')
249+
.off('click')
250+
.click(function () {
251+
IPython.notebook.restore_checkpoint_dialog();
252+
}).find('a').html("Revert to: <br/>" + d.format("mmm dd HH:MM:ss"));
253+
}
226254

227255
IPython.MenuBar = MenuBar;
228256

IPython/frontend/html/notebook/static/js/notebook.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,10 +1696,13 @@ var IPython = (function (IPython) {
16961696
});
16971697

16981698
}
1699+
16991700
// Create the kernel after the notebook is completely loaded to prevent
17001701
// code execution upon loading, which is a security risk.
17011702
if (! this.read_only) {
17021703
this.start_kernel();
1704+
// load our checkpoint list
1705+
IPython.notebook.list_checkpoints();
17031706
}
17041707
$([IPython.events]).trigger('notebook_loaded.Notebook');
17051708
};

IPython/frontend/html/notebook/templates/notebook.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
<li id="save_notebook"><a href="#">Save</a></li>
6060
<li id="save_checkpoint"><a href="#">Save Checkpoint</a></li>
6161
<hr/>
62+
<li id="restore_checkpoint"><a href="#">Revert to Checkpoint</a></li>
63+
<hr/>
6264
<li><a href="#">Download as</a>
6365
<ul>
6466
<li id="download_ipynb"><a href="#">IPython (.ipynb)</a></li>

0 commit comments

Comments
 (0)