Ordne Akten und Vorgaenge nach fachlichem Datum oder eigener Reihenfolge und mache den Inhalt zur Arbeitsansicht.
Deploy Development / deploy (push) Successful in 22s
Test Suite / pytest-backend (push) Successful in 51s
Test Suite / smoke-dev (push) Successful in 1s
Test Suite / frontend-build (push) Successful in 6s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-17 09:36:48 +02:00
1 parent 27925093e2
commit 52bda91aad
22 files changed
+2079 -258

No files matched your search

+270
View File
@@ -0,0 +1,270 @@
import { useState } from "react";
import { Link } from "react-router-dom";
import { api } from "../api.js";
import { ErrorNote } from "./widgets.jsx";
export 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 formatStamp(value) {
if (!value) return "";
const [day, time = ""] = String(value).split("T");
return `${formatDate(day)} ${time.replace("Z", " UTC").slice(0, 8)}`.trim();
}
export function kindLabel(kind) {
if (kind === "note") return "Notiz";
if (kind === "file") return "Datei";
if (kind === "external_ref") return "Paperless";
return "Unterlage";
}
export function fachDate(element) {
return element?.dates?.document_on || null;
}
export function Trail({ items }) {
if (!items?.length) return null;
return (
<nav className="trail" aria-label="Pfad">
{items.map((item, index) => (
<span key={`${item.label}-${index}`}>
{index ? <span className="trail__sep" aria-hidden="true">/</span> : null}
{item.href ? <Link to={item.href}>{item.label}</Link> : <span aria-current="page">{item.label}</span>}
</span>
))}
</nav>
);
}
function sectionsOf(chapters, bindings) {
const buckets = new Map();
const loose = [];
for (const binding of bindings || []) {
if (binding.chapter_id && chapters.some((chapter) => chapter.id === binding.chapter_id)) {
const list = buckets.get(binding.chapter_id) || [];
list.push(binding);
buckets.set(binding.chapter_id, list);
} else {
loose.push(binding);
}
}
const sections = (chapters || [])
.filter((chapter) => (buckets.get(chapter.id) || []).length)
.map((chapter) => ({ id: chapter.id, title: chapter.title, items: buckets.get(chapter.id) }));
if (loose.length || !sections.length) {
sections.push({ id: "loose", title: sections.length ? "Ohne Kapitel" : "", items: loose });
}
return sections;
}
export function ContentBoard({
record,
bindings,
context,
containerKind,
containerId,
sortable = true,
onChange,
itemHref,
}) {
const source = bindings || record?.bindings || [];
const chapters = record?.chapters || [];
const [error, setError] = useState("");
const [pending, setPending] = useState(false);
const custom = record?.content_order === "position";
const direction = record?.content_order_dir === "desc" ? "desc" : "asc";
const sections = sectionsOf(chapters, source);
const canSort = sortable && record?.rights?.edit;
async function saveMode(mode, nextDirection) {
setError("");
setPending(true);
try {
await api(`/api/v1/${containerKind === "case" ? "cases" : "matters"}/${containerId}/content-order`, {
method: "PATCH",
body: {
expected_version: record.version,
mode,
direction: nextDirection,
...(context && containerKind === "matter" ? { context } : {}),
},
});
onChange();
} catch (err) {
setError(err.message);
} finally {
setPending(false);
}
}
async function move(bindingId, delta) {
const next = sections.map((section) => ({ ...section, items: [...section.items] }));
let moved = false;
for (const section of next) {
const index = section.items.findIndex((item) => item.id === bindingId);
const target = index + delta;
if (index < 0 || target < 0 || target >= section.items.length) continue;
const [item] = section.items.splice(index, 1);
section.items.splice(target, 0, item);
moved = true;
}
if (!moved) return;
setError("");
setPending(true);
try {
await api(`/api/v1/${containerKind === "case" ? "cases" : "matters"}/${containerId}/bindings/order`, {
method: "POST",
body: {
expected_version: record.version,
binding_ids: next.flatMap((section) => section.items.map((item) => item.id)),
...(context && containerKind === "matter" ? { context } : {}),
},
});
onChange();
} catch (err) {
setError(err.message);
} finally {
setPending(false);
}
}
return (
<div className="contents">
{canSort ? (
<div className="order-bar" role="group" aria-label="Ordnung der Inhalte">
<button type="button" className={record.content_order !== "position" && direction === "asc" ? "" : "quiet"} disabled={pending} onClick={() => saveMode("date", "asc")}>
Fachliches Datum, aufsteigend
</button>
<button type="button" className={record.content_order !== "position" && direction === "desc" ? "" : "quiet"} disabled={pending} onClick={() => saveMode("date", "desc")}>
Fachliches Datum, absteigend
</button>
<button type="button" className={custom ? "" : "quiet"} disabled={pending} onClick={() => saveMode("position", direction)}>
Eigene Reihenfolge
</button>
</div>
) : (
<p className="muted">{custom ? "Eigene Reihenfolge" : `Fachliches Datum, ${direction === "desc" ? "absteigend" : "aufsteigend"}`}</p>
)}
<ErrorNote error={error} />
{source.length ? (
sections.map((section) => (
<section key={section.id} className="content-section">
{section.title ? <h3 className="chapter-title">{section.title}</h3> : null}
<ol className="content-list">
{section.items.map((binding, index) => {
const element = binding.element;
const href = itemHref(binding);
return (
<li key={binding.id} className="content-row">
<Link className="content-row__main" to={href}>
<span className="content-row__date">{formatDate(fachDate(element))}</span>
<span className="content-row__title">{element.title}</span>
<span className="content-row__kind">{kindLabel(element.kind)}</span>
</Link>
{canSort && custom ? (
<span className="content-row__move">
<button type="button" className="quiet" aria-label={`${element.title} nach oben`} disabled={pending || index === 0} onClick={() => move(binding.id, -1)}>Nach oben</button>
<button type="button" className="quiet" aria-label={`${element.title} nach unten`} disabled={pending || index === section.items.length - 1} onClick={() => move(binding.id, 1)}>Nach unten</button>
</span>
) : null}
</li>
);
})}
</ol>
</section>
))
) : (
<p className="muted">Noch keine Unterlage und keine Notiz.</p>
)}
</div>
);
}
export function CourseList({ items }) {
if (!items) return <p className="muted">Verlauf wird geladen …</p>;
if (!items.length) return <p className="muted">Noch kein fachlicher Verlauf.</p>;
return (
<ol className="timeline">
{items.map((item) => (
<li key={item.id}>
<time>{item.dated ? formatDate(item.document_on) : "Ohne Datum"}</time>
<div>
<strong>{item.title}</strong>
<span>{kindLabel(item.kind)}{item.sent_on ? ` · Versand ${formatDate(item.sent_on)}` : ""}{item.received_on ? ` · Zugang ${formatDate(item.received_on)}` : ""}</span>
</div>
</li>
))}
</ol>
);
}
export function RecordTabs({ coursePath, auditPath }) {
const [tab, setTab] = useState("");
const [course, setCourse] = useState(null);
const [audit, setAudit] = useState(null);
const [cursor, setCursor] = useState(null);
const [error, setError] = useState("");
async function showCourse() {
setTab("course");
if (course) return;
setError("");
try {
const data = await api(coursePath);
setCourse(data.items);
} catch (err) {
setError(err.message);
}
}
async function showAudit(nextCursor) {
setTab("audit");
setError("");
try {
const joiner = auditPath.includes("?") ? "&" : "?";
const data = await api(`${auditPath}${nextCursor ? `${joiner}cursor=${encodeURIComponent(nextCursor)}` : ""}`);
setAudit((current) => (nextCursor ? [...(current || []), ...data.items] : data.items));
setCursor(data.next_cursor);
} catch (err) {
setError(err.message);
}
}
return (
<section className="section">
<div className="order-bar">
<button type="button" className={tab === "course" ? "" : "quiet"} onClick={showCourse}>Fachlicher Verlauf</button>
<button type="button" className={tab === "audit" ? "" : "quiet"} onClick={() => showAudit("")}>Änderungsprotokoll</button>
</div>
<ErrorNote error={error} />
{tab === "course" ? <CourseList items={course} /> : null}
{tab === "audit" ? <AuditLog items={audit} nextCursor={cursor} onMore={() => showAudit(cursor)} /> : null}
</section>
);
}
export function AuditLog({ items, nextCursor, onMore }) {
if (!items) return <p className="muted">Protokoll wird geladen …</p>;
if (!items.length) return <p className="muted">Noch kein Eintrag.</p>;
return (
<div className="stack">
<ol className="timeline">
{items.map((item) => (
<li key={item.id}>
<time>{formatStamp(item.occurred_at)}</time>
<div>
<strong>{item.label}</strong>
<span>{item.title}{item.actor_display_name ? ` · ${item.actor_display_name}` : ""}</span>
</div>
</li>
))}
</ol>
{nextCursor ? <button type="button" className="quiet" onClick={onMore}>Weitere Einträge</button> : null}
</div>
);
}