mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-21 01:57:41 +02:00
feat(printers): show plate name on card for multi-plate active prints (#881)
When two printers were running different plates of the same multi-plate 3MF, the Printers page cards displayed the same file name on both and there was no way to tell them apart. The Queue view already had this information by cross-referencing the archive's plate list; the card didn't have the linkage. Expose `current_archive_id` (resolved by matching the MQTT `subtask_id` against `PrintArchive.subtask_id` — the bridge introduced in #972 for restart-resume) and `current_plate_id` (parsed from `gcode_file` by a new shared `parse_plate_id` helper) on the status endpoint. The helper is also called from the WebSocket push path so plate transitions reflect within 100 ms instead of waiting 30 s for the next REST poll; the archive id itself stays REST-only since it's stable for the life of a print and shouldn't make the push path touch the DB. The card fetches plate metadata via the same `api.getArchivePlates()` call QueuePage uses — shared React Query cache keeps it cheap across polls — and renders the actual plate name (or a "Plate N" fallback) only when `is_multi_plate` is true. Single-plate prints stay clean. Falls back to the previous `plate_N.gcode` regex path when there's no archive linkage (e.g. prints started directly from the printer LCD). Tests cover the plate-id extraction across Bambu Studio path shapes (backend parse_plate_id, printer_state_to_dict wiring) and the label override precedence in formatPrintName (frontend).
This commit is contained in:
@@ -39,6 +39,7 @@ from backend.app.services.bambu_ftp import (
|
||||
)
|
||||
from backend.app.services.printer_manager import (
|
||||
get_derived_status_name,
|
||||
parse_plate_id,
|
||||
printer_manager,
|
||||
supports_chamber_temp,
|
||||
supports_drying,
|
||||
@@ -561,6 +562,26 @@ async def get_printer_status(
|
||||
k: v for k, v in temperatures.items() if k not in ("chamber", "chamber_target", "chamber_heating")
|
||||
}
|
||||
|
||||
# Resolve the active print's archive + plate (#881 follow-up): lets the
|
||||
# printer card show the actual plate name for multi-plate 3MFs instead of
|
||||
# just the 3MF filename. Only attempted for active prints, since subtask_id
|
||||
# is only meaningful then.
|
||||
current_archive_id: int | None = None
|
||||
current_plate_id: int | None = None
|
||||
if state.state in ("RUNNING", "PAUSE"):
|
||||
current_plate_id = parse_plate_id(state.gcode_file)
|
||||
if state.subtask_id:
|
||||
from backend.app.models.archive import PrintArchive
|
||||
|
||||
archive_row = await db.execute(
|
||||
select(PrintArchive.id)
|
||||
.where(PrintArchive.subtask_id == state.subtask_id)
|
||||
.where(PrintArchive.printer_id == printer_id)
|
||||
.order_by(PrintArchive.created_at.desc())
|
||||
.limit(1)
|
||||
)
|
||||
current_archive_id = archive_row.scalar_one_or_none()
|
||||
|
||||
return PrinterStatus(
|
||||
id=printer_id,
|
||||
name=printer.name,
|
||||
@@ -612,6 +633,8 @@ async def get_printer_status(
|
||||
developer_mode=state.developer_mode if state else None,
|
||||
awaiting_plate_clear=printer_manager.is_awaiting_plate_clear(printer_id),
|
||||
supports_drying=supports_drying(printer.model, state.firmware_version),
|
||||
current_archive_id=current_archive_id,
|
||||
current_plate_id=current_plate_id,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user