Add priority flag to jobs

- Migration 0010: priority BOOLEAN NOT NULL DEFAULT 0 on print_jobs
- Priority jobs sort above normal jobs in the list
- Checkbox in Add Job modal; warning icon in list; badge on detail page

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Martin Hohenberg
2026-06-18 22:17:55 +02:00
parent e7df987e5b
commit 6f85cd5d1c
5 changed files with 41 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
"""add priority flag to print_jobs
Revision ID: 0010
Revises: 0009
Create Date: 2026-06-18
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
revision: str = "0010"
down_revision: Union[str, None] = "0009"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.add_column("print_jobs", sa.Column("priority", sa.Boolean(), nullable=False, server_default="0"))
def downgrade() -> None:
op.drop_column("print_jobs", "priority")

View File

@@ -3,7 +3,7 @@ import uuid as _uuid
from datetime import datetime
from decimal import Decimal
from sqlalchemy import DateTime, Enum, ForeignKey, Integer, Numeric, String, Text, func
from sqlalchemy import Boolean, DateTime, Enum, ForeignKey, Integer, Numeric, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.models.base import Base
@@ -29,6 +29,7 @@ class PrintJob(Base):
file_name: Mapped[str | None] = mapped_column(String(255))
job_material: Mapped[str | None] = mapped_column(String(50))
job_color: Mapped[str | None] = mapped_column(String(100))
priority: Mapped[bool] = mapped_column(Boolean, default=False)
status: Mapped[JobStatus] = mapped_column(Enum(JobStatus), default=JobStatus.queued)
queue_position: Mapped[int | None] = mapped_column(Integer)
started_at: Mapped[datetime | None] = mapped_column(DateTime)

View File

@@ -135,7 +135,7 @@ def jobs_page(request: Request, q: str = "", db: Session = Depends(get_db)):
return templates.TemplateResponse("jobs.html", {
"request": request,
"active": "jobs",
"jobs": query.order_by(PrintJob.created_at.desc()).all(),
"jobs": query.order_by(PrintJob.priority.desc(), PrintJob.created_at.desc()).all(),
"q": q,
"printers": db.query(Printer).order_by(Printer.name).all(),
"filaments": db.query(Filament).order_by(Filament.material, Filament.color).all(),
@@ -153,6 +153,7 @@ async def create_job(
customer: str = Form(""),
job_material: str = Form(""),
job_color: str = Form(""),
priority: str = Form(""),
bracket_id: str = Form(""),
amount: int = Form(1),
notes: str = Form(""),
@@ -193,6 +194,7 @@ async def create_job(
customer=customer_str,
job_material=job_material or None,
job_color=job_color or None,
priority=bool(priority),
notes=notes.strip() or None,
)
db.add(job)

View File

@@ -10,6 +10,7 @@
<div class="d-flex align-items-center gap-2">
<h5 class="text-white mb-0">{{ job.file_name or job.name }}</h5>
{% set s = job.status.value %}
{% if job.priority %}<span class="badge bg-warning text-dark"><i class="bi bi-exclamation-circle me-1"></i>Priority</span>{% endif %}
{% if s == 'printing' %}<span class="badge bg-primary">printing</span>
{% elif s == 'done' %}<span class="badge bg-success">done</span>
{% elif s == 'failed' %}<span class="badge bg-danger">failed</span>

View File

@@ -30,6 +30,7 @@
<table class="table table-dark table-hover mb-0 align-middle" style="font-size:.875rem">
<thead>
<tr class="text-secondary small">
<th class="fw-normal"></th>
<th class="fw-normal">UUID</th>
<th class="fw-normal">Customer</th>
<th class="fw-normal">File</th>
@@ -42,6 +43,9 @@
<tbody>
{% for j in jobs %}
<tr>
<td style="width:24px">
{% if j.priority %}<i class="bi bi-exclamation-circle-fill text-warning" title="Priority"></i>{% endif %}
</td>
<td class="font-monospace text-secondary" style="font-size:.75rem">
{{ j.job_uuid[:8] if j.job_uuid else '—' }}
</td>
@@ -157,6 +161,13 @@
</div>
</div>
<div class="form-check form-switch mb-1">
<input class="form-check-input" type="checkbox" name="priority" id="priorityCheck" value="1">
<label class="form-check-label text-secondary small" for="priorityCheck">
<i class="bi bi-exclamation-circle text-warning me-1"></i>Priority
</label>
</div>
<div class="row g-3">
<div class="col-md-4">
<label class="form-label text-secondary small">Amount</label>