Merge pull request 'Multiple Dateien importieren' (#6) from develop into main
Deploy Production / deploy (push) Successful in 38s

Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
Lars committed 2026-10-18 17:04:16 +02:00
commit 37662c2bd8
4 files changed
+191 -29

No files matched your search

+2 -1
View File
@@ -771,7 +771,8 @@ def test_nested_chapter_export_keeps_path_and_complete_mail(client, db, monkeypa
assert "Nebenkostenabrechnung 2025" in normalized
assert "Übermittelte Abrechnungsunterlagen" in normalized
assert "Einzelbelege/" in normalized
assert normalized.endswith("/Heizkostenbeleg/Heizkostenbeleg.pdf")
assert "Heizkostenbeleg/" in normalized
assert normalized.endswith("/Heizkostenbeleg.pdf")
assert any("Nebenkostenabrechnung 2025" in name and "Antwort des Vermieters" in name for name in names)
assert not any("Hausmeister" in name or name.endswith("/haus.pdf") for name in names)
assert not any(name.startswith("02 ") and "Nicht" in name for name in names)
+161 -27
View File
@@ -635,7 +635,7 @@ export function CaseDetail() {
<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={() => { setModal(""); load(); }} />
<FileForm context={context} chapters={record.chapters} initialChapter={addChapterId} targetLabel={targetLabel} onChange={(finished = true) => { load(); if (finished) setModal(""); }} />
</Modal>
<Modal open={modal === "paperless"} title="Aus Paperless" onClose={() => setModal("")}>
<PaperlessPicker context={context} chapterId={addChapterId} chapterTitle={addChapterId ? chapterPathLabel(record.chapters, addChapterId) : ""} targetLabel={targetLabel} onInserted={load} onDone={() => { setModal(""); load(); }} />
@@ -870,12 +870,12 @@ export function ContentForms({ context, placement, chapters, onChange }) {
);
}
function chapterSelect(chapters, value, setValue) {
function chapterSelect(chapters, value, setValue, disabled = false) {
if (!chapters?.length) return null;
return (
<label>
Kapitel
<select value={value} onChange={(event) => setValue(event.target.value)}>
<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>
@@ -885,6 +885,12 @@ function chapterSelect(chapters, value, setValue) {
);
}
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("");
@@ -956,22 +962,68 @@ export function NoteForm({ context, placement, chapters = [], initialChapter = "
export function FileForm({ context, placement, chapters = [], initialChapter = "", targetLabel = "", onChange }) {
const [title, setTitle] = useState("");
const [file, setFile] = useState(null);
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]);
async function submit(event) {
event.preventDefault();
if (!file) return;
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", title);
form.set("upload", file);
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) {
@@ -983,30 +1035,112 @@ export function FileForm({ context, placement, chapters = [], initialChapter = "
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);
setError("");
try {
await api("/api/v1/files", { method: "POST", form });
setTitle("");
setFile(null);
markDirty(false);
onChange();
} catch (err) {
setError(err.message);
}
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>
<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 <DateField value={documentOn} onChange={setDocumentOn} /></label>
<label>Versand <DateField value={sentOn} onChange={setSentOn} /></label>
<label>Zugang <DateField value={receivedOn} onChange={setReceivedOn} /></label>
<DirectionChoice value={direction} onChange={setDirection} />
{chapterSelect(chapters, chapterId, setChapterId)}
<button type="submit">Datei hinzufügen</button>
{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>
);
+1 -1
View File
@@ -580,7 +580,7 @@ export function MatterDetail() {
<NoteForm context={rightsContext} placement={placement} chapters={record.chapters} initialChapter={addChapterId} targetLabel={targetLabel} onChange={() => { setModal(""); load(); }} />
</Modal>
<Modal open={modal === "file"} title="Datei" onClose={() => setModal("")}>
<FileForm context={rightsContext} placement={placement} chapters={record.chapters} initialChapter={addChapterId} targetLabel={targetLabel} onChange={() => { setModal(""); load(); }} />
<FileForm context={rightsContext} placement={placement} chapters={record.chapters} initialChapter={addChapterId} targetLabel={targetLabel} onChange={(finished = true) => { load(); if (finished) setModal(""); }} />
</Modal>
<Modal open={modal === "paperless"} title="Aus Paperless" onClose={() => setModal("")}>
<PaperlessPicker context={rightsContext} placement={placement} chapterId={addChapterId} chapterTitle={addChapterId ? chapterPathLabel(record.chapters, addChapterId) : ""} targetLabel={targetLabel} onInserted={load} onDone={() => { setModal(""); load(); }} />
+27
View File
@@ -527,6 +527,33 @@ button.nav-item:active { transform: none; }
.export-review > p { text-align: left; }
.add-choices { display: grid; gap: 8px; }
.add-choices button { min-height: 44px; justify-content: flex-start; }
.file-batch {
list-style: none;
margin: 0;
padding: 0;
display: grid;
gap: 10px;
max-height: 280px;
overflow: auto;
}
.file-batch li {
display: grid;
gap: 6px;
padding: 10px;
border: 1px solid var(--border);
border-radius: 10px;
background: var(--surface2);
}
.file-batch label { overflow-wrap: anywhere; }
.file-batch__remove { justify-self: start; }
.file-batch__file {
display: flex;
gap: 8px;
align-items: center;
justify-content: space-between;
}
.file-batch__file span { min-width: 0; overflow-wrap: anywhere; }
.file-batch__file button { flex: none; }
.hierarchy__parent { margin-bottom: 8px; }
.order-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.order-bar button { min-height: 44px; }