chore: bump version to 0.8.95 and update legal documents features
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 35s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 15s
Test Suite / playwright-tests (push) Successful in 56s
Deploy Development / deploy (push) Successful in 40s
Test Suite / pytest-backend (push) Successful in 35s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 15s
Test Suite / playwright-tests (push) Successful in 56s
- Updated app version to 0.8.95 with a new build date of 2026-05-12. - Enhanced legal documents functionality to support section numbering and Markdown formatting in the output. - Updated dependencies in package.json to include 'marked' and 'react-markdown'. - Added new CSS styles for legal document presentation. - Refactored PDF generation logic to incorporate new metadata and improved document structure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
04663e090a
commit
81b9e8f601
7 files changed
+533
-163
No files matched your search
@@ -1,90 +1,9 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { jsPDF } from 'jspdf'
|
||||
import { FileText, Plus, Edit2, Archive, CheckCircle, Clock, Copy, Download, ChevronUp, ChevronDown } from 'lucide-react'
|
||||
import api from '../utils/api'
|
||||
import { generateLegalPdf } from '../utils/legalPdfExport'
|
||||
|
||||
// ─── PDF generation ──────────────────────────────────────────────────────────
|
||||
|
||||
function generateLegalPdf(doc) {
|
||||
const pdf = new jsPDF({ format: 'a4', unit: 'mm' })
|
||||
const marginL = 22
|
||||
const marginR = 22
|
||||
const marginTop = 28
|
||||
const pageW = 210
|
||||
const contentW = pageW - marginL - marginR
|
||||
const bottomLimit = 277 // A4 297mm - 20mm bottom margin
|
||||
let y = marginTop
|
||||
|
||||
const checkBreak = (need) => {
|
||||
if (y + need > bottomLimit) {
|
||||
pdf.addPage()
|
||||
y = marginTop
|
||||
}
|
||||
}
|
||||
|
||||
// Title
|
||||
pdf.setFont('helvetica', 'bold')
|
||||
pdf.setFontSize(20)
|
||||
pdf.text(doc.title, marginL, y)
|
||||
y += 10
|
||||
|
||||
// Meta line
|
||||
const STATUS_DE = { published: 'Gültig seit', draft: 'Entwurf — Stand', archived: 'Archiviert — Stand' }
|
||||
const dateStr = doc.published_at
|
||||
? new Date(doc.published_at).toLocaleDateString('de-DE')
|
||||
: new Date(doc.updated_at || doc.created_at).toLocaleDateString('de-DE')
|
||||
const metaLine = `Version ${doc.version} | ${STATUS_DE[doc.status] || doc.status} ${dateStr}`
|
||||
|
||||
pdf.setFont('helvetica', 'normal')
|
||||
pdf.setFontSize(10)
|
||||
pdf.setTextColor(90, 90, 90)
|
||||
pdf.text(metaLine, marginL, y)
|
||||
y += 3
|
||||
pdf.setDrawColor(0, 0, 0)
|
||||
pdf.setLineWidth(0.4)
|
||||
pdf.line(marginL, y, pageW - marginR, y)
|
||||
y += 8
|
||||
pdf.setTextColor(0, 0, 0)
|
||||
|
||||
// Sections
|
||||
for (const section of (doc.content_sections || [])) {
|
||||
checkBreak(14)
|
||||
pdf.setFont('helvetica', 'bold')
|
||||
pdf.setFontSize(11)
|
||||
pdf.text(section.heading || '', marginL, y)
|
||||
y += 6
|
||||
|
||||
if (section.content) {
|
||||
pdf.setFont('helvetica', 'normal')
|
||||
pdf.setFontSize(10)
|
||||
const lines = pdf.splitTextToSize(section.content, contentW)
|
||||
for (const line of lines) {
|
||||
checkBreak(5)
|
||||
pdf.text(line, marginL, y)
|
||||
y += 5
|
||||
}
|
||||
}
|
||||
y += 5
|
||||
}
|
||||
|
||||
// Footer on every page
|
||||
const total = pdf.getNumberOfPages()
|
||||
for (let i = 1; i <= total; i++) {
|
||||
pdf.setPage(i)
|
||||
pdf.setFont('helvetica', 'normal')
|
||||
pdf.setFontSize(8)
|
||||
pdf.setTextColor(150, 150, 150)
|
||||
const fy = 289
|
||||
pdf.text(
|
||||
`Shinkan Jinkendo | Exportiert am ${new Date().toLocaleDateString('de-DE')}`,
|
||||
marginL, fy
|
||||
)
|
||||
pdf.text(`Seite ${i} von ${total}`, pageW - marginR, fy, { align: 'right' })
|
||||
pdf.setTextColor(0, 0, 0)
|
||||
}
|
||||
|
||||
pdf.save(`${doc.document_type}_v${doc.version}.pdf`)
|
||||
}
|
||||
const PDF_STATUS_META = { published: 'Gültig seit', draft: 'Entwurf — Stand', archived: 'Archiviert — Stand' }
|
||||
|
||||
// ─── Sub-components ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -191,7 +110,12 @@ function SectionEditor({ sections, onChange }) {
|
||||
/>
|
||||
</div>
|
||||
<div className="form-row">
|
||||
<label className="form-label">Inhalt</label>
|
||||
<label className="form-label">
|
||||
Inhalt
|
||||
<span className="form-sub">
|
||||
Einfache Markdown-Formatierung: **fett**, *kursiv*, Listen (- oder 1.), [Link](https://…), Zeilenumbruch mit Leerzeile.
|
||||
</span>
|
||||
</label>
|
||||
<textarea
|
||||
className="form-input" rows={4} value={sec.content}
|
||||
onChange={e => update(i, 'content', e.target.value)}
|
||||
@@ -454,7 +378,11 @@ export default function AdminLegalDocumentsPage() {
|
||||
|
||||
const handleDownload = async (doc) => {
|
||||
const full = await api.getLegalDocument(doc.id)
|
||||
generateLegalPdf(full)
|
||||
const dateStr = full.published_at
|
||||
? new Date(full.published_at).toLocaleDateString('de-DE')
|
||||
: new Date(full.updated_at || full.created_at).toLocaleDateString('de-DE')
|
||||
const metaLine = `Version ${full.version} | ${PDF_STATUS_META[full.status] || full.status} ${dateStr}`
|
||||
generateLegalPdf(full, metaLine)
|
||||
}
|
||||
|
||||
const publishedDoc = documents.find(d => d.status === 'published')
|
||||
|
||||
@@ -1,76 +1,9 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { jsPDF } from 'jspdf'
|
||||
import LegalDocumentBody from '../components/LegalDocumentBody'
|
||||
import { generateLegalPdf, legalSectionNumber } from '../utils/legalPdfExport'
|
||||
import api from '../utils/api'
|
||||
|
||||
function generateLegalPdf(doc) {
|
||||
const pdf = new jsPDF({ format: 'a4', unit: 'mm' })
|
||||
const marginL = 22, marginR = 22, marginTop = 28, pageW = 210
|
||||
const contentW = pageW - marginL - marginR
|
||||
const bottomLimit = 277
|
||||
let y = marginTop
|
||||
|
||||
const checkBreak = (need) => {
|
||||
if (y + need > bottomLimit) { pdf.addPage(); y = marginTop }
|
||||
}
|
||||
|
||||
pdf.setFont('helvetica', 'bold')
|
||||
pdf.setFontSize(20)
|
||||
pdf.text(doc.title, marginL, y)
|
||||
y += 10
|
||||
|
||||
const dateStr = doc.published_at
|
||||
? new Date(doc.published_at).toLocaleDateString('de-DE')
|
||||
: new Date(doc.updated_at || doc.created_at).toLocaleDateString('de-DE')
|
||||
const metaLine = `Version ${doc.version} | Gueltig seit ${dateStr}`
|
||||
|
||||
pdf.setFont('helvetica', 'normal')
|
||||
pdf.setFontSize(10)
|
||||
pdf.setTextColor(90, 90, 90)
|
||||
pdf.text(metaLine, marginL, y)
|
||||
y += 3
|
||||
pdf.setDrawColor(0, 0, 0)
|
||||
pdf.setLineWidth(0.4)
|
||||
pdf.line(marginL, y, pageW - marginR, y)
|
||||
y += 8
|
||||
pdf.setTextColor(0, 0, 0)
|
||||
|
||||
for (const section of (doc.content_sections || [])) {
|
||||
checkBreak(14)
|
||||
pdf.setFont('helvetica', 'bold')
|
||||
pdf.setFontSize(11)
|
||||
pdf.text(section.heading || '', marginL, y)
|
||||
y += 6
|
||||
if (section.content) {
|
||||
pdf.setFont('helvetica', 'normal')
|
||||
pdf.setFontSize(10)
|
||||
const lines = pdf.splitTextToSize(section.content, contentW)
|
||||
for (const line of lines) {
|
||||
checkBreak(5)
|
||||
pdf.text(line, marginL, y)
|
||||
y += 5
|
||||
}
|
||||
}
|
||||
y += 5
|
||||
}
|
||||
|
||||
const total = pdf.getNumberOfPages()
|
||||
for (let i = 1; i <= total; i++) {
|
||||
pdf.setPage(i)
|
||||
pdf.setFont('helvetica', 'normal')
|
||||
pdf.setFontSize(8)
|
||||
pdf.setTextColor(150, 150, 150)
|
||||
const fy = 289
|
||||
pdf.text(
|
||||
`Shinkan Jinkendo | Exportiert am ${new Date().toLocaleDateString('de-DE')}`,
|
||||
marginL, fy
|
||||
)
|
||||
pdf.text(`Seite ${i} von ${total}`, pageW - marginR, fy, { align: 'right' })
|
||||
}
|
||||
|
||||
pdf.save(`${doc.document_type}_v${doc.version}.pdf`)
|
||||
}
|
||||
|
||||
// document_type values used in the DB / API
|
||||
const TYPE_MAP = {
|
||||
impressum: 'impressum',
|
||||
@@ -283,7 +216,13 @@ function LegalPage({ type }) {
|
||||
<h1 style={{ margin: 0, color: 'var(--text1)' }}>{title}</h1>
|
||||
{apiDoc && (
|
||||
<button
|
||||
onClick={() => generateLegalPdf(apiDoc)}
|
||||
onClick={() => {
|
||||
const dateStr = apiDoc.published_at
|
||||
? new Date(apiDoc.published_at).toLocaleDateString('de-DE')
|
||||
: new Date(apiDoc.updated_at || apiDoc.created_at).toLocaleDateString('de-DE')
|
||||
const metaLine = `Version ${apiDoc.version} | Gueltig seit ${dateStr}`
|
||||
generateLegalPdf(apiDoc, metaLine)
|
||||
}}
|
||||
className="btn btn-secondary"
|
||||
style={{ fontSize: '0.82rem', padding: '4px 12px', flexShrink: 0 }}
|
||||
>
|
||||
@@ -295,11 +234,11 @@ function LegalPage({ type }) {
|
||||
{sections.map((section, i) => (
|
||||
<div key={i} style={{ marginBottom: '1.75rem' }}>
|
||||
<h2 style={{ fontSize: '1.05rem', marginBottom: '0.4rem', color: 'var(--text1)' }}>
|
||||
{section.heading}
|
||||
{section.heading
|
||||
? `${legalSectionNumber(i)} ${section.heading}`
|
||||
: legalSectionNumber(i)}
|
||||
</h2>
|
||||
<p style={{ color: isPlaceholder ? 'var(--text3)' : 'var(--text1)', fontStyle: isPlaceholder ? 'italic' : 'normal', margin: 0, whiteSpace: 'pre-wrap' }}>
|
||||
{section.content}
|
||||
</p>
|
||||
<LegalDocumentBody content={section.content} muted={isPlaceholder} />
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user