From 8a095c712c80c94a133e931774ee3fc1aa62d8f7 Mon Sep 17 00:00:00 2001 From: p Date: Wed, 12 Aug 2026 18:09:49 +0800 Subject: [PATCH] workspace: full tree dspy + urlwidget button + PopupWindow binds --- wwwroot/api/workspace_popup.dspy | 13 +++++- wwwroot/api/workspace_tree.dspy | 68 +++++++++++--------------------- wwwroot/index.ui | 2 +- 3 files changed, 36 insertions(+), 47 deletions(-) diff --git a/wwwroot/api/workspace_popup.dspy b/wwwroot/api/workspace_popup.dspy index c5889b7..5a04efe 100644 --- a/wwwroot/api/workspace_popup.dspy +++ b/wwwroot/api/workspace_popup.dspy @@ -1,4 +1,4 @@ -# workspace_popup.dspy - 返回工作空间 PopupWindow(binds 由按钮脚本处理) +# workspace_popup.dspy - 返回 PopupWindow(全量树,binds在顶层) uid = await get_user() if not uid: @@ -61,12 +61,23 @@ async with DBPools().sqlorContext(dbname) as sor: "widgettype": "VScrollPanel", "id": "ws_files", "options": { + "dataurl": entire_url("/pipeline-sdlc/api/workspace_files.dspy") + "?id=__root__", "css": "filler", "padding": "8px", "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"] + } }] } diff --git a/wwwroot/api/workspace_tree.dspy b/wwwroot/api/workspace_tree.dspy index 732fca0..bac0893 100644 --- a/wwwroot/api/workspace_tree.dspy +++ b/wwwroot/api/workspace_tree.dspy @@ -1,9 +1,7 @@ -# workspace_tree.dspy - 返回目录子节点(支持 id 参数做懒加载) +# workspace_tree.dspy - 返回完整目录树(非懒加载,所有节点一次性返回) import os -node_id = (params_kw or {}).get('id', '').strip() - uid = await get_user() if not uid: 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 if not ws_dir or not os.path.isdir(ws_dir): - if not node_id: - return [{"id": "__root__", "parentid": "", "label": "📁 工作空间(不可用)", "path": "", "is_leaf": False}] - return [] + return [{"id": "__root__", "parentid": "", "label": "📁 工作空间(不可用)", "path": ""}] -# 初始加载:无 id 参数,只返回根节点 -if not node_id: - return [{ - "id": "__root__", - "parentid": "", - "label": "📁 " + os.path.basename(ws_dir), - "path": ws_dir, - "is_leaf": False - }] +items = [{"id": "__root__", "parentid": "", "label": "📁 " + os.path.basename(ws_dir), "path": ws_dir, "is_leaf": False}] -# 展开节点:返回该目录的直接子目录 -if node_id == '__root__': - scan_path = ws_dir - rel_prefix = "" -else: - scan_path = ws_dir + '/' + node_id - rel_prefix = node_id - -if not os.path.isdir(scan_path): - return [] - -items = [] -try: - entries = sorted(os.listdir(scan_path)) -except Exception: - return [] - -for name in entries: - full = os.path.join(scan_path, name) - 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 - }) +def scan_dir(path, parent_id, rel_prefix): + try: + entries = sorted(os.listdir(path)) + except Exception: + return + for name in entries: + full = os.path.join(path, name) + 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": parent_id, + "label": "📁 " + name, + "path": full, + "is_leaf": False + }) + scan_dir(full, rel_path, rel_path) +scan_dir(ws_dir, "__root__", "") return items diff --git a/wwwroot/index.ui b/wwwroot/index.ui index 196563b..33f52d3 100644 --- a/wwwroot/index.ui +++ b/wwwroot/index.ui @@ -1 +1 @@ -{"widgettype": "VBox", "options": {"width": "100%", "height": "100%", "padding": "0"}, "subwidgets": [{"widgettype": "HBox", "options": {"width": "100%", "alignItems": "center", "padding": "16px 24px 8px 24px", "cheight": 6, "gap": "12px"}, "subwidgets": [{"widgettype": "Title2", "options": {"text": "开发产线驾驶舱"}}, {"widgettype": "Text", "options": {"text": "AI驱动的对话式开发", "cfontsize": 0.9, "color": "#94a3b8"}}, {"widgettype": "Filler"}]}, {"widgettype": "HBox", "id": "context_bar", "options": {"width": "100%", "padding": "4px 24px 4px 24px", "cheight": 2.5, "gap": "12px", "alignItems": "center", "bgcolor": "#e8f0fe"}, "subwidgets": [{"widgettype": "Html", "options": {"html": "", "height": "0", "width": "0"}}, {"widgettype": "Form", "id": "project_form", "options": {"name": "project_form", "cols": 1, "fields": [{"name": "project_id", "uitype": "code", "label": "", "placeholder": "选择项目", "cwidth": 20, "dataurl": "/pipeline-sdlc/api/cockpit_project_picker.dspy", "valueField": "value", "textField": "text", "nullable": true}]}, "binds": [{"wid": "self", "event": "changed", "actiontype": "script", "target": "self", "script": "var v=this.getValue();var pid=(v||{}).project_id||'';if(!pid)return;fetch('/pipeline-sdlc/api/cockpit_context_update.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'project_id='+encodeURIComponent(pid)}).then(function(r){return r.json()}).then(function(r){if(r.success){var pl=bricks.getWidgetById('task_btn',bricks.app);if(pl&&pl.text_w)pl.text_w.set_text('任务');}})"}]}, {"widgettype": "Button", "id": "task_btn", "options": {"label": "任务", "css": "small"}, "binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": "fetch('/pipeline-sdlc/api/cockpit_context.dspy').then(function(r){return r.json()}).then(function(d){var pid=d.project_id||'';var pn=d.project_name||'';if(!pid){var pw=new bricks.PopupWindow({title:'选择项目',cwidth:32,cheight:16,auto_open:true});var form=new bricks.Form({name:'p_picker',cols:1,fields:[{name:'project_id',uitype:'code',label:'项目',placeholder:'请选择项目',cwidth:26,dataurl:'/pipeline-sdlc/api/cockpit_project_picker.dspy',valueField:'value',textField:'text'}]});var vb=new bricks.VBox({padding:'12px',gap:'12px'});vb.add_widget(new bricks.Text({text:'请选择项目:',cfontsize:0.95,color:'#64748b'}));vb.add_widget(form);pw.content_w.add_widget(vb);setTimeout(function(){var sel=pw.content_w.dom_element.querySelector('select');if(sel)sel.addEventListener('change',function(){var v=sel.value;if(!v)return;fetch('/pipeline-sdlc/api/cockpit_context_update.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'project_id='+encodeURIComponent(v)}).then(function(r){return r.json()}).then(function(r){if(r.success){pw.destroy();var sel2=bricks.getWidgetById('project_selector',bricks.app);if(sel2)sel2.setValue(r.project_id);var tb=bricks.getWidgetById('task_btn',bricks.app);if(tb&&tb.text_w)tb.text_w.set_text('\\u4efb\\u52a1');}});});},500);return;}var upw=new bricks.PopupWindow({title:pn+' - \\u4efb\\u52a1\\u5217\\u8868',cwidth:60,cheight:30,auto_open:true});var vs=new bricks.VScrollPanel({css:'filler',padding:'12px',gap:'8px'});upw.content_w.add_widget(vs);fetch('/pipeline-sdlc/api/cockpit_project_tasks.dspy').then(function(r){return r.json()}).then(function(data){var tasks=data.tasks||[];if(tasks.length===0){vs.add_widget(new bricks.Text({text:'\\u6682\\u65e0\\u4efb\\u52a1',cfontsize:0.9,color:'#94a3b8'}));return;}for(var i=0;isetTimeout(function(){fetch('/pipeline-sdlc/api/cockpit_context.dspy').then(function(r){return r.json()}).then(function(d){if(d.project_id){var sel=bricks.getWidgetById('project_selector',bricks.app);if(sel)sel.setValue(d.project_id);}})},200);", "height": "0", "width": "0"}}, {"widgettype": "Form", "id": "project_form", "options": {"name": "project_form", "cols": 1, "fields": [{"name": "project_id", "uitype": "code", "label": "", "placeholder": "选择项目", "cwidth": 20, "dataurl": "/pipeline-sdlc/api/cockpit_project_picker.dspy", "valueField": "value", "textField": "text", "nullable": true}]}, "binds": [{"wid": "self", "event": "changed", "actiontype": "script", "target": "self", "script": "var v=this.getValue();var pid=(v||{}).project_id||'';if(!pid)return;fetch('/pipeline-sdlc/api/cockpit_context_update.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'project_id='+encodeURIComponent(pid)}).then(function(r){return r.json()}).then(function(r){if(r.success){var pl=bricks.getWidgetById('task_btn',bricks.app);if(pl&&pl.text_w)pl.text_w.set_text('任务');}})"}]}, {"widgettype": "Button", "id": "task_btn", "options": {"label": "任务", "css": "small"}, "binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": "fetch('/pipeline-sdlc/api/cockpit_context.dspy').then(function(r){return r.json()}).then(function(d){var pid=d.project_id||'';var pn=d.project_name||'';if(!pid){var pw=new bricks.PopupWindow({title:'选择项目',cwidth:32,cheight:16,auto_open:true});var form=new bricks.Form({name:'p_picker',cols:1,fields:[{name:'project_id',uitype:'code',label:'项目',placeholder:'请选择项目',cwidth:26,dataurl:'/pipeline-sdlc/api/cockpit_project_picker.dspy',valueField:'value',textField:'text'}]});var vb=new bricks.VBox({padding:'12px',gap:'12px'});vb.add_widget(new bricks.Text({text:'请选择项目:',cfontsize:0.95,color:'#64748b'}));vb.add_widget(form);pw.content_w.add_widget(vb);setTimeout(function(){var sel=pw.content_w.dom_element.querySelector('select');if(sel)sel.addEventListener('change',function(){var v=sel.value;if(!v)return;fetch('/pipeline-sdlc/api/cockpit_context_update.dspy',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'project_id='+encodeURIComponent(v)}).then(function(r){return r.json()}).then(function(r){if(r.success){pw.destroy();var sel2=bricks.getWidgetById('project_selector',bricks.app);if(sel2)sel2.setValue(r.project_id);var tb=bricks.getWidgetById('task_btn',bricks.app);if(tb&&tb.text_w)tb.text_w.set_text('\\u4efb\\u52a1');}});});},500);return;}var upw=new bricks.PopupWindow({title:pn+' - \\u4efb\\u52a1\\u5217\\u8868',cwidth:60,cheight:30,auto_open:true});var vs=new bricks.VScrollPanel({css:'filler',padding:'12px',gap:'8px'});upw.content_w.add_widget(vs);fetch('/pipeline-sdlc/api/cockpit_project_tasks.dspy').then(function(r){return r.json()}).then(function(data){var tasks=data.tasks||[];if(tasks.length===0){vs.add_widget(new bricks.Text({text:'\\u6682\\u65e0\\u4efb\\u52a1',cfontsize:0.9,color:'#94a3b8'}));return;}for(var i=0;i