Mache die Akte zum Sammler und binde Paperless sowie E-Mail an.
Deploy Development / deploy (push) Successful in 22s
Deploy Development / deploy (push) Successful in 22s
Erfassen liegt in Dialogen, Vorgaenge erscheinen als Kacheln in der Akte, und Quellen lassen Dokumente und IMAP-Nachrichten verknuepfen. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
332be8376e
commit
b03f571cd8
16 files changed
+1040
-149
No files matched your search
@@ -702,6 +702,7 @@ def post_external(body: ExternalIn, principal: Principal = Depends(get_principal
|
|||||||
body.dates.document_on,
|
body.dates.document_on,
|
||||||
body.dates.sent_on,
|
body.dates.sent_on,
|
||||||
body.dates.received_on,
|
body.dates.received_on,
|
||||||
|
body.detail.model_dump(exclude_none=True) if body.detail else None,
|
||||||
)
|
)
|
||||||
return _created(f"/api/v1/elements/{element['id']}", {"id": str(element["id"]), "title": element["title"]})
|
return _created(f"/api/v1/elements/{element['id']}", {"id": str(element["id"]), "title": element["title"]})
|
||||||
|
|
||||||
|
|||||||
@@ -144,14 +144,34 @@ class DatesIn(APIModel):
|
|||||||
received_on: date | None = None
|
received_on: date | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class ExternalDetail(APIModel):
|
||||||
|
correspondent: str | None = Field(default=None, max_length=200)
|
||||||
|
message_from: str | None = Field(default=None, max_length=200)
|
||||||
|
open_url: str | None = Field(default=None, max_length=500, pattern=r"^https?://")
|
||||||
|
|
||||||
|
|
||||||
class ExternalIn(APIModel):
|
class ExternalIn(APIModel):
|
||||||
title: str = Field(min_length=1, max_length=200)
|
title: str = Field(min_length=1, max_length=200)
|
||||||
source: Literal["paperless", "url"]
|
source: Literal["paperless", "url", "imap"]
|
||||||
external_id: str = Field(min_length=1, max_length=200)
|
external_id: str = Field(min_length=1, max_length=200)
|
||||||
context: ContextIn
|
context: ContextIn
|
||||||
placement: ContextIn | None = None
|
placement: ContextIn | None = None
|
||||||
chapter_id: UUID | None = None
|
chapter_id: UUID | None = None
|
||||||
dates: DatesIn = DatesIn()
|
dates: DatesIn = DatesIn()
|
||||||
|
detail: ExternalDetail | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class ConnectorIn(APIModel):
|
||||||
|
kind: Literal["paperless", "imap"]
|
||||||
|
name: str = Field(min_length=1, max_length=120)
|
||||||
|
base_url: str | None = None
|
||||||
|
token: str | None = None
|
||||||
|
host: str | None = None
|
||||||
|
port: int | None = Field(default=None, ge=1, le=65535)
|
||||||
|
username: str | None = None
|
||||||
|
password: str | None = None
|
||||||
|
mailbox: str | None = Field(default=None, max_length=200)
|
||||||
|
security: Literal["ssl", "starttls"] | None = None
|
||||||
|
|
||||||
|
|
||||||
class DeleteElementIn(APIModel):
|
class DeleteElementIn(APIModel):
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
"""Connector administration and live Paperless / IMAP lookup."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends
|
||||||
|
from psycopg import Connection
|
||||||
|
|
||||||
|
from app.access.policy import Ctx
|
||||||
|
from app.api.deps import Principal, get_conn, get_principal
|
||||||
|
from app.api.routes import _created, _ctx_model
|
||||||
|
from app.api.schemas import ConnectorIn, ExternalIn
|
||||||
|
from app.core.errors import unprocessable
|
||||||
|
from app.ops import create_external
|
||||||
|
from app.sources import (
|
||||||
|
clean_base_url,
|
||||||
|
delete_connector,
|
||||||
|
imap_messages,
|
||||||
|
list_connectors,
|
||||||
|
paperless_documents,
|
||||||
|
probe,
|
||||||
|
save_connector,
|
||||||
|
)
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/api/v1/connectors")
|
||||||
|
def get_connectors(principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||||
|
return {"items": list_connectors(conn, principal.account_id)}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/api/v1/connectors", status_code=201)
|
||||||
|
def post_connector(body: ConnectorIn, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||||
|
name, settings, secret = _connector_parts(body)
|
||||||
|
row = save_connector(conn, principal.account_id, body.kind, name, settings, secret)
|
||||||
|
return row
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/api/v1/connectors/{connector_id}", status_code=204)
|
||||||
|
def remove_connector(connector_id: UUID, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||||
|
delete_connector(conn, principal.account_id, connector_id)
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/api/v1/connectors/{connector_id}/probe")
|
||||||
|
def probe_connector(connector_id: UUID, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||||
|
return probe(conn, principal.account_id, connector_id)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/api/v1/sources/paperless/documents")
|
||||||
|
def search_paperless(q: str = "", principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||||
|
return {"items": paperless_documents(conn, principal.account_id, q.strip())}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/api/v1/sources/imap/messages")
|
||||||
|
def search_mail(
|
||||||
|
connector_id: UUID,
|
||||||
|
q: str = "",
|
||||||
|
principal: Principal = Depends(get_principal),
|
||||||
|
conn: Connection = Depends(get_conn),
|
||||||
|
):
|
||||||
|
return {"items": imap_messages(conn, principal.account_id, connector_id, q.strip())}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/api/v1/sources/link", status_code=201)
|
||||||
|
def link_source(body: ExternalIn, principal: Principal = Depends(get_principal), conn: Connection = Depends(get_conn)):
|
||||||
|
if body.source not in {"paperless", "imap"}:
|
||||||
|
raise unprocessable("Verknüpft werden Paperless-Dokumente und E-Mails.")
|
||||||
|
element = create_external(
|
||||||
|
conn,
|
||||||
|
principal.account_id,
|
||||||
|
principal.scope_id,
|
||||||
|
body.title,
|
||||||
|
body.source,
|
||||||
|
body.external_id,
|
||||||
|
Ctx(body.context.kind, body.context.id),
|
||||||
|
_ctx_model(body.placement),
|
||||||
|
body.chapter_id,
|
||||||
|
body.dates.document_on,
|
||||||
|
body.dates.sent_on,
|
||||||
|
body.dates.received_on,
|
||||||
|
body.detail.model_dump(exclude_none=True) if body.detail else None,
|
||||||
|
)
|
||||||
|
return _created(f"/api/v1/elements/{element['id']}", {"id": str(element["id"]), "title": element["title"]})
|
||||||
|
|
||||||
|
|
||||||
|
def _connector_parts(body: ConnectorIn) -> tuple[str, dict, str]:
|
||||||
|
if body.kind == "paperless":
|
||||||
|
if not body.base_url or not body.token or len(body.token.strip()) < 8:
|
||||||
|
raise unprocessable("Paperless braucht eine Adresse und einen API-Schlüssel.")
|
||||||
|
return body.name.strip(), {"base_url": clean_base_url(body.base_url)}, body.token.strip()
|
||||||
|
if not body.host or not body.username or not body.password:
|
||||||
|
raise unprocessable("Ein E-Mail-Konto braucht Server, Benutzername und Passwort.")
|
||||||
|
host = body.host.strip()
|
||||||
|
if " " in host or len(host) > 200:
|
||||||
|
raise unprocessable("Der Mailserver ist ungültig.")
|
||||||
|
return body.name.strip(), {
|
||||||
|
"host": host,
|
||||||
|
"port": body.port or 993,
|
||||||
|
"username": body.username.strip(),
|
||||||
|
"mailbox": (body.mailbox or "INBOX").strip() or "INBOX",
|
||||||
|
"security": body.security or "ssl",
|
||||||
|
}, body.password
|
||||||
@@ -10,6 +10,7 @@ from fastapi.exceptions import RequestValidationError
|
|||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
|
|
||||||
from app.api.routes import router
|
from app.api.routes import router
|
||||||
|
from app.api.sources import router as sources_router
|
||||||
from app.core.errors import Problem, problem_response
|
from app.core.errors import Problem, problem_response
|
||||||
from app.core.settings import get_settings
|
from app.core.settings import get_settings
|
||||||
from app.db.pool import open_pool
|
from app.db.pool import open_pool
|
||||||
@@ -113,6 +114,7 @@ def create_app() -> FastAPI:
|
|||||||
)
|
)
|
||||||
|
|
||||||
app.include_router(router)
|
app.include_router(router)
|
||||||
|
app.include_router(sources_router)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -526,13 +526,13 @@ def add_annotation(conn, actor: UUID, binding_id: UUID, body: str, context: Ctx
|
|||||||
return row
|
return row
|
||||||
|
|
||||||
|
|
||||||
def create_external(conn, actor: UUID, scope_id: UUID, title: str, source: str, external_id: str, context: Ctx, placement: Ctx | None, chapter_id: UUID | None, document_on, sent_on, received_on) -> dict:
|
def create_external(conn, actor: UUID, scope_id: UUID, title: str, source: str, external_id: str, context: Ctx, placement: Ctx | None, chapter_id: UUID | None, document_on, sent_on, received_on, detail: dict | None = None) -> dict:
|
||||||
target, rights_context = _placement(context, placement)
|
target, rights_context = _placement(context, placement)
|
||||||
require_container_edit(conn, actor, target, rights_context)
|
require_container_edit(conn, actor, target, rights_context)
|
||||||
element = _new_element(conn, actor, scope_id, title, "external_ref")
|
element = _new_element(conn, actor, scope_id, title, "external_ref")
|
||||||
conn.execute(
|
conn.execute(
|
||||||
"INSERT INTO external_references (element_id, source, external_id) VALUES (%s, %s, %s)",
|
"INSERT INTO external_references (element_id, source, external_id, detail) VALUES (%s, %s, %s, %s)",
|
||||||
(element["id"], source, external_id.strip()),
|
(element["id"], source, external_id.strip()[:200], Json(detail or {})),
|
||||||
)
|
)
|
||||||
binding = insert_binding(conn, element["id"], target.kind, target.id, chapter_id, actor)
|
binding = insert_binding(conn, element["id"], target.kind, target.id, chapter_id, actor)
|
||||||
record_dates(conn, actor, scope_id, element["id"], rights_context or target, document_on, sent_on, received_on)
|
record_dates(conn, actor, scope_id, element["id"], rights_context or target, document_on, sent_on, received_on)
|
||||||
|
|||||||
@@ -104,11 +104,15 @@ def _element_body(conn, element: dict) -> dict:
|
|||||||
}
|
}
|
||||||
elif element["kind"] == "external_ref":
|
elif element["kind"] == "external_ref":
|
||||||
ref = conn.execute(
|
ref = conn.execute(
|
||||||
"SELECT source, external_id FROM external_references WHERE element_id = %s",
|
"SELECT source, external_id, detail FROM external_references WHERE element_id = %s",
|
||||||
(element["id"],),
|
(element["id"],),
|
||||||
).fetchone()
|
).fetchone()
|
||||||
if ref is not None:
|
if ref is not None:
|
||||||
payload["external"] = {"source": ref["source"], "external_id": ref["external_id"]}
|
payload["external"] = {
|
||||||
|
"source": ref["source"],
|
||||||
|
"external_id": ref["external_id"],
|
||||||
|
"detail": ref["detail"] or {},
|
||||||
|
}
|
||||||
return payload
|
return payload
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,236 @@
|
|||||||
|
"""Paperless and IMAP connectors. Secrets stay on the server."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import imaplib
|
||||||
|
import json
|
||||||
|
import ssl
|
||||||
|
from email.header import decode_header
|
||||||
|
from email.parser import BytesParser
|
||||||
|
from urllib.error import HTTPError, URLError
|
||||||
|
from urllib.parse import urlencode, urlparse
|
||||||
|
from urllib.request import Request, urlopen
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
from psycopg.types.json import Json
|
||||||
|
|
||||||
|
from app.core.errors import not_found, unprocessable
|
||||||
|
|
||||||
|
|
||||||
|
def save_connector(conn, owner_id: UUID, kind: str, name: str, settings: dict, secret: str) -> dict:
|
||||||
|
if kind == "paperless":
|
||||||
|
existing = conn.execute(
|
||||||
|
"SELECT id FROM connectors WHERE owner_id = %s AND kind = 'paperless'",
|
||||||
|
(owner_id,),
|
||||||
|
).fetchone()
|
||||||
|
if existing:
|
||||||
|
row = conn.execute(
|
||||||
|
"""
|
||||||
|
UPDATE connectors
|
||||||
|
SET name = %s, settings = %s, secret = %s
|
||||||
|
WHERE id = %s
|
||||||
|
RETURNING id, kind, name, settings, created_at
|
||||||
|
""",
|
||||||
|
(name, Json(settings), secret, existing["id"]),
|
||||||
|
).fetchone()
|
||||||
|
return _public(row)
|
||||||
|
row = conn.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO connectors (owner_id, kind, name, settings, secret)
|
||||||
|
VALUES (%s, %s, %s, %s, %s)
|
||||||
|
RETURNING id, kind, name, settings, created_at
|
||||||
|
""",
|
||||||
|
(owner_id, kind, name, Json(settings), secret),
|
||||||
|
).fetchone()
|
||||||
|
return _public(row)
|
||||||
|
|
||||||
|
|
||||||
|
def list_connectors(conn, owner_id: UUID) -> list[dict]:
|
||||||
|
rows = conn.execute(
|
||||||
|
"""
|
||||||
|
SELECT id, kind, name, settings, created_at
|
||||||
|
FROM connectors WHERE owner_id = %s
|
||||||
|
ORDER BY kind, name
|
||||||
|
""",
|
||||||
|
(owner_id,),
|
||||||
|
).fetchall()
|
||||||
|
return [_public(row) for row in rows]
|
||||||
|
|
||||||
|
|
||||||
|
def delete_connector(conn, owner_id: UUID, connector_id: UUID) -> None:
|
||||||
|
row = conn.execute(
|
||||||
|
"DELETE FROM connectors WHERE id = %s AND owner_id = %s RETURNING id",
|
||||||
|
(connector_id, owner_id),
|
||||||
|
).fetchone()
|
||||||
|
if row is None:
|
||||||
|
raise not_found()
|
||||||
|
|
||||||
|
|
||||||
|
def probe(conn, owner_id: UUID, connector_id: UUID) -> dict:
|
||||||
|
row = _owned(conn, owner_id, connector_id)
|
||||||
|
if row["kind"] == "paperless":
|
||||||
|
count = _paperless_count(row["settings"]["base_url"], row["secret"])
|
||||||
|
return {"ok": True, "detail": f"Paperless antwortet. {count} Dokumente sichtbar."}
|
||||||
|
_imap_login(row["settings"], row["secret"])
|
||||||
|
return {"ok": True, "detail": "Das Postfach ist erreichbar."}
|
||||||
|
|
||||||
|
|
||||||
|
def paperless_documents(conn, owner_id: UUID, query: str) -> list[dict]:
|
||||||
|
row = conn.execute(
|
||||||
|
"""
|
||||||
|
SELECT settings, secret FROM connectors
|
||||||
|
WHERE owner_id = %s AND kind = 'paperless'
|
||||||
|
ORDER BY created_at DESC LIMIT 1
|
||||||
|
""",
|
||||||
|
(owner_id,),
|
||||||
|
).fetchone()
|
||||||
|
if row is None:
|
||||||
|
raise unprocessable("Paperless ist noch nicht verbunden. Lege die Quelle unter Quellen an.")
|
||||||
|
base = row["settings"]["base_url"].rstrip("/")
|
||||||
|
payload = _paperless_get(base, row["secret"], "/api/documents/", {"query": query, "page_size": "20"})
|
||||||
|
items = []
|
||||||
|
for doc in payload.get("results") or []:
|
||||||
|
created = str(doc.get("created") or "")[:10]
|
||||||
|
title = (doc.get("title") or doc.get("original_file_name") or f"Dokument {doc.get('id')}").strip()
|
||||||
|
items.append(
|
||||||
|
{
|
||||||
|
"id": str(doc.get("id")),
|
||||||
|
"title": title[:200],
|
||||||
|
"document_on": created if len(created) == 10 else None,
|
||||||
|
"correspondent": _correspondent(doc),
|
||||||
|
"open_url": f"{base}/documents/{doc.get('id')}/",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return items
|
||||||
|
|
||||||
|
|
||||||
|
def imap_messages(conn, owner_id: UUID, connector_id: UUID, query: str) -> list[dict]:
|
||||||
|
row = _owned(conn, owner_id, connector_id)
|
||||||
|
if row["kind"] != "imap":
|
||||||
|
raise unprocessable("Das ist kein E-Mail-Konto.")
|
||||||
|
return _imap_list(row["settings"], row["secret"], query)
|
||||||
|
|
||||||
|
|
||||||
|
def _owned(conn, owner_id: UUID, connector_id: UUID) -> dict:
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT id, kind, name, settings, secret FROM connectors WHERE id = %s AND owner_id = %s",
|
||||||
|
(connector_id, owner_id),
|
||||||
|
).fetchone()
|
||||||
|
if row is None:
|
||||||
|
raise not_found()
|
||||||
|
return row
|
||||||
|
|
||||||
|
|
||||||
|
def _public(row) -> dict:
|
||||||
|
return {
|
||||||
|
"id": str(row["id"]),
|
||||||
|
"kind": row["kind"],
|
||||||
|
"name": row["name"],
|
||||||
|
"settings": row["settings"],
|
||||||
|
"created_at": row["created_at"].strftime("%Y-%m-%dT%H:%M:%SZ"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def clean_base_url(value: str) -> str:
|
||||||
|
raw = value.strip()
|
||||||
|
parsed = urlparse(raw)
|
||||||
|
if parsed.scheme not in {"http", "https"} or not parsed.netloc or parsed.username or parsed.password:
|
||||||
|
raise unprocessable("Die Paperless-Adresse muss mit http:// oder https:// beginnen.")
|
||||||
|
if len(raw) > 300:
|
||||||
|
raise unprocessable("Die Paperless-Adresse ist zu lang.")
|
||||||
|
return raw.rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
def _paperless_count(base: str, token: str) -> int:
|
||||||
|
payload = _paperless_get(base, token, "/api/documents/", {"page_size": "1"})
|
||||||
|
return int(payload.get("count") or 0)
|
||||||
|
|
||||||
|
|
||||||
|
def _paperless_get(base: str, token: str, path: str, params: dict) -> dict:
|
||||||
|
url = f"{base}{path}?{urlencode(params)}"
|
||||||
|
request = Request(url, headers={"Authorization": f"Token {token}", "Accept": "application/json"})
|
||||||
|
try:
|
||||||
|
with urlopen(request, timeout=12) as response:
|
||||||
|
return json.loads(response.read().decode("utf-8"))
|
||||||
|
except HTTPError as exc:
|
||||||
|
if exc.code in {401, 403}:
|
||||||
|
raise unprocessable("Paperless hat den Schlüssel abgelehnt.") from exc
|
||||||
|
raise unprocessable("Paperless hat die Anfrage nicht beantwortet.") from exc
|
||||||
|
except (URLError, TimeoutError, json.JSONDecodeError) as exc:
|
||||||
|
raise unprocessable("Paperless ist nicht erreichbar.") from exc
|
||||||
|
|
||||||
|
|
||||||
|
def _correspondent(doc: dict) -> str | None:
|
||||||
|
value = doc.get("correspondent_name") or doc.get("correspondent")
|
||||||
|
if isinstance(value, str) and value.strip():
|
||||||
|
return value.strip()[:200]
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _imap_login(settings: dict, secret: str) -> imaplib.IMAP4:
|
||||||
|
host = settings["host"]
|
||||||
|
port = int(settings["port"])
|
||||||
|
security = settings.get("security") or "ssl"
|
||||||
|
try:
|
||||||
|
if security == "starttls":
|
||||||
|
client = imaplib.IMAP4(host, port, timeout=12)
|
||||||
|
client.starttls(ssl.create_default_context())
|
||||||
|
else:
|
||||||
|
client = imaplib.IMAP4_SSL(host, port, ssl_context=ssl.create_default_context(), timeout=12)
|
||||||
|
client.login(settings["username"], secret)
|
||||||
|
return client
|
||||||
|
except imaplib.IMAP4.error as exc:
|
||||||
|
raise unprocessable("Das Postfach hat die Anmeldung abgelehnt.") from exc
|
||||||
|
except (OSError, TimeoutError) as exc:
|
||||||
|
raise unprocessable("Das Postfach ist nicht erreichbar.") from exc
|
||||||
|
|
||||||
|
|
||||||
|
def _imap_list(settings: dict, secret: str, query: str) -> list[dict]:
|
||||||
|
client = _imap_login(settings, secret)
|
||||||
|
try:
|
||||||
|
mailbox = settings.get("mailbox") or "INBOX"
|
||||||
|
status, _ = client.select(mailbox, readonly=True)
|
||||||
|
if status != "OK":
|
||||||
|
raise unprocessable("Das Postfach enthält dieses Fach nicht.")
|
||||||
|
status, data = client.search(None, "ALL")
|
||||||
|
if status != "OK" or not data or not data[0]:
|
||||||
|
return []
|
||||||
|
ids = data[0].split()[-25:]
|
||||||
|
needle = query.strip().lower()
|
||||||
|
items = []
|
||||||
|
for mid in reversed(ids):
|
||||||
|
status, fetched = client.fetch(mid, "(BODY.PEEK[HEADER.FIELDS (FROM SUBJECT DATE MESSAGE-ID)])")
|
||||||
|
if status != "OK" or not fetched or not isinstance(fetched[0], tuple):
|
||||||
|
continue
|
||||||
|
header = BytesParser().parsebytes(fetched[0][1])
|
||||||
|
subject = _decode(header.get("Subject")) or "(ohne Betreff)"
|
||||||
|
sender = _decode(header.get("From"))
|
||||||
|
if needle and needle not in subject.lower() and needle not in sender.lower():
|
||||||
|
continue
|
||||||
|
message_id = (header.get("Message-ID") or f"uid:{mid.decode()}").strip()
|
||||||
|
items.append(
|
||||||
|
{
|
||||||
|
"id": message_id[:200],
|
||||||
|
"title": subject[:200],
|
||||||
|
"message_from": sender[:200],
|
||||||
|
"date": _decode(header.get("Date"))[:80],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return items
|
||||||
|
finally:
|
||||||
|
try:
|
||||||
|
client.logout()
|
||||||
|
except imaplib.IMAP4.error:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _decode(value: str | None) -> str:
|
||||||
|
if not value:
|
||||||
|
return ""
|
||||||
|
parts = []
|
||||||
|
for text, encoding in decode_header(value):
|
||||||
|
if isinstance(text, bytes):
|
||||||
|
parts.append(text.decode(encoding or "utf-8", errors="replace"))
|
||||||
|
else:
|
||||||
|
parts.append(text)
|
||||||
|
return "".join(parts).strip()
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
ALTER TABLE external_references DROP CONSTRAINT external_references_source;
|
||||||
|
ALTER TABLE external_references
|
||||||
|
ADD CONSTRAINT external_references_source CHECK (source IN ('paperless', 'url', 'imap'));
|
||||||
|
ALTER TABLE external_references
|
||||||
|
ADD COLUMN detail jsonb NOT NULL DEFAULT '{}'::jsonb;
|
||||||
|
|
||||||
|
CREATE TABLE connectors (
|
||||||
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
owner_id uuid NOT NULL REFERENCES auth_accounts (id),
|
||||||
|
kind text NOT NULL,
|
||||||
|
name text NOT NULL,
|
||||||
|
settings jsonb NOT NULL,
|
||||||
|
secret text NOT NULL,
|
||||||
|
created_at timestamptz NOT NULL DEFAULT now(),
|
||||||
|
CONSTRAINT connectors_kind CHECK (kind IN ('paperless', 'imap')),
|
||||||
|
CONSTRAINT connectors_name_len CHECK (char_length(name) BETWEEN 1 AND 120)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX connectors_owner ON connectors (owner_id, kind);
|
||||||
@@ -9,6 +9,7 @@ import { CaseList, CaseDetail } from "./pages/Cases.jsx";
|
|||||||
import { MatterList, MatterDetail } from "./pages/Matters.jsx";
|
import { MatterList, MatterDetail } from "./pages/Matters.jsx";
|
||||||
import { Rooms } from "./pages/Rooms.jsx";
|
import { Rooms } from "./pages/Rooms.jsx";
|
||||||
import { Search } from "./pages/Search.jsx";
|
import { Search } from "./pages/Search.jsx";
|
||||||
|
import { Sources } from "./pages/Sources.jsx";
|
||||||
|
|
||||||
export function App() {
|
export function App() {
|
||||||
const [session, setSession] = useState(undefined);
|
const [session, setSession] = useState(undefined);
|
||||||
@@ -77,6 +78,7 @@ export function App() {
|
|||||||
<Route path="matters" element={<MatterList />} />
|
<Route path="matters" element={<MatterList />} />
|
||||||
<Route path="matters/:id" element={<MatterDetail />} />
|
<Route path="matters/:id" element={<MatterDetail />} />
|
||||||
<Route path="rooms" element={<Rooms />} />
|
<Route path="rooms" element={<Rooms />} />
|
||||||
|
<Route path="sources" element={<Sources />} />
|
||||||
<Route path="search" element={<Search />} />
|
<Route path="search" element={<Search />} />
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
+135
-58
@@ -2,6 +2,8 @@ import { useContext, useEffect, useState } from "react";
|
|||||||
import { Link, useParams } from "react-router-dom";
|
import { Link, useParams } from "react-router-dom";
|
||||||
import { api, markDirty, textToDocument } from "../api.js";
|
import { api, markDirty, textToDocument } from "../api.js";
|
||||||
import { SessionContext } from "../session.js";
|
import { SessionContext } from "../session.js";
|
||||||
|
import { Modal } from "./Modal.jsx";
|
||||||
|
import { MailPicker, PaperlessPicker } from "./Sources.jsx";
|
||||||
import { BindingList, Chronology, ErrorNote, ShareBox } from "./widgets.jsx";
|
import { BindingList, Chronology, ErrorNote, ShareBox } from "./widgets.jsx";
|
||||||
|
|
||||||
export function CaseList() {
|
export function CaseList() {
|
||||||
@@ -9,6 +11,7 @@ export function CaseList() {
|
|||||||
const [items, setItems] = useState([]);
|
const [items, setItems] = useState([]);
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
const [creating, setCreating] = useState(false);
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
const data = await api("/api/v1/cases");
|
const data = await api("/api/v1/cases");
|
||||||
@@ -26,6 +29,7 @@ export function CaseList() {
|
|||||||
await api("/api/v1/cases", { method: "POST", body: { title } });
|
await api("/api/v1/cases", { method: "POST", body: { title } });
|
||||||
setTitle("");
|
setTitle("");
|
||||||
markDirty(false);
|
markDirty(false);
|
||||||
|
setCreating(false);
|
||||||
await load();
|
await load();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err.message);
|
setError(err.message);
|
||||||
@@ -37,30 +41,41 @@ export function CaseList() {
|
|||||||
<header className="page-head">
|
<header className="page-head">
|
||||||
<div>
|
<div>
|
||||||
<h1>Akten</h1>
|
<h1>Akten</h1>
|
||||||
<p className="muted">Sichtbar ist, was du lesen darfst — auch aus anderen Datenräumen. Neue Akten entstehen in „{session.scope.name}“.</p>
|
<p className="muted">Eine Akte sammelt die Vorgänge. Neu angelegt wird sie in „{session.scope.name}“.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<button type="button" onClick={() => setCreating(true)}>Akte anlegen</button>
|
||||||
</header>
|
</header>
|
||||||
<form onSubmit={create} className="inline">
|
|
||||||
<input
|
|
||||||
value={title}
|
|
||||||
onChange={(event) => {
|
|
||||||
setTitle(event.target.value);
|
|
||||||
markDirty(true);
|
|
||||||
}}
|
|
||||||
placeholder="Neue Akte, zum Beispiel Mietstreit"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<button type="submit">Akte anlegen</button>
|
|
||||||
</form>
|
|
||||||
<ErrorNote error={error} />
|
<ErrorNote error={error} />
|
||||||
<ul className="index">
|
{items.length ? (
|
||||||
{items.map((item) => (
|
<div className="tiles">
|
||||||
<li key={item.id}>
|
{items.map((item) => (
|
||||||
<Link to={`/cases/${item.id}`}>{item.title}</Link>
|
<Link key={item.id} className="tile" to={`/cases/${item.id}`}>
|
||||||
<span>{item.status === "open" ? "Offen" : "Geschlossen"}</span>
|
<span className="tile__kind">Akte</span>
|
||||||
</li>
|
<strong>{item.title}</strong>
|
||||||
))}
|
<span>{item.status === "open" ? "Offen" : "Geschlossen"}</span>
|
||||||
</ul>
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="muted">Noch keine Akte. Lege die erste an.</p>
|
||||||
|
)}
|
||||||
|
<Modal open={creating} title="Akte anlegen" onClose={() => setCreating(false)}>
|
||||||
|
<form onSubmit={create} className="stack">
|
||||||
|
<label>
|
||||||
|
Titel
|
||||||
|
<input
|
||||||
|
value={title}
|
||||||
|
onChange={(event) => {
|
||||||
|
setTitle(event.target.value);
|
||||||
|
markDirty(true);
|
||||||
|
}}
|
||||||
|
placeholder="Zum Beispiel Mietstreit Musterstraße"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<button type="submit">Akte anlegen</button>
|
||||||
|
</form>
|
||||||
|
</Modal>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -70,6 +85,8 @@ export function CaseDetail() {
|
|||||||
const [record, setRecord] = useState(null);
|
const [record, setRecord] = useState(null);
|
||||||
const [events, setEvents] = useState([]);
|
const [events, setEvents] = useState([]);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
const [modal, setModal] = useState("");
|
||||||
|
const [selected, setSelected] = useState(null);
|
||||||
const context = { kind: "case", id };
|
const context = { kind: "case", id };
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
@@ -98,53 +115,113 @@ export function CaseDetail() {
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<ErrorNote error={error} />
|
<ErrorNote error={error} />
|
||||||
<div className="split">
|
<section className="section">
|
||||||
<section className="card">
|
<div className="section-bar">
|
||||||
<h2>Vorgänge</h2>
|
<h2>Vorgänge</h2>
|
||||||
<ul>
|
{record.rights.edit ? <button type="button" onClick={() => setModal("matter")}>Vorgang anlegen</button> : null}
|
||||||
|
</div>
|
||||||
|
{record.matters.length ? (
|
||||||
|
<div className="tiles">
|
||||||
{record.matters.map((matter) => (
|
{record.matters.map((matter) => (
|
||||||
<li key={matter.id}>
|
<Link key={matter.id} className="tile" to={`/matters/${matter.id}?context_kind=case&context_id=${id}`}>
|
||||||
<Link to={`/matters/${matter.id}?context_kind=case&context_id=${id}`}>{matter.title}</Link>
|
<span className="tile__kind">Vorgang</span>
|
||||||
</li>
|
<strong>{matter.title}</strong>
|
||||||
|
<span>{matter.status === "open" ? "Offen" : "Geschlossen"}</span>
|
||||||
|
</Link>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</div>
|
||||||
{record.rights.edit ? <NewMatter caseId={id} onChange={load} /> : null}
|
) : (
|
||||||
{record.subcases?.length ? (
|
<p className="muted">Diese Akte hat noch keinen Vorgang.</p>
|
||||||
<>
|
)}
|
||||||
<h3>Unterakten</h3>
|
|
||||||
<ul>
|
|
||||||
{record.subcases.map((item) => (
|
|
||||||
<li key={item.id}><Link to={`/cases/${item.id}`}>{item.title}</Link></li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
{record.rights.edit ? <NewSubcase parentId={id} onChange={load} /> : null}
|
|
||||||
</section>
|
|
||||||
<section className="card">
|
|
||||||
<h2>Kapitel</h2>
|
|
||||||
<ul>{record.chapters.map((chapter) => <li key={chapter.id}>{chapter.title}</li>)}</ul>
|
|
||||||
{record.rights.edit ? <ChapterForm path={`/api/v1/cases/${id}/chapters`} onChange={load} /> : null}
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
<section className="card">
|
|
||||||
<h2>Inhalte</h2>
|
|
||||||
<BindingList bindings={record.bindings} context={context} canEdit={record.rights.edit} isOwner={record.is_owner} onChange={load} />
|
|
||||||
{record.rights.edit ? <ContentForms context={context} chapters={record.chapters} onChange={load} /> : null}
|
|
||||||
</section>
|
</section>
|
||||||
{record.grants || record.rights.share || record.is_owner ? (
|
<section className="section">
|
||||||
record.rights.share || record.is_owner ? (
|
<div className="section-bar">
|
||||||
<ShareBox path={`/api/v1/cases/${id}/grants`} grants={record.grants || []} onChange={load} />
|
<h2>Unterlagen</h2>
|
||||||
) : null
|
{record.rights.edit ? <button type="button" onClick={() => setModal("add")}>Hinzufügen</button> : null}
|
||||||
|
</div>
|
||||||
|
{record.bindings.length ? (
|
||||||
|
<div className="tiles">
|
||||||
|
{record.bindings.map((binding) => (
|
||||||
|
<button key={binding.id} type="button" className="tile" onClick={() => setSelected(binding)}>
|
||||||
|
<span className="tile__kind">{sourceKind(binding.element)}</span>
|
||||||
|
<strong>{binding.element.title}</strong>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="muted">Noch keine Notiz, Datei oder Verknüpfung.</p>
|
||||||
|
)}
|
||||||
|
</section>
|
||||||
|
{record.subcases?.length ? (
|
||||||
|
<section className="section">
|
||||||
|
<h2>Unterakten</h2>
|
||||||
|
<div className="tiles">
|
||||||
|
{record.subcases.map((item) => (
|
||||||
|
<Link key={item.id} className="tile" to={`/cases/${item.id}`}>
|
||||||
|
<span className="tile__kind">Unterakte</span>
|
||||||
|
<strong>{item.title}</strong>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
) : null}
|
) : null}
|
||||||
<section className="card">
|
<div className="row">
|
||||||
|
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("more")}>Kapitel und Unterakte</button> : null}
|
||||||
|
{record.rights.share || record.is_owner ? <button type="button" className="quiet" onClick={() => setModal("share")}>Teilen</button> : null}
|
||||||
|
</div>
|
||||||
|
<section className="section">
|
||||||
<h2>Chronologie</h2>
|
<h2>Chronologie</h2>
|
||||||
<Chronology items={events} />
|
<Chronology items={events} />
|
||||||
</section>
|
</section>
|
||||||
|
<Modal open={modal === "matter"} title="Vorgang anlegen" onClose={() => setModal("")}>
|
||||||
|
<NewMatter caseId={id} onChange={() => { setModal(""); load(); }} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "add"} title="Hinzufügen" onClose={() => setModal("")}>
|
||||||
|
<div className="choice">
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "note"} title="Notiz" onClose={() => setModal("")}>
|
||||||
|
<NoteForm context={context} chapters={record.chapters} onChange={() => { setModal(""); load(); }} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "file"} title="Datei" onClose={() => setModal("")}>
|
||||||
|
<FileForm context={context} chapters={record.chapters} onChange={() => { setModal(""); load(); }} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "paperless"} title="Aus Paperless" onClose={() => setModal("")}>
|
||||||
|
<PaperlessPicker context={context} onDone={() => { setModal(""); load(); }} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "mail"} title="E-Mail verbinden" onClose={() => setModal("")}>
|
||||||
|
<MailPicker context={context} onDone={() => { setModal(""); load(); }} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "more"} title="Struktur" onClose={() => setModal("")}>
|
||||||
|
<div className="stack">
|
||||||
|
<ChapterForm path={`/api/v1/cases/${id}/chapters`} onChange={load} />
|
||||||
|
<NewSubcase parentId={id} onChange={load} />
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "share"} title="Teilen" onClose={() => setModal("")}>
|
||||||
|
<ShareBox path={`/api/v1/cases/${id}/grants`} grants={record.grants || []} onChange={load} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={Boolean(selected)} title={selected?.element.title || "Unterlage"} onClose={() => setSelected(null)}>
|
||||||
|
{selected ? (
|
||||||
|
<BindingList bindings={[selected]} context={context} canEdit={record.rights.edit} isOwner={record.is_owner} onChange={() => { setSelected(null); load(); }} />
|
||||||
|
) : null}
|
||||||
|
</Modal>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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";
|
||||||
|
return "Referenz";
|
||||||
|
}
|
||||||
|
|
||||||
function NewMatter({ caseId, onChange }) {
|
function NewMatter({ caseId, onChange }) {
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
@@ -236,7 +313,7 @@ function chapterSelect(chapters, value, setValue) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function NoteForm({ context, placement, chapters, onChange }) {
|
export function NoteForm({ context, placement, chapters, onChange }) {
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const [text, setText] = useState("");
|
const [text, setText] = useState("");
|
||||||
const [chapterId, setChapterId] = useState("");
|
const [chapterId, setChapterId] = useState("");
|
||||||
@@ -277,7 +354,7 @@ function NoteForm({ context, placement, chapters, onChange }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function FileForm({ context, placement, chapters, onChange }) {
|
export function FileForm({ context, placement, chapters, onChange }) {
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const [file, setFile] = useState(null);
|
const [file, setFile] = useState(null);
|
||||||
const [chapterId, setChapterId] = useState("");
|
const [chapterId, setChapterId] = useState("");
|
||||||
|
|||||||
+113
-80
@@ -1,9 +1,11 @@
|
|||||||
import { useContext, useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import { Link, useParams, useSearchParams } from "react-router-dom";
|
import { Link, useParams, useSearchParams } from "react-router-dom";
|
||||||
import { api, markDirty } from "../api.js";
|
import { api } from "../api.js";
|
||||||
import { SessionContext } from "../session.js";
|
import { SessionContext } from "../session.js";
|
||||||
|
import { Modal } from "./Modal.jsx";
|
||||||
|
import { MailPicker, PaperlessPicker } from "./Sources.jsx";
|
||||||
import { BindingList, Chronology, ErrorNote, ShareBox } from "./widgets.jsx";
|
import { BindingList, Chronology, ErrorNote, ShareBox } from "./widgets.jsx";
|
||||||
import { ChapterForm, ContentForms } from "./Cases.jsx";
|
import { ChapterForm, FileForm, NoteForm } from "./Cases.jsx";
|
||||||
|
|
||||||
function pageContext(params) {
|
function pageContext(params) {
|
||||||
const kind = params.get("context_kind");
|
const kind = params.get("context_kind");
|
||||||
@@ -15,7 +17,6 @@ function pageContext(params) {
|
|||||||
export function MatterList() {
|
export function MatterList() {
|
||||||
const { session } = useContext(SessionContext);
|
const { session } = useContext(SessionContext);
|
||||||
const [items, setItems] = useState([]);
|
const [items, setItems] = useState([]);
|
||||||
const [title, setTitle] = useState("");
|
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
@@ -27,48 +28,38 @@ export function MatterList() {
|
|||||||
load().catch((err) => setError(err.message));
|
load().catch((err) => setError(err.message));
|
||||||
}, [session.scope.id]);
|
}, [session.scope.id]);
|
||||||
|
|
||||||
async function create(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
try {
|
|
||||||
await api("/api/v1/matters", { method: "POST", body: { title } });
|
|
||||||
setTitle("");
|
|
||||||
markDirty(false);
|
|
||||||
await load();
|
|
||||||
} catch (err) {
|
|
||||||
setError(err.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="page">
|
<main className="page">
|
||||||
<header className="page-head">
|
<header className="page-head">
|
||||||
<div>
|
<div>
|
||||||
<h1>Vorgänge</h1>
|
<h1>Vorgänge</h1>
|
||||||
<p className="muted">Ein Vorgang kann ohne Akte bestehen und mehreren Akten zugeordnet werden. Neu angelegt wird er in „{session.scope.name}“.</p>
|
<p className="muted">Ein Vorgang gehört in eine Akte. Lege ihn dort an, dann sammelt die Akte die Arbeit.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<Link className="quiet linkish" to="/cases">Zu den Akten</Link>
|
||||||
</header>
|
</header>
|
||||||
<form onSubmit={create} className="inline">
|
|
||||||
<input value={title} onChange={(event) => { setTitle(event.target.value); markDirty(true); }} placeholder="Neuer Vorgang" required />
|
|
||||||
<button type="submit">Vorgang anlegen</button>
|
|
||||||
</form>
|
|
||||||
<ErrorNote error={error} />
|
<ErrorNote error={error} />
|
||||||
<ul className="index">
|
{items.length ? (
|
||||||
{items.map((item) => {
|
<div className="tiles">
|
||||||
const context = item.contexts?.[0];
|
{items.map((item) => {
|
||||||
const params = new URLSearchParams();
|
const context = item.contexts?.[0];
|
||||||
if (context && context.kind !== "direct") {
|
const params = new URLSearchParams();
|
||||||
params.set("context_kind", context.kind);
|
if (context && context.kind !== "direct") {
|
||||||
params.set("context_id", context.id);
|
params.set("context_kind", context.kind);
|
||||||
}
|
params.set("context_id", context.id);
|
||||||
const suffix = params.toString() ? `?${params}` : "";
|
}
|
||||||
return (
|
const suffix = params.toString() ? `?${params}` : "";
|
||||||
<li key={item.id}>
|
return (
|
||||||
<Link to={`/matters/${item.id}${suffix}`}>{item.title}</Link>
|
<Link key={item.id} className="tile" to={`/matters/${item.id}${suffix}`}>
|
||||||
<span>{item.status === "open" ? "Offen" : "Geschlossen"}</span>
|
<span className="tile__kind">Vorgang</span>
|
||||||
</li>
|
<strong>{item.title}</strong>
|
||||||
);
|
<span>{item.status === "open" ? "Offen" : "Geschlossen"}</span>
|
||||||
})}
|
</Link>
|
||||||
</ul>
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="muted">Noch kein Vorgang. Öffne eine Akte und lege ihn dort an.</p>
|
||||||
|
)}
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -80,6 +71,8 @@ export function MatterDetail() {
|
|||||||
const [record, setRecord] = useState(null);
|
const [record, setRecord] = useState(null);
|
||||||
const [events, setEvents] = useState([]);
|
const [events, setEvents] = useState([]);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
const [modal, setModal] = useState("");
|
||||||
|
const [selected, setSelected] = useState(null);
|
||||||
const rightsContext = inherited || { kind: "matter", id };
|
const rightsContext = inherited || { kind: "matter", id };
|
||||||
const placement = inherited?.kind === "case" ? { kind: "matter", id } : null;
|
const placement = inherited?.kind === "case" ? { kind: "matter", id } : null;
|
||||||
|
|
||||||
@@ -112,57 +105,97 @@ export function MatterDetail() {
|
|||||||
</header>
|
</header>
|
||||||
<ErrorNote error={error} />
|
<ErrorNote error={error} />
|
||||||
{record.case_links?.length ? (
|
{record.case_links?.length ? (
|
||||||
<section className="card">
|
<div className="tiles">
|
||||||
<h2>Akten</h2>
|
{record.case_links.map((link) => (
|
||||||
<ul>
|
<Link key={link.id} className="tile" to={`/cases/${link.case_id}`}>
|
||||||
{record.case_links.map((link) => (
|
<span className="tile__kind">Akte</span>
|
||||||
<li key={link.id}><Link to={`/cases/${link.case_id}`}>{link.title}</Link></li>
|
<strong>{link.title}</strong>
|
||||||
))}
|
</Link>
|
||||||
</ul>
|
))}
|
||||||
</section>
|
</div>
|
||||||
) : null}
|
) : (
|
||||||
<section className="card">
|
<p className="muted">Dieser Vorgang liegt noch in keiner Akte.</p>
|
||||||
<h2>Nachverfolgung</h2>
|
)}
|
||||||
|
<section className="section">
|
||||||
|
<div className="section-bar">
|
||||||
|
<h2>Nachverfolgung</h2>
|
||||||
|
{record.rights.edit ? <button type="button" onClick={() => setModal("work")}>Aufgabe oder Frist</button> : null}
|
||||||
|
</div>
|
||||||
<p className="notice">Das Erledigen einer Aufgabe erfüllt eine verknüpfte Frist nicht.</p>
|
<p className="notice">Das Erledigen einer Aufgabe erfüllt eine verknüpfte Frist nicht.</p>
|
||||||
<WorkLists record={record} context={inherited} onChange={load} />
|
<WorkLists record={record} context={inherited} onChange={load} />
|
||||||
{record.rights.edit ? <WorkForms matterId={id} context={inherited} tasks={record.tasks} onChange={load} /> : null}
|
|
||||||
</section>
|
</section>
|
||||||
<section className="card">
|
<section className="section">
|
||||||
<h2>Inhalte</h2>
|
<div className="section-bar">
|
||||||
<BindingList bindings={record.bindings} context={rightsContext} canEdit={record.rights.edit} isOwner={record.is_owner} onChange={load} />
|
<h2>Unterlagen</h2>
|
||||||
{record.rights.edit ? (
|
{record.rights.edit ? <button type="button" onClick={() => setModal("add")}>Hinzufügen</button> : null}
|
||||||
<ContentForms context={rightsContext} placement={placement} chapters={record.chapters} onChange={load} />
|
</div>
|
||||||
) : null}
|
{record.bindings.length ? (
|
||||||
</section>
|
<div className="tiles">
|
||||||
<section className="card">
|
{record.bindings.map((binding) => (
|
||||||
<h2>Kapitel, Teilvorgänge, Querverweise</h2>
|
<button key={binding.id} type="button" className="tile" onClick={() => setSelected(binding)}>
|
||||||
<ul>{record.chapters.map((chapter) => <li key={chapter.id}>{chapter.title}</li>)}</ul>
|
<span className="tile__kind">{binding.element.kind === "note" ? "Notiz" : binding.element.kind === "file" ? "Datei" : binding.element.external?.source === "imap" ? "E-Mail" : "Paperless"}</span>
|
||||||
{record.rights.edit ? <ChapterForm path={`/api/v1/matters/${id}/chapters${inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : ""}`} onChange={load} /> : null}
|
<strong>{binding.element.title}</strong>
|
||||||
{record.submatters?.length ? (
|
</button>
|
||||||
<ul>
|
|
||||||
{record.submatters.map((item) => (
|
|
||||||
<li key={item.id}>
|
|
||||||
<Link to={`/matters/${item.id}${inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : ""}`}>{item.title}</Link>
|
|
||||||
</li>
|
|
||||||
))}
|
))}
|
||||||
</ul>
|
</div>
|
||||||
) : null}
|
) : (
|
||||||
{record.cross_links?.length ? (
|
<p className="muted">Noch nichts in diesem Vorgang.</p>
|
||||||
<ul>
|
)}
|
||||||
{record.cross_links.map((item) => (
|
|
||||||
<li key={item.id}><Link to={`/matters/${item.matter_id}`}>{item.title}</Link></li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
) : null}
|
|
||||||
{record.rights.edit ? <SubmatterForm parentId={id} context={inherited} onChange={load} /> : null}
|
|
||||||
</section>
|
</section>
|
||||||
{record.rights.share || record.is_owner ? (
|
<div className="row">
|
||||||
<ShareBox path={`/api/v1/matters/${id}/grants`} grants={record.grants || []} onChange={load} />
|
{record.rights.edit ? <button type="button" className="quiet" onClick={() => setModal("more")}>Kapitel und Teilvorgang</button> : null}
|
||||||
) : null}
|
{record.rights.share || record.is_owner ? <button type="button" className="quiet" onClick={() => setModal("share")}>Teilen</button> : null}
|
||||||
<section className="card">
|
</div>
|
||||||
|
<section className="section">
|
||||||
<h2>Chronologie</h2>
|
<h2>Chronologie</h2>
|
||||||
<Chronology items={events} />
|
<Chronology items={events} />
|
||||||
</section>
|
</section>
|
||||||
|
<Modal open={modal === "work"} title="Aufgabe oder Frist" onClose={() => setModal("")}>
|
||||||
|
<WorkForms matterId={id} context={inherited} tasks={record.tasks} onChange={() => { setModal(""); load(); }} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "add"} title="Hinzufügen" onClose={() => setModal("")}>
|
||||||
|
<div className="choice">
|
||||||
|
<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>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "note"} title="Notiz" onClose={() => setModal("")}>
|
||||||
|
<NoteForm context={rightsContext} placement={placement} chapters={record.chapters} onChange={() => { setModal(""); load(); }} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "file"} title="Datei" onClose={() => setModal("")}>
|
||||||
|
<FileForm context={rightsContext} placement={placement} chapters={record.chapters} onChange={() => { setModal(""); load(); }} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "paperless"} title="Aus Paperless" onClose={() => setModal("")}>
|
||||||
|
<PaperlessPicker context={rightsContext} placement={placement} onDone={() => { setModal(""); load(); }} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "mail"} title="E-Mail verbinden" onClose={() => setModal("")}>
|
||||||
|
<MailPicker context={rightsContext} placement={placement} onDone={() => { setModal(""); load(); }} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "more"} title="Struktur" onClose={() => setModal("")}>
|
||||||
|
<div className="stack">
|
||||||
|
<ChapterForm path={`/api/v1/matters/${id}/chapters${inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : ""}`} onChange={load} />
|
||||||
|
<SubmatterForm parentId={id} context={inherited} onChange={load} />
|
||||||
|
{record.submatters?.length ? (
|
||||||
|
<ul className="index">
|
||||||
|
{record.submatters.map((item) => (
|
||||||
|
<li key={item.id}>
|
||||||
|
<Link to={`/matters/${item.id}${inherited ? `?context_kind=${inherited.kind}&context_id=${inherited.id}` : ""}`}>{item.title}</Link>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
<Modal open={modal === "share"} title="Teilen" onClose={() => setModal("")}>
|
||||||
|
<ShareBox path={`/api/v1/matters/${id}/grants`} grants={record.grants || []} onChange={load} />
|
||||||
|
</Modal>
|
||||||
|
<Modal open={Boolean(selected)} title={selected?.element.title || "Unterlage"} onClose={() => setSelected(null)}>
|
||||||
|
{selected ? (
|
||||||
|
<BindingList bindings={[selected]} context={rightsContext} canEdit={record.rights.edit} isOwner={record.is_owner} onChange={() => { setSelected(null); load(); }} />
|
||||||
|
) : null}
|
||||||
|
</Modal>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
|
export function Modal({ open, title, onClose, children }) {
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return undefined;
|
||||||
|
function onKey(event) {
|
||||||
|
if (event.key === "Escape") onClose();
|
||||||
|
}
|
||||||
|
document.addEventListener("keydown", onKey);
|
||||||
|
const previous = document.body.style.overflow;
|
||||||
|
document.body.style.overflow = "hidden";
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener("keydown", onKey);
|
||||||
|
document.body.style.overflow = previous;
|
||||||
|
};
|
||||||
|
}, [open, onClose]);
|
||||||
|
|
||||||
|
if (!open) return null;
|
||||||
|
return (
|
||||||
|
<div className="modal-overlay" onClick={(event) => { if (event.target === event.currentTarget) onClose(); }}>
|
||||||
|
<div className="modal" role="dialog" aria-modal="true" aria-label={title}>
|
||||||
|
<header className="modal__bar">
|
||||||
|
<h2>{title}</h2>
|
||||||
|
<button type="button" className="quiet" onClick={onClose}>Schließen</button>
|
||||||
|
</header>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ const NAV = [
|
|||||||
{ to: "/cases", label: "Akten", icon: "folder" },
|
{ to: "/cases", label: "Akten", icon: "folder" },
|
||||||
{ to: "/matters", label: "Vorgänge", icon: "layers" },
|
{ to: "/matters", label: "Vorgänge", icon: "layers" },
|
||||||
{ to: "/rooms", label: "Datenräume", icon: "rooms" },
|
{ to: "/rooms", label: "Datenräume", icon: "rooms" },
|
||||||
|
{ to: "/sources", label: "Quellen", icon: "sources" },
|
||||||
];
|
];
|
||||||
|
|
||||||
export function Shell() {
|
export function Shell() {
|
||||||
@@ -123,6 +124,9 @@ function NavIcon({ name }) {
|
|||||||
if (name === "layers") {
|
if (name === "layers") {
|
||||||
return <svg {...common}><path d="m12 3 9 5-9 5-9-5z" /><path d="m3 12 9 5 9-5" /><path d="m3 17 9 5 9-5" /></svg>;
|
return <svg {...common}><path d="m12 3 9 5-9 5-9-5z" /><path d="m3 12 9 5 9-5" /><path d="m3 17 9 5 9-5" /></svg>;
|
||||||
}
|
}
|
||||||
|
if (name === "sources") {
|
||||||
|
return <svg {...common}><path d="M4 7h16" /><path d="M4 12h10" /><path d="M4 17h16" /><path d="M18 10v4" /></svg>;
|
||||||
|
}
|
||||||
if (name === "logout") {
|
if (name === "logout") {
|
||||||
return <svg {...common}><path d="M9 6H5a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h4" /><path d="M14 16l4-4-4-4" /><path d="M18 12H9" /></svg>;
|
return <svg {...common}><path d="M9 6H5a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h4" /><path d="M14 16l4-4-4-4" /><path d="M18 12H9" /></svg>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,297 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
|
import { api } from "../api.js";
|
||||||
|
import { ErrorNote } from "./widgets.jsx";
|
||||||
|
|
||||||
|
export function Sources() {
|
||||||
|
const [items, setItems] = useState([]);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [notice, setNotice] = useState("");
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
const data = await api("/api/v1/connectors");
|
||||||
|
setItems(data.items);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
load().catch((err) => setError(err.message));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="page">
|
||||||
|
<header className="page-head">
|
||||||
|
<div>
|
||||||
|
<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>
|
||||||
|
</header>
|
||||||
|
<ErrorNote error={error} />
|
||||||
|
{notice ? <p className="notice">{notice}</p> : null}
|
||||||
|
<div className="tiles">
|
||||||
|
{items.map((item) => (
|
||||||
|
<article key={item.id} className="tile">
|
||||||
|
<span className="tile__kind">{item.kind === "paperless" ? "Paperless" : "IMAP"}</span>
|
||||||
|
<strong>{item.name}</strong>
|
||||||
|
<span>{item.kind === "paperless" ? item.settings.base_url : item.settings.username}</span>
|
||||||
|
<div className="row">
|
||||||
|
<button type="button" className="quiet" onClick={() => probe(item.id, setNotice, setError)}>Prüfen</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>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function PaperlessForm({ onSaved, onError }) {
|
||||||
|
const [name, setName] = useState("Paperless");
|
||||||
|
const [baseUrl, setBaseUrl] = useState("");
|
||||||
|
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 },
|
||||||
|
});
|
||||||
|
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">Paperless verbinden</button>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MailForm({ onSaved, onError }) {
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
const [host, setHost] = useState("");
|
||||||
|
const [port, setPort] = useState("993");
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [security, setSecurity] = useState("ssl");
|
||||||
|
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
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">Konto hinzufügen</button>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PaperlessPicker({ context, placement, onDone }) {
|
||||||
|
const [query, setQuery] = useState("");
|
||||||
|
const [items, setItems] = useState([]);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
async function search(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
setError("");
|
||||||
|
try {
|
||||||
|
const data = await api(`/api/v1/sources/paperless/documents?q=${encodeURIComponent(query)}`);
|
||||||
|
setItems(data.items);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function link(item) {
|
||||||
|
setError("");
|
||||||
|
try {
|
||||||
|
await api("/api/v1/external-refs", {
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
title: item.title,
|
||||||
|
source: "paperless",
|
||||||
|
external_id: item.id,
|
||||||
|
context,
|
||||||
|
...(placement ? { placement } : {}),
|
||||||
|
...(item.document_on || item.correspondent || item.open_url
|
||||||
|
? {
|
||||||
|
dates: { document_on: item.document_on || null, sent_on: null, received_on: null },
|
||||||
|
detail: {
|
||||||
|
...(item.correspondent ? { correspondent: item.correspondent } : {}),
|
||||||
|
...(item.open_url ? { open_url: item.open_url } : {}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
onDone();
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="stack">
|
||||||
|
<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">Die Verbindung richtest du unter <Link to="/sources">Quellen</Link> ein.</p>
|
||||||
|
<div className="stack">
|
||||||
|
{items.map((item) => (
|
||||||
|
<button key={item.id} type="button" className="quiet" onClick={() => link(item)}>{item.title}</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MailPicker({ context, placement, onDone }) {
|
||||||
|
const [accounts, setAccounts] = useState([]);
|
||||||
|
const [accountId, setAccountId] = useState("");
|
||||||
|
const [query, setQuery] = useState("");
|
||||||
|
const [items, setItems] = useState([]);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
api("/api/v1/connectors")
|
||||||
|
.then((data) => {
|
||||||
|
const mail = data.items.filter((item) => item.kind === "imap");
|
||||||
|
setAccounts(mail);
|
||||||
|
if (mail[0]) setAccountId(mail[0].id);
|
||||||
|
})
|
||||||
|
.catch((err) => setError(err.message));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function search(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
if (!accountId) {
|
||||||
|
setError("Lege zuerst ein E-Mail-Konto unter Quellen an.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setError("");
|
||||||
|
try {
|
||||||
|
const data = await api(`/api/v1/sources/imap/messages?connector_id=${accountId}&q=${encodeURIComponent(query)}`);
|
||||||
|
setItems(data.items);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function link(item) {
|
||||||
|
setError("");
|
||||||
|
try {
|
||||||
|
await api("/api/v1/external-refs", {
|
||||||
|
method: "POST",
|
||||||
|
body: {
|
||||||
|
title: item.title,
|
||||||
|
source: "imap",
|
||||||
|
external_id: item.id,
|
||||||
|
context,
|
||||||
|
...(placement ? { placement } : {}),
|
||||||
|
...(item.message_from ? { detail: { message_from: item.message_from } } : {}),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
onDone();
|
||||||
|
} catch (err) {
|
||||||
|
setError(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="stack">
|
||||||
|
<form onSubmit={search} className="stack">
|
||||||
|
<label>
|
||||||
|
Konto
|
||||||
|
<select value={accountId} onChange={(event) => setAccountId(event.target.value)}>
|
||||||
|
{accounts.length ? null : <option value="">Kein Konto</option>}
|
||||||
|
{accounts.map((item) => (
|
||||||
|
<option key={item.id} value={item.id}>{item.name}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<div className="inline">
|
||||||
|
<input value={query} onChange={(event) => setQuery(event.target.value)} placeholder="Betreff oder Absender" />
|
||||||
|
<button type="submit">Abrufen</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<ErrorNote error={error} />
|
||||||
|
<div className="stack">
|
||||||
|
{items.map((item) => (
|
||||||
|
<button key={item.id} type="button" className="quiet" onClick={() => link(item)}>
|
||||||
|
{item.title}{item.message_from ? ` · ${item.message_from}` : ""}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -151,7 +151,7 @@ function Binding({ binding, context, canEdit, isOwner, onChange }) {
|
|||||||
<article className="item">
|
<article className="item">
|
||||||
<header className="item-head">
|
<header className="item-head">
|
||||||
<div>
|
<div>
|
||||||
<p className="eyebrow">{kindLabel(element.kind)}</p>
|
<p className="eyebrow">{kindLabel(element)}</p>
|
||||||
<h3>{element.title}</h3>
|
<h3>{element.title}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
@@ -190,8 +190,14 @@ function Binding({ binding, context, canEdit, isOwner, onChange }) {
|
|||||||
) : null}
|
) : null}
|
||||||
{element.kind === "external_ref" && element.external ? (
|
{element.kind === "external_ref" && element.external ? (
|
||||||
<p className="ref">
|
<p className="ref">
|
||||||
{element.external.source === "paperless" ? "Paperless" : "Externe Adresse"} {element.external.external_id}
|
{element.external.source === "paperless" ? "Paperless" : element.external.source === "imap" ? "E-Mail" : "Externe Adresse"}
|
||||||
<span>Nur eine Referenz, keine Kopie und kein Abruf.</span>
|
{element.external.detail?.correspondent ? ` · ${element.external.detail.correspondent}` : ""}
|
||||||
|
{element.external.detail?.message_from ? ` · ${element.external.detail.message_from}` : ""}
|
||||||
|
{element.external.detail?.open_url ? (
|
||||||
|
<a href={element.external.detail.open_url} target="_blank" rel="noreferrer">In Paperless öffnen</a>
|
||||||
|
) : (
|
||||||
|
<span>Verknüpft, ohne die Quelle zu kopieren.</span>
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
{binding.rights.share && context ? (
|
{binding.rights.share && context ? (
|
||||||
@@ -268,10 +274,13 @@ function DateLine({ dates }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function kindLabel(kind) {
|
function kindLabel(element) {
|
||||||
|
const kind = element.kind;
|
||||||
if (kind === "note") return "Notiz";
|
if (kind === "note") return "Notiz";
|
||||||
if (kind === "file") return "Datei";
|
if (kind === "file") return "Datei";
|
||||||
if (kind === "external_ref") return "Externe Referenz";
|
if (element.external?.source === "paperless") return "Paperless";
|
||||||
|
if (element.external?.source === "imap") return "E-Mail";
|
||||||
|
if (kind === "external_ref") return "Referenz";
|
||||||
return kind;
|
return kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -295,6 +295,59 @@ label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(-
|
|||||||
}
|
}
|
||||||
.desktop-sidebar__logout:hover { color: var(--danger); background: rgba(216, 90, 48, 0.08); }
|
.desktop-sidebar__logout:hover { color: var(--danger); background: rgba(216, 90, 48, 0.08); }
|
||||||
|
|
||||||
|
.section { display: grid; gap: 10px; }
|
||||||
|
.section-bar { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
|
||||||
|
.section-bar h2, .section > h2 {
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text3);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
}
|
||||||
|
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
|
||||||
|
.tile {
|
||||||
|
display: grid;
|
||||||
|
gap: 6px;
|
||||||
|
align-content: start;
|
||||||
|
text-align: left;
|
||||||
|
text-decoration: none;
|
||||||
|
background: var(--surface);
|
||||||
|
color: var(--text1);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 14px;
|
||||||
|
min-height: 108px;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.tile:hover { border-color: var(--accent); }
|
||||||
|
.tile strong { font-size: 16px; font-weight: 700; line-height: 1.3; }
|
||||||
|
.tile span, .tile__kind { font-size: 12px; color: var(--text3); font-weight: 600; }
|
||||||
|
.tile__kind { text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
|
||||||
|
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||||
|
.choice button { min-height: 72px; }
|
||||||
|
.modal-overlay {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 40;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
padding: 16px;
|
||||||
|
background: rgba(28, 27, 24, 0.45);
|
||||||
|
}
|
||||||
|
.modal {
|
||||||
|
width: min(520px, 100%);
|
||||||
|
max-height: min(86vh, 760px);
|
||||||
|
overflow: auto;
|
||||||
|
background: var(--surface);
|
||||||
|
color: var(--text1);
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 18px;
|
||||||
|
box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
|
||||||
|
}
|
||||||
|
.modal__bar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 14px; }
|
||||||
|
.modal h2 { font-size: 18px; color: var(--text1); text-transform: none; letter-spacing: 0; margin: 0; }
|
||||||
|
.modal h3 { font-size: 13px; }
|
||||||
|
|
||||||
.page { display: grid; gap: 16px; }
|
.page { display: grid; gap: 16px; }
|
||||||
.page-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
|
.page-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
|
||||||
.split, .forms { display: grid; gap: 12px; }
|
.split, .forms { display: grid; gap: 12px; }
|
||||||
|
|||||||
Reference in new issue
Block a user