Compare commits
19 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
960341f6a7 | ||
![]() |
819684f29b | ||
![]() |
2421e1b6bc | ||
![]() |
54e6560285 | ||
![]() |
11014c81ba | ||
![]() |
63080b1ddb | ||
![]() |
7713b49329 | ||
![]() |
146b4c07b3 | ||
![]() |
ff17f23784 | ||
![]() |
b4a2a5909f | ||
![]() |
6c3da63c33 | ||
![]() |
00eb4f80bc | ||
![]() |
f14dfab46d | ||
![]() |
4d09c983f4 | ||
![]() |
e654a1bc43 | ||
![]() |
2047ef6685 | ||
![]() |
c0f54ee64b | ||
![]() |
b2b4b2d437 | ||
![]() |
136b6b0a88 |
10 changed files with 84 additions and 27 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -161,3 +161,5 @@ ENV/
|
|||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
|
||||
.DS_Store
|
3
MANIFEST.in
Normal file
3
MANIFEST.in
Normal file
|
@ -0,0 +1,3 @@
|
|||
recursive-include jupyterlab_templates/templates/ *
|
||||
include README.md
|
||||
include LICENSE
|
5
Makefile
5
Makefile
|
@ -20,6 +20,9 @@ serverextension: install ## enable serverextension
|
|||
labextension: install ## enable labextension
|
||||
jupyter labextension install .
|
||||
|
||||
dist: ## dist to pypi
|
||||
python3 setup.py sdist upload -r pypi
|
||||
|
||||
# docs: ## make documentation
|
||||
# make -C ./docs html
|
||||
|
||||
|
@ -31,4 +34,4 @@ help:
|
|||
print-%:
|
||||
@echo '$*=$($*)'
|
||||
|
||||
.PHONY: clean install serverextension labextension test tests help docs
|
||||
.PHONY: clean install serverextension labextension test tests help docs dist
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# jupyterlab_iframe
|
||||
Open a site in a widget, or add a set of "quicklinks".
|
||||
|
||||
[](https://pypi.python.org/pypi/jupyterlab_iframe)
|
||||
[](https://pypi.python.org/pypi/jupyterlab_iframe)
|
||||
[](https://www.npmjs.com/package/jupyterlab_iframe)
|
||||
|
@ -18,4 +19,5 @@ install the server extension, and add the following to `jupyter_notebook_config.
|
|||
|
||||
```python3
|
||||
c.JupyterLabIFrame.iframes = ['list', 'of', 'sites']
|
||||
c.JupyterLabIFrame.welcome = 'a site'
|
||||
```
|
||||
|
|
BIN
jupyterlab_iframe/.DS_Store
vendored
BIN
jupyterlab_iframe/.DS_Store
vendored
Binary file not shown.
|
@ -4,11 +4,12 @@ from notebook.utils import url_path_join
|
|||
|
||||
|
||||
class IFrameHandler(IPythonHandler):
|
||||
def initialize(self, iframes=None):
|
||||
self.iframes = iframes
|
||||
def initialize(self, welcome=None, sites=None):
|
||||
self.sites = sites
|
||||
self.welcome = welcome
|
||||
|
||||
def get(self):
|
||||
self.finish(ujson.dumps(self.iframes))
|
||||
self.finish(ujson.dumps({'welcome': self.welcome or '', 'sites': self.sites}))
|
||||
|
||||
|
||||
def load_jupyter_server_extension(nb_server_app):
|
||||
|
@ -19,11 +20,13 @@ def load_jupyter_server_extension(nb_server_app):
|
|||
nb_server_app (NotebookWebApplication): handle to the Notebook webserver instance.
|
||||
"""
|
||||
web_app = nb_server_app.web_app
|
||||
iframes = nb_server_app.config.get('JupyterLabIFrame', {}).get('iframes', [])
|
||||
sites = nb_server_app.config.get('JupyterLabIFrame', {}).get('iframes', [])
|
||||
welcome = nb_server_app.config.get('JupyterLabIFrame', {}).get('welcome', [])
|
||||
|
||||
host_pattern = '.*$'
|
||||
base_url = web_app.settings['base_url']
|
||||
|
||||
print('Installing jupyterlab_iframe handler on path %s' % '/iframes')
|
||||
print('Handinling iframes: %s' % iframes)
|
||||
print('Installing jupyterlab_iframe handler on path %s' % url_path_join(base_url, 'iframes'))
|
||||
print('Handling iframes: %s' % sites)
|
||||
|
||||
web_app.add_handlers(host_pattern, [(url_path_join(base_url, '/iframes'), IFrameHandler, {'iframes': iframes})])
|
||||
web_app.add_handlers(host_pattern, [(url_path_join(base_url, 'iframes'), IFrameHandler, {'welcome': welcome, 'sites': sites})])
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "jupyterlab_iframe",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.4",
|
||||
"description": "A JupyterLab extension.",
|
||||
"author": "Tim Paine",
|
||||
"main": "lib/index.js",
|
||||
|
@ -21,9 +21,10 @@
|
|||
"extension": true
|
||||
},
|
||||
"dependencies": {
|
||||
"@jupyterlab/application": "^0.15.0",
|
||||
"@jupyterlab/apputils": "^0.15.0",
|
||||
"@jupyterlab/docmanager": "^0.15.0",
|
||||
"@jupyterlab/application": "^0.16.0",
|
||||
"@jupyterlab/apputils": "^0.16.0",
|
||||
"@jupyterlab/coreutils": "^1.0.2",
|
||||
"@jupyterlab/docmanager": "^0.16.0",
|
||||
"@phosphor/disposable": "^1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
6
setup.cfg
Normal file
6
setup.cfg
Normal file
|
@ -0,0 +1,6 @@
|
|||
[bdist_wheel]
|
||||
universal=1
|
||||
|
||||
[metadata]
|
||||
description_file = README.md
|
||||
license_file = LICENSE
|
5
setup.py
5
setup.py
|
@ -9,11 +9,11 @@ with open(path.join(here, 'README.md'), encoding='utf-8') as f:
|
|||
|
||||
setup(
|
||||
name='jupyterlab_iframe',
|
||||
version='0.0.2',
|
||||
version='0.0.8',
|
||||
description='IFrame widgets for JupyterLab',
|
||||
long_description=long_description,
|
||||
url='https://github.com/timkpaine/jupyterlab_iframe',
|
||||
download_url='https://github.com/timkpaine/jupyterlab_iframe/archive/v0.0.2.tar.gz',
|
||||
download_url='https://github.com/timkpaine/jupyterlab_iframe/archive/v0.0.8.tar.gz',
|
||||
author='Tim Paine',
|
||||
author_email='t.paine154@gmail.com',
|
||||
license='GPL',
|
||||
|
@ -29,6 +29,7 @@ setup(
|
|||
keywords='jupyter jupyterlab',
|
||||
|
||||
packages=find_packages(exclude=['tests', ]),
|
||||
data_files=[('', ["LICENSE", "README.md"])],
|
||||
zip_safe=False,
|
||||
|
||||
# entry_points={
|
||||
|
|
62
src/index.ts
62
src/index.ts
|
@ -6,6 +6,10 @@ import {
|
|||
ICommandPalette, showDialog, Dialog
|
||||
} from '@jupyterlab/apputils';
|
||||
|
||||
import {
|
||||
PageConfig
|
||||
} from '@jupyterlab/coreutils'
|
||||
|
||||
import {
|
||||
IDocumentManager
|
||||
} from '@jupyterlab/docmanager';
|
||||
|
@ -50,7 +54,7 @@ class OpenIFrameWidget extends Widget {
|
|||
|
||||
let input = document.createElement('input');
|
||||
input.value = '';
|
||||
input.placeholder = 'http://tim.paine.nyc';
|
||||
input.placeholder = 'http://path.to.site';
|
||||
|
||||
body.appendChild(existingLabel);
|
||||
body.appendChild(input);
|
||||
|
@ -67,6 +71,22 @@ class OpenIFrameWidget extends Widget {
|
|||
}
|
||||
}
|
||||
|
||||
function registerSite(app: JupyterLab, palette: ICommandPalette, site: string){
|
||||
let command = 'iframe:open-' + site;
|
||||
|
||||
app.commands.addCommand(command, {
|
||||
label: 'Open ' + site,
|
||||
isEnabled: () => true,
|
||||
execute: () => {
|
||||
let widget = new IFrameWidget(site);
|
||||
app.shell.addToMainArea(widget);
|
||||
app.shell.activateById(widget.id);
|
||||
}
|
||||
});
|
||||
palette.addItem({command: command, category: 'Sites'});
|
||||
}
|
||||
|
||||
|
||||
function activate(app: JupyterLab, docManager: IDocumentManager, palette: ICommandPalette, restorer: ILayoutRestorer) {
|
||||
|
||||
// Declare a widget variable
|
||||
|
@ -88,6 +108,10 @@ function activate(app: JupyterLab, docManager: IDocumentManager, palette: IComma
|
|||
focusNodeSelector: 'input',
|
||||
buttons: [Dialog.cancelButton(), Dialog.okButton({ label: 'GO' })]
|
||||
}).then(result => {
|
||||
if (result.button.label === 'CANCEL') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.value) {
|
||||
return null;
|
||||
}
|
||||
|
@ -109,25 +133,38 @@ function activate(app: JupyterLab, docManager: IDocumentManager, palette: IComma
|
|||
|
||||
// grab sites from serverextension
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "/iframes", true);
|
||||
xhr.open("GET", PageConfig.getBaseUrl() + "iframes", true);
|
||||
xhr.onload = function (e:any) {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
let sites = JSON.parse(xhr.responseText);
|
||||
let jsn = JSON.parse(xhr.responseText);
|
||||
let welcome = jsn['welcome'];
|
||||
let welcome_included = false;
|
||||
|
||||
let sites = jsn['sites'];
|
||||
|
||||
for(let site of sites){
|
||||
console.log('adding quicklink for ' + site);
|
||||
let command = 'iframe:open-' + site;
|
||||
app.commands.addCommand(command, {
|
||||
label: 'Open ' + site,
|
||||
isEnabled: () => true,
|
||||
execute: () => {
|
||||
widget = new IFrameWidget(site);
|
||||
app.shell.addToMainArea(widget);
|
||||
app.shell.activateById(widget.id);
|
||||
|
||||
if (site == welcome){
|
||||
welcome_included = true;
|
||||
}
|
||||
registerSite(app, palette, site);
|
||||
}
|
||||
|
||||
if (!welcome_included) {
|
||||
registerSite(app, palette, welcome);
|
||||
}
|
||||
|
||||
if (welcome) {
|
||||
app.restored.then(() => {
|
||||
if(!localStorage.getItem('jupyterlab_iframe_welcome')) {
|
||||
localStorage.setItem('jupyterlab_iframe_welcome', 'false');
|
||||
app.commands.execute('iframe:open-' + welcome);
|
||||
}
|
||||
});
|
||||
palette.addItem({command: command, category: 'Sites'});
|
||||
}
|
||||
|
||||
} else {
|
||||
console.error(xhr.statusText);
|
||||
}
|
||||
|
@ -141,5 +178,4 @@ function activate(app: JupyterLab, docManager: IDocumentManager, palette: IComma
|
|||
console.log('JupyterLab extension jupyterlab_iframe is activated!');
|
||||
};
|
||||
|
||||
|
||||
export default extension;
|
||||
|
|
Loading…
Add table
Reference in a new issue