Warne vor bereits eingefügten Quelldokumenten und biete Nicht einfügen, erneut einfügen oder zusätzliches Einbinden an.
Deploy Development / deploy (push) Successful in 44s
Deploy Development / deploy (push) Successful in 44s
Prüfstufen hier, darin, Umfeld stehen als Kontoeinstellung bereit. Der Server antwortet bei einem sicheren Treffer mit 409 und bindet auf Wunsch das vorhandene Element zusätzlich ein. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a6dc24d8fe
commit
f925661937
19 files changed
+748
-133
No files matched your search
+132
-49
@@ -5,6 +5,7 @@ import { api, fetchBlob } from "../api.js";
|
||||
import { MailBody } from "../mail-view.jsx";
|
||||
import { NewConnector, useSourceModules } from "../sources/connector-config.jsx";
|
||||
import { SourceFrame, registerSourceModule } from "../sources/registry.jsx";
|
||||
import { PresentNote, bindable, describeMatch, lookupPresent, presentKey, useExternalPlacement } from "../sources/duplicates.jsx";
|
||||
|
||||
const SEARCH_LIMITS = {
|
||||
paperless: "Die Suche läuft in Paperless selbst, über Titel und Inhalt, den Titel allein, den Inhalt allein oder den Volltextindex. Filter nach Korrespondent, Dokumenttyp, Speicherpfad, Tags, Dokumentdatum, Hinzugefügt-Datum und Archivnummer grenzen sie ein.",
|
||||
@@ -303,6 +304,9 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
const [total, setTotal] = useState(null);
|
||||
const [searched, setSearched] = useState(false);
|
||||
const [picked, setPicked] = useState(() => new Map());
|
||||
// Documents that are already present around the target, by presentKey. `review` holds the choices while the user decides.
|
||||
const [present, setPresent] = useState(() => new Map());
|
||||
const [review, setReview] = useState(null);
|
||||
const [previewKey, setPreviewKey] = useState("");
|
||||
const [previewUrl, setPreviewUrl] = useState("");
|
||||
const [pending, setPending] = useState(false);
|
||||
@@ -417,12 +421,33 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
setTotal(typeof data.total === "number" ? data.total : null);
|
||||
setSearched(true);
|
||||
if (!asked && data.connector_id) setConnectorId(data.connector_id);
|
||||
refreshPresent(data.items || [], asked || data.connector_id || "");
|
||||
} catch (err) {
|
||||
if (token !== searchRef.current) return;
|
||||
setError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
function presentEntry(item, bound = connectorId) {
|
||||
return { source: "paperless", external_id: String(item.id), connector_id: item.connector_id || bound };
|
||||
}
|
||||
|
||||
function matchesOf(item) {
|
||||
const entry = presentEntry(item);
|
||||
return present.get(presentKey(entry.source, entry.connector_id, entry.external_id)) || [];
|
||||
}
|
||||
|
||||
async function refreshPresent(list, bound) {
|
||||
const entries = list.map((item) => presentEntry(item, bound));
|
||||
const found = await lookupPresent(context, placement, entries);
|
||||
setPresent((current) => {
|
||||
const next = new Map(current);
|
||||
entries.forEach((entry) => next.delete(presentKey(entry.source, entry.connector_id, entry.external_id)));
|
||||
found.forEach((value, key) => next.set(key, value));
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
invalidate();
|
||||
closePreview();
|
||||
@@ -469,52 +494,82 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
}
|
||||
}
|
||||
|
||||
async function linkMany() {
|
||||
async function linkMany(choices = null) {
|
||||
const chosen = [...picked.values()];
|
||||
if (!chosen.length) return;
|
||||
setError("");
|
||||
const keyOf = (item) => `${item.connector_id || connectorId}:${item.id}`;
|
||||
if (!choices) {
|
||||
const known = chosen.filter((item) => matchesOf(item).length);
|
||||
if (known.length) {
|
||||
setReview(new Map(known.map((item) => [keyOf(item), "skip"])));
|
||||
return;
|
||||
}
|
||||
}
|
||||
setReview(null);
|
||||
setPending(true);
|
||||
const inserted = [];
|
||||
const skipped = [];
|
||||
const conflicts = [];
|
||||
try {
|
||||
for (const item of chosen) {
|
||||
await api("/api/v1/external-refs", {
|
||||
method: "POST",
|
||||
body: {
|
||||
title: item.title,
|
||||
source: "paperless",
|
||||
external_id: String(item.id),
|
||||
context,
|
||||
...(placement ? { placement } : {}),
|
||||
...(chapterId ? { chapter_id: chapterId } : {}),
|
||||
...(item.document_on || item.correspondent || item.open_url || connectorId
|
||||
? {
|
||||
dates: { document_on: item.document_on || null, sent_on: null, received_on: null },
|
||||
detail: {
|
||||
...(item.connector_id || connectorId ? { connector_id: item.connector_id || connectorId } : {}),
|
||||
...(item.correspondent ? { correspondent: item.correspondent } : {}),
|
||||
...(item.open_url ? { open_url: item.open_url } : {}),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
inserted.push(`${item.connector_id || connectorId}:${item.id}`);
|
||||
const key = keyOf(item);
|
||||
const choice = choices?.get(key);
|
||||
if (choice === "skip") {
|
||||
skipped.push(key);
|
||||
continue;
|
||||
}
|
||||
const existing = choice === "bind" ? bindable(matchesOf(item)) : null;
|
||||
try {
|
||||
await api("/api/v1/external-refs", {
|
||||
method: "POST",
|
||||
body: {
|
||||
title: item.title,
|
||||
source: "paperless",
|
||||
external_id: String(item.id),
|
||||
context,
|
||||
...(placement ? { placement } : {}),
|
||||
...(chapterId ? { chapter_id: chapterId } : {}),
|
||||
...(choice === "insert" ? { duplicate: "insert" } : {}),
|
||||
...(existing ? { bind_element_id: existing.element_id } : {}),
|
||||
...(item.document_on || item.correspondent || item.open_url || connectorId
|
||||
? {
|
||||
dates: { document_on: item.document_on || null, sent_on: null, received_on: null },
|
||||
detail: {
|
||||
...(item.connector_id || connectorId ? { connector_id: item.connector_id || connectorId } : {}),
|
||||
...(item.correspondent ? { correspondent: item.correspondent } : {}),
|
||||
...(item.open_url ? { open_url: item.open_url } : {}),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
inserted.push(key);
|
||||
} catch (err) {
|
||||
// Inserted by someone else in the meantime: ask again instead of failing.
|
||||
if (err.code !== "already_present") throw err;
|
||||
conflicts.push(item);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
if (conflicts.length) {
|
||||
await refreshPresent(conflicts, connectorId);
|
||||
setReview(new Map(conflicts.map((item) => [keyOf(item), "skip"])));
|
||||
}
|
||||
if (inserted.length) {
|
||||
setItems((current) => current.filter((item) => !inserted.includes(`${connectorId}:${item.id}`)));
|
||||
setPicked((current) => {
|
||||
const next = new Map(current);
|
||||
inserted.forEach((id) => next.delete(id));
|
||||
return next;
|
||||
});
|
||||
onInserted?.();
|
||||
}
|
||||
if (inserted.length === chosen.length) onDone();
|
||||
setPicked((current) => {
|
||||
const next = new Map(current);
|
||||
[...inserted, ...skipped].forEach((id) => next.delete(id));
|
||||
return next;
|
||||
});
|
||||
if (inserted.length && inserted.length + skipped.length === chosen.length) onDone();
|
||||
}
|
||||
|
||||
function setFilter(name, value) {
|
||||
@@ -706,8 +761,37 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
<ErrorNote error={error} />
|
||||
<p className="muted">{SEARCH_LIMITS.paperless}</p>
|
||||
<p className="muted">Die Verbindung richtest du unter <Link to="/sources">Quellen</Link> ein. Ausgewählte Belege bleiben erhalten, wenn du weiterblätterst oder neu suchst.</p>
|
||||
{review ? (
|
||||
<div className="card stack duplicate-panel" role="alert">
|
||||
<strong>Diese Belege sind schon vorhanden. Was soll geschehen?</strong>
|
||||
<ul className="duplicate-list">
|
||||
{[...picked.values()].filter((item) => review.has(`${item.connector_id || connectorId}:${item.id}`)).map((item) => {
|
||||
const key = `${item.connector_id || connectorId}:${item.id}`;
|
||||
const matches = matchesOf(item);
|
||||
return (
|
||||
<li key={key}>
|
||||
<span>{item.title}: {matches.length ? describeMatch(matches[0]) : "schon vorhanden"}</span>
|
||||
<select
|
||||
value={review.get(key)}
|
||||
aria-label={`Entscheidung für ${item.title}`}
|
||||
onChange={(event) => setReview((current) => new Map(current).set(key, event.target.value))}
|
||||
>
|
||||
<option value="skip">Nicht einfügen</option>
|
||||
<option value="insert">Trotzdem erneut einfügen</option>
|
||||
{bindable(matches) ? <option value="bind">Vorhandenes zusätzlich einbinden</option> : null}
|
||||
</select>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
<div className="row">
|
||||
<button type="button" className="quiet" disabled={pending} onClick={() => setReview(null)}>Zurück zur Auswahl</button>
|
||||
<button type="button" disabled={pending} onClick={() => linkMany(review)}>Entscheidung ausführen</button>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
{items.length || picked.size ? (
|
||||
<button type="button" disabled={pending || picked.size === 0} onClick={linkMany}>
|
||||
<button type="button" disabled={pending || picked.size === 0 || Boolean(review)} onClick={() => linkMany()}>
|
||||
{picked.size ? `${picked.size} Belege einfügen` : "Belege auswählen"}
|
||||
</button>
|
||||
) : null}
|
||||
@@ -745,6 +829,7 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
</button>
|
||||
<div className="paperless-card__body">
|
||||
<strong>{item.title}</strong>
|
||||
<PresentNote matches={matchesOf(item)} />
|
||||
{facts.length ? <span className="paperless-card__facts">{facts.join(" · ")}</span> : null}
|
||||
{item.tags?.length ? (
|
||||
<ul className="paperless-card__tags" aria-label="Tags">
|
||||
@@ -901,6 +986,7 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
const [preview, setPreview] = useState(null);
|
||||
const [previewError, setPreviewError] = useState("");
|
||||
const [adopting, setAdopting] = useState(false);
|
||||
const { place, panel } = useExternalPlacement({ context, placement, onPlaced: () => onDone() });
|
||||
const [loading, setLoading] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const requestRef = useRef(0);
|
||||
@@ -1083,26 +1169,22 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
if (cc) detail.message_cc = cc;
|
||||
if (attachments.length) detail.attachments = attachments;
|
||||
try {
|
||||
await api("/api/v1/external-refs", {
|
||||
method: "POST",
|
||||
body: {
|
||||
title: item.title,
|
||||
source: "imap",
|
||||
external_id: item.id,
|
||||
context,
|
||||
...(placement ? { placement } : {}),
|
||||
...(chapterId ? { chapter_id: chapterId } : {}),
|
||||
...(item.document_on ? {
|
||||
dates: {
|
||||
document_on: item.document_on,
|
||||
sent_on: direction === "out" ? item.document_on : null,
|
||||
received_on: direction === "in" ? item.document_on : null,
|
||||
},
|
||||
} : {}),
|
||||
detail,
|
||||
},
|
||||
await place({
|
||||
title: item.title,
|
||||
source: "imap",
|
||||
external_id: item.id,
|
||||
context,
|
||||
...(placement ? { placement } : {}),
|
||||
...(chapterId ? { chapter_id: chapterId } : {}),
|
||||
...(item.document_on ? {
|
||||
dates: {
|
||||
document_on: item.document_on,
|
||||
sent_on: direction === "out" ? item.document_on : null,
|
||||
received_on: direction === "in" ? item.document_on : null,
|
||||
},
|
||||
} : {}),
|
||||
detail,
|
||||
});
|
||||
onDone();
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
@@ -1183,6 +1265,7 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
{selected && !preview && !previewError ? <p className="muted">Vorschau wird geladen …</p> : null}
|
||||
{preview ? <MailBody html={preview.html} text={preview.text} truncated={preview.text_truncated} notices={preview.notices} /> : null}
|
||||
<ErrorNote error={error} />
|
||||
{panel}
|
||||
<button type="button" onClick={() => link(selected)} disabled={!selected.uid || adopting}>{adopting ? "Wird übernommen …" : "Übernehmen"}</button>
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user