Jeder Datenraum hat einen Eigentümer, der Verwalter bleibt, den Raum übertragen kann und im Notfall vom Betreiber ersetzt wird. Neue Akten und Vorgänge folgen der Voreinstellung des Raums: Bei "im Raum teilen" lesen Leser sie und bearbeiten Mitglieder und Verwalter; Weitergeben und Löschen bleiben beim Owner, der eine Akte privat stellen oder einzelne Personen ausnehmen kann. Bestehende Akten bleiben privat. Beim ersten weiteren Mitglied zeigt die Oberfläche, was sichtbar wird. Das Löschen von Akte und Vorgang verlangt jetzt den Owner statt nur das Bearbeitungsrecht und schließt damit R-01. Die Rechte der Raumfreigabe gelten nur bei aktivem Raum, aktiver Mitgliedschaft und aktivem Konto. Die lokale Suite läuft mit 128 Tests grün, der Frontend-Build und 19 Node-Tests ebenfalls. Die Oberfläche wurde noch nicht im Browser bedient. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
871 lines
33 KiB
React
871 lines
33 KiB
React
import { useContext, useEffect, useRef, useState } from "react";
|
|
import { Link, useNavigate, useParams, useSearchParams } from "react-router-dom";
|
|
import { api, isDirty, markDirty } from "../api.js";
|
|
import { SessionContext } from "../session.js";
|
|
import { Modal } from "./Modal.jsx";
|
|
import "./Sources.jsx";
|
|
import { SourcePicker, moduleFor, sourceModules } from "../sources/registry.jsx";
|
|
import { ErrorNote, ShareBox } from "./widgets.jsx";
|
|
import { chapterPathLabel, siblingChapterIds, trailWithChapter } from "./chapters.js";
|
|
import { ChapterForm, FileForm, NoteForm } from "./Cases.jsx";
|
|
import { ContentBoard, DateField, 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";
|
|
import { ExportPackage } from "./ExportPackage.jsx";
|
|
import { RoomShare } from "../admin/RoomShare.jsx";
|
|
|
|
function pageContext(params) {
|
|
const kind = params.get("context_kind");
|
|
const id = params.get("context_id");
|
|
if (!kind || !id || kind === "direct") return null;
|
|
return { kind, id };
|
|
}
|
|
|
|
export function MatterList() {
|
|
const { session } = useContext(SessionContext);
|
|
const navigate = useNavigate();
|
|
const [params] = useSearchParams();
|
|
const [items, setItems] = useState(null);
|
|
const [error, setError] = useState("");
|
|
const [creating, setCreating] = useState(params.get("neu") === "1");
|
|
const [title, setTitle] = useState("");
|
|
const [pending, setPending] = useState(false);
|
|
|
|
async function load() {
|
|
const data = await api("/api/v1/matters");
|
|
setItems(data.items);
|
|
}
|
|
|
|
useEffect(() => {
|
|
load().catch((err) => setError(err.message));
|
|
}, [session.scope.id]);
|
|
|
|
return (
|
|
<main className="page">
|
|
<header className="page-head">
|
|
<div>
|
|
<h1>Vorgänge</h1>
|
|
<p className="muted">Ein Vorgang kann eigenständig beginnen und später einer Akte zugeordnet werden.</p>
|
|
</div>
|
|
<button type="button" onClick={() => setCreating(true)}>Vorgang anlegen</button>
|
|
</header>
|
|
<ErrorNote error={error} />
|
|
{items === null ? <p className="muted">Vorgänge werden geladen …</p> : items.length ? (
|
|
<RecordTree
|
|
items={items}
|
|
parentKey="parent_matter_id"
|
|
hrefFor={(item) => matterOpenHref(item)}
|
|
/>
|
|
) : (
|
|
<p className="muted">Noch kein Vorgang.</p>
|
|
)}
|
|
<Modal open={creating} title="Vorgang anlegen" onClose={() => setCreating(false)}>
|
|
<form className="stack compact" onSubmit={async (event) => {
|
|
event.preventDefault();
|
|
if (pending) return;
|
|
setError("");
|
|
setPending(true);
|
|
try {
|
|
const matter = await api("/api/v1/matters", { method: "POST", body: { title, home_scope_id: session.scope.id } });
|
|
markDirty(false);
|
|
setCreating(false);
|
|
navigate(`/matters/${matter.id}`);
|
|
} catch (err) {
|
|
setError(err.message);
|
|
} finally {
|
|
setPending(false);
|
|
}
|
|
}}>
|
|
<label>Titel <input value={title} onChange={(event) => { setTitle(event.target.value); markDirty(true); }} required /></label>
|
|
<button type="submit" disabled={pending}>{pending ? "Wird angelegt …" : "Vorgang anlegen"}</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
</Modal>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
function contextQuery(inherited) {
|
|
return inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : "";
|
|
}
|
|
|
|
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 placementNodes(record) {
|
|
const matter = {
|
|
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}`,
|
|
current: false,
|
|
children: [],
|
|
})),
|
|
};
|
|
const rooted = record.parent_matter_id && record.parent_title ? [{
|
|
id: record.parent_matter_id,
|
|
title: record.parent_title,
|
|
kind: "Vorgang",
|
|
href: `/matters/${record.parent_matter_id}`,
|
|
current: false,
|
|
children: [matter],
|
|
}] : [matter];
|
|
const cases = record.placements || [];
|
|
if (cases.length < 2) return rooted;
|
|
return [
|
|
...rooted,
|
|
...cases.map((item) => ({
|
|
id: item.case_id,
|
|
title: String(item.label || "Akte").replaceAll("Unterakte ", "").replaceAll("Akte ", "").replaceAll(" → ", " / "),
|
|
kind: "Akte",
|
|
href: `/matters/${record.id}?context_kind=case&context_id=${item.case_id}`,
|
|
current: false,
|
|
children: [],
|
|
})),
|
|
];
|
|
}
|
|
|
|
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() {
|
|
const { id } = useParams();
|
|
const navigate = useNavigate();
|
|
const [params, setParams] = useSearchParams();
|
|
const inherited = pageContext(params);
|
|
const chapterId = params.get("kapitel") || "";
|
|
const [record, setRecord] = useState(null);
|
|
const [error, setError] = useState("");
|
|
const [modal, setModal] = useState("");
|
|
const [chapterParentId, setChapterParentId] = useState("");
|
|
const [addChapterId, setAddChapterId] = useState("");
|
|
const rightsContext = inherited || { kind: "matter", id };
|
|
const placement = inherited?.kind === "case" ? { kind: "matter", id } : null;
|
|
const [view, setView] = useState("contents");
|
|
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}` : "";
|
|
const detail = await api(`/api/v1/matters/${id}${query}`);
|
|
pendingChapter.current = "";
|
|
setRecord(detail);
|
|
return detail;
|
|
}
|
|
|
|
async function renameMatter() {
|
|
const title = window.prompt("Vorgangsname", record.title);
|
|
if (!title || title.trim() === record.title) return;
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/matters/${id}`, {
|
|
method: "PATCH",
|
|
body: { expected_version: record.version, title: title.trim(), context: rightsContext },
|
|
});
|
|
load();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
async function archiveMatter() {
|
|
const next = record.status === "closed" ? "open" : "closed";
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/matters/${id}`, {
|
|
method: "PATCH",
|
|
body: { expected_version: record.version, status: next, context: rightsContext },
|
|
});
|
|
load();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
async function deleteMatter() {
|
|
if (!window.confirm("Diesen Vorgang löschen? Teilvorgänge müssen vorher gelöst sein. Inhalte bleiben erhalten.")) return;
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/matters/${id}/delete`, {
|
|
method: "POST",
|
|
body: { expected_version: record.version, context: rightsContext },
|
|
});
|
|
navigate("/matters");
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
setRecord(null);
|
|
setError("");
|
|
setView("contents");
|
|
setModal("");
|
|
setStructureOpen(false);
|
|
const query = inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : "";
|
|
api(`/api/v1/matters/${id}${query}`).then((detail) => {
|
|
if (!alive) return;
|
|
pendingChapter.current = "";
|
|
setRecord(detail);
|
|
}).catch((err) => {
|
|
if (alive) setError(err.message);
|
|
});
|
|
return () => { alive = false; };
|
|
}, [id, inherited?.kind, inherited?.id]);
|
|
|
|
useEffect(() => {
|
|
if (!record || record.id !== id) return;
|
|
const known = (record.chapters || []).some((chapter) => chapter.id === chapterId);
|
|
if (chapterId && !known && pendingChapter.current === chapterId) return;
|
|
if (chapterId && !known) writeChapter(params, setParams, "");
|
|
if (params.get("bereich")) {
|
|
const next = new URLSearchParams(params);
|
|
next.delete("bereich");
|
|
setParams(next, { replace: true });
|
|
}
|
|
}, [record, id, chapterId, params, setParams]);
|
|
|
|
useEffect(() => {
|
|
if (!record || record.id !== id || inherited?.kind === "case") return;
|
|
const placements = record.placements || [];
|
|
if (placements.length !== 1) return;
|
|
const next = new URLSearchParams(params);
|
|
next.set("context_kind", "case");
|
|
next.set("context_id", placements[0].case_id);
|
|
setParams(next, { replace: true });
|
|
}, [record, id, inherited?.kind]);
|
|
|
|
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;
|
|
if ((record.bindings || []).some((item) => item.id === entryId)) return;
|
|
const updated = new URLSearchParams(params);
|
|
updated.delete("eintrag");
|
|
setParams(updated, { replace: true });
|
|
}, [record, id, entryId, params, setParams]);
|
|
|
|
useEffect(() => {
|
|
if (entryId) return;
|
|
restoreScroll(listRef.current, `tsumugu-scroll:${id}:${chapterId}`);
|
|
}, [entryId, id, chapterId, record]);
|
|
|
|
function chooseChapter(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");
|
|
setStructureOpen(false);
|
|
}
|
|
|
|
function openEntry(binding) {
|
|
rememberScroll(listRef.current, `tsumugu-scroll:${id}:${chapterId}`);
|
|
const updated = new URLSearchParams(params);
|
|
updated.set("eintrag", binding.id);
|
|
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);
|
|
}
|
|
|
|
function openChapter(parentId = "") {
|
|
setChapterParentId(parentId || "");
|
|
setModal("chapter");
|
|
}
|
|
|
|
function openAdd(targetChapterId = chapterId) {
|
|
setAddChapterId(targetChapterId || "");
|
|
setModal("add");
|
|
}
|
|
|
|
async function moveChapter(chapterIdToMove, delta) {
|
|
const ids = siblingChapterIds(record?.chapters || [], chapterIdToMove);
|
|
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 = 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: String(item.label || "Akte").replaceAll("Unterakte ", "").replaceAll("Akte ", "").replaceAll(" → ", " / "),
|
|
}));
|
|
const contextValue = inherited?.kind === "case" ? inherited.id : (contexts.length === 1 ? contexts[0].id : "");
|
|
const nodes = caseTree && inherited ? caseNodes(caseTree, parentTree, id, inherited.id) : placementNodes(record);
|
|
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) => inherited?.kind === "case" && 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 (
|
|
<>
|
|
<Workspace
|
|
width={width}
|
|
structureOpen={structureOpen}
|
|
setStructureOpen={setStructureOpen}
|
|
hasEntry={Boolean(entry)}
|
|
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}
|
|
allLabel=""
|
|
allCount={(record.bindings || []).length}
|
|
chapterHeading={`Kapitel in ${record.title}`}
|
|
onChapter={chooseChapter}
|
|
onAddChapter={canEdit ? () => openChapter(chapterId) : null}
|
|
onAddRootChapter={canEdit ? () => openChapter("") : null}
|
|
canAddChapter={canEdit}
|
|
onMoveChapter={moveChapter}
|
|
canReorder={canEdit && chapters.length > 1}
|
|
links={links}
|
|
onNavigate={() => setStructureOpen(false)}
|
|
onClose={width < 1500 ? () => setStructureOpen(false) : null}
|
|
/>
|
|
)}
|
|
reader={entry ? (
|
|
<ReadingPane
|
|
binding={entry}
|
|
context={rightsContext}
|
|
backLabel={activeChapter?.title || "Alle Inhalte"}
|
|
onClose={closeEntry}
|
|
onReload={load}
|
|
canDetach={canEdit}
|
|
canDestroy={Boolean(record.is_owner)}
|
|
onOpenRelated={(elementId) => {
|
|
const found = (record.bindings || []).find((item) => item.element?.id === elementId);
|
|
if (found) openEntry(found);
|
|
}}
|
|
/>
|
|
) : null}
|
|
>
|
|
<div className="workspace-pin">
|
|
<header className="workspace-head">
|
|
<div>
|
|
<Trail items={trailWithChapter(record.trail?.length ? record.trail : objectTrail(record, query), record.chapters, chapterId, `/matters/${id}${query}`)} />
|
|
<Placements items={record.placements} />
|
|
<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">
|
|
{width < 1500 ? <button type="button" className="quiet" onClick={() => setStructureOpen(true)}>Struktur</button> : null}
|
|
{canEdit ? (
|
|
<button type="button" className="desktop-add" onClick={() => openAdd(chapterId)}>
|
|
<NavIcon name="plus" /> Inhalt hinzufügen
|
|
</button>
|
|
) : null}
|
|
<ObjectMenu view={view} onView={setView}>
|
|
<button type="button" className="quiet" onClick={() => setModal("export")}>Übergabepaket</button>
|
|
{canEdit ? <button type="button" className="quiet" onClick={renameMatter}>Umbenennen</button> : null}
|
|
{canEdit ? <button type="button" className="quiet" onClick={archiveMatter}>{record.status === "closed" ? "Wieder öffnen" : "Archivieren"}</button> : null}
|
|
{canEdit ? <button type="button" className="quiet" onClick={() => setModal("move")}>Verschieben</button> : null}
|
|
{canEdit ? <button type="button" className="danger" onClick={deleteMatter}>Löschen</button> : null}
|
|
{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>
|
|
</div>
|
|
</header>
|
|
{!canEdit ? <p className="muted">In {targetLabel} fehlt das Bearbeitungsrecht.</p> : null}
|
|
<ErrorNote error={error} />
|
|
<WorkSwitch view={view} onView={setView} />
|
|
</div>
|
|
{view === "contents" ? (
|
|
<ContentBoard
|
|
record={record}
|
|
context={inherited}
|
|
containerKind="matter"
|
|
containerId={id}
|
|
onlyChapter={chapterId}
|
|
selectedId={entryId}
|
|
listTitle={activeChapter ? chapterPathLabel(record.chapters, activeChapter.id) : "Alle Inhalte"}
|
|
onAddSubchapter={canEdit ? openChapter : null}
|
|
onAddContent={canEdit ? openAdd : null}
|
|
onOpen={(binding) => {
|
|
rememberScroll(listRef.current, scrollKey);
|
|
openEntry(binding);
|
|
}}
|
|
onChange={load}
|
|
itemHref={(binding) => {
|
|
const search = new URLSearchParams(params);
|
|
search.set("eintrag", binding.id);
|
|
const text = search.toString();
|
|
return text ? `/matters/${id}?${text}` : `/matters/${id}`;
|
|
}}
|
|
/>
|
|
) : 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}
|
|
{canEdit && view === "contents" ? (
|
|
<button type="button" className="mobile-add" onClick={() => openAdd(chapterId)}>
|
|
<NavIcon name="plus" /> Inhalt hinzufügen
|
|
</button>
|
|
) : null}
|
|
</Workspace>
|
|
<Modal open={modal === "export"} title="Übergabepaket erstellen" wide onClose={() => setModal("")}>
|
|
<ExportPackage matterId={id} context={rightsContext} onClose={() => setModal("")} />
|
|
</Modal>
|
|
<Modal open={modal === "work"} title="Aufgabe oder Frist" onClose={() => setModal("")}>
|
|
<WorkForms matterId={id} context={inherited} deadlines={record.deadlines || []} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "add"} title={`Hinzufügen in ${targetLabel}`} onClose={() => setModal("")}>
|
|
<TargetLine label={targetLabel} chapters={record.chapters} chapterId={addChapterId} />
|
|
<div className="add-choices">
|
|
<button type="button" onClick={() => openChapter(addChapterId)}>{addChapterId ? "Unterkapitel" : "Kapitel"}</button>
|
|
{addChapterId ? <button type="button" onClick={() => openChapter("")}>Kapitel auf oberster Ebene</button> : null}
|
|
<button type="button" onClick={() => setModal("note")}>Notiz</button>
|
|
<button type="button" onClick={() => setModal("file")}>Datei</button>
|
|
{sourceModules().map((module) => (
|
|
<button key={module.kind} type="button" onClick={() => setModal(`source:${module.kind}`)}>{module.addLabel || module.title}</button>
|
|
))}
|
|
</div>
|
|
</Modal>
|
|
<Modal open={modal === "note"} title="Notiz" onClose={() => setModal("")}>
|
|
<NoteForm context={rightsContext} placement={placement} chapters={record.chapters} initialChapter={addChapterId} targetLabel={targetLabel} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "file"} title="Datei" onClose={() => setModal("")}>
|
|
<FileForm context={rightsContext} placement={placement} chapters={record.chapters} initialChapter={addChapterId} targetLabel={targetLabel} onChange={(finished = true) => { load(); if (finished) setModal(""); }} />
|
|
</Modal>
|
|
<Modal open={modal.startsWith("source:")} title={moduleFor(modal.slice(7))?.title || "Quelle"} wide={Boolean(moduleFor(modal.slice(7))?.wide)} split={Boolean(moduleFor(modal.slice(7))?.wide)} onClose={() => setModal("")}>
|
|
<SourcePicker sourceKind={modal.slice(7)} context={rightsContext} placement={placement} chapterId={addChapterId} chapterTitle={addChapterId ? chapterPathLabel(record.chapters, addChapterId) : ""} targetLabel={targetLabel} onInserted={load} onDone={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "submatter"} title="Teilvorgang anlegen" onClose={() => setModal("")}>
|
|
<SubmatterForm parentId={id} context={inherited} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "cross"} title="Querverweis" onClose={() => setModal("")}>
|
|
<CrossLinkForm matterId={id} context={inherited} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "chapter"} title={chapterParentId ? `Unterkapitel in ${targetLabel}` : `Kapitel in ${targetLabel}`} onClose={() => setModal("")}>
|
|
<ChapterForm
|
|
path={`/api/v1/matters/${id}/chapters${inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : ""}`}
|
|
targetLabel={targetLabel}
|
|
parentChapter={chapterParentId ? { id: chapterParentId, title: chapterPathLabel(record.chapters, chapterParentId) } : null}
|
|
onChange={(created) => {
|
|
setModal("");
|
|
if (created?.id) {
|
|
pendingChapter.current = created.id;
|
|
writeChapter(params, setParams, created.id);
|
|
}
|
|
load();
|
|
}}
|
|
/>
|
|
</Modal>
|
|
<Modal open={modal === "share"} title="Teilen" onClose={() => setModal("")}>
|
|
{record.is_owner ? <RoomShare resource="matters" id={id} onChange={load} /> : null}
|
|
<ShareBox path={`/api/v1/matters/${id}/grants`} grants={record.grants || []} onChange={load} allowSources={Boolean(record.is_owner)} />
|
|
</Modal>
|
|
<Modal open={modal === "move"} title="Vorgang verschieben" onClose={() => setModal("")}>
|
|
<MoveMatter
|
|
matterId={id}
|
|
version={record.version}
|
|
context={rightsContext}
|
|
soleCaseId={(record.placements || []).length === 1 ? record.placements[0].case_id : ""}
|
|
onDone={() => { setModal(""); load(); }}
|
|
/>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|
|
|
|
function MoveMatter({ matterId, version, context, soleCaseId = "", onDone }) {
|
|
const [cases, setCases] = useState([]);
|
|
const [caseId, setCaseId] = useState("");
|
|
const [matters, setMatters] = useState([]);
|
|
const [parentId, setParentId] = useState("");
|
|
const [clearParent, setClearParent] = useState(false);
|
|
const [error, setError] = useState("");
|
|
const [pending, setPending] = useState(false);
|
|
|
|
useEffect(() => {
|
|
api("/api/v1/cases").then((data) => setCases(data.items || data || [])).catch((err) => setError(err.message));
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!caseId) {
|
|
setMatters([]);
|
|
return undefined;
|
|
}
|
|
api(`/api/v1/cases/${caseId}`).then((detail) => {
|
|
const direct = detail.matters || [];
|
|
setMatters(direct.filter((item) => item.id !== matterId));
|
|
}).catch((err) => setError(err.message));
|
|
return undefined;
|
|
}, [caseId, matterId]);
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
if (!caseId && !parentId && !clearParent) {
|
|
setError("Wähle eine Akte oder einen übergeordneten Vorgang.");
|
|
return;
|
|
}
|
|
setPending(true);
|
|
setError("");
|
|
try {
|
|
const fromCase = context?.kind === "case" ? context.id : soleCaseId;
|
|
await api(`/api/v1/matters/${matterId}/move`, {
|
|
method: "POST",
|
|
body: {
|
|
expected_version: version,
|
|
context: fromCase ? { kind: "case", id: fromCase } : context,
|
|
...(caseId ? { case_id: caseId } : {}),
|
|
...(parentId ? { parent_matter_id: parentId } : {}),
|
|
...(clearParent ? { clear_parent: true } : {}),
|
|
},
|
|
});
|
|
onDone();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
} finally {
|
|
setPending(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form className="stack" onSubmit={submit}>
|
|
<label>
|
|
Akte oder Unterakte
|
|
<select value={caseId} onChange={(event) => setCaseId(event.target.value)}>
|
|
<option value="">Akte unverändert lassen</option>
|
|
{cases.map((item) => <option key={item.id} value={item.id}>{item.title}</option>)}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Übergeordneter Vorgang
|
|
<select value={parentId} disabled={!caseId || clearParent} onChange={(event) => setParentId(event.target.value)}>
|
|
<option value="">Kein neuer übergeordneter Vorgang</option>
|
|
{matters.map((item) => <option key={item.id} value={item.id}>{item.title}</option>)}
|
|
</select>
|
|
</label>
|
|
<label className="check">
|
|
<input type="checkbox" checked={clearParent} onChange={(event) => { setClearParent(event.target.checked); if (event.target.checked) setParentId(""); }} />
|
|
Aus dem übergeordneten Vorgang lösen
|
|
</label>
|
|
<button type="submit" disabled={pending}>{pending ? "Wird verschoben …" : "Verschieben"}</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function WorkForms({ matterId, context, deadlines, onChange }) {
|
|
const [taskTitle, setTaskTitle] = useState("");
|
|
const [taskDue, setTaskDue] = useState("");
|
|
const [deadlineId, setDeadlineId] = useState("");
|
|
const [deadlineTitle, setDeadlineTitle] = useState("");
|
|
const [deadlineDue, setDeadlineDue] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
async function addDeadline(event) {
|
|
event.preventDefault();
|
|
setError("");
|
|
try {
|
|
await api("/api/v1/deadlines", {
|
|
method: "POST",
|
|
body: {
|
|
title: deadlineTitle,
|
|
due_on: deadlineDue,
|
|
matter_id: matterId,
|
|
...(context ? { context } : {}),
|
|
},
|
|
});
|
|
setDeadlineTitle("");
|
|
setDeadlineDue("");
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
async function addTask(event) {
|
|
event.preventDefault();
|
|
setError("");
|
|
try {
|
|
const task = await api("/api/v1/tasks", {
|
|
method: "POST",
|
|
body: {
|
|
title: taskTitle,
|
|
matter_id: matterId,
|
|
...(taskDue ? { due_on: taskDue } : {}),
|
|
...(context ? { context } : {}),
|
|
},
|
|
});
|
|
if (deadlineId) {
|
|
await api(`/api/v1/tasks/${task.id}/deadline-links`, {
|
|
method: "POST",
|
|
body: { deadline_id: deadlineId, ...(context ? { context } : {}) },
|
|
});
|
|
}
|
|
setTaskTitle("");
|
|
setTaskDue("");
|
|
setDeadlineId("");
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="forms">
|
|
<form onSubmit={addDeadline} className="stack compact">
|
|
<h3>Frist</h3>
|
|
<input value={deadlineTitle} onChange={(event) => setDeadlineTitle(event.target.value)} placeholder="Maßgeblicher Termin" required />
|
|
<label>Frist <DateField value={deadlineDue} onChange={setDeadlineDue} required /></label>
|
|
<button type="submit">Frist erfassen</button>
|
|
</form>
|
|
<form onSubmit={addTask} className="stack compact">
|
|
<h3>Aufgabe</h3>
|
|
<input value={taskTitle} onChange={(event) => setTaskTitle(event.target.value)} placeholder="Was ist vor der Frist zu tun?" required />
|
|
<label>Arbeitstermin <DateField value={taskDue} onChange={setTaskDue} /></label>
|
|
<label>
|
|
Gehört zur Frist
|
|
<select value={deadlineId} onChange={(event) => setDeadlineId(event.target.value)}>
|
|
<option value="">Ohne Frist</option>
|
|
{deadlines.map((deadline) => (
|
|
<option key={deadline.id} value={deadline.id}>{deadline.title}</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<button type="submit">Aufgabe anlegen</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function CrossLinkForm({ matterId, context, onChange }) {
|
|
const [targets, setTargets] = useState([]);
|
|
const [targetId, setTargetId] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
useEffect(() => {
|
|
api("/api/v1/placement-targets")
|
|
.then((data) => setTargets(data.items.filter((item) => item.kind === "matter" && item.id !== matterId)))
|
|
.catch((err) => setError(err.message));
|
|
}, [matterId]);
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
const target = targets.find((item) => item.id === targetId);
|
|
if (!target) return;
|
|
const via = (target.contexts || []).find((item) => item.kind === "direct") || target.contexts?.[0];
|
|
const targetContext = !via || via.kind === "direct" ? { kind: "matter", id: target.id } : { kind: via.kind, id: via.id };
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/matters/${matterId}/cross-links`, {
|
|
method: "POST",
|
|
body: {
|
|
target_matter_id: target.id,
|
|
target_context: targetContext,
|
|
...(context ? { source_context: context } : {}),
|
|
},
|
|
});
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="stack">
|
|
<label>
|
|
Vorgang
|
|
<select value={targetId} onChange={(event) => setTargetId(event.target.value)} required>
|
|
<option value="">Auswählen</option>
|
|
{targets.map((item) => (
|
|
<option key={item.id} value={item.id}>{item.title}</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<button type="submit" disabled={!targetId}>Verweisen</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function SubmatterForm({ parentId, context, onChange }) {
|
|
const [title, setTitle] = useState("");
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
await api("/api/v1/matters", {
|
|
method: "POST",
|
|
body: { title, parent_matter_id: parentId, ...(context ? { context } : {}) },
|
|
});
|
|
setTitle("");
|
|
onChange();
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="inline">
|
|
<input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Teilvorgang" required />
|
|
<button type="submit">Teilvorgang</button>
|
|
</form>
|
|
);
|
|
}
|