From 4db8e3fafdd54b7ac1f9288c7bffba593eeaf155 Mon Sep 17 00:00:00 2001 From: p
Date: Wed, 12 Aug 2026 15:18:47 +0800 Subject: [PATCH] workspace: root dir files initially, __root__ handling --- wwwroot/api/workspace_files.dspy | 40 +++++++++++--------------------- wwwroot/api/workspace_popup.dspy | 1 + 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/wwwroot/api/workspace_files.dspy b/wwwroot/api/workspace_files.dspy index 71144c1..c11c336 100644 --- a/wwwroot/api/workspace_files.dspy +++ b/wwwroot/api/workspace_files.dspy @@ -1,11 +1,10 @@ -# workspace_files.dspy - 返回目录下文件列表(Bricks widget 格式) -# id 是相对路径,需拼接 workspace_dir +# workspace_files.dspy - 返回目录下文件列表 import os folder_id = (params_kw or {}).get('id', '').strip() -if not folder_id or folder_id == '__root__': +if not folder_id: return {"widgettype": "Text", "options": {"text": "请从左侧选择目录", "cfontsize": 0.9}} uid = await get_user() @@ -31,7 +30,11 @@ async with DBPools().sqlorContext(dbname) as sor: org_id = getattr(proj[0], 'org_id', '0') or '0' ws_dir = workspace_base + '/' + org_id + '/' + pname -full_dir = ws_dir + '/' + folder_id if ws_dir else folder_id +# __root__ means workspace root directory +if 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}} @@ -55,39 +58,22 @@ for name in entries: fname_escaped = name.replace("'", "\\'") row = { "widgettype": "HBox", - "options": { - "padding": "6px 10px", - "alignItems": "center", - "gap": "8px", - "borderRadius": "4px", - "style": {"cursor": "pointer"}, - }, + "options": {"padding": "6px 10px", "alignItems": "center", "gap": "8px", "borderRadius": "4px"}, "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"}}, ], - "binds": [{ + } + 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)}}}})}});}})" - }] if is_text else [] - } if is_text else { - "widgettype": "HBox", - "options": { - "padding": "6px 10px", - "alignItems": "center", - "gap": "8px", - "borderRadius": "4px", - }, - "subwidgets": [ - {"widgettype": "Text", "options": {"text": icon, "cfontsize": 1.2}}, - {"widgettype": "Text", "options": {"text": name, "cfontsize": 0.9, "color": "#94a3b8", "css": "filler"}}, - {"widgettype": "Text", "options": {"text": f"{size/1024:.1f}KB", "cfontsize": 0.75, "color": "#94a3b8"}}, - ], - } + }] files.append(row) if not files: diff --git a/wwwroot/api/workspace_popup.dspy b/wwwroot/api/workspace_popup.dspy index 403c760..d2330aa 100644 --- a/wwwroot/api/workspace_popup.dspy +++ b/wwwroot/api/workspace_popup.dspy @@ -70,6 +70,7 @@ 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"