-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.ts
44 lines (41 loc) · 1.53 KB
/
run.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
import {JupyterFrontEnd} from "@jupyterlab/application";
import {Dialog, showDialog} from "@jupyterlab/apputils";
import {PageConfig} from "@jupyterlab/coreutils";
import {IDocumentManager} from "@jupyterlab/docmanager";
import {IRequestResult, request} from "requests-helper";
export
function generateSample(app: JupyterFrontEnd, docManager: IDocumentManager): void {
showDialog({
buttons: [Dialog.cancelButton(), Dialog.okButton({ label: "Ok" })],
title: "Generate Preview?",
}).then((result) => {
if (result.button.label === "CANCEL") {
return;
}
const context = docManager.contextForWidget(app.shell.currentWidget);
let path = "";
let model = {};
if (context) {
path = context.path;
model = context.model.toJSON();
}
return new Promise((resolve) => {
request("post",
PageConfig.getBaseUrl() + "jupyterlab_powerpoint/generate",
{},
{path, model},
).then((res: IRequestResult) => {
if (res.ok) {
// todo
} else {
showDialog({
body: "Check the Jupyter logs for the exception.",
buttons: [Dialog.okButton({ label: "Ok" })],
title: "Something went wrong!",
}).then(() => {resolve(); });
}
});
});
},
);
}