828 lines
34 KiB
React
828 lines
34 KiB
React
import { useContext, useEffect, useRef, useState } from "react";
|
|
import { Link, useParams, useSearchParams } from "react-router-dom";
|
|
import { api, markDirty, textToDocument } 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 { ContentBoard, ObjectMenu, OrderChoice, RecordTree, SurfaceView, TargetLine, Trail, WorkLists, WorkSwitch, selectionOf, withSelection, writeSelection } from "./content.jsx";
|
|
|
|
export function CaseList() {
|
|
const { session } = useContext(SessionContext);
|
|
const [items, setItems] = useState([]);
|
|
const [title, setTitle] = useState("");
|
|
const [roomId, setRoomId] = useState(session.rooms[0]?.id || "");
|
|
const [roomFilter, setRoomFilter] = useState("");
|
|
const [error, setError] = useState("");
|
|
const [creating, setCreating] = useState(false);
|
|
|
|
async function load() {
|
|
const data = await api("/api/v1/cases");
|
|
setItems(data.items);
|
|
}
|
|
|
|
useEffect(() => {
|
|
load().catch((err) => setError(err.message));
|
|
}, [session.scope.id]);
|
|
|
|
async function create(event) {
|
|
event.preventDefault();
|
|
setError("");
|
|
try {
|
|
await api("/api/v1/cases", { method: "POST", body: { title, home_scope_id: roomId } });
|
|
setTitle("");
|
|
markDirty(false);
|
|
setCreating(false);
|
|
await load();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<main className="page">
|
|
<header className="page-head">
|
|
<div>
|
|
<h1>Akten</h1>
|
|
<p className="muted">Eine Akte sammelt die Vorgänge. Der Datenraum an der Akte bestimmt, wer sie sieht.</p>
|
|
</div>
|
|
<button type="button" onClick={() => setCreating(true)}>Akte anlegen</button>
|
|
</header>
|
|
<ErrorNote error={error} />
|
|
<div className="filters">
|
|
<button type="button" className={roomFilter ? "quiet" : ""} onClick={() => setRoomFilter("")}>Alle</button>
|
|
{session.rooms.map((room) => (
|
|
<button key={room.id} type="button" className={roomFilter === room.id ? "" : "quiet"} onClick={() => setRoomFilter(room.id)}>
|
|
{room.name}
|
|
</button>
|
|
))}
|
|
</div>
|
|
{items.filter((item) => !roomFilter || item.home_scope_id === roomFilter).length ? (
|
|
<RecordTree
|
|
items={items.filter((item) => !roomFilter || item.home_scope_id === roomFilter)}
|
|
parentKey="parent_case_id"
|
|
hrefFor={(item) => `/cases/${item.id}`}
|
|
/>
|
|
) : (
|
|
<p className="muted">Noch keine Akte. Lege die erste an.</p>
|
|
)}
|
|
<Modal open={creating} title="Akte anlegen" onClose={() => setCreating(false)}>
|
|
<form onSubmit={create} className="stack">
|
|
<label>
|
|
Titel
|
|
<input
|
|
value={title}
|
|
onChange={(event) => {
|
|
setTitle(event.target.value);
|
|
markDirty(true);
|
|
}}
|
|
placeholder="Zum Beispiel Mietstreit Musterstraße"
|
|
required
|
|
/>
|
|
</label>
|
|
<label>
|
|
Datenraum
|
|
<select value={roomId} onChange={(event) => setRoomId(event.target.value)}>
|
|
{session.rooms.map((room) => (
|
|
<option key={room.id} value={room.id}>{room.name}</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<button type="submit">Akte anlegen</button>
|
|
</form>
|
|
</Modal>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
function OutlineLink({ kind, title, to }) {
|
|
return (
|
|
<Link className="hierarchy__row" to={to}>
|
|
<span className="hierarchy__kind">{kind}</span>
|
|
<strong>{title}</strong>
|
|
</Link>
|
|
);
|
|
}
|
|
|
|
function matterChapters(record, matterId) {
|
|
return (record.contained || []).find((item) => item.matter_id === matterId)?.chapters || [];
|
|
}
|
|
|
|
function ChapterLinks({ chapters, scopeId, scope, chapterId, onChapter }) {
|
|
if (!chapters.length) return null;
|
|
return (
|
|
<ul>
|
|
{chapters.map((chapter) => (
|
|
<li key={chapter.id}>
|
|
<button
|
|
type="button"
|
|
className={scope === scopeId && chapterId === chapter.id ? "hierarchy__row is-current" : "hierarchy__row"}
|
|
onClick={() => onChapter(scopeId, chapter.id)}
|
|
>
|
|
<span className="hierarchy__kind">Kapitel</span>
|
|
<strong>{chapter.title}</strong>
|
|
</button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
);
|
|
}
|
|
|
|
function MatterBranch({ matter, caseId, scope, chapterId, record, onScope, onChapter }) {
|
|
const selected = scope === matter.id && !chapterId;
|
|
return (
|
|
<li>
|
|
<div className="hierarchy__line">
|
|
<button type="button" className={selected ? "hierarchy__row is-current" : "hierarchy__row"} onClick={() => onScope(matter.id)}>
|
|
<span className="hierarchy__kind">{matter.kind_label || "Vorgang"}</span>
|
|
<strong>{matter.title}</strong>
|
|
</button>
|
|
<Link className="hierarchy__open" to={`/matters/${matter.id}?context_kind=case&context_id=${caseId}`}>Öffnen</Link>
|
|
</div>
|
|
<ChapterLinks chapters={matterChapters(record, matter.id)} scopeId={matter.id} scope={scope} chapterId={chapterId} onChapter={onChapter} />
|
|
{matter.children?.length ? (
|
|
<ul>
|
|
{matter.children.map((child) => (
|
|
<MatterBranch key={child.id} matter={child} caseId={caseId} scope={scope} chapterId={chapterId} record={record} onScope={onScope} onChapter={onChapter} />
|
|
))}
|
|
</ul>
|
|
) : null}
|
|
</li>
|
|
);
|
|
}
|
|
|
|
function CaseOutline({ record, caseId, scope, chapterId, onScope, onChapter }) {
|
|
const hasParent = Boolean(record.parent_case_id && record.parent_title);
|
|
return (
|
|
<nav className="outline-nav" aria-label="Gliederung">
|
|
<h2>Gliederung</h2>
|
|
<button type="button" className={scope === "all" ? "hierarchy__row is-current" : "hierarchy__row"} onClick={() => onScope("all")}>
|
|
<span className="hierarchy__kind">Überblick</span>
|
|
<strong>Alle Inhalte</strong>
|
|
</button>
|
|
<button type="button" className={scope === "direct" && !chapterId ? "hierarchy__row is-current" : "hierarchy__row"} onClick={() => onScope("direct")}>
|
|
<span className="hierarchy__kind">Akte</span>
|
|
<strong>Direkt in dieser Akte</strong>
|
|
</button>
|
|
<ChapterLinks chapters={record.chapters || []} scopeId="direct" scope={scope} chapterId={chapterId} onChapter={onChapter} />
|
|
{hasParent ? (
|
|
<p className="hierarchy__parent">Übergeordnet: <Link to={`/cases/${record.parent_case_id}`}>Akte {record.parent_title}</Link></p>
|
|
) : null}
|
|
{record.subcases?.length ? (
|
|
<>
|
|
<h3>Unterakten</h3>
|
|
<ul className="hierarchy">
|
|
{record.subcases.map((item) => (
|
|
<li key={item.id}><OutlineLink kind="Unterakte" title={item.title} to={`/cases/${item.id}`} /></li>
|
|
))}
|
|
</ul>
|
|
</>
|
|
) : null}
|
|
{record.matters?.length ? (
|
|
<>
|
|
<h3>Vorgänge</h3>
|
|
<ul className="hierarchy">
|
|
{record.matters.map((matter) => (
|
|
<MatterBranch key={matter.id} matter={matter} caseId={caseId} scope={scope} chapterId={chapterId} record={record} onScope={onScope} onChapter={onChapter} />
|
|
))}
|
|
</ul>
|
|
</>
|
|
) : null}
|
|
</nav>
|
|
);
|
|
}
|
|
|
|
function matterOrigin(group) {
|
|
const kind = group.kind_label === "Teilvorgang" ? "Teilvorgang" : "Vorgang";
|
|
const parent = group.parent_title ? ` · Vorgang ${group.parent_title}` : "";
|
|
return `Aus ${kind} ${group.title}${parent}`;
|
|
}
|
|
|
|
function chapterOrigin(base, chapters, chapterId) {
|
|
const title = (chapters || []).find((chapter) => chapter.id === chapterId)?.title;
|
|
return title ? `${base} · Kapitel ${title}` : base;
|
|
}
|
|
|
|
function mergedCaseItems(record, direction, caseId) {
|
|
const rows = [
|
|
...(record.bindings || []).map((binding) => ({
|
|
...binding,
|
|
origin: chapterOrigin("Direkt in dieser Akte", record.chapters, binding.chapter_id),
|
|
readerHref: `/cases/${caseId}/items/${binding.id}`,
|
|
})),
|
|
...(record.contained || []).flatMap((group) => (group.bindings || []).map((binding) => ({
|
|
...binding,
|
|
origin: chapterOrigin(matterOrigin(group), group.chapters, binding.chapter_id),
|
|
readerHref: `/matters/${group.matter_id}/items/${binding.id}?context_kind=case&context_id=${caseId}`,
|
|
}))),
|
|
];
|
|
const counts = {};
|
|
for (const row of rows) counts[row.element.id] = (counts[row.element.id] || 0) + 1;
|
|
const marked = rows.map((row) => ({ ...row, shared: counts[row.element.id] > 1 }));
|
|
const dated = marked.filter((row) => row.element.dates?.document_on);
|
|
const undated = marked.filter((row) => !row.element.dates?.document_on);
|
|
dated.sort((a, b) => a.element.dates.document_on.localeCompare(b.element.dates.document_on) || a.id.localeCompare(b.id));
|
|
if (direction === "desc") dated.reverse();
|
|
undated.sort((a, b) => a.id.localeCompare(b.id));
|
|
return [...dated, ...undated];
|
|
}
|
|
|
|
export function CaseDetail() {
|
|
const { id } = useParams();
|
|
const [params, setParams] = useSearchParams();
|
|
const { scope, chapterId } = selectionOf(params);
|
|
const [record, setRecord] = useState(null);
|
|
const [error, setError] = useState("");
|
|
const [modal, setModal] = useState("");
|
|
const [view, setView] = useState("contents");
|
|
const [dateDir, setDateDir] = useState("asc");
|
|
const [outlineOpen, setOutlineOpen] = useState(false);
|
|
const pendingChapter = useRef("");
|
|
const context = { kind: "case", id };
|
|
|
|
async function load() {
|
|
const detail = await api(`/api/v1/cases/${id}`);
|
|
pendingChapter.current = "";
|
|
setRecord(detail);
|
|
return detail;
|
|
}
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
setRecord(null);
|
|
setError("");
|
|
setView("contents");
|
|
setModal("");
|
|
setDateDir("asc");
|
|
setOutlineOpen(false);
|
|
api(`/api/v1/cases/${id}`).then((detail) => {
|
|
if (!alive) return;
|
|
pendingChapter.current = "";
|
|
setRecord(detail);
|
|
}).catch((err) => {
|
|
if (alive) setError(err.message);
|
|
});
|
|
return () => { alive = false; };
|
|
}, [id]);
|
|
|
|
useEffect(() => {
|
|
if (!record || record.id !== id) return;
|
|
const known = new Set(["all", "direct", ...(record.contained || []).map((item) => item.matter_id)]);
|
|
const nextScope = known.has(scope) ? scope : "all";
|
|
const chapters = nextScope === "direct"
|
|
? (record.chapters || [])
|
|
: (record.contained || []).find((item) => item.matter_id === nextScope)?.chapters || [];
|
|
const nextChapter = chapterId && chapters.some((chapter) => chapter.id === chapterId) ? chapterId : "";
|
|
if (chapterId && !nextChapter && pendingChapter.current === chapterId) return;
|
|
if (nextScope !== scope || nextChapter !== chapterId) writeSelection(params, setParams, nextScope, nextChapter);
|
|
}, [record, id, scope, chapterId, params, setParams]);
|
|
|
|
function choose(nextScope, nextChapter = "") {
|
|
writeSelection(params, setParams, nextScope, nextChapter);
|
|
setView("contents");
|
|
setOutlineOpen(false);
|
|
}
|
|
|
|
if (error && !record) return <main className="page"><ErrorNote error={error} /></main>;
|
|
if (!record) return <main className="page"><p className="muted">Akte wird geladen …</p></main>;
|
|
|
|
const group = scope !== "all" && scope !== "direct"
|
|
? (record.contained || []).find((item) => item.matter_id === scope) || null
|
|
: null;
|
|
const target = scope === "direct"
|
|
? {
|
|
scope: "direct",
|
|
label: `Akte ${record.title}`,
|
|
edit: Boolean(record.rights?.edit),
|
|
chapters: record.chapters || [],
|
|
chapterPath: `/api/v1/cases/${id}/chapters`,
|
|
}
|
|
: group
|
|
? {
|
|
scope: group.matter_id,
|
|
label: `${group.kind_label || "Vorgang"} ${group.title}`,
|
|
edit: Boolean(group.rights?.edit),
|
|
chapters: group.chapters || [],
|
|
chapterPath: `/api/v1/matters/${group.matter_id}/chapters?context_kind=case&context_id=${id}`,
|
|
}
|
|
: null;
|
|
const activeChapter = target?.chapters.find((chapter) => chapter.id === chapterId) || null;
|
|
const merged = mergedCaseItems(record, dateDir, id);
|
|
const addPlacement = group ? { kind: "matter", id: group.matter_id } : null;
|
|
|
|
return (
|
|
<main className="page">
|
|
<header className="page-head">
|
|
<div>
|
|
<Trail items={record.trail} />
|
|
<p className="eyebrow">{record.kind_label || "Akte"} · {record.home_scope_name}</p>
|
|
<h1>{record.title}</h1>
|
|
<p className="muted">{record.status === "open" ? "Offen" : "Geschlossen"}</p>
|
|
</div>
|
|
<div className="row">
|
|
{target?.edit ? <button type="button" onClick={() => setModal("add")}>Inhalt hinzufügen</button> : null}
|
|
<ObjectMenu view={view} onView={setView}>
|
|
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("matter")}>Vorgang anlegen und zuordnen</button> : null}
|
|
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("assign")}>Vorhandenen Vorgang zuordnen</button> : null}
|
|
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("subcase")}>Unterakte anlegen</button> : null}
|
|
{target?.edit ? <button type="button" className="quiet" onClick={() => setModal("chapter")}>Kapitel hinzufügen</button> : null}
|
|
{!target ? <p className="muted">Für ein Kapitel zuerst einen Bereich wählen.</p> : null}
|
|
{target && !target.edit ? <p className="muted">In {target.label} fehlt das Bearbeitungsrecht.</p> : null}
|
|
{record.rights.share || record.is_owner ? <button type="button" className="quiet" onClick={() => setModal("share")}>Teilen</button> : null}
|
|
</ObjectMenu>
|
|
</div>
|
|
</header>
|
|
<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">
|
|
<CaseOutline
|
|
record={record}
|
|
caseId={id}
|
|
scope={scope}
|
|
chapterId={chapterId}
|
|
onScope={(next) => choose(next)}
|
|
onChapter={(nextScope, nextChapter) => choose(nextScope, nextChapter)}
|
|
/>
|
|
</div>
|
|
</aside>
|
|
<div className="record-main">
|
|
<WorkSwitch view={view} onView={setView} />
|
|
{view === "contents" ? (
|
|
<p className="target-line">
|
|
{target ? (
|
|
<>Bearbeitet wird <strong>{target.label}</strong>{activeChapter ? <> · Kapitel <strong>{activeChapter.title}</strong></> : null}</>
|
|
) : (
|
|
"Lesesicht aller Inhalte. Zum Bearbeiten einen Bereich in der Gliederung wählen."
|
|
)}
|
|
</p>
|
|
) : null}
|
|
{view === "contents" && scope === "all" ? (
|
|
<div className="stack">
|
|
<OrderChoice mode="date" direction={dateDir} onChange={(_mode, next) => setDateDir(next)} />
|
|
<ContentBoard
|
|
record={{ bindings: merged, chapters: [], content_order: "date", content_order_dir: dateDir, rights: { edit: false }, version: record.version }}
|
|
bindings={merged}
|
|
sortable={false}
|
|
containerKind="case"
|
|
containerId={id}
|
|
onChange={load}
|
|
itemHref={(binding) => binding.readerHref}
|
|
/>
|
|
</div>
|
|
) : null}
|
|
{view === "contents" && scope === "direct" ? (
|
|
<ContentBoard
|
|
record={record}
|
|
containerKind="case"
|
|
containerId={id}
|
|
onlyChapter={chapterId}
|
|
onChange={load}
|
|
itemHref={(binding) => withSelection(`/cases/${id}/items/${binding.id}`, params)}
|
|
/>
|
|
) : null}
|
|
{view === "contents" && group ? (
|
|
<ContentBoard
|
|
record={{ ...group, rights: group.rights, chapters: group.chapters || [] }}
|
|
bindings={group.bindings}
|
|
context={context}
|
|
containerKind="matter"
|
|
containerId={group.matter_id}
|
|
onlyChapter={chapterId}
|
|
onChange={load}
|
|
itemHref={(binding) => withSelection(`/matters/${group.matter_id}/items/${binding.id}?context_kind=case&context_id=${id}`, params)}
|
|
/>
|
|
) : null}
|
|
{view === "contents" && scope !== "all" && scope !== "direct" && !group ? (
|
|
<p className="muted">Dieser Bereich hat in der Akte keine eigenen Unterlagen.</p>
|
|
) : null}
|
|
{view === "work" ? <WorkLists record={record} context={context} onChange={load} /> : null}
|
|
{view === "course" || view === "audit" ? (
|
|
<SurfaceView view={view} coursePath={`/api/v1/cases/${id}/course`} auditPath={`/api/v1/cases/${id}/chronology`} />
|
|
) : null}
|
|
{view === "links" ? (
|
|
<div className="stack">
|
|
<h2>Zuordnungen</h2>
|
|
<p className="muted">Unterakten, Vorgänge und Freigaben dieses Objekts.</p>
|
|
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("matter")}>Vorgang anlegen und zuordnen</button> : null}
|
|
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("assign")}>Vorhandenen Vorgang zuordnen</button> : null}
|
|
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("subcase")}>Unterakte anlegen</button> : null}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
<Modal open={modal === "matter"} title="Vorgang anlegen und zuordnen" onClose={() => setModal("")}>
|
|
<NewMatter caseId={id} homeScopeId={record.home_scope_id} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "assign"} title="Vorhandenen Vorgang zuordnen" onClose={() => setModal("")}>
|
|
<AssignMatter caseId={id} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "add" && Boolean(target)} title={target ? `Hinzufügen in ${target.label}` : "Hinzufügen"} onClose={() => setModal("")}>
|
|
<TargetLine label={target?.label} chapters={target?.chapters} chapterId={activeChapter?.id || ""} />
|
|
<div className="choice">
|
|
<button type="button" onClick={() => setModal("note")}>Notiz</button>
|
|
<button type="button" onClick={() => setModal("file")}>Datei</button>
|
|
<button type="button" onClick={() => setModal("paperless")}>Paperless</button>
|
|
<button type="button" onClick={() => setModal("mail")}>E-Mail</button>
|
|
</div>
|
|
</Modal>
|
|
<Modal open={modal === "note" && Boolean(target)} title="Notiz" onClose={() => setModal("")}>
|
|
<NoteForm context={context} placement={addPlacement} chapters={target?.chapters || []} initialChapter={activeChapter?.id || ""} targetLabel={target?.label || ""} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "file" && Boolean(target)} title="Datei" onClose={() => setModal("")}>
|
|
<FileForm context={context} placement={addPlacement} chapters={target?.chapters || []} initialChapter={activeChapter?.id || ""} targetLabel={target?.label || ""} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "paperless" && Boolean(target)} title="Aus Paperless" onClose={() => setModal("")}>
|
|
<PaperlessPicker context={context} placement={addPlacement} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter?.title || ""} targetLabel={target?.label || ""} onDone={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "mail" && Boolean(target)} title="E-Mail verbinden" wide onClose={() => setModal("")}>
|
|
<MailPicker context={context} placement={addPlacement} chapterId={activeChapter?.id || ""} chapterTitle={activeChapter?.title || ""} targetLabel={target?.label || ""} onDone={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "subcase"} title="Unterakte anlegen" onClose={() => setModal("")}>
|
|
<NewSubcase parentId={id} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "chapter" && Boolean(target)} title={target ? `Kapitel in ${target.label} hinzufügen` : "Kapitel hinzufügen"} onClose={() => setModal("")}>
|
|
<ChapterForm
|
|
path={target?.chapterPath || ""}
|
|
onChange={(created) => {
|
|
setModal("");
|
|
if (created?.id && target) {
|
|
pendingChapter.current = created.id;
|
|
writeSelection(params, setParams, target.scope, created.id);
|
|
}
|
|
load();
|
|
}}
|
|
/>
|
|
</Modal>
|
|
<Modal open={modal === "share"} title="Teilen" onClose={() => setModal("")}>
|
|
<ShareBox path={`/api/v1/cases/${id}/grants`} grants={record.grants || []} onChange={load} />
|
|
</Modal>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
export function ChapterBoard({ chapters, bindings, onOpen }) {
|
|
const loose = bindings.filter((item) => !item.chapter_id);
|
|
return (
|
|
<div className="stack">
|
|
{chapters.map((chapter) => (
|
|
<div key={chapter.id} className="chapter">
|
|
<h3>{chapter.title}</h3>
|
|
<BindingTiles items={bindings.filter((item) => item.chapter_id === chapter.id)} onOpen={onOpen} />
|
|
</div>
|
|
))}
|
|
{loose.length || !chapters.length ? (
|
|
<div className="chapter">
|
|
{chapters.length ? <h3>Ohne Kapitel</h3> : null}
|
|
<BindingTiles
|
|
items={loose}
|
|
onOpen={onOpen}
|
|
empty={chapters.length ? "Außerhalb der Kapitel liegt noch nichts." : "Noch keine Notiz, Datei oder Verknüpfung."}
|
|
/>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function BindingTiles({ items, onOpen, empty }) {
|
|
if (!items.length) return <p className="muted">{empty || "In diesem Kapitel liegt noch nichts."}</p>;
|
|
return (
|
|
<div className="tiles">
|
|
{items.map((binding) => (
|
|
<button key={binding.id} type="button" className="tile" onClick={() => onOpen(binding)}>
|
|
<span className="tile__kind">{sourceKind(binding.element)}</span>
|
|
<strong>{binding.element.title}</strong>
|
|
</button>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function sourceKind(element) {
|
|
if (element.kind === "note") return "Notiz";
|
|
if (element.kind === "file") return "Datei";
|
|
if (element.external?.source === "paperless") return "Paperless";
|
|
if (element.external?.source === "imap") return "E-Mail";
|
|
return "Referenz";
|
|
}
|
|
|
|
function NewMatter({ caseId, homeScopeId, onChange }) {
|
|
const [title, setTitle] = useState("");
|
|
const [error, setError] = useState("");
|
|
const [pending, setPending] = useState(false);
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
if (pending) return;
|
|
setError("");
|
|
setPending(true);
|
|
try {
|
|
const matter = await api("/api/v1/matters", { method: "POST", body: { title, ...(homeScopeId ? { home_scope_id: homeScopeId } : {}) } });
|
|
await api(`/api/v1/matters/${matter.id}/case-links`, { method: "POST", body: { case_id: caseId } });
|
|
setTitle("");
|
|
markDirty(false);
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
} finally {
|
|
setPending(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="stack compact">
|
|
<h3>Vorgang anlegen und zuordnen</h3>
|
|
<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 und zuordnen"}</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function AssignMatter({ caseId, onChange }) {
|
|
const [matters, setMatters] = useState([]);
|
|
const [matterId, setMatterId] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
useEffect(() => {
|
|
api("/api/v1/matters").then((data) => setMatters(data.items)).catch((err) => setError(err.message));
|
|
}, []);
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/matters/${matterId}/case-links`, { method: "POST", body: { case_id: caseId } });
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="stack compact">
|
|
<label>
|
|
Vorhandener Vorgang
|
|
<select value={matterId} onChange={(event) => setMatterId(event.target.value)} required>
|
|
<option value="">Auswählen</option>
|
|
{matters.map((item) => <option key={item.id} value={item.id}>{item.title}</option>)}
|
|
</select>
|
|
</label>
|
|
<button type="submit">Vorhandenen Vorgang zuordnen</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function NewSubcase({ parentId, onChange }) {
|
|
const [title, setTitle] = useState("");
|
|
const [rightsMode, setRightsMode] = useState("inherit_parent");
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
await api("/api/v1/cases", { method: "POST", body: { title, parent_case_id: parentId, rights_mode: rightsMode } });
|
|
setTitle("");
|
|
onChange();
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="stack compact">
|
|
<h3>Unterakte</h3>
|
|
<input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Titel der Unterakte" required />
|
|
<select value={rightsMode} onChange={(event) => setRightsMode(event.target.value)}>
|
|
<option value="inherit_parent">Rechte der Akte übernehmen</option>
|
|
<option value="explicit">Eigene Rechte</option>
|
|
</select>
|
|
<button type="submit">Unterakte anlegen</button>
|
|
</form>
|
|
);
|
|
}
|
|
|
|
export function ChapterForm({ path, onChange }) {
|
|
const [title, setTitle] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
setError("");
|
|
try {
|
|
const created = await api(path, { method: "POST", body: { title } });
|
|
setTitle("");
|
|
onChange(created);
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="inline">
|
|
<input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Kapitel" required />
|
|
<button type="submit">Hinzufügen</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
export function ContentForms({ context, placement, chapters, onChange }) {
|
|
return (
|
|
<div className="forms">
|
|
<NoteForm context={context} placement={placement} chapters={chapters} onChange={onChange} />
|
|
<FileForm context={context} placement={placement} chapters={chapters} onChange={onChange} />
|
|
<ExternalForm context={context} placement={placement} chapters={chapters} onChange={onChange} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function chapterSelect(chapters, value, setValue) {
|
|
if (!chapters?.length) return null;
|
|
return (
|
|
<label>
|
|
Kapitel
|
|
<select value={value} onChange={(event) => setValue(event.target.value)}>
|
|
<option value="">Ohne Kapitel</option>
|
|
{chapters.map((chapter) => (
|
|
<option key={chapter.id} value={chapter.id}>{chapter.title}</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
);
|
|
}
|
|
|
|
export function NoteForm({ context, placement, chapters = [], initialChapter = "", targetLabel = "", onChange }) {
|
|
const [title, setTitle] = useState("");
|
|
const [text, setText] = useState("");
|
|
const [documentOn, setDocumentOn] = useState("");
|
|
const [chapterId, setChapterId] = useState(initialChapter);
|
|
const [error, setError] = useState("");
|
|
const [pending, setPending] = useState(false);
|
|
|
|
useEffect(() => { setChapterId(initialChapter || ""); }, [initialChapter]);
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
if (pending) return;
|
|
setError("");
|
|
setPending(true);
|
|
try {
|
|
await api("/api/v1/notes", {
|
|
method: "POST",
|
|
body: {
|
|
title,
|
|
document: textToDocument(text),
|
|
context,
|
|
...(placement ? { placement } : {}),
|
|
...(chapterId ? { chapter_id: chapterId } : {}),
|
|
...(documentOn ? { dates: { document_on: documentOn } } : {}),
|
|
},
|
|
});
|
|
setTitle("");
|
|
setText("");
|
|
setDocumentOn("");
|
|
markDirty(false);
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
} finally {
|
|
setPending(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="stack compact">
|
|
<TargetLine label={targetLabel} chapters={chapters} chapterId={chapterId} />
|
|
<h3>Notiz</h3>
|
|
<label>Titel <input value={title} onChange={(event) => { setTitle(event.target.value); markDirty(true); }} required /></label>
|
|
<label>Gemeinsamer Text <textarea rows={4} value={text} onChange={(event) => { setText(event.target.value); markDirty(true); }} /></label>
|
|
<label>Bezugsdatum, optional <input type="date" value={documentOn} onChange={(event) => setDocumentOn(event.target.value)} /></label>
|
|
{chapterSelect(chapters, chapterId, setChapterId)}
|
|
<button type="submit" disabled={pending}>{pending ? "Wird angelegt …" : "Notiz anlegen"}</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
export function FileForm({ context, placement, chapters = [], initialChapter = "", targetLabel = "", onChange }) {
|
|
const [title, setTitle] = useState("");
|
|
const [file, setFile] = useState(null);
|
|
const [chapterId, setChapterId] = useState(initialChapter);
|
|
const [documentOn, setDocumentOn] = useState("");
|
|
const [sentOn, setSentOn] = useState("");
|
|
const [receivedOn, setReceivedOn] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
useEffect(() => { setChapterId(initialChapter || ""); }, [initialChapter]);
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
if (!file) return;
|
|
const form = new FormData();
|
|
form.set("title", title);
|
|
form.set("upload", file);
|
|
form.set("context_kind", context.kind);
|
|
form.set("context_id", context.id);
|
|
if (placement) {
|
|
form.set("placement_kind", placement.kind);
|
|
form.set("placement_id", placement.id);
|
|
}
|
|
if (chapterId) form.set("chapter_id", chapterId);
|
|
if (documentOn) form.set("document_on", documentOn);
|
|
if (sentOn) form.set("sent_on", sentOn);
|
|
if (receivedOn) form.set("received_on", receivedOn);
|
|
setError("");
|
|
try {
|
|
await api("/api/v1/files", { method: "POST", form });
|
|
setTitle("");
|
|
setFile(null);
|
|
markDirty(false);
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="stack compact">
|
|
<TargetLine label={targetLabel} chapters={chapters} chapterId={chapterId} />
|
|
<h3>Datei</h3>
|
|
<input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Titel des Schreibens" required />
|
|
<input type="file" accept="application/pdf,image/png,image/jpeg,image/webp" onChange={(event) => setFile(event.target.files?.[0] || null)} required />
|
|
<label>Dokumentdatum <input type="date" value={documentOn} onChange={(event) => setDocumentOn(event.target.value)} /></label>
|
|
<label>Versand <input type="date" value={sentOn} onChange={(event) => setSentOn(event.target.value)} /></label>
|
|
<label>Zugang <input type="date" value={receivedOn} onChange={(event) => setReceivedOn(event.target.value)} /></label>
|
|
{chapterSelect(chapters, chapterId, setChapterId)}
|
|
<button type="submit">Datei hinzufügen</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function ExternalForm({ context, placement, chapters = [], initialChapter = "", targetLabel = "", onChange }) {
|
|
const [title, setTitle] = useState("");
|
|
const [externalId, setExternalId] = useState("");
|
|
const [source, setSource] = useState("paperless");
|
|
const [chapterId, setChapterId] = useState(initialChapter);
|
|
const [documentOn, setDocumentOn] = useState("");
|
|
const [sentOn, setSentOn] = useState("");
|
|
const [receivedOn, setReceivedOn] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
useEffect(() => { setChapterId(initialChapter || ""); }, [initialChapter]);
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
setError("");
|
|
try {
|
|
await api("/api/v1/external-refs", {
|
|
method: "POST",
|
|
body: {
|
|
title,
|
|
source,
|
|
external_id: externalId,
|
|
context,
|
|
...(placement ? { placement } : {}),
|
|
...(chapterId ? { chapter_id: chapterId } : {}),
|
|
dates: {
|
|
document_on: documentOn || null,
|
|
sent_on: sentOn || null,
|
|
received_on: receivedOn || null,
|
|
},
|
|
},
|
|
});
|
|
setTitle("");
|
|
setExternalId("");
|
|
onChange();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="stack compact">
|
|
<TargetLine label={targetLabel} chapters={chapters} chapterId={chapterId} />
|
|
<h3>Paperless oder andere Referenz</h3>
|
|
<input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Anzeigetitel" required />
|
|
<select value={source} onChange={(event) => setSource(event.target.value)}>
|
|
<option value="paperless">Paperless</option>
|
|
<option value="url">Andere Quelle</option>
|
|
</select>
|
|
<input value={externalId} onChange={(event) => setExternalId(event.target.value)} placeholder="Externe ID" required />
|
|
<label>Dokumentdatum <input type="date" value={documentOn} onChange={(event) => setDocumentOn(event.target.value)} /></label>
|
|
<label>Versand <input type="date" value={sentOn} onChange={(event) => setSentOn(event.target.value)} /></label>
|
|
<label>Zugang <input type="date" value={receivedOn} onChange={(event) => setReceivedOn(event.target.value)} /></label>
|
|
{chapterSelect(chapters, chapterId, setChapterId)}
|
|
<button type="submit">Referenz erfassen</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function rightsText(rights) {
|
|
const parts = ["Lesen"];
|
|
if (rights.edit) parts.push("Bearbeiten");
|
|
if (rights.share) parts.push("Weitergeben");
|
|
if (rights.delete) parts.push("Löschen");
|
|
return parts.join(", ") + ".";
|
|
}
|