Halte Anlagen und Versand als eigene Verwendung fest, damit die uebermittelte Fassung und ihre Nachweise spaeter nicht still mit der Arbeitsfassung verschmelzen.
Deploy Development / deploy (push) Successful in 28s
Test Suite / pytest-backend (push) Successful in 1m37s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 9s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-18 09:57:59 +02:00
1 parent f21c64a944
commit 3c190c87b4
27 files changed
+3953 -71

No files matched your search

+208 -19
View File
@@ -11,10 +11,23 @@ import { ErrorNote } from "./widgets.jsx";
import {
buildChapterSections,
chapterPathLabel,
countLabel,
descendantChapterIds,
findSection,
sectionCounts,
siblingChapterIds,
} from "./chapters.js";
import {
AttachDialog,
Chronology,
DispatchDialog,
EvidenceDialog,
hostMark,
restoreFold,
scopeBody,
unitMarks,
UnitDetail,
} from "./correspondence.jsx";
export function formatDate(value) {
if (!value) return "Ohne Datum";
@@ -756,6 +769,9 @@ function EntryActions({
onRemove,
onMove,
onPlaceChapter,
onAttach,
onDispatch,
onEvidence,
}) {
const anchorRef = useRef(null);
const [open, setOpen] = useState(false);
@@ -823,6 +839,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 && 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 ? <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>
@@ -919,6 +938,8 @@ export function ContentBoard({
const chapters = record?.chapters || [];
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 [indicator, setIndicator] = useState(null);
const [folded, setFolded] = useState(() => new Set());
@@ -930,11 +951,17 @@ export function ContentBoard({
const savingDirection = useRef(false);
const custom = record?.content_order === "position";
const direction = record?.content_order_dir === "desc" ? "desc" : "asc";
const forest = buildChapterSections(chapters, source);
const viewMode = record?.content_view === "chronology" ? "chronology" : "structure";
const listed = source.filter((item) => !item.correspondence?.fold);
const forest = buildChapterSections(chapters, listed);
const loose = looseSection(forest.loose, chapters);
const selectedSection = onlyChapter ? findSection(forest.roots, onlyChapter) : null;
const visibleRoots = onlyChapter ? (selectedSection ? [selectedSection] : []) : forest.roots;
const shownCount = onlyChapter ? (selectedSection?.items.length || 0) : source.length;
const shownCount = viewMode === "chronology"
? ""
: onlyChapter
? countLabel(sectionCounts(selectedSection).direct, sectionCounts(selectedSection).nested)
: String(listed.length);
const activePath = onlyChapter ? chapterPathLabel(chapters, onlyChapter) : "";
const canSort = sortable && record?.rights?.edit;
const canEdit = Boolean(record?.rights?.edit);
@@ -1081,13 +1108,13 @@ export function ContentBoard({
};
}, []);
async function saveMode(mode, nextDirection) {
async function saveMode(mode, nextDirection, nextView = viewMode) {
setError("");
setPending(true);
try {
await api(`${orderPath}/content-order`, {
method: "PATCH",
body: { expected_version: record.version, mode, direction: nextDirection, ...orderContext },
body: { expected_version: record.version, mode, direction: nextDirection, view: nextView, ...orderContext },
});
onChange();
} catch (err) {
@@ -1097,6 +1124,30 @@ export function ContentBoard({
}
}
function orderedIds(sections) {
const hidden = source.filter((item) => item.correspondence?.fold);
const used = new Set();
const ids = [];
for (const section of sections) {
for (const item of section.items) {
ids.push(item.id);
used.add(item.id);
}
const chapterId = section.id === "loose" ? null : section.id;
for (const item of hidden) {
const itemChapter = item.chapter_id || null;
if ((chapterId ? itemChapter === chapterId : !itemChapter) && !used.has(item.id)) {
ids.push(item.id);
used.add(item.id);
}
}
}
for (const item of source) {
if (!used.has(item.id)) ids.push(item.id);
}
return ids;
}
async function persist(next, version = record.version) {
setError("");
setPending(true);
@@ -1105,7 +1156,7 @@ export function ContentBoard({
method: "POST",
body: {
expected_version: version,
binding_ids: next.flatMap((section) => section.items.map((item) => item.id)),
binding_ids: orderedIds(next),
...orderContext,
},
});
@@ -1423,7 +1474,7 @@ export function ContentBoard({
return (
<div className="contents" ref={rootRef}>
<div className="content-toolbar">
<h2>{activePath || listTitle || "Inhalte"} <span className="count">{shownCount}</span></h2>
<h2>{viewMode === "chronology" ? "Chronologie" : (activePath || listTitle || "Inhalte")} <span className="count">{shownCount}</span></h2>
<div className="content-toolbar__tools">
{canSort && chapters.length && !picking ? (
<button type="button" className="quiet content-toolbar__pick" onClick={() => { setPicking(true); setPickTarget(onlyChapter || ""); }}>Mehrere einordnen</button>
@@ -1432,8 +1483,10 @@ export function ContentBoard({
<OrderChoice
mode={custom ? "position" : "date"}
direction={direction}
view={viewMode}
disabled={pending}
allowPosition
allowChronology
onChange={saveMode}
/>
) : sortable ? (
@@ -1456,21 +1509,78 @@ 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" className="quiet" onClick={() => { setPicking(false); setPicked(new Set()); }}>Auswahl beenden</button>
</div>
) : null}
{source.length || chapters.length ? (
{viewMode === "chronology" ? (
<Chronology bindings={source} direction={direction} itemHref={itemHref} selectedId={selectedId} onOpen={onOpen} />
) : source.length || chapters.length ? (
renderBlockList()
) : (
<p className="muted">Noch keine Unterlage und keine Notiz.</p>
)}
<Modal open={dialog?.type === "attach" || dialog?.type === "bulk"} title="Anlagen zuordnen" onClose={() => setDialog(null)}>
{dialog?.type === "bulk" && !dialog.host ? (
<form className="stack" onSubmit={(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 });
}}>
<p>Hauptschriftstück für die ausgewählten Unterlagen wählen. Die Kapitel bleiben bestehen, bis sie separat aufgelöst werden.</p>
<label>
Hauptschriftstü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>)}
</select>
</label>
<button type="submit">Weiter zur Reihenfolge</button>
</form>
) : null}
{dialog?.type === "attach" && dialog.host ? (
<AttachDialog
host={dialog.host}
candidates={dialog.candidates}
scope={scopeBody(actionContext(), containerKind, containerId)}
pending={pending}
onClose={() => setDialog(null)}
onDone={() => { setDialog(null); setPicked(new Set()); setPicking(false); onChange(); }}
/>
) : null}
</Modal>
<Modal open={dialog?.type === "dispatch"} title="Versand dokumentieren" onClose={() => setDialog(null)}>
{dialog?.type === "dispatch" ? (
<DispatchDialog
host={dialog.host}
scope={scopeBody(actionContext(), containerKind, containerId)}
pending={pending}
onClose={() => setDialog(null)}
onDone={() => { setDialog(null); onChange(); }}
/>
) : null}
</Modal>
<Modal open={dialog?.type === "evidence"} title="Als Versandnachweis zuordnen" onClose={() => setDialog(null)}>
{dialog?.type === "evidence" ? (
<EvidenceDialog
element={dialog.binding.element}
hosts={listed.filter((item) => item.element.id !== dialog.binding.element.id)}
scope={scopeBody(actionContext(), containerKind, containerId)}
pending={pending}
onClose={() => setDialog(null)}
onDone={() => onChange()}
/>
) : null}
</Modal>
</div>
);
function renderBlockList() {
const blocks = [...visibleRoots];
if (!onlyChapter && loose) blocks.push(loose);
return blocks.map((section) => renderBlock(section, 0, false));
return blocks.map((section) => renderBlock(section, 0, Boolean(onlyChapter && section.id === onlyChapter)));
}
function renderBlock(section, depth, hideHead) {
@@ -1526,7 +1636,7 @@ export function ContentBoard({
) : null}
<ChapterHeading
section={section}
count={section.items.length}
count={countLabel(sectionCounts(section).direct, sectionCounts(section).nested)}
expanded={expanded}
movable={movable}
canEdit={canEdit && section.id !== "loose"}
@@ -1572,7 +1682,8 @@ 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].filter(Boolean).join(" · ");
const facts = [party, formatDate(fachDate(element)), sourceLabel(element), way, unitMarks(binding)].filter(Boolean).join(" · ");
const samePiece = hostMark(binding);
const originText = binding.origin && section.title && !binding.origin.includes(section.title)
? `${binding.origin}${binding.shared ? " · weitere Einbindung" : ""}`
: binding.origin && !section.title
@@ -1661,7 +1772,71 @@ export function ContentBoard({
{text ? (
<Link className="preview-row__text" to={href} 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}
</div>
<EntryActions
element={element}
@@ -1681,6 +1856,13 @@ 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)),
})}
onDispatch={(row) => setDialog({ type: "dispatch", host: row })}
onEvidence={(row) => setDialog({ type: "evidence", binding: row })}
/>
</li>
);
@@ -1698,24 +1880,31 @@ export function ContentBoard({
}
}
export function OrderChoice({ mode, direction, disabled, allowPosition = false, onChange }) {
const value = mode === "position" ? "position" : direction === "desc" ? "date-desc" : "date-asc";
export function OrderChoice({ mode, direction, view = "structure", disabled, allowPosition = false, allowChronology = false, onChange }) {
const value = view === "chronology"
? (direction === "desc" ? "chrono-desc" : "chrono-asc")
: mode === "position" ? "position" : direction === "desc" ? "date-desc" : "date-asc";
return (
<label className="order-choice">
<span>Ordnung</span>
<span>{allowChronology ? "Ansicht" : "Ordnung"}</span>
<select
aria-label="Ordnung der Inhalte"
aria-label="Ansicht und Ordnung der Inhalte"
value={value}
disabled={disabled}
onChange={(event) => {
const next = event.target.value;
if (next === "position") onChange("position", direction === "desc" ? "desc" : "asc");
else onChange("date", next === "date-desc" ? "desc" : "asc");
const kept = mode === "position" ? "position" : "date";
if (next === "chrono-asc") onChange(kept, "asc", "chronology");
else if (next === "chrono-desc") onChange(kept, "desc", "chronology");
else if (next === "position") onChange("position", direction === "desc" ? "desc" : "asc", "structure");
else onChange("date", next === "date-desc" ? "desc" : "asc", "structure");
}}
>
<option value="date-asc">Fachliches Datum, aufsteigend</option>
<option value="date-desc">Fachliches Datum, absteigend</option>
{allowPosition ? <option value="position">Eigene Reihenfolge</option> : null}
<option value="date-asc">{allowChronology ? "Gliederung, Datum aufsteigend" : "Fachliches Datum, aufsteigend"}</option>
<option value="date-desc">{allowChronology ? "Gliederung, Datum absteigend" : "Fachliches Datum, absteigend"}</option>
{allowPosition ? <option value="position">{allowChronology ? "Gliederung, eigene Reihenfolge" : "Eigene Reihenfolge"}</option> : null}
{allowChronology ? <option value="chrono-asc">Chronologie, aufsteigend</option> : null}
{allowChronology ? <option value="chrono-desc">Chronologie, absteigend</option> : null}
</select>
</label>
);