Führe die Konfigurationsansicht der Connectoren ein, damit Paperless und IMAP ihre Felder selbst deklarieren.
Das Modul liefert ein Feldmanifest und validiert es; ein leeres Geheimnisfeld behält das gespeicherte. Die Oberfläche rendert die Felder generisch in einer Detailansicht je Zugang mit Prüfstand, Fähigkeiten und Verwendung. Die providerspezifischen Formulare in Sources.jsx entfallen, die flachen API-Felder bleiben als Kompatibilität. Das Standardfach eines IMAP-Kontos öffnet der Picker zuerst. Die Backend-Tests wurden in der Entwicklungsumgebung nicht ausgeführt; der Lauf auf develop steht aus. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c29bd29f34
commit
eb58dce4cd
20 files changed
+1071
-244
No files matched your search
@@ -10,6 +10,7 @@ import { MatterList, MatterDetail } from "./pages/Matters.jsx";
|
||||
import { Rooms } from "./pages/Rooms.jsx";
|
||||
import { Search } from "./pages/Search.jsx";
|
||||
import { Sources } from "./pages/Sources.jsx";
|
||||
import { ConnectorConfig } from "./sources/connector-config.jsx";
|
||||
import { Users } from "./pages/Users.jsx";
|
||||
import { Work } from "./pages/Work.jsx";
|
||||
import { Settings } from "./pages/Settings.jsx";
|
||||
@@ -106,6 +107,7 @@ export function App() {
|
||||
<Route path="settings" element={<Settings />} />
|
||||
<Route path="rooms" element={<Rooms />} />
|
||||
<Route path="sources" element={<Sources />} />
|
||||
<Route path="sources/:connectorId" element={<ConnectorConfig />} />
|
||||
<Route path="users" element={<Users />} />
|
||||
<Route path="search" element={<Search />} />
|
||||
</Route>
|
||||
|
||||
+27
-158
@@ -1,8 +1,9 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
import { api, fetchBlob } from "../api.js";
|
||||
import { MailBody } from "../mail-view.jsx";
|
||||
import { SourceFrame, moduleFor, registerSourceModule, sourceModules } from "../sources/registry.jsx";
|
||||
import { NewConnector, useSourceModules } from "../sources/connector-config.jsx";
|
||||
import { SourceFrame, registerSourceModule } from "../sources/registry.jsx";
|
||||
|
||||
const SEARCH_LIMITS = {
|
||||
paperless: "Suchtext gilt für Titel und Dokumentinhalt. Zusätzlich gibt es Titel, Korrespondent, Dokumenttyp, Tags, Dokumentdatum und Sortierung.",
|
||||
@@ -15,10 +16,9 @@ import { ErrorNote } from "./widgets.jsx";
|
||||
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;
|
||||
const [adding, setAdding] = useState(false);
|
||||
const { modules, error: moduleError } = useSourceModules();
|
||||
const navigate = useNavigate();
|
||||
|
||||
async function load() {
|
||||
const data = await api("/api/v1/connectors");
|
||||
@@ -29,6 +29,8 @@ export function Sources() {
|
||||
load().catch((err) => setError(err.message));
|
||||
}, []);
|
||||
|
||||
const labels = new Map(modules.map((item) => [item.kind, item.label]));
|
||||
|
||||
return (
|
||||
<main className="page">
|
||||
<header className="page-head">
|
||||
@@ -36,145 +38,31 @@ export function Sources() {
|
||||
<h1>Quellen</h1>
|
||||
<p className="muted">Paperless und E-Mail-Konten bleiben bei dir. Eine Verknüpfung zeigt in der Akte nur Titel und Herkunft.</p>
|
||||
</div>
|
||||
{modules.length ? <button type="button" onClick={() => setAdding(true)} disabled={adding}>Quelle hinzufügen</button> : null}
|
||||
</header>
|
||||
<ErrorNote error={error} />
|
||||
{notice ? <p className="notice">{notice}</p> : null}
|
||||
<ErrorNote error={error || moduleError} />
|
||||
{adding ? (
|
||||
<NewConnector
|
||||
modules={modules}
|
||||
onCancel={() => setAdding(false)}
|
||||
onSaved={(saved) => navigate(`/sources/${saved.id}`)}
|
||||
/>
|
||||
) : null}
|
||||
{!items.length && !adding ? <p className="muted">Noch keine Quelle verbunden.</p> : null}
|
||||
<div className="tiles">
|
||||
{items.map((item) => (
|
||||
<article key={item.id} className="tile">
|
||||
<span className="tile__kind">{moduleFor(item.kind)?.title || item.kind}</span>
|
||||
<Link key={item.id} to={`/sources/${item.id}`} className="tile">
|
||||
<span className="tile__kind">{labels.get(item.kind) || item.kind}</span>
|
||||
<strong>{item.name}</strong>
|
||||
<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>
|
||||
<span>{item.probe ? (item.probe.ok ? "Zuletzt erreichbar" : "Letzte Prüfung fehlgeschlagen") : "Noch nicht geprüft"}</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
{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, 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 {
|
||||
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) {
|
||||
onError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={submit} className="stack">
|
||||
<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">{connectorId ? "Zugang dieser Instanz erneuern" : "Paperless-Instanz verbinden"}</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
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(settings?.security || initialSecurity);
|
||||
|
||||
async function submit(event) {
|
||||
event.preventDefault();
|
||||
onError("");
|
||||
try {
|
||||
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) {
|
||||
onError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={submit} className="stack">
|
||||
<label>Name <input value={name} onChange={(event) => setName(event.target.value)} placeholder="Postfach" /></label>
|
||||
<label>Server <input value={host} onChange={(event) => setHost(event.target.value)} placeholder="imap.example" required /></label>
|
||||
<label>Port <input value={port} onChange={(event) => setPort(event.target.value)} required /></label>
|
||||
<label>
|
||||
Verbindung
|
||||
<select value={security} onChange={(event) => setSecurity(event.target.value)}>
|
||||
<option value="ssl">SSL</option>
|
||||
<option value="starttls">STARTTLS</option>
|
||||
</select>
|
||||
</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">{connectorId ? "Zugang dieses Kontos erneuern" : "Konto hinzufügen"}</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function paperlessLabel(item) {
|
||||
const dated = formatDate(item.document_on);
|
||||
return dated !== "Ohne Datum" ? `${dated} · ${item.title}` : item.title;
|
||||
@@ -653,7 +541,9 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
if (!alive) return;
|
||||
const list = data.items || [];
|
||||
setFolders(list);
|
||||
const preferred = list.find((item) => item.selectable && item.name.toUpperCase() === "INBOX")
|
||||
const standard = accounts.find((item) => item.id === accountId)?.settings?.mailbox;
|
||||
const preferred = (standard && list.find((item) => item.selectable && item.name === standard))
|
||||
|| list.find((item) => item.selectable && item.name.toUpperCase() === "INBOX")
|
||||
|| list.find((item) => item.selectable);
|
||||
setMailbox(preferred ? preferred.name : "");
|
||||
if (!preferred) setLoading("");
|
||||
@@ -893,26 +783,5 @@ export function MailPicker({ context, placement, chapterId = "", chapterTitle =
|
||||
);
|
||||
}
|
||||
|
||||
async function probe(id, setNotice, setError) {
|
||||
setError("");
|
||||
setNotice("");
|
||||
try {
|
||||
const data = await api(`/api/v1/connectors/${id}/probe`, { method: "POST" });
|
||||
setNotice(data.detail);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(id, load, setError) {
|
||||
setError("");
|
||||
try {
|
||||
await api(`/api/v1/connectors/${id}`, { method: "DELETE" });
|
||||
await load();
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
registerSourceModule({ kind: "paperless", title: "Paperless", addLabel: "Paperless", manual: true, searchHint: SEARCH_LIMITS.paperless, Form: PaperlessForm, Picker: PaperlessPicker });
|
||||
registerSourceModule({ kind: "imap", title: "E-Mail-Konto", addLabel: "E-Mail", wide: true, searchHint: SEARCH_LIMITS.imap, Form: MailForm, Picker: MailPicker });
|
||||
registerSourceModule({ kind: "paperless", title: "Paperless", addLabel: "Paperless", manual: 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 });
|
||||
@@ -0,0 +1,48 @@
|
||||
// Pure helpers for module-declared configuration fields. No React, so Node can test them.
|
||||
|
||||
export function initialValues(fields, settings = null) {
|
||||
const values = {};
|
||||
for (const field of fields || []) {
|
||||
if (field.secret) {
|
||||
values[field.key] = "";
|
||||
continue;
|
||||
}
|
||||
const stored = settings?.[field.key];
|
||||
const value = stored ?? field.default ?? "";
|
||||
values[field.key] = String(value);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
// A blank secret is left out when an existing instance is edited: the server keeps the stored one.
|
||||
export function fieldsToPayload(fields, values, { editing = false } = {}) {
|
||||
const config = {};
|
||||
const missing = [];
|
||||
for (const field of fields || []) {
|
||||
const raw = values?.[field.key] ?? "";
|
||||
const blank = String(raw).trim() === "";
|
||||
if (blank) {
|
||||
if (field.secret && editing) continue;
|
||||
if (field.required) missing.push(field.label);
|
||||
continue;
|
||||
}
|
||||
if (field.type === "number") {
|
||||
const number = Number(String(raw).trim());
|
||||
config[field.key] = Number.isInteger(number) ? number : String(raw).trim();
|
||||
} else {
|
||||
config[field.key] = field.secret ? String(raw) : String(raw).trim();
|
||||
}
|
||||
}
|
||||
return { config, missing };
|
||||
}
|
||||
|
||||
export function missingMessage(missing) {
|
||||
if (!missing.length) return "";
|
||||
return missing.length === 1 ? `${missing[0]} fehlt.` : `Es fehlen: ${missing.join(", ")}.`;
|
||||
}
|
||||
|
||||
export function probeSummary(probe) {
|
||||
if (!probe) return "Noch nicht geprüft.";
|
||||
const state = probe.ok ? "Erreichbar" : "Fehlgeschlagen";
|
||||
return probe.detail ? `${state}: ${probe.detail}` : state;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { fieldsToPayload, initialValues, missingMessage, probeSummary } from "./config-core.js";
|
||||
|
||||
const fields = [
|
||||
{ key: "host", label: "Server", type: "text", required: true },
|
||||
{ key: "port", label: "Port", type: "number", required: true, default: 993 },
|
||||
{ key: "mailbox", label: "Standardfach", type: "text", default: "INBOX" },
|
||||
{ key: "password", label: "Passwort", type: "password", required: true, secret: true },
|
||||
];
|
||||
|
||||
test("new instances start with the declared defaults and an empty secret", () => {
|
||||
assert.deepEqual(initialValues(fields), { host: "", port: "993", mailbox: "INBOX", password: "" });
|
||||
});
|
||||
|
||||
test("stored settings win over defaults and a secret is never prefilled", () => {
|
||||
const values = initialValues(fields, { host: "mail.example.test", port: 143, password: "geheim" });
|
||||
assert.equal(values.host, "mail.example.test");
|
||||
assert.equal(values.port, "143");
|
||||
assert.equal(values.password, "");
|
||||
});
|
||||
|
||||
test("a new instance needs every required field including the secret", () => {
|
||||
const { config, missing } = fieldsToPayload(fields, { host: "h", port: "993", mailbox: "", password: "" });
|
||||
assert.deepEqual(missing, ["Passwort"]);
|
||||
assert.deepEqual(config, { host: "h", port: 993 });
|
||||
assert.equal(missingMessage(missing), "Passwort fehlt.");
|
||||
});
|
||||
|
||||
test("editing leaves a blank secret out so the server keeps the stored one", () => {
|
||||
const { config, missing } = fieldsToPayload(
|
||||
fields,
|
||||
{ host: " mail.example.test ", port: "143", mailbox: "Archiv", password: "" },
|
||||
{ editing: true },
|
||||
);
|
||||
assert.deepEqual(missing, []);
|
||||
assert.deepEqual(config, { host: "mail.example.test", port: 143, mailbox: "Archiv" });
|
||||
assert.equal("password" in config, false);
|
||||
});
|
||||
|
||||
test("a new secret is sent unchanged, a non-number stays a string for the server to refuse", () => {
|
||||
const { config } = fieldsToPayload(fields, { host: "h", port: "abc", mailbox: "", password: " pw " }, { editing: true });
|
||||
assert.equal(config.password, " pw ");
|
||||
assert.equal(config.port, "abc");
|
||||
});
|
||||
|
||||
test("the last check is summarised without inventing a state", () => {
|
||||
assert.equal(probeSummary(null), "Noch nicht geprüft.");
|
||||
assert.equal(probeSummary({ ok: true, detail: "Das Postfach ist erreichbar." }), "Erreichbar: Das Postfach ist erreichbar.");
|
||||
assert.equal(probeSummary({ ok: false, detail: "" }), "Fehlgeschlagen");
|
||||
});
|
||||
@@ -0,0 +1,108 @@
|
||||
import { useState } from "react";
|
||||
import { api } from "../api.js";
|
||||
import { ErrorNote } from "../pages/widgets.jsx";
|
||||
import { fieldsToPayload, initialValues, missingMessage } from "./config-core.js";
|
||||
import { moduleFor } from "./registry-core.js";
|
||||
|
||||
const INPUT_TYPES = { text: "text", url: "url", number: "number", password: "password" };
|
||||
|
||||
export function ConfigFields({ fields, values, onChange, editing = false, hasSecret = false, disabled = false }) {
|
||||
return (
|
||||
<>
|
||||
{fields.map((field) => {
|
||||
const id = `config-${field.key}`;
|
||||
const hint = field.secret && editing && hasSecret ? "Unverändert lassen, wenn der Schlüssel gleich bleibt." : field.help;
|
||||
return (
|
||||
<label key={field.key} htmlFor={id}>
|
||||
{field.label}
|
||||
{field.type === "select" ? (
|
||||
<select id={id} value={values[field.key] ?? ""} disabled={disabled} onChange={(event) => onChange(field.key, event.target.value)}>
|
||||
{field.options.map((option) => <option key={option.value} value={option.value}>{option.label}</option>)}
|
||||
</select>
|
||||
) : (
|
||||
<input
|
||||
id={id}
|
||||
type={INPUT_TYPES[field.type] || "text"}
|
||||
value={values[field.key] ?? ""}
|
||||
disabled={disabled}
|
||||
required={field.required && !(field.secret && editing && hasSecret)}
|
||||
autoComplete={field.secret ? "new-password" : "off"}
|
||||
placeholder={field.secret && editing && hasSecret ? "••••••••" : field.placeholder || ""}
|
||||
min={field.minimum ?? undefined}
|
||||
max={field.maximum ?? undefined}
|
||||
maxLength={field.type === "number" ? undefined : field.max_length}
|
||||
onChange={(event) => onChange(field.key, event.target.value)}
|
||||
/>
|
||||
)}
|
||||
{hint ? <span className="muted">{hint}</span> : null}
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// One form for a new or an existing instance. A module may bring its own `Form` instead.
|
||||
export function ConnectorForm({ module, connector = null, onSaved, onError }) {
|
||||
const fields = module.config_fields || [];
|
||||
const [name, setName] = useState(connector?.name || module.label || "");
|
||||
const [values, setValues] = useState(() => initialValues(fields, connector?.settings));
|
||||
const [pending, setPending] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const editing = Boolean(connector);
|
||||
const Custom = moduleFor(module.kind)?.Form;
|
||||
|
||||
if (Custom) {
|
||||
return <Custom connectorId={connector?.id || ""} initialName={connector?.name || module.label} settings={connector?.settings || null} onSaved={onSaved} onError={onError} />;
|
||||
}
|
||||
|
||||
async function submit(event) {
|
||||
event.preventDefault();
|
||||
setError("");
|
||||
onError?.("");
|
||||
const { config, missing } = fieldsToPayload(fields, values, { editing });
|
||||
if (!name.trim()) missing.unshift("Name");
|
||||
if (missing.length) {
|
||||
setError(missingMessage(missing));
|
||||
return;
|
||||
}
|
||||
setPending(true);
|
||||
try {
|
||||
const body = { kind: module.kind, name: name.trim(), config };
|
||||
const saved = editing
|
||||
? await api(`/api/v1/connectors/${connector.id}`, { method: "PATCH", body })
|
||||
: await api("/api/v1/connectors", { method: "POST", body });
|
||||
setValues((current) => {
|
||||
const next = { ...current };
|
||||
for (const field of fields) if (field.secret) next[field.key] = "";
|
||||
return next;
|
||||
});
|
||||
await onSaved?.(saved);
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={submit} className="stack">
|
||||
<label htmlFor="config-name">
|
||||
Name
|
||||
<input id="config-name" value={name} maxLength={120} required disabled={pending} onChange={(event) => setName(event.target.value)} />
|
||||
</label>
|
||||
<ConfigFields
|
||||
fields={fields}
|
||||
values={values}
|
||||
editing={editing}
|
||||
hasSecret={Boolean(connector?.has_secret)}
|
||||
disabled={pending}
|
||||
onChange={(key, value) => setValues((current) => ({ ...current, [key]: value }))}
|
||||
/>
|
||||
<ErrorNote error={error} />
|
||||
<div className="row">
|
||||
<button type="submit" disabled={pending}>{editing ? "Änderungen speichern" : `${module.label} verbinden`}</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link, useNavigate, useParams } from "react-router-dom";
|
||||
import { api } from "../api.js";
|
||||
import { ErrorNote } from "../pages/widgets.jsx";
|
||||
import { probeSummary } from "./config-core.js";
|
||||
import { ConnectorForm } from "./config-form.jsx";
|
||||
|
||||
export function useSourceModules() {
|
||||
const [modules, setModules] = useState([]);
|
||||
const [error, setError] = useState("");
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
api("/api/v1/sources/capabilities")
|
||||
.then((data) => {
|
||||
if (alive) setModules(data.modules || []);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (alive) setError(err.message);
|
||||
});
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, []);
|
||||
return { modules, error };
|
||||
}
|
||||
|
||||
const OPERATIONS = [
|
||||
["navigate", "Ordner und Struktur durchsuchen"],
|
||||
["read_preview", "Vorschau vor dem Übernehmen"],
|
||||
["read_original", "Original abrufen"],
|
||||
["read_attachment", "Anlagen abrufen"],
|
||||
["edit_content", "Inhalt in der Quelle bearbeiten"],
|
||||
["edit_metadata", "Metadaten in der Quelle bearbeiten"],
|
||||
];
|
||||
|
||||
const SEARCH_FILTERS = [
|
||||
["query", "Suchtext"],
|
||||
["title", "Titel"],
|
||||
["correspondent", "Korrespondent"],
|
||||
["document_type", "Dokumenttyp"],
|
||||
["tags", "Tags"],
|
||||
["document_range", "Dokumentdatum"],
|
||||
["sort", "Sortierung"],
|
||||
["continuation", "Weitere Seiten"],
|
||||
];
|
||||
|
||||
function Availability({ items, source }) {
|
||||
return (
|
||||
<ul className="plain-list">
|
||||
{items.map(([key, label]) => (
|
||||
<li key={key}>
|
||||
{label}: <strong>{source[key] ? "ja" : "nicht verfügbar"}</strong>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
export function NewConnector({ modules, onSaved, onCancel }) {
|
||||
const [kind, setKind] = useState(modules[0]?.kind || "");
|
||||
const module = modules.find((item) => item.kind === kind) || modules[0];
|
||||
const [error, setError] = useState("");
|
||||
if (!module) return <p className="muted">Es ist keine Quelle registriert.</p>;
|
||||
return (
|
||||
<section className="card stack" aria-label="Quelle hinzufügen">
|
||||
<h2>Quelle hinzufügen</h2>
|
||||
{modules.length > 1 ? (
|
||||
<label htmlFor="new-source-kind">
|
||||
Art der Quelle
|
||||
<select id="new-source-kind" value={module.kind} onChange={(event) => { setKind(event.target.value); setError(""); }}>
|
||||
{modules.map((item) => <option key={item.kind} value={item.kind}>{item.label}</option>)}
|
||||
</select>
|
||||
</label>
|
||||
) : null}
|
||||
<ErrorNote error={error} />
|
||||
<ConnectorForm key={module.kind} module={module} onSaved={onSaved} onError={setError} />
|
||||
{onCancel ? <button type="button" className="quiet" onClick={onCancel}>Abbrechen</button> : null}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function ConnectorConfig() {
|
||||
const { connectorId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const { modules, error: moduleError } = useSourceModules();
|
||||
const [connector, setConnector] = useState(null);
|
||||
const [error, setError] = useState("");
|
||||
const [notice, setNotice] = useState("");
|
||||
const [checking, setChecking] = useState(false);
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
|
||||
async function load() {
|
||||
setConnector(await api(`/api/v1/connectors/${connectorId}`));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setConnector(null);
|
||||
setError("");
|
||||
load().catch((err) => setError(err.message));
|
||||
}, [connectorId]);
|
||||
|
||||
async function check() {
|
||||
setChecking(true);
|
||||
setError("");
|
||||
setNotice("");
|
||||
try {
|
||||
const result = await api(`/api/v1/connectors/${connectorId}/probe`, { method: "POST" });
|
||||
setNotice(result.detail || "Die Verbindung wurde geprüft.");
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
} finally {
|
||||
setChecking(false);
|
||||
await load().catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
setError("");
|
||||
try {
|
||||
await api(`/api/v1/connectors/${connectorId}`, { method: "DELETE" });
|
||||
navigate("/sources");
|
||||
} catch (err) {
|
||||
setError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
const module = modules.find((item) => item.kind === connector?.kind);
|
||||
const capabilities = connector?.capabilities;
|
||||
|
||||
return (
|
||||
<main className="page">
|
||||
<header className="page-head">
|
||||
<div>
|
||||
<p className="muted"><Link to="/sources">Quellen</Link></p>
|
||||
<h1>{connector?.name || "Zugang"}</h1>
|
||||
{module ? <p className="muted">{module.label}</p> : null}
|
||||
</div>
|
||||
</header>
|
||||
<ErrorNote error={error || moduleError} />
|
||||
{notice ? <p className="notice" role="status">{notice}</p> : null}
|
||||
{connector && module ? (
|
||||
<div className="stack">
|
||||
<section className="card stack" aria-label="Zugang">
|
||||
<h2>Zugang</h2>
|
||||
<ConnectorForm
|
||||
key={`${connector.id}-${connector.name}-${connector.probe?.at || ""}`}
|
||||
module={module}
|
||||
connector={connector}
|
||||
onSaved={async () => { setNotice("Gespeichert. Die Instanz und ihre Verknüpfungen bleiben dieselben."); await load(); }}
|
||||
onError={setError}
|
||||
/>
|
||||
</section>
|
||||
<section className="card stack" aria-label="Verbindung">
|
||||
<h2>Verbindung</h2>
|
||||
<p>{probeSummary(connector.probe)}</p>
|
||||
{connector.probe?.at ? <p className="muted">Zuletzt geprüft: {new Date(connector.probe.at).toLocaleString("de-DE")}</p> : null}
|
||||
<div className="row">
|
||||
<button type="button" className="quiet" disabled={checking} onClick={check}>{checking ? "Prüft …" : "Verbindung prüfen"}</button>
|
||||
</div>
|
||||
</section>
|
||||
{capabilities ? (
|
||||
<section className="card stack" aria-label="Fähigkeiten">
|
||||
<h2>Fähigkeiten</h2>
|
||||
<Availability items={OPERATIONS} source={capabilities} />
|
||||
<h3>Suche</h3>
|
||||
<Availability items={SEARCH_FILTERS} source={capabilities.search || {}} />
|
||||
</section>
|
||||
) : null}
|
||||
<section className="card stack" aria-label="Verwendung und Schutz">
|
||||
<h2>Verwendung und Schutz</h2>
|
||||
<p>{connector.references === 1 ? "Eine eigene Verknüpfung nutzt diesen Zugang." : `${connector.references} eigene Verknüpfungen nutzen diesen Zugang.`}</p>
|
||||
<p className="muted">
|
||||
Zugangsdaten sind derzeit unverschlüsselt in der Datenbank abgelegt (Schutzprofil „{connector.protection_profile}“) und werden nie wieder angezeigt.
|
||||
</p>
|
||||
</section>
|
||||
<section className="card stack" aria-label="Entfernen">
|
||||
<h2>Entfernen</h2>
|
||||
{confirming ? (
|
||||
<>
|
||||
<p>
|
||||
{connector.references
|
||||
? `${connector.references} Verknüpfung(en) bleiben in den Akten stehen, lassen sich aber nicht mehr öffnen, bis ein anderer Zugang zugeordnet ist.`
|
||||
: "Dieser Zugang wird entfernt."}
|
||||
</p>
|
||||
<div className="row">
|
||||
<button type="button" className="danger" onClick={remove}>Endgültig entfernen</button>
|
||||
<button type="button" className="quiet" onClick={() => setConfirming(false)}>Abbrechen</button>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="row">
|
||||
<button type="button" className="danger" onClick={() => setConfirming(true)}>Zugang entfernen</button>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
) : !error ? (
|
||||
<p className="muted">Wird geladen …</p>
|
||||
) : null}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -1,33 +1,5 @@
|
||||
import { createElement, useState } from "react";
|
||||
import { api } from "../api.js";
|
||||
import { registerSourceModule, unregisterSourceModule } from "./registry-core.js";
|
||||
|
||||
function SampleForm({ onSaved, onError, connectorId = "", initialName = "Beispielquelle", settings = null }) {
|
||||
const [name, setName] = useState(initialName);
|
||||
const [catalog, setCatalog] = useState(settings?.catalog || "alpha");
|
||||
|
||||
async function submit(event) {
|
||||
event.preventDefault();
|
||||
onError("");
|
||||
try {
|
||||
const body = { kind: "sample", name, config: { catalog } };
|
||||
if (connectorId) await api(`/api/v1/connectors/${connectorId}`, { method: "PATCH", body });
|
||||
else await api("/api/v1/connectors", { method: "POST", body });
|
||||
await onSaved();
|
||||
} catch (err) {
|
||||
onError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
return createElement(
|
||||
"form",
|
||||
{ onSubmit: submit, className: "stack" },
|
||||
createElement("label", null, "Name ", createElement("input", { value: name, onChange: (event) => setName(event.target.value), required: true })),
|
||||
createElement("label", null, "Katalog ", createElement("input", { value: catalog, onChange: (event) => setCatalog(event.target.value), required: true })),
|
||||
createElement("button", { type: "submit" }, connectorId ? "Zugang erneuern" : "Beispielquelle verbinden"),
|
||||
);
|
||||
}
|
||||
|
||||
export function installSampleSource() {
|
||||
return registerSourceModule({
|
||||
kind: "sample",
|
||||
@@ -35,7 +7,6 @@ export function installSampleSource() {
|
||||
addLabel: "Beispielquelle",
|
||||
representation: "text",
|
||||
manual: true,
|
||||
Form: SampleForm,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1714,3 +1714,5 @@ button.pick-tree__twist {
|
||||
@media (max-width: 390px) {
|
||||
.source-filters label, .note-source__bar button, .note-editor button, .note-editor [role="radio"] { min-height: 44px; }
|
||||
}
|
||||
|
||||
.plain-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: 14px; }
|
||||
Reference in new issue
Block a user