1 |
|
2 |
|
3 | import { nullTranslator } from '@jupyterlab/translation';
|
4 | import { kernelIcon, terminalIcon, VDomModel, VDomRenderer } from '@jupyterlab/ui-components';
|
5 | import React from 'react';
|
6 | import { GroupItem, TextItem } from '@jupyterlab/statusbar';
|
7 |
|
8 |
|
9 |
|
10 | const HALF_SPACING = 4;
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function RunningSessionsComponent(props) {
|
19 | return (React.createElement(GroupItem, { tabIndex: 0, spacing: HALF_SPACING, onClick: props.handleClick, onKeyDown: props.handleKeyDown },
|
20 | React.createElement(GroupItem, { spacing: HALF_SPACING },
|
21 | React.createElement(TextItem, { source: props.terminals }),
|
22 | React.createElement(terminalIcon.react, { left: '1px', top: '3px', stylesheet: 'statusBar' })),
|
23 | React.createElement(GroupItem, { spacing: HALF_SPACING },
|
24 | React.createElement(TextItem, { source: props.sessions }),
|
25 | React.createElement(kernelIcon.react, { top: '2px', stylesheet: 'statusBar' }))));
|
26 | }
|
27 |
|
28 |
|
29 |
|
30 | export class RunningSessions extends VDomRenderer {
|
31 | |
32 |
|
33 |
|
34 | constructor(opts) {
|
35 | super(new RunningSessions.Model());
|
36 | this._serviceManager = opts.serviceManager;
|
37 | this._handleClick = opts.onClick;
|
38 | this._handleKeyDown = opts.onKeyDown;
|
39 | this.translator = opts.translator || nullTranslator;
|
40 | this._trans = this.translator.load('jupyterlab');
|
41 | this._serviceManager.sessions.runningChanged.connect(this._onSessionsRunningChanged, this);
|
42 | this._serviceManager.terminals.runningChanged.connect(this._onTerminalsRunningChanged, this);
|
43 | this.addClass('jp-mod-highlighted');
|
44 | }
|
45 | |
46 |
|
47 |
|
48 | render() {
|
49 | if (!this.model) {
|
50 | return null;
|
51 | }
|
52 |
|
53 |
|
54 | this.title.caption = this._trans.__('%1 Terminals, %2 Kernel sessions', this.model.terminals, this.model.sessions);
|
55 | return (React.createElement(RunningSessionsComponent, { sessions: this.model.sessions, terminals: this.model.terminals, handleClick: this._handleClick, handleKeyDown: this._handleKeyDown }));
|
56 | }
|
57 | |
58 |
|
59 |
|
60 | dispose() {
|
61 | super.dispose();
|
62 | this._serviceManager.sessions.runningChanged.disconnect(this._onSessionsRunningChanged, this);
|
63 | this._serviceManager.terminals.runningChanged.disconnect(this._onTerminalsRunningChanged, this);
|
64 | }
|
65 | |
66 |
|
67 |
|
68 | _onSessionsRunningChanged(manager, sessions) {
|
69 | this.model.sessions = sessions.length;
|
70 | }
|
71 | |
72 |
|
73 |
|
74 | _onTerminalsRunningChanged(manager, terminals) {
|
75 | this.model.terminals = terminals.length;
|
76 | }
|
77 | }
|
78 |
|
79 |
|
80 |
|
81 | (function (RunningSessions) {
|
82 | |
83 |
|
84 |
|
85 | class Model extends VDomModel {
|
86 | constructor() {
|
87 | super(...arguments);
|
88 | this._terminals = 0;
|
89 | this._sessions = 0;
|
90 | }
|
91 | |
92 |
|
93 |
|
94 | get sessions() {
|
95 | return this._sessions;
|
96 | }
|
97 | set sessions(sessions) {
|
98 | const oldSessions = this._sessions;
|
99 | this._sessions = sessions;
|
100 | if (oldSessions !== this._sessions) {
|
101 | this.stateChanged.emit(void 0);
|
102 | }
|
103 | }
|
104 | |
105 |
|
106 |
|
107 | get terminals() {
|
108 | return this._terminals;
|
109 | }
|
110 | set terminals(terminals) {
|
111 | const oldTerminals = this._terminals;
|
112 | this._terminals = terminals;
|
113 | if (oldTerminals !== this._terminals) {
|
114 | this.stateChanged.emit(void 0);
|
115 | }
|
116 | }
|
117 | }
|
118 | RunningSessions.Model = Model;
|
119 | })(RunningSessions || (RunningSessions = {}));
|
120 |
|
\ | No newline at end of file |