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)
|
ws_id = int(ws_cookie)
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
rows = conn.execute(
|
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,),
|
(ws_id,),
|
||||||
).fetchall()
|
).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):
|
except (ValueError, Exception):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -51,12 +51,30 @@ def _sidebar_data(request: Request, repos: list[dict]) -> dict:
|
|||||||
"children": [],
|
"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 {
|
return {
|
||||||
"workspace_name": ws, "workspace_initial": initial,
|
"workspace_name": ws, "workspace_initial": initial,
|
||||||
|
"active_ws_name": active_ws_name,
|
||||||
|
"workspace_pages": workspace_pages,
|
||||||
"current_page": "Dashboard", "last_edited": "now",
|
"current_page": "Dashboard", "last_edited": "now",
|
||||||
"recent_pages": recent_pages,
|
"recent_pages": recent_pages,
|
||||||
"private_pages": [],
|
"private_pages": [],
|
||||||
"favorite_pages": [],
|
"favorite_pages": [],
|
||||||
|
"shared_pages": [],
|
||||||
"user": user,
|
"user": user,
|
||||||
"workspace_key": "",
|
"workspace_key": "",
|
||||||
}
|
}
|
||||||
@@ -524,17 +542,19 @@ async def create_local_workspace_item(request: Request):
|
|||||||
import json
|
import json
|
||||||
body = await request.json()
|
body = await request.json()
|
||||||
name = body.get("name", "Untitled").strip()
|
name = body.get("name", "Untitled").strip()
|
||||||
|
item_type = body.get("type", "page")
|
||||||
ws = _get_active_workspace(request)
|
ws = _get_active_workspace(request)
|
||||||
ws_id = ws["id"] if ws else None
|
ws_id = ws["id"] if ws else None
|
||||||
|
section = 'Workspace' if item_type == 'folder' else 'Private'
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
cursor = conn.execute(
|
cursor = conn.execute(
|
||||||
"INSERT INTO pages (workspace, workspace_id, title, content, content_format, parent_section) "
|
"INSERT INTO pages (workspace, workspace_id, title, content, content_format, parent_section) "
|
||||||
"VALUES ('', ?, ?, '', 'blocks', 'Private')",
|
"VALUES ('', ?, ?, '', 'blocks', ?)",
|
||||||
(ws_id, name),
|
(ws_id, name, section),
|
||||||
)
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
pid = cursor.lastrowid
|
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}")
|
@router.put("/api/local-workspace/items/{item_id:int}")
|
||||||
|
|||||||
@@ -95,11 +95,11 @@
|
|||||||
<div class="sidebar-section-items" x-show="sectionsOpen.workspace" x-transition>
|
<div class="sidebar-section-items" x-show="sectionsOpen.workspace" x-transition>
|
||||||
<ul class="sidebar-items" data-section="workspace">
|
<ul class="sidebar-items" data-section="workspace">
|
||||||
{% for page in workspace_pages %}
|
{% for page in workspace_pages %}
|
||||||
<li class="sidebar-item" data-id="{{ page.db_id }}">
|
<li class="sidebar-item" data-id="{{ page.db_id }}">
|
||||||
<span class="page-icon">📄</span>
|
<span class="page-icon">{{ page.icon or '📄' }}</span>
|
||||||
<a href="/pages/{{ page.db_id }}" class="page-name">{{ page.name }}</a>
|
<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>
|
<button class="sidebar-item-delete" @click="deleteWorkspacePage({{ page.db_id }})" title="Delete">×</button>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if not workspace_pages %}
|
{% 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>
|
<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