fix: workspace name shows even empty, folders vs files, delete button
- dashboard.py _sidebar_data now reads active workspace cookie - Workspace name always displays (even with 0 pages) - Folders stored with parent_section='Workspace' (icon 📁) - Files stored with parent_section='Private' (icon 📄) - Delete button uses @click directive (not onclick app.) - workspace_pages loaded in dashboard's _sidebar_data
This commit is contained in:
@@ -148,10 +148,11 @@ def _load_workspace_pages(ws_cookie: str) -> list:
|
||||
ws_id = int(ws_cookie)
|
||||
with get_conn() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT id, title FROM pages WHERE workspace_id=? AND parent_id IS NULL ORDER BY created_at DESC",
|
||||
"SELECT id, title, parent_section FROM pages WHERE workspace_id=? AND parent_id IS NULL ORDER BY created_at DESC",
|
||||
(ws_id,),
|
||||
).fetchall()
|
||||
return [{"db_id": r["id"], "name": r["title"] or "Untitled", "id": f"page/{r['id']}"} for r in rows]
|
||||
return [{"db_id": r["id"], "name": r["title"] or "Untitled", "id": f"page/{r['id']}",
|
||||
"icon": "📁" if r.get("parent_section") == "Workspace" else "📄"} for r in rows]
|
||||
except (ValueError, Exception):
|
||||
return []
|
||||
|
||||
|
||||
@@ -51,12 +51,30 @@ def _sidebar_data(request: Request, repos: list[dict]) -> dict:
|
||||
"children": [],
|
||||
})
|
||||
|
||||
# Active workspace from cookie
|
||||
from app.routers.board import _load_workspace_pages
|
||||
ws_cookie = request.cookies.get("flowdeck_workspace", "")
|
||||
active_ws_name = "Workspace"
|
||||
workspace_pages = []
|
||||
if ws_cookie:
|
||||
workspace_pages = _load_workspace_pages(ws_cookie)
|
||||
try:
|
||||
with get_conn() as conn:
|
||||
ws_row = conn.execute("SELECT name FROM workspaces WHERE id=?", (int(ws_cookie),)).fetchone()
|
||||
if ws_row:
|
||||
active_ws_name = ws_row["name"]
|
||||
except (ValueError, Exception):
|
||||
pass
|
||||
|
||||
return {
|
||||
"workspace_name": ws, "workspace_initial": initial,
|
||||
"active_ws_name": active_ws_name,
|
||||
"workspace_pages": workspace_pages,
|
||||
"current_page": "Dashboard", "last_edited": "now",
|
||||
"recent_pages": recent_pages,
|
||||
"private_pages": [],
|
||||
"favorite_pages": [],
|
||||
"shared_pages": [],
|
||||
"user": user,
|
||||
"workspace_key": "",
|
||||
}
|
||||
@@ -524,17 +542,19 @@ async def create_local_workspace_item(request: Request):
|
||||
import json
|
||||
body = await request.json()
|
||||
name = body.get("name", "Untitled").strip()
|
||||
item_type = body.get("type", "page")
|
||||
ws = _get_active_workspace(request)
|
||||
ws_id = ws["id"] if ws else None
|
||||
section = 'Workspace' if item_type == 'folder' else 'Private'
|
||||
with get_conn() as conn:
|
||||
cursor = conn.execute(
|
||||
"INSERT INTO pages (workspace, workspace_id, title, content, content_format, parent_section) "
|
||||
"VALUES ('', ?, ?, '', 'blocks', 'Private')",
|
||||
(ws_id, name),
|
||||
"VALUES ('', ?, ?, '', 'blocks', ?)",
|
||||
(ws_id, name, section),
|
||||
)
|
||||
conn.commit()
|
||||
pid = cursor.lastrowid
|
||||
return {"id": pid, "name": name, "type": "page"}
|
||||
return {"id": pid, "name": name, "type": item_type}
|
||||
|
||||
|
||||
@router.put("/api/local-workspace/items/{item_id:int}")
|
||||
|
||||
@@ -95,11 +95,11 @@
|
||||
<div class="sidebar-section-items" x-show="sectionsOpen.workspace" x-transition>
|
||||
<ul class="sidebar-items" data-section="workspace">
|
||||
{% for page in workspace_pages %}
|
||||
<li class="sidebar-item" data-id="{{ page.db_id }}">
|
||||
<span class="page-icon">📄</span>
|
||||
<a href="/pages/{{ page.db_id }}" class="page-name">{{ page.name }}</a>
|
||||
<button class="sidebar-item-delete" onclick="event.preventDefault();app.deleteWorkspacePage({{ page.db_id }})" title="Delete">×</button>
|
||||
</li>
|
||||
<li class="sidebar-item" data-id="{{ page.db_id }}">
|
||||
<span class="page-icon">{{ page.icon or '📄' }}</span>
|
||||
<a href="/pages/{{ page.db_id }}" class="page-name">{{ page.name }}</a>
|
||||
<button class="sidebar-item-delete" @click="deleteWorkspacePage({{ page.db_id }})" title="Delete">×</button>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% if not workspace_pages %}
|
||||
<li class="sidebar-item empty-hint"><span class="page-icon">📄</span><span class="page-name text-dim">No pages yet</span></li>
|
||||
|
||||
Reference in New Issue
Block a user