fix: Library preserves sidebar tree and categorizes by parent_section
- Sidebar data (board._sidebar_data()) no longer overwritten by library content - New variables: lib_recent, lib_favorites, lib_shared, lib_private - Pages categorized by parent_section column: Private/Favorites/Shared - Recents tab shows all non-trashed pages ordered by updated_at - library.html updated to use lib_* variables instead of sidebar data - Favorites/Shared tabs hidden when empty (lib_has_favorites/lib_has_shared)
This commit is contained in:
+38
-28
@@ -71,42 +71,52 @@ async def trash_page(request: Request, owner: str = Query(default=""), repo: str
|
||||
|
||||
@router.get("/library", response_class=HTMLResponse)
|
||||
async def library_page(request: Request, owner: str = Query(default=""), repo: str = Query(default="")):
|
||||
"""Library page avec onglets Recents, Favorites, Shared, Private — scopé au workspace."""
|
||||
"""Library page avec onglets Recents, Favorites, Shared, Private — scopé au workspace.
|
||||
|
||||
La sidebar garde exactement la même arborescence que dans le workspace.
|
||||
Seul le contenu principal change pour afficher les pages triées par catégorie.
|
||||
"""
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
from app.routers.board import _sidebar_data as board_sidebar
|
||||
env = Environment(loader=FileSystemLoader("app/templates"))
|
||||
sidebar = board_sidebar(request, owner, repo)
|
||||
# Load all pages for the workspace from DB
|
||||
sidebar = board_sidebar(request, owner, repo) # Sidebar intacte, inchangée
|
||||
|
||||
ws_key = f"{owner}/{repo}" if owner and repo else ""
|
||||
with get_conn() as conn:
|
||||
base_query = (
|
||||
"SELECT id, title, workspace, parent_section, updated_at FROM pages "
|
||||
"WHERE parent_section != 'Trash'"
|
||||
)
|
||||
params = []
|
||||
if ws_key:
|
||||
rows = conn.execute(
|
||||
"SELECT id, title, workspace, updated_at FROM pages "
|
||||
"WHERE workspace=? ORDER BY updated_at DESC",
|
||||
(ws_key,),
|
||||
).fetchall()
|
||||
else:
|
||||
rows = conn.execute(
|
||||
"SELECT id, title, workspace, updated_at FROM pages "
|
||||
"ORDER BY updated_at DESC",
|
||||
).fetchall()
|
||||
all_pages = []
|
||||
for r in rows:
|
||||
page = dict(r)
|
||||
all_pages.append({
|
||||
"id": f"page/{page['id']}",
|
||||
"name": page["title"] or "Untitled",
|
||||
base_query += " AND workspace=?"
|
||||
params.append(ws_key)
|
||||
base_query += " ORDER BY updated_at DESC"
|
||||
rows = conn.execute(base_query, params).fetchall()
|
||||
|
||||
def to_page(r):
|
||||
r = dict(r)
|
||||
return {
|
||||
"id": f"page/{r['id']}",
|
||||
"name": r["title"] or "Untitled",
|
||||
"icon": "📄",
|
||||
"url": f"/pages/{page['id']}",
|
||||
"url": f"/pages/{r['id']}",
|
||||
"created_by": "You",
|
||||
"source": page.get("workspace") or "🔒 Private",
|
||||
"last_edited": page.get("updated_at", "now"),
|
||||
"last_visited": page.get("updated_at", "now"),
|
||||
})
|
||||
sidebar["recent_pages"] = all_pages
|
||||
sidebar["favorite_pages"] = []
|
||||
sidebar["private_pages"] = [p for p in all_pages if p.get("source") == "🔒 Private"]
|
||||
sidebar["shared_pages"] = []
|
||||
"source": r.get("workspace") or "🔒 Private",
|
||||
"last_edited": r.get("updated_at", "now"),
|
||||
"last_visited": r.get("updated_at", "now"),
|
||||
}
|
||||
|
||||
all_pages = [to_page(r) for r in rows]
|
||||
|
||||
# Catégoriser par parent_section — sidebar data intacte
|
||||
sidebar["lib_recent"] = all_pages
|
||||
sidebar["lib_favorites"] = [p for p, r in zip(all_pages, rows) if (r["parent_section"] or "") == "Favorites"]
|
||||
sidebar["lib_shared"] = [p for p, r in zip(all_pages, rows) if (r["parent_section"] or "") == "Shared"]
|
||||
sidebar["lib_private"] = [p for p, r in zip(all_pages, rows) if (r["parent_section"] or "Private") == "Private"]
|
||||
sidebar["lib_has_favorites"] = len(sidebar["lib_favorites"]) > 0
|
||||
sidebar["lib_has_shared"] = len(sidebar["lib_shared"]) > 0
|
||||
|
||||
template = env.get_template("library.html")
|
||||
return template.render(**sidebar)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user