Zeige referenzierte Paperless-Dokumente zum Ansehen und Drucken.
Deploy Development / deploy (push) Successful in 22s
Deploy Development / deploy (push) Successful in 22s
Die Datei bleibt in Paperless. Tsumugu laedt sie nur fuer die Ansicht und speichert keine Kopie. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0108a296bc
commit
871c7d3ad5
7 files changed
+167
-14
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, documentToText, downloadFile, markDirty, textToDocument } from "../api.js";
|
||||
import { api, documentToText, downloadFile, fetchPaperless, markDirty, textToDocument } from "../api.js";
|
||||
import { Modal } from "./Modal.jsx";
|
||||
|
||||
export function ErrorNote({ error }) {
|
||||
if (!error) return null;
|
||||
@@ -44,6 +45,26 @@ function Binding({ binding, context, canEdit, isOwner, onChange }) {
|
||||
const [targetKey, setTargetKey] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
const [notice, setNotice] = useState("");
|
||||
const [previewUrl, setPreviewUrl] = useState("");
|
||||
const [viewing, setViewing] = useState(false);
|
||||
const frameRef = useRef(null);
|
||||
|
||||
useEffect(() => () => {
|
||||
if (previewUrl) URL.revokeObjectURL(previewUrl);
|
||||
}, [previewUrl]);
|
||||
|
||||
async function viewPaperless() {
|
||||
setError("");
|
||||
setViewing(true);
|
||||
try {
|
||||
const blob = await fetchPaperless(element.id, context);
|
||||
if (previewUrl) URL.revokeObjectURL(previewUrl);
|
||||
setPreviewUrl(URL.createObjectURL(blob));
|
||||
} catch (err) {
|
||||
setViewing(false);
|
||||
setError(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveNote(event) {
|
||||
event.preventDefault();
|
||||
@@ -189,17 +210,32 @@ function Binding({ binding, context, canEdit, isOwner, onChange }) {
|
||||
)
|
||||
) : null}
|
||||
{element.kind === "external_ref" && element.external ? (
|
||||
<p className="ref">
|
||||
{element.external.source === "paperless" ? "Paperless" : element.external.source === "imap" ? "E-Mail" : "Externe Adresse"}
|
||||
{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>
|
||||
<div className="ref">
|
||||
<p>
|
||||
{element.external.source === "paperless" ? "Paperless" : element.external.source === "imap" ? "E-Mail" : "Externe Adresse"}
|
||||
{element.external.detail?.correspondent ? ` · ${element.external.detail.correspondent}` : ""}
|
||||
{element.external.detail?.message_from ? ` · ${element.external.detail.message_from}` : ""}
|
||||
</p>
|
||||
{element.external.source === "paperless" ? (
|
||||
<button type="button" onClick={viewPaperless}>Ansehen</button>
|
||||
) : (
|
||||
<span>Verknüpft, ohne die Quelle zu kopieren.</span>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
) : null}
|
||||
<Modal
|
||||
open={viewing}
|
||||
wide
|
||||
title={element.title}
|
||||
onClose={() => setViewing(false)}
|
||||
>
|
||||
<div className="viewer">
|
||||
{previewUrl ? <iframe ref={frameRef} title={element.title} src={previewUrl} /> : <p className="muted">Dokument wird geladen …</p>}
|
||||
<div className="row">
|
||||
<button type="button" onClick={() => frameRef.current?.contentWindow?.print()} disabled={!previewUrl}>Drucken</button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
{binding.rights.share && context ? (
|
||||
<form onSubmit={bindElsewhere} className="inline" onFocus={loadTargets}>
|
||||
<select value={targetKey} onChange={(event) => setTargetKey(event.target.value)} onFocus={loadTargets}>
|
||||
|
||||
Reference in new issue
Block a user