feat(03-02): implement printer detail page with driver info and regenerate placeholder
- Add GET /printers/{printer_id} route to pages.py with LEFT OUTER JOINs on Client and Driver
- Create printer_detail.html full-page template showing all config fields and driver info
- Display "No driver assigned" when driver FK is null
- Add disabled "Regenerate Package" button (Phase 4 placeholder)
- Make printer names in printer_list.html clickable links to detail page
This commit is contained in:
@@ -7,6 +7,7 @@ from fastapi.responses import HTMLResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from peewee import JOIN
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
templates = Jinja2Templates(directory=str(Path(__file__).parent.parent / "templates"))
|
||||
@@ -73,6 +74,35 @@ def printers_page(request: Request):
|
||||
)
|
||||
|
||||
|
||||
@router.get("/printers/{printer_id}", response_class=HTMLResponse)
|
||||
def printer_detail(request: Request, printer_id: int):
|
||||
from imptune.db.models import Client, Driver, Printer
|
||||
|
||||
printer = (
|
||||
Printer.select(Printer, Client, Driver)
|
||||
.join(Client, JOIN.LEFT_OUTER)
|
||||
.switch(Printer)
|
||||
.join(Driver, JOIN.LEFT_OUTER)
|
||||
.where(Printer.id == printer_id)
|
||||
.first()
|
||||
)
|
||||
if printer is None:
|
||||
return HTMLResponse(
|
||||
content="<h1>404 Not Found</h1><p>Printer not found.</p>",
|
||||
status_code=404,
|
||||
)
|
||||
|
||||
driver_names: list[str] = []
|
||||
if printer.driver_id and printer.driver.driver_desc:
|
||||
driver_names = json.loads(printer.driver.driver_desc)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
request=request,
|
||||
name="printer_detail.html",
|
||||
context={"printer": printer, "driver_names": driver_names},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/clients", response_class=HTMLResponse)
|
||||
def clients_page(request: Request):
|
||||
from imptune.db.models import Client
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<tbody>
|
||||
{% for p in printers %}
|
||||
<tr>
|
||||
<td>{{ p.name }}</td>
|
||||
<td><a href="/printers/{{ p.id }}">{{ p.name }}</a></td>
|
||||
<td>{{ p.ip_address }}</td>
|
||||
<td>{{ p.port_name }}</td>
|
||||
<td>{{ p.driver.original_filename if p.driver_id else '—' }}</td>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<h1>{{ printer.name }}</h1>
|
||||
<article>
|
||||
<h2>Configuration</h2>
|
||||
<dl>
|
||||
<dt>IP Address</dt><dd>{{ printer.ip_address }}</dd>
|
||||
<dt>Port Name</dt><dd>{{ printer.port_name }}</dd>
|
||||
<dt>Duplex Mode</dt><dd>{{ printer.duplex_mode }}</dd>
|
||||
<dt>Color Mode</dt><dd>{{ "Color" if printer.color_mode else "Grayscale" }}</dd>
|
||||
<dt>Paper Size</dt><dd>{{ printer.paper_size }}</dd>
|
||||
<dt>Collate</dt><dd>{{ "Yes" if printer.collate else "No" }}</dd>
|
||||
<dt>Client</dt><dd>{{ printer.client.name if printer.client_id else "Unassigned" }}</dd>
|
||||
</dl>
|
||||
|
||||
<h2>Driver</h2>
|
||||
{% if printer.driver_id %}
|
||||
<dl>
|
||||
<dt>Package</dt><dd>{{ printer.driver.original_filename }}</dd>
|
||||
<dt>Driver Name(s)</dt><dd>{{ driver_names | join(", ") }}</dd>
|
||||
<dt>Architecture</dt><dd>{{ printer.driver.architecture or "Unknown" }}</dd>
|
||||
</dl>
|
||||
{% else %}
|
||||
<p>No driver assigned</p>
|
||||
{% endif %}
|
||||
|
||||
<h2>Actions</h2>
|
||||
<button disabled aria-busy="false" title="Available after script generation is implemented (Phase 4)">
|
||||
Regenerate Package
|
||||
</button>
|
||||
<a href="/printers" role="button" class="secondary">Back to Printers</a>
|
||||
</article>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user