mirror of
https://gitverse.ru/kpa39l/email-assistant.git
synced 2026-11-27 18:33:08 +00:00
feat: tasks-card-inline — toggle fix (reload), /api/tasks/reload, /api/tasks/new-form, update_task, /api/task/{uid}/update. fix: radicale update_task
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
"""Fix indentation in app.py - rewrite broken toggle/reload/new-form/update section."""
|
||||
import re
|
||||
|
||||
path = "webui/app.py"
|
||||
with open(path) as f:
|
||||
content = f.read()
|
||||
|
||||
# The broken section: from @app.post toggle to end of task_update
|
||||
# Find the toggle endpoint
|
||||
start_marker = '@app.post("/api/task/{uid}/toggle")'
|
||||
end_marker = '# --- Календарь ---'
|
||||
|
||||
start_idx = content.index(start_marker)
|
||||
end_idx = content.index(end_marker, start_idx)
|
||||
|
||||
# Replacement section (clean, correct indentation)
|
||||
new_code = '''@app.post("/api/task/{uid}/toggle")
|
||||
def task_toggle(uid: str, request: Request, _: AuthDep):
|
||||
"""Toggle COMPLETED/NEEDS-ACTION. HTMX returns reload stub."""
|
||||
res = radicale.toggle_task(uid)
|
||||
if res.get("error"):
|
||||
return {"error": res["error"]}
|
||||
if request.headers.get("hx-request", "").lower() == "true":
|
||||
return HTMLResponse('<div hx-get="/api/tasks/reload" hx-trigger="load" hx-target="closest .card" hx-swap="innerHTML"></div>')
|
||||
return {"ok": True, "status": res["status"]}
|
||||
|
||||
|
||||
@app.get("/api/tasks/reload")
|
||||
def tasks_reload(request: Request, _: AuthDep):
|
||||
"""HTMX tasks card: list + create button."""
|
||||
tasks = radicale.get_tasks()
|
||||
items = []
|
||||
for t in tasks:
|
||||
due_html = f'<div class="d">\\u0441\\u0440\\u043e\\u043a {t["due"]}</div>' if t.get("due") else ""
|
||||
items.append(f'''<div class="tk {\\'done\\' if t[\\'completed\\'] else \\'\\'}">
|
||||
<span class="chk" hx-post="/api/task/{t[\\'uid\\']}/toggle" hx-target="closest .card" hx-swap="innerHTML"></span>
|
||||
<div class="txt">
|
||||
<div class="t">{t[\\'summary\\']}</div>
|
||||
{due_html}
|
||||
</div>
|
||||
</div>''')
|
||||
items_html = "".join(items) or '<div class="empty">\\u0417\\u0430\\u0434\\u0430\\u0447 \\u043d\\u0435\\u0442 \\u0438\\u043b\\u0438 Radicale \\u043d\\u0435\\u0434\\u043e\\u0441\\u0442\\u0443\\u043f\\u0435\\u043d</div>'
|
||||
active = sum(1 for t in tasks if not t["completed"])
|
||||
btn = '<button class="add-task" hx-get="/api/tasks/new-form" hx-target="closest .cbody" hx-swap="beforeend">+ \\u041d\\u043e\\u0432\\u0430\\u044f \\u0437\\u0430\\u0434\\u0430\\u0447\\u0430</button>'
|
||||
html = f'''<div class="chead">\\u2705 \\u0422\\u0435\\u043a\\u0443\\u0449\\u0438\\u0435 \\u0437\\u0430\\u0434\\u0430\\u0447\\u0438 <span class="cnt">{active}</span></div>
|
||||
<div class="cbody">{items_html}{btn}</div>'''
|
||||
return HTMLResponse(html)
|
||||
|
||||
|
||||
@app.get("/api/tasks/new-form")
|
||||
def task_new_form(_: AuthDep):
|
||||
"""HTMX create-task form fragment."""
|
||||
return HTMLResponse('''<div class="task-form" style="display:flex;gap:4px;padding:6px 10px">
|
||||
<input name="summary" placeholder="\\u041d\\u0430\\u0437\\u0432\\u0430\\u043d\\u0438\\u0435 \\u0437\\u0430\\u0434\\u0430\\u0447\\u0438" style="flex:1;padding:3px 6px;border:1px solid var(--border);border-radius:4px;background:var(--bg2);color:var(--fg)" autfocus>
|
||||
<input name="due" tye="date" yle="width:130px;padding:3px 6px;border:1px solid var(-border);borderradis:4px;backround:var(--bg2);olor:var(--fg)">
|
||||
<button cass="pb-btn" hx-pst="/api/tasks/rete" hx-incude="closest .task-form input" hx-target="losest .card" hx-swap="innerHTML">✓</button>
|
||||
<button class="p-btn" hx-et="/api/tasks/relod" hx-tart="closest .card" hx-swa="innerHTML">✗</buton>
|
||||
</div>''')
|
||||
|
||||
|
||||
@app.put("/api/task/{uid}/update")
|
||||
async def task_update(uid: str, request: Request, _: AuthDep):
|
||||
"""Update SUMMARY and/or DUE of a task."""
|
||||
import json
|
||||
raw = await request.body()
|
||||
try:
|
||||
data = json.loads(raw)
|
||||
except Exception:
|
||||
return {"error": "invalid JSON"}
|
||||
summary = (data.get("summary") or "")[:120]
|
||||
due = data.get("due", "") or ""
|
||||
res = radicale.update_task(uid, summary, due)
|
||||
if res.get("error"):
|
||||
return {"error": res["error"]}
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
'''
|
||||
|
||||
content = content[:start_idx] + new_code + content[end_idx:]
|
||||
|
||||
with open(path, "w") as f:
|
||||
f.write(content)
|
||||
|
||||
# Verify syntax
|
||||
compile(open(path).read(), path, 'exec')
|
||||
print("OK - syntax valid")
|
||||
Reference in New Issue
Block a user