Lege Anlagen und Versandbelege direkt am Schriftstueck ab, damit die Zuordnung aus dem Vorgang gezogen werden kann und mehrere Belege an einem Versand bleiben.
Deploy Development / deploy (push) Successful in 26s
Test Suite / pytest-backend (push) Successful in 1m35s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 8s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-18 10:35:32 +02:00
1 parent c138df5e68
commit c774fb7206
9 files changed
+663 -200

No files matched your search

+281 -92
View File
@@ -27,6 +27,7 @@ import {
scopeBody,
unitMarks,
UnitDetail,
writeAssign,
} from "./correspondence.jsx";
export function formatDate(value) {
@@ -839,9 +840,9 @@ function EntryActions({
) : null}
{canSort && custom ? <button type="button" disabled={pending || index === 0} onClick={() => { close(); onMove(binding.id, -1); }}>Nach oben</button> : null}
{canSort && custom ? <button type="button" disabled={pending || index === lastIndex} onClick={() => { close(); onMove(binding.id, 1); }}>Nach unten</button> : null}
{canEdit && onAttach ? <button type="button" onClick={() => { close(); onAttach(binding); }}>Anlagen zuordnen</button> : null}
{canEdit && onAttach ? <button type="button" onClick={() => { close(); onAttach(binding); }}>Anlage aus der Liste wählen</button> : null}
{canEdit && onDispatch ? <button type="button" onClick={() => { close(); onDispatch(binding); }}>Versand dokumentieren</button> : null}
{canEdit && onEvidence ? <button type="button" onClick={() => { close(); onEvidence(binding); }}>Als Versandnachweis zuordnen …</button> : null}
{canEdit && onEvidence ? <button type="button" onClick={() => { close(); onEvidence(binding); }}>Als Beleg zuordnen …</button> : null}
{canEdit ? <button type="button" onClick={() => { close(); onRemove(binding, false); }}>Aus diesem Zusammenhang entfernen</button> : null}
{canEdit && canDestroy ? <button type="button" className="danger" onClick={() => { close(); onRemove(binding, true); }}>Überall löschen</button> : null}
</MenuPopover>
@@ -857,11 +858,12 @@ function TypeGlyph({ name, tone, size = 28 }) {
width={size}
height={size}
alt=""
draggable={false}
/>
);
}
function EntryMark({ element, context }) {
function EntryMark({ element, context, assignable = false, onAssignStart, onAssignEnd }) {
const symbol = elementSymbol(element);
const photo = symbol === "image" && Boolean(element.preview?.available);
const [url, setUrl] = useState("");
@@ -883,8 +885,16 @@ function EntryMark({ element, context }) {
};
}, [photo, element.id, element.preview?.source, context?.kind, context?.id]);
return (
<span className={url ? "entry-mark entry-mark--photo" : "entry-mark"}>
{url ? <img className="entry-mark__photo" alt="" src={url} /> : (
<span
className={url ? "entry-mark entry-mark--photo" : "entry-mark"}
draggable={assignable}
role={assignable ? "button" : undefined}
tabIndex={assignable ? 0 : undefined}
aria-label={assignable ? `${element.title} als Anlage oder Beleg ziehen` : undefined}
onDragStart={assignable ? onAssignStart : undefined}
onDragEnd={assignable ? onAssignEnd : undefined}
>
{url ? <img className="entry-mark__photo" alt="" draggable={false} src={url} /> : (
<>
<TypeGlyph name={symbol} tone="light" />
<TypeGlyph name={symbol} tone="dark" />
@@ -939,14 +949,16 @@ export function ContentBoard({
const [error, setError] = useState("");
const [pending, setPending] = useState(false);
const [dialog, setDialog] = useState(null);
const [openUnits, setOpenUnits] = useState(() => new Set());
const [draggingId, setDraggingId] = useState("");
const [carry, setCarry] = useState(null);
const [indicator, setIndicator] = useState(null);
const [folded, setFolded] = useState(() => new Set());
const [picking, setPicking] = useState(false);
const [picked, setPicked] = useState(() => new Set());
const [pickTarget, setPickTarget] = useState("");
const dragRef = useRef(null);
const carryRef = useRef(null);
const releaseRef = useRef(null);
const rootRef = useRef(null);
const savingDirection = useRef(false);
const custom = record?.content_order === "position";
@@ -1081,6 +1093,10 @@ export function ContentBoard({
const node = rootRef.current;
if (!node) return undefined;
function place(event) {
if (carryRef.current) {
event.preventDefault();
return;
}
const drag = dragRef.current;
if (!drag?.html5) return;
event.preventDefault();
@@ -1096,6 +1112,17 @@ export function ContentBoard({
setIndicator({ sectionId, index: drag.index });
}
function drop(event) {
const carried = carryRef.current;
if (carried) {
if (event.target?.closest?.(".drop-well")) return;
if (carried.source === "attachment" || carried.source === "evidence") {
event.preventDefault();
releaseRef.current?.(carried);
}
carryRef.current = null;
setCarry(null);
return;
}
if (!dragRef.current?.html5) return;
place(event);
finishDragRef.current(dragRef.current);
@@ -1456,6 +1483,125 @@ export function ContentBoard({
}, 0);
}
function beginCarry(payload) {
carryRef.current = payload;
setCarry(payload);
}
function endCarry() {
carryRef.current = null;
setCarry(null);
}
function bindingByElement(elementId) {
return source.find((item) => item.element?.id === elementId) || null;
}
function dispatchOf(dispatchId) {
for (const item of source) {
const found = (item.correspondence?.dispatches || []).find((entry) => entry.id === dispatchId);
if (found) return { host: item, dispatch: found };
}
return null;
}
const correspondenceScope = () => scopeBody(actionContext(), containerKind, containerId);
async function releaseToList(payload) {
setPending(true);
setError("");
try {
const scope = correspondenceScope();
if (payload.source === "attachment") {
const host = bindingByElement(payload.hostElementId);
if (!host) return;
await api(`/api/v1/elements/${host.element.id}/attachments/${payload.elementId}/detach`, {
method: "POST",
body: { expected_version: host.element.version, ...scope },
});
} else if (payload.source === "evidence") {
const found = dispatchOf(payload.dispatchId);
if (!found) return;
await api(`/api/v1/dispatches/${found.dispatch.id}/evidence/${payload.elementId}/detach`, {
method: "POST",
body: { expected_version: found.dispatch.version, ...scope },
});
}
const item = bindingByElement(payload.elementId);
if (item?.correspondence?.fold) {
await restoreFold(item.id, item.element.version, scope);
}
onChange();
} catch (err) {
setError(err.message);
} finally {
setPending(false);
}
}
releaseRef.current = releaseToList;
async function dropAttachment(hostBinding, payload) {
if (!payload || payload.elementId === hostBinding.element.id) return;
const already = (hostBinding.correspondence?.attachments || []).some((item) => item.element_id === payload.elementId);
if (payload.source === "attachment" && payload.hostElementId === hostBinding.element.id) return;
if (already) {
setError("Diese Anlage ist dem Schreiben bereits zugeordnet.");
return;
}
setPending(true);
setError("");
try {
const scope = correspondenceScope();
if (payload.source === "attachment") {
const from = bindingByElement(payload.hostElementId);
if (!from) return;
await api(`/api/v1/elements/${from.element.id}/attachments/${payload.elementId}/detach`, {
method: "POST",
body: { expected_version: from.element.version, ...scope },
});
}
if (payload.source === "evidence") {
const found = dispatchOf(payload.dispatchId);
if (!found) return;
await api(`/api/v1/dispatches/${found.dispatch.id}/evidence/${payload.elementId}/detach`, {
method: "POST",
body: { expected_version: found.dispatch.version, ...scope },
});
}
await api(`/api/v1/elements/${hostBinding.element.id}/attachments`, {
method: "POST",
body: {
expected_version: hostBinding.element.version,
attachment_element_ids: [payload.elementId],
fold: "attachment",
...scope,
},
});
onChange();
} catch (err) {
setError(err.message);
} finally {
setPending(false);
}
}
function dropReceipt(hostBinding, payload, dispatch) {
if (!payload || payload.elementId === hostBinding.element.id) return;
if (payload.source === "evidence" && dispatch && payload.dispatchId === dispatch.id) return;
const item = bindingByElement(payload.elementId);
const found = payload.source === "evidence" ? dispatchOf(payload.dispatchId) : null;
setDialog({
type: "evidence",
binding: item || { element: { id: payload.elementId, title: payload.title || "Unterlage", version: 1 } },
hosts: [hostBinding],
dispatchId: dispatch ? dispatch.id : "",
replace: found && (!dispatch || found.dispatch.id !== dispatch.id)
? { dispatchId: found.dispatch.id, version: found.dispatch.version }
: null,
});
}
function beginDrag(event, drag) {
if (pending || (event.button != null && event.button !== 0)) return;
event.preventDefault();
@@ -1509,7 +1655,7 @@ export function ContentBoard({
</select>
</label>
<button type="button" disabled={pending || picked.size === 0} onClick={() => placeMany([...picked], pickTarget)}>Einordnen</button>
<button type="button" disabled={pending || picked.size === 0} onClick={() => setDialog({ type: "bulk" })}>Als Anlagen zuordnen</button>
<button type="button" disabled={pending || picked.size === 0} onClick={() => setDialog({ type: "bulk" })}>Als Anlagen an ein Schriftstück</button>
<button type="button" className="quiet" onClick={() => { setPicking(false); setPicked(new Set()); }}>Auswahl beenden</button>
</div>
) : null}
@@ -1520,34 +1666,54 @@ export function ContentBoard({
) : (
<p className="muted">Noch keine Unterlage und keine Notiz.</p>
)}
<Modal open={dialog?.type === "attach" || dialog?.type === "bulk"} title="Anlagen zuordnen" onClose={() => setDialog(null)}>
<Modal open={dialog?.type === "attach" || dialog?.type === "bulk"} title="Anlagen" onClose={() => setDialog(null)}>
{dialog?.type === "bulk" && !dialog.host ? (
<form className="stack" onSubmit={(event) => {
<form className="stack" onSubmit={async (event) => {
event.preventDefault();
const host = listed.find((item) => item.id === new FormData(event.currentTarget).get("host"));
if (!host) return;
const candidates = listed.filter((item) => picked.has(item.id) && item.id !== host.id);
setDialog({ type: "attach", host, candidates });
const host = source.find((item) => item.id === new FormData(event.currentTarget).get("host"));
const ids = [...picked].map((id) => source.find((item) => item.id === id)).filter((item) => item && item.id !== host?.id).map((item) => item.element.id);
if (!host || !ids.length) return;
setPending(true);
setError("");
try {
await api(`/api/v1/elements/${host.element.id}/attachments`, {
method: "POST",
body: {
expected_version: host.element.version,
attachment_element_ids: ids,
fold: "attachment",
...scopeBody(actionContext(), containerKind, containerId),
},
});
setDialog(null);
setPicked(new Set());
setPicking(false);
onChange();
} catch (err) {
setError(err.message);
} finally {
setPending(false);
}
}}>
<p>Hauptschriftstück für die ausgewählten Unterlagen wählen. Die Kapitel bleiben bestehen, bis sie separat aufgelöst werden.</p>
<p>Die ausgewählten Unterlagen werden Anlagen dieses Schriftstücks und verschwinden aus der normalen Liste. Zurückziehen legt sie wieder dorthin.</p>
<label>
Hauptschriftstück
Schriftstück
<select name="host" defaultValue="">
<option value="">Schriftstück wählen</option>
{listed.map((item) => <option key={item.id} value={item.id}>{item.element.title}</option>)}
{source.map((item) => <option key={item.id} value={item.id}>{item.element.title}</option>)}
</select>
</label>
<button type="submit">Weiter zur Reihenfolge</button>
<button type="submit" disabled={pending}>Als Anlagen zuordnen</button>
</form>
) : null}
{dialog?.type === "attach" && dialog.host ? (
<AttachDialog
host={dialog.host}
candidates={dialog.candidates}
host={source.find((item) => item.id === dialog.host.id) || dialog.host}
candidates={source.filter((item) => item.element.id !== (source.find((entry) => entry.id === dialog.host.id) || dialog.host).element.id)}
scope={scopeBody(actionContext(), containerKind, containerId)}
pending={pending}
onClose={() => setDialog(null)}
onDone={() => { setDialog(null); setPicked(new Set()); setPicking(false); onChange(); }}
onDone={() => onChange()}
/>
) : null}
</Modal>
@@ -1562,11 +1728,34 @@ export function ContentBoard({
/>
) : null}
</Modal>
<Modal open={dialog?.type === "evidence"} title="Als Versandnachweis zuordnen" onClose={() => setDialog(null)}>
<Modal open={dialog?.type === "receipt-source"} title="Beleg wählen" onClose={() => setDialog(null)}>
{dialog?.type === "receipt-source" ? (
<div className="stack">
<p>Unterlage aus diesem Vorgang als Beleg von <strong>{dialog.host.element.title}</strong>.</p>
<ul className="choice-list choice-list--scroll">
{source.filter((item) => item.element.id !== dialog.host.element.id).map((item) => (
<li key={item.id}>
<span>{item.element.title}</span>
<button type="button" onClick={() => setDialog({
type: "evidence",
binding: item,
hosts: [dialog.host],
dispatchId: dialog.dispatchId,
})}>Als Beleg</button>
</li>
))}
</ul>
{!source.filter((item) => item.element.id !== dialog.host.element.id).length ? <p className="muted">Keine weitere Unterlage.</p> : null}
</div>
) : null}
</Modal>
<Modal open={dialog?.type === "evidence"} title="Beleg zuordnen" onClose={() => setDialog(null)}>
{dialog?.type === "evidence" ? (
<EvidenceDialog
element={dialog.binding.element}
hosts={listed.filter((item) => item.element.id !== dialog.binding.element.id)}
hosts={dialog.hosts || source.filter((item) => item.element.id !== dialog.binding.element.id)}
presetDispatchId={dialog.dispatchId}
replace={dialog.replace || null}
scope={scopeBody(actionContext(), containerKind, containerId)}
pending={pending}
onClose={() => setDialog(null)}
@@ -1749,11 +1938,32 @@ export function ContentBoard({
<span className="handle__grip" aria-hidden="true" />
</button>
) : null}
<EntryMark element={element} context={context} />
<EntryMark
element={element}
context={context}
assignable={canEdit && !pending && !picking}
onAssignStart={(event) => {
event.stopPropagation();
beginCarry({
source: "list",
elementId: element.id,
bindingId: binding.id,
title: element.title,
});
writeAssign(event, {
source: "list",
elementId: element.id,
bindingId: binding.id,
title: element.title,
});
}}
onAssignEnd={endCarry}
/>
<div className="preview-row__body">
<Link
className="preview-row__title"
to={href}
draggable={false}
aria-current={selectedId === binding.id ? "true" : undefined}
onClick={openFromList}
>
@@ -1770,73 +1980,56 @@ export function ContentBoard({
<BezugMenu element={element} source={source} onOpen={onOpen} itemHref={itemHref} canEdit={canEdit} onClearBezug={clearBezug} />
</div>
{text ? (
<Link className="preview-row__text" to={href} onClick={openFromList}>{text}</Link>
<Link className="preview-row__text" to={href} draggable={false} onClick={openFromList}>{text}</Link>
) : null}
{samePiece ? <span className="preview-row__origin">{samePiece}</span> : null}
{originText ? <span className="preview-row__origin">{originText}</span> : null}
{(binding.correspondence?.attachments?.length || binding.correspondence?.dispatches?.length) ? (
<button
type="button"
className="quiet unit-toggle"
aria-expanded={openUnits.has(binding.id)}
onClick={(event) => {
event.preventDefault();
event.stopPropagation();
setOpenUnits((current) => {
const next = new Set(current);
if (next.has(binding.id)) next.delete(binding.id);
else next.add(binding.id);
return next;
});
}}
>
{openUnits.has(binding.id) ? "Anlagen zuklappen" : "Anlagen"}
</button>
) : null}
{openUnits.has(binding.id) ? (
<UnitDetail
binding={binding}
canEdit={canEdit}
pending={pending}
scope={scopeBody(actionContext(), containerKind, containerId)}
onOpen={(elementId) => {
const found = source.find((item) => item.element?.id === elementId);
if (found) onOpen?.(found);
}}
onDetach={async (elementId) => {
setPending(true);
setError("");
try {
await api(`/api/v1/elements/${element.id}/attachments/${elementId}/detach`, {
method: "POST",
body: {
expected_version: element.version,
...scopeBody(actionContext(), containerKind, containerId),
},
});
onChange();
} catch (err) {
setError(err.message);
} finally {
setPending(false);
}
}}
onUnfold={async (elementId) => {
const found = source.find((item) => item.element?.id === elementId);
if (!found) return;
setPending(true);
setError("");
try {
await restoreFold(found.id, found.element.version, scopeBody(actionContext(), containerKind, containerId));
onChange();
} catch (err) {
setError(err.message);
} finally {
setPending(false);
}
}}
/>
) : null}
<UnitDetail
binding={binding}
canEdit={canEdit}
pending={pending}
carry={carry}
scope={scopeBody(actionContext(), containerKind, containerId)}
onCarryStart={beginCarry}
onCarryEnd={endCarry}
onOpen={(elementId) => {
const found = source.find((item) => item.element?.id === elementId);
if (found) onOpen?.(found);
}}
onDropAttachment={(payload) => dropAttachment(binding, payload)}
onDropReceipt={(payload, dispatch) => dropReceipt(binding, payload, dispatch)}
onPickAttachments={() => setDialog({ type: "attach", host: binding })}
onPickReceipt={(dispatch) => setDialog({
type: "receipt-source",
host: binding,
dispatchId: dispatch ? dispatch.id : "",
})}
onDocumentDispatch={() => setDialog({ type: "dispatch", host: binding })}
onDetach={(elementId) => releaseToList({
source: "attachment",
elementId,
hostElementId: element.id,
})}
onDetachEvidence={(proof, dispatch) => releaseToList({
source: "evidence",
elementId: proof.element_id,
dispatchId: dispatch.id,
})}
onUnfold={async (elementId) => {
const found = source.find((item) => item.element?.id === elementId);
if (!found) return;
setPending(true);
setError("");
try {
await restoreFold(found.id, found.element.version, scopeBody(actionContext(), containerKind, containerId));
onChange();
} catch (err) {
setError(err.message);
} finally {
setPending(false);
}
}}
/>
</div>
<EntryActions
element={element}
@@ -1856,11 +2049,7 @@ export function ContentBoard({
onRemove={removeBinding}
onMove={move}
onPlaceChapter={placeChapter}
onAttach={(row) => setDialog({
type: "attach",
host: row,
candidates: listed.filter((item) => item.element.id !== row.element.id && !(row.correspondence?.attachments || []).some((entry) => entry.element_id === item.element.id)),
})}
onAttach={(row) => setDialog({ type: "attach", host: row })}
onDispatch={(row) => setDialog({ type: "dispatch", host: row })}
onEvidence={(row) => setDialog({ type: "evidence", binding: row })}
/>