workspace: full tree dspy + urlwidget button + PopupWindow binds

This commit is contained in:
p 2026-08-12 18:09:49 +08:00
parent 9ec29726b2
commit 8a095c712c
3 changed files with 36 additions and 47 deletions

View File

@ -1,4 +1,4 @@
# workspace_popup.dspy - 返回工作空间 PopupWindow(binds 由按钮脚本处理) # workspace_popup.dspy - 返回 PopupWindow(全量树,binds在顶层)
uid = await get_user() uid = await get_user()
if not uid: if not uid:
@ -61,12 +61,23 @@ async with DBPools().sqlorContext(dbname) as sor:
"widgettype": "VScrollPanel", "widgettype": "VScrollPanel",
"id": "ws_files", "id": "ws_files",
"options": { "options": {
"dataurl": entire_url("/pipeline-sdlc/api/workspace_files.dspy") + "?id=__root__",
"css": "filler", "css": "filler",
"padding": "8px", "padding": "8px",
"gap": "4px" "gap": "4px"
} }
} }
] ]
}],
"binds": [{
"wid": "ws_tree",
"event": "selected",
"actiontype": "urlwidget",
"target": "ws_files",
"options": {
"url": entire_url("/pipeline-sdlc/api/workspace_files.dspy"),
"event_params": ["user_data.id"]
}
}] }]
} }

View File

@ -1,9 +1,7 @@
# workspace_tree.dspy - 返回目录子节点(支持 id 参数做懒加载) # workspace_tree.dspy - 返回完整目录树(非懒加载,所有节点一次性返回)
import os import os
node_id = (params_kw or {}).get('id', '').strip()
uid = await get_user() uid = await get_user()
if not uid: if not uid:
uid = 'user-01' uid = 'user-01'
@ -29,49 +27,29 @@ async with DBPools().sqlorContext(dbname) as sor:
ws_dir = ws if ws.startswith('/') else workspace_base + '/' + org_id + '/' + pname ws_dir = ws if ws.startswith('/') else workspace_base + '/' + org_id + '/' + pname
if not ws_dir or not os.path.isdir(ws_dir): if not ws_dir or not os.path.isdir(ws_dir):
if not node_id: return [{"id": "__root__", "parentid": "", "label": "📁 工作空间(不可用)", "path": ""}]
return [{"id": "__root__", "parentid": "", "label": "📁 工作空间(不可用)", "path": "", "is_leaf": False}]
return []
# 初始加载:无 id 参数,只返回根节点 items = [{"id": "__root__", "parentid": "", "label": "📁 " + os.path.basename(ws_dir), "path": ws_dir, "is_leaf": False}]
if not node_id:
return [{
"id": "__root__",
"parentid": "",
"label": "📁 " + os.path.basename(ws_dir),
"path": ws_dir,
"is_leaf": False
}]
# 展开节点:返回该目录的直接子目录 def scan_dir(path, parent_id, rel_prefix):
if node_id == '__root__': try:
scan_path = ws_dir entries = sorted(os.listdir(path))
rel_prefix = "" except Exception:
else: return
scan_path = ws_dir + '/' + node_id for name in entries:
rel_prefix = node_id full = os.path.join(path, name)
if name.startswith('.') or name == '__pycache__':
if not os.path.isdir(scan_path): continue
return [] if os.path.isdir(full):
rel_path = rel_prefix + '/' + name if rel_prefix else name
items = [] items.append({
try: "id": rel_path,
entries = sorted(os.listdir(scan_path)) "parentid": parent_id,
except Exception: "label": "📁 " + name,
return [] "path": full,
"is_leaf": False
for name in entries: })
full = os.path.join(scan_path, name) scan_dir(full, rel_path, rel_path)
if name.startswith('.') or name == '__pycache__':
continue
if os.path.isdir(full):
rel_path = rel_prefix + '/' + name if rel_prefix else name
items.append({
"id": rel_path,
"parentid": node_id,
"label": "📁 " + name,
"path": full,
"is_leaf": False
})
scan_dir(ws_dir, "__root__", "")
return items return items

File diff suppressed because one or more lines are too long