|
@@ -3,7 +3,7 @@
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
import {
|
|
import {
|
|
- IContentsModel, IKernelMessage, IContentsManager
|
|
|
|
|
|
+ IKernelMessage
|
|
} from 'jupyter-js-services';
|
|
} from 'jupyter-js-services';
|
|
|
|
|
|
import {
|
|
import {
|
|
@@ -31,11 +31,11 @@ import {
|
|
} from '../output-area';
|
|
} from '../output-area';
|
|
|
|
|
|
import {
|
|
import {
|
|
- NBData, MarkdownCell, CodeCell,
|
|
|
|
|
|
+ MarkdownCell, CodeCell,
|
|
isMarkdownCell, isCodeCell,
|
|
isMarkdownCell, isCodeCell,
|
|
DisplayData, isDisplayData,
|
|
DisplayData, isDisplayData,
|
|
ExecuteResult, isExecuteResult,
|
|
ExecuteResult, isExecuteResult,
|
|
- Stream, isStream, Cell,
|
|
|
|
|
|
+ Stream, isStream, Cell, NotebookContent,
|
|
JupyterError, isJupyterError, Output, BaseOutput,
|
|
JupyterError, isJupyterError, Output, BaseOutput,
|
|
MAJOR_VERSION, MINOR_VERSION
|
|
MAJOR_VERSION, MINOR_VERSION
|
|
} from './nbformat';
|
|
} from './nbformat';
|
|
@@ -45,11 +45,11 @@ import {
|
|
* Build a complete notebook model from the notebook data.
|
|
* Build a complete notebook model from the notebook data.
|
|
*/
|
|
*/
|
|
export
|
|
export
|
|
-function populateNotebookModel(nb: INotebookModel, data: NBData): void {
|
|
|
|
|
|
+function populateNotebookModel(nb: INotebookModel, data: NotebookContent): void {
|
|
nb.cells.clear();
|
|
nb.cells.clear();
|
|
|
|
|
|
// iterate through the cell data, creating cell models
|
|
// iterate through the cell data, creating cell models
|
|
- data.content.cells.forEach((c) => {
|
|
|
|
|
|
+ data.cells.forEach((c) => {
|
|
let input = new InputAreaModel();
|
|
let input = new InputAreaModel();
|
|
input.textEditor = new EditorModel({ lineNumbers: false });
|
|
input.textEditor = new EditorModel({ lineNumbers: false });
|
|
input.textEditor.text = c.source;
|
|
input.textEditor.text = c.source;
|
|
@@ -75,8 +75,10 @@ function populateNotebookModel(nb: INotebookModel, data: NBData): void {
|
|
if (nb.cells.length) {
|
|
if (nb.cells.length) {
|
|
nb.selectedCellIndex = 0;
|
|
nb.selectedCellIndex = 0;
|
|
}
|
|
}
|
|
|
|
+ nb.metadata = data.metadata;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Build an output model from output message data.
|
|
* Build an output model from output message data.
|
|
*/
|
|
*/
|
|
@@ -134,35 +136,23 @@ function messageToModel(msg: IKernelMessage) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Save the current notebook state to disk.
|
|
|
|
|
|
+ * Get the current notebook content.
|
|
*/
|
|
*/
|
|
export
|
|
export
|
|
-function saveNotebook(nb: NotebookModel, contents: IContentsManager): Promise<IContentsModel> {
|
|
|
|
- if (!nb.session) {
|
|
|
|
- Promise.reject('No notebook session');
|
|
|
|
- }
|
|
|
|
- let cells = getNotebookData(nb);
|
|
|
|
- return nb.session.kernel.kernelInfo().then(info => {
|
|
|
|
- let name = nb.session.kernel.name;
|
|
|
|
- // TODO: Get the display name.
|
|
|
|
- let metadata = { kernelspec: { name, display_name: name },
|
|
|
|
- language_info: info.language_info
|
|
|
|
- };
|
|
|
|
- let notebook = { cells, metadata, nbformat: MAJOR_VERSION,
|
|
|
|
- nbformat_minor: MINOR_VERSION };
|
|
|
|
- return contents.save(nb.session.notebookPath, {
|
|
|
|
- type: 'notebook',
|
|
|
|
- content: notebook
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
|
|
+function getNotebookContent(nb: NotebookModel): NotebookContent {
|
|
|
|
+ return {
|
|
|
|
+ cells: getNotebookCells(nb),
|
|
|
|
+ metadata: nb.metadata,
|
|
|
|
+ nbformat: MAJOR_VERSION,
|
|
|
|
+ nbformat_minor: MINOR_VERSION
|
|
|
|
+ };
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Get the cell data for a given notebook.
|
|
* Get the cell data for a given notebook.
|
|
*/
|
|
*/
|
|
-export
|
|
|
|
-function getNotebookData(nb: NotebookModel): Cell[] {
|
|
|
|
|
|
+function getNotebookCells(nb: NotebookModel): Cell[] {
|
|
let cells: Cell[] = [];
|
|
let cells: Cell[] = [];
|
|
for (let i = 0; i < nb.cells.length; i++) {
|
|
for (let i = 0; i < nb.cells.length; i++) {
|
|
let cell = nb.cells.get(i);
|
|
let cell = nb.cells.get(i);
|