ciyidogan commited on
Commit
dbc8392
·
verified ·
1 Parent(s): d1a11ea

Upload 6 files

Browse files
static/js/auth.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function login() {
2
+ const username = document.getElementById('login-username').value;
3
+ const password = document.getElementById('login-password').value;
4
+ apiPost('/auth/login', { username, password })
5
+ .then(data => showResult('login-result', data))
6
+ .catch(err => console.error(err));
7
+ }
8
+
9
+ function changePassword() {
10
+ const username = document.getElementById('change-username').value;
11
+ const oldPassword = document.getElementById('old-password').value;
12
+ const newPassword = document.getElementById('new-password').value;
13
+ apiPost('/auth/change_password', { username, old_password: oldPassword, new_password: newPassword })
14
+ .then(data => showResult('change-password-result', data))
15
+ .catch(err => console.error(err));
16
+ }
static/js/common.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const apiBase = '';
2
+
3
+ function apiPost(path, body) {
4
+ return fetch(`${apiBase}${path}`, {
5
+ method: 'POST',
6
+ headers: { 'Content-Type': 'application/json' },
7
+ body: JSON.stringify(body)
8
+ }).then(res => res.json());
9
+ }
10
+
11
+ function apiGet(path) {
12
+ return fetch(`${apiBase}${path}`)
13
+ .then(res => res.json());
14
+ }
15
+
16
+ function showResult(id, data) {
17
+ document.getElementById(id).innerText = data.message || JSON.stringify(data, null, 2);
18
+ }
static/js/config.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function getConfig() {
2
+ apiGet('/config/get')
3
+ .then(data => {
4
+ document.getElementById('config-json').value = JSON.stringify(data, null, 2);
5
+ })
6
+ .catch(err => console.error(err));
7
+ }
8
+
9
+ function updateConfig() {
10
+ const config = JSON.parse(document.getElementById('config-json').value);
11
+ apiPost('/config/update', config)
12
+ .then(data => showResult('config-result', data))
13
+ .catch(err => console.error(err));
14
+ }
static/js/project.js ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function listProjects() {
2
+ apiGet('/project/list')
3
+ .then(data => {
4
+ document.getElementById('projects-json').value = JSON.stringify(data, null, 2);
5
+ })
6
+ .catch(err => console.error(err));
7
+ }
8
+
9
+ function addProject() {
10
+ const projectName = document.getElementById('new-project-name').value;
11
+ apiPost('/project/add', { project_name: projectName })
12
+ .then(data => showResult('project-result', data))
13
+ .catch(err => console.error(err));
14
+ }
15
+
16
+ function updateProject() {
17
+ const projectName = document.getElementById('update-project-name').value;
18
+ const clientLastUpdated = document.getElementById('update-last-updated').value;
19
+ apiPost('/project/update', { project_name: projectName, client_last_updated: clientLastUpdated })
20
+ .then(data => showResult('project-result', data))
21
+ .catch(err => console.error(err));
22
+ }
23
+
24
+ function publishProject() {
25
+ const projectName = document.getElementById('publish-project-name').value;
26
+ const clientLastUpdated = document.getElementById('publish-last-updated').value;
27
+ apiPost('/project/publish', { project_name: projectName, client_last_updated: clientLastUpdated })
28
+ .then(data => showResult('project-result', data))
29
+ .catch(err => console.error(err));
30
+ }
31
+
32
+ function addIntent() {
33
+ const projectName = document.getElementById('intent-project-name').value;
34
+ const versionNumber = parseInt(document.getElementById('intent-version-number').value);
35
+ const intentName = document.getElementById('intent-name').value;
36
+ const clientLastUpdated = document.getElementById('intent-last-updated').value;
37
+ const intent = { name: intentName, examples: [], parameters: [], action: '', humanization_prompt: '' };
38
+ apiPost('/project/add_intent', { project_name: projectName, version_number: versionNumber, intent, client_last_updated: clientLastUpdated })
39
+ .then(data => showResult('intent-result', data))
40
+ .catch(err => console.error(err));
41
+ }
42
+
43
+ function deleteIntent() {
44
+ const projectName = document.getElementById('delete-intent-project-name').value;
45
+ const versionNumber = parseInt(document.getElementById('delete-intent-version-number').value);
46
+ const intentName = document.getElementById('delete-intent-name').value;
47
+ const clientLastUpdated = document.getElementById('delete-intent-last-updated').value;
48
+ apiPost('/project/delete_intent', { project_name: projectName, version_number: versionNumber, intent_name: intentName, client_last_updated: clientLastUpdated })
49
+ .then(data => showResult('intent-result', data))
50
+ .catch(err => console.error(err));
51
+ }
52
+
53
+ function addApi() {
54
+ const apiName = document.getElementById('api-name').value;
55
+ const apiDef = JSON.parse(document.getElementById('api-def').value);
56
+ apiPost('/project/add_api', { api_name: apiName, api_def: apiDef })
57
+ .then(data => showResult('api-result', data))
58
+ .catch(err => console.error(err));
59
+ }
60
+
61
+ function deleteApi() {
62
+ const apiName = document.getElementById('delete-api-name').value;
63
+ apiPost('/project/delete_api', { api_name: apiName })
64
+ .then(data => showResult('api-result', data))
65
+ .catch(err => console.error(err));
66
+ }
static/js/spark.js ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function sparkStartup() {
2
+ const payload = JSON.parse(document.getElementById('spark-startup-payload').value);
3
+ apiPost('/spark/startup', payload)
4
+ .then(data => showResult('spark-result', data))
5
+ .catch(err => console.error(err));
6
+ }
7
+
8
+ function sparkProjectList() {
9
+ apiGet('/spark/project_list')
10
+ .then(data => showResult('spark-result', data))
11
+ .catch(err => console.error(err));
12
+ }
13
+
14
+ function sparkEnable() {
15
+ const payload = JSON.parse(document.getElementById('spark-enable-payload').value);
16
+ apiPost('/spark/enable', payload)
17
+ .then(data => showResult('spark-result', data))
18
+ .catch(err => console.error(err));
19
+ }
20
+
21
+ function sparkDisable() {
22
+ const payload = JSON.parse(document.getElementById('spark-disable-payload').value);
23
+ apiPost('/spark/disable', payload)
24
+ .then(data => showResult('spark-result', data))
25
+ .catch(err => console.error(err));
26
+ }
27
+
28
+ function sparkDelete() {
29
+ const payload = JSON.parse(document.getElementById('spark-delete-payload').value);
30
+ apiPost('/spark/delete', payload)
31
+ .then(data => showResult('spark-result', data))
32
+ .catch(err => console.error(err));
33
+ }
static/js/test.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ function runTests() {
2
+ apiPost('/test/run', {})
3
+ .then(data => showResult('test-result', data))
4
+ .catch(err => console.error(err));
5
+ }