Lege Anlagen und Belege an der Markierung ab, damit die Zeile schlank bleibt und das Verschieben seine eigene Linie behaelt.
Deploy Development / deploy (push) Successful in 26s
Test Suite / pytest-backend (push) Successful in 2m0s
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 11:03:01 +02:00
1 parent c774fb7206
commit be027a1025
3 files changed
+512 -307

No files matched your search

+122 -64
View File
@@ -18,14 +18,13 @@ import {
siblingChapterIds,
} from "./chapters.js";
import {
AttachDialog,
Chronology,
DispatchDialog,
EvidenceDialog,
hostMark,
restoreFold,
scopeBody,
unitMarks,
StructureAssignDialog,
UnitDetail,
writeAssign,
} from "./correspondence.jsx";
@@ -455,7 +454,7 @@ function MenuPopover({ open, anchorRef, onClose, label, children, sheet = false
);
}
export function DirectionControl({ direction = "", title, disabled = false, onChange }) {
export function DirectionControl({ direction = "", title, disabled = false, onChange, dropId = "" }) {
const anchorRef = useRef(null);
const [open, setOpen] = useState(false);
const known = directionWord(direction);
@@ -467,11 +466,12 @@ export function DirectionControl({ direction = "", title, disabled = false, onCh
anchorRef.current?.focus();
}
return (
<span className={`direction-column${direction === "local" ? " direction-column--local" : ""}`}>
<span className={`direction-column${direction === "local" ? " direction-column--local" : ""}`} data-use-drop={dropId || undefined}>
<button
ref={anchorRef}
type="button"
className="direction-trigger"
data-use-drop={dropId || undefined}
aria-label={name}
aria-haspopup="dialog"
aria-expanded={open}
@@ -772,7 +772,6 @@ function EntryActions({
onPlaceChapter,
onAttach,
onDispatch,
onEvidence,
}) {
const anchorRef = useRef(null);
const [open, setOpen] = useState(false);
@@ -840,9 +839,8 @@ 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); }}>Anlage aus der Liste wählen</button> : null}
{canEdit && onAttach ? <button type="button" onClick={() => { close(); onAttach(binding); }}>Anlagen und Belege zuordnen</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 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>
@@ -863,7 +861,11 @@ function TypeGlyph({ name, tone, size = 28 }) {
);
}
function EntryMark({ element, context, assignable = false, onAssignStart, onAssignEnd }) {
function useDropId(node) {
return node?.closest?.("[data-use-drop]")?.getAttribute("data-use-drop") || "";
}
function EntryMark({ element, context, assignable = false, dropId = "", onAssignStart, onAssignEnd }) {
const symbol = elementSymbol(element);
const photo = symbol === "image" && Boolean(element.preview?.available);
const [url, setUrl] = useState("");
@@ -887,6 +889,7 @@ function EntryMark({ element, context, assignable = false, onAssignStart, onAssi
return (
<span
className={url ? "entry-mark entry-mark--photo" : "entry-mark"}
data-use-drop={dropId || undefined}
draggable={assignable}
role={assignable ? "button" : undefined}
tabIndex={assignable ? 0 : undefined}
@@ -950,7 +953,6 @@ export function ContentBoard({
const [pending, setPending] = useState(false);
const [dialog, setDialog] = useState(null);
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);
@@ -959,6 +961,7 @@ export function ContentBoard({
const dragRef = useRef(null);
const carryRef = useRef(null);
const releaseRef = useRef(null);
const placeUseRef = useRef(null);
const rootRef = useRef(null);
const savingDirection = useRef(false);
const custom = record?.content_order === "position";
@@ -1093,34 +1096,46 @@ export function ContentBoard({
const node = rootRef.current;
if (!node) return undefined;
function place(event) {
if (carryRef.current) {
const carried = carryRef.current;
if (carried) {
event.preventDefault();
const useId = useDropId(event.target);
if (useId && useId !== carried.bindingId) setIndicator({ kind: "use", bindingId: useId });
else setIndicator(null);
return;
}
const drag = dragRef.current;
if (!drag?.html5) return;
event.preventDefault();
if (drag.kind === "chapter") {
drag.useBindingId = null;
drag.index = chapterUnder(event.clientY, drag.parentId);
setIndicator({ sectionId: drag.chapterId, index: drag.index, kind: "chapter", parentId: drag.parentId || "" });
return;
}
const useId = useDropId(event.target);
if (useId && useId !== drag.bindingId) {
drag.useBindingId = useId;
drag.index = null;
setIndicator({ kind: "use", bindingId: useId });
return;
}
drag.useBindingId = null;
const sectionId = event.target?.closest?.("[data-section]")?.getAttribute("data-section");
if (!sectionId) return;
drag.targetSectionId = sectionId;
drag.index = indexAt(sectionId, event.clientY);
setIndicator({ sectionId, index: drag.index });
setIndicator({ sectionId, index: drag.index, kind: "order" });
}
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);
}
const useId = useDropId(event.target);
event.preventDefault();
carryRef.current = null;
setCarry(null);
setIndicator(null);
if (useId) placeUseRef.current?.(useId, carried);
else if (carried.source === "attachment" || carried.source === "evidence") releaseRef.current?.(carried);
return;
}
if (!dragRef.current?.html5) return;
@@ -1384,6 +1399,24 @@ export function ContentBoard({
dragRef.current = null;
setDraggingId("");
setIndicator(null);
if (drag?.useBindingId && drag.bindingId && drag.useBindingId !== drag.bindingId) {
const host = source.find((item) => item.id === drag.useBindingId);
const item = source.find((item) => item.id === drag.bindingId);
if (host && item && host.element.id !== item.element.id) {
setDialog({
type: "place-use",
host,
binding: item,
payload: {
source: "list",
elementId: item.element.id,
bindingId: item.id,
title: item.element.title,
},
});
}
return;
}
if (!drag || !drag.moved || drag.index == null) return;
if (drag.kind === "chapter") {
const ids = siblingChapterIds(chapters, drag.chapterId);
@@ -1434,13 +1467,23 @@ export function ContentBoard({
if (event.clientY < 72) window.scrollBy(0, -16);
if (event.clientY > window.innerHeight - 72) window.scrollBy(0, 16);
if (drag.kind === "chapter") {
drag.useBindingId = null;
drag.index = chapterUnder(event.clientY, drag.parentId);
setIndicator({ sectionId: drag.chapterId, index: drag.index, kind: "chapter", parentId: drag.parentId || "" });
return;
}
const useId = useDropId(document.elementFromPoint(event.clientX, event.clientY));
if (useId && useId !== drag.bindingId) {
drag.useBindingId = useId;
drag.index = null;
drag.moved = true;
setIndicator({ kind: "use", bindingId: useId });
return;
}
drag.useBindingId = null;
drag.targetSectionId = sectionUnder(event.clientY) || drag.sectionId;
drag.index = indexAt(drag.targetSectionId, event.clientY);
setIndicator({ sectionId: drag.targetSectionId, index: drag.index });
setIndicator({ sectionId: drag.targetSectionId, index: drag.index, kind: "order" });
}
function release(event) {
@@ -1485,12 +1528,11 @@ export function ContentBoard({
function beginCarry(payload) {
carryRef.current = payload;
setCarry(payload);
}
function endCarry() {
carryRef.current = null;
setCarry(null);
setIndicator(null);
}
function bindingByElement(elementId) {
@@ -1586,22 +1628,25 @@ export function ContentBoard({
}
}
function dropReceipt(hostBinding, payload, dispatch) {
if (!payload || payload.elementId === hostBinding.element.id) return;
if (payload.source === "evidence" && dispatch && payload.dispatchId === dispatch.id) return;
function openPlace(hostBindingId, payload) {
const host = source.find((item) => item.id === hostBindingId);
if (!host || !payload || host.element.id === payload.elementId) return;
if (payload.source === "attachment" && payload.hostElementId === host.element.id) return;
if (payload.source === "evidence") {
const found = dispatchOf(payload.dispatchId);
if (found?.host?.element.id === host.element.id) return;
}
const item = bindingByElement(payload.elementId);
const found = payload.source === "evidence" ? dispatchOf(payload.dispatchId) : null;
setDialog({
type: "evidence",
type: "place-use",
host,
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,
payload,
});
}
placeUseRef.current = openPlace;
function beginDrag(event, drag) {
if (pending || (event.button != null && event.button !== 0)) return;
event.preventDefault();
@@ -1666,7 +1711,7 @@ export function ContentBoard({
) : (
<p className="muted">Noch keine Unterlage und keine Notiz.</p>
)}
<Modal open={dialog?.type === "attach" || dialog?.type === "bulk"} title="Anlagen" onClose={() => setDialog(null)}>
<Modal wide open={dialog?.type === "attach" || dialog?.type === "bulk"} title={dialog?.type === "attach" ? "Anlagen und Belege" : "Anlagen"} onClose={() => setDialog(null)}>
{dialog?.type === "bulk" && !dialog.host ? (
<form className="stack" onSubmit={async (event) => {
event.preventDefault();
@@ -1707,9 +1752,10 @@ export function ContentBoard({
</form>
) : null}
{dialog?.type === "attach" && dialog.host ? (
<AttachDialog
<StructureAssignDialog
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)}
bindings={source}
chapters={chapters}
scope={scopeBody(actionContext(), containerKind, containerId)}
pending={pending}
onClose={() => setDialog(null)}
@@ -1728,24 +1774,44 @@ export function ContentBoard({
/>
) : null}
</Modal>
<Modal open={dialog?.type === "receipt-source"} title="Beleg wählen" onClose={() => setDialog(null)}>
{dialog?.type === "receipt-source" ? (
<Modal open={dialog?.type === "place-use"} title="Ablegen" onClose={() => setDialog(null)}>
{dialog?.type === "place-use" ? (
<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}
<p><strong>{dialog.payload.title || dialog.binding.element.title}</strong> an <strong>{dialog.host.element.title}</strong></p>
<button type="button" disabled={pending} onClick={async () => {
await dropAttachment(dialog.host, dialog.payload);
setDialog(null);
}}>Als Anlage</button>
<button type="button" disabled={pending} onClick={async () => {
const payload = dialog.payload;
if (payload.source === "attachment") {
const from = bindingByElement(payload.hostElementId);
if (from) {
setPending(true);
setError("");
try {
await api(`/api/v1/elements/${from.element.id}/attachments/${payload.elementId}/detach`, {
method: "POST",
body: { expected_version: from.element.version, ...correspondenceScope() },
});
} catch (err) {
setError(err.message);
setPending(false);
return;
}
setPending(false);
}
}
const found = payload.source === "evidence" ? dispatchOf(payload.dispatchId) : null;
setDialog({
type: "evidence",
binding: dialog.binding,
hosts: [dialog.host],
dispatchId: dialog.host.correspondence?.dispatches?.[0]?.id || "",
replace: found ? { dispatchId: found.dispatch.id, version: found.dispatch.version } : null,
});
}}>Als Beleg</button>
<button type="button" className="quiet" onClick={() => setDialog(null)}>Abbrechen</button>
</div>
) : null}
</Modal>
@@ -1871,7 +1937,7 @@ export function ContentBoard({
const sourceSymbol = contentSourceSymbol(element);
const way = directionWord(binding.communication?.direction) || "Keine Angabe";
const party = counterpartLabel(element, binding.communication?.direction);
const facts = [party, formatDate(fachDate(element)), sourceLabel(element), way, unitMarks(binding)].filter(Boolean).join(" · ");
const facts = [party, formatDate(fachDate(element)), sourceLabel(element), way].filter(Boolean).join(" · ");
const samePiece = hostMark(binding);
const originText = binding.origin && section.title && !binding.origin.includes(section.title)
? `${binding.origin}${binding.shared ? " · weitere Einbindung" : ""}`
@@ -1881,6 +1947,7 @@ export function ContentBoard({
const rowClass = [
"preview-row",
draggingId === binding.id ? "is-dragging" : "",
indicator?.kind === "use" && indicator.bindingId === binding.id ? "is-use-target" : "",
selectedId === binding.id ? "is-selected" : "",
picking && picked.has(binding.id) ? "is-picked" : "",
picking ? "preview-row--picking" : "",
@@ -1893,7 +1960,7 @@ export function ContentBoard({
}
return (
<li key={binding.id} data-binding={binding.id} className={rowClass}>
{indicator?.sectionId === section.id && indicator?.kind !== "chapter" && indicator.index === index ? <div className="insert-line" /> : null}
{indicator?.kind === "order" && indicator?.sectionId === section.id && indicator.index === index ? <div className="insert-line" /> : null}
{picking ? (
<label className="pick-box">
<input
@@ -1914,6 +1981,7 @@ export function ContentBoard({
direction={directionValue(binding.communication)}
title={element.title}
disabled={pending}
dropId={binding.id}
onChange={(value) => saveRowDirection(binding, value)}
/>
) : (
@@ -1941,6 +2009,7 @@ export function ContentBoard({
<EntryMark
element={element}
context={context}
dropId={canEdit ? binding.id : ""}
assignable={canEdit && !pending && !picking}
onAssignStart={(event) => {
event.stopPropagation();
@@ -1988,7 +2057,6 @@ export function ContentBoard({
binding={binding}
canEdit={canEdit}
pending={pending}
carry={carry}
scope={scopeBody(actionContext(), containerKind, containerId)}
onCarryStart={beginCarry}
onCarryEnd={endCarry}
@@ -1996,15 +2064,6 @@ export function ContentBoard({
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,
@@ -2051,12 +2110,11 @@ export function ContentBoard({
onPlaceChapter={placeChapter}
onAttach={(row) => setDialog({ type: "attach", host: row })}
onDispatch={(row) => setDialog({ type: "dispatch", host: row })}
onEvidence={(row) => setDialog({ type: "evidence", binding: row })}
/>
</li>
);
})}
{indicator?.sectionId === section.id && indicator?.kind !== "chapter" && indicator.index === section.items.length ? <li className="insert-line" aria-hidden="true" /> : null}
{indicator?.kind === "order" && indicator?.sectionId === section.id && indicator.index === section.items.length ? <li className="insert-line" aria-hidden="true" /> : null}
</ol> : null}
{expanded && section.children?.length ? (
<div className="chapter-children">
+373 -226
View File
@@ -1,6 +1,7 @@
import { useState } from "react";
import { useMemo, useState } from "react";
import { Link } from "react-router-dom";
import { api } from "../api.js";
import { buildChapterSections, sectionCounts } from "./chapters.js";
function formatDate(value) {
if (!value) return "Ohne Datum";
@@ -81,34 +82,103 @@ export function writeAssign(event, payload) {
event.dataTransfer.setData("text/plain", payload.title || "");
}
export function readAssign(event) {
const raw = event.dataTransfer.getData(ASSIGN_MIME);
if (!raw) return null;
try {
return JSON.parse(raw);
} catch {
return null;
function ancestorIds(chapters, chapterId) {
const byId = new Map((chapters || []).map((chapter) => [chapter.id, chapter]));
const ids = [];
const seen = new Set();
let current = chapterId ? byId.get(chapterId) : null;
while (current && !seen.has(current.id)) {
seen.add(current.id);
ids.push(current.id);
current = current.parent_chapter_id ? byId.get(current.parent_chapter_id) : null;
}
return ids;
}
function assignEvent(event) {
return [...(event.dataTransfer?.types || [])].includes(ASSIGN_MIME);
function branchItems(section) {
return [
...(section.items || []),
...(section.children || []).flatMap(branchItems),
];
}
export function AttachDialog({ host, candidates, scope, pending, onClose, onDone }) {
const current = host.correspondence?.attachments || [];
const taken = new Set(current.map((item) => item.element_id));
function titleMatches(binding, needle) {
if (!needle) return true;
return (binding.element?.title || "").toLowerCase().includes(needle);
}
function branchVisible(section, needle) {
if (!needle) return true;
if ((section.items || []).some((item) => titleMatches(item, needle))) return true;
return (section.children || []).some((child) => branchVisible(child, needle));
}
export function StructureAssignDialog({ host, bindings, chapters, scope, pending, onClose, onDone }) {
const tree = useMemo(() => buildChapterSections(chapters, bindings), [chapters, bindings]);
const [opened, setOpened] = useState(() => new Set(host.chapter_id ? ancestorIds(chapters, host.chapter_id) : ["loose"]));
const [query, setQuery] = useState("");
const [selected, setSelected] = useState(() => new Set());
const [step, setStep] = useState("pick");
const [role, setRole] = useState("email");
const [fold, setFold] = useState("evidence");
const [dispatchId, setDispatchId] = useState(host.correspondence?.dispatches?.[0]?.id || "");
const [channel, setChannel] = useState("email");
const [sentOn, setSentOn] = useState("");
const [counterpart, setCounterpart] = useState("");
const [error, setError] = useState("");
const [busy, setBusy] = useState(false);
const needle = query.trim().toLowerCase();
const available = candidates.filter((item) => {
if (taken.has(item.element.id) || item.element.id === host.element.id) return false;
if (!needle) return true;
return item.element.title.toLowerCase().includes(needle);
});
const taken = new Set((host.correspondence?.attachments || []).map((item) => item.element_id));
const dispatches = host.correspondence?.dispatches || [];
async function add(elementId) {
function toggle(id) {
setSelected((current) => {
const next = new Set(current);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
});
}
function toggleIds(ids) {
if (!ids.length) return;
setSelected((current) => {
const next = new Set(current);
const allOn = ids.every((id) => next.has(id));
ids.forEach((id) => {
if (allOn) next.delete(id);
else next.add(id);
});
return next;
});
}
function toggleChapter(section) {
toggleIds(branchItems(section).map((item) => item.element.id).filter((id) => id !== host.element.id));
}
function visibleIds() {
const ids = [];
function walk(section) {
if (!branchVisible(section, needle)) return;
for (const item of section.items || []) {
if (item.element.id !== host.element.id && titleMatches(item, needle)) ids.push(item.element.id);
}
for (const child of section.children || []) walk(child);
}
tree.roots.forEach(walk);
for (const item of tree.loose) {
if (item.element.id !== host.element.id && titleMatches(item, needle)) ids.push(item.element.id);
}
return ids;
}
async function saveAttachments() {
const ids = [...selected].filter((id) => id !== host.element.id && !taken.has(id));
if (!ids.length) {
setError("In der Auswahl ist keine neue Anlage.");
return;
}
setBusy(true);
setError("");
try {
@@ -116,68 +186,216 @@ export function AttachDialog({ host, candidates, scope, pending, onClose, onDone
method: "POST",
body: fieldBody(scope, {
expected_version: host.element.version,
attachment_element_ids: [elementId],
attachment_element_ids: ids,
fold: "attachment",
}),
});
onDone();
onClose();
} catch (err) {
setError(err.message);
onDone();
} finally {
setBusy(false);
}
}
async function remove(elementId) {
async function saveReceipts(event) {
event.preventDefault();
const ids = [...selected].filter((id) => id !== host.element.id);
if (!ids.length) return;
setBusy(true);
setError("");
try {
await api(`/api/v1/elements/${host.element.id}/attachments/${elementId}/detach`, {
method: "POST",
body: fieldBody(scope, { expected_version: host.element.version }),
});
if (!dispatchId) {
await api(`/api/v1/elements/${host.element.id}/dispatches`, {
method: "POST",
body: fieldBody(scope, {
expected_version: host.element.version,
channel,
sent_on: sentOn || null,
counterpart: counterpart.trim() || null,
attachment_element_ids: (host.correspondence?.attachments || []).map((item) => item.element_id),
evidence: ids.map((id) => ({ element_id: id, role, fold })),
historical_gap: false,
}),
});
} else {
const dispatch = dispatches.find((item) => item.id === dispatchId);
const already = new Set((dispatch?.evidence || []).map((item) => item.element_id));
const fresh = ids.filter((id) => !already.has(id));
if (!fresh.length) {
setError("Diese Belege liegen an dem Versand bereits.");
return;
}
let version = dispatch?.version || 1;
for (const id of fresh) {
await api(`/api/v1/dispatches/${dispatchId}/evidence`, {
method: "POST",
body: fieldBody(scope, {
expected_version: version,
element_id: id,
role,
fold,
}),
});
version += 1;
}
}
onDone();
onClose();
} catch (err) {
setError(err.message);
onDone();
} finally {
setBusy(false);
}
}
function renderRow(item, depth) {
const id = item.element.id;
const isHost = id === host.element.id;
return (
<li key={item.id} className="pick-tree__row" style={{ "--depth": depth }}>
<label>
<input type="checkbox" checked={selected.has(id)} disabled={isHost} onChange={() => toggle(id)} />
<span>{item.element.title}</span>
<span className="muted">{formatDate(item.element.dates?.document_on)}</span>
{isHost ? <span className="muted">dieses Schriftstück</span> : null}
{taken.has(id) ? <span className="muted">Anlage</span> : null}
</label>
</li>
);
}
function renderSection(section, depth) {
if (!branchVisible(section, needle)) return null;
const expanded = Boolean(needle) || opened.has(section.id);
const counts = sectionCounts(section);
const total = counts.direct + counts.nested;
return (
<li key={section.id}>
<div className="pick-tree__chapter" style={{ "--depth": depth }}>
<button
type="button"
className="quiet"
aria-expanded={expanded}
onClick={() => setOpened((current) => {
const next = new Set(current);
if (next.has(section.id)) next.delete(section.id);
else next.add(section.id);
return next;
})}
>
{expanded ? "▾" : "▸"} {section.title}
<span className="muted">{total}</span>
</button>
<button type="button" className="quiet" aria-label={`Alle in ${section.title} auswählen`} onClick={() => toggleChapter(section)}>alle</button>
</div>
{expanded ? (
<ul className="pick-tree__items">
{(section.items || []).filter((item) => titleMatches(item, needle)).map((item) => renderRow(item, depth + 1))}
{(section.children || []).map((child) => renderSection(child, depth + 1))}
</ul>
) : null}
</li>
);
}
const loose = tree.loose.filter((item) => titleMatches(item, needle));
const roots = tree.roots.map((section) => renderSection(section, 0)).filter(Boolean);
return (
<div className="stack">
<p>Anlagen von <strong>{host.element.title}</strong>. Bereits zugeordnete Anlagen stehen oben. Eine weitere Unterlage aus diesem Vorgang wird daraus genommen und nur noch hier gezeigt.</p>
<section>
<h3>Zugeordnet</h3>
{current.length ? (
<ol className="choice-list">
{current.map((item, index) => (
<li key={item.id}>
<span>{index + 1}. {item.title}</span>
<span className="muted">{formatDate(item.document_on)}</span>
<button type="button" className="quiet" disabled={pending || busy} onClick={() => remove(item.element_id)}>Lösen</button>
</li>
))}
</ol>
) : <p className="muted">Noch keine Anlage an diesem Schriftstück.</p>}
</section>
<div className="stack pick-tree">
<p>Zuordnen an <strong>{host.element.title}</strong>. Kapitel bleiben geschlossen, bis sie geöffnet werden.</p>
<label>
Weitere Unterlage
<input value={query} onChange={(event) => setQuery(event.target.value)} placeholder="Titel suchen" />
Suchen
<input value={query} onChange={(event) => setQuery(event.target.value)} placeholder="Titel" />
</label>
{available.length ? (
<ul className="choice-list choice-list--scroll">
{available.map((item) => (
<li key={item.id}>
<span>{item.element.title}</span>
<span className="muted">{formatDate(item.element.dates?.document_on)}</span>
<button type="button" disabled={pending || busy} onClick={() => add(item.element.id)}>Als Anlage</button>
</li>
))}
</ul>
) : <p className="muted">Keine weitere passende Unterlage in diesem Vorgang.</p>}
{step === "pick" ? (
<>
<ul className="pick-tree__list">
{roots}
{loose.length ? (
<li>
<div className="pick-tree__chapter">
<button
type="button"
className="quiet"
aria-expanded={Boolean(needle) || opened.has("loose")}
onClick={() => setOpened((current) => {
const next = new Set(current);
if (next.has("loose")) next.delete("loose");
else next.add("loose");
return next;
})}
>
{needle || opened.has("loose") ? "▾" : "▸"} Ohne Kapitel
<span className="muted">{loose.length}</span>
</button>
<button type="button" className="quiet" onClick={() => toggleIds(loose.map((item) => item.element.id).filter((id) => id !== host.element.id))}>alle</button>
</div>
{needle || opened.has("loose") ? (
<ul className="pick-tree__items">
{loose.map((item) => renderRow(item, 1))}
</ul>
) : null}
</li>
) : null}
{!roots.length && !loose.length ? <li className="muted">Nichts mit diesem Titel.</li> : null}
</ul>
<div className="pick-tree__bar">
<span>{selected.size} ausgewählt</span>
{needle ? <button type="button" className="quiet" onClick={() => toggleIds(visibleIds())}>Sichtbare</button> : null}
<button type="button" disabled={pending || busy || !selected.size} onClick={saveAttachments}>Als Anlagen</button>
<button type="button" disabled={pending || busy || !selected.size} onClick={() => { setError(""); setStep("receipt"); }}>Als Belege</button>
<button type="button" className="quiet" onClick={onClose}>Schließen</button>
</div>
</>
) : (
<form className="stack" onSubmit={saveReceipts}>
<p>{selected.size} Belege. Dieselbe Rolle gilt für die Auswahl.</p>
<label>
Versand
<select value={dispatchId} onChange={(event) => setDispatchId(event.target.value)}>
<option value="">Neuen Versand anlegen</option>
{dispatches.map((item) => (
<option key={item.id} value={item.id}>
{item.sent_on ? formatDate(item.sent_on) : "undatiert"} · {item.channel_label}
</option>
))}
</select>
</label>
{!dispatchId ? (
<>
<label>
Weg
<select value={channel} onChange={(event) => setChannel(event.target.value)}>
<option value="email">E-Mail</option>
<option value="post">Post</option>
<option value="other">Sonstiger Weg</option>
</select>
</label>
<label>Versanddatum<input type="date" value={sentOn} onChange={(event) => setSentOn(event.target.value)} /></label>
<label>Gegenüber<input value={counterpart} onChange={(event) => setCounterpart(event.target.value)} maxLength={200} /></label>
</>
) : null}
<label>
Rolle
<select value={role} onChange={(event) => setRole(event.target.value)}>
{RECEIPT_ROLES.map(([value, label]) => <option key={value} value={value}>{label}</option>)}
</select>
</label>
<fieldset>
<legend>Darstellung in der Liste</legend>
<label><input type="radio" name="assign-fold" checked={fold === "evidence"} onChange={() => setFold("evidence")} /> Nur am Versand zeigen</label>
<label><input type="radio" name="assign-fold" checked={fold === "keep"} onChange={() => setFold("keep")} /> Zusätzlich als eigenen Eintrag behalten</label>
</fieldset>
<button type="submit" disabled={pending || busy}>Belege zuordnen</button>
<button type="button" className="quiet" onClick={() => setStep("pick")}>Zurück zur Struktur</button>
</form>
)}
{error ? <p className="error">{error}</p> : null}
<button type="button" className="quiet" onClick={onClose}>Schließen</button>
</div>
);
}
@@ -425,42 +643,6 @@ export function ComparisonList({ comparisons = [], state, reason }) {
);
}
function DropWell({ label, hint, armed, onDrop, onPick }) {
const [over, setOver] = useState(false);
return (
<div
className={["drop-well", armed ? "is-armed" : "", over ? "is-over" : ""].filter(Boolean).join(" ")}
onDragEnter={(event) => {
if (!assignEvent(event)) return;
event.preventDefault();
event.stopPropagation();
setOver(true);
}}
onDragOver={(event) => {
if (!assignEvent(event)) return;
event.preventDefault();
event.stopPropagation();
event.dataTransfer.dropEffect = "move";
}}
onDragLeave={(event) => {
if (event.currentTarget.contains(event.relatedTarget)) return;
setOver(false);
}}
onDrop={(event) => {
if (!assignEvent(event)) return;
event.preventDefault();
event.stopPropagation();
setOver(false);
const payload = readAssign(event);
if (payload) onDrop(payload);
}}
>
<span>{over ? hint : label}</span>
{onPick ? <button type="button" className="quiet" onClick={onPick}>Wählen</button> : null}
</div>
);
}
function chipDrag(enabled, payload, onCarryStart, onCarryEnd) {
return {
role: "button",
@@ -482,153 +664,118 @@ export function UnitDetail({
canEdit,
pending,
scope,
carry,
onOpen,
onDetach,
onDetachEvidence,
onUnfold,
onCarryStart,
onCarryEnd,
onDropAttachment,
onDropReceipt,
onPickAttachments,
onPickReceipt,
}) {
const pack = binding.correspondence || {};
const attachments = pack.attachments || [];
const dispatches = pack.dispatches || [];
const show = canEdit || attachments.length || dispatches.length || (pack.hosts || []).length;
if (!show) return null;
const armed = Boolean(carry && carry.elementId !== binding.element.id);
if (!attachments.length && !dispatches.length) {
if (!canEdit) return null;
return (
<div className="use-strip">
<DropWell label="Anlage hier ablegen" hint="Als Anlage zuordnen" armed={armed} onDrop={onDropAttachment} onPick={onPickAttachments} />
<DropWell label="Beleg hier ablegen" hint="Versand mit diesem Beleg anlegen" armed={armed} onDrop={(payload) => onDropReceipt(payload, null)} onPick={() => onPickReceipt(null)} />
</div>
);
}
const [open, setOpen] = useState(false);
if (!attachments.length && !dispatches.length) return null;
const summary = unitMarks(binding) || "Anlagen und Belege";
return (
<div className="unit-detail">
<section>
<h4>Anlagen</h4>
{canEdit ? (
<DropWell
label="Anlage hier ablegen"
hint="Als Anlage zuordnen"
armed={armed}
onDrop={onDropAttachment}
onPick={onPickAttachments}
/>
) : null}
{attachments.length ? (
<ol>
{attachments.map((item, index) => (
<li key={item.id} className="use-chip">
<span
className="use-chip__grip"
aria-label={`${item.title} aus den Anlagen ziehen`}
{...chipDrag(canEdit && !pending, {
source: "attachment",
elementId: item.element_id,
hostElementId: binding.element.id,
title: item.title,
}, onCarryStart, onCarryEnd)}
/>
<span>{index + 1}. {item.title}</span>
<span className="muted">{formatDate(item.document_on)}</span>
{item.binding_id ? (
<button type="button" className="quiet" onClick={() => onOpen(item.element_id)}>Öffnen</button>
) : null}
{canEdit ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onDetach(item.element_id)}>In die Liste</button>
) : null}
</li>
))}
</ol>
) : null}
</section>
{dispatches.map((item) => (
<section key={item.id}>
<h4>
Versand {item.undated ? "undatiert" : formatDate(item.sent_on)} · {item.channel_label}
{item.counterpart ? ` · ${item.counterpart}` : " · Gegenüber unbekannt"}
</h4>
<p className="muted">
{item.provenance === "reconstructed" ? "Rekonstruierte Dokumentation. " : "Beim Dokumentieren gesichert. "}
{item.completeness === "secured" ? "Inhaltsstand gesichert." : null}
{item.completeness === "partial" ? "Inhaltsstand nur teilweise gesichert." : null}
{item.completeness === "gap" ? "Kein vollständiger gesicherter Inhaltsstand." : null}
</p>
{canEdit ? (
<DropWell
label="Beleg hier ablegen"
hint="Als Beleg dieses Versands"
armed={armed}
onDrop={(payload) => onDropReceipt(payload, item)}
onPick={() => onPickReceipt(item)}
/>
<div className="unit-fold">
<button type="button" className="quiet unit-toggle" aria-expanded={open} onClick={() => setOpen((value) => !value)}>
{open ? "Zuklappen" : summary}
</button>
{open ? (
<div className="unit-detail unit-detail--slim">
{attachments.length ? (
<section>
<h4>Anlagen</h4>
<ol>
{attachments.map((item, index) => (
<li key={item.id} className="use-chip">
{canEdit ? (
<span
className="use-chip__grip"
aria-label={`${item.title} aus den Anlagen ziehen`}
{...chipDrag(!pending, {
source: "attachment",
elementId: item.element_id,
hostElementId: binding.element.id,
bindingId: item.binding_id || "",
title: item.title,
}, onCarryStart, onCarryEnd)}
/>
) : null}
<span>{index + 1}. {item.title}</span>
<span className="muted">{formatDate(item.document_on)}</span>
{item.binding_id ? (
<button type="button" className="quiet" onClick={() => onOpen(item.element_id)}>Öffnen</button>
) : null}
{canEdit ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onDetach(item.element_id)}>In die Liste</button>
) : null}
</li>
))}
</ol>
</section>
) : null}
{item.evidence?.length ? (
<ul>
{item.evidence.map((proof) => (
<li key={proof.id} className="use-chip">
<span
className="use-chip__grip"
aria-label={`${proof.title} aus den Belegen ziehen`}
{...chipDrag(canEdit && !pending, {
source: "evidence",
elementId: proof.element_id,
dispatchId: item.id,
version: item.version,
title: proof.title,
}, onCarryStart, onCarryEnd)}
/>
<button type="button" className="quiet" onClick={() => onOpen(proof.element_id)}>
{receiptRoleLabel(proof.role, proof.role_label)}: {proof.title}
</button>
<span className="muted">{formatDate(proof.document_on)}</span>
{proof.source_state === "gap" ? <span>Lücke: {proof.gap_reason}</span> : null}
<ComparisonList comparisons={proof.comparisons} state={proof.source_state} reason={proof.gap_reason} />
{canEdit ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onDetachEvidence(proof, item)}>
In die Liste
</button>
) : null}
{canEdit && proof.listed_fold === "evidence" ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onUnfold(proof.element_id)}>
Zusätzlich in der Liste zeigen
</button>
) : null}
</li>
))}
</ul>
) : null}
<details className="use-editions">
<summary>Gesicherte Fassung</summary>
<ol>
{item.items.map((part) => (
<li key={part.id}>
<span>{part.role === "host" ? "Schreiben" : "Anlage"}: {part.title}</span>
<span className="muted">Dokumentdatum {formatDate(part.document_on)}</span>
{part.source_state === "gap" ? <span>Lücke: {part.gap_reason}</span> : scope ? (
<a href={snapshotHref(item.id, part.id, scope)}>Öffnen</a>
) : <span>Gesichert</span>}
</li>
))}
</ol>
</details>
</section>
))}
{canEdit ? (
<DropWell
label="Beleg für einen weiteren Versand"
hint="Neuen Versand mit diesem Beleg anlegen"
armed={armed}
onDrop={(payload) => onDropReceipt(payload, null)}
onPick={() => onPickReceipt(null)}
/>
{dispatches.map((item) => (
<section key={item.id}>
<h4>
Versand {item.undated ? "undatiert" : formatDate(item.sent_on)} · {item.channel_label}
{item.counterpart ? ` · ${item.counterpart}` : ""}
</h4>
{item.evidence?.length ? (
<ul>
{item.evidence.map((proof) => (
<li key={proof.id} className="use-chip">
{canEdit ? (
<span
className="use-chip__grip"
aria-label={`${proof.title} aus den Belegen ziehen`}
{...chipDrag(!pending, {
source: "evidence",
elementId: proof.element_id,
dispatchId: item.id,
hostElementId: binding.element.id,
version: item.version,
title: proof.title,
}, onCarryStart, onCarryEnd)}
/>
) : null}
<button type="button" className="quiet" onClick={() => onOpen(proof.element_id)}>
{receiptRoleLabel(proof.role, proof.role_label)}: {proof.title}
</button>
<span className="muted">{formatDate(proof.document_on)}</span>
{proof.source_state === "gap" ? <span>Lücke: {proof.gap_reason}</span> : null}
{canEdit ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onDetachEvidence(proof, item)}>
In die Liste
</button>
) : null}
{canEdit && proof.listed_fold === "evidence" ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onUnfold(proof.element_id)}>
Zusätzlich in der Liste zeigen
</button>
) : null}
</li>
))}
</ul>
) : <p className="muted">Ohne Beleg</p>}
<details className="use-editions">
<summary>Gesicherte Fassung</summary>
<ol>
{item.items.map((part) => (
<li key={part.id}>
<span>{part.role === "host" ? "Schreiben" : "Anlage"}: {part.title}</span>
<span className="muted">{formatDate(part.document_on)}</span>
{part.source_state === "gap" ? <span>Lücke: {part.gap_reason}</span> : scope ? (
<a href={snapshotHref(item.id, part.id, scope)}>Öffnen</a>
) : <span>Gesichert</span>}
</li>
))}
</ol>
</details>
</section>
))}
</div>
) : null}
</div>
);
+17 -17
View File
@@ -1329,33 +1329,33 @@ button.hierarchy__row { width: 100%; min-height: 34px; padding: 6px 8px; border:
.choice-list li, .choice-list label { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.choice-list--scroll { max-height: 240px; overflow: auto; }
.choice-list__move { display: inline-flex; gap: 4px; margin-left: auto; }
.unit-fold { margin-top: 2px; }
.unit-detail, .comparison, .chrono { display: grid; gap: 8px; margin-top: 8px; }
.unit-detail--slim { gap: 4px; margin-top: 2px; }
.unit-detail h4, .chrono h3 { margin: 0; font-size: 13px; }
.unit-detail section { display: grid; gap: 4px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: color-mix(in srgb, var(--surface) 88%, var(--bg)); }
.unit-detail--slim section { padding: 0; border: 0; border-radius: 0; background: transparent; gap: 2px; }
.unit-detail--slim button.quiet, .unit-detail--slim summary { min-height: 22px; height: 22px; padding: 0 6px; font-size: 12px; }
.unit-detail ol, .unit-detail ul, .comparison ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.unit-detail--slim ol, .unit-detail--slim ul { gap: 0; }
.unit-detail li { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: center; min-width: 0; max-width: 100%; }
.unit-detail li .muted { white-space: nowrap; }
.use-strip { display: grid; gap: 4px; margin-top: 6px; }
.use-strip .drop-well { min-height: 32px; padding-top: 0; padding-bottom: 0; background: transparent; }
.drop-well {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
min-height: 44px;
padding: 4px 8px 4px 12px;
border: 1px dashed var(--border);
border-radius: 8px;
color: var(--text2);
background: var(--surface);
}
.drop-well.is-armed { border-color: var(--brand); color: var(--text1); background: var(--accent-light); }
.drop-well.is-over { outline: 2px solid var(--brand); background: var(--accent-light); }
.use-chip { cursor: default; }
.use-chip__grip { width: 14px; height: 22px; border: 0; padding: 0; border-left: 2px dotted var(--text3); border-right: 2px dotted var(--text3); background: transparent; flex: none; cursor: grab; }
.entry-mark[draggable="true"] { cursor: grab; }
.use-editions summary { cursor: pointer; color: var(--text2); font-size: 13px; }
.unit-toggle { min-height: 32px; }
.unit-toggle { min-height: 22px; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.preview-row.is-use-target .direction-trigger,
.preview-row.is-use-target .entry-mark {
box-shadow: inset 0 0 0 2px var(--accent);
background: var(--accent-light);
}
.pick-tree__list { max-height: 60vh; overflow: auto; margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.pick-tree__items { margin: 0; padding: 0; list-style: none; }
.pick-tree__chapter, .pick-tree__row { display: flex; gap: 8px; align-items: center; min-height: 28px; padding-left: calc(var(--depth, 0) * 14px); }
.pick-tree__chapter > span, .pick-tree__row label { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.pick-tree button.quiet { min-height: 28px; height: 28px; padding: 0 8px; font-size: 13px; }
.pick-tree__bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; position: sticky; bottom: 0; background: var(--surface); padding-top: 8px; }
.count { white-space: normal; }
.chapter-children { display: grid; gap: 8px; margin-top: 8px; }
.pick-bar {