feat: inline edit — click task name → Alpine input → Enter saves via PUT /api/task/{uid}/update. fix: app.py indentation, CSS add-task/t-edit-wrap

This commit is contained in:
2026-10-24 06:15:13 +00:00
parent 22c2223840
commit c1cbd4bc46
3 changed files with 37 additions and 7 deletions
+18
View File
@@ -0,0 +1,18 @@
"""Fix indentation of lines 379-381 in app.py."""
path = "webui/app.py"
with open(path) as f:
lines = f.readlines()
# Fix lines 379-381: remove 8 leading spaces (they have 16, should have 8)
for i in range(378, 382): # 0-indexed: 378 = line 379
if i < len(lines):
stripped = lines[i].lstrip()
current_indent = len(lines[i]) - len(stripped)
if current_indent == 16:
lines[i] = " " * 8 + stripped
with open(path, "w") as f:
f.writelines(lines)
compile(open(path).read(), path, 'exec')
print("OK")
+12 -3
View File
@@ -371,14 +371,22 @@ def task_toggle(uid: str, request: Request, _: AuthDep,
@app.get("/api/tasks/reload")
def tasks_reload(request: Request, _: AuthDep):
"""HTMX-фрагмент: весь блок задач для главной (создание + инлайн-редактирование)."""
import json as _json
tasks = radicale.get_tasks()
items = []
for t in tasks:
due_html = f'<div class="d">срок {t["due"]}</div>' if t.get("due") else ""
items.append(f'''<div class="tk {'done' if t['completed'] else ''}">
sid = _json.dumps(t["summary"], ensure_ascii=False)
xdata = '{{edit:{},editing:false}}'.format(sid)
items.append(f'''<div class="tk {'done' if t['completed'] else ''}" x-data="{xdata}">
<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>
<div class="t" x-on:click="edit={sid};editing=true">{t['summary']}</div>
<template x-if="editing">
<div class="t-edit-wrap">
<input x-model="edit" x-on:keyup.enter="fetch('/api/task/{t['uid']}/update',{{method:'PUT',headers:{{'Content-Type':'application/json'}},body:JSON.stringify({{summary:edit}})}}).then(()=>location.reload())" x-on:keyup.escape="editing=false;edit=''">
</div>
</template>
{due_html}
</div>
</div>''')
@@ -386,7 +394,8 @@ def tasks_reload(request: Request, _: AuthDep):
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">+ Новая задача</button>'
html = f'''<div class="chead">✅ Текущие задачи <span class="cnt">{active}</span></div>
<div class="cbody">{items_html}{btn}</div>'''
<div class="cbody">
{items_html}{btn}</div>'''
return HTMLResponse(html)
+3
View File
@@ -198,6 +198,9 @@ body.f3 .c3{flex:1}
.pb-btn{background:none;border:1px solid var(--border);color:var(--fg);cursor:pointer;font-size:16px;padding:3px 8px;border-radius:6px;line-height:1}
.pb-btn:hover{background:var(--hover);border-color:var(--accent)}
.pb-btn:disabled{opacity:0.4;cursor:default}
.add-task{background:none;border:1px dashed var(--fg3);color:var(--fg2);cursor:pointer;font-size:12px;padding:6px 14px;border-radius:6px;margin:6px 10px;width:calc(100% - 20px)}
.add-task:hover{border-color:var(--accent);color:var(--fg)}
.t-edit-wrap input{width:100%;padding:2px 4px;border:1px solid var(--accent);border-radius:4px;background:var(--bg);color:var(--fg);font:inherit;font-size:12.5px}
.em{display:flex;gap:8px;padding:8px 14px;border-bottom:1px solid var(--border);
cursor:pointer;align-items:flex-start}