-
Notifications
You must be signed in to change notification settings - Fork 11
/
ProfilePanel.ts
76 lines (63 loc) · 2.29 KB
/
ProfilePanel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { StackedPanel } from '@lumino/widgets';
import type { ISessionContext } from '@jupyterlab/apputils';
import type { Message } from '@lumino/messaging';
import type { NotebookAPI } from './dataAPI/jupyter/notebook';
import { ProfileModel } from './dataAPI/ProfileModel';
import { ProfileView } from './components/ProfileView';
import { LabIcon } from '@jupyterlab/ui-components';
import appIconStr from '../style/logo.svg';
export class ProfilePanel extends StackedPanel {
constructor() {
super();
this.addClass('auto-profile-wrapper');
this.id = 'auto-profile-app';
this.title.caption = 'Autoprofiler'; // shown on hover
this.title.iconClass = 'autoprofile-logo';
const icon = new LabIcon({
name: 'auto-profile-app:app-icon',
svgstr: appIconStr
});
this.title.icon = icon;
// MODEL init
this._profileModel = new ProfileModel(this._sessionContext);
// VIEW init
this._profileView = new ProfileView(this._profileModel);
this.addWidget(this._profileView);
}
// ~~~~~~~~~ Variables, getters, setters ~~~~~~~~~
private _sessionContext: ISessionContext;
private _profileModel: ProfileModel;
private _profileView: ProfileView;
get session(): ISessionContext {
return this._sessionContext;
}
set session(session: ISessionContext) {
this._sessionContext = session;
}
public async connectNotebook(notebook: NotebookAPI) {
if (notebook.hasConnection) {
this.session = notebook.panel.sessionContext;
}
await this._profileModel.connectNotebook(notebook, () => { return this.isVisible });
}
// ~~~~~~~~~ Lifecycle methods for closing panel ~~~~~~~~~
dispose(): void {
this._sessionContext.dispose();
super.dispose();
}
protected onCloseRequest(msg: Message): void {
super.onCloseRequest(msg);
this.dispose();
}
/**
* Called before the widget is made visible.
* NOTE: when using beforeShow, this.isVisible is false during update.
*
* other useful state messages are onAfterShow,
* onBeforeHide, onAfterHide.
* @param msg
*/
protected onBeforeShow(msg: Message): void {
this._profileModel.updateAll();
}
}