diff --git a/apps/homepage/config/custom.css b/apps/homepage/config/custom.css index 826bac0..e36f34a 100644 --- a/apps/homepage/config/custom.css +++ b/apps/homepage/config/custom.css @@ -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 { display: flex; gap: 20px; @@ -10,35 +31,39 @@ background: rgba(15, 23, 42, 0.4); border: 1px solid rgba(51, 65, 85, 0.3); border-radius: 12px; - padding: 15px; - min-height: 220px; + padding: 20px; + min-height: 600px; /* Enforce min height for 3-4 courses */ backdrop-filter: blur(4px); + display: flex; + flex-direction: column; } .hp-kanban-col h3 { - font-size: 0.7rem; - margin: 0 0 12px 0; + font-size: 0.9rem !important; + margin: 0 0 1.5rem 0 !important; text-transform: uppercase; - color: #94a3b8; + color: #f1f5f9; text-align: center; letter-spacing: 0.1em; - font-weight: 800; - opacity: 0.8; + font-weight: 700; + padding-bottom: 0.5rem; + border-bottom: 2px solid rgba(56, 189, 248, 0.3); } .hp-kanban-list { display: flex; flex-direction: column; - gap: 10px; - min-height: 150px; + gap: 12px; + flex: 1; } .hp-kanban-card { background: rgba(30, 41, 59, 0.8); border: 1px solid rgba(51, 65, 85, 0.5); border-radius: 8px; - padding: 12px; + padding: 15px; cursor: grab; + position: relative; transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); } @@ -50,44 +75,137 @@ } .hp-kanban-card-title { - font-size: 0.85rem; + font-size: 0.95rem; font-weight: 700; - margin-bottom: 4px; + margin-bottom: 6px; color: #f8fafc; + padding-right: 40px; } .hp-kanban-card-desc { - font-size: 0.75rem; + font-size: 0.8rem; color: #94a3b8; - margin-bottom: 10px; - line-height: 1.3; + margin-bottom: 12px; + line-height: 1.4; } .hp-kanban-card-links { display: flex; - gap: 12px; + flex-direction: column; + gap: 8px; border-top: 1px solid rgba(51, 65, 85, 0.3); - padding-top: 8px; - font-size: 0.7rem; + padding-top: 10px; } .hp-kanban-card-links a { - color: #60a5fa; text-decoration: none; font-weight: 600; + font-size: 0.75rem; + padding: 4px 8px; + border-radius: 4px; + text-align: center; } -.hp-kanban-card-links a:hover { - text-decoration: underline; +.milestone-link { + 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 { opacity: 0.1; transform: scale(0.9); } -/* Hide the placeholder card that we use to spawn the section */ -section h2[title="Learning Hub"] + ul, -section h2[title="Learning Hub"] + .grid { +.hp-kanban-card-actions { + position: absolute; + 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; } diff --git a/apps/homepage/config/custom.js b/apps/homepage/config/custom.js index 96094cf..d778508 100644 --- a/apps/homepage/config/custom.js +++ b/apps/homepage/config/custom.js @@ -1,5 +1,5 @@ /** - * Learning Kanban Native Integration for Homepage + * Learning Kanban Native Integration for Homepage (v4 - Autonomous & Anchorless) */ function getApiBase() { @@ -11,27 +11,25 @@ function getApiBase() { } const API_BASE = getApiBase(); +let allCourses = []; async function fetchCourses() { try { const response = await fetch(`${API_BASE}/api/courses`); - if (!response.ok) return []; - return await response.json(); + if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); + allCourses = await response.json(); + return allCourses; } catch (e) { - console.error("Failed to fetch courses", e); + console.warn("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); + 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' }, @@ -45,64 +43,74 @@ async function updateCourseStatus(courseId, newStatus) { function createKanbanCard(course) { return `
+
+ + +
${course.title}
${course.description || ''}
`; } 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; - } - } + // 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 (!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 = ` -
-
-

🚀 In Progress

-
+ 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 = ` +
+

Learning Hub

+
-
-

📅 Planning

-
+
+
+

🚀 In Progress

+
+
+
+

📅 Planning

+
+
+
+

📦 Archive

+
+
-
-

📦 Archive

-
-
-
- `; + `; + injectModal(); + } + await refreshBoardContent(section); +} + +async function refreshBoardContent(section) { 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 => { - const col = board.querySelector(`.hp-kanban-col[data-status="${course.status}"] .hp-kanban-list`); - if (col) { - col.innerHTML += createKanbanCard(course); - } + const list = board.querySelector(`.hp-kanban-col[data-status="${course.status}"] .hp-kanban-list`); + if (list) list.innerHTML += createKanbanCard(course); }); - // Add Drag & Drop Listeners + // Re-bind Drag & Drop const cards = board.querySelectorAll('.hp-kanban-card'); cards.forEach(card => { card.addEventListener('dragstart', (e) => { @@ -119,22 +127,111 @@ async function renderKanban() { 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); - 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 = ` +
+
+

Add Course

+
+ +
+
+
+
+
+ +
+
+ + +
+
+
+
+ `; + 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 target = document.querySelector('h2'); - if (target && !document.querySelector('.hp-kanban-board')) { + const servicesGrid = document.getElementById('services'); + if (servicesGrid && !document.getElementById('hp-learning-hub-section')) { renderKanban(); } - }, 200); + }, 500); }); observer.observe(document.body, { childList: true, subtree: true }); diff --git a/apps/homepage/config/services.yaml b/apps/homepage/config/services.yaml index 8d207c9..2506fa9 100644 --- a/apps/homepage/config/services.yaml +++ b/apps/homepage/config/services.yaml @@ -52,10 +52,3 @@ description: Diagramming Tool server: my-docker container: mermaid-live-editor - -# # Kanban Board Anchor -# - Learning Hub: -# - Placeholder: -# icon: bookshelf.png -# href: # -# description: "This will be replaced by the Kanban board" diff --git a/apps/homepage/config/widgets.yaml b/apps/homepage/config/widgets.yaml index b1cf0f5..f195daf 100644 --- a/apps/homepage/config/widgets.yaml +++ b/apps/homepage/config/widgets.yaml @@ -5,8 +5,7 @@ - resources: cpu: true memory: true - disk: / - search: - provider: duckduckgo + provider: google target: _blank diff --git a/apps/homepage/docker-compose.yml b/apps/homepage/docker-compose.yml index 5a271d6..cc7c641 100644 --- a/apps/homepage/docker-compose.yml +++ b/apps/homepage/docker-compose.yml @@ -5,6 +5,7 @@ services: restart: always volumes: - ./config:/app/config + - /home:/home:ro environment: - HOMEPAGE_ALLOWED_HOSTS=arch-services.mywire.org networks: @@ -17,14 +18,13 @@ services: - "traefik.http.routers.homepage.entrypoints=websecure" - "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.middlewares=https-redirect@docker" # Local (HTTP) - "traefik.http.routers.homepage-local.rule=Host(`homepage.localhost`) || Host(`dashboard.localhost`) || Host(`localhost`)" - - - "traefik.http.routers.homepage-local.entrypoints=web" - "traefik.http.services.homepage.loadbalancer.server.port=3000" diff --git a/apps/learning/app/main.py b/apps/learning/app/main.py index 932eb81..d9d861f 100644 --- a/apps/learning/app/main.py +++ b/apps/learning/app/main.py @@ -7,6 +7,8 @@ from typing import List, Optional from pydantic import BaseModel import uvicorn import os +import psutil +import docker from . import models, database @@ -15,6 +17,12 @@ models.Base.metadata.create_all(bind=database.engine) app = FastAPI(title="Learning Hub API") +# Initialize Docker client +try: + docker_client = docker.from_env() +except Exception: + docker_client = None + app.add_middleware( CORSMiddleware, allow_origins=["*"], @@ -46,6 +54,64 @@ class Course(CourseBase): class Config: 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]) def read_courses(db: Session = Depends(get_db)): return db.query(models.Course).all() @@ -109,8 +175,10 @@ def startup_event(): db.commit() db.close() -# Serves CSS/JS and index -app.mount("/", StaticFiles(directory="app/static", html=True), name="static") +# Deprecated standalone UI - Serving only API +@app.get("/") +def read_root(): + return {"message": "Learning Hub API is running. Use the main dashboard to access the Kanban board."} if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/apps/learning/docker-compose.yml b/apps/learning/docker-compose.yml index 4a0a939..9c82ab7 100644 --- a/apps/learning/docker-compose.yml +++ b/apps/learning/docker-compose.yml @@ -5,8 +5,10 @@ services: working_dir: /app volumes: - .:/app + - /var/run/docker.sock:/var/run/docker.sock + - /home:/home:ro 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: - proxy-net labels: @@ -15,7 +17,6 @@ services: - "traefik.http.routers.learning.rule=Host(`learning.arch-services.mywire.org`)" - "traefik.http.routers.learning.entrypoints=websecure" - "traefik.http.routers.learning.tls=true" - - "traefik.http.routers.learning.middlewares=authelia-auth@docker" # Public (Redirect) - "traefik.http.routers.learning-red.rule=Host(`learning.arch-services.mywire.org`)"