本文整理汇总了TypeScript中@jupyterlab/services.ServerConnection.makeSettings方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ServerConnection.makeSettings方法的具体用法?TypeScript ServerConnection.makeSettings怎么用?TypeScript ServerConnection.makeSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@jupyterlab/services.ServerConnection
的用法示例。
在下文中一共展示了ServerConnection.makeSettings方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: showDialog
}).then(result => {
if (result.button.accept) {
let setting = ServerConnection.makeSettings();
let apiURL = URLExt.join(setting.baseUrl, 'api/shutdown');
ServerConnection.makeRequest(apiURL, { method: 'POST' }, setting)
.then(result => {
if (result.ok) {
// Close this window if the shutdown request has been successful
let body = document.createElement('div');
body.innerHTML = `<p>You have shut down the Jupyter server. You can now close this tab.</p>
<p>To use JupyterLab again, you will need to relaunch it.</p>`;
showDialog({
title: 'Server stopped',
body: new Widget({ node: body }),
buttons: []
});
window.close();
} else {
throw new ServerConnection.ResponseError(result);
}
})
.catch(data => {
throw new ServerConnection.NetworkError(data);
});
}
});
示例2: describe
describe('#getDownloadUrl()', () => {
const settings = ServerConnection.makeSettings({
baseUrl: 'http://foo'
});
it('should get the url of a file', async () => {
const drive = new Drive({ serverSettings: settings });
const test1 = drive.getDownloadUrl('bar.txt');
const test2 = drive.getDownloadUrl('fizz/buzz/bar.txt');
const test3 = drive.getDownloadUrl('/bar.txt');
const urls = await Promise.all([test1, test2, test3]);
expect(urls[0]).to.equal('http://foo/files/bar.txt');
expect(urls[1]).to.equal('http://foo/files/fizz/buzz/bar.txt');
expect(urls[2]).to.equal('http://foo/files/bar.txt');
});
it('should encode characters', async () => {
const drive = new Drive({ serverSettings: settings });
const url = await drive.getDownloadUrl('b ar?3.txt');
expect(url).to.equal('http://foo/files/b%20ar%3F3.txt');
});
it('should not handle relative paths', async () => {
const drive = new Drive({ serverSettings: settings });
const url = await drive.getDownloadUrl('fizz/../bar.txt');
expect(url).to.equal('http://foo/files/fizz/../bar.txt');
});
});
示例3: it
it('should use baseUrl for wsUrl', () => {
const conf: Partial<ServerConnection.ISettings> = {
baseUrl: 'https://host/path'
};
const settings = ServerConnection.makeSettings(conf);
expect(settings.baseUrl).to.equal(conf.baseUrl);
expect(settings.wsUrl).to.equal('wss://host/path');
});
示例4: requestJsonPromise
function requestJsonPromise(url: string, argument: any): Promise<JSONObject> {
let request = {
method: 'POST',
body: JSON.stringify(argument),
};
let settings = ServerConnection.makeSettings();
return ServerConnection.makeRequest(url, request, settings)
.then(handleError)
.then((response) => {
return response.json();
});
}
示例5: function
document.addEventListener('DOMContentLoaded', function(event) {
// Connect to the notebook webserver.
let connectionInfo = ServerConnection.makeSettings({
baseUrl: BASEURL,
wsUrl: WSURL
});
Kernel.getSpecs(connectionInfo).then(kernelSpecs => {
return Kernel.startNew({
name: kernelSpecs.default,
serverSettings: connectionInfo
});
}).then(kernel => {
// Create a codemirror instance
let code = require('../widget_code.json').join('\n');
let inputarea = document.getElementsByClassName('inputarea')[0] as HTMLElement;
let editor = CodeMirror(inputarea, {
value: code,
mode: 'python',
tabSize: 4,
showCursorWhenSelecting: true,
viewportMargin: Infinity,
readOnly: true
});
// Create the widget area and widget manager
let widgetarea = document.getElementsByClassName('widgetarea')[0] as HTMLElement;
let manager = new WidgetManager(kernel, widgetarea);
// Run backend code to create the widgets. You could also create the
// widgets in the frontend, like the other widget examples demonstrate.
let execution = kernel.requestExecute({ code: code });
execution.onIOPub = (msg) => {
// If we have a display message, display the widget.
if (KernelMessage.isDisplayDataMsg(msg)) {
let widgetData: any = msg.content.data['application/vnd.jupyter.widget-view+json'];
if (widgetData !== undefined && widgetData.version_major === 2) {
let model = manager.get_model(widgetData.model_id);
if (model !== undefined) {
model.then(model => {
manager.display_model(msg, model);
});
}
}
}
};
});
});
示例6: function
xmlhttp.onreadystatechange = function () {
//Call a function when the state changes.
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
let response = JSON.parse(xmlhttp.responseText);
// TODO: this will need to be changed to check the status code 429
// when https://github.com/jupyter/tmpnb/pull/283 is implemented.
if (response.status === 'full') {
let widgetarea = document.getElementsByClassName("widgetarea")[0] as HTMLElement;
widgetarea.innerText = "The tmpnb server does not have any available kernels.";
throw new Error('Tmpnb does not have any available kernels');
}
let serverUrl = baseUrl.concat(JSON.parse(xmlhttp.responseText).url);
let wsUrl = 'ws:' + serverUrl.split(':').slice(1).join(':');
// Connect to the notebook webserver.
let connectionInfo: any = ServerConnection.makeSettings({
baseUrl: serverUrl,
wsUrl: wsUrl
});
Kernel.getSpecs(connectionInfo).then(kernelSpecs => {
return Kernel.startNew({name: kernelSpecs.default, serverSettings: connectionInfo});
}).then(kernel => {
// Create a codemirror instance
let code = require('../widget_code.json').join("\n");
let inputarea = document.getElementsByClassName("inputarea")[0] as HTMLElement;
let editor = CodeMirror(inputarea, {
value: code,
mode: "python",
tabSize: 4,
showCursorWhenSelecting: true,
viewportMargin: Infinity,
readOnly: true
});
// Create the widget area and widget manager
let widgetarea = document.getElementsByClassName("widgetarea")[0] as HTMLElement;
let manager = new WidgetManager(kernel, widgetarea);
// Run backend code to create the widgets. You could also create the
// widgets in the frontend, like the other widget examples demonstrate.
let request = kernel.requestExecute({ code: code });
request.onIOPub = (msg) => {
// If we have a display message, display the widget.
console.log(msg);
}
});
}
}
示例7: describe
describe('SettingManager', () => {
const manager = new SettingManager({
serverSettings: ServerConnection.makeSettings({ pageUrl: 'lab' })
});
describe('#constructor()', () => {
it('should accept no options', () => {
const manager = new SettingManager();
expect(manager).to.be.an.instanceof(SettingManager);
});
it('should accept options', () => {
const manager = new SettingManager({
serverSettings: ServerConnection.makeSettings()
});
expect(manager).to.be.an.instanceof(SettingManager);
});
});
describe('#serverSettings', () => {
it('should be the server settings', () => {
const baseUrl = 'foo';
const serverSettings = ServerConnection.makeSettings({ baseUrl });
const manager = new SettingManager({ serverSettings });
expect(manager.serverSettings.baseUrl).to.equal(baseUrl);
});
});
describe('#fetch()', () => {
it('should fetch settings for an extension', async () => {
const id = '@jupyterlab/apputils-extension:themes';
expect((await manager.fetch(id)).id).to.equal(id);
});
});
describe('#save()', () => {
it('should save a setting', async () => {
const id = '@jupyterlab/apputils-extension:themes';
const theme = 'Foo Theme';
const raw = `{"theme": "${theme}"}`;
await manager.save(id, raw);
expect(JSON.parse((await manager.fetch(id)).raw).theme).to.equal(theme);
});
});
});
示例8: isNbInGit
function isNbInGit(args: {readonly path: string}): Promise<boolean> {
let request = {
method: 'POST',
body: JSON.stringify(args),
};
let settings = ServerConnection.makeSettings();
return ServerConnection.makeRequest(
URLExt.join(urlRStrip(settings.baseUrl), '/nbdime/api/isgit'),
request, settings).then((response) => {
if (!response.ok) {
return Promise.reject(response);
}
return response.json() as Promise<IApiResponse>;
}).then((data) => {
return data['is_git'];
});
}