diff --git a/package.json b/package.json index 151befa..714a531 100644 --- a/package.json +++ b/package.json @@ -27,14 +27,20 @@ "extension": true }, "dependencies": { - "@jupyterlab/application": "^0.17.2", - "@jupyterlab/apputils": "^0.17.2", - "@jupyterlab/codemirror": "^0.17.2", - "@jupyterlab/coreutils": "^2.0.0-0", - "@jupyterlab/docmanager": "^0.17.2", - "@jupyterlab/fileeditor": "^0.17.2", - "@jupyterlab/notebook": "^0.17.2", + "@jupyterlab/application": "^0.19.1", + "@jupyterlab/apputils": "^0.19.1", + "@jupyterlab/codemirror": "^0.19.1", + "@jupyterlab/coreutils": "^2.2.1", + "@jupyterlab/cells": "^0.19.1", + "@jupyterlab/outputarea": "^0.19.1", + "@jupyterlab/docmanager": "^0.19.1", + "@jupyterlab/fileeditor": "^0.19.1", + "@jupyterlab/notebook": "^0.19.1", + "@jupyterlab/rendermime": "^0.19.1", + "@jupyterlab/codeeditor": "^0.19.1", + "@jupyterlab/docregistry": "^0.19.1", "@phosphor/widgets": "^1.6.0", + "@types/react": "^16.8.1", "diff-match-patch": "^1.0.1", "jquery": "^3.3.1" }, @@ -54,8 +60,8 @@ "raw-loader": "^0.5.1", "rimraf": "^2.6.1", "style-loader": "^0.21.0", - "ts-node": "^7.0.0", - "typescript": "~2.4.0", + "ts-node": "8.0.2", + "typescript": "3.3.1", "webpack": "^4.16.1", "webpack-cli": "^3.1.0" } diff --git a/src/lab/index.ts b/src/lab/index.ts index 4f74410..0b5f7f8 100644 --- a/src/lab/index.ts +++ b/src/lab/index.ts @@ -28,6 +28,8 @@ import { nbformat } from '@jupyterlab/coreutils'; import { log } from '../utils/log'; import { INotebookOpener, IScriptOpener } from '../packages/gather/opener'; +//import { UUID } from '@phosphor/coreutils'; + /** * Try to only write Jupyter Lab-specific implementation code in this file. * If there is any program analysis / text processing, widgets that could be shared with Jupyter @@ -140,6 +142,9 @@ class ExecutionLoggerExtension implements DocumentRegistry.IWidgetExtension { + const notebookModel = widget.content.model; let notebookJson = notebookModel.toJSON() as nbformat.INotebookContent; notebookJson.cells = [] @@ -418,6 +424,15 @@ class Clipboard implements ICellClipboard { function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks: INotebookTracker, docManager: IDocumentManager) { console.log('Activating code gathering tools'); + + + docManager.activateRequested.connect( + (docMan, msg) => { + notebooks.forEach((widget: NotebookPanel) => print(widget)) + + }); + + let gatherModel = new GatherModel(); @@ -425,6 +440,99 @@ function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks: app.docRegistry.addWidgetExtension('Notebook', notificationExtension); let executionSlicer = new ExecutionLogSlicer(new DataflowAnalyzer()); + + + + + + let historyLoaded = 0; + let previousSaveLogLength = executionSlicer._executionLog.length + function print(notebook: NotebookPanel){ + + //deserializes execution history on load of the notebook metadata + if (executionSlicer._executionLog.length == 0 && historyLoaded == 0) { + var seconds = 0; + var intervalId = setInterval(function(){ + seconds+=1 + if(seconds == 10) { + console.log("history is empty") + clearInterval(intervalId); + historyLoaded = 1; + } else { + + if (notebook.model.metadata.get("executionHistory")) { + let history = notebook.model.metadata.get("executionHistory"); + + console.log("History Loading...") + console.log("Loading Before", executionSlicer._executionLog); + console.log("Notebook Stored Execution History", notebook.model.metadata.get("executionHistory")); + + for (let x in (history)){ + let cell =((history)[x.toString()]); + + executionSlicer.logExecution(cell) + } + //notebook.model.metadata.set("executionHistory","") + historyLoaded = 1; + previousSaveLogLength = executionSlicer._executionLog.length + console.log("Loading After", executionSlicer._executionLog); + clearInterval(intervalId); + } else { + console.log(notebook.model.metadata.get("executionHistory")); + console.log("still waiting!", seconds); + } + } + }, 1000); + } + + //Notebook listener serializes execution log to metadata on save + notebook.context.saveState.connect((context, msg) => { + + let currentSaveLogLength = executionSlicer._programBuilder._cellPrograms.length + if (msg == "started" && currentSaveLogLength != previousSaveLogLength){ + + console.log("Saving File and Updating Execution History..."); + console.log("before", notebook.model.metadata.get("executionHistory")); + + let cellPrograms = executionSlicer._programBuilder._cellPrograms; + let tempCellGroup: any = []; + + for (var i = previousSaveLogLength; i < cellPrograms.length; i++) { + let cell = cellPrograms[i].cell; + let tempCell: any = {}; + tempCell["id"] = cell.id; + tempCell["is_cell"] = cell.is_cell; + tempCell["executionCount"] = cell.executionCount; + tempCell["hasError"] = cell.hasError; + tempCell["isCode"] = cell.isCode; + tempCell["text"] = cell.text; + tempCell["gathered"] = cell.gathered; + tempCellGroup.push(tempCell); + } + + let history = notebook.model.metadata.get("executionHistory"); + let tempHistory: any = {}; + let counter = 0 + + for (let x in (history)){ + tempHistory[counter.toString()] = (history)[x.toString()]; + counter += 1; + } + for (var i = 0; i void) { app.commands.addCommand(command, { label, execute }); palette.addItem({ command, category: 'Clean Up' }); diff --git a/src/lab/labcell.ts b/src/lab/labcell.ts index 7481c80..317865a 100644 --- a/src/lab/labcell.ts +++ b/src/lab/labcell.ts @@ -77,4 +77,5 @@ export class LabCell extends AbstractOutputterCell { is_cell: boolean = true; is_outputter_cell: boolean = true; private _model: ICodeCellModel; + } \ No newline at end of file diff --git a/src/slicing/ExecutionSlicer.ts b/src/slicing/ExecutionSlicer.ts index 40b5e9c..8bfd751 100644 --- a/src/slicing/ExecutionSlicer.ts +++ b/src/slicing/ExecutionSlicer.ts @@ -52,8 +52,8 @@ export class SlicedExecution { */ export class ExecutionLogSlicer { - private _executionLog = new Array(); - private _programBuilder: ProgramBuilder; + public _executionLog = new Array(); + public _programBuilder: ProgramBuilder; private _dataflowAnalyzer: DataflowAnalyzer; /** diff --git a/src/slicing/ProgramBuilder.ts b/src/slicing/ProgramBuilder.ts index 9d34ec8..ef59d13 100644 --- a/src/slicing/ProgramBuilder.ts +++ b/src/slicing/ProgramBuilder.ts @@ -217,7 +217,7 @@ export class ProgramBuilder { return null; } - private _cellPrograms: CellProgram[]; + public _cellPrograms: CellProgram[]; private _dataflowAnalyzer: DataflowAnalyzer; private _magicsRewriter: MagicsRewriter = new MagicsRewriter(); } \ No newline at end of file