workspace: root dir files initially, __root__ handling
This commit is contained in:
parent
222d3e2e75
commit
4db8e3fafd
@ -1,11 +1,10 @@
|
|||||||
# workspace_files.dspy - 返回目录下文件列表(Bricks widget 格式)
|
# workspace_files.dspy - 返回目录下文件列表
|
||||||
# id 是相对路径,需拼接 workspace_dir
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
folder_id = (params_kw or {}).get('id', '').strip()
|
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}}
|
return {"widgettype": "Text", "options": {"text": "请从左侧选择目录", "cfontsize": 0.9}}
|
||||||
|
|
||||||
uid = await get_user()
|
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'
|
org_id = getattr(proj[0], 'org_id', '0') or '0'
|
||||||
ws_dir = workspace_base + '/' + org_id + '/' + pname
|
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):
|
if not os.path.isdir(full_dir):
|
||||||
return {"widgettype": "Text", "options": {"text": "目录不可用: " + folder_id}}
|
return {"widgettype": "Text", "options": {"text": "目录不可用: " + folder_id}}
|
||||||
@ -55,39 +58,22 @@ for name in entries:
|
|||||||
fname_escaped = name.replace("'", "\\'")
|
fname_escaped = name.replace("'", "\\'")
|
||||||
row = {
|
row = {
|
||||||
"widgettype": "HBox",
|
"widgettype": "HBox",
|
||||||
"options": {
|
"options": {"padding": "6px 10px", "alignItems": "center", "gap": "8px", "borderRadius": "4px"},
|
||||||
"padding": "6px 10px",
|
|
||||||
"alignItems": "center",
|
|
||||||
"gap": "8px",
|
|
||||||
"borderRadius": "4px",
|
|
||||||
"style": {"cursor": "pointer"},
|
|
||||||
},
|
|
||||||
"subwidgets": [
|
"subwidgets": [
|
||||||
{"widgettype": "Text", "options": {"text": icon, "cfontsize": 1.2}},
|
{"widgettype": "Text", "options": {"text": icon, "cfontsize": 1.2}},
|
||||||
{"widgettype": "Text", "options": {"text": name, "cfontsize": 0.9, "color": "#1e293b", "css": "filler"}},
|
{"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"}},
|
{"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",
|
"wid": "self",
|
||||||
"event": "click",
|
"event": "click",
|
||||||
"actiontype": "script",
|
"actiontype": "script",
|
||||||
"target": "self",
|
"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)}}}})}});}})"
|
"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)
|
files.append(row)
|
||||||
|
|
||||||
if not files:
|
if not files:
|
||||||
|
|||||||
@ -70,6 +70,7 @@ 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"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user