Fix post-create redirect and add bracket filter to jobs list
- After job creation always redirect to /jobs (never bracket detail) - If a bracket was involved, redirect to /jobs?bracket_id=X instead - GET /jobs?bracket_id=X filters the list and shows a dismissible bracket badge - Amount label now says '(≥2 creates a bracket)' to make the side effect clear Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -127,18 +127,23 @@ def create_printer_type(
|
||||
# ── Jobs ───────────────────────────────────────────────────────────────────────
|
||||
|
||||
@router.get("/jobs", response_class=HTMLResponse)
|
||||
def jobs_page(request: Request, q: str = "", db: Session = Depends(get_db)):
|
||||
def jobs_page(request: Request, q: str = "", bracket_id: str = "", db: Session = Depends(get_db)):
|
||||
query = db.query(PrintJob)
|
||||
if q:
|
||||
like = f"%{q}%"
|
||||
query = query.filter(
|
||||
or_(PrintJob.customer.ilike(like), PrintJob.file_name.ilike(like))
|
||||
)
|
||||
active_bracket = None
|
||||
if bracket_id:
|
||||
query = query.filter(PrintJob.bracket_id == int(bracket_id))
|
||||
active_bracket = db.query(JobBracket).filter(JobBracket.id == int(bracket_id)).first()
|
||||
return templates.TemplateResponse("jobs.html", {
|
||||
"request": request,
|
||||
"active": "jobs",
|
||||
"jobs": query.order_by(PrintJob.priority.desc(), PrintJob.created_at.desc()).all(),
|
||||
"q": q,
|
||||
"active_bracket": active_bracket,
|
||||
"printers": db.query(Printer).order_by(Printer.name).all(),
|
||||
"brackets": db.query(JobBracket).order_by(JobBracket.name).all(),
|
||||
"stl_files": (stl_files := list_stl_files()),
|
||||
@@ -205,8 +210,8 @@ async def create_job(
|
||||
|
||||
db.commit()
|
||||
|
||||
if effective_bracket_id and amount > 1:
|
||||
return RedirectResponse(url=f"/brackets/{effective_bracket_id}", status_code=HTTP_303_SEE_OTHER)
|
||||
if effective_bracket_id:
|
||||
return RedirectResponse(url=f"/jobs?bracket_id={effective_bracket_id}", status_code=HTTP_303_SEE_OTHER)
|
||||
return RedirectResponse(url="/jobs", status_code=HTTP_303_SEE_OTHER)
|
||||
|
||||
|
||||
|
||||
@@ -21,7 +21,14 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
{% if q %}
|
||||
{% if active_bracket %}
|
||||
<div class="d-flex align-items-center gap-2 mb-3">
|
||||
<span class="badge bg-secondary fs-6 fw-normal px-3 py-2">
|
||||
<i class="bi bi-collection me-1"></i>{{ active_bracket.name }}
|
||||
</span>
|
||||
<a href="/jobs{% if q %}?q={{ q }}{% endif %}" class="text-secondary text-decoration-none small">× clear filter</a>
|
||||
</div>
|
||||
{% elif q %}
|
||||
<p class="text-secondary small mb-3">Results for <strong class="text-white">{{ q }}</strong></p>
|
||||
{% endif %}
|
||||
|
||||
@@ -180,11 +187,13 @@
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-4">
|
||||
<label class="form-label text-secondary small">Amount</label>
|
||||
<label class="form-label text-secondary small">
|
||||
Amount
|
||||
<span class="text-secondary fw-normal">(≥2 creates a bracket)</span>
|
||||
</label>
|
||||
<input type="number" name="amount"
|
||||
class="form-control bg-dark border-secondary text-white"
|
||||
value="1" min="1" max="500"
|
||||
title=">1 auto-creates a bracket">
|
||||
value="1" min="1" max="500">
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<label class="form-label text-secondary small">
|
||||
|
||||
Reference in New Issue
Block a user