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

Skip to content

Commit 0c16365

Browse files
committed
restore checkpoints in a sub-list
minor styling update to the restore dialog as well
1 parent c801089 commit 0c16365

6 files changed

Lines changed: 48 additions & 24 deletions

File tree

IPython/frontend/html/notebook/static/css/style.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var IPython = (function (IPython) {
6060
IPython.notebook.select(i);
6161
}
6262
});
63+
this.element.find("#restore_checkpoint").find("ul").find("li").hide();
6364
};
6465

6566

@@ -228,26 +229,33 @@ var IPython = (function (IPython) {
228229
});
229230

230231
$([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
231-
that.update_restore_checkpoint(data);
232+
that.update_restore_checkpoint([data]);
232233
});
233234
};
234235

235-
MenuBar.prototype.update_restore_checkpoint = function(checkpoint) {
236-
if (!checkpoint) {
237-
this.element.find("#restore_checkpoint")
238-
.addClass('ui-state-disabled')
239-
.off('click')
240-
.find('a').text("Revert");
241-
return;
236+
MenuBar.prototype.update_restore_checkpoint = function(checkpoints) {
237+
if (! checkpoints) {
238+
checkpoints = [];
242239
};
243-
var d = new Date(checkpoint.last_modified);
244-
this.element.find("#restore_checkpoint")
245-
.removeClass('ui-state-disabled')
246-
.off('click')
247-
.click(function () {
248-
IPython.notebook.restore_checkpoint_dialog();
249-
}).find('a').html("Revert to: <br/>" + d.format("mmm dd HH:MM:ss"));
250-
}
240+
this.element.find("#restore_checkpoint").find("ul").find("li").each(function(i) {
241+
var li = $(this);
242+
var a = li.find("a");
243+
a.off("click");
244+
if (checkpoints.length <= i) {
245+
li.hide();
246+
return;
247+
} else {
248+
li.show();
249+
};
250+
var checkpoint = checkpoints[i];
251+
var d = new Date(checkpoint.last_modified);
252+
li.find('a').text(
253+
d.format("mmm dd HH:MM:ss")
254+
).click(function () {
255+
IPython.notebook.restore_checkpoint_dialog(checkpoint);
256+
});
257+
});
258+
};
251259

252260
IPython.MenuBar = MenuBar;
253261

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,7 @@ var IPython = (function (IPython) {
18391839
} else {
18401840
this.last_checkpoint = null;
18411841
}
1842-
$([IPython.events]).trigger('checkpoints_listed.Notebook', data);
1842+
$([IPython.events]).trigger('checkpoints_listed.Notebook', [data]);
18431843
};
18441844

18451845
/**
@@ -1894,25 +1894,28 @@ var IPython = (function (IPython) {
18941894
$([IPython.events]).trigger('checkpoint_failed.Notebook');
18951895
};
18961896

1897-
Notebook.prototype.restore_checkpoint_dialog = function () {
1897+
Notebook.prototype.restore_checkpoint_dialog = function (checkpoint) {
18981898
var that = this;
1899-
var checkpoint = this.last_checkpoint;
1899+
var checkpoint = checkpoint || this.last_checkpoint;
19001900
if ( ! checkpoint ) {
19011901
console.log("restore dialog, but no checkpoint to restore to!");
19021902
return;
19031903
}
19041904
var dialog = $('<div/>').append(
1905-
$('<p/>').text("Are you sure you want to revert the notebook to " +
1905+
$('<p/>').addClass("p-space").text(
1906+
"Are you sure you want to revert the notebook to " +
19061907
"the latest checkpoint?"
19071908
).append(
19081909
$("<strong/>").text(
19091910
" This cannot be undone."
19101911
)
19111912
)
19121913
).append(
1913-
$('<p/>').text("The checkpoint was last updated at")
1914+
$('<p/>').addClass("p-space").text("The checkpoint was last updated at:")
19141915
).append(
1915-
$('<p/>').text(Date(checkpoint.last_modified))
1916+
$('<p/>').addClass("p-space").text(
1917+
Date(checkpoint.last_modified)
1918+
).css("text-align", "center")
19161919
);
19171920

19181921
$(document).append(dialog);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var IPython = (function (IPython) {
5757
that.set_save_status('Last Save Failed!');
5858
});
5959
$([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
60-
that.set_last_checkpoint(data);
60+
that.set_last_checkpoint(data[0]);
6161
});
6262

6363
$([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {

IPython/frontend/html/notebook/static/less/notebook.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,7 @@ input.raw_input {
507507
height: 1em;
508508
}
509509

510+
p.p-space {
511+
margin-bottom: 10px;
512+
}
513+

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@
5959
<li id="rename_notebook"><a href="#">Rename...</a></li>
6060
<li id="save_checkpoint"><a href="#">Save and Checkpoint</a></li>
6161
<hr/>
62-
<li id="restore_checkpoint"><a href="#">Revert to Checkpoint</a></li>
62+
<li id="restore_checkpoint"><a href="#">Revert to Checkpoint</a>
63+
<ul>
64+
<li><a href="#"></a></li>
65+
<li><a href="#"></a></li>
66+
<li><a href="#"></a></li>
67+
<li><a href="#"></a></li>
68+
<li><a href="#"></a></li>
69+
</ul>
70+
</li>
6371
<hr/>
6472
<li><a href="#">Download as</a>
6573
<ul>

0 commit comments

Comments
 (0)