diff --git a/packetserver/http/routers/dashboard.py b/packetserver/http/routers/dashboard.py new file mode 100644 index 0000000..449ef5e --- /dev/null +++ b/packetserver/http/routers/dashboard.py @@ -0,0 +1,22 @@ +# packetserver/http/routers/dashboard.py +from fastapi import APIRouter, Depends, Request +from fastapi.responses import HTMLResponse + +from packetserver.http.dependencies import get_current_http_user +from packetserver.http.auth import HttpUser +from packetserver.http.server import templates # for TemplateResponse + +router = APIRouter(tags=["dashboard"]) + + +@router.get("/dashboard", response_class=HTMLResponse) +async def dashboard(request: Request, current_user: HttpUser = Depends(get_current_http_user)): + # Fetch messages via internal API call (reuse list logic) + from packetserver.http.routers.messages import get_messages as api_get_messages + messages_resp = await api_get_messages(current_user=current_user, type="all", limit=100) + messages = messages_resp["messages"] + + return templates.TemplateResponse( + "dashboard.html", + {"request": request, "current_user": current_user.username, "messages": messages} + ) \ No newline at end of file diff --git a/packetserver/http/server.py b/packetserver/http/server.py index 5a50264..e789347 100644 --- a/packetserver/http/server.py +++ b/packetserver/http/server.py @@ -4,7 +4,7 @@ from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates from pathlib import Path -from .routers import public, profile, messages, send +from .routers import public, profile, messages, send # dashboard removed for now BASE_DIR = Path(__file__).parent.resolve() @@ -14,12 +14,18 @@ app = FastAPI( version="0.1.0", ) -# Static and templates -app.mount("/static", StaticFiles(directory=BASE_DIR / "static"), name="static") +# Define templates EARLY (before importing dashboard) templates = Jinja2Templates(directory=BASE_DIR / "templates") +# Static files +app.mount("/static", StaticFiles(directory=BASE_DIR / "static"), name="static") + +# Now safe to import dashboard (it needs templates) +from .routers import dashboard # add this line + # Include routers app.include_router(public.router) app.include_router(profile.router) app.include_router(messages.router) -app.include_router(send.router) \ No newline at end of file +app.include_router(send.router) +app.include_router(dashboard.router) # now works \ No newline at end of file diff --git a/packetserver/http/templates/base.html b/packetserver/http/templates/base.html new file mode 100644 index 0000000..c47a389 --- /dev/null +++ b/packetserver/http/templates/base.html @@ -0,0 +1,29 @@ + + + + + + {% block title %}PacketServer Dashboard{% endblock %} + + {# optional custom #} + + + + +
+ {% block content %}{% endblock %} +
+ + + {% block scripts %}{% endblock %} + + \ No newline at end of file diff --git a/packetserver/http/templates/dashboard.html b/packetserver/http/templates/dashboard.html new file mode 100644 index 0000000..1f2869b --- /dev/null +++ b/packetserver/http/templates/dashboard.html @@ -0,0 +1,98 @@ +{% extends "base.html" %} + +{% block title %}Dashboard - {{ current_user }}{% endblock %} + +{% block content %} +

Messages

+ + + + + + + + + + + + + + + + + + {% for msg in messages %} + + + + + + + + {% else %} + + {% endfor %} + +
FromToPreviewDateRead
{{ msg.from }}{{ msg.to | join(', ') }}{{ msg.text | truncate(60) | escape }}{{ msg.sent_at | replace('Z', '') }}{% if msg.retrieved %}{% else %}{% endif %}
No messages
+{% endblock %} + +{% block scripts %} + +{% endblock %} \ No newline at end of file