Skip to content

Commit

Permalink
store cell id in metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Jul 27, 2012
1 parent 474eed8 commit 7e8d57c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
17 changes: 10 additions & 7 deletions IPython/frontend/html/notebook/static/js/cell.js
Expand Up @@ -25,10 +25,11 @@ var IPython = (function (IPython) {
this.element.data("cell", this);
this.bind_events();
}
if( this.cell_id == undefined)
{
this.cell_id = utils.uuid();
}
// alway create uuid, it will be overwritten
// when loading from JSON. Trying to check for
// this.cell_id = undefined create issues
// with inheritence
this.cell_id = utils.uuid();
};


Expand Down Expand Up @@ -96,7 +97,9 @@ var IPython = (function (IPython) {
Cell.prototype.toJSON = function () {
var data = {};
data.metadata = this.metadata;
data.uuid = this.cell_id
if (this.cell_id != undefined){
data.metadata.uuid = this.cell_id
}
return data;
};

Expand All @@ -105,8 +108,8 @@ var IPython = (function (IPython) {
if (data.metadata !== undefined) {
this.metadata = data.metadata;
}
if (data.uuid !== undefined) {
this.cell_id = data.uuid;
if (data.metadata.uuid !== undefined) {
this.cell_id = data.metadata.uuid;
}
};

Expand Down
8 changes: 6 additions & 2 deletions IPython/frontend/html/notebook/static/js/notebook.js
Expand Up @@ -776,8 +776,8 @@ var IPython = (function (IPython) {

// we don't want to have du plicate uuid, so for now, we are carefull
// of deleting the uuid befor copying.
if( json.uuid != undefined){
delete json.uuid
if( json.metadata.uuid != undefined){
delete json.metadata.uuid
}
this.clipboard = json;
this.enable_paste();
Expand All @@ -789,6 +789,10 @@ var IPython = (function (IPython) {
var cell_data = this.clipboard;
var new_cell = this.insert_cell_above(cell_data.cell_type);
new_cell.fromJSON(cell_data);
// generate uuid at cell paste
// for a cell can be paste many time and we need unique ids.
new.cell.cell_id = utils.uuid();

old_cell = this.get_next_cell(new_cell);
this.delete_cell(this.find_cell_index(old_cell));
this.select(this.find_cell_index(new_cell));
Expand Down

0 comments on commit 7e8d57c

Please sign in to comment.