Schließe die Connector-Kapselung ab, damit Paperless, IMAP und weitere Quellen über dieselbe Anbindung laufen.
Deploy Development / deploy (push) Successful in 28s
Test Suite / pytest-backend (push) Failing after 2m18s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 10s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-10-19 15:00:50 +02:00
1 parent 75a3949f7c
commit d6b70d8f92
75 files changed
+9477 -414

No files matched your search

+12 -14
View File
@@ -4,7 +4,8 @@ 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 { MailPicker, PaperlessPicker } from "./Sources.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";
@@ -635,8 +636,9 @@ export function CaseDetail() {
{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>
<button type="button" onClick={() => setModal("paperless")}>Paperless</button>
<button type="button" onClick={() => setModal("mail")}>E-Mail</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("")}>
@@ -645,11 +647,8 @@ export function CaseDetail() {
<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 === "paperless"} title="Aus Paperless" onClose={() => setModal("")}>
<PaperlessPicker context={context} chapterId={addChapterId} chapterTitle={addChapterId ? chapterPathLabel(record.chapters, addChapterId) : ""} targetLabel={targetLabel} onInserted={load} onDone={() => { setModal(""); load(); }} />
</Modal>
<Modal open={modal === "mail"} title="E-Mail verbinden" wide split onClose={() => setModal("")}>
<MailPicker context={context} chapterId={addChapterId} chapterTitle={addChapterId ? chapterPathLabel(record.chapters, addChapterId) : ""} targetLabel={targetLabel} onDone={() => { setModal(""); load(); }} />
<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(); }} />
@@ -717,8 +716,7 @@ function BindingTiles({ items, onOpen, empty }) {
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";
if (element.external?.source) return moduleFor(element.external.source)?.addLabel || moduleFor(element.external.source)?.title || "Referenz";
return "Referenz";
}
@@ -1157,7 +1155,8 @@ export function FileForm({ context, placement, chapters = [], initialChapter = "
function ExternalForm({ context, placement, chapters = [], initialChapter = "", targetLabel = "", onChange }) {
const [title, setTitle] = useState("");
const [externalId, setExternalId] = useState("");
const [source, setSource] = useState("paperless");
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("");
@@ -1197,11 +1196,10 @@ function ExternalForm({ context, placement, chapters = [], initialChapter = "",
return (
<form onSubmit={submit} className="stack compact">
<TargetLine label={targetLabel} chapters={chapters} chapterId={chapterId} />
<h3>Paperless oder andere Referenz</h3>
<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)}>
<option value="paperless">Paperless</option>
<option value="url">Andere Quelle</option>
{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>
+1 -1
View File
@@ -71,7 +71,7 @@ function symbolFor(node) {
if (node.kind === "matter") return node.label === "Teilvorgang" ? "submatter" : "matter";
if (node.kind === "annotation" || node.content_kind === "note") return "note";
if (node.content_kind === "email") return "email";
if (node.content_kind === "paperless") return "source-archive";
if (node.content_kind === "source") return "source-archive";
if (node.content_kind === "url") return "link";
return "file";
}
+7 -8
View File
@@ -3,7 +3,8 @@ import { Link, useNavigate, useParams, useSearchParams } from "react-router-dom"
import { api, isDirty, markDirty } from "../api.js";
import { SessionContext } from "../session.js";
import { Modal } from "./Modal.jsx";
import { MailPicker, PaperlessPicker } from "./Sources.jsx";
import "./Sources.jsx";
import { SourcePicker, moduleFor, sourceModules } from "../sources/registry.jsx";
import { ErrorNote, ShareBox } from "./widgets.jsx";
import { chapterPathLabel, siblingChapterIds, trailWithChapter } from "./chapters.js";
import { ChapterForm, FileForm, NoteForm } from "./Cases.jsx";
@@ -580,8 +581,9 @@ export function MatterDetail() {
{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>
<button type="button" onClick={() => setModal("paperless")}>Paperless</button>
<button type="button" onClick={() => setModal("mail")}>E-Mail</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("")}>
@@ -590,11 +592,8 @@ export function MatterDetail() {
<Modal open={modal === "file"} title="Datei" onClose={() => setModal("")}>
<FileForm context={rightsContext} placement={placement} chapters={record.chapters} initialChapter={addChapterId} targetLabel={targetLabel} onChange={(finished = true) => { load(); if (finished) setModal(""); }} />
</Modal>
<Modal open={modal === "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(); }} />
</Modal>
<Modal open={modal === "mail"} title="E-Mail verbinden" wide split onClose={() => setModal("")}>
<MailPicker context={rightsContext} placement={placement} chapterId={addChapterId} chapterTitle={addChapterId ? chapterPathLabel(record.chapters, addChapterId) : ""} targetLabel={targetLabel} onDone={() => { setModal(""); load(); }} />
<Modal open={modal.startsWith("source:")} title={moduleFor(modal.slice(7))?.title || "Quelle"} wide={Boolean(moduleFor(modal.slice(7))?.wide)} split={Boolean(moduleFor(modal.slice(7))?.wide)} onClose={() => setModal("")}>
<SourcePicker sourceKind={modal.slice(7)} context={rightsContext} placement={placement} chapterId={addChapterId} chapterTitle={addChapterId ? chapterPathLabel(record.chapters, addChapterId) : ""} targetLabel={targetLabel} onInserted={load} onDone={() => { setModal(""); load(); }} />
</Modal>
<Modal open={modal === "submatter"} title="Teilvorgang anlegen" onClose={() => setModal("")}>
<SubmatterForm parentId={id} context={inherited} onChange={() => { setModal(""); load(); }} />
+49 -19
View File
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState } from "react";
import { documentToText, downloadMailPart, fetchFile, fetchMailPart, fetchPaperless, markDirty, textToDocument, api } from "../api.js";
import { documentToText, downloadMailPart, fetchExternal, fetchFile, fetchMailPart, markDirty, textToDocument, api } from "../api.js";
import { SourceAssignment, noteEditor, representationOf } from "../sources/registry.jsx";
import { ErrorNote } from "./widgets.jsx";
import { UnitDetail } from "./correspondence.jsx";
import { dateCaption, DateField, DirectionChoice, DirectionColumn, directionValue, directionWord, formatDate, mailFacts, MarkdownEditor, sourceLabel } from "./content.jsx";
@@ -83,6 +84,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
const [pages, setPages] = useState(0);
const [scale, setScale] = useState(1);
const [text, setText] = useState("");
const [sourceText, setSourceText] = useState("");
const [note, setNote] = useState("");
const [summary, setSummary] = useState("");
const [documentOn, setDocumentOn] = useState("");
@@ -114,15 +116,15 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
useEffect(() => {
if (!element) return undefined;
const mail = element.external?.source === "imap";
if (element.kind === "note" || mail) setPhase("ready");
else if (!element.preview?.available) setPhase("missing");
const kind = representationOf(element);
if (kind === "note" || kind === "mail") setPhase("ready");
else if (kind === "locked" || kind === "unassigned" || !element.preview?.available) setPhase("missing");
setError("");
return undefined;
}, [element?.id, element?.kind, element?.external?.source, element?.preview?.available]);
}, [element?.id, element?.kind, element?.external?.source, element?.external?.resolution, element?.file?.protection_profile, element?.preview?.available]);
useEffect(() => {
if (!element || element.kind === "note" || element.external?.source === "imap" || !element.preview?.available) return undefined;
if (!element || representationOf(element) === "note" || representationOf(element) === "mail" || representationOf(element) === "locked" || representationOf(element) === "unassigned" || !element.preview?.available) return undefined;
let alive = true;
let url = "";
setPage(1);
@@ -136,9 +138,16 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
}
setBlobUrl("");
setPhase("loading");
const load = element.external?.source === "paperless" ? fetchPaperless(element.id, context) : fetchFile(element.id, context);
const view = representationOf(element);
const load = view === "source-file" || view === "text" ? fetchExternal(element.id, context) : fetchFile(element.id, context);
load.then(async (blob) => {
if (!alive) return;
if (view === "text") {
setSourceText(await blob.text());
setMedia("text");
setPhase("ready");
return;
}
url = URL.createObjectURL(blob);
setBlobUrl(url);
if (blob.type.startsWith("image/")) {
@@ -179,10 +188,10 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
alive = false;
if (url) URL.revokeObjectURL(url);
};
}, [element?.id, element?.kind, element?.external?.source, element?.preview?.available, context?.kind, context?.id]);
}, [element?.id, element?.kind, element?.external?.source, element?.external?.resolution, element?.file?.protection_profile, element?.preview?.available, context?.kind, context?.id]);
useEffect(() => {
if (!element || element.external?.source !== "imap") return undefined;
if (!element || representationOf(element) !== "mail") return undefined;
if (shownIndex === null) {
setPhase("ready");
setPdf(null);
@@ -251,7 +260,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
}, [element?.id, element?.external?.source, shownIndex, letter, context?.kind, context?.id]);
useEffect(() => {
if (!element || element.external?.source !== "imap") return undefined;
if (!element || representationOf(element) !== "mail") return undefined;
let alive = true;
const params = new URLSearchParams();
if (context?.kind && context?.id) {
@@ -330,8 +339,9 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
async function openOriginal() {
setError("");
try {
const blob = element.external?.source === "paperless"
? await fetchPaperless(element.id, context)
const view = representationOf(element);
const blob = view === "source-file" || view === "text"
? await fetchExternal(element.id, context)
: await fetchFile(element.id, context);
const url = URL.createObjectURL(blob);
window.open(url, "_blank", "noopener");
@@ -345,14 +355,20 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
event.preventDefault();
setError("");
try {
const updated = await api(`/api/v1/notes/${element.id}`, {
method: "PATCH",
body: { expected_version: element.version, document: textToDocument(text), context },
const updated = await noteEditor.save({
api,
element,
context,
document: textToDocument(text),
});
markDirty(false);
setNotice(updated.notice || "Der gemeinsame Text ist gespeichert.");
onReload();
} catch (err) {
if (err.status === 409) {
setError("Der Stand hat sich geändert. Der eingegebene Text bleibt stehen. Bitte neu laden.");
return;
}
setError(err.message);
}
}
@@ -478,7 +494,10 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
const communication = binding.communication || {};
const shownDirection = communication.direction || null;
const isMail = element.external?.source === "imap";
const kind = representationOf(element);
const isMail = kind === "mail";
const locked = kind === "locked";
const unassigned = kind === "unassigned";
const mailDetail = letter || element.external?.detail || {};
const shownFile = isMail ? (letter?.attachments || []).find((item) => item.index === shownIndex) || null : null;
@@ -564,7 +583,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
)}
</article>
) : null}
{element.kind === "note" ? (
{element.kind === "note" && noteEditor.available ? (
<form className="reader-note" onSubmit={saveNote}>
<MarkdownEditor value={text} disabled={!binding.rights.edit} onChange={(value) => { setText(value); markDirty(true); }} />
<p className="muted">Diese Änderung betrifft den gemeinsamen Inhalt der Notiz, nicht die hiesige Anmerkung. Gespeichert wird Markdown.</p>
@@ -580,8 +599,18 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
/>
<p className="muted">Keine Angabe bleibt leer. Versand- und Zugangsdatum ändern die Richtung nicht.</p>
</form>
{!isMail && phase === "loading" ? <p className="reader-pane__state">Vorschau wird geladen …</p> : null}
{!isMail && phase === "missing" ? (
{!isMail && locked ? (
<div className="reader-pane__state">
<p>Die Metadaten sind sichtbar. Der Inhalt ist geschützt und wird in dieser Lieferung nicht entschlüsselt.</p>
</div>
) : null}
{!isMail && unassigned ? (
<div className="reader-pane__state">
<SourceAssignment element={element} onAssigned={onReload} />
</div>
) : null}
{!isMail && !locked && !unassigned && phase === "loading" ? <p className="reader-pane__state">Vorschau wird geladen …</p> : null}
{!isMail && !locked && !unassigned && phase === "missing" ? (
<div className="reader-pane__state">
<p>Für diesen Inhalt gibt es keine eingebaute Vorschau.</p>
<button type="button" onClick={openOriginal}>Original öffnen</button>
@@ -593,6 +622,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
<button type="button" onClick={openOriginal}>Original öffnen</button>
</div>
) : null}
{!isMail && media === "text" ? <pre className="mail-letter__body">{sourceText}</pre> : null}
{!isMail && media === "image" && blobUrl ? (
<img className="reader-image" alt={element.title} src={blobUrl} style={{ width: `${Math.round(scale * 100)}%` }} />
) : null}
+122 -47
View File
@@ -1,7 +1,13 @@
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { api } from "../api.js";
import { TargetLine, formatDate } from "./content.jsx";
import { SourceFrame, defineSourceModules, moduleFor, sourceModules } from "../sources/registry.jsx";
const SEARCH_LIMITS = {
paperless: "Suche in dieser Lieferung: Stichwort. Korrespondent, Dokumenttyp, Tags, Zeitraum und Sortierung sind noch nicht verfügbar.",
imap: "Suche im gewählten Fach: Stichwort und weitere Seiten. Korrespondent, Dokumenttyp, Tags und Sortierung sind noch nicht verfügbar.",
};
import { formatDate } from "./content.jsx";
import { NavIcon } from "./icons.jsx";
import { ErrorNote } from "./widgets.jsx";
@@ -9,6 +15,9 @@ export function Sources() {
const [items, setItems] = useState([]);
const [error, setError] = useState("");
const [notice, setNotice] = useState("");
const [renew, setRenew] = useState(null);
const modules = sourceModules();
const RenewForm = renew ? moduleFor(renew.kind)?.Form : null;
async function load() {
const data = await api("/api/v1/connectors");
@@ -32,41 +41,59 @@ export function Sources() {
<div className="tiles">
{items.map((item) => (
<article key={item.id} className="tile">
<span className="tile__kind">{item.kind === "paperless" ? "Paperless" : "IMAP"}</span>
<span className="tile__kind">{moduleFor(item.kind)?.title || item.kind}</span>
<strong>{item.name}</strong>
<span>{item.kind === "paperless" ? item.settings.base_url : item.settings.username}</span>
<span>{item.settings.base_url || item.settings.username || item.settings.catalog || ""}</span>
<div className="row">
<button type="button" className="quiet" onClick={() => probe(item.id, setNotice, setError)}>Prüfen</button>
<button type="button" className="quiet" onClick={() => setRenew(item)}>Zugang erneuern</button>
<button type="button" className="danger" onClick={() => remove(item.id, load, setError)}>Entfernen</button>
</div>
</article>
))}
</div>
<section className="card">
<h2>Paperless</h2>
<PaperlessForm onSaved={load} onError={setError} />
</section>
<section className="card">
<h2>E-Mail-Konto</h2>
<MailForm onSaved={load} onError={setError} />
</section>
{renew ? (
<section className="card">
<h2>Zugang erneuern: {renew.name}</h2>
<p className="muted">Dasselbe Konto behält seine Instanz. Eine weitere Instanz legst du darunter neu an.</p>
{RenewForm ? (
<RenewForm
connectorId={renew.id}
initialName={renew.name}
settings={renew.settings}
onSaved={async () => { setRenew(null); await load(); }}
onError={setError}
/>
) : (
<p className="muted">Dieser Zugang wird über sein Modul erneuert.</p>
)}
</section>
) : null}
{modules.filter((module) => module.Form).map((module) => (
<section key={module.kind} className="card">
<h2>{module.title}</h2>
<module.Form onSaved={load} onError={setError} />
</section>
))}
</main>
);
}
function PaperlessForm({ onSaved, onError }) {
const [name, setName] = useState("Paperless");
const [baseUrl, setBaseUrl] = useState("");
function PaperlessForm({ onSaved, onError, connectorId = "", initialName = "Paperless", initialUrl = "", settings = null }) {
const [name, setName] = useState(initialName);
const [baseUrl, setBaseUrl] = useState(settings?.base_url || initialUrl);
const [token, setToken] = useState("");
async function submit(event) {
event.preventDefault();
onError("");
try {
await api("/api/v1/connectors", {
method: "POST",
body: { kind: "paperless", name, base_url: baseUrl, token },
});
const body = { kind: "paperless", name, base_url: baseUrl, token };
if (connectorId) {
await api(`/api/v1/connectors/${connectorId}`, { method: "PATCH", body });
} else {
await api("/api/v1/connectors", { method: "POST", body });
}
setToken("");
await onSaved();
} catch (err) {
@@ -79,36 +106,48 @@ function PaperlessForm({ onSaved, onError }) {
<label>Name <input value={name} onChange={(event) => setName(event.target.value)} required /></label>
<label>Adresse <input value={baseUrl} onChange={(event) => setBaseUrl(event.target.value)} placeholder="https://paperless.example" required /></label>
<label>API-Schlüssel <input type="password" value={token} onChange={(event) => setToken(event.target.value)} autoComplete="off" required /></label>
<button type="submit">Paperless verbinden</button>
<button type="submit">{connectorId ? "Zugang dieser Instanz erneuern" : "Paperless-Instanz verbinden"}</button>
</form>
);
}
function MailForm({ onSaved, onError }) {
const [name, setName] = useState("");
const [host, setHost] = useState("");
const [port, setPort] = useState("993");
const [username, setUsername] = useState("");
function MailForm({
onSaved,
onError,
connectorId = "",
initialName = "",
initialHost = "",
initialPort = "993",
initialUsername = "",
initialSecurity = "ssl",
settings = null,
}) {
const [name, setName] = useState(initialName);
const [host, setHost] = useState(settings?.host || initialHost);
const [port, setPort] = useState(String(settings?.port || initialPort));
const [username, setUsername] = useState(settings?.username || initialUsername);
const [password, setPassword] = useState("");
const [security, setSecurity] = useState("ssl");
const [security, setSecurity] = useState(settings?.security || initialSecurity);
async function submit(event) {
event.preventDefault();
onError("");
try {
await api("/api/v1/connectors", {
method: "POST",
body: {
kind: "imap",
name: name || username,
host,
port: Number(port),
username,
password,
security,
mailbox: "INBOX",
},
});
const body = {
kind: "imap",
name: name || username,
host,
port: Number(port),
username,
password,
security,
mailbox: "INBOX",
};
if (connectorId) {
await api(`/api/v1/connectors/${connectorId}`, { method: "PATCH", body });
} else {
await api("/api/v1/connectors", { method: "POST", body });
}
setPassword("");
await onSaved();
} catch (err) {
@@ -130,7 +169,7 @@ function MailForm({ onSaved, onError }) {
</label>
<label>Benutzername <input value={username} onChange={(event) => setUsername(event.target.value)} required /></label>
<label>Passwort <input type="password" value={password} onChange={(event) => setPassword(event.target.value)} autoComplete="off" required /></label>
<button type="submit">Konto hinzufügen</button>
<button type="submit">{connectorId ? "Zugang dieses Kontos erneuern" : "Konto hinzufügen"}</button>
</form>
);
}
@@ -143,16 +182,35 @@ function paperlessLabel(item) {
export function PaperlessPicker({ context, placement, chapterId = "", chapterTitle = "", targetLabel = "", onDone, onInserted }) {
const [query, setQuery] = useState("");
const [items, setItems] = useState([]);
const [connectors, setConnectors] = useState([]);
const [connectorId, setConnectorId] = useState("");
const [picked, setPicked] = useState(() => new Map());
const [pending, setPending] = useState(false);
const [error, setError] = useState("");
useEffect(() => {
api("/api/v1/connectors")
.then((data) => {
const paper = (data.items || []).filter((item) => item.kind === "paperless");
setConnectors(paper);
if (paper.length === 1) setConnectorId(paper[0].id);
})
.catch((err) => setError(err.message));
}, []);
async function search(event) {
event.preventDefault();
setError("");
if (connectors.length > 1 && !connectorId) {
setError("Wähle zuerst den Paperless-Zugang.");
return;
}
try {
const data = await api(`/api/v1/sources/paperless/documents?q=${encodeURIComponent(query)}`);
const params = new URLSearchParams({ q: query });
if (connectorId) params.set("connector_id", connectorId);
const data = await api(`/api/v1/sources/paperless/documents?${params}`);
setItems(data.items);
if (data.connector_id) setConnectorId(data.connector_id);
} catch (err) {
setError(err.message);
}
@@ -185,10 +243,11 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
context,
...(placement ? { placement } : {}),
...(chapterId ? { chapter_id: chapterId } : {}),
...(item.document_on || item.correspondent || item.open_url
...(item.document_on || item.correspondent || item.open_url || connectorId
? {
dates: { document_on: item.document_on || null, sent_on: null, received_on: null },
detail: {
...(connectorId ? { connector_id: connectorId } : {}),
...(item.correspondent ? { correspondent: item.correspondent } : {}),
...(item.open_url ? { open_url: item.open_url } : {}),
},
@@ -216,13 +275,24 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
}
return (
<div className="stack">
<TargetLine label={targetLabel} chapterId={chapterId} chapterTitle={chapterTitle} />
<SourceFrame targetLabel={targetLabel} chapterId={chapterId} chapterTitle={chapterTitle}>
{connectors.length > 1 ? (
<label>
Paperless-Zugang
<select value={connectorId} onChange={(event) => { setConnectorId(event.target.value); setItems([]); }}>
<option value="">Zugang wählen</option>
{connectors.map((item) => (
<option key={item.id} value={item.id}>{item.name}</option>
))}
</select>
</label>
) : null}
<form onSubmit={search} className="inline">
<input value={query} onChange={(event) => setQuery(event.target.value)} placeholder="Titel oder Stichwort" />
<button type="submit">Suchen</button>
</form>
<ErrorNote error={error} />
<p className="muted">{SEARCH_LIMITS.paperless}</p>
<p className="muted">Die Verbindung richtest du unter <Link to="/sources">Quellen</Link> ein. Mehrere Treffer lassen sich zusammen einfügen.</p>
{items.length || picked.size ? (
<button type="button" disabled={pending || picked.size === 0} onClick={linkMany}>
@@ -243,7 +313,7 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
</label>
))}
</div>
</div>
</SourceFrame>
);
}
@@ -539,8 +609,7 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
const selected = items.find((item) => `${mailbox}:${item.uid || item.id}` === selectedKey) || null;
return (
<div className="stack">
<TargetLine label={targetLabel} chapterId={chapterId} chapterTitle={chapterTitle} />
<SourceFrame targetLabel={targetLabel} chapterId={chapterId} chapterTitle={chapterTitle}>
<label>
Konto
<select value={accountId} onChange={(event) => setAccountId(event.target.value)}>
@@ -558,6 +627,7 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
<input value={draft} onChange={(event) => setDraft(event.target.value)} placeholder="Im gewählten Fach suchen" aria-label="Im gewählten Fach suchen" />
<button type="submit" className="quiet" disabled={!mailbox || !!loading}>Suchen</button>
</form>
<p className="muted">{SEARCH_LIMITS.imap}</p>
<ErrorNote error={error} />
{accountId && !loading && !mailbox && !error ? <p className="muted">Dieses Konto hat keine lesbaren Fächer.</p> : null}
{loading ? <p className="muted">{loading}</p> : null}
@@ -607,7 +677,7 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
)}
</aside>
</div>
</div>
</SourceFrame>
);
}
@@ -631,3 +701,8 @@ async function remove(id, load, setError) {
setError(err.message);
}
}
defineSourceModules([
{ kind: "paperless", title: "Paperless", addLabel: "Paperless", manual: true, searchHint: SEARCH_LIMITS.paperless, Form: PaperlessForm, Picker: PaperlessPicker },
{ kind: "imap", title: "E-Mail-Konto", addLabel: "E-Mail", wide: true, searchHint: SEARCH_LIMITS.imap, Form: MailForm, Picker: MailPicker },
]);
+12 -7
View File
@@ -1,7 +1,8 @@
import { useEffect, useLayoutEffect, useRef, useState } from "react";
import { createPortal } from "react-dom";
import { Link } from "react-router-dom";
import { api, fetchFile, fetchPaperless } from "../api.js";
import { api, fetchExternal, fetchFile } from "../api.js";
import { moduleFor } from "../sources/registry-core.js";
import { contentSourceSymbol, contentSymbol, symbolUrl } from "../content-symbol.mjs";
import { bezugCount, counterpartLabel, directionSymbol } from "../list-meta.mjs";
import { MarkdownView } from "../markdown.jsx";
@@ -307,20 +308,24 @@ const SYMBOL_LABEL = {
};
function elementSymbol(element) {
if (element?.external?.source === "imap") return "email";
const media = element?.preview?.media;
const representation = moduleFor(element?.external?.source)?.representation;
if (media === "email" || representation === "email") return "email";
return contentSymbol(element || {});
}
export function sourceLabel(element) {
const type = SYMBOL_LABEL[elementSymbol(element)] || "Datei";
if (element.external?.source === "paperless") return `${type} · Paperless`;
if (element.external?.source === "imap") return "E-Mail";
const module = moduleFor(element.external?.source);
if (module?.representation === "email") return module.addLabel || "E-Mail";
if (module) return `${type} · ${module.addLabel || module.title}`;
if (element.kind === "external_ref" && type === "Verweis") return "Referenz";
return type;
}
export function mailFacts(element) {
if (element?.external?.source !== "imap") return "";
const module = moduleFor(element?.external?.source);
if (element?.preview?.media !== "email" && module?.representation !== "email") return "";
const detail = element.external.detail || {};
const from = detail.message_from ? `Von: ${detail.message_from}` : "";
const to = detail.message_to ? `An: ${detail.message_to}` : "";
@@ -872,7 +877,7 @@ function EntryMark({ element, context, assignable = false, dropId = "", hot = fa
if (!photo) return undefined;
let alive = true;
let current = "";
const load = element.preview.source === "paperless" ? fetchPaperless(element.id, context) : fetchFile(element.id, context);
const load = element.kind === "external_ref" ? fetchExternal(element.id, context) : fetchFile(element.id, context);
load.then((blob) => {
if (!alive || !blob.type.startsWith("image/")) return;
current = URL.createObjectURL(blob);
@@ -1963,7 +1968,7 @@ export function ContentBoard({
async function placeReceipt(hostBinding, payload, element) {
if (!payload || payload.elementId === hostBinding.element.id) return;
const role = element?.external?.source === "imap" ? "email" : "other";
const role = moduleFor(element?.external?.source)?.representation === "email" ? "email" : "other";
setPending(true);
setError("");
try {
+2 -1
View File
@@ -1,6 +1,7 @@
import { useEffect, useMemo, useRef, useState } from "react";
import { Link } from "react-router-dom";
import { api } from "../api.js";
import { moduleFor } from "../sources/registry-core.js";
import { buildChapterSections, sectionCounts } from "./chapters.js";
function formatDate(value) {
@@ -65,7 +66,7 @@ export function receiptRoleLabel(role, fallback = "") {
}
function receiptCaption(proof) {
if (proof.role === "email" && proof.source !== "imap") return "Beleg";
if (proof.role === "email" && moduleFor(proof.source)?.representation !== "email") return "Beleg";
return receiptRoleLabel(proof.role, proof.role_label);
}
+9 -8
View File
@@ -1,6 +1,7 @@
import { useEffect, useRef, useState } from "react";
import { Link } from "react-router-dom";
import { api, documentToText, downloadFile, fetchPaperless, markDirty, textToDocument } from "../api.js";
import { api, documentToText, downloadFile, fetchExternal, markDirty, textToDocument } from "../api.js";
import { moduleFor } from "../sources/registry-core.js";
import { Modal } from "./Modal.jsx";
export function ErrorNote({ error }) {
@@ -53,11 +54,11 @@ function Binding({ binding, context, canEdit, isOwner, onChange }) {
if (previewUrl) URL.revokeObjectURL(previewUrl);
}, [previewUrl]);
async function viewPaperless() {
async function viewOriginal() {
setError("");
setViewing(true);
try {
const blob = await fetchPaperless(element.id, context);
const blob = await fetchExternal(element.id, context);
if (previewUrl) URL.revokeObjectURL(previewUrl);
setPreviewUrl(URL.createObjectURL(blob));
} catch (err) {
@@ -212,12 +213,12 @@ function Binding({ binding, context, canEdit, isOwner, onChange }) {
{element.kind === "external_ref" && element.external ? (
<div className="ref">
<p>
{element.external.source === "paperless" ? "Paperless" : element.external.source === "imap" ? "E-Mail" : "Externe Adresse"}
{moduleFor(element.external.source)?.addLabel || moduleFor(element.external.source)?.title || "Externe Adresse"}
{element.external.detail?.correspondent ? ` · ${element.external.detail.correspondent}` : ""}
{element.external.detail?.message_from ? ` · ${element.external.detail.message_from}` : ""}
</p>
{element.external.source === "paperless" ? (
<button type="button" onClick={viewPaperless}>Ansehen</button>
{moduleFor(element.external.source)?.representation && moduleFor(element.external.source).representation !== "email" ? (
<button type="button" onClick={viewOriginal}>Ansehen</button>
) : (
<span>Verknüpft, ohne die Quelle zu kopieren.</span>
)}
@@ -314,8 +315,8 @@ function kindLabel(element) {
const kind = element.kind;
if (kind === "note") return "Notiz";
if (kind === "file") return "Datei";
if (element.external?.source === "paperless") return "Paperless";
if (element.external?.source === "imap") return "E-Mail";
const module = moduleFor(element.external?.source);
if (module) return module.addLabel || module.title;
if (kind === "external_ref") return "Referenz";
return kind;
}