feat(PORT-004A): add workspace bootstrap and scoped settings
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import Request
|
||||
from fastapi.responses import RedirectResponse
|
||||
from nicegui import ui
|
||||
|
||||
from app.models.portfolio import PortfolioConfig, get_portfolio_repository
|
||||
from app.models.portfolio import PortfolioConfig
|
||||
from app.models.workspace import WORKSPACE_COOKIE, get_workspace_repository
|
||||
from app.pages.common import dashboard_page
|
||||
from app.services.alerts import AlertService, build_portfolio_alert_context
|
||||
from app.services.settings_status import save_status_text
|
||||
@@ -16,11 +19,40 @@ def _alert_badge_classes(severity: str) -> str:
|
||||
}.get(severity, "rounded-full bg-slate-100 px-3 py-1 text-xs font-semibold text-slate-700")
|
||||
|
||||
|
||||
def _render_workspace_recovery() -> None:
|
||||
with ui.column().classes("mx-auto mt-24 w-full max-w-2xl gap-6 px-6 text-center"):
|
||||
ui.icon("folder_off").classes("mx-auto text-6xl text-slate-400")
|
||||
ui.label("Workspace not found").classes("text-3xl font-bold text-slate-900 dark:text-slate-50")
|
||||
ui.label(
|
||||
"The requested workspace is unavailable. Start a new workspace or return to the welcome page."
|
||||
).classes("text-base text-slate-500 dark:text-slate-400")
|
||||
with ui.row().classes("mx-auto gap-3"):
|
||||
ui.link("Get started", "/workspaces/bootstrap").classes(
|
||||
"rounded-lg bg-slate-900 px-5 py-3 text-sm font-semibold text-white no-underline dark:bg-slate-100 dark:text-slate-900"
|
||||
)
|
||||
ui.link("Go to welcome page", "/").classes(
|
||||
"rounded-lg border border-slate-300 px-5 py-3 text-sm font-semibold text-slate-700 no-underline dark:border-slate-700 dark:text-slate-200"
|
||||
)
|
||||
|
||||
|
||||
@ui.page("/settings")
|
||||
def settings_page() -> None:
|
||||
"""Settings page with persistent portfolio configuration."""
|
||||
repo = get_portfolio_repository()
|
||||
config = repo.load()
|
||||
def legacy_settings_page(request: Request):
|
||||
repo = get_workspace_repository()
|
||||
workspace_id = request.cookies.get(WORKSPACE_COOKIE, "")
|
||||
if workspace_id and repo.workspace_exists(workspace_id):
|
||||
return RedirectResponse(url=f"/{workspace_id}/settings", status_code=307)
|
||||
return RedirectResponse(url="/", status_code=307)
|
||||
|
||||
|
||||
@ui.page("/{workspace_id}/settings")
|
||||
def settings_page(workspace_id: str) -> None:
|
||||
"""Settings page with workspace-scoped persistent portfolio configuration."""
|
||||
workspace_repo = get_workspace_repository()
|
||||
if not workspace_repo.workspace_exists(workspace_id):
|
||||
_render_workspace_recovery()
|
||||
return
|
||||
|
||||
config = workspace_repo.load_portfolio_config(workspace_id)
|
||||
alert_service = AlertService()
|
||||
|
||||
syncing_entry_basis = False
|
||||
@@ -61,6 +93,7 @@ def settings_page() -> None:
|
||||
"Settings",
|
||||
"Configure portfolio assumptions, collateral entry basis, preferred market data inputs, and alert thresholds.",
|
||||
"settings",
|
||||
workspace_id=workspace_id,
|
||||
):
|
||||
with ui.row().classes("w-full gap-6 max-lg:flex-col"):
|
||||
with ui.card().classes(
|
||||
@@ -326,7 +359,7 @@ def settings_page() -> None:
|
||||
def save_settings() -> None:
|
||||
try:
|
||||
new_config = build_preview_config()
|
||||
repo.save(new_config)
|
||||
workspace_repo.save_portfolio_config(workspace_id, new_config)
|
||||
render_alert_state()
|
||||
|
||||
status.set_text(save_status_text(new_config))
|
||||
|
||||
Reference in New Issue
Block a user