pipeline-sdlc/wwwroot/api/workspace_popup.dspy

127 lines
5.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# workspace_popup.dspy - 返回 PopupWindow,内含 ResourceBrowser(含打开/删除 tools)
import json as _json
uid = await get_user()
if not uid:
uid = 'user-01'
dbname = get_module_dbname('pipeline-sdlc')
import os
session_id = (params_kw or {}).get('session_id', '') or ''
pipeline_id = (params_kw or {}).get('pipeline_id', '') or ''
_sid_q = ("?session_id=" + session_id) if session_id else ""
async with DBPools().sqlorContext(dbname) as sor:
# 产线隔离:传了 pipeline_id 时,会话项目跨产线则视为无项目
# (商机/投标产线入口不显示开发产线项目的空间)
project_dir, _ = await get_project_dir_pl(sor, uid, session_id, pipeline_id)
pname = os.path.basename(project_dir) if project_dir else ''
if not project_dir:
resp = {
"widgettype": "PopupWindow",
"options": {"title": "提示", "cwidth": 30, "cheight": 8, "auto_open": True},
"subwidgets": [{
"widgettype": "Text",
"options": {"text": "请先在会话中切换项目", "cfontsize": 1, "color": "#64748b", "padding": "20px"}
}]
}
else:
view_url = entire_url("/pipeline-sdlc/api/workspace_view.dspy")
edit_url = entire_url("/pipeline-sdlc/api/workspace_open.dspy")
delete_url = entire_url("/pipeline-sdlc/api/workspace_delete.dspy") + _sid_q
_sid_js = _json.dumps(("&session_id=" + session_id) if session_id else "")
# 查看:txt/md 用 MdWidget 渲染,其他下载查看
view_script = (
"if(!bricks.app._ws_sel)return;"
"var r=await fetch(" + _json.dumps(view_url) + "+'?id='+encodeURIComponent(bricks.app._ws_sel.id)+" + _sid_js + ");"
"var d=await r.json();"
"bricks.widgetBuild(d,bricks.app);"
)
# 编辑:文本 vi 编辑、媒体播放、图片预览、其他下载
edit_script = (
"if(!bricks.app._ws_sel)return;"
"var r=await fetch(" + _json.dumps(edit_url) + "+'?id='+encodeURIComponent(bricks.app._ws_sel.id)+" + _sid_js + ");"
"var d=await r.json();"
"bricks.widgetBuild(d,bricks.app);"
)
# 删除:删除选中文件并刷新
delete_script = (
"if(!bricks.app._ws_sel)return;"
"var body=new URLSearchParams();"
"body.append('id',bricks.app._ws_sel.id);"
"var resp=await fetch(" + _json.dumps(delete_url) + ",{method:'POST',body:body});"
"var rj=await resp.json();"
"if(rj.status=='ok'){"
"bricks.app._ws_sel=null;bricks.app._ws_sel_el=null;"
"var rb=bricks.getWidgetById('ws_rb',bricks.app);"
"if(rb){var cid=rb.current_id;rb.current_id=undefined;await rb.render_browser(cid);}"
"}else{var m=new bricks.Message({title:'删除失败',message:rj.message||'未知错误'});m.open();}"
)
resp = {
"widgettype": "PopupWindow",
"options": {
"title": pname + " - 工作空间",
"width": "85%",
"height": "80%",
"auto_open": True
},
"subwidgets": [{
"widgettype": "ResourceBrowser",
"id": "ws_rb",
"options": {
"tree_options": {
"widgettype": "Tree",
"options": {
"dataurl": entire_url("/pipeline-sdlc/api/workspace_tree.dspy") + _sid_q,
"textField": "label",
"idField": "id",
"cfontsize": 1.0
}
},
"browser_options": {
"widgettype": "urlwidget",
"options": {
"url": entire_url("/pipeline-sdlc/api/workspace_files.dspy") + _sid_q
},
"tools": [
{
"widgettype": "Button",
"options": {"label": "查看", "css": "small"},
"binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": view_script}]
},
{
"widgettype": "Button",
"options": {"label": "编辑", "css": "small"},
"binds": [{"wid": "self", "event": "click", "actiontype": "script", "target": "self", "script": edit_script}]
},
{
"widgettype": "Button",
"options": {"label": "删除", "css": "small"},
"binds": [{
"wid": "self", "event": "click", "actiontype": "script", "target": "self",
"conform": {
"title": "删除确认",
"message": "确认删除选中的文件?",
"conform": {"label": "删除"},
"discard": {"label": "取消"}
},
"script": delete_script
}]
}
]
},
"tree_width": "280px"
}
}]
}
return _json.dumps(resp, ensure_ascii=False)