fix: restore tags_list DSPY+UI, fix result scope in tag DSPY files
This commit is contained in:
parent
fecdc753a2
commit
bbdafd5d99
17
wwwroot/tags_list/add.dspy
Normal file
17
wwwroot/tags_list/add.dspy
Normal file
@ -0,0 +1,17 @@
|
||||
ns = params_kw.copy()
|
||||
import uuid
|
||||
db = DBPools()
|
||||
dbname = get_module_dbname('rag')
|
||||
name = ns.get('name', '').strip()
|
||||
kb_id = ns.get('kb_id', '')
|
||||
color = ns.get('color', '#3b82f6')
|
||||
if not name or not kb_id:
|
||||
result = {"widgettype": "Message", "options": {"user_data": {"error": "name and kb_id required"}}}
|
||||
else:
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
tag_id = uuid.uuid4().hex[:16]
|
||||
await sor.sqlExe(
|
||||
"INSERT INTO tags (id, kb_id, name, color, org_id, created_at) VALUES (${id}$, ${kb_id}$, ${name}$, ${color}$, '', NOW())",
|
||||
{"id": tag_id, "kb_id": kb_id, "name": name, "color": color})
|
||||
result = {"widgettype": "Message", "options": {"user_data": {"id": tag_id, "name": name, "color": color, "kb_id": kb_id}}}
|
||||
result
|
||||
9
wwwroot/tags_list/data.dspy
Normal file
9
wwwroot/tags_list/data.dspy
Normal file
@ -0,0 +1,9 @@
|
||||
ns = params_kw.copy()
|
||||
db = DBPools()
|
||||
dbname = get_module_dbname('rag')
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
recs = await sor.R('tags', {})
|
||||
result = []
|
||||
for r in recs:
|
||||
result.append({"id": r.id, "name": r.name, "color": r.color, "kb_id": r.kb_id, "created_at": str(r.created_at) if r.created_at else ''})
|
||||
result
|
||||
12
wwwroot/tags_list/delete.dspy
Normal file
12
wwwroot/tags_list/delete.dspy
Normal file
@ -0,0 +1,12 @@
|
||||
ns = params_kw.copy()
|
||||
db = DBPools()
|
||||
dbname = get_module_dbname('rag')
|
||||
tag_id = ns.get('id', '')
|
||||
if not tag_id:
|
||||
result = {"widgettype": "Message", "options": {"user_data": {"error": "id required"}}}
|
||||
else:
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
await sor.sqlExe("DELETE FROM media_tags WHERE tag_id=${id}$", {"id": tag_id})
|
||||
await sor.sqlExe("DELETE FROM tags WHERE id=${id}$", {"id": tag_id})
|
||||
result = {"widgettype": "Message", "options": {"user_data": {"id": tag_id}}}
|
||||
result
|
||||
22
wwwroot/tags_list/update.dspy
Normal file
22
wwwroot/tags_list/update.dspy
Normal file
@ -0,0 +1,22 @@
|
||||
ns = params_kw.copy()
|
||||
db = DBPools()
|
||||
dbname = get_module_dbname('rag')
|
||||
tag_id = ns.get('id', '')
|
||||
name = ns.get('name', '').strip()
|
||||
color = ns.get('color', '#3b82f6')
|
||||
if not tag_id:
|
||||
result = {"widgettype": "Message", "options": {"user_data": {"error": "id required"}}}
|
||||
else:
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
parts = []
|
||||
params = {"id": tag_id}
|
||||
if name:
|
||||
parts.append("name=${name}$")
|
||||
params["name"] = name
|
||||
if color:
|
||||
parts.append("color=${color}$")
|
||||
params["color"] = color
|
||||
if parts:
|
||||
await sor.sqlExe(f"UPDATE tags SET {', '.join(parts)} WHERE id=${{id}}$", params)
|
||||
result = {"widgettype": "Message", "options": {"user_data": {"id": tag_id, "name": name, "color": color}}}
|
||||
result
|
||||
Loading…
x
Reference in New Issue
Block a user