Scope git commit to current diagram + fix complete JSON export/import

- Git commit: "Current diagram only" checkbox stages only that diagram's
  JSON file instead of all diagrams
- JSON export now includes: waypoints, twisted_pair, twist_pitch, shielded,
  show_size_label, bundle_id, bundle_label, sheet_id, sheets, wire_bundles
- JSON import reconstructs sheets and bundles with remapped IDs so restored
  diagrams are exact copies

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-24 20:02:19 -04:00
parent 7ae79bc9aa
commit 072e620d56
6 changed files with 130 additions and 21 deletions
+34 -4
View File
@@ -119,10 +119,38 @@ async def import_diagram(request: Request, db: Session = Depends(get_db)):
db.add(new_diag)
db.flush()
id_map = {}
# Sheets: old id → new Sheet object
sheet_map = {}
for s in data.get("sheets", []):
ns = models.Sheet(
diagram_id=new_diag.id,
name=s.get("name", "Sheet 1"),
position=s.get("position", 0),
)
db.add(ns)
db.flush()
if "id" in s:
sheet_map[s["id"]] = ns.id
# Wire bundles: old id → new bundle id
bundle_map = {}
for b in data.get("wire_bundles", []):
nb = models.WireBundle(
diagram_id=new_diag.id,
label=b.get("label", ""),
jacket_color=b.get("jacket_color", "#2a2a2a"),
)
db.add(nb)
db.flush()
if "id" in b:
bundle_map[b["id"]] = nb.id
# Devices: old id → new device id
dev_map = {}
for dev_data in data.get("devices", []):
new_dev = models.Device(
diagram_id=new_diag.id,
sheet_id=sheet_map.get(dev_data.get("sheet_id")),
device_type=dev_data.get("device_type", "generic"),
label=dev_data.get("label", ""),
reference=dev_data.get("reference", ""),
@@ -136,15 +164,16 @@ async def import_diagram(request: Request, db: Session = Depends(get_db)):
db.add(new_dev)
db.flush()
if "id" in dev_data:
id_map[dev_data["id"]] = new_dev.id
dev_map[dev_data["id"]] = new_dev.id
for wire_data in data.get("wires", []):
new_wire = models.Wire(
diagram_id=new_diag.id,
sheet_id=sheet_map.get(wire_data.get("sheet_id")),
label=wire_data.get("label", ""),
from_device_id=id_map.get(wire_data.get("from_device_id")),
from_device_id=dev_map.get(wire_data.get("from_device_id")),
from_pin=wire_data.get("from_pin", ""),
to_device_id=id_map.get(wire_data.get("to_device_id")),
to_device_id=dev_map.get(wire_data.get("to_device_id")),
to_pin=wire_data.get("to_pin", ""),
color_primary=wire_data.get("color_primary", "#FF0000"),
color_stripe=wire_data.get("color_stripe"),
@@ -157,6 +186,7 @@ async def import_diagram(request: Request, db: Session = Depends(get_db)):
twist_pitch=wire_data.get("twist_pitch", 16.0),
shielded=wire_data.get("shielded", False),
show_size_label=wire_data.get("show_size_label", False),
bundle_id=bundle_map.get(wire_data.get("bundle_id")),
)
db.add(new_wire)