From 9f5327f3be156db3bd87f011c5e25e148a571519 Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 18 Oct 2026 11:35:03 +0200 Subject: [PATCH] Schliesse das Ablegen an der Markierung ab und halte Anlagen und Belege getrennt, damit der Dialog erscheint und zugeordnete Unterlagen im Uebergabepaket nur beim Schreiben stehen. Co-authored-by: Cursor --- backend/app/exporting.py | 14 + backend/tests/test_correspondence.py | 5 + frontend/src/pages/content.jsx | 195 ++++++++------ frontend/src/pages/correspondence.jsx | 375 ++++++++++++++++---------- frontend/src/styles.css | 102 +++++-- 5 files changed, 457 insertions(+), 234 deletions(-) diff --git a/backend/app/exporting.py b/backend/app/exporting.py index 34a1aeb..5495e62 100644 --- a/backend/app/exporting.py +++ b/backend/app/exporting.py @@ -272,6 +272,8 @@ def _matter_node(conn, actor, matter, page: Ctx, root: bool) -> ExportNode: children: list[ExportNode] = [] children.extend(_chapter_nodes(conn, actor, page, chapters, grouped)) for binding in grouped.get(None, []): + if not _stands_in_chapter(binding): + continue children.append(_binding_node(conn, actor, binding, page)) rows = conn.execute( "SELECT * FROM matters WHERE parent_matter_id = %s AND deleted_at IS NULL ORDER BY title, id", @@ -293,6 +295,16 @@ def _matter_node(conn, actor, matter, page: Ctx, root: bool) -> ExportNode: ) +def _stands_in_chapter(binding: dict) -> bool: + """A folded attachment or receipt stays under its letter, not as another chapter row.""" + pack = binding.get("correspondence") or {} + if pack.get("fold") in {"attachment", "evidence"}: + return False + if pack.get("hosts"): + return False + return True + + def _chapter_nodes(conn, actor, page, chapters: list[dict], grouped: dict[str | None, list]) -> list[ExportNode]: by_parent: dict[str | None, list[dict]] = {} for chapter in chapters: @@ -305,6 +317,8 @@ def _chapter_nodes(conn, actor, page, chapters: list[dict], grouped: dict[str | nested = build(chapter["id"], chapter_path) items = [] for item in grouped.get(chapter["id"], []): + if not _stands_in_chapter(item): + continue node = _binding_node(conn, actor, item, page) node.relation = f"Kapitel: {chapter_path}" items.append(node) diff --git a/backend/tests/test_correspondence.py b/backend/tests/test_correspondence.py index 6c9f056..3fedee3 100644 --- a/backend/tests/test_correspondence.py +++ b/backend/tests/test_correspondence.py @@ -311,6 +311,11 @@ def test_dispatch_keeps_the_secured_stand_and_distinct_mail_parts(client, db, mo assert uses == 3 hidden = _detail(ada, matter["id"]) assert _binding(hidden, "Gesendete Nachricht")["correspondence"]["fold"] == "evidence" + placed = list(_walk(ada.request("GET", f"/api/v1/matters/{matter['id']}/export-tree")["tree"])) + assert not any(node["kind"] == "binding" and node["title"] in {"Rechnung 2023", "Gesendete Nachricht"} for node in placed) + assert sum(1 for node in placed if node["kind"] == "attachment" and node["title"] == "Rechnung 2023") == 1 + assert any(node["kind"] == "dispatch_item" and node["title"] == "Rechnung 2023" for node in placed) + assert any(node["kind"] == "evidence" and node["title"] == "Gesendete Nachricht" for node in placed) ada.request( "PATCH", f"/api/v1/bindings/{_binding(hidden, 'Gesendete Nachricht')['id']}/fold", diff --git a/frontend/src/pages/content.jsx b/frontend/src/pages/content.jsx index b221009..c48999a 100644 --- a/frontend/src/pages/content.jsx +++ b/frontend/src/pages/content.jsx @@ -1099,14 +1099,17 @@ export function ContentBoard({ const carried = carryRef.current; if (carried) { event.preventDefault(); + if (event.dataTransfer) event.dataTransfer.dropEffect = "move"; const useId = useDropId(event.target); - if (useId && useId !== carried.bindingId) setIndicator({ kind: "use", bindingId: useId }); + carried.useBindingId = useId && useId !== carried.bindingId ? useId : ""; + if (carried.useBindingId) setIndicator({ kind: "use", bindingId: carried.useBindingId }); else setIndicator(null); return; } const drag = dragRef.current; - if (!drag?.html5) return; + if (!drag?.html5 || drag.done) return; event.preventDefault(); + if (event.dataTransfer) event.dataTransfer.dropEffect = "move"; if (drag.kind === "chapter") { drag.useBindingId = null; drag.index = chapterUnder(event.clientY, drag.parentId); @@ -1130,17 +1133,20 @@ export function ContentBoard({ function drop(event) { const carried = carryRef.current; if (carried) { - const useId = useDropId(event.target); event.preventDefault(); + if (carried.settled) return; + carried.settled = true; + const useId = useDropId(event.target) || carried.useBindingId || ""; carryRef.current = null; setIndicator(null); - if (useId) placeUseRef.current?.(useId, carried); + if (useId && useId !== carried.bindingId) placeUseRef.current?.(useId, carried); else if (carried.source === "attachment" || carried.source === "evidence") releaseRef.current?.(carried); return; } - if (!dragRef.current?.html5) return; + const drag = dragRef.current; + if (!drag?.html5 || drag.done) return; place(event); - finishDragRef.current(dragRef.current); + finishDragRef.current(drag); } node.addEventListener("dragover", place); node.addEventListener("drop", drop); @@ -1396,6 +1402,8 @@ export function ContentBoard({ } function finishDrag(drag) { + if (!drag || drag.done) return; + drag.done = true; dragRef.current = null; setDraggingId(""); setIndicator(null); @@ -1491,7 +1499,7 @@ export function ContentBoard({ window.removeEventListener("pointermove", track); window.removeEventListener("pointerup", release); window.removeEventListener("pointercancel", cancel); - if (!drag || drag.html5 || drag.pointerId !== event.pointerId) return; + if (!drag || drag.done || drag.pointerId !== event.pointerId) return; finishDrag(drag); } @@ -1519,10 +1527,8 @@ export function ContentBoard({ function endHtml5() { setTimeout(() => { const drag = dragRef.current; - if (!drag?.html5) return; - dragRef.current = null; - setDraggingId(""); - setIndicator(null); + if (!drag?.html5 || drag.done) return; + finishDrag(drag); }, 0); } @@ -1530,9 +1536,32 @@ export function ContentBoard({ carryRef.current = payload; } - function endCarry() { + function endCarry(event) { + const carried = carryRef.current; + if (!carried) { + setIndicator(null); + return; + } carryRef.current = null; setIndicator(null); + if (carried.settled) return; + carried.settled = true; + const x = event?.clientX || 0; + const y = event?.clientY || 0; + const pointOk = x > 0 || y > 0; + const moved = Math.hypot(x - (carried.anchorX || 0), y - (carried.anchorY || 0)); + if (pointOk && moved < 8 && !carried.useBindingId) return; + const hit = pointOk ? document.elementFromPoint(x, y) : null; + if (hit && rootRef.current && !rootRef.current.contains(hit)) return; + if (!hit && !carried.useBindingId) return; + const useId = hit ? useDropId(hit) : (carried.useBindingId || ""); + if (useId && useId !== carried.bindingId) { + placeUseRef.current?.(useId, carried); + return; + } + if (!hit || useId) return; + if (hit.closest?.(`[data-carry="${carried.source}:${carried.elementId}"]`)) return; + if (carried.source === "attachment" || carried.source === "evidence") releaseRef.current?.(carried); } function bindingByElement(elementId) { @@ -1992,16 +2021,9 @@ export function ContentBoard({ type="button" className="handle" aria-label={`${element.title} ziehen`} - draggable={!pending} + draggable={false} disabled={pending} onPointerDown={(event) => beginDrag(event, { bindingId: binding.id, sectionId: section.id })} - onDragStart={(event) => { - event.dataTransfer.effectAllowed = "move"; - event.dataTransfer.setData("text/plain", binding.id); - markHtml5({ bindingId: binding.id, sectionId: section.id, targetSectionId: section.id }); - setDraggingId(binding.id); - }} - onDragEnd={endHtml5} >