Rolodex UX: add /rolodex/{id}/edit route, prefill support for new form, fix edit links, and improve empty state guidance. Also fix header width lints in template.

This commit is contained in:
HotSwapp
2025-10-13 10:37:20 -05:00
parent 42ea13e413
commit 4cd35c66fd
3 changed files with 36 additions and 12 deletions

View File

@@ -2604,12 +2604,37 @@ async def rolodex_list(
@app.get("/rolodex/new") @app.get("/rolodex/new")
async def rolodex_new(request: Request): async def rolodex_new(
request: Request,
prefill: str | None = Query(None, alias="_prefill"),
db: Session = Depends(get_db),
):
user = get_current_user_from_session(request.session) user = get_current_user_from_session(request.session)
if not user: if not user:
return RedirectResponse(url="/login", status_code=302) return RedirectResponse(url="/login", status_code=302)
return templates.TemplateResponse("rolodex_edit.html", {"request": request, "user": user, "client": None}) client = None
if prefill:
try:
client_id = int(prefill)
client = db.query(Client).filter(Client.id == client_id).first()
except ValueError:
client = None
return templates.TemplateResponse("rolodex_edit.html", {"request": request, "user": user, "client": client})
@app.get("/rolodex/{client_id}/edit")
async def rolodex_edit(client_id: int, request: Request, db: Session = Depends(get_db)):
user = get_current_user_from_session(request.session)
if not user:
return RedirectResponse(url="/login", status_code=302)
client = db.query(Client).filter(Client.id == client_id).first()
if not client:
raise HTTPException(status_code=404, detail="Client not found")
return templates.TemplateResponse("rolodex_edit.html", {"request": request, "user": user, "client": client})
@app.get("/rolodex/{client_id}") @app.get("/rolodex/{client_id}")

View File

@@ -56,7 +56,7 @@
<th style="width: 40px;"><input class="form-check-input js-select-all" type="checkbox"></th> <th style="width: 40px;"><input class="form-check-input js-select-all" type="checkbox"></th>
{% endif %} {% endif %}
{% for h in headers %} {% for h in headers %}
<th{% if h.width %} style="width: {{ h.width }};"{% endif %}{% if h.align == 'end' %} class="text-end"{% endif %}>{{ h.title }}</th> <th{% if h.width %} width="{{ h.width | replace('px', '') }}"{% endif %}{% if h.align == 'end' %} class="text-end"{% endif %}>{{ h.title }}</th>
{% endfor %} {% endfor %}
</tr> </tr>
</thead> </thead>
@@ -91,7 +91,12 @@
{% endfor %} {% endfor %}
{% else %} {% else %}
<tr> <tr>
<td colspan="8" class="text-center text-muted py-4">No clients found.</td> <td colspan="8" class="text-center text-muted py-4">
No clients found.
<div class="small mt-1">
If you've imported legacy data, go to <a href="/admin">Admin</a> and run <em>Sync to Modern Models</em> to populate Clients and Phones.
</div>
</td>
</tr> </tr>
{% endif %} {% endif %}
</tbody> </tbody>

View File

@@ -11,12 +11,9 @@
</a> </a>
<h2 class="mb-0">Client</h2> <h2 class="mb-0">Client</h2>
<div class="ms-auto"> <div class="ms-auto">
<a class="btn btn-sm btn-outline-primary" href="/rolodex/{{ client.id }}/edit" onclick="event.preventDefault(); document.getElementById('editFormLink').submit();"> <a class="btn btn-sm btn-outline-primary" href="/rolodex/{{ client.id }}/edit">
<i class="bi bi-pencil-square me-1"></i>Edit <i class="bi bi-pencil-square me-1"></i>Edit
</a> </a>
<form id="editFormLink" method="get" action="/rolodex/new" class="d-none">
<input type="hidden" name="_" value="1">
</form>
</div> </div>
</div> </div>
@@ -57,12 +54,9 @@
</div> </div>
<div class="d-flex gap-2"> <div class="d-flex gap-2">
<a class="btn btn-primary" href="/rolodex/new" onclick="event.preventDefault(); document.getElementById('editClientForm').submit();"> <a class="btn btn-primary" href="/rolodex/{{ client.id }}/edit">
<i class="bi bi-pencil-square me-1"></i>Edit Client <i class="bi bi-pencil-square me-1"></i>Edit Client
</a> </a>
<form id="editClientForm" method="get" action="/rolodex/new" class="d-none">
<input type="hidden" name="_prefill" value="{{ client.id }}">
</form>
<form method="post" action="/rolodex/{{ client.id }}/delete" onsubmit="return confirm('Delete this client? This cannot be undone.');"> <form method="post" action="/rolodex/{{ client.id }}/delete" onsubmit="return confirm('Delete this client? This cannot be undone.');">
<button type="submit" class="btn btn-outline-danger"> <button type="submit" class="btn btn-outline-danger">
<i class="bi bi-trash me-1"></i>Delete <i class="bi bi-trash me-1"></i>Delete