@jupyterlab/running
Advanced tools
Comparing version 0.17.0-1 to 0.17.1
@@ -14,2 +14,4 @@ import { Message } from '@phosphor/messaging'; | ||
constructor(options: RunningSessions.IOptions); | ||
protected onUpdateRequest(msg: Message): void; | ||
protected onAfterAttach(msg: Message): void; | ||
/** | ||
@@ -23,55 +25,5 @@ * A signal emitted when a kernel session open is requested. | ||
readonly terminalOpenRequested: ISignal<this, TerminalSession.IModel>; | ||
/** | ||
* The renderer used by the running sessions widget. | ||
*/ | ||
readonly renderer: RunningSessions.IRenderer; | ||
/** | ||
* Refresh the widget. | ||
*/ | ||
refresh(): Promise<void>; | ||
/** | ||
* Handle the DOM events for the widget. | ||
* | ||
* @param event - The DOM event sent to the widget. | ||
* | ||
* #### Notes | ||
* This method implements the DOM `EventListener` interface and is | ||
* called in response to events on the widget's DOM nodes. It should | ||
* not be called directly by user code. | ||
*/ | ||
handleEvent(event: Event): void; | ||
/** | ||
* A message handler invoked on an `'after-attach'` message. | ||
*/ | ||
protected onAfterAttach(msg: Message): void; | ||
/** | ||
* A message handler invoked on a `'before-detach'` message. | ||
*/ | ||
protected onBeforeDetach(msg: Message): void; | ||
/** | ||
* A message handler invoked on an `'update-request'` message. | ||
*/ | ||
protected onUpdateRequest(msg: Message): void; | ||
/** | ||
* Handle the `'click'` event for the widget. | ||
* | ||
* #### Notes | ||
* This listener is attached to the document node. | ||
*/ | ||
private _evtClick; | ||
/** | ||
* Handle a change to the running sessions. | ||
*/ | ||
private _onSessionsChanged; | ||
/** | ||
* Handle a change to the running terminals. | ||
*/ | ||
private _onTerminalsChanged; | ||
private _manager; | ||
private _renderer; | ||
private _runningSessions; | ||
private _runningTerminals; | ||
private _refreshId; | ||
private _sessionOpenRequested; | ||
private _terminalOpenRequested; | ||
private options; | ||
} | ||
@@ -90,199 +42,3 @@ /** | ||
manager: ServiceManager.IManager; | ||
/** | ||
* The renderer for the running sessions widget. | ||
* | ||
* The default is a shared renderer instance. | ||
*/ | ||
renderer?: IRenderer; | ||
} | ||
/** | ||
* A renderer for use with a running sessions widget. | ||
*/ | ||
interface IRenderer { | ||
/** | ||
* Create the root node for the running sessions widget. | ||
*/ | ||
createNode(): HTMLElement; | ||
/** | ||
* Create a fully populated header node for the terminals section. | ||
* | ||
* @returns A new node for a running terminal session header. | ||
*/ | ||
createTerminalHeaderNode(): HTMLElement; | ||
/** | ||
* Create a fully populated header node for the sessions section. | ||
* | ||
* @returns A new node for a running kernel session header. | ||
*/ | ||
createSessionHeaderNode(): HTMLElement; | ||
/** | ||
* Create a node for a running terminal session item. | ||
* | ||
* @returns A new node for a running terminal session item. | ||
* | ||
* #### Notes | ||
* The data in the node should be uninitialized. | ||
* | ||
* The `updateTerminalNode` method will be called for initialization. | ||
*/ | ||
createTerminalNode(): HTMLLIElement; | ||
/** | ||
* Create a node for a running kernel session item. | ||
* | ||
* @returns A new node for a running kernel session item. | ||
* | ||
* #### Notes | ||
* The data in the node should be uninitialized. | ||
* | ||
* The `updateSessionNode` method will be called for initialization. | ||
*/ | ||
createSessionNode(): HTMLLIElement; | ||
/** | ||
* Get the shutdown node for a terminal node. | ||
* | ||
* @param node - A node created by a call to `createTerminalNode`. | ||
* | ||
* @returns The node representing the shutdown option. | ||
* | ||
* #### Notes | ||
* A click on this node is considered a shutdown request. | ||
* A click anywhere else on the node is considered an open request. | ||
*/ | ||
getTerminalShutdown(node: HTMLLIElement): HTMLElement; | ||
/** | ||
* Get the shutdown node for a session node. | ||
* | ||
* @param node - A node created by a call to `createSessionNode`. | ||
* | ||
* @returns The node representing the shutdown option. | ||
* | ||
* #### Notes | ||
* A click on this node is considered a shutdown request. | ||
* A click anywhere else on the node is considered an open request. | ||
*/ | ||
getSessionShutdown(node: HTMLLIElement): HTMLElement; | ||
/** | ||
* Populate a node with running terminal session data. | ||
* | ||
* @param node - A node created by a call to `createTerminalNode`. | ||
* | ||
* @param models - The list of terminal session models. | ||
* | ||
* #### Notes | ||
* This method should completely reset the state of the node to | ||
* reflect the data for the session models. | ||
*/ | ||
updateTerminalNode(node: HTMLLIElement, model: TerminalSession.IModel): void; | ||
/** | ||
* Populate a node with running kernel session data. | ||
* | ||
* @param node - A node created by a call to `createSessionNode`. | ||
* | ||
* @param models - The list of kernel session models. | ||
* | ||
* @param kernelName - The kernel display name. | ||
* | ||
* #### Notes | ||
* This method should completely reset the state of the node to | ||
* reflect the data for the session models. | ||
*/ | ||
updateSessionNode(node: HTMLLIElement, model: Session.IModel, kernelName: string): void; | ||
} | ||
/** | ||
* The default implementation of `IRenderer`. | ||
*/ | ||
class Renderer implements IRenderer { | ||
/** | ||
* Create the root node for the running sessions widget. | ||
*/ | ||
createNode(): HTMLElement; | ||
/** | ||
* Create a fully populated header node for the terminals section. | ||
* | ||
* @returns A new node for a running terminal session header. | ||
*/ | ||
createTerminalHeaderNode(): HTMLElement; | ||
/** | ||
* Create a fully populated header node for the sessions section. | ||
* | ||
* @returns A new node for a running kernel session header. | ||
*/ | ||
createSessionHeaderNode(): HTMLElement; | ||
/** | ||
* Create a node for a running terminal session item. | ||
* | ||
* @returns A new node for a running terminal session item. | ||
* | ||
* #### Notes | ||
* The data in the node should be uninitialized. | ||
* | ||
* The `updateTerminalNode` method will be called for initialization. | ||
*/ | ||
createTerminalNode(): HTMLLIElement; | ||
/** | ||
* Create a node for a running kernel session item. | ||
* | ||
* @returns A new node for a running kernel session item. | ||
* | ||
* #### Notes | ||
* The data in the node should be uninitialized. | ||
* | ||
* The `updateSessionNode` method will be called for initialization. | ||
*/ | ||
createSessionNode(): HTMLLIElement; | ||
/** | ||
* Get the shutdown node for a terminal node. | ||
* | ||
* @param node - A node created by a call to `createTerminalNode`. | ||
* | ||
* @returns The node representing the shutdown option. | ||
* | ||
* #### Notes | ||
* A click on this node is considered a shutdown request. | ||
* A click anywhere else on the node is considered an open request. | ||
*/ | ||
getTerminalShutdown(node: HTMLLIElement): HTMLElement; | ||
/** | ||
* Get the shutdown node for a session node. | ||
* | ||
* @param node - A node created by a call to `createSessionNode`. | ||
* | ||
* @returns The node representing the shutdown option. | ||
* | ||
* #### Notes | ||
* A click on this node is considered a shutdown request. | ||
* A click anywhere else on the node is considered an open request. | ||
*/ | ||
getSessionShutdown(node: HTMLLIElement): HTMLElement; | ||
/** | ||
* Populate a node with running terminal session data. | ||
* | ||
* @param node - A node created by a call to `createTerminalNode`. | ||
* | ||
* @param models - The list of terminal session models. | ||
* | ||
* #### Notes | ||
* This method should completely reset the state of the node to | ||
* reflect the data for the session models. | ||
*/ | ||
updateTerminalNode(node: HTMLLIElement, model: TerminalSession.IModel): void; | ||
/** | ||
* Populate a node with running kernel session data. | ||
* | ||
* @param node - A node created by a call to `createSessionNode`. | ||
* | ||
* @param models - The list of kernel session models. | ||
* | ||
* @param kernelName - The kernel display name. | ||
* | ||
* #### Notes | ||
* This method should completely reset the state of the node to | ||
* reflect the data for the session models. | ||
*/ | ||
updateSessionNode(node: HTMLLIElement, model: Session.IModel, kernelName: string): void; | ||
} | ||
/** | ||
* The default `Renderer` instance. | ||
*/ | ||
const defaultRenderer: Renderer; | ||
} |
527
lib/index.js
"use strict"; | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const React = __importStar(require("react")); | ||
const ReactDOM = __importStar(require("react-dom")); | ||
const signaling_1 = require("@phosphor/signaling"); | ||
const domutils_1 = require("@phosphor/domutils"); | ||
const widgets_1 = require("@phosphor/widgets"); | ||
@@ -28,10 +36,2 @@ const apputils_1 = require("@jupyterlab/apputils"); | ||
/** | ||
* The class name added to a shutdown all terminals button. | ||
*/ | ||
const SHUTDOWN_TERMINALS_CLASS = 'jp-RunningSessions-terminalShutdownAll'; | ||
/** | ||
* The class name added to a shutdown all sessions button. | ||
*/ | ||
const SHUTDOWN_SESSIONS_CLASS = 'jp-RunningSessions-sessionShutdownAll'; | ||
/** | ||
* The class name added to the running terminal sessions section. | ||
@@ -41,10 +41,2 @@ */ | ||
/** | ||
* The class name added to the running terminal sessions section. | ||
*/ | ||
const TERMINALS_CLASS = 'jp-RunningSessions-terminalSection'; | ||
/** | ||
* The class name added to the running kernel sessions section. | ||
*/ | ||
const SESSIONS_CLASS = 'jp-RunningSessions-sessionsSection'; | ||
/** | ||
* The class name added to the running sessions section header. | ||
@@ -93,3 +85,77 @@ */ | ||
const TERMINAL_ICON_CLASS = 'jp-mod-terminal'; | ||
function Item(props) { | ||
const { model } = props; | ||
return (React.createElement("li", { className: ITEM_CLASS, onClick: () => props.openRequested.emit(model) }, | ||
React.createElement("span", { className: `${ITEM_ICON_CLASS} ${props.iconClass(model)}` }), | ||
React.createElement("span", { className: ITEM_LABEL_CLASS, title: props.labelTitle ? props.labelTitle(model) : '' }, props.label(model)), | ||
React.createElement("button", { className: `${SHUTDOWN_BUTTON_CLASS} jp-mod-styled`, onClick: () => props.shutdown(model) }, "SHUTDOWN"))); | ||
} | ||
class List extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { models: [] }; | ||
} | ||
render() { | ||
return (React.createElement("ul", { className: LIST_CLASS }, this.state.models.map((m, i) => (React.createElement(Item, Object.assign({ key: i, model: m }, this.props)))))); | ||
} | ||
componentDidMount() { | ||
if (this.props.available) { | ||
this.props.manager.runningChanged.connect((_, models) => this.setState({ | ||
models: models.filter(this.props.filterRunning || (_ => true)) | ||
})); | ||
} | ||
} | ||
} | ||
/** | ||
* The Section component contains the shared look and feel for an interactive list of kernels and sessions. | ||
* | ||
* It is specialized for each based on it's props. | ||
*/ | ||
function Section(props) { | ||
function onShutdown() { | ||
apputils_1.showDialog({ | ||
title: `Shutdown All ${props.name} Sessions?`, | ||
buttons: [apputils_1.Dialog.cancelButton(), apputils_1.Dialog.warnButton({ label: 'SHUTDOWN' })] | ||
}).then(result => { | ||
if (result.button.accept) { | ||
props.manager.shutdownAll(); | ||
} | ||
}); | ||
} | ||
return (React.createElement("div", { className: SECTION_CLASS }, props.available && (React.createElement(React.Fragment, null, | ||
React.createElement("div", { className: SECTION_HEADER_CLASS }, | ||
props.name, | ||
" Sessions", | ||
React.createElement("button", { title: `Shutdown All ${props.name} Sessions…`, className: SHUTDOWN_CLASS, onClick: onShutdown })), | ||
React.createElement("div", { className: CONTAINER_CLASS }, | ||
React.createElement(List, Object.assign({}, props))))))); | ||
} | ||
function RunningSessionsComponent({ manager, sessionOpenRequested, terminalOpenRequested }) { | ||
const terminalsAvailable = manager.terminals.isAvailable(); | ||
return (React.createElement(React.Fragment, null, | ||
React.createElement("div", { className: HEADER_CLASS }, | ||
React.createElement("button", { title: "Refresh List", className: REFRESH_CLASS, onClick: () => { | ||
if (terminalsAvailable) { | ||
manager.terminals.refreshRunning(); | ||
} | ||
manager.sessions.refreshRunning(); | ||
} })), | ||
React.createElement(Section, { openRequested: terminalOpenRequested, manager: manager.terminals, name: "Terminal", iconClass: () => `${ITEM_ICON_CLASS} ${TERMINAL_ICON_CLASS}`, label: m => `terminals/${m.name}`, available: terminalsAvailable, shutdown: m => manager.terminals.shutdown(m.name) }), | ||
React.createElement(Section, { openRequested: sessionOpenRequested, manager: manager.sessions, filterRunning: m => !!((m.name || coreutils_1.PathExt.basename(m.path)).indexOf('.') !== -1 || m.name), name: "Kernel", iconClass: m => { | ||
if ((m.name || coreutils_1.PathExt.basename(m.path)).indexOf('.ipynb') !== -1) { | ||
return NOTEBOOK_ICON_CLASS; | ||
} | ||
else if (m.type.toLowerCase() === 'console') { | ||
return CONSOLE_ICON_CLASS; | ||
} | ||
return FILE_ICON_CLASS; | ||
}, label: m => m.name || coreutils_1.PathExt.basename(m.path), available: true, labelTitle: m => { | ||
let kernelName = m.kernel.name; | ||
if (manager.specs) { | ||
kernelName = manager.specs.kernelspecs[kernelName].display_name; | ||
} | ||
return `Path: ${m.path}\nKernel: ${kernelName}`; | ||
}, shutdown: m => manager.sessions.shutdown(m.id) }))); | ||
} | ||
/** | ||
* A class that exposes the running terminal and kernel sessions. | ||
@@ -102,40 +168,19 @@ */ | ||
constructor(options) { | ||
super({ | ||
node: (options.renderer || RunningSessions.defaultRenderer).createNode() | ||
}); | ||
this._runningSessions = []; | ||
this._runningTerminals = []; | ||
this._refreshId = -1; | ||
super(); | ||
this._sessionOpenRequested = new signaling_1.Signal(this); | ||
this._terminalOpenRequested = new signaling_1.Signal(this); | ||
let manager = (this._manager = options.manager); | ||
this._renderer = options.renderer || RunningSessions.defaultRenderer; | ||
this.options = options; | ||
// this can't be in the react element, because then it would be too nested | ||
this.addClass(RUNNING_CLASS); | ||
// Populate the terminals section. | ||
if (manager.terminals.isAvailable()) { | ||
let termNode = apputils_1.DOMUtils.findElement(this.node, TERMINALS_CLASS); | ||
let termHeader = this._renderer.createTerminalHeaderNode(); | ||
termHeader.className = SECTION_HEADER_CLASS; | ||
termNode.appendChild(termHeader); | ||
let termContainer = document.createElement('div'); | ||
termContainer.className = CONTAINER_CLASS; | ||
let termList = document.createElement('ul'); | ||
termList.className = LIST_CLASS; | ||
termContainer.appendChild(termList); | ||
termNode.appendChild(termContainer); | ||
manager.terminals.runningChanged.connect(this._onTerminalsChanged, this); | ||
} | ||
// Populate the sessions section. | ||
let sessionNode = apputils_1.DOMUtils.findElement(this.node, SESSIONS_CLASS); | ||
let sessionHeader = this._renderer.createSessionHeaderNode(); | ||
sessionHeader.className = SECTION_HEADER_CLASS; | ||
sessionNode.appendChild(sessionHeader); | ||
let sessionContainer = document.createElement('div'); | ||
sessionContainer.className = CONTAINER_CLASS; | ||
let sessionList = document.createElement('ul'); | ||
sessionList.className = LIST_CLASS; | ||
sessionContainer.appendChild(sessionList); | ||
sessionNode.appendChild(sessionContainer); | ||
manager.sessions.runningChanged.connect(this._onSessionsChanged, this); | ||
} | ||
onUpdateRequest(msg) { | ||
ReactDOM.render(React.createElement(RunningSessionsComponent, { manager: this.options.manager, sessionOpenRequested: this._sessionOpenRequested, terminalOpenRequested: this._terminalOpenRequested }), this.node); | ||
} | ||
/* Called after the widget is attached to the DOM | ||
* | ||
* Make sure the widget is rendered, even if the model has not changed. | ||
*/ | ||
onAfterAttach(msg) { | ||
this.update(); | ||
} | ||
/** | ||
@@ -153,382 +198,4 @@ * A signal emitted when a kernel session open is requested. | ||
} | ||
/** | ||
* The renderer used by the running sessions widget. | ||
*/ | ||
get renderer() { | ||
return this._renderer; | ||
} | ||
/** | ||
* Refresh the widget. | ||
*/ | ||
refresh() { | ||
let terminals = this._manager.terminals; | ||
let sessions = this._manager.sessions; | ||
clearTimeout(this._refreshId); | ||
let promises = []; | ||
if (terminals.isAvailable()) { | ||
promises.push(terminals.refreshRunning()); | ||
} | ||
promises.push(sessions.refreshRunning()); | ||
return Promise.all(promises).then(() => void 0); | ||
} | ||
/** | ||
* Handle the DOM events for the widget. | ||
* | ||
* @param event - The DOM event sent to the widget. | ||
* | ||
* #### Notes | ||
* This method implements the DOM `EventListener` interface and is | ||
* called in response to events on the widget's DOM nodes. It should | ||
* not be called directly by user code. | ||
*/ | ||
handleEvent(event) { | ||
if (event.type === 'click') { | ||
this._evtClick(event); | ||
} | ||
} | ||
/** | ||
* A message handler invoked on an `'after-attach'` message. | ||
*/ | ||
onAfterAttach(msg) { | ||
this.node.addEventListener('click', this); | ||
} | ||
/** | ||
* A message handler invoked on a `'before-detach'` message. | ||
*/ | ||
onBeforeDetach(msg) { | ||
this.node.removeEventListener('click', this); | ||
} | ||
/** | ||
* A message handler invoked on an `'update-request'` message. | ||
*/ | ||
onUpdateRequest(msg) { | ||
// Fetch common variables. | ||
let termSection = apputils_1.DOMUtils.findElement(this.node, TERMINALS_CLASS); | ||
let termList = apputils_1.DOMUtils.findElement(termSection, LIST_CLASS); | ||
let sessionSection = apputils_1.DOMUtils.findElement(this.node, SESSIONS_CLASS); | ||
let sessionList = apputils_1.DOMUtils.findElement(sessionSection, LIST_CLASS); | ||
let renderer = this._renderer; | ||
let specs = this._manager.specs; | ||
// Create a dummy div if terminals are not available. | ||
termList = termList || document.createElement('div'); | ||
// Remove any excess item nodes. | ||
while (termList.children.length > this._runningTerminals.length) { | ||
termList.removeChild(termList.firstChild); | ||
} | ||
while (sessionList.children.length > this._runningSessions.length) { | ||
sessionList.removeChild(sessionList.firstChild); | ||
} | ||
// Add any missing item nodes. | ||
while (termList.children.length < this._runningTerminals.length) { | ||
let node = renderer.createTerminalNode(); | ||
node.classList.add(ITEM_CLASS); | ||
termList.appendChild(node); | ||
} | ||
while (sessionList.children.length < this._runningSessions.length) { | ||
let node = renderer.createSessionNode(); | ||
node.classList.add(ITEM_CLASS); | ||
sessionList.appendChild(node); | ||
} | ||
// Populate the nodes. | ||
for (let i = 0; i < this._runningTerminals.length; i++) { | ||
let node = termList.children[i]; | ||
renderer.updateTerminalNode(node, this._runningTerminals[i]); | ||
} | ||
for (let i = 0; i < this._runningSessions.length; i++) { | ||
let node = sessionList.children[i]; | ||
let model = this._runningSessions[i]; | ||
let kernelName = model.kernel.name; | ||
if (specs) { | ||
kernelName = specs.kernelspecs[kernelName].display_name; | ||
} | ||
renderer.updateSessionNode(node, model, kernelName); | ||
} | ||
} | ||
/** | ||
* Handle the `'click'` event for the widget. | ||
* | ||
* #### Notes | ||
* This listener is attached to the document node. | ||
*/ | ||
_evtClick(event) { | ||
// Fetch common variables. | ||
let termSection = apputils_1.DOMUtils.findElement(this.node, TERMINALS_CLASS); | ||
let termList = apputils_1.DOMUtils.findElement(termSection, LIST_CLASS); | ||
let sessionSection = apputils_1.DOMUtils.findElement(this.node, SESSIONS_CLASS); | ||
let sessionList = apputils_1.DOMUtils.findElement(sessionSection, LIST_CLASS); | ||
let refresh = apputils_1.DOMUtils.findElement(this.node, REFRESH_CLASS); | ||
let shutdownTerms = apputils_1.DOMUtils.findElement(this.node, SHUTDOWN_TERMINALS_CLASS); | ||
let shutdownSessions = apputils_1.DOMUtils.findElement(this.node, SHUTDOWN_SESSIONS_CLASS); | ||
let renderer = this._renderer; | ||
let clientX = event.clientX; | ||
let clientY = event.clientY; | ||
// Check for a refresh. | ||
if (domutils_1.ElementExt.hitTest(refresh, clientX, clientY)) { | ||
this.refresh(); | ||
return; | ||
} | ||
// Check for terminals shutdown. | ||
// Terminals might be disabled, check node exist first. | ||
if (shutdownTerms && domutils_1.ElementExt.hitTest(shutdownTerms, clientX, clientY)) { | ||
apputils_1.showDialog({ | ||
title: 'Shutdown All Terminals?', | ||
body: 'Shut down all terminals?', | ||
buttons: [ | ||
apputils_1.Dialog.cancelButton(), | ||
apputils_1.Dialog.warnButton({ label: 'SHUTDOWN' }) | ||
] | ||
}).then(result => { | ||
if (result.button.accept) { | ||
this._manager.terminals.shutdownAll(); | ||
} | ||
}); | ||
} | ||
// Check for sessions shutdown. | ||
if (domutils_1.ElementExt.hitTest(shutdownSessions, clientX, clientY)) { | ||
apputils_1.showDialog({ | ||
title: 'Shutdown All Sessions?', | ||
body: 'Shut down all sessions?', | ||
buttons: [ | ||
apputils_1.Dialog.cancelButton(), | ||
apputils_1.Dialog.warnButton({ label: 'SHUTDOWN' }) | ||
] | ||
}).then(result => { | ||
if (result.button.accept) { | ||
this._manager.sessions.shutdownAll(); | ||
} | ||
}); | ||
} | ||
// Create a dummy div if terminals are not available. | ||
termList = termList || document.createElement('div'); | ||
// Check for a terminal item click. | ||
let index = apputils_1.DOMUtils.hitTestNodes(termList.children, clientX, clientY); | ||
if (index !== -1) { | ||
let node = termList.children[index]; | ||
let shutdown = renderer.getTerminalShutdown(node); | ||
let model = this._runningTerminals[index]; | ||
if (domutils_1.ElementExt.hitTest(shutdown, clientX, clientY)) { | ||
this._manager.terminals.shutdown(model.name); | ||
return; | ||
} | ||
this._terminalOpenRequested.emit(model); | ||
} | ||
// Check for a session item click. | ||
index = apputils_1.DOMUtils.hitTestNodes(sessionList.children, clientX, clientY); | ||
if (index !== -1) { | ||
let node = sessionList.children[index]; | ||
let shutdown = renderer.getSessionShutdown(node); | ||
let model = this._runningSessions[index]; | ||
if (domutils_1.ElementExt.hitTest(shutdown, clientX, clientY)) { | ||
this._manager.sessions.shutdown(model.id); | ||
return; | ||
} | ||
this._sessionOpenRequested.emit(model); | ||
} | ||
} | ||
/** | ||
* Handle a change to the running sessions. | ||
*/ | ||
_onSessionsChanged(sender, models) { | ||
// Strip out non-file backed sessions. | ||
this._runningSessions = []; | ||
for (let session of models) { | ||
let name = session.name || coreutils_1.PathExt.basename(session.path); | ||
if (name.indexOf('.') !== -1 || session.name) { | ||
this._runningSessions.push(session); | ||
} | ||
} | ||
this.update(); | ||
} | ||
/** | ||
* Handle a change to the running terminals. | ||
*/ | ||
_onTerminalsChanged(sender, models) { | ||
this._runningTerminals = models; | ||
this.update(); | ||
} | ||
} | ||
exports.RunningSessions = RunningSessions; | ||
/** | ||
* The namespace for the `RunningSessions` class statics. | ||
*/ | ||
(function (RunningSessions) { | ||
/** | ||
* The default implementation of `IRenderer`. | ||
*/ | ||
class Renderer { | ||
/** | ||
* Create the root node for the running sessions widget. | ||
*/ | ||
createNode() { | ||
let node = document.createElement('div'); | ||
let header = document.createElement('div'); | ||
header.className = HEADER_CLASS; | ||
let terminals = document.createElement('div'); | ||
terminals.className = `${SECTION_CLASS} ${TERMINALS_CLASS}`; | ||
let sessions = document.createElement('div'); | ||
sessions.className = `${SECTION_CLASS} ${SESSIONS_CLASS}`; | ||
let refresh = document.createElement('button'); | ||
refresh.title = 'Refresh List'; | ||
refresh.className = REFRESH_CLASS; | ||
header.appendChild(refresh); | ||
node.appendChild(header); | ||
node.appendChild(terminals); | ||
node.appendChild(sessions); | ||
return node; | ||
} | ||
/** | ||
* Create a fully populated header node for the terminals section. | ||
* | ||
* @returns A new node for a running terminal session header. | ||
*/ | ||
createTerminalHeaderNode() { | ||
let node = document.createElement('div'); | ||
node.textContent = 'Terminal Sessions'; | ||
let shutdown = document.createElement('button'); | ||
shutdown.title = 'Shutdown All Terminal Sessions…'; | ||
shutdown.className = `${SHUTDOWN_CLASS} ${SHUTDOWN_TERMINALS_CLASS}`; | ||
node.appendChild(shutdown); | ||
return node; | ||
} | ||
/** | ||
* Create a fully populated header node for the sessions section. | ||
* | ||
* @returns A new node for a running kernel session header. | ||
*/ | ||
createSessionHeaderNode() { | ||
let node = document.createElement('div'); | ||
node.textContent = 'Kernel Sessions'; | ||
let shutdown = document.createElement('button'); | ||
shutdown.title = 'Shutdown All Kernel Sessions…'; | ||
shutdown.className = `${SHUTDOWN_CLASS} ${SHUTDOWN_SESSIONS_CLASS}`; | ||
node.appendChild(shutdown); | ||
return node; | ||
} | ||
/** | ||
* Create a node for a running terminal session item. | ||
* | ||
* @returns A new node for a running terminal session item. | ||
* | ||
* #### Notes | ||
* The data in the node should be uninitialized. | ||
* | ||
* The `updateTerminalNode` method will be called for initialization. | ||
*/ | ||
createTerminalNode() { | ||
let node = document.createElement('li'); | ||
let icon = document.createElement('span'); | ||
icon.className = `${ITEM_ICON_CLASS} ${TERMINAL_ICON_CLASS}`; | ||
let label = document.createElement('span'); | ||
label.className = ITEM_LABEL_CLASS; | ||
let shutdown = document.createElement('button'); | ||
shutdown.className = `${SHUTDOWN_BUTTON_CLASS} jp-mod-styled`; | ||
shutdown.textContent = 'SHUTDOWN'; | ||
node.appendChild(icon); | ||
node.appendChild(label); | ||
node.appendChild(shutdown); | ||
return node; | ||
} | ||
/** | ||
* Create a node for a running kernel session item. | ||
* | ||
* @returns A new node for a running kernel session item. | ||
* | ||
* #### Notes | ||
* The data in the node should be uninitialized. | ||
* | ||
* The `updateSessionNode` method will be called for initialization. | ||
*/ | ||
createSessionNode() { | ||
let node = document.createElement('li'); | ||
let icon = document.createElement('span'); | ||
icon.className = ITEM_ICON_CLASS; | ||
let label = document.createElement('span'); | ||
label.className = ITEM_LABEL_CLASS; | ||
let shutdown = document.createElement('button'); | ||
shutdown.className = `${SHUTDOWN_BUTTON_CLASS} jp-mod-styled`; | ||
shutdown.textContent = 'SHUTDOWN'; | ||
node.appendChild(icon); | ||
node.appendChild(label); | ||
node.appendChild(shutdown); | ||
return node; | ||
} | ||
/** | ||
* Get the shutdown node for a terminal node. | ||
* | ||
* @param node - A node created by a call to `createTerminalNode`. | ||
* | ||
* @returns The node representing the shutdown option. | ||
* | ||
* #### Notes | ||
* A click on this node is considered a shutdown request. | ||
* A click anywhere else on the node is considered an open request. | ||
*/ | ||
getTerminalShutdown(node) { | ||
return apputils_1.DOMUtils.findElement(node, SHUTDOWN_BUTTON_CLASS); | ||
} | ||
/** | ||
* Get the shutdown node for a session node. | ||
* | ||
* @param node - A node created by a call to `createSessionNode`. | ||
* | ||
* @returns The node representing the shutdown option. | ||
* | ||
* #### Notes | ||
* A click on this node is considered a shutdown request. | ||
* A click anywhere else on the node is considered an open request. | ||
*/ | ||
getSessionShutdown(node) { | ||
return apputils_1.DOMUtils.findElement(node, SHUTDOWN_BUTTON_CLASS); | ||
} | ||
/** | ||
* Populate a node with running terminal session data. | ||
* | ||
* @param node - A node created by a call to `createTerminalNode`. | ||
* | ||
* @param models - The list of terminal session models. | ||
* | ||
* #### Notes | ||
* This method should completely reset the state of the node to | ||
* reflect the data for the session models. | ||
*/ | ||
updateTerminalNode(node, model) { | ||
let label = apputils_1.DOMUtils.findElement(node, ITEM_LABEL_CLASS); | ||
label.textContent = `terminals/${model.name}`; | ||
} | ||
/** | ||
* Populate a node with running kernel session data. | ||
* | ||
* @param node - A node created by a call to `createSessionNode`. | ||
* | ||
* @param models - The list of kernel session models. | ||
* | ||
* @param kernelName - The kernel display name. | ||
* | ||
* #### Notes | ||
* This method should completely reset the state of the node to | ||
* reflect the data for the session models. | ||
*/ | ||
updateSessionNode(node, model, kernelName) { | ||
let icon = apputils_1.DOMUtils.findElement(node, ITEM_ICON_CLASS); | ||
let name = model.name || coreutils_1.PathExt.basename(model.path); | ||
if (name.indexOf('.ipynb') !== -1) { | ||
icon.className = `${ITEM_ICON_CLASS} ${NOTEBOOK_ICON_CLASS}`; | ||
} | ||
else if (model.type.toLowerCase() === 'console') { | ||
icon.className = `${ITEM_ICON_CLASS} ${CONSOLE_ICON_CLASS}`; | ||
} | ||
else { | ||
icon.className = `${ITEM_ICON_CLASS} ${FILE_ICON_CLASS}`; | ||
} | ||
let label = apputils_1.DOMUtils.findElement(node, ITEM_LABEL_CLASS); | ||
label.textContent = name; | ||
let title = `Path: ${model.path}\n` + `Kernel: ${kernelName}`; | ||
label.title = title; | ||
} | ||
} | ||
RunningSessions.Renderer = Renderer; | ||
/** | ||
* The default `Renderer` instance. | ||
*/ | ||
RunningSessions.defaultRenderer = new Renderer(); | ||
})(RunningSessions = exports.RunningSessions || (exports.RunningSessions = {})); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@jupyterlab/running", | ||
"version": "0.17.0-1", | ||
"version": "0.17.1", | ||
"description": "JupyterLab - Running Sessions Panel", | ||
@@ -33,9 +33,10 @@ "homepage": "https://github.com/jupyterlab/jupyterlab", | ||
"dependencies": { | ||
"@jupyterlab/apputils": "^0.17.0-1", | ||
"@jupyterlab/coreutils": "^2.0.0-1", | ||
"@jupyterlab/services": "^3.0.0-1", | ||
"@phosphor/domutils": "^1.1.2", | ||
"@jupyterlab/apputils": "^0.17.1", | ||
"@jupyterlab/coreutils": "^2.0.1", | ||
"@jupyterlab/services": "^3.0.1", | ||
"@phosphor/messaging": "^1.2.2", | ||
"@phosphor/signaling": "^1.2.2", | ||
"@phosphor/widgets": "^1.6.0" | ||
"@phosphor/widgets": "^1.6.0", | ||
"react": "~16.4.0", | ||
"react-dom": "~16.4.0" | ||
}, | ||
@@ -42,0 +43,0 @@ "devDependencies": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
30858
8
404
1
3
7
0
49
+ Addedreact@~16.4.0
+ Addedreact-dom@~16.4.0
- Removed@phosphor/domutils@^1.1.2
Updated@jupyterlab/apputils@^0.17.1
Updated@jupyterlab/coreutils@^2.0.1
Updated@jupyterlab/services@^3.0.1