Add cancel job action
POST /jobs/{id}/cancel sets status → cancelled, frees printer if printing,
logs 'Job cancelled'. Button visible in all non-terminal states (queued, printing).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -354,6 +354,20 @@ def start_job(job_id: int, printer_id: int = Form(...), db: Session = Depends(ge
|
|||||||
return RedirectResponse(url=f"/jobs/{job_id}", status_code=HTTP_303_SEE_OTHER)
|
return RedirectResponse(url=f"/jobs/{job_id}", status_code=HTTP_303_SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/jobs/{job_id}/cancel")
|
||||||
|
def cancel_job(job_id: int, db: Session = Depends(get_db)):
|
||||||
|
from fastapi import HTTPException
|
||||||
|
job = db.query(PrintJob).filter(PrintJob.id == job_id).first()
|
||||||
|
if not job:
|
||||||
|
raise HTTPException(404, "Job not found")
|
||||||
|
if job.printer and job.status == JobStatus.printing:
|
||||||
|
job.printer.status = PrinterStatus.idle
|
||||||
|
job.status = JobStatus.cancelled
|
||||||
|
db.add(JobLog(job_id=job_id, message="Job cancelled"))
|
||||||
|
db.commit()
|
||||||
|
return RedirectResponse(url=f"/jobs/{job_id}", status_code=HTTP_303_SEE_OTHER)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/jobs/{job_id}/stop")
|
@router.post("/jobs/{job_id}/stop")
|
||||||
def stop_job(job_id: int, db: Session = Depends(get_db)):
|
def stop_job(job_id: int, db: Session = Depends(get_db)):
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
|||||||
@@ -27,14 +27,13 @@
|
|||||||
|
|
||||||
{# ── Job actions ── #}
|
{# ── Job actions ── #}
|
||||||
{% set s = job.status.value %}
|
{% set s = job.status.value %}
|
||||||
{% if s == 'queued' %}
|
{% if s not in ('done', 'cancelled') %}
|
||||||
<div class="mb-4">
|
<div class="d-flex gap-2 mb-4">
|
||||||
|
{% if s == 'queued' %}
|
||||||
<button class="btn btn-success btn-sm" data-bs-toggle="modal" data-bs-target="#startModal">
|
<button class="btn btn-success btn-sm" data-bs-toggle="modal" data-bs-target="#startModal">
|
||||||
<i class="bi bi-play-fill me-1"></i>Start Job
|
<i class="bi bi-play-fill me-1"></i>Start Job
|
||||||
</button>
|
</button>
|
||||||
</div>
|
{% elif s == 'printing' %}
|
||||||
{% elif s == 'printing' %}
|
|
||||||
<div class="d-flex gap-2 mb-4">
|
|
||||||
<form method="POST" action="/jobs/{{ job.id }}/finish">
|
<form method="POST" action="/jobs/{{ job.id }}/finish">
|
||||||
<button type="submit" class="btn btn-success btn-sm">
|
<button type="submit" class="btn btn-success btn-sm">
|
||||||
<i class="bi bi-check-lg me-1"></i>Finish
|
<i class="bi bi-check-lg me-1"></i>Finish
|
||||||
@@ -45,6 +44,12 @@
|
|||||||
<i class="bi bi-stop-fill me-1"></i>Stop
|
<i class="bi bi-stop-fill me-1"></i>Stop
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
<form method="POST" action="/jobs/{{ job.id }}/cancel">
|
||||||
|
<button type="submit" class="btn btn-outline-danger btn-sm">
|
||||||
|
<i class="bi bi-x-lg me-1"></i>Cancel Job
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user