Files
nixos-core/homepage/config/custom.js
T
kiskaadee ef72e3ea0f refactor(core): decouple applications to separate deployments and streamline core control plane
This commit restructures the homeserver repository to isolate the core gateway and management tools (Control Plane) from user applications (Data Plane). This allows applications to have independent lifecycles and CI/CD pipelines, preventing git history contamination.

- Relocated user applications (excalidraw, gitea, jellyfin, learning-hub, mermaid, ollama) to an external deployments directory.
- Moved homepage to the root directory as a core server component and removed the empty apps directory.
- Streamlined up.sh and down.sh to deploy and stop only core services and homepage, removing --infra-only parameters.
- Replaced all hardcoded domain names with a configurable global DOMAIN environment variable in docker-compose files.
- Used Authelia templating ({{ env "DOMAIN" }}) in configuration.yml to dynamically resolve SSO cookie domains and redirection URLs.
- Updated up.sh and down.sh helpers to explicitly pass env files via --env-file flags, resolving compose interpolation warnings.
- Created a declarative NixOS module (infra/nixos/dynu-ddns.nix) to orchestrate the Dynu DDNS update script.
- Created Authelia .env-example template for setup reproducibility.
- Refactored .gitignore to exclude obsolete app cache rules and keep it minimal to core secrets, volumes, and logs.
- Updated documentation (README, architecture, roadmap, usability) to document decoupled deployments and public/SSO service templates.
2026-06-14 23:33:35 -05:00

235 lines
9.2 KiB
JavaScript

/**
* Learning Kanban Native Integration for Homepage (v4 - Autonomous & Anchorless)
*/
function getApiBase() {
return `https://learning.arch-services.mywire.org`;
}
const API_BASE = getApiBase();
let allCourses = [];
async function fetchCourses() {
try {
const response = await fetch(`${API_BASE}/api/courses`);
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
allCourses = await response.json();
return allCourses;
} catch (e) {
console.warn("Failed to fetch courses", e);
return [];
}
}
async function updateCourseStatus(courseId, newStatus) {
try {
const course = allCourses.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 `
<div class="hp-kanban-card" draggable="true" data-id="${course.id}">
<div class="hp-kanban-card-actions">
<button onclick="window.hpShowCourseModal(${course.id})" title="Edit">✏️</button>
<button onclick="window.hpDeleteCourse(${course.id})" title="Delete">🗑️</button>
</div>
<div class="hp-kanban-card-title">${course.title}</div>
<div class="hp-kanban-card-desc">${course.description || ''}</div>
<div class="hp-kanban-card-links">
${course.last_link ? `<a href="${course.last_link}" target="_blank" class="milestone-link">🚩 Milestone ↗</a>` : ''}
<a href="${course.main_link}" target="_blank" class="hub-link">Hub ↗</a>
</div>
</div>
`;
}
async function renderKanban() {
// Look for the main services grid - this is our insertion point
const servicesGrid = document.getElementById('services');
if (!servicesGrid) return;
// Check if we already created our section
let section = document.getElementById('hp-learning-hub-section');
if (!section) {
section = document.createElement('section');
section.id = 'hp-learning-hub-section';
section.className = 'hp-kanban-section';
// Insert after services grid
servicesGrid.after(section);
section.innerHTML = `
<div class="hp-section-header">
<h2>Learning Hub</h2>
<button class="hp-add-btn" onclick="window.hpShowCourseModal()">+ Add Course</button>
</div>
<div class="hp-kanban-board">
<div class="hp-kanban-col" data-status="WIP">
<h3>🚀 In Progress</h3>
<div class="hp-kanban-list"></div>
</div>
<div class="hp-kanban-col" data-status="Planning">
<h3>📅 Planning</h3>
<div class="hp-kanban-list"></div>
</div>
<div class="hp-kanban-col" data-status="Archive">
<h3>📦 Archive</h3>
<div class="hp-kanban-list"></div>
</div>
</div>
`;
injectModal();
}
await refreshBoardContent(section);
}
async function refreshBoardContent(section) {
const courses = await fetchCourses();
const board = section.querySelector('.hp-kanban-board');
if (!board) return;
board.querySelectorAll('.hp-kanban-list').forEach(l => l.innerHTML = '');
courses.forEach(course => {
const list = board.querySelector(`.hp-kanban-col[data-status="${course.status}"] .hp-kanban-list`);
if (list) list.innerHTML += createKanbanCard(course);
});
// Re-bind Drag & Drop
const cards = board.querySelectorAll('.hp-kanban-card');
cards.forEach(card => {
card.addEventListener('dragstart', (e) => {
e.dataTransfer.setData('text/plain', card.dataset.id);
card.classList.add('dragging');
});
card.addEventListener('dragend', () => card.classList.remove('dragging'));
});
const cols = board.querySelectorAll('.hp-kanban-col');
cols.forEach(col => {
col.addEventListener('dragover', (e) => e.preventDefault());
col.addEventListener('drop', async (e) => {
e.preventDefault();
const id = e.dataTransfer.getData('text/plain');
const status = col.dataset.status;
const draggingCard = document.querySelector(`.hp-kanban-card[data-id="${id}"]`);
if (draggingCard) col.querySelector('.hp-kanban-list').appendChild(draggingCard);
await updateCourseStatus(id, status);
});
});
}
// Modal Logic
window.hpShowCourseModal = function(id = null) {
const modal = document.getElementById('hp-course-modal');
if (!modal) return;
const form = document.getElementById('hp-course-form');
modal.style.display = 'flex';
if (id) {
const course = allCourses.find(c => c.id == id);
if (!course) return;
document.getElementById('hp-modal-title').innerText = 'Edit Course';
document.getElementById('hp-course-id').value = course.id;
document.getElementById('hp-title').value = course.title;
document.getElementById('hp-description').value = course.description || '';
document.getElementById('hp-main_link').value = course.main_link;
document.getElementById('hp-last_link').value = course.last_link || '';
document.getElementById('hp-status').value = course.status;
} else {
document.getElementById('hp-modal-title').innerText = 'Add New Course';
form.reset();
document.getElementById('hp-course-id').value = '';
}
};
window.hpCloseModal = () => {
const modal = document.getElementById('hp-course-modal');
if (modal) modal.style.display = 'none';
};
window.hpDeleteCourse = async (id) => {
if (confirm('Delete this course?')) {
await fetch(`${API_BASE}/api/courses/${id}`, { method: 'DELETE' });
const section = document.getElementById('hp-learning-hub-section');
if (section) refreshBoardContent(section);
}
};
function injectModal() {
if (document.getElementById('hp-course-modal')) return;
const modalHtml = `
<div id="hp-course-modal" class="hp-modal">
<div class="hp-modal-content">
<h2 id="hp-modal-title">Add Course</h2>
<form id="hp-course-form">
<input type="hidden" id="hp-course-id">
<div class="hp-form-group"><label>Title</label><input type="text" id="hp-title" required></div>
<div class="hp-form-group"><label>Description</label><textarea id="hp-description"></textarea></div>
<div class="hp-form-group"><label>Main Link</label><input type="url" id="hp-main_link" required></div>
<div class="hp-form-group"><label>Milestone Link</label><input type="url" id="hp-last_link"></div>
<div class="hp-form-group"><label>Status</label>
<select id="hp-status">
<option value="WIP">WIP</option>
<option value="Planning">Planning</option>
<option value="Archive">Archive</option>
</select>
</div>
<div class="hp-modal-actions">
<button type="button" onclick="hpCloseModal()">Cancel</button>
<button type="submit">Save</button>
</div>
</form>
</div>
</div>
`;
document.body.insertAdjacentHTML('beforeend', modalHtml);
document.getElementById('hp-course-form').onsubmit = async (e) => {
e.preventDefault();
const id = document.getElementById('hp-course-id').value;
const data = {
title: document.getElementById('hp-title').value,
description: document.getElementById('hp-description').value,
main_link: document.getElementById('hp-main_link').value,
last_link: document.getElementById('hp-last_link').value,
status: document.getElementById('hp-status').value
};
const method = id ? 'PUT' : 'POST';
const url = id ? `${API_BASE}/api/courses/${id}` : `${API_BASE}/api/courses`;
await fetch(url, {
method,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
window.hpCloseModal();
const section = document.getElementById('hp-learning-hub-section');
if (section) refreshBoardContent(section);
};
}
// Observer
let debounceTimer;
const observer = new MutationObserver(() => {
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
const servicesGrid = document.getElementById('services');
if (servicesGrid && !document.getElementById('hp-learning-hub-section')) {
renderKanban();
}
}, 500);
});
observer.observe(document.body, { childList: true, subtree: true });
renderKanban();