/** * Learning Kanban Native Integration for Homepage */ function getApiBase() { const host = window.location.hostname; if (host === 'localhost' || host.endsWith('.localhost')) { return `http://learning.localhost`; } return `https://learning.arch-services.mywire.org`; } const API_BASE = getApiBase(); async function fetchCourses() { try { const response = await fetch(`${API_BASE}/api/courses`); if (!response.ok) return []; return await response.json(); } catch (e) { console.error("Failed to fetch courses", e); return []; } } async function updateCourseStatus(courseId, newStatus) { try { const res = await fetch(`${API_BASE}/api/courses`); const courses = await res.json(); const course = courses.find(c => c.id == courseId); if (!course) return; course.status = newStatus; await fetch(`${API_BASE}/api/courses/${courseId}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(course) }); } catch (e) { console.error("Failed to update course", e); } } function createKanbanCard(course) { return `
`; } async function renderKanban() { // Find the section by its title const sections = document.querySelectorAll('section'); let container = null; for (const section of sections) { const h2 = section.querySelector('h2'); // Match the group name from services.yaml if (h2 && h2.textContent.trim() === 'Learning Hub') { container = section; break; } } if (!container) return; // Target the list area (usually follows the h2) const listArea = container.querySelector('ul') || container.querySelector('.grid') || container.lastElementChild; if (!listArea) return; // Replace the entire list area with our board listArea.outerHTML = `