Add 'Compute now' button to job detail File & Geometry card
POST /jobs/{id}/analyse clears the stl_cache entry and re-runs trimesh,
then redirects back to the detail page. Button hidden for .gcode files.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -21,7 +21,7 @@ from app.models.todo import Todo
|
||||
from app.constants import COLORS, MATERIALS
|
||||
from app.filamentdb import available_colors, available_materials, get_stock
|
||||
from app.stl import get_stl_dir, list_stl_files
|
||||
from app.stl_analysis import analyse, get_cache_map
|
||||
from app.stl_analysis import analyse, get_cache_map # noqa: F401 used in job_detail route
|
||||
|
||||
router = APIRouter()
|
||||
templates = Jinja2Templates(directory="app/templates")
|
||||
@@ -222,6 +222,18 @@ def job_detail(job_id: int, request: Request, db: Session = Depends(get_db)):
|
||||
})
|
||||
|
||||
|
||||
@router.post("/jobs/{job_id}/analyse")
|
||||
def analyse_job_file(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 or not job.file_name:
|
||||
raise HTTPException(status_code=404, detail="Job or file not found")
|
||||
db.query(StlCache).filter_by(filename=job.file_name).delete()
|
||||
db.commit()
|
||||
analyse(job.file_name, db)
|
||||
return RedirectResponse(url=f"/jobs/{job_id}", status_code=HTTP_303_SEE_OTHER)
|
||||
|
||||
|
||||
@router.post("/jobs/{job_id}/log")
|
||||
def add_job_log(job_id: int, message: str = Form(...), db: Session = Depends(get_db)):
|
||||
db.add(JobLog(job_id=job_id, message=message.strip()))
|
||||
|
||||
@@ -70,8 +70,15 @@
|
||||
{# ── STL geometry ── #}
|
||||
<div class="col-md-6">
|
||||
<div class="card h-100">
|
||||
<div class="card-header text-secondary small text-uppercase fw-normal" style="border-color:#21262d">
|
||||
File & Geometry
|
||||
<div class="card-header border-secondary d-flex align-items-center justify-content-between" style="border-color:#21262d">
|
||||
<span class="text-secondary small text-uppercase fw-normal">File & Geometry</span>
|
||||
{% if job.file_name and not job.file_name.endswith('.gcode') %}
|
||||
<form method="POST" action="/jobs/{{ job.id }}/analyse">
|
||||
<button type="submit" class="btn btn-outline-secondary btn-sm py-0 px-2" style="font-size:.75rem">
|
||||
<i class="bi bi-cpu me-1"></i>Compute now
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
{% if job.file_name %}
|
||||
@@ -91,7 +98,7 @@
|
||||
{% elif job.file_name and job.file_name.endswith('.gcode') %}
|
||||
<p class="text-secondary small mb-0">Geometry not available for gcode files.</p>
|
||||
{% elif job.file_name %}
|
||||
<p class="text-secondary small mb-0">Not yet analysed — will be computed on next upload.</p>
|
||||
<p class="text-secondary small mb-0">Not yet analysed.</p>
|
||||
{% else %}
|
||||
<p class="text-secondary small mb-0">No file attached.</p>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user