add empty metadata field on cells/worksheets

These are unused for now, but will allow adding data to the notebook without a full version bump.
This commit is contained in:
MinRK 2012-04-27 17:24:18 -07:00
parent b5e488d78c
commit 362feaa295
4 changed files with 20 additions and 3 deletions

View File

@ -19,6 +19,7 @@ var IPython = (function (IPython) {
this.read_only = false;
this.selected = false;
this.element = null;
this.metadata = {};
this.create_element();
if (this.element !== null) {
this.element.data("cell", this);
@ -90,10 +91,16 @@ var IPython = (function (IPython) {
Cell.prototype.toJSON = function () {
var data = {};
data.metadata = this.metadata;
return data;
};
Cell.prototype.fromJSON = function (data) {
if (data.metadata !== undefined) {
this.metadata = data.metadata;
}
};

View File

@ -264,6 +264,7 @@ var IPython = (function (IPython) {
// JSON serialization
CodeCell.prototype.fromJSON = function (data) {
IPython.Cell.prototype.fromJSON.apply(this, arguments);
if (data.cell_type === 'code') {
if (data.input !== undefined) {
this.set_text(data.input);
@ -286,7 +287,7 @@ var IPython = (function (IPython) {
CodeCell.prototype.toJSON = function () {
var data = {};
var data = IPython.Cell.prototype.toJSON.apply(this);
data.input = this.get_text();
data.cell_type = 'code';
if (this.input_prompt_number) {

View File

@ -25,6 +25,8 @@ var IPython = (function (IPython) {
this.paste_enabled = false;
this.dirty = false;
this.metadata = {};
// single worksheet for now
this.worksheet_metadata = {};
this.control_key_active = false;
this.notebook_id = null;
this.notebook_name = null;
@ -1003,6 +1005,9 @@ var IPython = (function (IPython) {
// Only handle 1 worksheet for now.
var worksheet = data.worksheets[0];
if (worksheet !== undefined) {
if (worksheet.metadata) {
this.worksheet_metadata = worksheet.metadata;
}
var new_cells = worksheet.cells;
ncells = new_cells.length;
var cell_data = null;
@ -1031,7 +1036,10 @@ var IPython = (function (IPython) {
};
var data = {
// Only handle 1 worksheet for now.
worksheets : [{cells:cell_array}],
worksheets : [{
cells: cell_array,
metadata: this.worksheet_metadata
}],
metadata : this.metadata
};
return data;

View File

@ -155,6 +155,7 @@ var IPython = (function (IPython) {
TextCell.prototype.fromJSON = function (data) {
IPython.Cell.prototype.fromJSON.apply(this, arguments);
if (data.cell_type === this.cell_type) {
if (data.source !== undefined) {
this.set_text(data.source);
@ -167,7 +168,7 @@ var IPython = (function (IPython) {
TextCell.prototype.toJSON = function () {
var data = {};
var data = IPython.Cell.prototype.toJSON.apply(this);
data.cell_type = this.cell_type;
data.source = this.get_text();
return data;