ciyidogan commited on
Commit
e19913f
·
verified ·
1 Parent(s): e44e061

Update static/js/project.js

Browse files
Files changed (1) hide show
  1. static/js/project.js +58 -66
static/js/project.js CHANGED
@@ -1,66 +1,58 @@
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
- }
 
1
+ function listProjects() {
2
+ apiGet('/project/list')
3
+ .then(data => {
4
+ const select = document.getElementById('project-select');
5
+ select.innerHTML = '<option value="">-- Select a project --</option>';
6
+ Object.keys(data).forEach(project => {
7
+ const option = document.createElement('option');
8
+ option.value = project;
9
+ option.text = project;
10
+ select.appendChild(option);
11
+ });
12
+ })
13
+ .catch(err => console.error(err));
14
+ }
15
+
16
+ function loadProjectDetails() {
17
+ const project = document.getElementById('project-select').value;
18
+ if (!project) return;
19
+
20
+ apiGet(`/project/${project}/latest`)
21
+ .then(data => {
22
+ const details = document.getElementById('project-details');
23
+ const info = document.getElementById('project-info');
24
+ details.classList.remove('d-none');
25
+
26
+ let html = `<p><strong>Version:</strong> ${data.version_number}</p>`;
27
+ html += `<p><strong>Published:</strong> ${data.published ? '✅ Yes' : '❌ No'}</p>`;
28
+ html += `<div><strong>Intents:</strong><ul>`;
29
+ data.intents.forEach(intent => {
30
+ html += `<li>${intent.name} <button class="btn btn-sm btn-danger ml-2" onclick="removeIntent('${intent.name}')">–</button></li>`;
31
+ });
32
+ html += `</ul><button class="btn btn-sm btn-success" onclick="addIntent()">+ Add Intent</button></div>`;
33
+ info.innerHTML = html;
34
+
35
+ if (data.published) {
36
+ document.querySelectorAll('#project-info input, #project-info button').forEach(el => {
37
+ el.disabled = true;
38
+ });
39
+ }
40
+ })
41
+ .catch(err => console.error(err));
42
+ }
43
+
44
+ function saveProject() {
45
+ alert('Save logic will be implemented here.');
46
+ }
47
+
48
+ function publishProject() {
49
+ alert('Publish logic will be implemented here.');
50
+ }
51
+
52
+ function addIntent() {
53
+ alert('Add Intent logic will be implemented here.');
54
+ }
55
+
56
+ function removeIntent(name) {
57
+ alert(`Remove Intent '${name}' logic will be implemented here.`);
58
+ }