feat: integrate autonomous learning kanban into homepage dashboard
- Refactored Learning Hub into a headless API with system/docker monitoring endpoints. - Implemented autonomous JavaScript-based Kanban board injection for homepage. - Added full CRUD support for courses directly from the main dashboard. - Optimized layout for full-width workspace and improved mobile responsiveness. - Updated system monitoring to target /home partition and fixed widget API errors.
This commit is contained in:
1 parent
3af018fa30
commit
a8d75037de
7 files changed
+355
-79
No files matched your search
+142
-24
@@ -1,3 +1,24 @@
|
|||||||
|
.hp-kanban-section {
|
||||||
|
width: 100% !important;
|
||||||
|
flex-basis: 100% !important;
|
||||||
|
margin-top: 2rem !important;
|
||||||
|
display: block !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-section-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
border-bottom: 1px solid rgba(51, 65, 85, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-section-header h2 {
|
||||||
|
margin: 0 !important;
|
||||||
|
font-size: 1.5rem !important;
|
||||||
|
}
|
||||||
|
|
||||||
.hp-kanban-board {
|
.hp-kanban-board {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 20px;
|
gap: 20px;
|
||||||
@@ -10,35 +31,39 @@
|
|||||||
background: rgba(15, 23, 42, 0.4);
|
background: rgba(15, 23, 42, 0.4);
|
||||||
border: 1px solid rgba(51, 65, 85, 0.3);
|
border: 1px solid rgba(51, 65, 85, 0.3);
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
padding: 15px;
|
padding: 20px;
|
||||||
min-height: 220px;
|
min-height: 600px; /* Enforce min height for 3-4 courses */
|
||||||
backdrop-filter: blur(4px);
|
backdrop-filter: blur(4px);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hp-kanban-col h3 {
|
.hp-kanban-col h3 {
|
||||||
font-size: 0.7rem;
|
font-size: 0.9rem !important;
|
||||||
margin: 0 0 12px 0;
|
margin: 0 0 1.5rem 0 !important;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
color: #94a3b8;
|
color: #f1f5f9;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
letter-spacing: 0.1em;
|
letter-spacing: 0.1em;
|
||||||
font-weight: 800;
|
font-weight: 700;
|
||||||
opacity: 0.8;
|
padding-bottom: 0.5rem;
|
||||||
|
border-bottom: 2px solid rgba(56, 189, 248, 0.3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.hp-kanban-list {
|
.hp-kanban-list {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 10px;
|
gap: 12px;
|
||||||
min-height: 150px;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hp-kanban-card {
|
.hp-kanban-card {
|
||||||
background: rgba(30, 41, 59, 0.8);
|
background: rgba(30, 41, 59, 0.8);
|
||||||
border: 1px solid rgba(51, 65, 85, 0.5);
|
border: 1px solid rgba(51, 65, 85, 0.5);
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 12px;
|
padding: 15px;
|
||||||
cursor: grab;
|
cursor: grab;
|
||||||
|
position: relative;
|
||||||
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,44 +75,137 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.hp-kanban-card-title {
|
.hp-kanban-card-title {
|
||||||
font-size: 0.85rem;
|
font-size: 0.95rem;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 6px;
|
||||||
color: #f8fafc;
|
color: #f8fafc;
|
||||||
|
padding-right: 40px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hp-kanban-card-desc {
|
.hp-kanban-card-desc {
|
||||||
font-size: 0.75rem;
|
font-size: 0.8rem;
|
||||||
color: #94a3b8;
|
color: #94a3b8;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 12px;
|
||||||
line-height: 1.3;
|
line-height: 1.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hp-kanban-card-links {
|
.hp-kanban-card-links {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 12px;
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
border-top: 1px solid rgba(51, 65, 85, 0.3);
|
border-top: 1px solid rgba(51, 65, 85, 0.3);
|
||||||
padding-top: 8px;
|
padding-top: 10px;
|
||||||
font-size: 0.7rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.hp-kanban-card-links a {
|
.hp-kanban-card-links a {
|
||||||
color: #60a5fa;
|
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hp-kanban-card-links a:hover {
|
.milestone-link {
|
||||||
text-decoration: underline;
|
background: #3b82f6;
|
||||||
|
color: white !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hub-link {
|
||||||
|
background: rgba(51, 65, 85, 0.5);
|
||||||
|
color: #94a3b8 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.milestone-link:hover { background: #2563eb; }
|
||||||
|
.hub-link:hover { background: rgba(51, 65, 85, 0.8); color: white !important; }
|
||||||
|
|
||||||
.hp-kanban-card.dragging {
|
.hp-kanban-card.dragging {
|
||||||
opacity: 0.1;
|
opacity: 0.1;
|
||||||
transform: scale(0.9);
|
transform: scale(0.9);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hide the placeholder card that we use to spawn the section */
|
.hp-kanban-card-actions {
|
||||||
section h2[title="Learning Hub"] + ul,
|
position: absolute;
|
||||||
section h2[title="Learning Hub"] + .grid {
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-kanban-card:hover .hp-kanban-card-actions {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-kanban-card-actions button {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-add-btn {
|
||||||
|
background: #3b82f6;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 6px 16px;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
font-weight: 600;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-add-btn:hover { background: #2563eb; }
|
||||||
|
|
||||||
|
/* Modal Styles */
|
||||||
|
.hp-modal {
|
||||||
|
display: none;
|
||||||
|
position: fixed;
|
||||||
|
z-index: 10000;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(0,0,0,0.8);
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-modal-content {
|
||||||
|
background: #1e293b;
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
width: 90%;
|
||||||
|
max-width: 450px;
|
||||||
|
border: 1px solid #334155;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-form-group { margin-bottom: 1rem; }
|
||||||
|
.hp-form-group label { display: block; font-size: 0.8rem; color: #94a3b8; margin-bottom: 4px; }
|
||||||
|
.hp-form-group input, .hp-form-group textarea, .hp-form-group select {
|
||||||
|
width: 100%;
|
||||||
|
background: #0f172a;
|
||||||
|
border: 1px solid #334155;
|
||||||
|
color: white;
|
||||||
|
padding: 8px;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-modal-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-modal-actions button {
|
||||||
|
padding: 8px 18px;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hp-kanban-board ~ ul,
|
||||||
|
.hp-kanban-board ~ .grid {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
+136
-39
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Learning Kanban Native Integration for Homepage
|
* Learning Kanban Native Integration for Homepage (v4 - Autonomous & Anchorless)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function getApiBase() {
|
function getApiBase() {
|
||||||
@@ -11,27 +11,25 @@ function getApiBase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const API_BASE = getApiBase();
|
const API_BASE = getApiBase();
|
||||||
|
let allCourses = [];
|
||||||
|
|
||||||
async function fetchCourses() {
|
async function fetchCourses() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE}/api/courses`);
|
const response = await fetch(`${API_BASE}/api/courses`);
|
||||||
if (!response.ok) return [];
|
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
||||||
return await response.json();
|
allCourses = await response.json();
|
||||||
|
return allCourses;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to fetch courses", e);
|
console.warn("Failed to fetch courses", e);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateCourseStatus(courseId, newStatus) {
|
async function updateCourseStatus(courseId, newStatus) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_BASE}/api/courses`);
|
const course = allCourses.find(c => c.id == courseId);
|
||||||
const courses = await res.json();
|
|
||||||
const course = courses.find(c => c.id == courseId);
|
|
||||||
if (!course) return;
|
if (!course) return;
|
||||||
|
|
||||||
course.status = newStatus;
|
course.status = newStatus;
|
||||||
|
|
||||||
await fetch(`${API_BASE}/api/courses/${courseId}`, {
|
await fetch(`${API_BASE}/api/courses/${courseId}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@@ -45,37 +43,40 @@ async function updateCourseStatus(courseId, newStatus) {
|
|||||||
function createKanbanCard(course) {
|
function createKanbanCard(course) {
|
||||||
return `
|
return `
|
||||||
<div class="hp-kanban-card" draggable="true" data-id="${course.id}">
|
<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-title">${course.title}</div>
|
||||||
<div class="hp-kanban-card-desc">${course.description || ''}</div>
|
<div class="hp-kanban-card-desc">${course.description || ''}</div>
|
||||||
<div class="hp-kanban-card-links">
|
<div class="hp-kanban-card-links">
|
||||||
<a href="${course.main_link}" target="_blank">Hub ↗</a>
|
${course.last_link ? `<a href="${course.last_link}" target="_blank" class="milestone-link">🚩 Milestone ↗</a>` : ''}
|
||||||
${course.last_link ? `<a href="${course.last_link}" target="_blank">Milestone ↗</a>` : ''}
|
<a href="${course.main_link}" target="_blank" class="hub-link">Hub ↗</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function renderKanban() {
|
async function renderKanban() {
|
||||||
// Find the section by its title
|
// Look for the main services grid - this is our insertion point
|
||||||
const sections = document.querySelectorAll('section');
|
const servicesGrid = document.getElementById('services');
|
||||||
let container = null;
|
if (!servicesGrid) return;
|
||||||
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;
|
// Check if we already created our section
|
||||||
|
let section = document.getElementById('hp-learning-hub-section');
|
||||||
|
|
||||||
// Target the list area (usually follows the h2)
|
if (!section) {
|
||||||
const listArea = container.querySelector('ul') || container.querySelector('.grid') || container.lastElementChild;
|
section = document.createElement('section');
|
||||||
if (!listArea) return;
|
section.id = 'hp-learning-hub-section';
|
||||||
|
section.className = 'hp-kanban-section';
|
||||||
|
// Insert after services grid
|
||||||
|
servicesGrid.after(section);
|
||||||
|
|
||||||
// Replace the entire list area with our board
|
section.innerHTML = `
|
||||||
listArea.outerHTML = `
|
<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-board">
|
||||||
<div class="hp-kanban-col" data-status="WIP">
|
<div class="hp-kanban-col" data-status="WIP">
|
||||||
<h3>🚀 In Progress</h3>
|
<h3>🚀 In Progress</h3>
|
||||||
@@ -91,18 +92,25 @@ async function renderKanban() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
injectModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
await refreshBoardContent(section);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshBoardContent(section) {
|
||||||
const courses = await fetchCourses();
|
const courses = await fetchCourses();
|
||||||
const board = container.querySelector('.hp-kanban-board');
|
const board = section.querySelector('.hp-kanban-board');
|
||||||
|
if (!board) return;
|
||||||
|
|
||||||
|
board.querySelectorAll('.hp-kanban-list').forEach(l => l.innerHTML = '');
|
||||||
|
|
||||||
courses.forEach(course => {
|
courses.forEach(course => {
|
||||||
const col = board.querySelector(`.hp-kanban-col[data-status="${course.status}"] .hp-kanban-list`);
|
const list = board.querySelector(`.hp-kanban-col[data-status="${course.status}"] .hp-kanban-list`);
|
||||||
if (col) {
|
if (list) list.innerHTML += createKanbanCard(course);
|
||||||
col.innerHTML += createKanbanCard(course);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add Drag & Drop Listeners
|
// Re-bind Drag & Drop
|
||||||
const cards = board.querySelectorAll('.hp-kanban-card');
|
const cards = board.querySelectorAll('.hp-kanban-card');
|
||||||
cards.forEach(card => {
|
cards.forEach(card => {
|
||||||
card.addEventListener('dragstart', (e) => {
|
card.addEventListener('dragstart', (e) => {
|
||||||
@@ -119,22 +127,111 @@ async function renderKanban() {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const id = e.dataTransfer.getData('text/plain');
|
const id = e.dataTransfer.getData('text/plain');
|
||||||
const status = col.dataset.status;
|
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);
|
await updateCourseStatus(id, status);
|
||||||
renderKanban(); // Re-render
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial detection and observer for React re-renders
|
// 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;
|
let debounceTimer;
|
||||||
const observer = new MutationObserver(() => {
|
const observer = new MutationObserver(() => {
|
||||||
clearTimeout(debounceTimer);
|
clearTimeout(debounceTimer);
|
||||||
debounceTimer = setTimeout(() => {
|
debounceTimer = setTimeout(() => {
|
||||||
const target = document.querySelector('h2');
|
const servicesGrid = document.getElementById('services');
|
||||||
if (target && !document.querySelector('.hp-kanban-board')) {
|
if (servicesGrid && !document.getElementById('hp-learning-hub-section')) {
|
||||||
renderKanban();
|
renderKanban();
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
observer.observe(document.body, { childList: true, subtree: true });
|
observer.observe(document.body, { childList: true, subtree: true });
|
||||||
|
|||||||
@@ -52,10 +52,3 @@
|
|||||||
description: Diagramming Tool
|
description: Diagramming Tool
|
||||||
server: my-docker
|
server: my-docker
|
||||||
container: mermaid-live-editor
|
container: mermaid-live-editor
|
||||||
|
|
||||||
# # Kanban Board Anchor
|
|
||||||
# - Learning Hub:
|
|
||||||
# - Placeholder:
|
|
||||||
# icon: bookshelf.png
|
|
||||||
# href: #
|
|
||||||
# description: "This will be replaced by the Kanban board"
|
|
||||||
@@ -5,8 +5,7 @@
|
|||||||
- resources:
|
- resources:
|
||||||
cpu: true
|
cpu: true
|
||||||
memory: true
|
memory: true
|
||||||
disk: /
|
|
||||||
|
|
||||||
- search:
|
- search:
|
||||||
provider: duckduckgo
|
provider: google
|
||||||
target: _blank
|
target: _blank
|
||||||
@@ -5,6 +5,7 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- ./config:/app/config
|
- ./config:/app/config
|
||||||
|
- /home:/home:ro
|
||||||
environment:
|
environment:
|
||||||
- HOMEPAGE_ALLOWED_HOSTS=arch-services.mywire.org
|
- HOMEPAGE_ALLOWED_HOSTS=arch-services.mywire.org
|
||||||
networks:
|
networks:
|
||||||
@@ -17,14 +18,13 @@ services:
|
|||||||
- "traefik.http.routers.homepage.entrypoints=websecure"
|
- "traefik.http.routers.homepage.entrypoints=websecure"
|
||||||
- "traefik.http.routers.homepage.tls=true"
|
- "traefik.http.routers.homepage.tls=true"
|
||||||
|
|
||||||
# Public (Redirect) - "traefik.http.routers.homepage-red.rule=Host(`arch-services.mywire.org`)"
|
# Public (Redirect)
|
||||||
|
- "traefik.http.routers.homepage-red.rule=Host(`arch-services.mywire.org`)"
|
||||||
- "traefik.http.routers.homepage-red.entrypoints=web"
|
- "traefik.http.routers.homepage-red.entrypoints=web"
|
||||||
- "traefik.http.routers.homepage-red.middlewares=https-redirect@docker"
|
- "traefik.http.routers.homepage-red.middlewares=https-redirect@docker"
|
||||||
|
|
||||||
# Local (HTTP)
|
# Local (HTTP)
|
||||||
- "traefik.http.routers.homepage-local.rule=Host(`homepage.localhost`) || Host(`dashboard.localhost`) || Host(`localhost`)"
|
- "traefik.http.routers.homepage-local.rule=Host(`homepage.localhost`) || Host(`dashboard.localhost`) || Host(`localhost`)"
|
||||||
|
|
||||||
|
|
||||||
- "traefik.http.routers.homepage-local.entrypoints=web"
|
- "traefik.http.routers.homepage-local.entrypoints=web"
|
||||||
|
|
||||||
- "traefik.http.services.homepage.loadbalancer.server.port=3000"
|
- "traefik.http.services.homepage.loadbalancer.server.port=3000"
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ from typing import List, Optional
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
import uvicorn
|
import uvicorn
|
||||||
import os
|
import os
|
||||||
|
import psutil
|
||||||
|
import docker
|
||||||
|
|
||||||
from . import models, database
|
from . import models, database
|
||||||
|
|
||||||
@@ -15,6 +17,12 @@ models.Base.metadata.create_all(bind=database.engine)
|
|||||||
|
|
||||||
app = FastAPI(title="Learning Hub API")
|
app = FastAPI(title="Learning Hub API")
|
||||||
|
|
||||||
|
# Initialize Docker client
|
||||||
|
try:
|
||||||
|
docker_client = docker.from_env()
|
||||||
|
except Exception:
|
||||||
|
docker_client = None
|
||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["*"],
|
allow_origins=["*"],
|
||||||
@@ -46,6 +54,64 @@ class Course(CourseBase):
|
|||||||
class Config:
|
class Config:
|
||||||
from_attributes = True
|
from_attributes = True
|
||||||
|
|
||||||
|
@app.get("/api/system-stats")
|
||||||
|
def get_system_stats():
|
||||||
|
cpu = psutil.cpu_percent(interval=None) # Use None for non-blocking if called frequently
|
||||||
|
ram = psutil.virtual_memory()
|
||||||
|
# Monitor /home partition
|
||||||
|
disk_path = '/home' if os.path.exists('/home') else '/'
|
||||||
|
disk = psutil.disk_usage(disk_path)
|
||||||
|
return {
|
||||||
|
"cpu": cpu,
|
||||||
|
"ram_total": round(ram.total / (1024**3), 2),
|
||||||
|
"ram_used": round(ram.used / (1024**3), 2),
|
||||||
|
"ram_percent": ram.percent,
|
||||||
|
"disk_total": round(disk.total / (1024**3), 2),
|
||||||
|
"disk_used": round(disk.used / (1024**3), 2),
|
||||||
|
"disk_percent": disk.percent
|
||||||
|
}
|
||||||
|
|
||||||
|
@app.get("/api/services")
|
||||||
|
def get_services():
|
||||||
|
services_config = {
|
||||||
|
"infrastructure": [
|
||||||
|
{"name": "Traefik", "container": "traefik", "href": "https://traefik.arch-services.mywire.org"},
|
||||||
|
{"name": "Authelia", "container": "authelia", "href": "https://auth.arch-services.mywire.org"},
|
||||||
|
{"name": "Portainer", "container": "portainer", "href": "https://portainer.arch-services.mywire.org"},
|
||||||
|
{"name": "Dozzle", "container": "dozzle", "href": "https://logs.arch-services.mywire.org"},
|
||||||
|
],
|
||||||
|
"applications": [
|
||||||
|
{"name": "Gitea", "container": "gitea", "href": "https://gitea.arch-services.mywire.org"},
|
||||||
|
{"name": "Ollama", "container": "ollama-ollama-1", "href": "https://ollama.arch-services.mywire.org"},
|
||||||
|
{"name": "Excalidraw", "container": "excalidraw-excalidraw-1", "href": "https://excalidraw.arch-services.mywire.org"},
|
||||||
|
{"name": "Mermaid", "container": "mermaid-live-editor", "href": "https://mermaid.arch-services.mywire.org"},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
results = {"infrastructure": [], "applications": []}
|
||||||
|
|
||||||
|
if not docker_client:
|
||||||
|
return services_config
|
||||||
|
|
||||||
|
for category in services_config:
|
||||||
|
for s in services_config[category]:
|
||||||
|
try:
|
||||||
|
container = docker_client.containers.get(s["container"])
|
||||||
|
status = container.status
|
||||||
|
except Exception:
|
||||||
|
status = "unknown"
|
||||||
|
results[category].append({**s, "status": status})
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
@app.get("/api/bookmarks")
|
||||||
|
def get_bookmarks():
|
||||||
|
return {
|
||||||
|
"Developer": [{"name": "Github", "href": "https://github.com/"}],
|
||||||
|
"Social": [{"name": "Reddit", "href": "https://reddit.com/"}],
|
||||||
|
"Entertainment": [{"name": "YouTube", "href": "https://youtube.com/"}]
|
||||||
|
}
|
||||||
|
|
||||||
@app.get("/api/courses", response_model=List[Course])
|
@app.get("/api/courses", response_model=List[Course])
|
||||||
def read_courses(db: Session = Depends(get_db)):
|
def read_courses(db: Session = Depends(get_db)):
|
||||||
return db.query(models.Course).all()
|
return db.query(models.Course).all()
|
||||||
@@ -109,8 +175,10 @@ def startup_event():
|
|||||||
db.commit()
|
db.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
# Serves CSS/JS and index
|
# Deprecated standalone UI - Serving only API
|
||||||
app.mount("/", StaticFiles(directory="app/static", html=True), name="static")
|
@app.get("/")
|
||||||
|
def read_root():
|
||||||
|
return {"message": "Learning Hub API is running. Use the main dashboard to access the Kanban board."}
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
||||||
@@ -5,8 +5,10 @@ services:
|
|||||||
working_dir: /app
|
working_dir: /app
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app
|
- .:/app
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
- /home:/home:ro
|
||||||
command: >
|
command: >
|
||||||
sh -c "pip install fastapi uvicorn sqlalchemy && python -m app.main"
|
sh -c "pip install fastapi uvicorn sqlalchemy psutil docker && python -m app.main"
|
||||||
networks:
|
networks:
|
||||||
- proxy-net
|
- proxy-net
|
||||||
labels:
|
labels:
|
||||||
@@ -15,7 +17,6 @@ services:
|
|||||||
- "traefik.http.routers.learning.rule=Host(`learning.arch-services.mywire.org`)"
|
- "traefik.http.routers.learning.rule=Host(`learning.arch-services.mywire.org`)"
|
||||||
- "traefik.http.routers.learning.entrypoints=websecure"
|
- "traefik.http.routers.learning.entrypoints=websecure"
|
||||||
- "traefik.http.routers.learning.tls=true"
|
- "traefik.http.routers.learning.tls=true"
|
||||||
- "traefik.http.routers.learning.middlewares=authelia-auth@docker"
|
|
||||||
|
|
||||||
# Public (Redirect)
|
# Public (Redirect)
|
||||||
- "traefik.http.routers.learning-red.rule=Host(`learning.arch-services.mywire.org`)"
|
- "traefik.http.routers.learning-red.rule=Host(`learning.arch-services.mywire.org`)"
|
||||||
|
|||||||
Reference in new issue
Block a user