This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathindex.ts
102 lines (83 loc) · 2.31 KB
/
index.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
Menu
} from '@phosphor/widgets';
import {
ICommandPalette
} from '@jupyterlab/apputils';
import {
JupyterFrontEnd, JupyterFrontEndPlugin
} from '@jupyterlab/application';
import {
PageConfig, URLExt
} from '@jupyterlab/coreutils';
import {
IMainMenu
} from '@jupyterlab/mainmenu';
/**
* The command IDs used by the plugin.
*/
export
namespace CommandIDs {
export
const controlPanel: string = 'hub:control-panel';
export
const logout: string = 'hub:logout';
};
/**
* Activate the jupyterhub extension.
*/
function activateHubExtension(app: JupyterFrontEnd, palette: ICommandPalette, mainMenu: IMainMenu): void {
// This config is provided by JupyterHub to the single-user server app
// in a dictionary: app.web_app.settings['page_config_data'].
let hubHost = PageConfig.getOption('hub_host');
let hubPrefix = PageConfig.getOption('hub_prefix');
let baseUrl = PageConfig.getOption('baseUrl');
if (!hubPrefix) {
console.log('jupyterlab-hub: No configuration found.');
return;
}
console.log('jupyterlab-hub: Found configuration ',
{ hubHost: hubHost, hubPrefix: hubPrefix });
const category = 'Hub';
const { commands } = app;
commands.addCommand(CommandIDs.controlPanel, {
label: 'Control Panel',
caption: 'Open the Hub control panel in a new browser tab',
execute: () => {
window.open(hubHost + URLExt.join(hubPrefix, 'home'), '_blank');
}
});
commands.addCommand(CommandIDs.logout, {
label: 'Logout',
caption: 'Log out of the Hub',
execute: () => {
window.location.href = hubHost + URLExt.join(baseUrl, 'logout');
}
});
// Add commands and menu itmes.
let menu = new Menu({ commands });
menu.title.label = category;
[
CommandIDs.controlPanel,
CommandIDs.logout,
].forEach(command => {
palette.addItem({ command, category });
menu.addItem({ command });
});
mainMenu.addMenu(menu, { rank: 100 });
}
/**
* Initialization data for the jupyterlab_hub extension.
*/
const hubExtension: JupyterFrontEndPlugin<void> = {
activate: activateHubExtension,
id: 'jupyter.extensions.jupyterlab-hub',
requires: [
ICommandPalette,
IMainMenu,
],
autoStart: true,
};
export default hubExtension;