feat(diarization-ui): add library text filters for title and content

This commit is contained in:
2026-03-21 15:38:47 +01:00
parent 5efd08674b
commit bd152429d6

46
app.py
View File

@@ -483,29 +483,39 @@ async def upload(project_id: int = Form(...), title: str = Form(""), file: Uploa
@app.get("/library", response_class=HTMLResponse)
def library(project_id: Optional[int] = None):
def library(project_id: Optional[str] = None, q_title: str = "", q_content: str = ""):
title_q = (q_title or "").strip()
content_q = (q_content or "").strip()
project_id_int = int(project_id) if (project_id and str(project_id).strip()) else None
where = []
params = []
if project_id_int:
where.append("d.project_id=?")
params.append(project_id_int)
if title_q:
where.append("LOWER(d.title) LIKE LOWER(?)")
params.append(f"%{title_q}%")
if content_q:
where.append("LOWER(d.content_md) LIKE LOWER(?)")
params.append(f"%{content_q}%")
where_sql = ("WHERE " + " AND ".join(where)) if where else ""
with db() as c:
projects = c.execute("SELECT id,name FROM projects ORDER BY name").fetchall()
if project_id:
docs = c.execute(
"""
f"""
SELECT d.id,d.kind,d.title,d.created_at,p.name AS project
FROM documents d JOIN projects p ON p.id=d.project_id
WHERE d.project_id=? ORDER BY d.id DESC
{where_sql}
ORDER BY d.id DESC LIMIT 500
""",
(project_id,),
).fetchall()
else:
docs = c.execute(
"""
SELECT d.id,d.kind,d.title,d.created_at,p.name AS project
FROM documents d JOIN projects p ON p.id=d.project_id
ORDER BY d.id DESC LIMIT 200
"""
tuple(params),
).fetchall()
p_opts = "<option value=''>Alle</option>" + "".join(
[f"<option value='{p['id']}' {'selected' if project_id==p['id'] else ''}>{p['name']}</option>" for p in projects]
[f"<option value='{p['id']}' {'selected' if project_id_int==p['id'] else ''}>{p['name']}</option>" for p in projects]
)
items = "".join(
[
@@ -523,10 +533,16 @@ def library(project_id: Optional[int] = None):
project_js = json.dumps([{"value": p["id"], "label": p["name"]} for p in projects], ensure_ascii=False)
body = f"""
<h2>Datenbank / Dokumente</h2>
<form method='get' class='row card'>
<form method='get' class='card'>
<div class='row'>
<label>Projekt:</label>
<select name='project_id'>{p_opts}</select>
</div>
<div class='row' style='margin-top:8px'>
<input name='q_title' placeholder='Titel enthält …' value='{title_q.replace("'", "&#39;")}'>
<input name='q_content' placeholder='Inhalt enthält …' value='{content_q.replace("'", "&#39;")}'>
<button type='submit'>Filtern</button>
</div>
</form>
{items or '<p>Keine Einträge.</p>'}
<script>