forked from heavyai/jupyterlab-heavyai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.ts
143 lines (126 loc) · 3.75 KB
/
connection.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import {
Dialog, showDialog
} from '@jupyterlab/apputils';
import {
JSONObject
} from '@phosphor/coreutils';
import {
PanelLayout, Widget
} from '@phosphor/widgets';
/**
* Connection data for the mapd browser client.
*/
export
interface IMapDConnectionData extends JSONObject {
/**
* The host of the connection, e.g. `metis.mapd.com`.
*/
host: string;
/**
* The protocol to use, e.g. `https`.
*/
protocol: string;
/**
* The port to use, e.g. `443`.
*/
port: string;
/**
* The user name.
*/
user: string;
/**
* The database name.
*/
dbName: string;
/**
* The password for the connection.
*/
password: string;
}
/**
* Show a dialog for entering MapD connection data.
*/
export
function showConnectionDialog(oldConnection?: IMapDConnectionData): Promise<IMapDConnectionData> {
return showDialog<IMapDConnectionData>({
title: 'MapD Connection',
body: new MapDConnectionDialog(oldConnection),
buttons: [Dialog.cancelButton(), Dialog.okButton()],
}).then(result => {
if (result.button.accept) {
return result.value;
} else {
return oldConnection;
}
});
}
/**
* A dialog for entering MapD connection data.
*/
export
class MapDConnectionDialog extends Widget implements Dialog.IBodyWidget<IMapDConnectionData> {
constructor(oldData?: IMapDConnectionData) {
super();
let layout = this.layout = new PanelLayout();
this._user = document.createElement('input');
this._password = document.createElement('input');
this._database = document.createElement('input');
this._host = document.createElement('input');
this._protocol = document.createElement('input');
this._port = document.createElement('input');
this._user.placeholder = 'User name';
this._password.placeholder = 'Password';
this._database.placeholder = 'Database name';
this._host.placeholder = 'Host name';
this._protocol.placeholder = 'Protocol';
this._port.placeholder = 'Port';
if (oldData) {
this._user.value = oldData.user;
this._password.value = oldData.password;
this._database.value = oldData.dbName;
this._host.value = oldData.host;
this._protocol.value = oldData.protocol;
this._port.value = oldData.port;
}
const userLabel = new Widget();
userLabel.node.textContent = 'User';
const passwordLabel = new Widget();
passwordLabel.node.textContent = 'Password';
const databaseLabel = new Widget();
databaseLabel.node.textContent = 'Database';
const hostLabel = new Widget();
hostLabel.node.textContent = 'Host';
const protocolLabel = new Widget();
protocolLabel.node.textContent = 'Protocol';
const portLabel = new Widget();
portLabel.node.textContent = 'Port';
layout.addWidget(userLabel);
layout.addWidget(new Widget({ node: this._user }));
layout.addWidget(passwordLabel);
layout.addWidget(new Widget({ node: this._password }));
layout.addWidget(databaseLabel);
layout.addWidget(new Widget({ node: this._database }));
layout.addWidget(hostLabel);
layout.addWidget(new Widget({ node: this._host }));
layout.addWidget(protocolLabel);
layout.addWidget(new Widget({ node: this._protocol }));
layout.addWidget(portLabel);
layout.addWidget(new Widget({ node: this._port }));
}
getValue(): IMapDConnectionData {
return {
user: this._user.value,
password: this._password.value,
dbName: this._database.value,
host: this._host.value,
protocol: this._protocol.value,
port: this._port.value
};
}
private _user: HTMLInputElement;
private _password: HTMLInputElement;
private _database: HTMLInputElement;
private _host: HTMLInputElement;
private _protocol: HTMLInputElement;
private _port: HTMLInputElement;
}