Zeige im Breadcrumb die Aktenstruktur und lass Kapitel samt Inhalt an ihren Ort ziehen.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
cafa4e8b92
commit
7ef73ad500
12 files changed
+627
-93
No files matched your search
+198
-24
@@ -152,12 +152,13 @@ function sectionsOf(chapters, bindings) {
|
||||
const sections = (chapters || []).map((chapter) => ({
|
||||
id: chapter.id,
|
||||
title: chapter.title,
|
||||
documentOn: chapter.document_on || "",
|
||||
items: buckets.get(chapter.id) || [],
|
||||
}));
|
||||
if (sections.length && loose.length) {
|
||||
sections.push({ id: "loose", title: "Ohne Kapitel", items: loose });
|
||||
sections.push({ id: "loose", title: "Ohne Kapitel", documentOn: "", items: loose });
|
||||
} else if (!sections.length) {
|
||||
sections.push({ id: "loose", title: "", items: loose });
|
||||
sections.push({ id: "loose", title: "", documentOn: "", items: loose });
|
||||
}
|
||||
return sections;
|
||||
}
|
||||
@@ -195,8 +196,8 @@ export function ObjectMenu({ view, onView, children }) {
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<button type="button" className="quiet" onClick={() => setOpen(true)}>Menü</button>
|
||||
<Modal open={open} title="Menü" onClose={() => setOpen(false)}>
|
||||
<button type="button" className="quiet" onClick={() => setOpen(true)}>Aktionen</button>
|
||||
<Modal open={open} title="Aktionen" onClose={() => setOpen(false)}>
|
||||
<div className="menu-list" onClick={() => setOpen(false)}>
|
||||
<button type="button" className={view === "course" ? "" : "quiet"} onClick={() => choose("course")}>Fachlicher Verlauf</button>
|
||||
<button type="button" className={view === "audit" ? "" : "quiet"} onClick={() => choose("audit")}>Änderungsprotokoll</button>
|
||||
@@ -319,14 +320,14 @@ export function ContentBoard({
|
||||
}
|
||||
}
|
||||
|
||||
async function persist(next) {
|
||||
async function persist(next, version = record.version) {
|
||||
setError("");
|
||||
setPending(true);
|
||||
try {
|
||||
await api(`${orderPath}/bindings/order`, {
|
||||
method: "POST",
|
||||
body: {
|
||||
expected_version: record.version,
|
||||
expected_version: version,
|
||||
binding_ids: next.flatMap((section) => section.items.map((item) => item.id)),
|
||||
...orderContext,
|
||||
},
|
||||
@@ -339,6 +340,48 @@ export function ContentBoard({
|
||||
}
|
||||
}
|
||||
|
||||
async function reorderChapters(ids) {
|
||||
setError("");
|
||||
setPending(true);
|
||||
try {
|
||||
await api(`${orderPath}/chapters/order`, {
|
||||
method: "POST",
|
||||
body: { expected_version: record.version, chapter_ids: ids, ...orderContext },
|
||||
});
|
||||
onChange();
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
function moveChapter(chapterId, delta) {
|
||||
const ids = chapters.map((chapter) => chapter.id);
|
||||
const index = ids.indexOf(chapterId);
|
||||
const target = index + delta;
|
||||
if (index < 0 || target < 0 || target >= ids.length) return;
|
||||
const [id] = ids.splice(index, 1);
|
||||
ids.splice(target, 0, id);
|
||||
reorderChapters(ids);
|
||||
}
|
||||
|
||||
async function saveChapterDate(chapterId, value) {
|
||||
setError("");
|
||||
setPending(true);
|
||||
try {
|
||||
await api(`/api/v1/chapters/${chapterId}`, {
|
||||
method: "PATCH",
|
||||
body: { expected_version: record.version, document_on: value || null, ...orderContext },
|
||||
});
|
||||
onChange();
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function move(bindingId, delta) {
|
||||
const next = sections.map((section) => ({ ...section, items: [...section.items] }));
|
||||
let moved = false;
|
||||
@@ -379,24 +422,73 @@ export function ContentBoard({
|
||||
return rows.length;
|
||||
}
|
||||
|
||||
function sectionUnder(clientY) {
|
||||
const nodes = [...(rootRef.current?.querySelectorAll("[data-section]") || [])];
|
||||
const hit = nodes.find((node) => {
|
||||
const rect = node.getBoundingClientRect();
|
||||
return clientY >= rect.top && clientY <= rect.bottom;
|
||||
});
|
||||
return hit?.getAttribute("data-section") || null;
|
||||
}
|
||||
|
||||
function chapterIndexAt(clientY) {
|
||||
const nodes = [...(rootRef.current?.querySelectorAll("[data-chapter]") || [])];
|
||||
for (let i = 0; i < nodes.length; i += 1) {
|
||||
const rect = nodes[i].getBoundingClientRect();
|
||||
if (clientY < rect.top + rect.height / 2) return i;
|
||||
}
|
||||
return nodes.length;
|
||||
}
|
||||
|
||||
function finishDrag(drag) {
|
||||
dragRef.current = null;
|
||||
setDraggingId("");
|
||||
setIndicator(null);
|
||||
if (!drag || !drag.moved || drag.index == null) return;
|
||||
if (drag.kind === "chapter") {
|
||||
const ids = chapters.map((chapter) => chapter.id);
|
||||
const from = ids.indexOf(drag.chapterId);
|
||||
if (from < 0) return;
|
||||
let target = drag.index;
|
||||
if (from < target) target -= 1;
|
||||
if (target < 0) target = 0;
|
||||
if (target > ids.length - 1) target = ids.length - 1;
|
||||
if (target === from) return;
|
||||
const [id] = ids.splice(from, 1);
|
||||
ids.splice(target, 0, id);
|
||||
reorderChapters(ids);
|
||||
return;
|
||||
}
|
||||
const next = sections.map((section) => ({ ...section, items: [...section.items] }));
|
||||
const section = next.find((item) => item.id === drag.sectionId);
|
||||
if (!section) return;
|
||||
const from = section.items.findIndex((item) => item.id === drag.bindingId);
|
||||
const source = next.find((item) => item.id === drag.sectionId);
|
||||
const targetSection = next.find((item) => item.id === (drag.targetSectionId || drag.sectionId));
|
||||
if (!source || !targetSection) return;
|
||||
const from = source.items.findIndex((item) => item.id === drag.bindingId);
|
||||
if (from < 0) return;
|
||||
let target = drag.index;
|
||||
if (from < target) target -= 1;
|
||||
if (source.id === targetSection.id && from < target) target -= 1;
|
||||
if (target < 0) target = 0;
|
||||
if (target > section.items.length - 1) target = section.items.length - 1;
|
||||
if (target === from) return;
|
||||
const [item] = section.items.splice(from, 1);
|
||||
section.items.splice(target, 0, item);
|
||||
persist(next);
|
||||
if (target > targetSection.items.length) target = targetSection.items.length;
|
||||
if (source.id === targetSection.id && target === from) return;
|
||||
const [item] = source.items.splice(from, 1);
|
||||
const nextChapter = targetSection.id === "loose" ? null : targetSection.id;
|
||||
const changed = (item.chapter_id || null) !== nextChapter;
|
||||
item.chapter_id = nextChapter;
|
||||
const insertAt = source.id === targetSection.id ? target : Math.min(target, targetSection.items.length);
|
||||
targetSection.items.splice(insertAt, 0, item);
|
||||
if (!changed) {
|
||||
persist(next);
|
||||
return;
|
||||
}
|
||||
setPending(true);
|
||||
setError("");
|
||||
api(`/api/v1/bindings/${item.id}/chapter`, {
|
||||
method: "PATCH",
|
||||
body: { expected_version: record.version, chapter_id: nextChapter, ...orderContext },
|
||||
}).then((moved) => persist(next, moved.version)).catch((err) => {
|
||||
setError(err.message);
|
||||
setPending(false);
|
||||
});
|
||||
}
|
||||
|
||||
function track(event) {
|
||||
@@ -405,8 +497,14 @@ export function ContentBoard({
|
||||
if (Math.abs(event.clientY - drag.startY) > 4) drag.moved = true;
|
||||
if (event.clientY < 72) window.scrollBy(0, -16);
|
||||
if (event.clientY > window.innerHeight - 72) window.scrollBy(0, 16);
|
||||
drag.index = indexAt(drag.sectionId, event.clientY);
|
||||
setIndicator({ sectionId: drag.sectionId, index: drag.index });
|
||||
if (drag.kind === "chapter") {
|
||||
drag.index = chapterIndexAt(event.clientY);
|
||||
setIndicator({ sectionId: drag.chapterId, index: drag.index, kind: "chapter" });
|
||||
return;
|
||||
}
|
||||
drag.targetSectionId = sectionUnder(event.clientY) || drag.sectionId;
|
||||
drag.index = indexAt(drag.targetSectionId, event.clientY);
|
||||
setIndicator({ sectionId: drag.targetSectionId, index: drag.index });
|
||||
}
|
||||
|
||||
function release(event) {
|
||||
@@ -439,26 +537,51 @@ export function ContentBoard({
|
||||
function onDragStart(event, bindingId, sectionId) {
|
||||
event.dataTransfer.effectAllowed = "move";
|
||||
event.dataTransfer.setData("text/plain", bindingId);
|
||||
dragRef.current = { pointerId: "html5", bindingId, sectionId, startY: event.clientY, moved: true, index: null, html5: true };
|
||||
dragRef.current = { pointerId: "html5", bindingId, sectionId, targetSectionId: sectionId, startY: event.clientY, moved: true, index: null, html5: true };
|
||||
setDraggingId(bindingId);
|
||||
}
|
||||
|
||||
function onChapterDragStart(event, chapterId) {
|
||||
event.dataTransfer.effectAllowed = "move";
|
||||
event.dataTransfer.setData("text/plain", chapterId);
|
||||
dragRef.current = { kind: "chapter", pointerId: "html5", chapterId, startY: event.clientY, moved: true, index: null, html5: true };
|
||||
setDraggingId(chapterId);
|
||||
}
|
||||
|
||||
function onDragOver(event, sectionId) {
|
||||
const drag = dragRef.current;
|
||||
if (!drag?.html5 || drag.sectionId !== sectionId) return;
|
||||
if (!drag?.html5 || drag.kind === "chapter") return;
|
||||
event.preventDefault();
|
||||
drag.targetSectionId = sectionId;
|
||||
drag.index = indexAt(sectionId, event.clientY);
|
||||
setIndicator({ sectionId, index: drag.index });
|
||||
}
|
||||
|
||||
function onChapterDragOver(event) {
|
||||
const drag = dragRef.current;
|
||||
if (!drag?.html5 || drag.kind !== "chapter") return;
|
||||
event.preventDefault();
|
||||
drag.index = chapterIndexAt(event.clientY);
|
||||
setIndicator({ sectionId: drag.chapterId, index: drag.index, kind: "chapter" });
|
||||
}
|
||||
|
||||
function onDrop(event, sectionId) {
|
||||
const drag = dragRef.current;
|
||||
if (!drag?.html5 || drag.sectionId !== sectionId) return;
|
||||
if (!drag?.html5 || drag.kind === "chapter") return;
|
||||
event.preventDefault();
|
||||
drag.targetSectionId = sectionId;
|
||||
drag.index = indexAt(sectionId, event.clientY);
|
||||
finishDrag(drag);
|
||||
}
|
||||
|
||||
function onChapterDrop(event) {
|
||||
const drag = dragRef.current;
|
||||
if (!drag?.html5 || drag.kind !== "chapter") return;
|
||||
event.preventDefault();
|
||||
drag.index = chapterIndexAt(event.clientY);
|
||||
finishDrag(drag);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="contents" ref={rootRef}>
|
||||
{canSort ? (
|
||||
@@ -478,12 +601,63 @@ export function ContentBoard({
|
||||
visibleSections.map((section) => (
|
||||
<section
|
||||
key={section.id}
|
||||
className="content-section"
|
||||
className={indicator?.kind === "chapter" && indicator.index === chapters.findIndex((chapter) => chapter.id === section.id) ? "content-section is-chapter-target" : "content-section"}
|
||||
data-section={section.id}
|
||||
onDragOver={(event) => onDragOver(event, section.id)}
|
||||
onDrop={(event) => onDrop(event, section.id)}
|
||||
data-chapter={section.id === "loose" ? undefined : section.id}
|
||||
onDragOver={(event) => {
|
||||
if (dragRef.current?.kind === "chapter") onChapterDragOver(event);
|
||||
else onDragOver(event, section.id);
|
||||
}}
|
||||
onDrop={(event) => {
|
||||
if (dragRef.current?.kind === "chapter") onChapterDrop(event);
|
||||
else onDrop(event, section.id);
|
||||
}}
|
||||
>
|
||||
{section.title ? <h3 className="chapter-title">{section.title}</h3> : null}
|
||||
{section.title ? (
|
||||
<div className="chapter-head">
|
||||
{canSort && custom && section.id !== "loose" && !onlyChapter ? (
|
||||
<button
|
||||
type="button"
|
||||
className="handle"
|
||||
aria-label={`${section.title} verschieben`}
|
||||
draggable={!pending}
|
||||
disabled={pending}
|
||||
onPointerDown={(event) => {
|
||||
if (event.button != null && event.button !== 0) return;
|
||||
dragRef.current = { kind: "chapter", pointerId: event.pointerId, chapterId: section.id, startY: event.clientY, moved: false, index: null };
|
||||
setDraggingId(section.id);
|
||||
window.addEventListener("pointermove", track);
|
||||
window.addEventListener("pointerup", release);
|
||||
window.addEventListener("pointercancel", cancel);
|
||||
}}
|
||||
onDragStart={(event) => onChapterDragStart(event, section.id)}
|
||||
onDragEnd={cancel}
|
||||
>
|
||||
<span className="handle__grip" aria-hidden="true" />
|
||||
</button>
|
||||
) : null}
|
||||
<h3 className="chapter-title">{section.title}</h3>
|
||||
{section.documentOn ? <span className="muted">{formatDate(section.documentOn)}</span> : null}
|
||||
{canSort && custom && section.id !== "loose" && !onlyChapter ? (
|
||||
<span className="chapter-move">
|
||||
<button type="button" className="quiet" aria-label={`${section.title} nach oben`} disabled={pending || chapters[0]?.id === section.id} onClick={() => moveChapter(section.id, -1)}>Nach oben</button>
|
||||
<button type="button" className="quiet" aria-label={`${section.title} nach unten`} disabled={pending || chapters[chapters.length - 1]?.id === section.id} onClick={() => moveChapter(section.id, 1)}>Nach unten</button>
|
||||
</span>
|
||||
) : null}
|
||||
{canSort && section.id !== "loose" ? (
|
||||
<label className="chapter-date">
|
||||
Datum
|
||||
<input
|
||||
type="date"
|
||||
aria-label={`Datum für ${section.title}`}
|
||||
value={section.documentOn || ""}
|
||||
disabled={pending}
|
||||
onChange={(event) => saveChapterDate(section.id, event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{section.title && !section.items.length ? <p className="muted">Noch nichts in diesem Kapitel.</p> : null}
|
||||
<ol className="preview-list">
|
||||
{section.items.map((binding, index) => {
|
||||
|
||||
Reference in new issue
Block a user