File size: 4,175 Bytes
c72f0c4
 
 
 
 
 
 
 
 
 
 
e19913f
 
 
c72f0c4
 
e19913f
c72f0c4
e19913f
c72f0c4
 
 
954a8a4
e19913f
 
c72f0c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78a2bad
c72f0c4
 
 
78a2bad
 
954a8a4
c72f0c4
 
 
 
e19913f
 
954a8a4
c72f0c4
 
 
 
e19913f
7abe33d
c72f0c4
 
 
7abe33d
 
c72f0c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7abe33d
 
c72f0c4
 
 
 
 
 
 
 
 
 
 
 
 
7abe33d
 
c72f0c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7abe33d
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
// 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 += `<p><strong>Version:</strong> ${data.version}</p>`;
    container.innerHTML += `<p><strong>Published:</strong> ${published}</p>`;
    const list = document.createElement('ul');
    data.intents.forEach(intent => {
        const li = document.createElement('li');
        li.style.marginBottom = '8px';
        li.innerHTML = `${intent.name} 
            <button class="btn btn-sm btn-primary" onclick="editIntent('${intent.id}')">Edit</button>
            <button class="btn btn-sm btn-danger" onclick="removeIntent('${intent.id}')">-</button>`;
        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.');
        });
}