Skip to content

Commit

Permalink
Backport PR #3939: minor checkpoint cleanup
Browse files Browse the repository at this point in the history
- remember list of checkpoints browser-side
- don't clobber list when a new checkpoint is created
- cleanup references in MenuBar restore list.
  There was a closure issue, where multiple menu items would actually all
  restore the same checkpoint.

Issues revealed by rgbkrk/bookstore, which supports multiple checkpoints.

I'm fine if this doesn't get into 1.0, given timing.
  • Loading branch information
minrk committed Aug 10, 2013
1 parent 370c8db commit 8589789
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
9 changes: 4 additions & 5 deletions IPython/html/static/notebook/js/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ var IPython = (function (IPython) {
this.update_restore_checkpoint(null);

$([IPython.events]).on('checkpoints_listed.Notebook', function (event, data) {
that.update_restore_checkpoint(data);
that.update_restore_checkpoint(IPython.notebook.checkpoints);
});

$([IPython.events]).on('checkpoint_created.Notebook', function (event, data) {
that.update_restore_checkpoint([data]);
that.update_restore_checkpoint(IPython.notebook.checkpoints);
});
};

Expand All @@ -247,8 +247,7 @@ var IPython = (function (IPython) {
return;
};

for (var i = 0; i < checkpoints.length; i++) {
var checkpoint = checkpoints[i];
checkpoints.map(function (checkpoint) {
var d = new Date(checkpoint.last_modified);
ul.append(
$("<li/>").append(
Expand All @@ -260,7 +259,7 @@ var IPython = (function (IPython) {
})
)
);
};
});
};

IPython.MenuBar = MenuBar;
Expand Down
30 changes: 27 additions & 3 deletions IPython/html/static/notebook/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var IPython = (function (IPython) {
this.metadata = {};
this._checkpoint_after_save = false;
this.last_checkpoint = null;
this.checkpoints = [];
this.autosave_interval = 0;
this.autosave_timer = null;
// autosave *at most* every two minutes
Expand Down Expand Up @@ -1825,10 +1826,32 @@ var IPython = (function (IPython) {
this.save_notebook();
};

/**
* Add a checkpoint for this notebook.
* for use as a callback from checkpoint creation.
*
* @method add_checkpoint
*/
Notebook.prototype.add_checkpoint = function (checkpoint) {
var found = false;
for (var i = 0; i < this.checkpoints.length; i++) {
var existing = this.checkpoints[i];
if (existing.checkpoint_id == checkpoint.checkpoint_id) {
found = true;
this.checkpoints[i] = checkpoint;
break;
}
}
if (!found) {
this.checkpoints.push(checkpoint);
}
this.last_checkpoint = this.checkpoints[this.checkpoints.length - 1];
};

/**
* List checkpoints for this notebook.
*
* @method list_checkpoint
* @method list_checkpoints
*/
Notebook.prototype.list_checkpoints = function () {
var url = this.baseProjectUrl() + 'notebooks/' + this.notebook_id + '/checkpoints';
Expand All @@ -1849,8 +1872,9 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.list_checkpoints_success = function (data, status, xhr) {
var data = $.parseJSON(data);
this.checkpoints = data;
if (data.length) {
this.last_checkpoint = data[0];
this.last_checkpoint = data[data.length - 1];
} else {
this.last_checkpoint = null;
}
Expand Down Expand Up @@ -1893,7 +1917,7 @@ var IPython = (function (IPython) {
*/
Notebook.prototype.create_checkpoint_success = function (data, status, xhr) {
var data = $.parseJSON(data);
this.last_checkpoint = data;
this.add_checkpoint(data);
$([IPython.events]).trigger('checkpoint_created.Notebook', data);
};

Expand Down

0 comments on commit 8589789

Please sign in to comment.