Oeffne Kapitel und Dokument auf derselben Arbeitsflaeche, damit Pfad, Rechte und eigene Reihenfolge beim Lesen erhalten bleiben.
Deploy Development / deploy (push) Successful in 33s
Test Suite / pytest-backend (push) Successful in 56s
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-17 14:19:06 +02:00
1 parent 94ef46d8eb
commit 448e9a06ff
34 files changed
+2998 -696

No files matched your search

+321 -139
View File
@@ -1,12 +1,15 @@
import { useContext, useEffect, useRef, useState } from "react";
import { Link, useNavigate, useParams, useSearchParams } from "react-router-dom";
import { api, markDirty } from "../api.js";
import { api, isDirty, markDirty } from "../api.js";
import { SessionContext } from "../session.js";
import { Modal } from "./Modal.jsx";
import { MailPicker, PaperlessPicker } from "./Sources.jsx";
import { ErrorNote, ShareBox } from "./widgets.jsx";
import { ChapterForm, FileForm, NoteForm } from "./Cases.jsx";
import { ContentBoard, ObjectMenu, Placements, RecordTree, SurfaceView, TargetLine, Trail, WorkLists, WorkSwitch, formatDate, matterOpenHref, writeChapter } from "./content.jsx";
import { ContentBoard, ObjectMenu, Placements, RecordTree, SurfaceView, TargetLine, Trail, WorkLists, WorkSwitch, matterOpenHref, saveChapterOrder, writeChapter } from "./content.jsx";
import { ReadingPane } from "./ReadingPane.jsx";
import { StructureNavigator, Workspace, rememberScroll, restoreScroll, useWorkspaceLayout } from "./workspace.jsx";
import { NavIcon } from "./icons.jsx";
function pageContext(params) {
const kind = params.get("context_kind");
@@ -79,78 +82,99 @@ export function MatterList() {
);
}
function matterTrail(record, chapter, href) {
if (!chapter) return record.trail;
const items = (record.trail || []).map((item, index, all) => (
index === all.length - 1 ? { ...item, href } : item
));
items.push({ label: `Kapitel ${chapter.title}`, href: null });
return items;
function contextQuery(inherited) {
return inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : "";
}
function MatterOutline({ record, inherited, chapterId, onChapter }) {
const matterQuery = inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : "";
const hasParent = Boolean(record.parent_matter_id && record.parent_title);
const hasChildren = Boolean(record.submatters?.length);
const hasCases = Boolean(record.placements?.length);
return (
<nav className="outline-nav" aria-label="Gliederung">
<h2>Gliederung</h2>
<button type="button" className={chapterId ? "hierarchy__row" : "hierarchy__row is-current"} onClick={() => onChapter("")}>
<span className="hierarchy__kind">Überblick</span>
<strong>Alle Inhalte</strong>
</button>
{hasParent ? (
<p className="hierarchy__parent">Übergeordnet: <Link to={`/matters/${record.parent_matter_id}${matterQuery}`}>Vorgang {record.parent_title}</Link></p>
) : null}
{hasCases ? (
<>
<h3>In diesen Akten</h3>
<ul className="hierarchy">
{record.placements.map((link) => (
<li key={link.case_id}>
<Link className="hierarchy__row" to={link.href}>
<span className="hierarchy__kind">Akte</span>
<strong>{link.label.replaceAll("Unterakte ", "").replaceAll("Akte ", "")}</strong>
{link.current ? <span className="muted">aktueller Handlungskontext</span> : null}
</Link>
</li>
))}
</ul>
</>
) : null}
{hasChildren ? (
<>
<h3>Teilvorgänge</h3>
<ul className="hierarchy">
{record.submatters.map((item) => (
<li key={item.id}>
<Link className="hierarchy__row" to={`/matters/${item.id}${matterQuery}`}>
<span className="hierarchy__kind">Teilvorgang</span>
<strong>{item.title}</strong>
</Link>
</li>
))}
</ul>
</>
) : null}
{record.chapters?.length ? (
<>
<h3>Kapitel</h3>
<ul className="hierarchy">
{record.chapters.map((chapter) => (
<li key={chapter.id}>
<button type="button" className={chapterId === chapter.id ? "hierarchy__row is-current" : "hierarchy__row"} onClick={() => onChapter(chapter.id)}>
<span className="hierarchy__kind">Kapitel</span>
<strong>{chapter.title}</strong>
</button>
</li>
))}
</ul>
</>
) : null}
</nav>
);
function mapMatterNodes(nodes, activeId, query) {
return (nodes || []).map((node) => ({
id: node.id,
title: node.title,
kind: node.kind_label || "Vorgang",
href: `/matters/${node.id}${query}`,
current: node.id === activeId,
children: mapMatterNodes(node.children, activeId, query),
}));
}
function caseNodes(caseRecord, parentRecord, activeId, contextId) {
const query = `?context_kind=case&context_id=${contextId}`;
const self = {
id: caseRecord.id,
title: caseRecord.title,
kind: caseRecord.kind_label || "Akte",
href: `/cases/${caseRecord.id}`,
current: false,
children: [
...(caseRecord.subcases || []).map((item) => ({
id: item.id,
title: item.title,
kind: "Unterakte",
href: `/cases/${item.id}`,
current: false,
children: [],
})),
...mapMatterNodes(caseRecord.matters, activeId, query),
],
};
if (!parentRecord) return [self];
const siblings = (parentRecord.subcases || []).map((item) => (item.id === caseRecord.id ? self : {
id: item.id,
title: item.title,
kind: "Unterakte",
href: `/cases/${item.id}`,
current: false,
children: [],
}));
return [{
id: parentRecord.id,
title: parentRecord.title,
kind: "Akte",
href: `/cases/${parentRecord.id}`,
current: false,
children: [
...(siblings.length ? siblings : [self]),
...mapMatterNodes(parentRecord.matters, activeId, `?context_kind=case&context_id=${parentRecord.id}`),
],
}];
}
function loneNodes(record, query) {
const current = {
id: record.id,
title: record.title,
kind: record.kind_label || "Vorgang",
href: null,
current: true,
children: (record.submatters || []).map((item) => ({
id: item.id,
title: item.title,
kind: "Teilvorgang",
href: `/matters/${item.id}${query}`,
current: false,
children: [],
})),
};
if (record.parent_matter_id && record.parent_title) {
return [{
id: record.parent_matter_id,
title: record.parent_title,
kind: "Vorgang",
href: `/matters/${record.parent_matter_id}${query}`,
current: false,
children: [current],
}];
}
return [current];
}
function objectTrail(record, query) {
const items = [{ label: "Vorgänge", href: "/matters" }];
if (record.parent_matter_id && record.parent_title) {
items.push({ label: record.parent_title, href: `/matters/${record.parent_matter_id}${query}` });
}
items.push({ label: record.title, href: null });
return items;
}
export function MatterDetail() {
@@ -164,8 +188,12 @@ export function MatterDetail() {
const rightsContext = inherited || { kind: "matter", id };
const placement = inherited?.kind === "case" ? { kind: "matter", id } : null;
const [view, setView] = useState("contents");
const [outlineOpen, setOutlineOpen] = useState(false);
const { width, structureOpen, setStructureOpen } = useWorkspaceLayout();
const listRef = useRef(null);
const [caseTree, setCaseTree] = useState(null);
const [parentTree, setParentTree] = useState(null);
const pendingChapter = useRef("");
const entryId = params.get("eintrag") || "";
async function load() {
const query = inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : "";
@@ -181,7 +209,7 @@ export function MatterDetail() {
setError("");
setView("contents");
setModal("");
setOutlineOpen(false);
setStructureOpen(false);
const query = inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : "";
api(`/api/v1/matters/${id}${query}`).then((detail) => {
if (!alive) return;
@@ -205,95 +233,249 @@ export function MatterDetail() {
}
}, [record, id, chapterId, params, setParams]);
useEffect(() => {
if (inherited?.kind !== "case") {
setCaseTree(null);
setParentTree(null);
return undefined;
}
let alive = true;
api(`/api/v1/cases/${inherited.id}`).then((detail) => {
if (!alive) return;
setCaseTree(detail);
if (!detail.parent_case_id) {
setParentTree(null);
return;
}
api(`/api/v1/cases/${detail.parent_case_id}`).then((parent) => {
if (alive) setParentTree(parent);
}).catch(() => {
if (alive) setParentTree(null);
});
}).catch(() => {
if (alive) setCaseTree(null);
});
return () => {
alive = false;
};
}, [inherited?.kind, inherited?.id]);
useEffect(() => {
if (!record || record.id !== id || !entryId) return;
const binding = (record.bindings || []).find((item) => item.id === entryId);
if (!binding) return;
const nextChapter = binding.chapter_id || "";
if ((chapterId || "") !== nextChapter) writeChapter(params, setParams, nextChapter);
}, [record, id, entryId, chapterId, params, setParams]);
useEffect(() => {
if (entryId) return;
restoreScroll(listRef.current, `tsumugu-scroll:${id}:${chapterId}`);
}, [entryId, id, chapterId, record]);
function chooseChapter(next) {
writeChapter(params, setParams, next);
const updated = new URLSearchParams(params);
if (next) updated.set("kapitel", next);
else updated.delete("kapitel");
updated.delete("eintrag");
updated.delete("bereich");
setParams(updated);
setView("contents");
setOutlineOpen(false);
setStructureOpen(false);
}
function openEntry(binding) {
rememberScroll(listRef.current, `tsumugu-scroll:${id}:${chapterId}`);
const updated = new URLSearchParams(params);
updated.set("eintrag", binding.id);
if (binding.chapter_id) updated.set("kapitel", binding.chapter_id);
else updated.delete("kapitel");
setParams(updated);
setView("contents");
}
function closeEntry() {
const updated = new URLSearchParams(params);
updated.delete("eintrag");
setParams(updated, { replace: true });
}
function switchContext(caseId) {
if (caseId === (inherited?.id || "")) return;
if (isDirty() && !window.confirm("Ungespeicherte Eingaben verwerfen und den Aktenkontext wechseln?")) return;
const updated = new URLSearchParams();
if (caseId) {
updated.set("context_kind", "case");
updated.set("context_id", caseId);
}
setParams(updated);
setStructureOpen(false);
}
async function moveChapter(chapterIdToMove, delta) {
const ids = (record?.chapters || []).map((chapter) => chapter.id);
const index = ids.indexOf(chapterIdToMove);
const target = index + delta;
if (!record || index < 0 || target < 0 || target >= ids.length) return;
const [moved] = ids.splice(index, 1);
ids.splice(target, 0, moved);
try {
await saveChapterOrder({ containerKind: "matter", containerId: id, record, context: inherited, ids });
await load();
} catch (err) {
setError(err.message);
}
}
if (error && !record) return <main className="page"><ErrorNote error={error} /></main>;
if (!record) return <main className="page"><p className="muted">Vorgang wird geladen …</p></main>;
const query = inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : "";
const query = contextQuery(inherited);
const targetLabel = `${record.kind_label || "Vorgang"} ${record.title}`;
const activeChapter = (record.chapters || []).find((chapter) => chapter.id === chapterId) || null;
const canEdit = Boolean(record.rights?.edit);
const chapters = (record.chapters || []).map((chapter) => ({
...chapter,
count: (record.bindings || []).filter((item) => item.chapter_id === chapter.id).length,
}));
const contexts = (record.placements || []).map((item) => ({
id: item.case_id,
label: item.label.replaceAll("Unterakte ", "").replaceAll("Akte ", "").replaceAll(" → ", " / "),
}));
const contextValue = inherited?.kind === "case" ? inherited.id : (contexts.length === 1 ? contexts[0].id : "");
const nodes = caseTree ? caseNodes(caseTree, parentTree, id, inherited.id) : loneNodes(record, query);
const links = [
...(record.cross_links || []).map((item) => ({
id: `cross-${item.id}`,
title: item.title,
kind: "Querverweis",
href: `/matters/${item.matter_id}${query}`,
})),
...(record.case_links || []).filter((item) => item.case_id !== inherited?.id).map((item) => ({
id: `case-${item.id}`,
title: item.title,
kind: "Weitere Akte",
href: `/cases/${item.case_id}`,
})),
];
const entry = (record.bindings || []).find((item) => item.id === entryId) || null;
const scrollKey = `tsumugu-scroll:${id}:${chapterId}`;
return (
<main className="page">
<header className="page-head">
<>
<Workspace
width={width}
structureOpen={structureOpen}
setStructureOpen={setStructureOpen}
hasEntry={Boolean(entryId)}
listRef={listRef}
nav={(
<StructureNavigator
contexts={contexts.length > 1 && !inherited ? [{ id: "", label: "Keine Akte gewählt" }, ...contexts] : contexts}
contextValue={contextValue}
onContext={contexts.length > 1 ? switchContext : null}
nodes={nodes}
chapters={chapters}
chapterId={chapterId}
allCount={(record.bindings || []).length}
chapterHeading={`Kapitel in ${record.title}`}
onChapter={chooseChapter}
onAddChapter={canEdit ? () => setModal("chapter") : null}
canAddChapter={canEdit}
onMoveChapter={moveChapter}
canReorder={canEdit && chapters.length > 1}
links={links}
onNavigate={() => setStructureOpen(false)}
onClose={width < 1500 ? () => setStructureOpen(false) : null}
/>
)}
reader={entryId ? (
<ReadingPane
binding={entry}
context={rightsContext}
backLabel={activeChapter?.title || "Alle Inhalte"}
onClose={closeEntry}
onReload={load}
canDetach={canEdit}
canDestroy={Boolean(record.is_owner)}
/>
) : null}
>
<header className="workspace-head">
<div>
<Trail items={matterTrail(record, activeChapter, `/matters/${id}${query}`)} />
<Trail items={objectTrail(record, query)} />
<Placements items={record.placements} />
<p className="eyebrow">{record.kind_label || "Vorgang"} · {record.home_scope_name}</p>
<h1>{record.title}</h1>
<p className="muted">{record.status === "open" ? "Offen" : "Geschlossen"}</p>
<div className="title-row">
<h1>{record.title}</h1>
<span className={record.status === "open" ? "status-pill" : "status-pill is-closed"}>{record.status === "open" ? "Offen" : "Geschlossen"}</span>
</div>
</div>
<div className="page-actions">
{canEdit ? <button type="button" onClick={() => setModal("add")}>Inhalt hinzufügen</button> : null}
{width < 1500 ? <button type="button" className="quiet" onClick={() => setStructureOpen(true)}>Struktur</button> : null}
{canEdit ? (
<button type="button" className="desktop-add" onClick={() => setModal("add")}>
<NavIcon name="plus" /> Inhalt hinzufügen
</button>
) : null}
<ObjectMenu view={view} onView={setView}>
{canEdit ? <button type="button" className="quiet" onClick={() => setModal("submatter")}>Teilvorgang anlegen</button> : null}
{canEdit ? <button type="button" className="quiet" onClick={() => setModal("cross")}>Querverweis</button> : null}
{record.rights.share || record.is_owner ? <button type="button" className="quiet" onClick={() => setModal("share")}>Teilen</button> : null}
</ObjectMenu>
{!canEdit ? <p className="muted">In {targetLabel} fehlt das Bearbeitungsrecht.</p> : null}
</div>
</header>
{!canEdit ? <p className="muted">In {targetLabel} fehlt das Bearbeitungsrecht.</p> : null}
<ErrorNote error={error} />
<div className="record-layout">
<aside className={outlineOpen ? "outline is-open" : "outline"}>
<button type="button" className="outline__toggle" onClick={() => setOutlineOpen((open) => !open)}>{outlineOpen ? "Bereiche schließen" : "Bereiche"}</button>
<div className="outline__body">
<MatterOutline record={record} inherited={inherited} chapterId={chapterId} onChapter={chooseChapter} />
</div>
</aside>
<div className="record-main">
<WorkSwitch view={view} onView={setView} />
{view === "contents" ? (
<>
<p className="target-line">
Bearbeitet wird <strong>{targetLabel}</strong>
{activeChapter ? <> · Kapitel <strong>{activeChapter.title}</strong></> : null}
</p>
<ContentBoard
record={record}
context={inherited}
containerKind="matter"
containerId={id}
onlyChapter={chapterId}
onChange={load}
itemHref={(binding) => {
const search = new URLSearchParams(query.replace(/^\?/, ""));
if (chapterId) search.set("kapitel", chapterId);
const next = search.toString();
return `/matters/${id}/items/${binding.id}${next ? `?${next}` : ""}`;
}}
/>
</>
) : null}
{view === "work" ? (
<div className="stack">
{record.rights.edit ? <button type="button" onClick={() => setModal("work")}>Aufgabe oder Frist</button> : null}
<WorkLists record={record} context={inherited} onChange={load} />
</div>
) : null}
{view === "course" || view === "audit" ? (
<SurfaceView view={view} coursePath={`/api/v1/matters/${id}/course${query}`} auditPath={`/api/v1/matters/${id}/chronology${query}`} />
) : null}
{view === "links" ? (
<div className="stack">
<h2>Zuordnungen</h2>
{record.case_links?.length ? record.case_links.map((item) => (
<p key={item.id}><Link to={`/cases/${item.case_id}`}>Akte {item.title}</Link></p>
)) : <p className="muted">Noch keiner Akte zugeordnet.</p>}
{record.cross_links?.length ? record.cross_links.map((item) => (
<p key={item.id}>Querverweis <Link to={matterOpenHref({ id: item.matter_id, contexts: [] })}>{item.title}</Link></p>
)) : <p className="muted">Kein Querverweis.</p>}
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("cross")}>Querverweis</button> : null}
</div>
) : null}
<WorkSwitch view={view} onView={setView} />
{view === "contents" ? (
<ContentBoard
record={record}
context={inherited}
containerKind="matter"
containerId={id}
onlyChapter={chapterId}
selectedId={entryId}
listTitle={activeChapter ? activeChapter.title : "Alle Inhalte"}
onOpen={(binding) => {
rememberScroll(listRef.current, scrollKey);
openEntry(binding);
}}
onChange={load}
itemHref={(binding) => {
const search = new URLSearchParams(query.replace(/^\?/, ""));
search.set("eintrag", binding.id);
if (binding.chapter_id) search.set("kapitel", binding.chapter_id);
return `/matters/${id}?${search}`;
}}
/>
) : null}
{view === "work" ? (
<div className="stack">
{record.rights.edit ? <button type="button" onClick={() => setModal("work")}>Aufgabe oder Frist</button> : null}
<WorkLists record={record} context={inherited} onChange={load} />
</div>
</div>
) : null}
{view === "course" || view === "audit" ? (
<SurfaceView view={view} coursePath={`/api/v1/matters/${id}/course${query}`} auditPath={`/api/v1/matters/${id}/chronology${query}`} />
) : null}
{view === "links" ? (
<div className="stack">
<h2>Zuordnungen</h2>
{record.case_links?.length ? record.case_links.map((item) => (
<p key={item.id}><Link to={`/cases/${item.case_id}`}>Akte {item.title}</Link></p>
)) : <p className="muted">Noch keiner Akte zugeordnet.</p>}
{record.cross_links?.length ? record.cross_links.map((item) => (
<p key={item.id}>Querverweis <Link to={matterOpenHref({ id: item.matter_id, contexts: [] })}>{item.title}</Link></p>
)) : <p className="muted">Kein Querverweis.</p>}
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("cross")}>Querverweis</button> : null}
</div>
) : null}
{canEdit && view === "contents" ? (
<button type="button" className="mobile-add" onClick={() => setModal("add")}>
<NavIcon name="plus" /> Inhalt hinzufügen
</button>
) : null}
</Workspace>
<Modal open={modal === "work"} title="Aufgabe oder Frist" onClose={() => setModal("")}>
<WorkForms matterId={id} context={inherited} tasks={record.tasks} onChange={() => { setModal(""); load(); }} />
</Modal>
@@ -341,7 +523,7 @@ export function MatterDetail() {
<Modal open={modal === "share"} title="Teilen" onClose={() => setModal("")}>
<ShareBox path={`/api/v1/matters/${id}/grants`} grants={record.grants || []} onChange={load} />
</Modal>
</main>
</>
);
}