Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ready to push up for PR #60

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/components/Endpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ const Endpoint = (props) => {

if (apiError) {
return (
<>
<button className='btn btn-sm btn-primary mb-4 mt-5' onClick={() => history.goBack()}>
Back
</button>
<p className='fw-bold mt-3 text-danger'>Error: {apiError['error']}. Please try again.</p>
</>
<div id='api-error' className='alert alert-danger'>
<strong>
Error {apiError.response.status}: {apiError.response.statusText}.
</strong>{' '}
Please try again.
</div>
);
}

Expand Down
9 changes: 8 additions & 1 deletion src/components/EndpointSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ const EndpointSearch = (props) => {
};

if (apiError) {
return <p className='fw-bold text-danger'>Error: {apiError['error']}. Please try again.</p>;
return (
<div id='api-error' className='alert alert-danger'>
<strong>
Error {apiError.response.status}: {apiError.response.statusText}.
</strong>{' '}
Please try again.
</div>
);
}

if (loading) {
Expand Down
24 changes: 10 additions & 14 deletions src/components/HubLoginWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,27 @@ const HubLogin = (props) => {
event.preventDefault();

try {
console.log(hubInputCode);
let response = await requestAPI<any>(`oauth_callback_manual?code=${hubInputCode}`);
console.log(response);
} catch (error) {
setAPIError(error);
}
};

if (apiError) {
return (
<>
<button className='btn btn-sm btn-primary mb-3 mt-5' onClick={() => window.location.href = '/' }>
Back
</button>
<p className='fw-bold text-danger'>
Error {apiError.response.status}: {apiError.response.statusText}. Please try again.
</p>
</>
);
}

return (
<div className='container mt-5'>
<div className='row'>
<div className='col-8'>

{apiError && (
<div id='api-error' className='alert alert-danger'>
<strong>
Error {apiError.response.status}: {apiError.response.statusText}.
</strong>{' '}
Please try again.
</div>
)}

<label htmlFor='code-input' className='form-label'>
Paste Code and Click Login
</label>
Expand Down
98 changes: 50 additions & 48 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application'
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
import { MainAreaWidget } from '@jupyterlab/apputils';
import { PageConfig } from '@jupyterlab/coreutils';
import { reactIcon } from '@jupyterlab/ui-components';

import { getBaseURL, GlobusIcon } from './utilities';
import { GlobusWidget } from './widget';
Expand All @@ -11,57 +10,13 @@ import { requestAPI } from './handler';

import '../style/index.css';

const addJupyterCommands = (app: JupyterFrontEnd, factory: IFileBrowserFactory, commands: Array<any>) => {
const addJupyterCommands = (app: JupyterFrontEnd, commands: Array<any>) => {
for (let command of commands) {
app.commands.addCommand(command.command, {
label: command.label,
caption: command.caption,
icon: GlobusIcon,
execute: async () => {
var files = factory.tracker.currentWidget.selectedItems();
var jupyterToken = PageConfig.getToken();
var label = 'Globus Jupyterlab Transfer';

let jupyterItems = [],
fileCheck = true;
while (fileCheck) {
let file = files.next();
if (file) {
jupyterItems.push(file);
} else {
fileCheck = false;
}
}

// GET config payload which contains basic auth data
const config = await requestAPI<any>('config');

// Start creating the widget, but don't attach unless authenticated
const content = new GlobusWidget(config, jupyterToken, jupyterItems);
const widget = new MainAreaWidget<GlobusWidget>({ content });
widget.title.label = label;
widget.title.icon = reactIcon;

if (config.is_logged_in) {
app.shell.add(widget, 'main');
} else {
if (config.is_hub) {
const hubContent = new HubLoginWidget();
const hubWidget = new MainAreaWidget<HubLoginWidget>({ content: hubContent });
app.shell.add(hubWidget, 'main');
}

// Poll for successful authentication.
let authInterval = window.setInterval(async () => {
const config = await requestAPI<any>('config');
if (config.is_logged_in) {
app.shell.add(widget, 'main');
clearInterval(authInterval);
}
}, 1000);
window.open(getBaseURL('globus-jupyterlab/login'), 'Globus Login', 'height=600,width=800').focus();
}
},
execute: command.execute
});
}
};
Expand Down Expand Up @@ -92,9 +47,56 @@ async function activateGlobus(app: JupyterFrontEnd, factory: IFileBrowserFactory
command: 'globus-jupyterlab-transfer/context-menu:open',
label: 'Initiate Globus Transfer',
caption: 'Login with Globus to initiate transfers',
execute: async () => {
var files = factory.tracker.currentWidget.selectedItems();
var jupyterToken = PageConfig.getToken();
var label = 'Globus Jupyterlab Transfer';

let jupyterItems = [],
fileCheck = true;
while (fileCheck) {
let file = files.next();
if (file) {
jupyterItems.push(file);
} else {
fileCheck = false;
}
}

// GET config payload which contains basic auth data
const config = await requestAPI<any>('config');

// Start creating the widget, but don't attach unless authenticated
const content = new GlobusWidget(config, jupyterToken, jupyterItems);
const widget = new MainAreaWidget<GlobusWidget>({ content });
widget.title.label = label;
widget.title.icon = GlobusIcon;

if (config.is_logged_in) {
app.shell.add(widget, 'main');
} else {
if (config.is_hub) {
const hubContent = new HubLoginWidget();
const hubWidget = new MainAreaWidget<HubLoginWidget>({ content: hubContent });
hubWidget.title.label = 'Authorization Code';
hubWidget.title.icon = GlobusIcon;
app.shell.add(hubWidget, 'main');
}

// Poll for successful authentication.
let authInterval = window.setInterval(async () => {
const config = await requestAPI<any>('config');
if (config.is_logged_in) {
app.shell.add(widget, 'main');
clearInterval(authInterval);
}
}, 1000);
window.open(getBaseURL('globus-jupyterlab/login'), 'Globus Login', 'height=600,width=800').focus();
}
}
},
];
addJupyterCommands(app, factory, commands);
addJupyterCommands(app, commands);
} catch (reason) {
console.error(`Error on GET /globus_jupyterlab/config.\n${reason}`);
}
Expand Down