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

+547
View File
@@ -0,0 +1,547 @@
import { useState } from "react";
import { Link } from "react-router-dom";
import { api } from "../api.js";
function formatDate(value) {
if (!value) return "Ohne Datum";
const [year, month, day] = String(value).slice(0, 10).split("-");
if (!year || !month || !day) return String(value);
return `${day}.${month}.${year}`;
}
export function scopeBody(context, containerKind, containerId) {
const rights = context || { kind: containerKind, id: containerId };
const same = rights.kind === containerKind && rights.id === containerId;
return { context: rights, placement: same ? null : { kind: containerKind, id: containerId } };
}
export function channelWord(channel) {
if (channel === "email") return "per E-Mail";
if (channel === "post") return "per Post";
if (channel === "other") return "sonstiger Weg";
return "";
}
export function unitMarks(binding) {
const pack = binding?.correspondence;
if (!pack) return "";
const parts = [];
const attachments = pack.attachments || [];
if (attachments.length === 1) parts.push("1 Anlage");
else if (attachments.length > 1) parts.push(`${attachments.length} Anlagen`);
const dispatches = pack.dispatches || [];
if (dispatches.length === 1) parts.push(channelWord(dispatches[0].channel));
else if (dispatches.length > 1) parts.push(`${dispatches.length} Versände`);
const evidence = dispatches.reduce((sum, item) => sum + (item.evidence || []).length, 0);
if (evidence === 1) parts.push("Nachweis");
else if (evidence > 1) parts.push(`${evidence} Nachweise`);
return parts.join(" · ");
}
export function hostMark(binding) {
const hosts = binding?.correspondence?.hosts || [];
if (!hosts.length) return "";
return `Dieselbe Unterlage · Anlage zu ${hosts.map((item) => item.title).join(", ")}`;
}
function snapshotHref(dispatchId, itemId, scope) {
const search = new URLSearchParams({
context_kind: scope.context.kind,
context_id: scope.context.id,
});
if (scope.placement) {
search.set("placement_kind", scope.placement.kind);
search.set("placement_id", scope.placement.id);
}
return `/api/v1/dispatches/${dispatchId}/items/${itemId}/content?${search}`;
}
function fieldBody(scope, extra) {
const body = { ...extra, context: scope.context };
if (scope.placement) body.placement = scope.placement;
return body;
}
export function AttachDialog({ host, candidates, scope, pending, onClose, onDone }) {
const initial = candidates.map((item) => item.element.id);
const [order, setOrder] = useState(initial);
const [chosen, setChosen] = useState(() => new Set(initial));
const [fold, setFold] = useState("attachment");
const [error, setError] = useState("");
function move(id, delta) {
setOrder((current) => {
const index = current.indexOf(id);
const target = index + delta;
if (index < 0 || target < 0 || target >= current.length) return current;
const next = [...current];
const [item] = next.splice(index, 1);
next.splice(target, 0, item);
return next;
});
}
async function save(event) {
event.preventDefault();
const ids = order.filter((id) => chosen.has(id));
if (!ids.length) {
setError("Es ist keine Anlage ausgewählt.");
return;
}
setError("");
try {
await api(`/api/v1/elements/${host.element.id}/attachments`, {
method: "POST",
body: fieldBody(scope, {
expected_version: host.element.version,
attachment_element_ids: ids,
fold,
}),
});
onDone();
} catch (err) {
setError(err.message);
}
}
return (
<form className="stack" onSubmit={save}>
<p>Anlagen von <strong>{host.element.title}</strong>. Die Dateien bleiben an ihrem Ort. Die aktuelle Liste ist nur die Zuordnung in diesem Zusammenhang.</p>
<ol className="choice-list">
{order.map((id, index) => {
const item = candidates.find((entry) => entry.element.id === id);
if (!item) return null;
return (
<li key={id}>
<label>
<input
type="checkbox"
checked={chosen.has(id)}
onChange={() => setChosen((current) => {
const next = new Set(current);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
})}
/>
<span>{item.element.title}</span>
<span className="muted">{formatDate(item.element.dates?.document_on)}</span>
</label>
<span className="choice-list__move">
<button type="button" disabled={index === 0} onClick={() => move(id, -1)} aria-label={`${item.element.title} nach oben`}>↑</button>
<button type="button" disabled={index === order.length - 1} onClick={() => move(id, 1)} aria-label={`${item.element.title} nach unten`}>↓</button>
</span>
</li>
);
})}
</ol>
<fieldset>
<legend>Vorkommen in der Liste</legend>
<label><input type="radio" name="fold" checked={fold === "keep"} onChange={() => setFold("keep")} /> Zusätzlich als eigenständige Einträge behalten</label>
<label><input type="radio" name="fold" checked={fold === "attachment"} onChange={() => setFold("attachment")} /> Nur in der Anlagenansicht zeigen</label>
</fieldset>
{error ? <p className="error">{error}</p> : null}
<button type="submit" disabled={pending}>Anlagen zuordnen</button>
<button type="button" className="quiet" onClick={onClose}>Abbrechen</button>
</form>
);
}
export function DispatchDialog({ host, scope, pending, onClose, onDone }) {
const proposal = host.correspondence?.attachments || [];
const [order, setOrder] = useState(proposal.map((item) => item.element_id));
const [chosen, setChosen] = useState(() => new Set(proposal.map((item) => item.element_id)));
const [channel, setChannel] = useState("email");
const [sentOn, setSentOn] = useState("");
const [counterpart, setCounterpart] = useState("");
const [historical, setHistorical] = useState(false);
const [error, setError] = useState("");
function move(id, delta) {
setOrder((current) => {
const index = current.indexOf(id);
const target = index + delta;
if (index < 0 || target < 0 || target >= current.length) return current;
const next = [...current];
const [item] = next.splice(index, 1);
next.splice(target, 0, item);
return next;
});
}
async function save(event) {
event.preventDefault();
setError("");
try {
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: order.filter((id) => chosen.has(id)),
evidence: [],
historical_gap: historical,
}),
});
onDone();
} catch (err) {
setError(err.message);
}
}
return (
<form className="stack" onSubmit={save}>
<p>Versand von <strong>{host.element.title}</strong> dokumentieren. Dabei wird nichts verschickt. Die Anlagenliste ist ein Vorschlag für diesen Versand.</p>
<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>
<p className="muted">Leer lassen, wenn der Versandtag unbekannt ist. Der Erfassungszeitpunkt ersetzt ihn nicht.</p>
<label>
Gegenüber
<input value={counterpart} onChange={(event) => setCounterpart(event.target.value)} maxLength={200} />
</label>
<p className="muted">Leer lassen, wenn das Gegenüber unbekannt ist.</p>
<fieldset>
<legend>Tatsächlich mitversendet</legend>
<ol className="choice-list">
{order.map((id, index) => {
const item = proposal.find((entry) => entry.element_id === id);
if (!item) return null;
return (
<li key={id}>
<label>
<input type="checkbox" checked={chosen.has(id)} onChange={() => setChosen((current) => {
const next = new Set(current);
if (next.has(id)) next.delete(id);
else next.add(id);
return next;
})} />
<span>{item.title}</span>
<span className="muted">{formatDate(item.document_on)}</span>
</label>
<span className="choice-list__move">
<button type="button" disabled={index === 0} onClick={() => move(id, -1)} aria-label={`${item.title} nach oben`}>↑</button>
<button type="button" disabled={index === order.length - 1} onClick={() => move(id, 1)} aria-label={`${item.title} nach unten`}>↓</button>
</span>
</li>
);
})}
</ol>
{!proposal.length ? <p className="muted">Keine zugeordnete Anlage. Das Schreiben kann allein dokumentiert werden.</p> : null}
</fieldset>
<label>
<input type="checkbox" checked={historical} onChange={(event) => setHistorical(event.target.checked)} />
Historische Originalfassung liegt nicht mehr vor
</label>
{error ? <p className="error">{error}</p> : null}
<button type="submit" disabled={pending}>Versand dokumentieren</button>
<button type="button" className="quiet" onClick={onClose}>Abbrechen</button>
</form>
);
}
export function EvidenceDialog({ element, hosts, scope, pending, onClose, onDone }) {
const [hostId, setHostId] = useState(hosts[0]?.element.id || "");
const host = hosts.find((item) => item.element.id === hostId) || null;
const [dispatchId, setDispatchId] = useState(host?.correspondence?.dispatches?.[0]?.id || "");
const [role, setRole] = useState("email");
const [fold, setFold] = useState("keep");
const [channel, setChannel] = useState("email");
const [sentOn, setSentOn] = useState("");
const [counterpart, setCounterpart] = useState("");
const [result, setResult] = useState(null);
const [error, setError] = useState("");
async function save(event) {
event.preventDefault();
if (!host) return;
setError("");
try {
let target = dispatchId;
if (!target) {
const created = 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: [{ element_id: element.id, role, fold }],
historical_gap: false,
}),
});
const proof = (created.evidence || []).find((item) => item.element_id === element.id);
setResult(proof || created);
onDone(false);
return;
}
const dispatch = (host.correspondence?.dispatches || []).find((item) => item.id === target);
const proof = await api(`/api/v1/dispatches/${target}/evidence`, {
method: "POST",
body: fieldBody(scope, {
expected_version: dispatch?.version || 1,
element_id: element.id,
role,
fold,
}),
});
setResult(proof);
onDone(false);
} catch (err) {
setError(err.message);
}
}
return (
<form className="stack" onSubmit={save}>
<p><strong>{element.title}</strong> als Nachweis zuordnen. Das Original bleibt vollständig erhalten.</p>
<label>
Hauptschriftstück
<select value={hostId} onChange={(event) => {
const next = event.target.value;
setHostId(next);
const found = hosts.find((item) => item.element.id === next);
setDispatchId(found?.correspondence?.dispatches?.[0]?.id || "");
}}>
{hosts.map((item) => <option key={item.element.id} value={item.element.id}>{item.element.title}</option>)}
</select>
</label>
<label>
Versand
<select value={dispatchId} onChange={(event) => setDispatchId(event.target.value)}>
<option value="">Neuen Versand in diesem Ablauf anlegen</option>
{(host?.correspondence?.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)}>
<option value="email">E-Mail/Versanddokumentation</option>
<option value="submission">Einlieferung</option>
<option value="delivery">Zustellung</option>
<option value="other">sonstiger Nachweis</option>
</select>
</label>
<fieldset>
<legend>Darstellung hier</legend>
<label><input type="radio" name="evidence-fold" checked={fold === "evidence"} onChange={() => setFold("evidence")} /> Hier als Nachweis darstellen</label>
<label><input type="radio" name="evidence-fold" checked={fold === "keep"} onChange={() => setFold("keep")} /> Zusätzlich als eigenständigen Eintrag behalten</label>
</fieldset>
{result ? <ComparisonList comparisons={result.comparisons || []} state={result.source_state} reason={result.gap_reason} /> : null}
{error ? <p className="error">{error}</p> : null}
<button type="submit" disabled={pending || !host}>Nachweis zuordnen</button>
<button type="button" className="quiet" onClick={onClose}>Schließen</button>
</form>
);
}
export function ComparisonList({ comparisons = [], state, reason }) {
if (!comparisons.length && state !== "gap") return null;
return (
<div className="comparison">
{state === "gap" ? <p>Originalfassung nicht gesichert: {reason}</p> : null}
{state === "identified" ? <p>Nachweis manuell zugeordnet. Gleiche Dateinamen werden nicht automatisch zusammengeführt.</p> : null}
<ul>
{comparisons.map((item) => (
<li key={`${item.filename}-${item.sha256}`}>
<strong>{item.filename}</strong>
{item.disposition === "same_bytes" ? ` · gleicher Dateiinhalt wie ${item.matches.map((match) => match.title).join(", ")} · Vorschlag, nicht automatisch zugeordnet` : null}
{item.disposition === "same_name_different_bytes" ? ` · gleicher Name, anderer Inhalt als ${item.matches.map((match) => match.title).join(", ")}` : null}
{item.disposition === "distinct" ? " · eigener Inhalt" : null}
</li>
))}
</ul>
</div>
);
}
export function UnitDetail({ binding, canEdit, pending, scope, onOpen, onDetach, onUnfold }) {
const pack = binding.correspondence || {};
const attachments = pack.attachments || [];
const dispatches = pack.dispatches || [];
if (!attachments.length && !dispatches.length && !(pack.hosts || []).length) return null;
return (
<div className="unit-detail">
{attachments.length ? (
<section>
<h4>Anlagen</h4>
<ol>
{attachments.map((item, index) => (
<li key={item.id}>
<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)}>Anlage lösen</button>
) : null}
</li>
))}
</ol>
</section>
) : null}
{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}
{item.recorded_at ? ` Erfasst ${formatDate(item.recorded_at.slice(0, 10))}.` : ""}
</p>
<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)}>Gesicherte Fassung</a>
) : <span>Gesicherte Fassung</span>}
</li>
))}
</ol>
{item.evidence?.length ? (
<ul>
{item.evidence.map((proof) => (
<li key={proof.id}>
<button type="button" className="quiet" onClick={() => onOpen(proof.element_id)}>
{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 && proof.listed_fold === "evidence" ? (
<button type="button" className="quiet" disabled={pending} onClick={() => onUnfold(proof.element_id)}>
Wieder als eigenständigen Eintrag zeigen
</button>
) : null}
</li>
))}
</ul>
) : <p className="muted">Vom Nutzer dokumentiert, noch ohne Nachweis.</p>}
</section>
))}
</div>
);
}
export function Chronology({ bindings, direction, itemHref, selectedId, onOpen }) {
const events = [];
for (const binding of bindings || []) {
if (binding.correspondence?.fold !== "evidence") {
events.push({
key: `doc-${binding.id}`,
date: binding.element?.dates?.document_on || "",
label: "Unterlage",
title: binding.element?.title || "",
detail: `Dokumentdatum ${formatDate(binding.element?.dates?.document_on)}`,
binding,
});
}
for (const dispatch of binding.correspondence?.dispatches || []) {
events.push({
key: `send-${dispatch.id}`,
date: dispatch.sent_on || "",
label: "Versand",
title: binding.element?.title || "",
detail: [
dispatch.undated ? "Versand undatiert" : `Versanddatum ${formatDate(dispatch.sent_on)}`,
dispatch.channel_label,
(dispatch.evidence || []).length === 1
? "1 Nachweis"
: (dispatch.evidence || []).length
? `${dispatch.evidence.length} Nachweise`
: "ohne Nachweis",
].join(" · "),
binding,
dispatch,
});
}
}
events.sort((left, right) => {
if (!left.date && !right.date) return left.key.localeCompare(right.key);
if (!left.date) return 1;
if (!right.date) return -1;
const compared = left.date.localeCompare(right.date);
if (compared) return direction === "desc" ? -compared : compared;
return left.key.localeCompare(right.key);
});
const undated = events.filter((item) => !item.date);
const dated = events.filter((item) => item.date);
const ordered = direction === "desc" ? [...undated, ...dated] : [...dated, ...undated];
const groups = [];
for (const event of ordered) {
const name = event.date ? formatDate(event.date) : "Ohne Datum";
const last = groups[groups.length - 1];
if (!last || last.name !== name) groups.push({ name, events: [event] });
else last.events.push(event);
}
if (!groups.length) return <p className="muted">In dieser Ansicht ist noch nichts zu sehen.</p>;
return (
<div className="chrono">
{groups.map((group) => (
<section key={group.name}>
<h3>{group.name}</h3>
<ol className="preview-list">
{group.events.map((event) => (
<li key={event.key} className={selectedId === event.binding.id ? "preview-row is-selected" : "preview-row"}>
<div className="preview-row__body">
<Link to={itemHref(event.binding)} onClick={(click) => {
if (click.metaKey || click.ctrlKey || click.shiftKey || click.altKey || click.button !== 0) return;
click.preventDefault();
onOpen(event.binding);
}}>
<strong>{event.label}: {event.title}</strong>
</Link>
<span className="preview-row__facts">{event.detail}</span>
</div>
</li>
))}
</ol>
</section>
))}
</div>
);
}
export async function restoreFold(bindingId, version, scope) {
await api(`/api/v1/bindings/${bindingId}/fold`, {
method: "PATCH",
body: fieldBody(scope, { expected_version: version, fold: null }),
});
}