Spaces:
Building
Building
Delete static/js/project.js
Browse files- static/js/project.js +0 -203
static/js/project.js
DELETED
@@ -1,203 +0,0 @@
|
|
1 |
-
document.addEventListener('DOMContentLoaded', function() {
|
2 |
-
loadProjectDetails();
|
3 |
-
setupEventListeners();
|
4 |
-
});
|
5 |
-
|
6 |
-
let CURRENT_PROJECT = null;
|
7 |
-
let CURRENT_VERSION = null;
|
8 |
-
|
9 |
-
function setupEventListeners() {
|
10 |
-
document.getElementById('saveChangesBtn').addEventListener('click', saveProject);
|
11 |
-
document.getElementById('publishVersionBtn').addEventListener('click', publishProject);
|
12 |
-
document.getElementById('addIntentBtn').addEventListener('click', showAddIntentModal);
|
13 |
-
document.getElementById('newVersionBtn').addEventListener('click', showNewVersionModal);
|
14 |
-
document.getElementById('newProjectBtn').addEventListener('click', showNewProjectModal);
|
15 |
-
}
|
16 |
-
|
17 |
-
function loadProjectDetails() {
|
18 |
-
fetch('/project/details')
|
19 |
-
.then(response => response.json())
|
20 |
-
.then(data => {
|
21 |
-
CURRENT_PROJECT = data.name;
|
22 |
-
CURRENT_VERSION = data.version;
|
23 |
-
renderProjectDetails(data);
|
24 |
-
})
|
25 |
-
.catch(error => {
|
26 |
-
console.error('Error loading project details:', error);
|
27 |
-
alert('Failed to load project details.');
|
28 |
-
});
|
29 |
-
}
|
30 |
-
|
31 |
-
function renderProjectDetails(data) {
|
32 |
-
const container = document.getElementById('projectDetails');
|
33 |
-
container.innerHTML = '';
|
34 |
-
|
35 |
-
const published = data.published ? '✅ Yes' : '❌ No';
|
36 |
-
container.innerHTML += `<p><strong>Project:</strong> ${data.name}</p>`;
|
37 |
-
container.innerHTML += `<p><strong>Version:</strong> ${data.version}</p>`;
|
38 |
-
container.innerHTML += `<p><strong>Published:</strong> ${published}</p>`;
|
39 |
-
|
40 |
-
const list = document.createElement('ul');
|
41 |
-
data.intents.forEach(intent => {
|
42 |
-
const li = document.createElement('li');
|
43 |
-
li.style.marginBottom = '8px';
|
44 |
-
li.innerHTML = `${intent.name}
|
45 |
-
<button class="btn btn-sm btn-primary" onclick="editIntent('${intent.id}')">Edit</button>
|
46 |
-
<button class="btn btn-sm btn-danger" onclick="removeIntent('${intent.id}')">-</button>`;
|
47 |
-
list.appendChild(li);
|
48 |
-
});
|
49 |
-
container.appendChild(list);
|
50 |
-
|
51 |
-
document.getElementById('publishVersionBtn').disabled = data.published;
|
52 |
-
}
|
53 |
-
|
54 |
-
function saveProject() {
|
55 |
-
fetch('/project/update', { method: 'POST' })
|
56 |
-
.then(response => response.json())
|
57 |
-
.then(() => alert('Project saved!'))
|
58 |
-
.catch(() => alert('Failed to save project.'));
|
59 |
-
}
|
60 |
-
|
61 |
-
function publishProject() {
|
62 |
-
fetch('/project/publish', { method: 'POST' })
|
63 |
-
.then(response => response.json())
|
64 |
-
.then(() => alert('Project published!'))
|
65 |
-
.catch(() => alert('Failed to publish project.'));
|
66 |
-
}
|
67 |
-
|
68 |
-
function showNewProjectModal() {
|
69 |
-
const name = prompt('Enter new project name:');
|
70 |
-
if (name) {
|
71 |
-
fetch('/project/new', {
|
72 |
-
method: 'POST',
|
73 |
-
headers: { 'Content-Type': 'application/json' },
|
74 |
-
body: JSON.stringify({ name })
|
75 |
-
})
|
76 |
-
.then(r => r.json())
|
77 |
-
.then(() => alert('Project created!'))
|
78 |
-
.catch(() => alert('Failed to create project.'));
|
79 |
-
}
|
80 |
-
}
|
81 |
-
|
82 |
-
function showNewVersionModal() {
|
83 |
-
fetch('/project/versions')
|
84 |
-
.then(response => response.json())
|
85 |
-
.then(versions => {
|
86 |
-
const select = document.getElementById('baseVersionSelect');
|
87 |
-
select.innerHTML = '';
|
88 |
-
versions.forEach(v => {
|
89 |
-
const option = document.createElement('option');
|
90 |
-
option.value = v.no;
|
91 |
-
option.textContent = `Version ${v.no}`;
|
92 |
-
select.appendChild(option);
|
93 |
-
});
|
94 |
-
$('#newVersionModal').modal('show');
|
95 |
-
})
|
96 |
-
.catch(() => alert('Failed to load versions.'));
|
97 |
-
}
|
98 |
-
|
99 |
-
function createNewVersion() {
|
100 |
-
const baseVersionId = document.getElementById('baseVersionSelect').value;
|
101 |
-
fetch('/project/new-version', {
|
102 |
-
method: 'POST',
|
103 |
-
headers: { 'Content-Type': 'application/json' },
|
104 |
-
body: JSON.stringify({
|
105 |
-
project_name: CURRENT_PROJECT,
|
106 |
-
base_version_no: parseInt(baseVersionId)
|
107 |
-
})
|
108 |
-
})
|
109 |
-
.then(r => r.json())
|
110 |
-
.then(() => {
|
111 |
-
alert('New version created!');
|
112 |
-
loadProjectDetails();
|
113 |
-
})
|
114 |
-
.catch(() => alert('Failed to create new version.'));
|
115 |
-
}
|
116 |
-
|
117 |
-
function loadSparkProjects() {
|
118 |
-
fetch('/spark/projects')
|
119 |
-
.then(response => response.json())
|
120 |
-
.then(data => {
|
121 |
-
if (data.error) {
|
122 |
-
alert('⚠ Spark service unreachable.');
|
123 |
-
return;
|
124 |
-
}
|
125 |
-
const list = document.getElementById('sparkProjectList');
|
126 |
-
list.innerHTML = '';
|
127 |
-
data.projects.forEach(p => {
|
128 |
-
const li = document.createElement('li');
|
129 |
-
li.textContent = p.name;
|
130 |
-
list.appendChild(li);
|
131 |
-
});
|
132 |
-
})
|
133 |
-
.catch(() => alert('⚠ Spark service unreachable.'));
|
134 |
-
}
|
135 |
-
|
136 |
-
function showAddIntentModal() {
|
137 |
-
$('#addIntentModal').modal('show');
|
138 |
-
}
|
139 |
-
|
140 |
-
function addHeaderRow() {
|
141 |
-
const container = document.getElementById('headerContainer');
|
142 |
-
const row = document.createElement('div');
|
143 |
-
row.className = 'header-row mb-2';
|
144 |
-
row.innerHTML = `
|
145 |
-
<input type="text" class="form-control d-inline-block header-key" placeholder="Key" style="width: 40%">
|
146 |
-
<input type="text" class="form-control d-inline-block header-value" placeholder="Value" style="width: 40%">
|
147 |
-
<button class="btn btn-danger btn-sm" onclick="this.parentElement.remove()">-</button>`;
|
148 |
-
container.appendChild(row);
|
149 |
-
}
|
150 |
-
|
151 |
-
function saveAPI() {
|
152 |
-
const name = document.getElementById('apiNameInput').value;
|
153 |
-
const url = document.getElementById('apiUrlInput').value;
|
154 |
-
const method = document.getElementById('apiMethodSelect').value;
|
155 |
-
const auth = document.getElementById('apiAuthInput').value;
|
156 |
-
const headers = [];
|
157 |
-
|
158 |
-
document.querySelectorAll('.header-row').forEach(row => {
|
159 |
-
const key = row.querySelector('.header-key').value;
|
160 |
-
const value = row.querySelector('.header-value').value;
|
161 |
-
if (key && value) {
|
162 |
-
headers.push({ key, value });
|
163 |
-
}
|
164 |
-
});
|
165 |
-
|
166 |
-
const apiData = { name, url, method, auth, headers };
|
167 |
-
|
168 |
-
fetch('/project/update-api', {
|
169 |
-
method: 'POST',
|
170 |
-
headers: { 'Content-Type': 'application/json' },
|
171 |
-
body: JSON.stringify({
|
172 |
-
project_name: CURRENT_PROJECT,
|
173 |
-
version_no: CURRENT_VERSION,
|
174 |
-
api_data: apiData
|
175 |
-
})
|
176 |
-
})
|
177 |
-
.then(r => r.json())
|
178 |
-
.then(() => alert('API updated!'))
|
179 |
-
.catch(() => alert('Failed to update API.'));
|
180 |
-
}
|
181 |
-
|
182 |
-
function login() {
|
183 |
-
const username = document.getElementById('usernameInput').value;
|
184 |
-
const password = document.getElementById('passwordInput').value;
|
185 |
-
|
186 |
-
fetch('/auth/login', {
|
187 |
-
method: 'POST',
|
188 |
-
headers: { 'Content-Type': 'application/json' },
|
189 |
-
body: JSON.stringify({ username, password })
|
190 |
-
})
|
191 |
-
.then(response => {
|
192 |
-
if (response.ok) {
|
193 |
-
document.getElementById('loginPanel').style.display = 'none';
|
194 |
-
document.getElementById('mainPanel').style.display = 'block';
|
195 |
-
loadProjectDetails();
|
196 |
-
} else {
|
197 |
-
document.getElementById('loginError').style.display = 'block';
|
198 |
-
}
|
199 |
-
})
|
200 |
-
.catch(() => {
|
201 |
-
document.getElementById('loginError').style.display = 'block';
|
202 |
-
});
|
203 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|