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, { spacing: HALF_SPACING, onClick: props.handleClick },
|
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.translator = opts.translator || nullTranslator;
|
39 | this._trans = this.translator.load('jupyterlab');
|
40 | this._serviceManager.sessions.runningChanged.connect(this._onSessionsRunningChanged, this);
|
41 | this._serviceManager.terminals.runningChanged.connect(this._onTerminalsRunningChanged, this);
|
42 | this.addClass('jp-mod-highlighted');
|
43 | }
|
44 | |
45 |
|
46 |
|
47 | render() {
|
48 | if (!this.model) {
|
49 | return null;
|
50 | }
|
51 |
|
52 |
|
53 | this.title.caption = this._trans.__('%1 Terminals, %2 Kernel sessions', this.model.terminals, this.model.sessions);
|
54 | return (React.createElement(RunningSessionsComponent, { sessions: this.model.sessions, terminals: this.model.terminals, handleClick: this._handleClick }));
|
55 | }
|
56 | |
57 |
|
58 |
|
59 | dispose() {
|
60 | super.dispose();
|
61 | this._serviceManager.sessions.runningChanged.disconnect(this._onSessionsRunningChanged, this);
|
62 | this._serviceManager.terminals.runningChanged.disconnect(this._onTerminalsRunningChanged, this);
|
63 | }
|
64 | |
65 |
|
66 |
|
67 | _onSessionsRunningChanged(manager, sessions) {
|
68 | this.model.sessions = sessions.length;
|
69 | }
|
70 | |
71 |
|
72 |
|
73 | _onTerminalsRunningChanged(manager, terminals) {
|
74 | this.model.terminals = terminals.length;
|
75 | }
|
76 | }
|
77 |
|
78 |
|
79 |
|
80 | (function (RunningSessions) {
|
81 | |
82 |
|
83 |
|
84 | class Model extends VDomModel {
|
85 | constructor() {
|
86 | super(...arguments);
|
87 | this._terminals = 0;
|
88 | this._sessions = 0;
|
89 | }
|
90 | |
91 |
|
92 |
|
93 | get sessions() {
|
94 | return this._sessions;
|
95 | }
|
96 | set sessions(sessions) {
|
97 | const oldSessions = this._sessions;
|
98 | this._sessions = sessions;
|
99 | if (oldSessions !== this._sessions) {
|
100 | this.stateChanged.emit(void 0);
|
101 | }
|
102 | }
|
103 | |
104 |
|
105 |
|
106 | get terminals() {
|
107 | return this._terminals;
|
108 | }
|
109 | set terminals(terminals) {
|
110 | const oldTerminals = this._terminals;
|
111 | this._terminals = terminals;
|
112 | if (oldTerminals !== this._terminals) {
|
113 | this.stateChanged.emit(void 0);
|
114 | }
|
115 | }
|
116 | }
|
117 | RunningSessions.Model = Model;
|
118 | })(RunningSessions || (RunningSessions = {}));
|
119 |
|
\ | No newline at end of file |