// project.js document.addEventListener('DOMContentLoaded', function() { loadProjectDetails(); setupEventListeners(); }); function setupEventListeners() { document.getElementById('saveChangesBtn').addEventListener('click', saveProject); document.getElementById('publishVersionBtn').addEventListener('click', publishProject); document.getElementById('addIntentBtn').addEventListener('click', showAddIntentModal); document.getElementById('newVersionBtn').addEventListener('click', showNewVersionModal); } function loadProjectDetails() { fetch('/project/details') .then(response => response.json()) .then(data => { renderProjectDetails(data); }) .catch(error => { console.error('Error loading project details:', error); alert('Failed to load project details.'); }); } function renderProjectDetails(data) { const container = document.getElementById('projectDetails'); container.innerHTML = ''; const published = data.published ? '✅ Yes' : '❌ No'; container.innerHTML += `

Version: ${data.version}

`; container.innerHTML += `

Published: ${published}

`; const list = document.createElement('ul'); data.intents.forEach(intent => { const li = document.createElement('li'); li.style.marginBottom = '8px'; li.innerHTML = `${intent.name} `; list.appendChild(li); }); container.appendChild(list); document.getElementById('publishVersionBtn').disabled = data.published; } function saveProject() { fetch('/project/update', { method: 'POST' }) .then(response => response.json()) .then(data => alert('Project saved!')) .catch(error => alert('Failed to save project.')); } function publishProject() { fetch('/project/publish', { method: 'POST' }) .then(response => response.json()) .then(data => alert('Project published!')) .catch(error => alert('Failed to publish project.')); } function showAddIntentModal() { // show modal for adding intent and API info $('#addIntentModal').modal('show'); } function showNewVersionModal() { fetch('/project/versions') .then(response => response.json()) .then(versions => { const select = document.getElementById('baseVersionSelect'); select.innerHTML = ''; versions.forEach(v => { const option = document.createElement('option'); option.value = v.id; option.textContent = `Version ${v.number}`; select.appendChild(option); }); $('#newVersionModal').modal('show'); }) .catch(error => { alert('Failed to load versions.'); }); } function createNewVersion() { const baseVersionId = document.getElementById('baseVersionSelect').value; fetch('/project/new-version', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ base_version_id: baseVersionId }) }) .then(response => response.json()) .then(data => { alert('New version created!'); loadProjectDetails(); }) .catch(error => alert('Failed to create new version.')); } function loadSparkProjects() { fetch('/spark/projects') .then(response => response.json()) .then(data => { if (data.error) { alert('⚠ Spark service unreachable.'); return; } const list = document.getElementById('sparkProjectList'); list.innerHTML = ''; data.projects.forEach(p => { const li = document.createElement('li'); li.textContent = p.name; list.appendChild(li); }); }) .catch(error => { alert('⚠ Spark service unreachable.'); }); }