diff --git a/wwwroot/tags_list/add.dspy b/wwwroot/tags_list/add.dspy new file mode 100644 index 0000000..96bc232 --- /dev/null +++ b/wwwroot/tags_list/add.dspy @@ -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 diff --git a/wwwroot/tags_list/data.dspy b/wwwroot/tags_list/data.dspy new file mode 100644 index 0000000..679971c --- /dev/null +++ b/wwwroot/tags_list/data.dspy @@ -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 diff --git a/wwwroot/tags_list/delete.dspy b/wwwroot/tags_list/delete.dspy new file mode 100644 index 0000000..5402873 --- /dev/null +++ b/wwwroot/tags_list/delete.dspy @@ -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 diff --git a/wwwroot/tags_list/update.dspy b/wwwroot/tags_list/update.dspy new file mode 100644 index 0000000..5559876 --- /dev/null +++ b/wwwroot/tags_list/update.dspy @@ -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