@jupyterlab/docmanager-extension
Advanced tools
Comparing version 0.17.2 to 0.17.3
@@ -6,2 +6,3 @@ "use strict"; | ||
const algorithm_1 = require("@phosphor/algorithm"); | ||
const widgets_1 = require("@phosphor/widgets"); | ||
const apputils_1 = require("@jupyterlab/apputils"); | ||
@@ -105,2 +106,11 @@ const coreutils_1 = require("@jupyterlab/coreutils"); | ||
exports.default = plugin; | ||
/* Widget to display the revert to checkpoint confirmation. */ | ||
class RevertConfirmWidget extends widgets_1.Widget { | ||
/** | ||
* Construct a new revert confirmation widget. | ||
*/ | ||
constructor(checkpoint) { | ||
super({ node: Private.createRevertConfirmNode(checkpoint) }); | ||
} | ||
} | ||
/** | ||
@@ -307,6 +317,16 @@ * Add the file operations commands to the application's command registry. | ||
execute: () => { | ||
if (isEnabled()) { | ||
let context = docManager.contextForWidget(shell.currentWidget); | ||
return context.revert(); | ||
if (!isEnabled()) { | ||
return; | ||
} | ||
const context = docManager.contextForWidget(shell.currentWidget); | ||
return apputils_1.showDialog({ | ||
title: 'Reload Notebook from Disk', | ||
body: `Are you sure you want to reload | ||
the notebook from the disk?`, | ||
buttons: [apputils_1.Dialog.cancelButton(), apputils_1.Dialog.warnButton({ label: 'Reload' })] | ||
}).then(result => { | ||
if (result.button.accept && !context.isDisposed) { | ||
return context.revert(); | ||
} | ||
}); | ||
} | ||
@@ -319,9 +339,33 @@ }); | ||
execute: () => { | ||
if (isEnabled()) { | ||
let context = docManager.contextForWidget(shell.currentWidget); | ||
if (context.model.readOnly) { | ||
return context.revert(); | ||
if (!isEnabled()) { | ||
return; | ||
} | ||
const context = docManager.contextForWidget(shell.currentWidget); | ||
return context.listCheckpoints().then(checkpoints => { | ||
if (checkpoints.length < 1) { | ||
return; | ||
} | ||
return context.restoreCheckpoint().then(() => context.revert()); | ||
} | ||
const lastCheckpoint = checkpoints[checkpoints.length - 1]; | ||
if (!lastCheckpoint) { | ||
return; | ||
} | ||
return apputils_1.showDialog({ | ||
title: 'Revert notebook to checkpoint', | ||
body: new RevertConfirmWidget(lastCheckpoint), | ||
buttons: [ | ||
apputils_1.Dialog.cancelButton(), | ||
apputils_1.Dialog.warnButton({ label: 'Revert' }) | ||
] | ||
}).then(result => { | ||
if (context.isDisposed) { | ||
return; | ||
} | ||
if (result.button.accept) { | ||
if (context.model.readOnly) { | ||
return context.revert(); | ||
} | ||
return context.restoreCheckpoint().then(() => context.revert()); | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -542,2 +586,28 @@ }); | ||
Private.id = 0; | ||
function createRevertConfirmNode(checkpoint) { | ||
let body = document.createElement('div'); | ||
let confirmMessage = document.createElement('p'); | ||
let confirmText = document.createTextNode(`Are you sure you want to revert | ||
the notebook to the latest checkpoint? `); | ||
let cannotUndoText = document.createElement('strong'); | ||
cannotUndoText.textContent = 'This cannot be undone.'; | ||
confirmMessage.appendChild(confirmText); | ||
confirmMessage.appendChild(cannotUndoText); | ||
let lastCheckpointMessage = document.createElement('p'); | ||
let lastCheckpointText = document.createTextNode('The checkpoint was last updated at: '); | ||
let lastCheckpointDate = document.createElement('p'); | ||
let date = new Date(checkpoint.last_modified); | ||
lastCheckpointDate.style.textAlign = 'center'; | ||
lastCheckpointDate.textContent = | ||
coreutils_1.Time.format(date, 'dddd, MMMM Do YYYY, h:mm:ss a') + | ||
' (' + | ||
coreutils_1.Time.formatHuman(date) + | ||
')'; | ||
lastCheckpointMessage.appendChild(lastCheckpointText); | ||
lastCheckpointMessage.appendChild(lastCheckpointDate); | ||
body.appendChild(confirmMessage); | ||
body.appendChild(lastCheckpointMessage); | ||
return body; | ||
} | ||
Private.createRevertConfirmNode = createRevertConfirmNode; | ||
})(Private || (Private = {})); |
{ | ||
"name": "@jupyterlab/docmanager-extension", | ||
"version": "0.17.2", | ||
"version": "0.17.3", | ||
"description": "JupyterLab - Document Manager Extension", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/jupyterlab/jupyterlab", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65280
634