53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
"""Frontend module for NiceGUI with FastAPI integration.
|
|
|
|
This module provides the NiceGUI frontend that can be initialized with a FastAPI app.
|
|
The dashboard shown is from dashboard_ui.py with real-time database data.
|
|
"""
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import RedirectResponse
|
|
|
|
from nicegui import app, ui
|
|
|
|
try:
|
|
from .dashboard_ui import create_dashboard, create_health_page
|
|
except ImportError:
|
|
from dashboard_ui import create_dashboard, create_health_page
|
|
|
|
|
|
def init(fastapi_app: FastAPI, storage_secret: str = 'Secr2t!') -> None:
|
|
"""Initialize the NiceGUI frontend with the FastAPI app.
|
|
|
|
Args:
|
|
fastapi_app: The FastAPI application instance.
|
|
storage_secret: Optional secret for persistent user storage.
|
|
"""
|
|
|
|
def render_dashboard_page() -> None:
|
|
ui.page_title('AI Software Factory')
|
|
create_dashboard()
|
|
|
|
# NOTE dark mode will be persistent for each user across tabs and server restarts
|
|
ui.dark_mode().bind_value(app.storage.user, 'dark_mode')
|
|
ui.checkbox('dark mode').bind_value(app.storage.user, 'dark_mode')
|
|
|
|
@ui.page('/')
|
|
def home() -> None:
|
|
render_dashboard_page()
|
|
|
|
@ui.page('/show')
|
|
def show() -> None:
|
|
render_dashboard_page()
|
|
|
|
@ui.page('/health-ui')
|
|
def health_ui() -> None:
|
|
create_health_page()
|
|
|
|
@fastapi_app.get('/dashboard', include_in_schema=False)
|
|
def dashboard_redirect() -> RedirectResponse:
|
|
return RedirectResponse(url='/', status_code=307)
|
|
|
|
ui.run_with(
|
|
fastapi_app,
|
|
storage_secret=storage_secret, # NOTE setting a secret is optional but allows for persistent storage per user
|
|
) |