Sprint 15: Suche, Ausweis, Teilen, Widget
- Volltext-Suche im Tagebuch (LIKE über Titel/Text/Tags, Debounce 350ms)
- Digitaler Heimtierausweis als druckbare HTML-Seite (/ausweis/{dog_id})
Enthält Impfungen, Medikamente, Allergien, Tierärzte, Chip-Nr.
- Hund teilen: Einladungslink-System (dog_shares-Tabelle, /teilen/{token})
Geteilte Hunde erscheinen in der Hundeliste, Tagebuch/Gesundheit lesbar
- Widget-Seite /#widget: zufälliges Tagebuchbild + nächste Erinnerung
Als PWA-Shortcut im Manifest verankert
- SW-Cache by-v144, APP_VER 117
This commit is contained in:
parent
d5f09cd16b
commit
34f29f9d0a
16 changed files with 917 additions and 35 deletions
213
backend/main.py
213
backend/main.py
|
|
@ -74,6 +74,8 @@ from routes.admin import router as admin_router
|
|||
from routes.webcal import router as webcal_router
|
||||
from routes.profile import router as profile_router
|
||||
from routes.import_data import router as import_router
|
||||
from routes.sharing import dog_router as sharing_dog_router, share_router as sharing_share_router
|
||||
from routes.widget import router as widget_router
|
||||
|
||||
app.include_router(auth_router, prefix="/api/auth", tags=["Auth"])
|
||||
app.include_router(dogs_router, prefix="/api/dogs", tags=["Hunde"])
|
||||
|
|
@ -99,7 +101,10 @@ app.include_router(chat_router, prefix="/api/chat", tags=["Chat"])
|
|||
app.include_router(admin_router, prefix="/api/admin", tags=["Admin"])
|
||||
app.include_router(webcal_router, prefix="/api/webcal", tags=["WebCal"])
|
||||
app.include_router(profile_router, prefix="/api/profile", tags=["Profil"])
|
||||
app.include_router(import_router, prefix="/api/import", tags=["Import"])
|
||||
app.include_router(import_router, prefix="/api/import", tags=["Import"])
|
||||
app.include_router(sharing_dog_router, prefix="/api/dogs", tags=["Teilen"])
|
||||
app.include_router(sharing_share_router, prefix="/api/share", tags=["Teilen"])
|
||||
app.include_router(widget_router, prefix="/api/widget", tags=["Widget"])
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
|
@ -445,6 +450,212 @@ async def public_dog_page(dog_id: int):
|
|||
return HTMLResponse(content=html)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Einladungsseite /teilen/{token} — SPA lädt + nimmt Einladung an
|
||||
# ------------------------------------------------------------------
|
||||
@app.get("/teilen/{token}")
|
||||
async def invite_page(token: str):
|
||||
return FileResponse(f"{STATIC_DIR}/index.html", headers={"Cache-Control": "no-cache"})
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Widget-Vorschau /widget
|
||||
# ------------------------------------------------------------------
|
||||
@app.get("/widget")
|
||||
async def widget_page():
|
||||
return FileResponse(f"{STATIC_DIR}/index.html", headers={"Cache-Control": "no-cache"})
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Digitaler Heimtierausweis /ausweis/{dog_id}
|
||||
# ------------------------------------------------------------------
|
||||
@app.get("/ausweis/{dog_id}")
|
||||
async def ausweis_page(dog_id: int, request: Request):
|
||||
from fastapi.responses import HTMLResponse
|
||||
from auth import get_current_user_optional, decode_token
|
||||
import json as _json
|
||||
|
||||
# Auth via Cookie
|
||||
token = request.cookies.get("by_token")
|
||||
user_id = None
|
||||
if token:
|
||||
try:
|
||||
payload = decode_token(token)
|
||||
user_id = int(payload["sub"])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not user_id:
|
||||
return HTMLResponse(
|
||||
'<meta charset="UTF-8"><p style="font-family:sans-serif;padding:2rem">'
|
||||
'Bitte <a href="/">einloggen</a> um den Ausweis anzuzeigen.</p>',
|
||||
status_code=401
|
||||
)
|
||||
|
||||
from database import db as _db
|
||||
with _db() as conn:
|
||||
dog = conn.execute(
|
||||
"""SELECT d.* FROM dogs d
|
||||
LEFT JOIN dog_shares ds ON ds.dog_id=d.id AND ds.shared_with_id=? AND ds.accepted_at IS NOT NULL
|
||||
WHERE d.id=? AND (d.user_id=? OR ds.id IS NOT NULL)""",
|
||||
(user_id, dog_id, user_id)
|
||||
).fetchone()
|
||||
if not dog:
|
||||
return HTMLResponse("<p>Hund nicht gefunden.</p>", status_code=404)
|
||||
|
||||
owner = conn.execute("SELECT name, email FROM users WHERE id=?", (dog["user_id"],)).fetchone()
|
||||
|
||||
health_rows = conn.execute(
|
||||
"SELECT * FROM health WHERE dog_id=? ORDER BY datum DESC",
|
||||
(dog_id,)
|
||||
).fetchall()
|
||||
|
||||
vets = conn.execute(
|
||||
"""SELECT DISTINCT t.name, t.strasse, t.plz, t.ort, t.telefon
|
||||
FROM tieraerzte t
|
||||
JOIN health h ON h.tierarzt_id = t.id
|
||||
WHERE h.dog_id=?""",
|
||||
(dog_id,)
|
||||
).fetchall()
|
||||
|
||||
dog = dict(dog)
|
||||
vets = [dict(v) for v in vets]
|
||||
|
||||
def esc(s):
|
||||
if not s: return ""
|
||||
return str(s).replace("&","&").replace("<","<").replace(">",">").replace('"',""")
|
||||
|
||||
def fmt_date(d):
|
||||
if not d: return "–"
|
||||
try:
|
||||
from datetime import date
|
||||
parts = d.split("-")
|
||||
return f"{int(parts[2])}.{int(parts[1])}.{parts[0]}"
|
||||
except Exception:
|
||||
return d
|
||||
|
||||
geschlecht = {"m": "Rüde", "w": "Hündin"}.get(dog.get("geschlecht",""), "–")
|
||||
|
||||
# Impfungen
|
||||
impfungen = [r for r in health_rows if r["typ"] == "impfung"]
|
||||
# Medikamente (aktiv)
|
||||
medis = [r for r in health_rows if r["typ"] == "medikament" and r["aktiv"]]
|
||||
# Allergien
|
||||
allergien = [r for r in health_rows if r["typ"] == "allergie"]
|
||||
|
||||
def health_rows_html(rows, cols):
|
||||
if not rows:
|
||||
return '<tr><td colspan="99" style="color:#999;font-style:italic">Keine Einträge</td></tr>'
|
||||
out = ""
|
||||
for r in rows:
|
||||
out += "<tr>" + "".join(f"<td>{esc(r[c])}</td>" for c in cols) + "</tr>"
|
||||
return out
|
||||
|
||||
photo_html = f'<img src="{esc(dog["foto_url"])}" alt="{esc(dog["name"])}" class="dog-photo">' if dog.get("foto_url") else '<div class="dog-photo-placeholder">🐕</div>'
|
||||
|
||||
vets_html = ""
|
||||
for v in vets:
|
||||
addr = ", ".join(filter(None, [v.get("strasse"), v.get("plz"), v.get("ort")]))
|
||||
vets_html += f'<div class="vet-card"><strong>{esc(v["name"])}</strong>'
|
||||
if addr: vets_html += f'<br><small>{esc(addr)}</small>'
|
||||
if v.get("telefon"): vets_html += f'<br><small>☎ {esc(v["telefon"])}</small>'
|
||||
vets_html += "</div>"
|
||||
if not vets_html:
|
||||
vets_html = '<span style="color:#999;font-style:italic">Keine Tierärzte eingetragen</span>'
|
||||
|
||||
html = f"""<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Heimtierausweis – {esc(dog["name"])}</title>
|
||||
<style>
|
||||
* {{ box-sizing: border-box; margin: 0; padding: 0; }}
|
||||
body {{ font-family: "Segoe UI", Arial, sans-serif; background: #FAF7F2; color: #1a1a1a; padding: 2rem; }}
|
||||
.ausweis {{ max-width: 800px; margin: 0 auto; background: #fff; border-radius: 12px; box-shadow: 0 2px 20px rgba(0,0,0,.08); overflow: hidden; }}
|
||||
.header {{ background: linear-gradient(135deg, #C4843A, #e8a857); color: #fff; padding: 2rem; display: flex; gap: 1.5rem; align-items: center; }}
|
||||
.dog-photo {{ width: 100px; height: 100px; border-radius: 50%; object-fit: cover; border: 3px solid rgba(255,255,255,.6); flex-shrink: 0; }}
|
||||
.dog-photo-placeholder {{ width: 100px; height: 100px; border-radius: 50%; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; font-size: 2.5rem; flex-shrink: 0; }}
|
||||
.header-info h1 {{ font-size: 1.8rem; font-weight: 700; }}
|
||||
.header-info .rasse {{ opacity: .85; font-size: 1rem; margin-top: .2rem; }}
|
||||
.meta-grid {{ display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; margin-top: 1rem; }}
|
||||
.meta-item {{ background: rgba(255,255,255,.15); border-radius: 8px; padding: .5rem .75rem; }}
|
||||
.meta-item .label {{ font-size: .65rem; opacity: .8; text-transform: uppercase; letter-spacing: .05em; }}
|
||||
.meta-item .value {{ font-weight: 600; font-size: .9rem; margin-top: .1rem; }}
|
||||
.body {{ padding: 1.5rem 2rem; }}
|
||||
.section {{ margin-bottom: 1.5rem; }}
|
||||
.section h2 {{ font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: #C4843A; font-weight: 700; margin-bottom: .75rem; padding-bottom: .4rem; border-bottom: 2px solid #f0e8dc; }}
|
||||
table {{ width: 100%; border-collapse: collapse; font-size: .85rem; }}
|
||||
th {{ text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: #888; font-weight: 600; padding: .4rem .5rem; border-bottom: 1px solid #eee; }}
|
||||
td {{ padding: .45rem .5rem; border-bottom: 1px solid #f5f5f5; vertical-align: top; }}
|
||||
tr:last-child td {{ border-bottom: none; }}
|
||||
.vet-card {{ display: inline-block; background: #f9f6f2; border: 1px solid #ede5d8; border-radius: 8px; padding: .6rem 1rem; margin-right: .5rem; margin-bottom: .5rem; font-size: .85rem; line-height: 1.5; }}
|
||||
.print-btn {{ display: block; margin: 0 auto 1.5rem; padding: .6rem 2rem; background: #C4843A; color: #fff; border: none; border-radius: 8px; font-size: 1rem; cursor: pointer; }}
|
||||
.footer {{ text-align: center; padding: 1rem; font-size: .7rem; color: #aaa; border-top: 1px solid #f0f0f0; }}
|
||||
@media print {{
|
||||
body {{ background: #fff; padding: 0; }}
|
||||
.ausweis {{ box-shadow: none; border-radius: 0; }}
|
||||
.print-btn {{ display: none; }}
|
||||
.no-print {{ display: none; }}
|
||||
}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="ausweis">
|
||||
<div class="header">
|
||||
{photo_html}
|
||||
<div class="header-info">
|
||||
<h1>{esc(dog["name"])}</h1>
|
||||
<div class="rasse">{esc(dog.get("rasse") or "Rasse unbekannt")}</div>
|
||||
<div class="meta-grid">
|
||||
<div class="meta-item"><div class="label">Geburtstag</div><div class="value">{fmt_date(dog.get("geburtstag"))}</div></div>
|
||||
<div class="meta-item"><div class="label">Geschlecht</div><div class="value">{geschlecht}</div></div>
|
||||
<div class="meta-item"><div class="label">Gewicht</div><div class="value">{f'{dog["gewicht_kg"]} kg' if dog.get("gewicht_kg") else "–"}</div></div>
|
||||
<div class="meta-item"><div class="label">Transponder</div><div class="value">{esc(dog.get("chip_nr")) or "–"}</div></div>
|
||||
<div class="meta-item"><div class="label">Besitzer</div><div class="value">{esc(owner["name"]) if owner else "–"}</div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="body">
|
||||
<button class="print-btn no-print" onclick="window.print()">🖨 Drucken / Als PDF speichern</button>
|
||||
|
||||
<div class="section">
|
||||
<h2>Impfungen</h2>
|
||||
<table>
|
||||
<thead><tr><th>Impfung</th><th>Datum</th><th>Nächste Fälligkeit</th><th>Charge</th><th>Tierarzt</th></tr></thead>
|
||||
<tbody>{health_rows_html(impfungen, ["bezeichnung","datum","naechstes","charge_nr","tierarzt_name"])}</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>Aktive Medikamente</h2>
|
||||
<table>
|
||||
<thead><tr><th>Medikament</th><th>Seit</th><th>Dosierung</th><th>Häufigkeit</th></tr></thead>
|
||||
<tbody>{health_rows_html(medis, ["bezeichnung","datum","dosierung","haeufigkeit"])}</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>Allergien & Unverträglichkeiten</h2>
|
||||
<table>
|
||||
<thead><tr><th>Allergen</th><th>Schweregrad</th><th>Reaktion</th><th>Seit</th></tr></thead>
|
||||
<tbody>{health_rows_html(allergien, ["bezeichnung","schweregrad","reaktion","datum"])}</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<h2>Tierärzte</h2>
|
||||
{vets_html}
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">Erstellt mit BAN YARO · banyaro.app · {fmt_date(__import__("datetime").date.today().isoformat())}</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>"""
|
||||
return HTMLResponse(html)
|
||||
|
||||
|
||||
# SPA Fallback — ALLE nicht-API-Routen gehen zur index.html
|
||||
@app.get("/{full_path:path}")
|
||||
async def spa_fallback(full_path: str):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue