diff --git a/next.config.ts b/next.config.ts index 833b631..33f267e 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,6 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { + outputFileTracingIncludes: { '/api/pdf-assets/[...path]': ['./node_modules/pdfjs-dist/build/pdf.worker.min.mjs', './node_modules/pdfjs-dist/cmaps/**/*', './node_modules/pdfjs-dist/standard_fonts/**/*', './node_modules/pdfjs-dist/wasm/**/*'] }, experimental: { serverActions: { bodySizeLimit: '10mb' } }, async redirects() { return [ diff --git a/package-lock.json b/package-lock.json index 3c5c121..344187f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "clsx": "^2.1.1", "lucide-react": "^1.34.0", "next": "16.1.6", + "pdfjs-dist": "^6.5.438", "react": "19.2.3", "react-dom": "19.2.3", "react-hook-form": "^7.71.2", @@ -586,6 +587,256 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@napi-rs/canvas": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas/-/canvas-1.1.0.tgz", + "integrity": "sha512-k+ph/D8H9GS8ZZ48okvHrKeJynkqAA1kMUZRuzRWNlQUDHXngq7oRaWMZBdmSfd9ZhVy9bwNKei/7wMboI/uMg==", + "license": "MIT", + "optional": true, + "workspaces": [ + "e2e/*" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "optionalDependencies": { + "@napi-rs/canvas-android-arm64": "1.1.0", + "@napi-rs/canvas-darwin-arm64": "1.1.0", + "@napi-rs/canvas-darwin-x64": "1.1.0", + "@napi-rs/canvas-linux-arm-gnueabihf": "1.1.0", + "@napi-rs/canvas-linux-arm64-gnu": "1.1.0", + "@napi-rs/canvas-linux-arm64-musl": "1.1.0", + "@napi-rs/canvas-linux-riscv64-gnu": "1.1.0", + "@napi-rs/canvas-linux-x64-gnu": "1.1.0", + "@napi-rs/canvas-linux-x64-musl": "1.1.0", + "@napi-rs/canvas-win32-arm64-msvc": "1.1.0", + "@napi-rs/canvas-win32-x64-msvc": "1.1.0" + } + }, + "node_modules/@napi-rs/canvas-android-arm64": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-android-arm64/-/canvas-android-arm64-1.1.0.tgz", + "integrity": "sha512-mKrSmRyhWK4q699Q1xthbZIZi7JBvLtsRNnOZAeFaLPOFT1yo8y82aRC2nNZbXTGJXU7fVDONgGQPr0vo3kerw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-darwin-arm64": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-arm64/-/canvas-darwin-arm64-1.1.0.tgz", + "integrity": "sha512-iqwST4g0oH+x8VCpBIYh+MYokv/mVvkM+v9oJGB0d9A3P2qBh42ogJlVyWq9SpPCrAjS7tplMb1D3OIfxl+utw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-darwin-x64": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-x64/-/canvas-darwin-x64-1.1.0.tgz", + "integrity": "sha512-jkeA8eVTxDum03LTvc32YJ28F6KB1U0gYwnWMfOAUQZvWWEh/kvONby4iWGJx3+Tw45UqMGMXjtw2GKNVZDhVg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-arm-gnueabihf": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm-gnueabihf/-/canvas-linux-arm-gnueabihf-1.1.0.tgz", + "integrity": "sha512-Y4YkKG1ijoqkgUdTEEBNG4k+2BK5bR5jGL6S56YxCXYPwGfUd5nED8/74xyc7z+bpixPasCjSYoP3xYPOIGNxw==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-arm64-gnu": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-gnu/-/canvas-linux-arm64-gnu-1.1.0.tgz", + "integrity": "sha512-dE/XthqYkiWcBVtKFlZbUXwAYfDuQGqDWixznipJNmevLGpprNnTVQZyftm1RZJudkIOn2EkzYZDMMETM08Row==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-arm64-musl": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-musl/-/canvas-linux-arm64-musl-1.1.0.tgz", + "integrity": "sha512-DqZ/CMcHlhU56pPjv9AP0h3U7MFQ5LzC1HzMyRMotL+PFsJmZJA/ziApPYVyyz78DaVLhI8t3So3ztqtijbYpg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-riscv64-gnu": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-riscv64-gnu/-/canvas-linux-riscv64-gnu-1.1.0.tgz", + "integrity": "sha512-kJ7m5n2VffxWXM5QGa5lfq8ZN4LdOJEoz3aAJAmIqYvKiZw1gRdXqpucnRXsF6D9nLYiiIlevaAtAclR7c5ilg==", + "cpu": [ + "riscv64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-x64-gnu": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-gnu/-/canvas-linux-x64-gnu-1.1.0.tgz", + "integrity": "sha512-uQ9JuJlRhQdHyttcMWOiwLkfIqkqaB0YFUVe835LUe12THt2b51HXkTItq0fxWT1jdhUPX2ylWZ1walkJyD6GQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-x64-musl": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-musl/-/canvas-linux-x64-musl-1.1.0.tgz", + "integrity": "sha512-has4CPPAkkCac/LZ13VAw5p+MJLdaKVoyrhumN/A7uJd6960xYkJNDZgUebyxiha82AFzXx6RV+QJg5qGG079g==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-win32-arm64-msvc": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-arm64-msvc/-/canvas-win32-arm64-msvc-1.1.0.tgz", + "integrity": "sha512-MJnktLKNijmXqdjTughHDZ9TDLZ9uUm2hvFXqaOqn0+w7lphXFnft6bpSgQAc9U1exc20UGIBlzGu9+kiCj9Ag==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-win32-x64-msvc": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-x64-msvc/-/canvas-win32-x64-msvc-1.1.0.tgz", + "integrity": "sha512-08575bFk7iiadxap4h+JxgGut9xDCHAGum6wh0eInN53zEMImkmEHi5MushX2FOmNO7qRNX7BPiDC5ZYBwHeEg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, "node_modules/@next/env": { "version": "16.1.6", "resolved": "https://registry.npmjs.org/@next/env/-/env-16.1.6.tgz", @@ -1500,6 +1751,18 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/pdfjs-dist": { + "version": "6.5.438", + "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-6.5.438.tgz", + "integrity": "sha512-vg8Pw1x+AFKy4AMDvhuWl5cOYV8d698UoEANoFFhc79hqXDnZQqnOXoxw3HG907WHOg1JYOvLhP756boddFxpA==", + "license": "Apache-2.0", + "engines": { + "node": ">=22.13.0 || >=24" + }, + "optionalDependencies": { + "@napi-rs/canvas": "^1.0.13" + } + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", diff --git a/package.json b/package.json index 65d84cb..424d6a7 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "clsx": "^2.1.1", "lucide-react": "^1.34.0", "next": "16.1.6", + "pdfjs-dist": "^6.5.438", "react": "19.2.3", "react-dom": "19.2.3", "react-hook-form": "^7.71.2", diff --git a/pdf-frontend.stderr.log b/pdf-frontend.stderr.log new file mode 100644 index 0000000..e69de29 diff --git a/pdf-frontend.stdout.log b/pdf-frontend.stdout.log new file mode 100644 index 0000000..e69de29 diff --git a/pdf-preview.stderr.log b/pdf-preview.stderr.log new file mode 100644 index 0000000..e69de29 diff --git a/pdf-preview.stdout.log b/pdf-preview.stdout.log new file mode 100644 index 0000000..79b181b --- /dev/null +++ b/pdf-preview.stdout.log @@ -0,0 +1,6 @@ +▲ Next.js 16.1.6 +- Local: http://localhost:4010 +- Network: http://10.8.1.11:4010 + +✓ Starting... +✓ Ready in 673ms diff --git a/src/actions/anzeigen/api-anzeigewerte.ts b/src/actions/anzeigen/api-anzeigewerte.ts index a74b770..c657de6 100644 --- a/src/actions/anzeigen/api-anzeigewerte.ts +++ b/src/actions/anzeigen/api-anzeigewerte.ts @@ -2,6 +2,15 @@ import { revalidatePath } from 'next/cache'; import type { DisplayTable, DisplayComparison, DisplaySlot } from '@/types/anzeigen/anzeigewerte'; const url = 'http://localhost:3000/rk2/anzeigewerte'; +type DisplayResult = { success: true; data: T } | { success: false; error: string }; + +// Erwartete API-Fehler als Daten zurückgeben: Next.js verbirgt geworfene Server-Action-Fehler im Produktionsbetrieb. +async function displayResult(work: () => Promise): Promise> { + try { return { success: true, data: await work() }; } + catch (cause) { + return { success: false, error: cause instanceof Error ? cause.message : 'ProCon-Vergleich konnte nicht verarbeitet werden.' }; + } +} async function request(path = '', init?: RequestInit): Promise { const response = await fetch(url + path, { cache: 'no-store', ...init }); const data = await response.json(); @@ -16,11 +25,17 @@ export async function api_saveDisplays(table: DisplayTable) { revalidatePath('/visualisierung'); return saved; } -export async function api_compareDisplay(id: string) { return request('/' + encodeURIComponent(id) + '/sync'); } +export async function api_compareDisplay(id: string) { + return displayResult(() => request('/' + encodeURIComponent(id) + '/sync')); +} export async function api_syncDisplay(id: string, data: Pick & { direction: 'toLocal' | 'toProcon'; fields: boolean; layout: boolean; graphics: boolean; targets: Partial>; layoutTargets: Record; placementIds?: string[]; -}) { return request('/' + encodeURIComponent(id) + '/sync', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); } +}) { + return displayResult(() => request('/' + encodeURIComponent(id) + '/sync', { + method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data), + })); +} export async function api_displayXaml() { return request<{ name: string; data: string }[]>('/xaml'); } export async function api_exportDisplayXaml(anlageId: string) { return request<{ count: number; directory: string }>('/xaml', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ anlageId }) }); diff --git a/src/actions/parameter/api-parameter.ts b/src/actions/parameter/api-parameter.ts index fa044a0..815427b 100644 --- a/src/actions/parameter/api-parameter.ts +++ b/src/actions/parameter/api-parameter.ts @@ -1,7 +1,19 @@ 'use server'; import { revalidatePath } from 'next/cache'; -import type { ParameterTable } from '@/types/parameter'; +import type { ParameterTable, ParameterComparison, ParameterBulkComparison, ProconParameterValues } from '@/types/parameter'; const url = 'http://localhost:3000/rk2/parameter'; +type ParameterResult = { success: true; data: T } | { success: false; error: string }; + +async function syncRequest(path: string, init?: RequestInit): Promise> { + try { + const response = await fetch(url + path, { cache: 'no-store', ...init }); + const result = await response.json(); + if (!response.ok) return { success: false, error: Array.isArray(result.message) ? result.message.join(', ') : result.message ?? 'Parameter-Abgleich fehlgeschlagen.' }; + return { success: true, data: result }; + } catch { + return { success: false, error: 'Parameter-Abgleich nicht erreichbar. Bitte Backend-Verbindung prüfen.' }; + } +} async function request(init?: RequestInit): Promise { const response = await fetch(url, { cache: 'no-store', ...init }); const data = await response.json(); @@ -22,15 +34,35 @@ export async function api_saveParameters(table: ParameterTable) { revalidatePath('/parameter'); return saved; } -export async function api_compareParameter(id: string): Promise { - const response = await fetch(url + '/' + encodeURIComponent(id) + '/sync', { cache: 'no-store' }); - const result = await response.json(); - if (!response.ok) throw new Error(Array.isArray(result.message) ? result.message.join(', ') : result.message ?? 'Vergleich fehlgeschlagen'); +export async function api_compareParameter(id: string) { + return syncRequest('/' + encodeURIComponent(id) + '/sync'); +} +export async function api_compareAllParameters() { + return syncRequest('/sync-all'); +} +export async function api_proconParameterValues() { + return syncRequest('/procon-values'); +} +export async function api_saveProconParameterValue(dto: { + anlageId: string; verbindungId: string; parameterId: number; version: string; wert: string | null; +}) { + return syncRequest<{ parameterId: number; wert: string | null }>('/procon-values', { + method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(dto), + }); +} +export async function api_syncAllParameters(dto: { + anlageId: string; verbindungId: string; version: string; direction: 'toLocal' | 'toProcon'; ids: string[]; +}) { + const result = await syncRequest('/sync-all', { + method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(dto), + }); + if (result.success) { revalidatePath('/parameter'); revalidatePath('/parameter/bearbeiten'); } return result; } -export async function api_syncParameter(id: string, dto: { anlageId: string; verbindungId: string; version: string; direction: 'toLocal' | 'toProcon' }): Promise { - const response = await fetch(url + '/' + encodeURIComponent(id) + '/sync', { method: 'POST', cache: 'no-store', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(dto) }); - const result = await response.json(); - if (!response.ok) throw new Error(Array.isArray(result.message) ? result.message.join(', ') : result.message ?? 'Synchronisierung fehlgeschlagen'); - revalidatePath('/parameter'); return result; +export async function api_syncParameter(id: string, dto: { anlageId: string; verbindungId: string; version: string; direction: 'toLocal' | 'toProcon' }) { + const result = await syncRequest('/' + encodeURIComponent(id) + '/sync', { + method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(dto), + }); + if (result.success) revalidatePath('/parameter', 'layout'); + return result; } diff --git a/src/actions/procon/api-zuordnung.ts b/src/actions/procon/api-zuordnung.ts index 45c8b58..3fd04c4 100644 --- a/src/actions/procon/api-zuordnung.ts +++ b/src/actions/procon/api-zuordnung.ts @@ -1,6 +1,12 @@ 'use server'; import type { MappingPreview } from '@/types/procon/zuordnung'; +import type { SavedAggregateLinks } from '@/types/procon/zuordnung'; const url = 'http://localhost:3000/procon/aggregate/zuordnung'; +export async function api_savedAggregateLinks(): Promise { + const response = await fetch(url + '/gespeichert', { cache: 'no-store' }); + if (!response.ok) throw new Error('Gespeicherte Zuordnung konnte nicht geladen werden.'); + return response.json(); +} export async function api_mappingRepair(dto: Pick & { proConAggregateId: number }) { const response = await fetch(url + '/reparieren', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(dto) }); const result = await response.json(); diff --git a/src/actions/visualisierung/api-library.ts b/src/actions/visualisierung/api-library.ts index 0a0c6ff..5a425c3 100644 --- a/src/actions/visualisierung/api-library.ts +++ b/src/actions/visualisierung/api-library.ts @@ -10,6 +10,13 @@ async function request(path = '', init?: RequestInit): Promise { return result; } export async function api_graphicLibrary() { return request(); } +export async function api_renameLibraryGraphic(id: string, input: { anlageId: string; version: number; name: string }) { + const asset = await request('/' + encodeURIComponent(id) + '/name', { + method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(input), + }); + revalidatePath('/', 'layout'); + return asset; +} export async function api_updateLibraryGraphic(id: string, input: { anlageId: string; version: number; generator: GrafikGeneratorDaten; variant: string }) { const body = JSON.stringify({ ...input, generator: { grafikTyp: input.generator.grafikTyp, config: input.generator.config, options: input.generator.options } }); if (new TextEncoder().encode(body).length > 9 * 1024 * 1024) throw new Error('Grafikparameter sind zu groß'); diff --git a/src/app/(pages)/procon/aggregate/[id]/visualisierungen/page.tsx b/src/app/(pages)/procon/aggregate/[id]/visualisierungen/page.tsx index 63b46b5..9363b10 100644 --- a/src/app/(pages)/procon/aggregate/[id]/visualisierungen/page.tsx +++ b/src/app/(pages)/procon/aggregate/[id]/visualisierungen/page.tsx @@ -1,5 +1,6 @@ import Link from 'next/link'; import { api_ProconAggregate_Visualisierungen } from '@/actions/procon/api-procon-aggregate'; +import AggregateSourceInfo from '@/components/procon/aggregateSourceInfo'; export default async function Page({ params }: { params: Promise<{ id: string }> }) { const { id } = await params; @@ -8,11 +9,14 @@ export default async function Page({ params }: { params: Promise<{ id: string }> try { const { aggregat: aggregate, visualisierungen } = await api_ProconAggregate_Visualisierungen(Number(id)); return
{back} -

{aggregate.SPSAntriebId} · {aggregate.Bezeichnung}

+

ProCon-Visualisierungen (SQL)

+

SPS-Antrieb {aggregate.SPSAntriebId} · {aggregate.Bezeichnung}

+

Diese Ansicht zeigt den gespeicherten Stand der verbundenen ProCon-SQL-Datenbank. Eigene Grafiken erstellst du in MongoDB; die gemeinsame Arbeitsfläche dient zum Vergleichen und Abgleichen.

- {[['Datenbank-ID', aggregate.Id], ['BMK', aggregate.BMK], ['View', aggregate.ViewName], ['Motoren', aggregate.AnzahlMotor]].map(([label, value]) => + {[['ProCon-Aggregat-ID (SQL)', aggregate.Id], ['BMK', aggregate.BMK], ['View', aggregate.ViewName], ['Motoren', aggregate.AnzahlMotor]].map(([label, value]) =>
{label}
{value ?? '—'}
)}
+

Visualisierungen ({visualisierungen.length})

Gemeinsame Arbeitsfläche öffnen {!visualisierungen.length ?

Für dieses Aggregat sind keine Visualisierungen vorhanden.

:
diff --git a/src/app/anlagen/pdf/page.tsx b/src/app/anlagen/pdf/page.tsx new file mode 100644 index 0000000..2fd3eab --- /dev/null +++ b/src/app/anlagen/pdf/page.tsx @@ -0,0 +1,9 @@ +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; +import { AnlagePdfViewer } from '@/components/rk/anlage/anlagePdfViewer'; + +export default async function Page({ searchParams }: { searchParams: Promise<{ unit?: string }> }) { + const anlage = await api_anlage_getSelected(); + if (!anlage?.id) return

Bitte zuerst eine Anlage auswählen.

; + const { unit } = await searchParams; + return ; +} diff --git a/src/app/anzeigewerte/export/route.ts b/src/app/anzeigewerte/export/route.ts index 20e7f16..15a443d 100644 --- a/src/app/anzeigewerte/export/route.ts +++ b/src/app/anzeigewerte/export/route.ts @@ -3,6 +3,6 @@ export async function GET() { const response = await fetch('http://localhost:3000/rk2/anzeigewerte/export', { cache: 'no-store' }); if (!response.ok) return new Response('Excel-Export fehlgeschlagen', { status: 502 }); return new Response(response.body, { headers: { 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'Content-Disposition': 'attachment; filename="Anzeigewerte.xlsx"', 'Cache-Control': 'no-store' } }); + 'Content-Disposition': 'attachment; filename="AllgemeinAnlagenVisualisierung.xlsx"', 'Cache-Control': 'no-store' } }); } catch { return new Response('Keine Verbindung zum Backend', { status: 502 }); } } diff --git a/src/app/api/anlagen/[id]/pdf/[[...path]]/route.ts b/src/app/api/anlagen/[id]/pdf/[[...path]]/route.ts new file mode 100644 index 0000000..3cf42aa --- /dev/null +++ b/src/app/api/anlagen/[id]/pdf/[[...path]]/route.ts @@ -0,0 +1,37 @@ +import { NextRequest } from 'next/server'; + +export const runtime = 'nodejs'; +export const dynamic = 'force-dynamic'; + +type Context = { params: Promise<{ id: string; path?: string[] }> }; + +async function proxy(request: NextRequest, context: Context) { + const { id, path = [] } = await context.params; + if (!/^[a-f\d]{24}$/i.test(id) || !( + path.length === 0 || path.length === 1 && ['file', 'units'].includes(path[0]) || + path.length === 2 && path[0] === 'units' && /^[a-f\d]{24}$/i.test(path[1]) + )) return Response.json({ message: 'Ungültiger PDF-Pfad' }, { status: 400 }); + const url = new URL(`http://localhost:3000/anlage/${id}/pdf${path.length ? '/' + path.join('/') : ''}`); + url.search = request.nextUrl.search; + const headers = new Headers(); + for (const name of ['content-type', 'range', 'if-range']) { + const value = request.headers.get(name); + if (value) headers.set(name, value); + } + try { + const response = await fetch(url, { + method: request.method, headers, cache: 'no-store', + body: request.method === 'GET' ? undefined : await request.arrayBuffer(), + }); + const outgoing = new Headers({ 'Cache-Control': 'no-store' }); + for (const name of ['content-type', 'content-length', 'content-range', 'accept-ranges']) { + const value = response.headers.get(name); + if (value) outgoing.set(name, value); + } + return new Response(response.body, { status: response.status, headers: outgoing }); + } catch { + return Response.json({ message: 'Keine Verbindung zum Backend' }, { status: 502 }); + } +} + +export { proxy as GET, proxy as POST, proxy as PATCH }; diff --git a/src/app/api/pdf-assets/[...path]/route.ts b/src/app/api/pdf-assets/[...path]/route.ts new file mode 100644 index 0000000..08d3b74 --- /dev/null +++ b/src/app/api/pdf-assets/[...path]/route.ts @@ -0,0 +1,18 @@ +import { readFile } from 'node:fs/promises'; +import { join } from 'node:path'; + +export const runtime = 'nodejs'; + +export async function GET(_request: Request, { params }: { params: Promise<{ path: string[] }> }) { + const { path } = await params; + const worker = path.length === 1 && path[0] === 'pdf.worker.min.mjs'; + const resource = path.length === 2 && ['cmaps', 'standard_fonts', 'wasm'].includes(path[0]) && /^[\w.-]+$/.test(path[1]); + if (!worker && !resource) return new Response(null, { status: 404 }); + try { + const file = await readFile(join(process.cwd(), 'node_modules/pdfjs-dist', ...(worker ? ['build', path[0]] : path))); + return new Response(file, { headers: { + 'Content-Type': worker ? 'text/javascript' : path.at(-1)?.endsWith('.wasm') ? 'application/wasm' : 'application/octet-stream', + 'Cache-Control': 'no-cache', + } }); + } catch { return new Response(null, { status: 404 }); } +} diff --git a/src/app/signals/assignments/page.tsx b/src/app/signals/assignments/page.tsx index 5de685b..3493ff7 100644 --- a/src/app/signals/assignments/page.tsx +++ b/src/app/signals/assignments/page.tsx @@ -29,7 +29,9 @@ export default async function AssignmentsPage() { return names; }; - const rows: AssignmentRow[] = signals.filter((signal) => signal.anlageId === anlage.id && signal.ioId).map((signal) => { + const plantSignals = signals.filter(signal => signal.anlageId === anlage.id); + const assignedIoIds = new Set(plantSignals.map(signal => signal.ioId).filter(Boolean)); + const rows: AssignmentRow[] = plantSignals.map((signal) => { const context = signal.componentId ? componentMap.get(signal.componentId) : undefined; const io = ioMap.get(signal.ioId!); return { @@ -48,12 +50,28 @@ export default async function AssignmentsPage() { byte: io?.adrByte, bit: io?.adrBit, functionText: io?.functionText ?? '', + pageReference: io?.seiteName ?? '', + description: signal.description ?? '', + signalType: signal.type, + status: !signal.ioId ? 'Signal ohne IO' : !io ? 'IO nicht gefunden' : signal.type !== io.adrType ? 'Typabweichung' : 'Zugeordnet', + assigned: !!io, }; }); + for (const io of ioMap.values()) { + if (assignedIoIds.has(io.id)) continue; + rows.push({ + id: `io-${io.id}`, type: io.adrType, byte: io.adrByte, bit: io.adrBit, + functionText: io.functionText ?? '', pageReference: io.seiteName ?? '', + group: '', bmk: '', unit: '', component: '', signal: '', signalType: '', description: '', + status: 'IO ohne Signal', assigned: false, + exportName: '', variableTable: '', exportComment: '', + }); + } return
-

IO-Zuordnungen ({rows.length})

+

MongoDB-IOs / meine Signale

+

Alle IOs und Signale der ausgewählten Anlage. Abgleich über die gespeicherte IO-Zuordnung; IOs ohne Signal und Signale ohne IO bleiben sichtbar.

Zuordnungen bearbeiten
; diff --git a/src/app/signals/page.tsx b/src/app/signals/page.tsx index 684411b..0247c15 100644 --- a/src/app/signals/page.tsx +++ b/src/app/signals/page.tsx @@ -24,6 +24,9 @@ export default async function PageSignale() {
+ + MongoDB-IOs / meine Signale vergleichen + Alle IO-Zuordnungen diff --git a/src/app/visu-aggregate/[componentId]/grafiken/page.tsx b/src/app/visu-aggregate/[componentId]/grafiken/page.tsx index 96064a9..ec90d65 100644 --- a/src/app/visu-aggregate/[componentId]/grafiken/page.tsx +++ b/src/app/visu-aggregate/[componentId]/grafiken/page.tsx @@ -1,13 +1,17 @@ import Link from 'next/link'; import { api_viewAggregate } from '@/actions/rk2/api-procon-view-aggregate'; import ViewAggregateForm from '@/components/rk2/visu-aggregate/viewAggregateForm'; +import AggregateSourceInfo from '@/components/procon/aggregateSourceInfo'; export default async function Page({ params }: { params: Promise<{ componentId: string }> }) { const { componentId } = await params; try { const data = await api_viewAggregate(componentId); return
Zurück zu VisuAggregate -

Grafiken – {data.name}

+

Eigene Grafiken (MongoDB) – {data.name}

+

Hier erstellst und speicherst du deine Hauptgrafik, Pfeile und weiteren Grafikelemente in MongoDB. Änderungen werden über Export/Import oder Abgleich nach ProCon übertragen.

+

Unit-Komponenten-ID: {componentId} · View: {data.viewName || 'Nicht vergeben'}

+
; } catch (error) { diff --git a/src/components/anzeigen/displayBulkEditor.tsx b/src/components/anzeigen/displayBulkEditor.tsx new file mode 100644 index 0000000..4dde493 --- /dev/null +++ b/src/components/anzeigen/displayBulkEditor.tsx @@ -0,0 +1,167 @@ +'use client'; + +import { useState } from 'react'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Select } from '@/components/ui/select'; +import LibraryPicker from '@/components/visualisierung/libraryPicker'; +import GraphicGeneratorDialog from '@/components/visualisierung/graphicGeneratorDialog'; +import { libraryBinding } from '@/types/visualisierung/library'; +import type { GrafikGeneratorDaten } from '@/types/visualisierung/graphic'; +import type { DisplayGraphic, DisplayRow, DisplaySlot } from '@/types/anzeigen/anzeigewerte'; +import { applyDisplayPlacements, applyDisplayValues, assignDisplayGraphic, type DisplayValuePatch, type PlacementPatch, type PlacementScope } from '@/lib/anzeigen/bulk'; + +const placementFields = [ + ['width', 'Breite'], ['height', 'Höhe'], ['x', 'X'], ['y', 'Y'], ['z', 'Z-Index'], +] as const; +const displayValueFields = [ + ['statistikProconId', 'StatistikTyp-ID (ProCon)'], ['zuweisungGauge', 'ZuweisungGauge'], + ['min', 'Min'], ['max', 'Max'], ['skalierung', 'Skalierung von SPS'], +] as const; + +export default function DisplayBulkEditor({ rows, selectedIds, anlageId, disabled, onApply }: { + rows: DisplayRow[]; selectedIds: ReadonlySet; anlageId: string; disabled: boolean; + onApply: (rows: DisplayRow[], message: string) => void; +}) { + const [enabled, setEnabled] = useState>>({}); + const [values, setValues] = useState({ width: '120', height: '80', x: '0', y: '0', z: '0' }); + const [show, setShow] = useState(true); + const [displayType, setDisplayType] = useState('Xaml'); + const [valueEnabled, setValueEnabled] = useState>>({}); + const [displayValues, setDisplayValues] = useState({ statistikProconId: '', zuweisungGauge: '', min: '', max: '', skalierung: '' }); + const [scope, setScope] = useState('first'); + const [positionMode, setPositionMode] = useState<'absolute' | 'offset'>('absolute'); + const [slot, setSlot] = useState('permanent'); + const [replaceExisting, setReplaceExisting] = useState(false); + const [picker, setPicker] = useState(false); + const [generating, setGenerating] = useState(false); + const [draft, setDraft] = useState(null); + const [variant, setVariant] = useState(''); + const [error, setError] = useState(''); + + function assign(graphic: DisplayGraphic) { + if (disabled || !selectedIds.size) return; + try { + const result = assignDisplayGraphic(rows, selectedIds, graphic, replaceExisting); + onApply(result.rows, `${result.changed} Anzeigen mit Grafik belegt, ${result.skipped} vorhandene Belegungen übersprungen. Bitte speichern.`); + setError(''); + } catch (cause) { setError(cause instanceof Error ? cause.message : 'Zuweisung fehlgeschlagen'); } + } + + return
+ Mehrfachbearbeitung · {selectedIds.size} gefilterte Anzeigen ausgewählt +
+

Die Änderungen gelten für die markierten Anzeigen im aktuellen Filter. Nur angehakte Felder werden übernommen.

+
+

Anzeigetyp

+
+ + +
+

Grafikbelegungen, Platzierungen und sonstige Anzeigedaten bleiben erhalten.

+
+
+

Statistik, Gauge und Wertebereich

+
{displayValueFields.map(([key, label]) =>
+ + setDisplayValues(current => ({ ...current, [key]: event.target.value }))} /> +
)}
+

Nur angehakte Felder ändern. Eine leere Eingabe setzt den Wert zurück. Min und Max werden je Anzeige geprüft.

+ +
+
+

Größe, Position und Sichtbarkeit

+
+ + +
+
{placementFields.map(([key, label]) =>
+ + setValues(current => ({ ...current, [key]: event.target.value }))} /> +
)} +
+
+
+

Absolutes X/Y setzt alle gewählten Platzierungen auf dieselbe Position. Verschieben erhält ihre Abstände. Die Anzeigegröße ändert die Platzierung, nicht die Bibliotheksgrafik.

+ +
+
+

Grafik gemeinsam zuweisen

+
+ + + + +
+ {draft &&
+ + +
} +

Andere Belegungen und vorhandene Platzierungen bleiben erhalten. Anschließend oben „Speichern“ klicken.

+
+
+ {error &&

{error}

} + {picker && setPicker(false)} onApply={asset => { + if (asset.anlageId !== anlageId) { setError('Anlage geändert. Seite neu laden.'); setPicker(false); return; } + assign(libraryBinding(asset, slot, '')); setPicker(false); + }} />} + {generating && setGenerating(false)} onApply={result => { + setDraft(result); setVariant(result.ergebnis.varianten[0].state); setGenerating(false); + }} saveHint="Danach die Variante wählen, den ausgewählten Anzeigen zuweisen und speichern." />} +
; +} diff --git a/src/components/anzeigen/displaySyncDialog.tsx b/src/components/anzeigen/displaySyncDialog.tsx index c553ed2..825ceb1 100644 --- a/src/components/anzeigen/displaySyncDialog.tsx +++ b/src/components/anzeigen/displaySyncDialog.tsx @@ -15,7 +15,9 @@ export default function DisplaySyncDialog({ id, onClose, onDone }: { id: string; async function load() { setBusy(true); setError(''); try { - const next = await api_compareDisplay(id); setData(next); + const result = await api_compareDisplay(id); + if (!result.success) { setError(result.error); return; } + const next = result.data; setData(next); const selected: Partial> = {}; for (const graphic of next.local.graphics) { const matches = next.visuals.filter(remote => remote.Discriminator === 'AnzeigeParameterXamlVisualisierung' && remote.State === ({ ein: 0, aus: 1, permanent: 2 })[graphic.slot]); @@ -33,7 +35,8 @@ export default function DisplaySyncDialog({ id, onClose, onDone }: { id: string; setBusy(true); setError(''); try { const next = await api_syncDisplay(id, { anlageId: data.anlageId, verbindungId: data.verbindungId, version: data.version, direction, ...parts, targets, layoutTargets }); - onDone(next); onClose(); + if (!next.success) { setError(next.error); return; } + onDone(next.data); onClose(); } catch (cause) { setError(cause instanceof Error ? cause.message : 'Synchronisierung fehlgeschlagen'); } finally { setBusy(false); } } @@ -54,6 +57,13 @@ export default function DisplaySyncDialog({ id, onClose, onDone }: { id: string; )}

Lokal: {(() => { const p = data.local.placements.find(p => p.id === graphic.placementId); return p ? `X ${p.x}, Y ${p.y}, ${p.width} × ${p.height}, Z ${p.z}, sichtbar: ${p.show}` : 'keine Platzierung'; })()}

+ {(() => { + const target = data.visuals.find(remote => remote.Id === targets[graphic.slot]); + const view = data.views.find(view => view.id === target?.ViewId); + return view && view.usages > 1 ?

+ XAML-View „{view.id}“ wird in ProCon {view.usages}-mal verwendet. Beim Übertragen der XAML-Grafik erhalten alle Verwendungen die neue Grafik. +

: null; + })()}
)} {data.visuals.some(v => v.Discriminator !== 'AnzeigeParameterXamlVisualisierung') && data.local.placements.map(placement =>
-
-
+
+ + + {bulkIds.size} von {visible.length} gefilterten Anzeigen markiert +
+ +
+ { + if (busy || syncId) return; + if (rows.some((row, index) => row !== data.rows[index])) update({ ...data, rows }); + setMessage(notice); setError(''); + }} /> +
+
+
Nr.BeschreibungTypGrafiken
{visible.sort((a, b) => a.datenNr - b.datenNr).map(row => + )}
AuswahlNr.BeschreibungTypGrafiken
setCheckedIds(current => { + const next = new Set(current); + if (event.target.checked) next.add(row.id); else next.delete(row.id); + return next; + })} /> {row.datenNr}{row.typ}{row.graphics.length}
{!visible.length &&

Keine Anzeigen gefunden.

}
- {selected &&
+ {selected &&

Löschen entfernt die Anzeige mit ihren Grafiken und Platzierungen nach dem Speichern. Die Daten-Nr. wird frei; andere Nummern bleiben erhalten. ProCon-Daten werden dabei nicht gelöscht.

@@ -152,6 +177,8 @@ export default function DisplayTable({ initial }: { initial: TableData }) { }} />} {generator && selected && g.slot === generator.slot && !g.libraryId)?.generator} onApply={applyGraphic} onClose={() => setGenerator(null)} saveHint="Danach die Anzeigewerte speichern. Position und Anzeigegröße bleiben erhalten." />} {syncId && setSyncId(null)} onDone={next => { setData(next); setDirty(false); setMessage('Synchronisierung abgeschlossen.'); }} />} +
{dirty &&

Ungespeicherte Änderungen

}{message &&

{message}

}{error &&

{error}

} +
; } diff --git a/src/components/navigation/appContent.tsx b/src/components/navigation/appContent.tsx index 828a1dc..b5fd650 100644 --- a/src/components/navigation/appContent.tsx +++ b/src/components/navigation/appContent.tsx @@ -4,7 +4,8 @@ import type { ReactNode } from 'react'; import AppBreadcrumbs from './appBreadcrumbs'; export default function AppContent({ children }: { children: ReactNode }) { - const editor = usePathname() === '/visualisierung'; + const pathname = usePathname(); + const editor = pathname === '/visualisierung' || pathname === '/sensoren-digital/bearbeiten' || pathname === '/anzeigewerte/bearbeiten'; return
{children} diff --git a/src/components/navigation/appSidebar.tsx b/src/components/navigation/appSidebar.tsx index 1e6fdd7..8e7ab2c 100644 --- a/src/components/navigation/appSidebar.tsx +++ b/src/components/navigation/appSidebar.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from 'react'; import { ChevronDown } from 'lucide-react'; import { proconNavigation } from '@/_config/procon-navigation'; -interface NavigationItem { label: string; href?: string } +interface NavigationItem { label: string; href?: string; children?: NavigationItem[] } interface NavigationGroup { id: string; label: string; items: NavigationItem[] } const groups: NavigationGroup[] = [ @@ -15,6 +15,7 @@ const groups: NavigationGroup[] = [ { label: 'Anlage auswählen', href: '/alt/rk/anlagen' }, { label: 'Gruppen', href: '/groups' }, { label: 'Units', href: '/units' }, + { label: 'Anlagen-PDF', href: '/anlagen/pdf' }, { label: 'EA’s', href: '/signals' }, { label: 'IO-Übersicht', href: '/ios' }, { label: 'Datensicherung', href: '/datensicherung' }, @@ -42,8 +43,9 @@ const groups: NavigationGroup[] = [ { label: 'Web-Visu', href: '/visualisierung' }, { label: 'Live-Anlagenansicht', href: '/live-anlage' }, { label: 'Grafikbibliothek', href: '/visualisierung/bibliothek' }, - { label: 'VisuAggregate', href: '/visu-aggregate' }, - { label: 'Grafikübersicht', href: '/visu-aggregate/grafiken' }, + { label: 'VisuAggregate', href: '/visu-aggregate', children: [ + { label: 'Grafikübersicht', href: '/visu-aggregate/grafiken' }, + ] }, { label: 'Positionstabelle', href: '/procon/positionen' }, { label: 'Zuordnung Aggregate', href: '/procon/zuordnung' }, { label: 'Zuordnung Signale Analog' }, @@ -55,10 +57,11 @@ export default function AppSidebar() { const pathname = usePathname(); const [expanded, setExpanded] = useState>({}); // Only the most specific route is active, including on detail and export pages. - const active = [...groups.flatMap(group => group.items), { label: 'Alt', href: '/alt' }] + const flatten = (items: NavigationItem[]): NavigationItem[] => items.flatMap(item => [item, ...flatten(item.children ?? [])]); + const active = [...groups.flatMap(group => flatten(group.items)), { label: 'Alt', href: '/alt' }] .filter(item => item.href && (pathname === item.href || item.href !== '/' && pathname.startsWith(item.href + '/'))) .sort((a, b) => b.href!.length - a.href!.length)[0]?.href; - const activeGroup = groups.find(group => group.items.some(item => item.href === active))?.id; + const activeGroup = groups.find(group => flatten(group.items).some(item => item.href === active))?.id; useEffect(() => { if (activeGroup) setExpanded(current => ({ ...current, [activeGroup]: true })); }, [activeGroup, pathname]); @@ -74,6 +77,15 @@ export default function AppSidebar() { ; } + function navigationEntry(item: NavigationItem) { + return
  • + {navigationLink(item)} + {item.children &&
      + {item.children.map(navigationEntry)} +
    } +
  • ; + } + return
    {graphic.xamlOverride !== undefined ?

    Aus ProCon übernommenes XAML; erneutes Generieren ersetzt diese Fassung.

    : variant?.svg && /* eslint-disable-next-line @next/next/no-img-element */ {`${labels[slot]}:} diff --git a/src/components/visualisierung/graphicGeneratorDialog.tsx b/src/components/visualisierung/graphicGeneratorDialog.tsx index aeb46ac..1b97d02 100644 --- a/src/components/visualisierung/graphicGeneratorDialog.tsx +++ b/src/components/visualisierung/graphicGeneratorDialog.tsx @@ -30,6 +30,11 @@ export default function GraphicGeneratorDialog({ initial, onApply, onClose, save const [rectTransparent,setRectTransparent]=useState(initial?.options.fill===undefined||['transparent','none'].includes(String(initial?.options.fill))); const [rectFill,setRectFill]=useState(/^#[0-9a-f]{6}$/i.test(String(initial?.options.fill))?String(initial?.options.fill):'#808080'); const [scale, setScale] = useState(Number(initial?.config.scale ?? 2)); + const [textContent, setTextContent] = useState(String(initial?.config.text ?? 'Text')); + const [textFontSize, setTextFontSize] = useState(Number(initial?.config.fontSize ?? 16)); + const [textFrame, setTextFrame] = useState(initial?.options.frame === true); + const [sensorDirection, setSensorDirection] = useState<'oben' | 'unten' | 'rechts' | 'links'>( + (initial?.options.direction as 'oben' | 'unten' | 'rechts' | 'links' | undefined) ?? 'unten'); const [raster, setRaster] = useState(Number(initial?.config.raster ?? 4)); const [length, setLength] = useState(Number(initial?.config.length ?? 200)); const [width, setWidth] = useState(Number(initial?.config.width ?? 40)); @@ -52,7 +57,13 @@ export default function GraphicGeneratorDialog({ initial, onApply, onClose, save if (busy) return; setBusy(true); setError(''); try { - if (type === 'rechteck') { + if (type === 'text') { + const config = { text: textContent, width: rectWidth, height: rectHeight, fontSize: textFontSize }; + const options = { ...colors, frame: textFrame, stroke: rectStroke, strokeWidth: rectStrokeWidth, + fill: rectTransparent ? 'transparent' : rectFill }; + const ergebnis = await api_drawRender('text', { config, options }); + setResult({ grafikTyp: 'text', config, options, ergebnis }); + } else if (type === 'rechteck') { const config={width:rectWidth,height:rectHeight},options={stroke:rectBorder?rectStroke:'none',strokeWidth:rectStrokeWidth,fill:rectTransparent?'transparent':rectFill}; const ergebnis=await api_drawRender('rechteck',{config,options});setResult({grafikTyp:'rechteck',config,options,ergebnis}); } else if (type === 'fahrwagenOben') { @@ -71,10 +82,11 @@ export default function GraphicGeneratorDialog({ initial, onApply, onClose, save const config = { scale, raster }, options = { colorInactive: colors.colorInactive, colorActive: colors.colorActive }; const ergebnis = await api_drawRender('punkt', { config, options }); setResult({ grafikTyp: 'punkt', config, options, ergebnis }); - } else if (type === 'motor') { + } else if (type === 'motor' || type === 'endschalter') { const config = { scale, raster }; - const ergebnis = await api_drawRender('motor', { config, options: colors }); - setResult({ grafikTyp: 'motor', config, options: colors, ergebnis }); + const options = type === 'endschalter' ? { ...colors, direction: sensorDirection } : colors; + const ergebnis = await api_drawRender(type, { config, options }); + setResult({ grafikTyp: type, config, options, ergebnis }); } else if (type === 'warnung') { const config = { width: warningWidth, height: warningHeight }, options = { color: warningColor }; const ergebnis = await api_drawRender('warnung', { config, options }); @@ -94,13 +106,32 @@ export default function GraphicGeneratorDialog({ initial, onApply, onClose, save
    setResult(undefined)} className="space-y-3">
    - {type === 'rechteck' ? <> + {type === 'text' ? <> +