1222 lines
48 KiB
React
1222 lines
48 KiB
React
import { useContext, useEffect, useRef, useState } from "react";
|
|
import { Link, useNavigate, useParams, useSearchParams } from "react-router-dom";
|
|
import { api, markDirty, textToDocument } from "../api.js";
|
|
import { SessionContext } from "../session.js";
|
|
import { chapterPathLabel, siblingChapterIds, trailWithChapter } from "./chapters.js";
|
|
import { Modal } from "./Modal.jsx";
|
|
import "./Sources.jsx";
|
|
import { SourcePicker, moduleFor, sourceModules } from "../sources/registry.jsx";
|
|
import { ErrorNote, ShareBox } from "./widgets.jsx";
|
|
import { ContentBoard, DateField, DirectionChoice, MarkdownEditor, ObjectMenu, OrderChoice, RecordTree, SurfaceView, TargetLine, Trail, WorkLists, WorkSwitch, saveChapterOrder, writeSelection } from "./content.jsx";
|
|
import { ReadingPane } from "./ReadingPane.jsx";
|
|
import { StructureNavigator, Workspace, rememberScroll, restoreScroll, useWorkspaceLayout } from "./workspace.jsx";
|
|
import { NavIcon } from "./icons.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 path = chapterPathLabel(chapters, chapterId);
|
|
return path ? `${base} · ${path}` : base;
|
|
}
|
|
|
|
function mergedCaseItems(record, direction, caseId) {
|
|
const rows = [
|
|
...(record.bindings || []).filter((binding) => binding?.element).map((binding) => ({
|
|
...binding,
|
|
origin: chapterOrigin("Direkt in dieser Akte", record.chapters, binding.chapter_id),
|
|
readerHref: `/cases/${caseId}?eintrag=${binding.id}${binding.chapter_id ? `&kapitel=${binding.chapter_id}` : ""}`,
|
|
})),
|
|
...(record.contained || []).flatMap((group) => (group.bindings || []).filter((binding) => binding?.element).map((binding) => ({
|
|
...binding,
|
|
origin: chapterOrigin(matterOrigin(group), group.chapters, binding.chapter_id),
|
|
readerHref: `/matters/${group.matter_id}?context_kind=case&context_id=${caseId}&eintrag=${binding.id}${binding.chapter_id ? `&kapitel=${binding.chapter_id}` : ""}`,
|
|
}))),
|
|
];
|
|
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];
|
|
}
|
|
|
|
function matterNode(matter, caseId) {
|
|
const query = `?context_kind=case&context_id=${caseId}`;
|
|
return {
|
|
id: matter.id,
|
|
title: matter.title,
|
|
kind: matter.kind_label || "Vorgang",
|
|
href: `/matters/${matter.id}${query}`,
|
|
current: false,
|
|
children: (matter.children || []).map((child) => matterNode(child, caseId)),
|
|
};
|
|
}
|
|
|
|
function caseNodes(record, parentRecord) {
|
|
const self = {
|
|
id: record.id,
|
|
title: record.title,
|
|
kind: record.kind_label || "Akte",
|
|
href: null,
|
|
current: true,
|
|
children: [
|
|
...(record.subcases || []).map((item) => ({
|
|
id: item.id,
|
|
title: item.title,
|
|
kind: "Unterakte",
|
|
href: `/cases/${item.id}`,
|
|
current: false,
|
|
children: [],
|
|
})),
|
|
...(record.matters || []).map((matter) => matterNode(matter, record.id)),
|
|
],
|
|
};
|
|
if (!parentRecord) return [self];
|
|
const siblings = (parentRecord.subcases || []).map((item) => (item.id === record.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]),
|
|
...(parentRecord.matters || []).map((matter) => matterNode(matter, parentRecord.id)),
|
|
],
|
|
}];
|
|
}
|
|
|
|
export function CaseDetail() {
|
|
const { id } = useParams();
|
|
const navigate = useNavigate();
|
|
const [params, setParams] = useSearchParams();
|
|
const rawScope = params.get("bereich") || "";
|
|
const overview = rawScope === "all" || rawScope === "ueberblick";
|
|
const chapterId = overview ? "" : (params.get("kapitel") || "");
|
|
const entryId = params.get("eintrag") || "";
|
|
const [record, setRecord] = useState(null);
|
|
const [parentTree, setParentTree] = useState(null);
|
|
const [error, setError] = useState("");
|
|
const [modal, setModal] = useState("");
|
|
const [chapterParentId, setChapterParentId] = useState("");
|
|
const [addChapterId, setAddChapterId] = useState("");
|
|
const [view, setView] = useState("contents");
|
|
const [dateDir, setDateDir] = useState("asc");
|
|
const { width, structureOpen, setStructureOpen } = useWorkspaceLayout();
|
|
const listRef = useRef(null);
|
|
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;
|
|
}
|
|
|
|
async function renameCase() {
|
|
const title = window.prompt("Aktenname", record.title);
|
|
if (!title || title.trim() === record.title) return;
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/cases/${id}`, { method: "PATCH", body: { expected_version: record.version, title: title.trim() } });
|
|
load();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
async function archiveCase() {
|
|
const next = record.status === "closed" ? "open" : "closed";
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/cases/${id}`, { method: "PATCH", body: { expected_version: record.version, status: next } });
|
|
load();
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
async function deleteCase() {
|
|
if (!window.confirm("Diese Akte löschen? Unterakten und zugeordnete Vorgänge müssen vorher gelöst sein. Inhalte bleiben erhalten.")) return;
|
|
setError("");
|
|
try {
|
|
await api(`/api/v1/cases/${id}/delete`, { method: "POST", body: { expected_version: record.version } });
|
|
navigate("/cases");
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
let alive = true;
|
|
setRecord(null);
|
|
setError("");
|
|
setView("contents");
|
|
setModal("");
|
|
setDateDir("asc");
|
|
setStructureOpen(false);
|
|
setParentTree(null);
|
|
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 || !record.parent_case_id) return undefined;
|
|
let alive = true;
|
|
api(`/api/v1/cases/${record.parent_case_id}`).then((parent) => {
|
|
if (alive) setParentTree(parent);
|
|
}).catch(() => {
|
|
if (alive) setParentTree(null);
|
|
});
|
|
return () => {
|
|
alive = false;
|
|
};
|
|
}, [record, id]);
|
|
|
|
useEffect(() => {
|
|
if (!record || record.id !== id) return;
|
|
const matterId = rawScope && !["all", "ueberblick", "direkt", "direct"].includes(rawScope) ? rawScope : "";
|
|
if (matterId && (record.contained || []).some((item) => item.matter_id === matterId)) {
|
|
const next = new URLSearchParams();
|
|
next.set("context_kind", "case");
|
|
next.set("context_id", id);
|
|
const chapter = params.get("kapitel");
|
|
if (chapter) next.set("kapitel", chapter);
|
|
navigate(`/matters/${matterId}?${next.toString()}`, { replace: true });
|
|
return;
|
|
}
|
|
if (!overview && chapterId && !(record.chapters || []).some((chapter) => chapter.id === chapterId)) {
|
|
if (pendingChapter.current === chapterId) return;
|
|
writeSelection(params, setParams, "direct", "");
|
|
}
|
|
}, [record, id, rawScope, overview, chapterId, params, setParams, navigate]);
|
|
|
|
useEffect(() => {
|
|
if (!record || record.id !== id || overview || !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, overview, entryId, params, setParams]);
|
|
|
|
useEffect(() => {
|
|
if (entryId) return;
|
|
restoreScroll(listRef.current, `tsumugu-scroll:case:${id}:${chapterId}:${overview ? "over" : "direct"}`);
|
|
}, [entryId, id, chapterId, overview, record]);
|
|
|
|
function chooseChapter(next) {
|
|
const updated = new URLSearchParams(params);
|
|
updated.delete("bereich");
|
|
updated.delete("eintrag");
|
|
if (next) updated.set("kapitel", next);
|
|
else updated.delete("kapitel");
|
|
setParams(updated);
|
|
setView("contents");
|
|
setStructureOpen(false);
|
|
}
|
|
|
|
function showOverview() {
|
|
const updated = new URLSearchParams(params);
|
|
updated.set("bereich", "ueberblick");
|
|
updated.delete("kapitel");
|
|
updated.delete("eintrag");
|
|
setParams(updated);
|
|
setView("contents");
|
|
setStructureOpen(false);
|
|
}
|
|
|
|
function openEntry(binding) {
|
|
rememberScroll(listRef.current, `tsumugu-scroll:case:${id}:${chapterId}:direct`);
|
|
const updated = new URLSearchParams(params);
|
|
updated.delete("bereich");
|
|
updated.set("eintrag", binding.id);
|
|
setParams(updated);
|
|
setView("contents");
|
|
}
|
|
|
|
function closeEntry() {
|
|
const updated = new URLSearchParams(params);
|
|
updated.delete("eintrag");
|
|
setParams(updated, { replace: true });
|
|
}
|
|
|
|
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: "case", containerId: id, record, 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">Akte wird geladen …</p></main>;
|
|
|
|
const canEdit = Boolean(record.rights?.edit);
|
|
const targetLabel = `${record.kind_label || "Akte"} ${record.title}`;
|
|
const activeChapter = (record.chapters || []).find((chapter) => chapter.id === chapterId) || null;
|
|
const chapters = (record.chapters || []).map((chapter) => ({
|
|
...chapter,
|
|
count: (record.bindings || []).filter((item) => item.chapter_id === chapter.id).length,
|
|
}));
|
|
const merged = mergedCaseItems(record, dateDir, id);
|
|
const contexts = [
|
|
...(parentTree ? [{ id: parentTree.id, label: parentTree.title }] : []),
|
|
{ id: record.id, label: record.title },
|
|
];
|
|
const entry = overview ? null : ((record.bindings || []).find((item) => item.id === entryId) || null);
|
|
const hasContained = Boolean(record.contained?.length);
|
|
|
|
return (
|
|
<>
|
|
<Workspace
|
|
width={width}
|
|
structureOpen={structureOpen}
|
|
setStructureOpen={setStructureOpen}
|
|
hasEntry={Boolean(entry) && !overview}
|
|
listRef={listRef}
|
|
nav={(
|
|
<StructureNavigator
|
|
contexts={contexts}
|
|
contextValue={id}
|
|
onContext={parentTree ? ((next) => { if (next !== id) navigate(`/cases/${next}`); }) : null}
|
|
nodes={caseNodes(record, parentTree)}
|
|
allLabel="Direkt in dieser Akte"
|
|
chapters={chapters}
|
|
chapterId={overview ? "" : chapterId}
|
|
allCount={(record.bindings || []).length}
|
|
overview={hasContained ? { active: overview, count: merged.length, onSelect: showOverview } : null}
|
|
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={[]}
|
|
onNavigate={() => setStructureOpen(false)}
|
|
onClose={width < 1500 ? () => setStructureOpen(false) : null}
|
|
/>
|
|
)}
|
|
reader={entry ? (
|
|
<ReadingPane
|
|
binding={entry}
|
|
context={context}
|
|
backLabel={activeChapter?.title || "Direkt in dieser Akte"}
|
|
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}
|
|
>
|
|
<header className="workspace-head">
|
|
<div>
|
|
<Trail items={trailWithChapter(record.trail, record.chapters, overview ? "" : chapterId, `/cases/${id}`)} />
|
|
<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}>
|
|
{record.rights.edit ? <button type="button" className="quiet" onClick={renameCase}>Umbenennen</button> : null}
|
|
{record.rights.edit ? <button type="button" className="quiet" onClick={archiveCase}>{record.status === "closed" ? "Wieder öffnen" : "Archivieren"}</button> : null}
|
|
{record.rights.edit ? <button type="button" className="danger" onClick={deleteCase}>Löschen</button> : null}
|
|
{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}
|
|
{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} />
|
|
{view === "contents" && overview ? (
|
|
<div className="stack">
|
|
<p className="muted">Überblick über direkte Inhalte und Inhalte der zugeordneten Vorgänge. Herkunft steht an jeder Zeile. Neue Inhalte und die eigene Reihenfolge gelten in der Akte oder im geöffneten Vorgang.</p>
|
|
<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}
|
|
listTitle="Überblick"
|
|
containerKind="case"
|
|
containerId={id}
|
|
onChange={load}
|
|
itemHref={(binding) => binding.readerHref}
|
|
/>
|
|
</div>
|
|
) : null}
|
|
{view === "contents" && !overview ? (
|
|
<ContentBoard
|
|
record={record}
|
|
containerKind="case"
|
|
containerId={id}
|
|
onlyChapter={chapterId}
|
|
selectedId={entryId}
|
|
listTitle={activeChapter ? chapterPathLabel(record.chapters, activeChapter.id) : "Direkt in dieser Akte"}
|
|
onAddSubchapter={canEdit ? openChapter : null}
|
|
onAddContent={canEdit ? openAdd : null}
|
|
context={context}
|
|
onOpen={openEntry}
|
|
onChange={load}
|
|
itemHref={(binding) => {
|
|
const search = new URLSearchParams(params);
|
|
search.delete("bereich");
|
|
search.set("eintrag", binding.id);
|
|
const text = search.toString();
|
|
return text ? `/cases/${id}?${text}` : `/cases/${id}`;
|
|
}}
|
|
/>
|
|
) : 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}
|
|
{canEdit && view === "contents" && !overview ? (
|
|
<button type="button" className="mobile-add" onClick={() => openAdd(chapterId)}>
|
|
<NavIcon name="plus" /> Inhalt hinzufügen
|
|
</button>
|
|
) : null}
|
|
</Workspace>
|
|
<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"} title={`Hinzufügen in ${targetLabel}`} onClose={() => setModal("")}>
|
|
<p className="muted">Dieser Inhalt liegt direkt in der Akte. Er erscheint unter „Direkt in dieser Akte“ und im Überblick, nicht in einem Vorgang.</p>
|
|
<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={context} chapters={record.chapters} initialChapter={addChapterId} targetLabel={targetLabel} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "file"} title="Datei" onClose={() => setModal("")}>
|
|
<FileForm context={context} 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={context} chapterId={addChapterId} chapterTitle={addChapterId ? chapterPathLabel(record.chapters, addChapterId) : ""} targetLabel={targetLabel} onInserted={load} onDone={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "subcase"} title="Unterakte anlegen" onClose={() => setModal("")}>
|
|
<NewSubcase parentId={id} onChange={() => { setModal(""); load(); }} />
|
|
</Modal>
|
|
<Modal open={modal === "chapter"} title={chapterParentId ? `Unterkapitel in ${targetLabel}` : `Kapitel in ${targetLabel}`} onClose={() => setModal("")}>
|
|
<ChapterForm
|
|
path={`/api/v1/cases/${id}/chapters`}
|
|
targetLabel={targetLabel}
|
|
parentChapter={chapterParentId ? { id: chapterParentId, title: chapterPathLabel(record.chapters, chapterParentId) } : null}
|
|
onChange={(created) => {
|
|
setModal("");
|
|
if (created?.id) {
|
|
pendingChapter.current = created.id;
|
|
writeSelection(params, setParams, "direct", created.id);
|
|
}
|
|
load();
|
|
}}
|
|
/>
|
|
</Modal>
|
|
<Modal open={modal === "share"} title="Teilen" onClose={() => setModal("")}>
|
|
<ShareBox path={`/api/v1/cases/${id}/grants`} grants={record.grants || []} onChange={load} allowSources={Boolean(record.is_owner)} />
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|
|
|
|
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) return moduleFor(element.external.source)?.addLabel || moduleFor(element.external.source)?.title || "Referenz";
|
|
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>
|
|
);
|
|
}
|
|
|
|
function caseTrail(record, caseId, group, scope, chapter) {
|
|
const extended = Boolean(group) || (scope === "direct" && chapter);
|
|
const items = (record.trail || []).map((item, index, all) => (
|
|
extended && index === all.length - 1 ? { ...item, href: `/cases/${caseId}` } : item
|
|
));
|
|
if (group) {
|
|
items.push({
|
|
label: `${group.kind_label || "Vorgang"} ${group.title}`,
|
|
href: chapter ? `/cases/${caseId}?bereich=${group.matter_id}` : null,
|
|
});
|
|
}
|
|
if (chapter && (group || scope === "direct")) items.push({ label: chapter.title, href: null });
|
|
return items;
|
|
}
|
|
|
|
export function ChapterForm({ path, onChange, targetLabel = "", parentChapter = null }) {
|
|
const [title, setTitle] = useState("");
|
|
const [dated, setDated] = useState("");
|
|
const [error, setError] = useState("");
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
setError("");
|
|
try {
|
|
const created = await api(path, {
|
|
method: "POST",
|
|
body: {
|
|
title,
|
|
...(dated ? { document_on: dated } : {}),
|
|
...(parentChapter?.id ? { parent_chapter_id: parentChapter.id } : {}),
|
|
},
|
|
});
|
|
setTitle("");
|
|
setDated("");
|
|
onChange(created);
|
|
} catch (err) {
|
|
setError(err.message);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={submit} className="stack compact">
|
|
{targetLabel ? <p className="target-line">Ziel: <strong>{targetLabel}</strong></p> : null}
|
|
<p className="target-line">
|
|
{parentChapter ? <>Elternkapitel: <strong>{parentChapter.title}</strong></> : <>Ebene: <strong>oberste Kapitel</strong></>}
|
|
</p>
|
|
<label>Titel <input value={title} onChange={(event) => setTitle(event.target.value)} placeholder={parentChapter ? "Unterkapitel" : "Kapitel"} required /></label>
|
|
<label>Fachliches Datum, optional <DateField value={dated} onChange={setDated} /></label>
|
|
<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, disabled = false) {
|
|
if (!chapters?.length) return null;
|
|
return (
|
|
<label>
|
|
Kapitel
|
|
<select value={value} disabled={disabled} onChange={(event) => setValue(event.target.value)}>
|
|
<option value="">Ohne Kapitel</option>
|
|
{chapters.map((chapter) => (
|
|
<option key={chapter.id} value={chapter.id}>{chapterPathLabel(chapters, chapter.id)}</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
);
|
|
}
|
|
|
|
function titleFromFilename(name) {
|
|
const trimmed = (name || "").trim();
|
|
const stem = trimmed.replace(/\.[^.]+$/, "").trim();
|
|
return (stem || trimmed || "Datei").slice(0, 200);
|
|
}
|
|
|
|
export function NoteForm({ context, placement, chapters = [], initialChapter = "", targetLabel = "", onChange }) {
|
|
const [title, setTitle] = useState("");
|
|
const [text, setText] = useState("");
|
|
const [documentOn, setDocumentOn] = useState("");
|
|
const [sentOn, setSentOn] = useState("");
|
|
const [receivedOn, setReceivedOn] = useState("");
|
|
const [direction, setDirection] = 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 || sentOn || receivedOn ? {
|
|
dates: {
|
|
document_on: documentOn || null,
|
|
sent_on: sentOn || null,
|
|
received_on: receivedOn || null,
|
|
},
|
|
} : {}),
|
|
...(direction ? { communication_direction: direction } : {}),
|
|
},
|
|
});
|
|
setTitle("");
|
|
setText("");
|
|
setDocumentOn("");
|
|
setSentOn("");
|
|
setReceivedOn("");
|
|
setDirection("");
|
|
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>
|
|
<MarkdownEditor value={text} onChange={(value) => { setText(value); markDirty(true); }} rows={8} />
|
|
<DirectionChoice value={direction} onChange={(value) => { setDirection(value); markDirty(true); }} />
|
|
<label>Bezugsdatum, optional <DateField value={documentOn} onChange={setDocumentOn} /></label>
|
|
<label>Versand, optional <DateField value={sentOn} onChange={setSentOn} /></label>
|
|
<label>Zugang, optional <DateField value={receivedOn} onChange={setReceivedOn} /></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 [files, setFiles] = useState([]);
|
|
const [chapterId, setChapterId] = useState(initialChapter);
|
|
const [documentOn, setDocumentOn] = useState("");
|
|
const [sentOn, setSentOn] = useState("");
|
|
const [receivedOn, setReceivedOn] = useState("");
|
|
const [direction, setDirection] = useState("");
|
|
const [error, setError] = useState("");
|
|
const [pending, setPending] = useState(false);
|
|
const [progress, setProgress] = useState(null);
|
|
const inputRef = useRef(null);
|
|
const fileSerial = useRef(0);
|
|
|
|
useEffect(() => { setChapterId(initialChapter || ""); }, [initialChapter]);
|
|
|
|
function nextFileKey() {
|
|
fileSerial.current += 1;
|
|
return `datei-${fileSerial.current}`;
|
|
}
|
|
|
|
function chooseFiles(list) {
|
|
const picked = Array.from(list || []);
|
|
if (inputRef.current) inputRef.current.value = "";
|
|
if (!picked.length) return;
|
|
const carried = title.trim().slice(0, 200);
|
|
const additions = picked.map((file) => ({
|
|
key: nextFileKey(),
|
|
file,
|
|
title: titleFromFilename(file.name),
|
|
}));
|
|
setFiles((current) => {
|
|
const batch = current.length === 0 && carried
|
|
? [{ ...additions[0], title: carried }, ...additions.slice(1)]
|
|
: additions;
|
|
return [...current, ...batch];
|
|
});
|
|
markDirty(true);
|
|
}
|
|
|
|
function setSingleTitle(value) {
|
|
markDirty(true);
|
|
if (files.length === 1) {
|
|
const key = files[0].key;
|
|
setFiles((current) => current.map((item) => (item.key === key ? { ...item, title: value } : item)));
|
|
return;
|
|
}
|
|
setTitle(value);
|
|
}
|
|
|
|
function setFileTitle(key, value) {
|
|
markDirty(true);
|
|
setFiles((current) => current.map((item) => (item.key === key ? { ...item, title: value } : item)));
|
|
}
|
|
|
|
function removeFile(key) {
|
|
if (files.length === 1 && files[0].key === key) setTitle(files[0].title);
|
|
setFiles((current) => current.filter((item) => item.key !== key));
|
|
}
|
|
|
|
async function uploadFile(item) {
|
|
const form = new FormData();
|
|
form.set("title", item.title.trim());
|
|
form.set("upload", item.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);
|
|
if (direction === "in" || direction === "out" || direction === "local") form.set("communication_direction", direction);
|
|
await api("/api/v1/files", { method: "POST", form });
|
|
}
|
|
|
|
async function submit(event) {
|
|
event.preventDefault();
|
|
if (pending) return;
|
|
if (!files.length) {
|
|
setError("Bitte mindestens eine Datei auswählen.");
|
|
return;
|
|
}
|
|
const batch = files.map((item) => ({ ...item, title: item.title.trim() }));
|
|
if (batch.some((item) => !item.title || item.title.length > 200)) {
|
|
setError("Jeder Titel muss vorhanden und höchstens 200 Zeichen lang sein.");
|
|
return;
|
|
}
|
|
setError("");
|
|
setPending(true);
|
|
const remaining = [];
|
|
let failed = null;
|
|
let uploaded = 0;
|
|
try {
|
|
for (let index = 0; index < batch.length; index += 1) {
|
|
const item = batch[index];
|
|
setProgress({ current: index + 1, total: batch.length });
|
|
try {
|
|
await uploadFile(item);
|
|
uploaded += 1;
|
|
} catch (err) {
|
|
failed = { name: item.file.name, message: err.message };
|
|
remaining.push(item, ...batch.slice(index + 1));
|
|
break;
|
|
}
|
|
}
|
|
} finally {
|
|
setPending(false);
|
|
setProgress(null);
|
|
}
|
|
if (failed) {
|
|
setFiles(remaining);
|
|
setError(uploaded
|
|
? `„${failed.name}“ wurde nicht eingebunden. ${failed.message} Bereits eingebundene Dateien bleiben erhalten.`
|
|
: `„${failed.name}“ wurde nicht eingebunden. ${failed.message}`);
|
|
if (uploaded) onChange(false);
|
|
return;
|
|
}
|
|
setTitle("");
|
|
setFiles([]);
|
|
markDirty(false);
|
|
onChange();
|
|
}
|
|
|
|
const singleTitle = files.length === 1 ? files[0].title : title;
|
|
const submitLabel = pending
|
|
? (progress ? `Datei ${progress.current} von ${progress.total} wird eingebunden …` : "Wird hinzugefügt …")
|
|
: (files.length > 1 ? `${files.length} Dateien hinzufügen` : "Datei hinzufügen");
|
|
|
|
return (
|
|
<form onSubmit={submit} className="stack compact">
|
|
<TargetLine label={targetLabel} chapters={chapters} chapterId={chapterId} />
|
|
<h3>Datei</h3>
|
|
{files.length <= 1 ? (
|
|
<label>
|
|
Titel
|
|
<input value={singleTitle} onChange={(event) => setSingleTitle(event.target.value)} placeholder="Titel des Schreibens" maxLength={200} required={files.length === 1} disabled={pending} />
|
|
</label>
|
|
) : null}
|
|
<label>
|
|
Dateien
|
|
<input
|
|
ref={inputRef}
|
|
type="file"
|
|
multiple
|
|
accept="application/pdf,image/png,image/jpeg,image/webp"
|
|
onChange={(event) => chooseFiles(event.target.files)}
|
|
disabled={pending}
|
|
/>
|
|
</label>
|
|
<p className="muted">Mehrere Dateien können gleichzeitig ausgewählt werden. Jede Datei wird einzeln eingebunden.</p>
|
|
{files.length === 1 ? (
|
|
<div className="file-batch__file">
|
|
<span className="muted">{files[0].file.name}</span>
|
|
<button type="button" className="quiet" onClick={() => removeFile(files[0].key)} disabled={pending}>Entfernen</button>
|
|
</div>
|
|
) : null}
|
|
{files.length > 1 ? (
|
|
<>
|
|
<ul className="file-batch">
|
|
{files.map((item) => (
|
|
<li key={item.key}>
|
|
<label>
|
|
{`Titel · ${item.file.name}`}
|
|
<input value={item.title} onChange={(event) => setFileTitle(item.key, event.target.value)} maxLength={200} required disabled={pending} />
|
|
</label>
|
|
<button type="button" className="quiet file-batch__remove" onClick={() => removeFile(item.key)} disabled={pending}>Entfernen</button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<p className="muted">Dokumentdatum, Versand, Zugang, Richtung und Kapitel gelten für alle ausgewählten Dateien.</p>
|
|
</>
|
|
) : null}
|
|
<label>Dokumentdatum <DateField value={documentOn} onChange={setDocumentOn} disabled={pending} /></label>
|
|
<label>Versand <DateField value={sentOn} onChange={setSentOn} disabled={pending} /></label>
|
|
<label>Zugang <DateField value={receivedOn} onChange={setReceivedOn} disabled={pending} /></label>
|
|
<DirectionChoice value={direction} onChange={setDirection} disabled={pending} />
|
|
{chapterSelect(chapters, chapterId, setChapterId, pending)}
|
|
<button type="submit" disabled={pending || !files.length}>{submitLabel}</button>
|
|
<ErrorNote error={error} />
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function ExternalForm({ context, placement, chapters = [], initialChapter = "", targetLabel = "", onChange }) {
|
|
const [title, setTitle] = useState("");
|
|
const [externalId, setExternalId] = useState("");
|
|
const sourceChoices = [{ kind: "url", title: "Andere Quelle" }, ...sourceModules().filter((item) => item.manual)];
|
|
const [source, setSource] = useState(() => sourceChoices.find((item) => item.kind !== "url")?.kind || "url");
|
|
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>Referenz erfassen</h3>
|
|
<input value={title} onChange={(event) => setTitle(event.target.value)} placeholder="Anzeigetitel" required />
|
|
<select value={source} onChange={(event) => setSource(event.target.value)}>
|
|
{sourceChoices.map((item) => <option key={item.kind} value={item.kind}>{item.title || item.addLabel}</option>)}
|
|
</select>
|
|
<input value={externalId} onChange={(event) => setExternalId(event.target.value)} placeholder="Externe ID" required />
|
|
<label>Dokumentdatum <DateField value={documentOn} onChange={setDocumentOn} /></label>
|
|
<label>Versand <DateField value={sentOn} onChange={setSentOn} /></label>
|
|
<label>Zugang <DateField value={receivedOn} onChange={setReceivedOn} /></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(", ") + ".";
|
|
}
|