feat(diarization-ui): add library text filters for title and content
This commit is contained in:
62
app.py
62
app.py
@@ -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(
|
||||
"""
|
||||
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
|
||||
""",
|
||||
(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
|
||||
"""
|
||||
).fetchall()
|
||||
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_sql}
|
||||
ORDER BY d.id DESC LIMIT 500
|
||||
""",
|
||||
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'>
|
||||
<label>Projekt:</label>
|
||||
<select name='project_id'>{p_opts}</select>
|
||||
<button type='submit'>Filtern</button>
|
||||
<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("'", "'")}'>
|
||||
<input name='q_content' placeholder='Inhalt enthält …' value='{content_q.replace("'", "'")}'>
|
||||
<button type='submit'>Filtern</button>
|
||||
</div>
|
||||
</form>
|
||||
{items or '<p>Keine Einträge.</p>'}
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user