tree: nested children for initial load
This commit is contained in:
parent
af7d7fc716
commit
3349bb1b33
@ -1,4 +1,4 @@
|
||||
# workspace_tree.dspy - 懒加载:返回指定节点的直接子目录
|
||||
# workspace_tree.dspy - 初始加载返回嵌套结构(根节点+children),展开时返回平级子节点
|
||||
|
||||
import os
|
||||
|
||||
@ -30,25 +30,46 @@ async with DBPools().sqlorContext(dbname) as sor:
|
||||
|
||||
if not ws_dir or not os.path.isdir(ws_dir):
|
||||
if not node_id:
|
||||
return [{"id": "__root__", "parentid": "", "label": "📁 工作空间(不可用)", "path": ws_dir, "is_leaf": False}]
|
||||
return [{
|
||||
"id": "__root__",
|
||||
"parentid": "",
|
||||
"label": "📁 工作空间(不可用)",
|
||||
"path": ws_dir,
|
||||
"is_leaf": True
|
||||
}]
|
||||
return []
|
||||
|
||||
# 初始加载:无 id,返回根节点
|
||||
# 初始加载:返回带 children 的嵌套结构
|
||||
if not node_id:
|
||||
return [{
|
||||
root = {
|
||||
"id": "__root__",
|
||||
"parentid": "",
|
||||
"label": "📁 " + os.path.basename(ws_dir),
|
||||
"path": ws_dir,
|
||||
"is_leaf": False
|
||||
}]
|
||||
|
||||
# 展开节点:id=__root__ → 扫描 ws_dir。否则拼完整路径
|
||||
if node_id == '__root__':
|
||||
scan_path = ws_dir
|
||||
else:
|
||||
scan_path = ws_dir + '/' + node_id
|
||||
"is_leaf": False,
|
||||
"children": []
|
||||
}
|
||||
try:
|
||||
entries = sorted(os.listdir(ws_dir))
|
||||
except Exception:
|
||||
entries = []
|
||||
for name in entries:
|
||||
full = os.path.join(ws_dir, name)
|
||||
if name.startswith('.') or name == '__pycache__':
|
||||
continue
|
||||
if os.path.isdir(full):
|
||||
root["children"].append({
|
||||
"id": name,
|
||||
"parentid": "__root__",
|
||||
"label": "📁 " + name,
|
||||
"path": full,
|
||||
"is_leaf": False,
|
||||
"children": []
|
||||
})
|
||||
return [root]
|
||||
|
||||
# 展开节点
|
||||
scan_path = ws_dir + '/' + node_id
|
||||
if not os.path.isdir(scan_path):
|
||||
return []
|
||||
|
||||
@ -63,9 +84,8 @@ for name in entries:
|
||||
if name.startswith('.') or name == '__pycache__':
|
||||
continue
|
||||
if os.path.isdir(full):
|
||||
rel_path = node_id + '/' + name if node_id != '__root__' else name
|
||||
items.append({
|
||||
"id": rel_path,
|
||||
"id": node_id + '/' + name,
|
||||
"parentid": node_id,
|
||||
"label": "📁 " + name,
|
||||
"path": full,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user