60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
// QA Checklist API Client
|
|
export async function loadQaChecklist() {
|
|
try {
|
|
const res = await fetch('/api/qa');
|
|
if (!res.ok) throw new Error("Failed to load QA data");
|
|
const tasks = await res.json();
|
|
|
|
const container = document.getElementById('qa-checklist-container');
|
|
if (!container) return;
|
|
|
|
container.innerHTML = ''; // Clear hardcoded items
|
|
|
|
tasks.forEach(task => {
|
|
const div = document.createElement('div');
|
|
div.className = 'check-item';
|
|
|
|
const checkbox = document.createElement('input');
|
|
checkbox.type = 'checkbox';
|
|
checkbox.checked = task.is_completed;
|
|
checkbox.dataset.id = task.id;
|
|
checkbox.addEventListener('change', async (e) => {
|
|
await toggleQaTask(task.id, e.target.checked);
|
|
updateQAProgress();
|
|
});
|
|
|
|
const label = document.createElement('label');
|
|
label.innerHTML = `<strong>${task.id}:</strong> ${task.label}`;
|
|
|
|
div.appendChild(checkbox);
|
|
div.appendChild(label);
|
|
container.appendChild(div);
|
|
});
|
|
|
|
// Expose function to global scope since HTML uses inline onchange="updateQAProgress()" for some reason
|
|
window.updateQAProgress = () => {
|
|
const total = document.querySelectorAll('.check-item input').length;
|
|
const checked = document.querySelectorAll('.check-item input:checked').length;
|
|
const pct = Math.round((checked / total) * 100) || 0;
|
|
document.getElementById('qa-progress-label').innerText = `${pct}% Complete`;
|
|
document.getElementById('qa-progress-bar').style.width = `${pct}%`;
|
|
};
|
|
|
|
window.updateQAProgress();
|
|
} catch (err) {
|
|
console.error("QA Loading Error:", err);
|
|
}
|
|
}
|
|
|
|
export async function toggleQaTask(id, is_completed) {
|
|
try {
|
|
await fetch(`/api/qa/${id}`, {
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ is_completed })
|
|
});
|
|
} catch (err) {
|
|
console.error("Failed to update QA task", err);
|
|
}
|
|
}
|