Filtere Paperless-Dokumente nach Zusatzfeldern und öffne die Auswahl als großen Dialog mit Filtern links und Treffern rechts.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9089d830b3
commit
f580fb282d
11 files changed
+386
-13
No files matched your search
@@ -93,7 +93,7 @@ const PAPERLESS_MODE_HINTS = {
|
||||
index: "Der Volltextindex von Paperless findet ganze Wörter, auch mit AND, OR und Anführungszeichen, und ordnet nach Relevanz. Ein neues Dokument erscheint erst, wenn Paperless es indexiert hat.",
|
||||
};
|
||||
|
||||
const NO_FACETS = { correspondents: [], document_types: [], storage_paths: [], tags: [] };
|
||||
const NO_FACETS = { correspondents: [], document_types: [], storage_paths: [], tags: [], custom_fields: [] };
|
||||
|
||||
const EMPTY_FILTERS = {
|
||||
query: "",
|
||||
@@ -109,6 +109,7 @@ const EMPTY_FILTERS = {
|
||||
addedFrom: "",
|
||||
addedTo: "",
|
||||
asn: "",
|
||||
custom: [],
|
||||
sort: "-created",
|
||||
};
|
||||
|
||||
@@ -124,7 +125,128 @@ function activeFilterCount(filters) {
|
||||
filters.addedFrom,
|
||||
filters.addedTo,
|
||||
filters.asn.trim(),
|
||||
].filter(Boolean).length;
|
||||
].filter(Boolean).length + customPayload(filters.custom).length;
|
||||
}
|
||||
|
||||
const CUSTOM_KINDS = {
|
||||
string: "text",
|
||||
url: "text",
|
||||
longtext: "text",
|
||||
integer: "number",
|
||||
float: "number",
|
||||
monetary: "number",
|
||||
date: "date",
|
||||
boolean: "boolean",
|
||||
select: "select",
|
||||
};
|
||||
|
||||
const CUSTOM_OPERATORS = {
|
||||
text: [["icontains", "enthält"], ["exact", "ist gleich"], ["istartswith", "beginnt mit"], ["iendswith", "endet mit"]],
|
||||
number: [["exact", "gleich"], ["gte", "mindestens"], ["lte", "höchstens"], ["gt", "größer als"], ["lt", "kleiner als"], ["range", "zwischen"]],
|
||||
date: [["exact", "am"], ["gte", "ab"], ["lte", "bis"], ["gt", "nach"], ["lt", "vor"], ["range", "zwischen"]],
|
||||
boolean: [["exact", "ist"]],
|
||||
select: [["exact", "ist"]],
|
||||
};
|
||||
|
||||
const CUSTOM_PRESENCE = [["set", "hat einen Wert"], ["unset", "ist leer"]];
|
||||
const CUSTOM_LIMIT = 5;
|
||||
|
||||
function customKind(field) {
|
||||
return CUSTOM_KINDS[field?.type] || "text";
|
||||
}
|
||||
|
||||
// Only rows that are complete go to the server. An empty row is a row not filled in yet.
|
||||
function customPayload(rows) {
|
||||
const payload = [];
|
||||
for (const row of rows) {
|
||||
if (!row.field) continue;
|
||||
if (row.op === "set" || row.op === "unset") {
|
||||
payload.push({ field: row.field, op: "exists", value: row.op === "set" });
|
||||
} else if (row.op === "range") {
|
||||
if (row.value && row.value2) payload.push({ field: row.field, op: "range", value: [row.value, row.value2] });
|
||||
} else if (row.kind === "boolean") {
|
||||
payload.push({ field: row.field, op: "exact", value: row.value !== "false" });
|
||||
} else if (String(row.value).trim()) {
|
||||
payload.push({ field: row.field, op: row.op, value: String(row.value).trim() });
|
||||
}
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
function CustomFieldFilters({ fields, rows, onChange }) {
|
||||
if (!fields.length) return null;
|
||||
const byId = new Map(fields.map((item) => [item.id, item]));
|
||||
|
||||
function update(key, patch) {
|
||||
onChange(rows.map((row) => (row.key === key ? { ...row, ...patch } : row)));
|
||||
}
|
||||
|
||||
function choose(key, id) {
|
||||
const field = byId.get(id);
|
||||
const kind = customKind(field);
|
||||
const first = field ? CUSTOM_OPERATORS[kind][0][0] : "";
|
||||
update(key, { field: id, kind, op: first, value: kind === "boolean" ? "true" : "", value2: "" });
|
||||
}
|
||||
|
||||
function add() {
|
||||
onChange([...rows, { key: `${Date.now()}-${rows.length}`, field: "", kind: "text", op: "", value: "", value2: "" }]);
|
||||
}
|
||||
|
||||
return (
|
||||
<fieldset className="paperless-custom">
|
||||
<legend>Zusatzfelder, alle Bedingungen zugleich</legend>
|
||||
{rows.map((row) => {
|
||||
const field = byId.get(row.field);
|
||||
const kind = customKind(field);
|
||||
const value = (name, label) => {
|
||||
if (kind === "boolean") {
|
||||
return (
|
||||
<select aria-label={label} value={row.value} onChange={(event) => update(row.key, { [name]: event.target.value })}>
|
||||
<option value="true">Ja</option>
|
||||
<option value="false">Nein</option>
|
||||
</select>
|
||||
);
|
||||
}
|
||||
if (kind === "select") {
|
||||
return (
|
||||
<select aria-label={label} value={row.value} onChange={(event) => update(row.key, { [name]: event.target.value })}>
|
||||
<option value="">Wert wählen</option>
|
||||
{(field.options || []).map((option) => <option key={option.id} value={option.id}>{option.name}</option>)}
|
||||
</select>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<input
|
||||
aria-label={label}
|
||||
type={kind === "date" ? "date" : "text"}
|
||||
inputMode={kind === "number" ? "decimal" : undefined}
|
||||
value={name === "value" ? row.value : row.value2}
|
||||
onChange={(event) => update(row.key, { [name]: event.target.value })}
|
||||
/>
|
||||
);
|
||||
};
|
||||
const presence = row.op === "set" || row.op === "unset";
|
||||
return (
|
||||
<div key={row.key} className="paperless-custom__row">
|
||||
<select aria-label="Zusatzfeld" value={row.field} onChange={(event) => choose(row.key, event.target.value)}>
|
||||
<option value="">Feld wählen</option>
|
||||
{fields.map((item) => <option key={item.id} value={item.id}>{item.name}</option>)}
|
||||
</select>
|
||||
{field ? (
|
||||
<select aria-label="Bedingung" value={row.op} onChange={(event) => update(row.key, { op: event.target.value })}>
|
||||
{CUSTOM_OPERATORS[kind].map(([op, label]) => <option key={op} value={op}>{label}</option>)}
|
||||
{CUSTOM_PRESENCE.map(([op, label]) => <option key={op} value={op}>{label}</option>)}
|
||||
</select>
|
||||
) : null}
|
||||
{field && !presence ? value("value", row.op === "range" ? "Von" : "Wert") : null}
|
||||
{field && row.op === "range" ? value("value2", "Bis") : null}
|
||||
<button type="button" className="quiet" onClick={() => onChange(rows.filter((item) => item.key !== row.key))}>Entfernen</button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{rows.length < CUSTOM_LIMIT ? <button type="button" className="quiet" onClick={add}>Zusatzfeld-Bedingung hinzufügen</button> : null}
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
|
||||
// The thumbnail comes through the server like every other Paperless call, so the key stays there.
|
||||
@@ -230,6 +352,8 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
if (filters.addedFrom) params.set("added_from", filters.addedFrom);
|
||||
if (filters.addedTo) params.set("added_to", filters.addedTo);
|
||||
if (filters.asn.trim()) params.set("asn", filters.asn.trim());
|
||||
const custom = customPayload(filters.custom);
|
||||
if (custom.length) params.set("custom", JSON.stringify(custom));
|
||||
if (filters.sort === "-score") {
|
||||
if (text && filters.mode === "index") params.set("sort", "-score");
|
||||
} else if (filters.sort) {
|
||||
@@ -404,6 +528,8 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
|
||||
return (
|
||||
<SourceFrame targetLabel={targetLabel} chapterId={chapterId} chapterTitle={chapterTitle}>
|
||||
<div className="paperless-layout">
|
||||
<aside className="paperless-layout__filters" aria-label="Suche und Filter">
|
||||
{connectors.length > 1 ? (
|
||||
<label>
|
||||
Paperless-Zugang
|
||||
@@ -442,7 +568,7 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
<button type="submit">Suchen</button>
|
||||
</div>
|
||||
<p className="muted">{PAPERLESS_MODE_HINTS[filters.mode]}</p>
|
||||
<details className="paperless-more" open={active > 0 ? true : undefined}>
|
||||
<details className="paperless-more" open>
|
||||
<summary>{active ? `Weitere Filter (${active} aktiv)` : "Weitere Filter"}</summary>
|
||||
<div className="source-filters">
|
||||
<label>
|
||||
@@ -503,6 +629,7 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
Archivnummer (ASN)
|
||||
<input inputMode="numeric" value={filters.asn} onChange={(event) => setFilter("asn", event.target.value)} />
|
||||
</label>
|
||||
<CustomFieldFilters fields={facets.custom_fields || []} rows={filters.custom} onChange={(rows) => setFilter("custom", rows)} />
|
||||
</div>
|
||||
</details>
|
||||
<label>
|
||||
@@ -521,6 +648,8 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
<button type="button" className="quiet" onClick={resetFilters}>Filter zurücksetzen</button>
|
||||
</div>
|
||||
</form>
|
||||
</aside>
|
||||
<section className="paperless-layout__results" aria-label="Treffer">
|
||||
<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>
|
||||
@@ -591,6 +720,8 @@ export function PaperlessPicker({ context, placement, chapterId = "", chapterTit
|
||||
{nextPage ? <button type="button" onClick={(event) => runSearch(event, nextPage)}>Weitere Treffer</button> : null}
|
||||
</div>
|
||||
) : null}
|
||||
</section>
|
||||
</div>
|
||||
</SourceFrame>
|
||||
);
|
||||
}
|
||||
@@ -998,5 +1129,5 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
);
|
||||
}
|
||||
|
||||
registerSourceModule({ kind: "paperless", title: "Paperless", addLabel: "Paperless", manual: true, searchHint: SEARCH_LIMITS.paperless, Picker: PaperlessPicker });
|
||||
registerSourceModule({ kind: "paperless", title: "Paperless", addLabel: "Paperless", manual: true, large: true, searchHint: SEARCH_LIMITS.paperless, Picker: PaperlessPicker });
|
||||
registerSourceModule({ kind: "imap", title: "E-Mail-Konto", addLabel: "E-Mail", wide: true, searchHint: SEARCH_LIMITS.imap, Picker: MailPicker });
|
||||
Reference in new issue
Block a user