From 751c953ad3ad501f3d511a5f8ca72e4052f789e8 Mon Sep 17 00:00:00 2001 From: p
Date: Thu, 13 Aug 2026 12:02:00 +0800
Subject: [PATCH] workspace: use ResourceBrowser widget
---
wwwroot/api/workspace_files.dspy | 28 +++++--------------
wwwroot/api/workspace_popup.dspy | 47 ++++++++++++--------------------
wwwroot/index.ui | 2 +-
3 files changed, 26 insertions(+), 51 deletions(-)
diff --git a/wwwroot/api/workspace_files.dspy b/wwwroot/api/workspace_files.dspy
index c11c336..2bb4fa9 100644
--- a/wwwroot/api/workspace_files.dspy
+++ b/wwwroot/api/workspace_files.dspy
@@ -1,12 +1,9 @@
-# workspace_files.dspy - 返回目录下文件列表
+# workspace_files.dspy - 返回目录文件列表(无 id 或 id=__root__ 时返回根目录文件)
import os
folder_id = (params_kw or {}).get('id', '').strip()
-if not folder_id:
- return {"widgettype": "Text", "options": {"text": "请从左侧选择目录", "cfontsize": 0.9}}
-
uid = await get_user()
if not uid:
uid = 'user-01'
@@ -30,20 +27,20 @@ async with DBPools().sqlorContext(dbname) as sor:
org_id = getattr(proj[0], 'org_id', '0') or '0'
ws_dir = workspace_base + '/' + org_id + '/' + pname
-# __root__ means workspace root directory
-if folder_id == '__root__':
+# 无 id 或 __root__ 都指向工作空间根目录
+if not folder_id or folder_id == '__root__':
full_dir = ws_dir
else:
full_dir = ws_dir + '/' + folder_id if ws_dir else folder_id
if not os.path.isdir(full_dir):
- return {"widgettype": "Text", "options": {"text": "目录不可用: " + folder_id}}
+ return {"widgettype": "Text", "options": {"text": "目录不可用: " + folder_id, "cfontsize": 0.9}}
files = []
try:
entries = sorted(os.listdir(full_dir))
except Exception as e:
- return {"widgettype": "Text", "options": {"text": "读取错误: " + str(e)}}
+ return {"widgettype": "Text", "options": {"text": "读取错误: " + str(e), "cfontsize": 0.9}}
for name in entries:
full = os.path.join(full_dir, name)
@@ -54,30 +51,19 @@ for name in entries:
ext = os.path.splitext(name)[1].lower()
is_text = ext in ['.md','.py','.js','.html','.css','.json','.txt','.xml','.yaml','.yml','.toml','.cfg','.sh','.sql','.dspy','.ui']
icon = "📄" if is_text else "🎬" if ext in ['.png','.jpg','.mp4'] else "📁"
- fpath_escaped = full.replace("\\", "\\\\").replace("'", "\\'")
- fname_escaped = name.replace("'", "\\'")
row = {
"widgettype": "HBox",
- "options": {"padding": "6px 10px", "alignItems": "center", "gap": "8px", "borderRadius": "4px"},
+ "options": {"padding": "6px 10px", "alignItems": "center", "gap": "8px"},
"subwidgets": [
{"widgettype": "Text", "options": {"text": icon, "cfontsize": 1.2}},
{"widgettype": "Text", "options": {"text": name, "cfontsize": 0.9, "color": "#1e293b", "css": "filler"}},
{"widgettype": "Text", "options": {"text": f"{size/1024:.1f}KB", "cfontsize": 0.75, "color": "#94a3b8"}},
],
}
- if is_text:
- row["options"]["style"] = {"cursor": "pointer"}
- row["binds"] = [{
- "wid": "self",
- "event": "click",
- "actiontype": "script",
- "target": "self",
- "script": f"var pw=new bricks.PopupWindow({{title:'{fname_escaped}',cwidth:70,cheight:32,auto_open:true}});var wt=new bricks.Wterm({{css:'filler',padding:'0'}});pw.content_w.add_widget(wt);var sb=new bricks.Button({{label:'保存'}});pw.content_w.add_widget(sb);fetch('/pipeline-sdlc/api/workspace_file.dspy?action=read&path='+encodeURIComponent('{fpath_escaped}')).then(function(r){{return r.json()}}).then(function(d){{if(d.error){{wt.write('Error: '+d.error);return}};wt.write(d.content||'');sb.bind('click',function(){{var c=wt.get_value();fetch('/pipeline-sdlc/api/workspace_file.dspy',{{method:'POST',headers:{{'Content-Type':'application/x-www-form-urlencoded'}},body:'action=save&path='+encodeURIComponent('{fpath_escaped}')+'&content='+encodeURIComponent(c)}}).then(function(r){{return r.json()}}).then(function(d){{if(d.success){{sb.set_text('已保存');setTimeout(function(){{sb.set_text('保存')}},2000)}}}})}});}})"
- }]
files.append(row)
if not files:
- return {"widgettype": "Text", "options": {"text": "(空目录)", "cfontsize": 0.85, "color": "#94a3b8"}}
+ return {"widgettype": "Text", "options": {"text": "(空目录)", "cfontsize": 0.85, "color": "#94a3b8", "padding": "8px"}}
return {
"widgettype": "VScrollPanel",
diff --git a/wwwroot/api/workspace_popup.dspy b/wwwroot/api/workspace_popup.dspy
index f59e8aa..97c1e53 100644
--- a/wwwroot/api/workspace_popup.dspy
+++ b/wwwroot/api/workspace_popup.dspy
@@ -1,4 +1,4 @@
-# workspace_popup.dspy - 用 VBox 代替 VScrollPanel
+# workspace_popup.dspy - 返回 PopupWindow,内含 ResourceBrowser 控件
uid = await get_user()
if not uid:
@@ -37,36 +37,25 @@ async with DBPools().sqlorContext(dbname) as sor:
"auto_open": True
},
"subwidgets": [{
- "widgettype": "HBox",
- "options": {"height": "100%"},
- "subwidgets": [
- {
- "widgettype": "VBox",
- "options": {"width": "280px"},
- "subwidgets": [{
- "widgettype": "Tree",
- "id": "ws_tree",
- "options": {
- "dataurl": entire_url("/pipeline-sdlc/api/workspace_tree.dspy"),
- "textField": "label",
- "idField": "id",
- "cfontsize": 1.0,
- "css": "filler",
- "padding": "4px",
- "cheight": "100%"
- }
- }]
- },
- {
- "widgettype": "VBox",
- "id": "ws_files",
+ "widgettype": "ResourceBrowser",
+ "options": {
+ "tree_options": {
+ "widgettype": "Tree",
"options": {
- "css": "filler",
- "padding": "8px",
- "gap": "4px"
+ "dataurl": entire_url("/pipeline-sdlc/api/workspace_tree.dspy"),
+ "textField": "label",
+ "idField": "id",
+ "cfontsize": 1.0
}
- }
- ]
+ },
+ "browser_options": {
+ "widgettype": "urlwidget",
+ "options": {
+ "url": entire_url("/pipeline-sdlc/api/workspace_files.dspy")
+ }
+ },
+ "tree_width": "280px"
+ }
}]
}
diff --git a/wwwroot/index.ui b/wwwroot/index.ui
index c609b03..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;i