From 5bb4e063dae703c36b5438c9c780da2a757ef43c Mon Sep 17 00:00:00 2001 From: MarcoWS00 Date: Fri, 4 Dec 2026 10:14:49 +0100 Subject: [PATCH] umstellung auf claud --- .vscode/settings.json | 5 +- development-3002.stdout.log | 348 +++++++++++++++++- package-lock.json | 4 +- package.json | 3 +- production-3001.stdout.log | 2 +- src/_config/backend.ts | 15 + src/_config/procon-navigation.ts | 1 - src/_config/sites.ts | 6 +- src/actions/anzeigen/api-anzeigewerte.ts | 4 +- src/actions/backup/api-backup.ts | 3 +- src/actions/draw/api-draw.ts | 3 +- .../fehlerliste/api-aggregat-meldungen.ts | 3 +- src/actions/fehlerliste/api-fehlerliste.ts | 3 +- src/actions/opcua/api-io-diagnostics.ts | 3 +- src/actions/opcua/api-io-simulation.ts | 3 +- src/actions/opcua/api-opcua.ts | 5 +- src/actions/opcua/api-structures.ts | 3 +- .../parameter/api-element-parameter.ts | 3 +- src/actions/parameter/api-parameter.ts | 3 +- src/actions/procon/api-group-sync.ts | 3 +- src/actions/procon/api-procon-aggregate.ts | 3 +- src/actions/procon/api-procon-anzeigen.ts | 3 +- src/actions/procon/api-procon-meldungen.ts | 3 +- src/actions/procon/api-procon-sensoren.ts | 3 +- src/actions/procon/api-procon-texte.ts | 3 +- src/actions/procon/api-procon-views.ts | 3 +- .../procon/api-procon-visualisierungen.ts | 3 +- src/actions/procon/api-project-import.ts | 3 +- src/actions/procon/api-sync.ts | 7 +- src/actions/procon/api-zuordnung.ts | 3 +- src/actions/rk/api-anlage.ts | 89 +++-- src/actions/rk/api-draw.ts | 57 +-- src/actions/rk/api-element.ts | 129 +++---- src/actions/rk/api-file-uplaod.ts | 32 +- src/actions/rk/api-groups.ts | 137 +++---- src/actions/rk/api-logNote.ts | 132 +++---- src/actions/rk/api-peripherie.ts | 92 +++-- src/actions/rk/api-procon-verbindungen.ts | 3 +- src/actions/rk/api-visuElements.ts | 83 ++--- src/actions/rk2/api-ablaeufe.ts | 24 ++ src/actions/rk2/api-component.ts | 3 +- src/actions/rk2/api-group-overview.ts | 81 ++++ src/actions/rk2/api-groups.ts | 46 ++- src/actions/rk2/api-ios.ts | 3 +- src/actions/rk2/api-procon-view-aggregate.ts | 3 +- src/actions/rk2/api-signals.ts | 23 +- src/actions/rk2/api-unit-material.ts | 53 +++ src/actions/rk2/api-unit-templates.ts | 7 +- src/actions/rk2/api-units.ts | 7 +- src/actions/rk2/api-visu-aggregate.ts | 3 +- src/actions/sensoren/api-analog.ts | 3 +- src/actions/sensoren/api-digital-opc.ts | 3 +- src/actions/sensoren/api-digital.ts | 3 +- src/actions/sensoren/api-motor-opc.ts | 3 +- .../steuerbuttons/api-steuerbuttons.ts | 3 +- src/actions/texte/api-texte.ts | 3 +- src/actions/visualisierung/api-library.ts | 3 +- src/actions/visualisierung/api-settings.ts | 3 +- src/app/(pages)/alt/page.tsx | 2 +- .../alt/rk/anlagen/[id]/verbindungen/page.tsx | 19 +- src/app/(pages)/alt/rk/anlagen/new/page.tsx | 6 +- src/app/(pages)/alt/rk/anlagen/page.tsx | 28 +- src/app/(pages)/procon/aggregate/page.tsx | 2 +- .../(pages)/procon/gesamtabgleich/page.tsx | 2 +- src/app/ablaeufe/page.tsx | 12 + src/app/anlagen/[id]/page.tsx | 65 ++++ src/app/anlagen/einstellungen/layout.tsx | 12 + .../einstellungen/opcua/certificate/route.ts | 34 ++ src/app/anlagen/einstellungen/opcua/page.tsx | 11 + src/app/anlagen/einstellungen/page.tsx | 49 +++ src/app/anlagen/einstellungen/pdf/page.tsx | 11 + src/app/anlagen/einstellungen/procon/page.tsx | 13 + src/app/anlagen/page.tsx | 7 + src/app/anlagen/pdf/page.tsx | 14 +- src/app/anzeigewerte/export/route.ts | 27 +- src/app/anzeigewerte/page.tsx | 2 +- .../api/anlagen/[id]/pdf/[[...path]]/route.ts | 104 ++++-- src/app/datensicherung/[id]/datei/route.ts | 9 +- src/app/datensicherung/page.tsx | 8 +- src/app/fehlerliste/export/route.ts | 27 +- src/app/groups/edit/[id]/page.tsx | 82 ++--- src/app/groups/page.tsx | 48 ++- src/app/hardware/io-import/page.tsx | 23 ++ src/app/hardware/io-uebersicht/page.tsx | 21 ++ src/app/hardware/io-zuordnung/page.tsx | 18 + src/app/hardware/page.tsx | 31 ++ .../hardware/zuordnung-uebersicht/page.tsx | 78 ++++ src/app/ios/page.tsx | 22 +- src/app/live-anlage/events/route.ts | 46 ++- src/app/page.tsx | 53 +-- src/app/parameter/export/route.ts | 27 +- src/app/projekte/error.tsx | 13 + src/app/projekte/neu/page.tsx | 5 + src/app/projekte/page.tsx | 8 + .../system/datensicherung/[id]/datei/route.ts | 43 +++ .../projekte/system/datensicherung/page.tsx | 17 + src/app/projekte/system/page.tsx | 17 + src/app/sensoren-analog/export/route.ts | 27 +- src/app/sensoren-analog/page.tsx | 2 +- src/app/sensoren-analog/xaml/route.ts | 24 +- src/app/sensoren-digital/export/route.ts | 27 +- src/app/sensoren-digital/page.tsx | 2 +- src/app/signals/[componentId]/page.tsx | 2 +- src/app/signals/assignment/page.tsx | 31 +- src/app/signals/assignments/page.tsx | 87 +---- src/app/signals/import/page.tsx | 45 +-- src/app/signals/page.tsx | 7 +- src/app/sps/io-diagnose/events/route.ts | 62 +++- src/app/sps/opcua-strukturen/live/route.ts | 69 +++- src/app/sps/opcua/certificate/route.ts | 11 +- src/app/sps/opcua/page.tsx | 9 +- src/app/steuerbuttons/export/route.ts | 27 +- src/app/texte/export/route.ts | 27 +- src/app/units/edit/[id]/page.tsx | 2 +- src/app/units/page.tsx | 101 +---- src/app/verbindungen/page.tsx | 13 +- src/app/visu-aggregate/export/route.ts | 34 +- src/components/ablaeufe/ablaeufeEditor.tsx | 171 +++++++++ src/components/ablaeufe/ablaufPreview.tsx | 30 ++ src/components/ablaeufe/boxPlan.tsx | 76 ++++ src/components/ablaeufe/materialGraph.tsx | 73 ++++ src/components/anzeigen/displayDataList.tsx | 58 +++ src/components/anzeigen/displayTable.tsx | 84 +++-- src/components/backup/backupPanel.tsx | 2 +- .../signals => hardware}/assignmentsTable.tsx | 0 .../{rk2/ios => hardware}/ioExcelCompare.tsx | 0 .../{rk2/ios => hardware}/ioExcelImport.tsx | 0 .../{rk2/ios => hardware}/ioExcelSave.tsx | 0 .../{rk2/ios => hardware}/ioExcelUpload.tsx | 0 .../{rk2/ios => hardware}/ioOverview.tsx | 0 .../signalIoAssignment.tsx | 0 .../navigation/anlageNavigation.tsx | 25 ++ .../navigation/anlageSectionHeader.tsx | 94 +++++ src/components/navigation/appBreadcrumbs.tsx | 122 +++--- src/components/navigation/appContent.tsx | 2 +- src/components/navigation/appHeader.tsx | 71 +++- src/components/navigation/appLayout.tsx | 83 +++-- src/components/navigation/appSidebar.tsx | 188 +++++----- src/components/opcua/opcPanel.tsx | 2 +- src/components/opcua/structuresPanel.tsx | 2 +- src/components/rk/anlage/anlageCreate.tsx | 145 ++++++-- src/components/rk/anlage/anlagePdfDialog.tsx | 92 +++++ .../rk/anlage/anlagePdfProvider.tsx | 53 +++ src/components/rk/anlage/anlagePdfViewer.tsx | 41 ++- .../rk/anlage/anlageUnitSummary.tsx | 62 ++++ src/components/rk/anlage/projectList.tsx | 101 +++++ .../rk2/ausgabe/ausgabeUnitInfo.tsx | 7 +- src/components/rk2/groups/groupDelete.tsx | 75 ++++ src/components/rk2/groups/groupEdit.tsx | 2 + src/components/rk2/groups/groupOverview.tsx | 228 ++++++++++++ src/components/rk2/units/unitCopyDialog.tsx | 2 +- src/components/rk2/units/unitEdit.tsx | 14 +- src/components/rk2/units/unitGroupFilter.tsx | 117 ++++++ src/components/rk2/units/unitMaterialFlow.tsx | 43 +++ src/components/rk2/units/unitOverview.tsx | 265 +++++++++++++ src/components/rk2/units/unitOverviewRow.tsx | 58 +++ src/components/sensoren/analogTable.tsx | 25 +- src/components/ui/Modal.tsx | 25 +- src/components/ui/navigation/breadcrumbs.tsx | 88 ++--- src/components/ui/rowDetailsDialog.tsx | 200 ++++++++++ src/hooks/useNavigationGuard.ts | 50 +-- src/hooks/useRowDetails.ts | 24 ++ src/lib/anzeigen/validation.test.ts | 33 ++ src/lib/anzeigen/validation.ts | 17 + src/lib/groups/content.test.ts | 91 +++++ src/lib/groups/content.ts | 217 +++++++++++ src/lib/projekte/navigation.test.ts | 143 +++++++ src/lib/units/overview.test.ts | 156 ++++++++ src/lib/units/overview.ts | 205 +++++++++++ src/types/anlagen/ablaeufe.ts | 8 + src/types/anlagen/materialfluss.ts | 21 ++ 171 files changed, 5471 insertions(+), 1333 deletions(-) create mode 100644 src/_config/backend.ts create mode 100644 src/actions/rk2/api-ablaeufe.ts create mode 100644 src/actions/rk2/api-group-overview.ts create mode 100644 src/actions/rk2/api-unit-material.ts create mode 100644 src/app/ablaeufe/page.tsx create mode 100644 src/app/anlagen/[id]/page.tsx create mode 100644 src/app/anlagen/einstellungen/layout.tsx create mode 100644 src/app/anlagen/einstellungen/opcua/certificate/route.ts create mode 100644 src/app/anlagen/einstellungen/opcua/page.tsx create mode 100644 src/app/anlagen/einstellungen/page.tsx create mode 100644 src/app/anlagen/einstellungen/pdf/page.tsx create mode 100644 src/app/anlagen/einstellungen/procon/page.tsx create mode 100644 src/app/anlagen/page.tsx create mode 100644 src/app/hardware/io-import/page.tsx create mode 100644 src/app/hardware/io-uebersicht/page.tsx create mode 100644 src/app/hardware/io-zuordnung/page.tsx create mode 100644 src/app/hardware/page.tsx create mode 100644 src/app/hardware/zuordnung-uebersicht/page.tsx create mode 100644 src/app/projekte/error.tsx create mode 100644 src/app/projekte/neu/page.tsx create mode 100644 src/app/projekte/page.tsx create mode 100644 src/app/projekte/system/datensicherung/[id]/datei/route.ts create mode 100644 src/app/projekte/system/datensicherung/page.tsx create mode 100644 src/app/projekte/system/page.tsx create mode 100644 src/components/ablaeufe/ablaeufeEditor.tsx create mode 100644 src/components/ablaeufe/ablaufPreview.tsx create mode 100644 src/components/ablaeufe/boxPlan.tsx create mode 100644 src/components/ablaeufe/materialGraph.tsx create mode 100644 src/components/anzeigen/displayDataList.tsx rename src/components/{rk2/signals => hardware}/assignmentsTable.tsx (100%) rename src/components/{rk2/ios => hardware}/ioExcelCompare.tsx (100%) rename src/components/{rk2/ios => hardware}/ioExcelImport.tsx (100%) rename src/components/{rk2/ios => hardware}/ioExcelSave.tsx (100%) rename src/components/{rk2/ios => hardware}/ioExcelUpload.tsx (100%) rename src/components/{rk2/ios => hardware}/ioOverview.tsx (100%) rename src/components/{rk2/signals => hardware}/signalIoAssignment.tsx (100%) create mode 100644 src/components/navigation/anlageNavigation.tsx create mode 100644 src/components/navigation/anlageSectionHeader.tsx create mode 100644 src/components/rk/anlage/anlagePdfDialog.tsx create mode 100644 src/components/rk/anlage/anlagePdfProvider.tsx create mode 100644 src/components/rk/anlage/anlageUnitSummary.tsx create mode 100644 src/components/rk/anlage/projectList.tsx create mode 100644 src/components/rk2/groups/groupDelete.tsx create mode 100644 src/components/rk2/groups/groupOverview.tsx create mode 100644 src/components/rk2/units/unitGroupFilter.tsx create mode 100644 src/components/rk2/units/unitMaterialFlow.tsx create mode 100644 src/components/rk2/units/unitOverview.tsx create mode 100644 src/components/rk2/units/unitOverviewRow.tsx create mode 100644 src/components/ui/rowDetailsDialog.tsx create mode 100644 src/hooks/useRowDetails.ts create mode 100644 src/lib/anzeigen/validation.test.ts create mode 100644 src/lib/anzeigen/validation.ts create mode 100644 src/lib/groups/content.test.ts create mode 100644 src/lib/groups/content.ts create mode 100644 src/lib/projekte/navigation.test.ts create mode 100644 src/lib/units/overview.test.ts create mode 100644 src/lib/units/overview.ts create mode 100644 src/types/anlagen/ablaeufe.ts create mode 100644 src/types/anlagen/materialfluss.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 7a73a41..b7ff076 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,2 +1,5 @@ { -} \ No newline at end of file + "editor.tabSize": 4, + "editor.insertSpaces": true, + "editor.detectIndentation": false +} diff --git a/development-3002.stdout.log b/development-3002.stdout.log index c05daf7..8bebb67 100644 --- a/development-3002.stdout.log +++ b/development-3002.stdout.log @@ -5,4 +5,350 @@ · serverActions ✓ Starting... -✓ Ready in 2.2s +✓ Ready in 1890ms + GET /units 200 in 2.4s (compile: 1964ms, render: 433ms) + GET /units 200 in 146ms (compile: 7ms, render: 139ms) + GET /units 200 in 139ms (compile: 75ms, render: 64ms) + GET /units 200 in 217ms (compile: 4ms, render: 213ms) + GET /units 200 in 133ms (compile: 74ms, render: 59ms) + GET /groups 200 in 1030ms (compile: 772ms, render: 258ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 1686ms (compile: 1551ms, render: 135ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 60ms (compile: 11ms, render: 49ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 51ms (compile: 11ms, render: 40ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 57ms (compile: 6ms, render: 50ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 183ms (compile: 109ms, render: 74ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 124ms (compile: 65ms, render: 59ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 106ms (compile: 44ms, render: 62ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 1153ms (compile: 1094ms, render: 59ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 1158ms (compile: 1096ms, render: 62ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 1175ms (compile: 1095ms, render: 80ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 1177ms (compile: 1094ms, render: 84ms) + GET /api/pdf-assets/pdf.worker.min.mjs 200 in 804ms (compile: 789ms, render: 15ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 200 in 58ms (compile: 13ms, render: 45ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 32ms (compile: 5ms, render: 27ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 42ms (compile: 4ms, render: 38ms) + GET /api/pdf-assets/wasm/qcms_bg.wasm 200 in 25ms (compile: 8ms, render: 17ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 120ms (compile: 56ms, render: 64ms) + GET /units 200 in 313ms (compile: 13ms, render: 299ms) + GET /projekte 200 in 2.3s (compile: 1910ms, render: 348ms) + GET /anzeigewerte/bearbeiten 200 in 2.3s (compile: 1911ms, render: 351ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 54ms (compile: 16ms, render: 38ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 55ms (compile: 14ms, render: 41ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 70ms (compile: 14ms, render: 56ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 71ms (compile: 13ms, render: 58ms) + GET /api/pdf-assets/pdf.worker.min.mjs 200 in 30ms (compile: 9ms, render: 21ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 200 in 45ms (compile: 2ms, render: 42ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 17ms (compile: 3ms, render: 13ms) + GET /api/pdf-assets/wasm/qcms_bg.wasm 200 in 14ms (compile: 2ms, render: 12ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 190ms (compile: 114ms, render: 76ms) + GET /units 200 in 71ms (compile: 13ms, render: 58ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 635ms (compile: 495ms, render: 140ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 645ms (compile: 496ms, render: 149ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 646ms (compile: 495ms, render: 151ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 650ms (compile: 494ms, render: 156ms) + GET /units 200 in 113ms (compile: 39ms, render: 74ms) + GET /api/pdf-assets/pdf.worker.min.mjs 200 in 266ms (compile: 248ms, render: 18ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 200 in 54ms (compile: 5ms, render: 49ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 39ms (compile: 9ms, render: 30ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 50ms (compile: 10ms, render: 40ms) + GET /api/pdf-assets/wasm/qcms_bg.wasm 200 in 15ms (compile: 3ms, render: 12ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 55ms (compile: 13ms, render: 42ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 53ms (compile: 8ms, render: 45ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 57ms (compile: 10ms, render: 47ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 34ms (compile: 6ms, render: 27ms) + GET /api/pdf-assets/pdf.worker.min.mjs 200 in 27ms (compile: 7ms, render: 20ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 200 in 50ms (compile: 1963µs, render: 48ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 23ms (compile: 3ms, render: 20ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 25ms (compile: 3ms, render: 23ms) + GET /api/pdf-assets/wasm/qcms_bg.wasm 200 in 21ms (compile: 3ms, render: 17ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 120ms (compile: 43ms, render: 77ms) + GET /sensoren-digital 200 in 925ms (compile: 844ms, render: 81ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 104ms (compile: 27ms, render: 77ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 50ms (compile: 9ms, render: 41ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 77ms (compile: 23ms, render: 54ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 132ms (compile: 71ms, render: 61ms) + GET /anlagen/einstellungen 200 in 389ms (compile: 341ms, render: 47ms) + GET /anlagen/einstellungen 200 in 288ms (compile: 54ms, render: 233ms) + GET /units 200 in 291ms (compile: 10ms, render: 280ms) + GET /verbindungen 200 in 737ms (compile: 668ms, render: 69ms) + GET /anlagen/einstellungen 200 in 42ms (compile: 8ms, render: 34ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 495ms (compile: 442ms, render: 52ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 501ms (compile: 444ms, render: 57ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 510ms (compile: 442ms, render: 68ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 512ms (compile: 442ms, render: 71ms) + GET /api/pdf-assets/pdf.worker.min.mjs 200 in 355ms (compile: 331ms, render: 23ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 200 in 51ms (compile: 6ms, render: 45ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 42ms (compile: 10ms, render: 33ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 44ms (compile: 9ms, render: 35ms) + GET /api/pdf-assets/wasm/qcms_bg.wasm 200 in 16ms (compile: 2ms, render: 14ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 57ms (compile: 13ms, render: 44ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 56ms (compile: 9ms, render: 47ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 68ms (compile: 10ms, render: 58ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 72ms (compile: 9ms, render: 63ms) + GET /api/pdf-assets/pdf.worker.min.mjs 200 in 22ms (compile: 6ms, render: 16ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 200 in 41ms (compile: 1978µs, render: 39ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 38ms (compile: 4ms, render: 34ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 42ms (compile: 4ms, render: 38ms) + GET /api/pdf-assets/wasm/qcms_bg.wasm 200 in 20ms (compile: 3ms, render: 17ms) + GET /anlagen/einstellungen 200 in 108ms (compile: 45ms, render: 63ms) + GET /anlagen/einstellungen 200 in 67ms (compile: 7ms, render: 60ms) + GET /anlagen/einstellungen 200 in 160ms (compile: 70ms, render: 90ms) + GET /anlagen/einstellungen 200 in 217ms (compile: 112ms, render: 105ms) + GET /anlagen/einstellungen 200 in 38ms (compile: 4ms, render: 34ms) + GET /anlagen/einstellungen 200 in 140ms (compile: 65ms, render: 75ms) + GET /anlagen/einstellungen 200 in 118ms (compile: 47ms, render: 70ms) + GET /anlagen/einstellungen 200 in 35ms (compile: 3ms, render: 32ms) + GET /anlagen/einstellungen 200 in 140ms (compile: 60ms, render: 80ms) + GET /anlagen/einstellungen 200 in 84ms (compile: 35ms, render: 48ms) + GET /anlagen/einstellungen 200 in 933ms (compile: 837ms, render: 97ms) + GET /anlagen/einstellungen 200 in 42ms (compile: 6ms, render: 36ms) + GET /anlagen/einstellungen/pdf 200 in 965ms (compile: 893ms, render: 72ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 755ms (compile: 607ms, render: 148ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 759ms (compile: 607ms, render: 152ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf 200 in 761ms (compile: 608ms, render: 153ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/units 200 in 761ms (compile: 606ms, render: 155ms) + GET /anlagen/einstellungen/pdf 200 in 107ms (compile: 37ms, render: 70ms) + GET /api/pdf-assets/pdf.worker.min.mjs 200 in 349ms (compile: 324ms, render: 25ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 200 in 58ms (compile: 12ms, render: 46ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 35ms (compile: 3ms, render: 31ms) + GET /api/anlagen/6995c490bb286cf2c27da0da/pdf/file?version=50bc04da-a60b-4fe7-a734-d43229144d6e 206 in 37ms (compile: 3ms, render: 34ms) + GET /api/pdf-assets/wasm/qcms_bg.wasm 200 in 17ms (compile: 2ms, render: 14ms) + GET /anlagen/einstellungen 200 in 84ms (compile: 33ms, render: 52ms) + GET /anlagen/einstellungen/procon 200 in 834ms (compile: 760ms, render: 73ms) + GET /anlagen/einstellungen 200 in 73ms (compile: 10ms, render: 63ms) + GET /anlagen/einstellungen 200 in 382ms (compile: 59ms, render: 323ms) + GET /anlagen/einstellungen/pdf 200 in 516ms (compile: 68ms, render: 448ms) + GET /anlagen/einstellungen 200 in 519ms (compile: 38ms, render: 481ms) + GET /anlagen/einstellungen/procon 200 in 529ms (compile: 126ms, render: 403ms) + GET /anlagen/einstellungen 200 in 167ms (compile: 119ms, render: 48ms) + GET /anlagen/einstellungen/opcua 200 in 1682ms (compile: 1409ms, render: 273ms) + GET /verbindungen 307 in 112ms (compile: 9ms, render: 103ms) + GET /sps/opcua 307 in 574ms (compile: 434ms, render: 140ms) + GET /anlagen/pdf?unit=test 307 in 570ms (compile: 457ms, render: 113ms) + GET /anlagen/einstellungen/opcua 200 in 46ms (compile: 9ms, render: 37ms) + GET /anlagen/einstellungen 200 in 36ms (compile: 6ms, render: 31ms) + GET /signals/import 200 in 1539ms (compile: 1462ms, render: 78ms) + GET /anlagen/einstellungen 200 in 58ms (compile: 11ms, render: 47ms) + GET /sps 200 in 801ms (compile: 753ms, render: 49ms) + GET /sps 200 in 35ms (compile: 3ms, render: 32ms) + GET /anlagen/einstellungen 200 in 179ms (compile: 44ms, render: 135ms) + GET /anlagen/einstellungen 200 in 171ms (compile: 94ms, render: 77ms) + GET /anlagen/einstellungen 200 in 181ms (compile: 114ms, render: 67ms) + GET /anlagen/einstellungen 200 in 141ms (compile: 72ms, render: 69ms) + GET /anlagen/einstellungen 200 in 42ms (compile: 6ms, render: 35ms) + GET /anlagen/einstellungen 200 in 162ms (compile: 93ms, render: 69ms) + GET /anlagen/einstellungen 200 in 132ms (compile: 41ms, render: 90ms) + GET /anlagen/einstellungen 200 in 155ms (compile: 90ms, render: 65ms) + GET /anlagen/einstellungen 200 in 122ms (compile: 35ms, render: 86ms) + GET /projekte 200 in 822ms (compile: 613ms, render: 210ms) + GET /projekte/system 200 in 1493ms (compile: 1220ms, render: 273ms) + GET /projekte/system/datensicherung 200 in 1495ms (compile: 1222ms, render: 274ms) +http://localhost:3000/anlage/selected/6995c490bb286cf2c27da0da +200 OK + POST /projekte 200 in 98ms (compile: 9ms, render: 89ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 785ms (compile: 683ms, render: 102ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 70ms (compile: 5ms, render: 66ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 146ms (compile: 13ms, render: 133ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 193ms (compile: 85ms, render: 108ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 145ms (compile: 40ms, render: 105ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 266ms (compile: 3ms, render: 263ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 1137ms (compile: 957ms, render: 180ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 89ms (compile: 5ms, render: 84ms) + GET /units/edit/6ae49e65706ab3f558d37066 200 in 2.1s (compile: 1873ms, render: 266ms) + POST /units/edit/6ae49e65706ab3f558d37066 200 in 86ms (compile: 10ms, render: 76ms) + POST /units/edit/6ae49e65706ab3f558d37066 200 in 37ms (compile: 4ms, render: 34ms) + GET /units/edit/6ae49e65706ab3f558d37066 200 in 75ms (compile: 12ms, render: 63ms) + POST /units/edit/6ae49e65706ab3f558d37066 200 in 39ms (compile: 6ms, render: 33ms) + POST /units/edit/6ae49e65706ab3f558d37066 200 in 35ms (compile: 3ms, render: 32ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 195ms (compile: 83ms, render: 113ms) + GET /units/edit/6ae9da372a95c343cbd959bb 200 in 83ms (compile: 23ms, render: 60ms) + POST /units/edit/6ae9da372a95c343cbd959bb 200 in 65ms (compile: 4ms, render: 61ms) + POST /units/edit/6ae9da372a95c343cbd959bb 200 in 52ms (compile: 4ms, render: 47ms) +Update unit +{ + name: 'ET', + type: 'Allgemein', + groupId: '6a8bf9e853f346de0c74c3d2', + bmk: '', + prefix: 'BA1', + postfix: '', + info: '', + components: [ + { + id: '6ae9da392a95c343cbd959bf', + name: 'SC', + index: 0, + prefix: '', + postfix: '', + type: 'Allgemein' + } + ], + anlageId: '6995c490bb286cf2c27da0da' +} + POST /units/edit/6ae9da372a95c343cbd959bb 200 in 98ms (compile: 11ms, render: 87ms) + GET /units 200 in 896ms (compile: 799ms, render: 97ms) + GET /units 200 in 55ms (compile: 4ms, render: 51ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 111ms (compile: 13ms, render: 98ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 137ms (compile: 42ms, render: 95ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 122ms (compile: 42ms, render: 80ms) + GET /units 200 in 499ms (compile: 408ms, render: 92ms) + GET /groups 200 in 145ms (compile: 13ms, render: 132ms) + GET /groups 200 in 1217ms (compile: 878ms, render: 338ms) + GET /groups 200 in 114ms (compile: 9ms, render: 105ms) + GET /groups 200 in 76ms (compile: 4ms, render: 71ms) + GET /groups/edit/6a990c63841b680fc48955b9 200 in 1737ms (compile: 1667ms, render: 70ms) + GET /groups/edit/6a990c63841b680fc48955b9 200 in 85ms (compile: 39ms, render: 45ms) + POST /groups/edit/6a990c63841b680fc48955b9 200 in 91ms (compile: 8ms, render: 83ms) + GET /groups 200 in 376ms (compile: 12ms, render: 364ms) + GET /groups 200 in 288ms (compile: 12ms, render: 276ms) + GET /anlagen/6995c490bb286cf2c27da0da 200 in 122ms (compile: 15ms, render: 107ms) + GET /signals 200 in 1135ms (compile: 1002ms, render: 133ms) + GET /ios 200 in 865ms (compile: 693ms, render: 172ms) + GET /signals/import 200 in 731ms (compile: 669ms, render: 62ms) + GET /ios 200 in 94ms (compile: 9ms, render: 85ms) + GET /signals 200 in 64ms (compile: 11ms, render: 54ms) + GET /signals/assignments 200 in 1037ms (compile: 866ms, render: 171ms) + GET /signals 200 in 83ms (compile: 12ms, render: 71ms) + GET /signals/assignments 200 in 104ms (compile: 3ms, render: 101ms) + GET /signals 200 in 341ms (compile: 158ms, render: 183ms) + GET /signals/assignments 200 in 97ms (compile: 5ms, render: 92ms) + GET /signals 200 in 55ms (compile: 4ms, render: 51ms) + GET /signals 200 in 208ms (compile: 138ms, render: 70ms) + GET /signals/assignment 200 in 931ms (compile: 759ms, render: 172ms) + GET /signals 200 in 70ms (compile: 8ms, render: 62ms) + GET /signals/import 200 in 739ms (compile: 551ms, render: 189ms) + POST /signals/import 200 in 157ms (compile: 5ms, render: 153ms) + POST /signals/import 200 in 52ms (compile: 8ms, render: 45ms) + POST /signals/import 200 in 48ms (compile: 4ms, render: 44ms) + POST /signals/import 200 in 82ms (compile: 5ms, render: 77ms) + GET /ios 200 in 117ms (compile: 11ms, render: 105ms) + GET /signals 200 in 66ms (compile: 6ms, render: 60ms) + GET /signals/import 200 in 95ms (compile: 4ms, render: 91ms) + GET /signals/import 200 in 57ms (compile: 4ms, render: 52ms) + GET /ios 200 in 82ms (compile: 4ms, render: 78ms) + GET /signals/import 200 in 53ms (compile: 4ms, render: 49ms) + GET /ios 200 in 94ms (compile: 4ms, render: 90ms) + GET /signals 200 in 53ms (compile: 5ms, render: 48ms) + GET /signals/assignments 200 in 123ms (compile: 10ms, render: 113ms) + GET /signals/assignment 200 in 138ms (compile: 13ms, render: 125ms) + GET /signals 200 in 63ms (compile: 5ms, render: 59ms) + GET /signals/assignment 200 in 90ms (compile: 4ms, render: 86ms) + GET /signals 200 in 57ms (compile: 5ms, render: 52ms) + GET /signals 200 in 50ms (compile: 5ms, render: 44ms) + GET /signals 200 in 198ms (compile: 106ms, render: 93ms) + GET /signals 200 in 1127ms (compile: 1000ms, render: 126ms) + GET /signals 200 in 100ms (compile: 4ms, render: 96ms) + GET /signals 200 in 107ms (compile: 34ms, render: 72ms) + GET /signals 200 in 743ms (compile: 597ms, render: 145ms) + GET /signals 200 in 103ms (compile: 14ms, render: 89ms) + GET /signals 200 in 51ms (compile: 5ms, render: 45ms) + GET /signals 200 in 149ms (compile: 67ms, render: 83ms) + GET /signals 200 in 920ms (compile: 789ms, render: 131ms) + GET /signals 200 in 158ms (compile: 16ms, render: 142ms) + GET /signals 200 in 40ms (compile: 4ms, render: 36ms) + GET /signals 200 in 37ms (compile: 4ms, render: 34ms) + GET /signals 200 in 47ms (compile: 5ms, render: 42ms) + GET /signals 200 in 45ms (compile: 5ms, render: 40ms) + GET /signals 200 in 47ms (compile: 4ms, render: 43ms) + GET /signals 200 in 43ms (compile: 4ms, render: 39ms) + GET /signals 200 in 41ms (compile: 4ms, render: 37ms) + GET /signals 200 in 44ms (compile: 4ms, render: 40ms) + GET /signals 200 in 48ms (compile: 7ms, render: 41ms) + GET /signals 200 in 45ms (compile: 4ms, render: 40ms) + GET /signals 200 in 46ms (compile: 8ms, render: 38ms) + GET /signals 200 in 41ms (compile: 4ms, render: 37ms) + GET /signals 200 in 793ms (compile: 576ms, render: 217ms) + GET /signals 200 in 795ms (compile: 576ms, render: 219ms) + GET /signals 200 in 795ms (compile: 575ms, render: 219ms) + GET /signals 200 in 1629ms (compile: 1409ms, render: 220ms) + GET /signals 200 in 94ms (compile: 17ms, render: 77ms) + GET /signals 200 in 103ms (compile: 49ms, render: 54ms) + GET /signals 200 in 38ms (compile: 4ms, render: 35ms) + GET /hardware 200 in 3.3s (compile: 1988ms, render: 1308ms) + GET /hardware/io-import 200 in 3.3s (compile: 1990ms, render: 1310ms) + GET /hardware/io-zuordnung 200 in 3.3s (compile: 1988ms, render: 1323ms) + GET /hardware/zuordnung-uebersicht 200 in 3.3s (compile: 1989ms, render: 1324ms) + GET /signals 200 in 144ms (compile: 85ms, render: 59ms) + GET /signals/import 307 in 1569ms (compile: 1340ms, render: 230ms) + GET /signals 200 in 119ms (compile: 68ms, render: 51ms) + GET /signals/assignments 307 in 888ms (compile: 691ms, render: 196ms) + GET /signals 200 in 98ms (compile: 62ms, render: 36ms) + GET /signals/assignment?unitId=test 307 in 831ms (compile: 659ms, render: 172ms) + GET /signals 200 in 132ms (compile: 5ms, render: 127ms) + GET /hardware/io-zuordnung 200 in 132ms (compile: 13ms, render: 119ms) + GET /hardware/zuordnung-uebersicht 200 in 108ms (compile: 11ms, render: 96ms) + GET /hardware/io-import 200 in 49ms (compile: 11ms, render: 38ms) + GET /hardware 200 in 42ms (compile: 12ms, render: 31ms) + GET /hardware/io-import 200 in 39ms (compile: 4ms, render: 35ms) + GET /hardware/zuordnung-uebersicht 200 in 103ms (compile: 9ms, render: 94ms) + GET /hardware/io-zuordnung 200 in 90ms (compile: 4ms, render: 87ms) + GET /hardware 200 in 28ms (compile: 4ms, render: 24ms) + GET /ios 200 in 109ms (compile: 10ms, render: 99ms) + GET /signals 200 in 59ms (compile: 4ms, render: 55ms) + GET /ios 200 in 91ms (compile: 3ms, render: 88ms) + GET /signals 200 in 57ms (compile: 7ms, render: 50ms) + GET /hardware/io-zuordnung 200 in 99ms (compile: 3ms, render: 96ms) + GET /signals 200 in 47ms (compile: 4ms, render: 43ms) + GET /ios 200 in 85ms (compile: 3ms, render: 82ms) + GET /hardware/zuordnung-uebersicht 200 in 108ms (compile: 7ms, render: 101ms) + GET /hardware/io-zuordnung 200 in 101ms (compile: 4ms, render: 97ms) + GET /hardware/io-zuordnung 200 in 426ms (compile: 195ms, render: 232ms) + GET /hardware/io-zuordnung 200 in 1003ms (compile: 806ms, render: 197ms) + GET /hardware/io-zuordnung 200 in 1006ms (compile: 807ms, render: 199ms) + GET /hardware/io-zuordnung 200 in 105ms (compile: 8ms, render: 97ms) + GET /hardware/io-zuordnung 200 in 233ms (compile: 32ms, render: 202ms) + GET /hardware/io-zuordnung 200 in 150ms (compile: 19ms, render: 131ms) + GET /hardware/io-zuordnung 200 in 209ms (compile: 61ms, render: 148ms) + GET /hardware 200 in 916ms (compile: 89ms, render: 827ms) + GET /hardware/io-zuordnung 200 in 927ms (compile: 9ms, render: 918ms) + GET /hardware/zuordnung-uebersicht 200 in 928ms (compile: 49ms, render: 879ms) + GET /hardware/io-uebersicht 200 in 1994ms (compile: 1585ms, render: 409ms) + GET /hardware/zuordnung-uebersicht 200 in 149ms (compile: 12ms, render: 137ms) + GET /hardware/io-zuordnung 200 in 107ms (compile: 12ms, render: 95ms) + GET /hardware 200 in 36ms (compile: 8ms, render: 28ms) + GET /sps/io-diagnose 200 in 1046ms (compile: 969ms, render: 78ms) + POST /sps/io-diagnose 200 in 544ms (compile: 4ms, render: 541ms) + GET /sps/io-diagnose 200 in 276ms (compile: 81ms, render: 195ms) + GET /sps/io-diagnose 200 in 36ms (compile: 4ms, render: 31ms) + GET /sps/simulation 200 in 1254ms (compile: 1154ms, render: 101ms) + GET /sps/simulation 200 in 40ms (compile: 5ms, render: 35ms) + GET /sps/io-diagnose/events?anlageId=6995c490bb286cf2c27da0da&connectionId=a8539908-5b41-4f25-9aec-a2303f589776&unitId=6a8c116adbe08c3d75e3aefd&token=918c0cda145272adb570f94b75560c800bd9466062647b77be488419d9331536 200 in 23.5s (compile: 888ms, render: 22.6s) + GET /sps/opcua-strukturen 200 in 1346ms (compile: 1223ms, render: 123ms) + GET /sps/opcua-strukturen 200 in 62ms (compile: 7ms, render: 56ms) + GET /motor-opc 200 in 1371ms (compile: 1226ms, render: 144ms) + GET /motor-opc 200 in 100ms (compile: 6ms, render: 94ms) + GET /sensoren-digital/live 200 in 1523ms (compile: 1454ms, render: 69ms) + GET /sensoren-digital/live 200 in 46ms (compile: 4ms, render: 42ms) + GET /sps/sensoren-digital 200 in 2.3s (compile: 1620ms, render: 686ms) + GET /sps/sensoren-digital 200 in 77ms (compile: 16ms, render: 61ms) + GET /procon/aggregate 200 in 1600ms (compile: 1426ms, render: 174ms) + GET /procon/aggregate 200 in 100ms (compile: 6ms, render: 94ms) + GET /procon 200 in 1272ms (compile: 1207ms, render: 65ms) + GET /procon 200 in 51ms (compile: 5ms, render: 47ms) + GET /parameter 200 in 1857ms (compile: 1755ms, render: 102ms) + GET /parameter 200 in 46ms (compile: 6ms, render: 40ms) + POST /parameter 200 in 58ms (compile: 6ms, render: 52ms) + POST /parameter 200 in 43ms (compile: 4ms, render: 38ms) + GET /parameter 200 in 186ms (compile: 10ms, render: 177ms) + GET /parameter 200 in 43ms (compile: 4ms, render: 39ms) + GET /parameter 200 in 179ms (compile: 121ms, render: 58ms) + GET /parameter 200 in 135ms (compile: 11ms, render: 125ms) + GET /parameter 200 in 39ms (compile: 3ms, render: 35ms) + GET /parameter 200 in 113ms (compile: 44ms, render: 69ms) + GET /parameter 200 in 41ms (compile: 3ms, render: 38ms) + GET /parameter 200 in 116ms (compile: 47ms, render: 70ms) + GET /parameter 200 in 124ms (compile: 14ms, render: 110ms) + GET /parameter 200 in 126ms (compile: 4ms, render: 122ms) + GET /parameter 200 in 67ms (compile: 4ms, render: 63ms) + GET /parameter 200 in 141ms (compile: 7ms, render: 134ms) + GET /parameter 200 in 43ms (compile: 4ms, render: 39ms) + GET /parameter 200 in 109ms (compile: 41ms, render: 69ms) + GET /parameter 200 in 44ms (compile: 4ms, render: 41ms) + GET /parameter 200 in 37ms (compile: 4ms, render: 34ms) + GET /parameter 200 in 172ms (compile: 9ms, render: 163ms) + GET /parameter 200 in 184ms (compile: 37ms, render: 147ms) + GET /parameter 200 in 85ms (compile: 4ms, render: 82ms) + GET /parameter 200 in 49ms (compile: 6ms, render: 43ms) + GET /parameter 200 in 142ms (compile: 16ms, render: 126ms) + GET /parameter 200 in 38ms (compile: 5ms, render: 34ms) + GET /parameter 200 in 55ms (compile: 6ms, render: 49ms) diff --git a/package-lock.json b/package-lock.json index 344187f..52d8b1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rk-frontend", - "version": "0.1.0", + "version": "0.3.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rk-frontend", - "version": "0.1.0", + "version": "0.3.6", "dependencies": { "@dnd-kit/core": "^6.3.1", "@dnd-kit/sortable": "^10.0.0", diff --git a/package.json b/package.json index 424d6a7..91551cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "rk-frontend", - "version": "0.1.0", + "version": "0.3.6", + "buildVersion": "2026.12.03.7", "private": true, "scripts": { "dev": "next dev --webpack", diff --git a/production-3001.stdout.log b/production-3001.stdout.log index 34be023..a937379 100644 --- a/production-3001.stdout.log +++ b/production-3001.stdout.log @@ -3,4 +3,4 @@ - Network: http://10.8.1.11:3001 ✓ Starting... -✓ Ready in 746ms +✓ Ready in 699ms diff --git a/src/_config/backend.ts b/src/_config/backend.ts new file mode 100644 index 0000000..6492c15 --- /dev/null +++ b/src/_config/backend.ts @@ -0,0 +1,15 @@ +// Basis-URL des NestJS-Backends. +// Sie wird über die Umgebungsvariable BACKEND_URL gesetzt (z. B. in .env.local), +// damit ein Umzug des Backends keine Änderungen im Code erfordert. +// Ohne Variable gilt der bisherige lokale Standard. +const DEFAULT_BACKEND_URL = 'http://localhost:3000'; + +const TRAILING_SLASHES = /\/+$/; + +const configuredBackendUrl = process.env.BACKEND_URL ?? DEFAULT_BACKEND_URL; + +// Abschließende Schrägstriche entfernen, da alle Pfade mit "/" beginnen. +export const BACKEND_URL = configuredBackendUrl.replace( + TRAILING_SLASHES, + '', +); diff --git a/src/_config/procon-navigation.ts b/src/_config/procon-navigation.ts index a0da99a..accbe9c 100644 --- a/src/_config/procon-navigation.ts +++ b/src/_config/procon-navigation.ts @@ -11,5 +11,4 @@ export const proconNavigation: { label: string; href?: string }[] = [ { label: 'Texte', href: '/texte' }, { label: 'Fehlerliste', href: '/fehlerliste' }, { label: 'Aggregatmeldungen', href: '/aggregat-meldungen' }, - { label: 'Verbindungen', href: '/verbindungen' }, ]; diff --git a/src/_config/sites.ts b/src/_config/sites.ts index 8012400..f380061 100644 --- a/src/_config/sites.ts +++ b/src/_config/sites.ts @@ -3,7 +3,7 @@ import { difference } from "next/dist/build/utils" const rkPrefix = '/alt/rk' export const Sites = { - main: { url: '/', name: 'Home' }, + main: { url: '/anlagen', name: 'Übersicht' }, alt: { url: '/alt', name: 'Alt' }, anlagen: { url: `${rkPrefix}/anlagen`, @@ -68,11 +68,11 @@ export const Sites = { signals: { url: `/signals`, name:"EA's" , import:{ - url:`/signals/import`, name:"Import" , + url:`/hardware/io-import`, name:"Import" , } }, - ios: { url: `/ios`, name:"IO " }, + ios: { url: `/hardware/io-uebersicht`, name:"IO " }, } diff --git a/src/actions/anzeigen/api-anzeigewerte.ts b/src/actions/anzeigen/api-anzeigewerte.ts index c657de6..7e5c88a 100644 --- a/src/actions/anzeigen/api-anzeigewerte.ts +++ b/src/actions/anzeigen/api-anzeigewerte.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { DisplayTable, DisplayComparison, DisplaySlot } from '@/types/anzeigen/anzeigewerte'; -const url = 'http://localhost:3000/rk2/anzeigewerte'; +const url = BACKEND_URL + '/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. @@ -25,6 +26,7 @@ export async function api_saveDisplays(table: DisplayTable) { revalidatePath('/visualisierung'); return saved; } +export async function api_saveDisplaysResult(table: DisplayTable) { return displayResult(() => api_saveDisplays(table)); } export async function api_compareDisplay(id: string) { return displayResult(() => request('/' + encodeURIComponent(id) + '/sync')); } diff --git a/src/actions/backup/api-backup.ts b/src/actions/backup/api-backup.ts index 5861b4a..2f07859 100644 --- a/src/actions/backup/api-backup.ts +++ b/src/actions/backup/api-backup.ts @@ -1,6 +1,7 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import type {BackupData,BackupManifest} from '@/types/backup'; -const url='http://localhost:3000/rk2/backups'; +const url = BACKEND_URL + '/rk2/backups'; async function request(init?:RequestInit):Promise{const response=await fetch(url,{cache:'no-store',...init});const data=await response.json();if(!response.ok)throw new Error(data.message??'Datensicherung fehlgeschlagen');return data;} export async function api_backups(){return request();} export async function api_createBackup(native:boolean){return request({method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({native})});} diff --git a/src/actions/draw/api-draw.ts b/src/actions/draw/api-draw.ts index 9bcb32e..a9e0a90 100644 --- a/src/actions/draw/api-draw.ts +++ b/src/actions/draw/api-draw.ts @@ -1,10 +1,11 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import type { DrawRenderData, DrawRenderRequests } from '@/types/draw/draw.types'; -const url = "http://localhost:3000/draw"; +const url = BACKEND_URL + "/draw"; export async function api_drawRender(grafikTyp: T, parameter: DrawRenderRequests[T],): Promise { diff --git a/src/actions/fehlerliste/api-aggregat-meldungen.ts b/src/actions/fehlerliste/api-aggregat-meldungen.ts index aca08de..ee7e55e 100644 --- a/src/actions/fehlerliste/api-aggregat-meldungen.ts +++ b/src/actions/fehlerliste/api-aggregat-meldungen.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import {revalidatePath} from 'next/cache'; import type {AggregatMeldungen,AggregatMeldungComparison} from '@/types/aggregat-meldungen'; -const url='http://localhost:3000/rk2/aggregat-meldungen'; +const url = BACKEND_URL + '/rk2/aggregat-meldungen'; async function request(path='',method='GET',body?:unknown):Promise{const r=await fetch(url+path,{method,cache:'no-store',...(body?{headers:{'Content-Type':'application/json'},body:JSON.stringify(body)}:{})});const data=await r.json();if(!r.ok)throw new Error(Array.isArray(data.message)?data.message.join(', '):data.message??'Anfrage fehlgeschlagen');return data;} export async function api_aggregatMeldungen(){return request();} export async function api_saveAggregatMeldungen(table:AggregatMeldungen){const result=await request('','PUT',table);revalidatePath('/aggregat-meldungen');return result;} diff --git a/src/actions/fehlerliste/api-fehlerliste.ts b/src/actions/fehlerliste/api-fehlerliste.ts index 9f60966..669918b 100644 --- a/src/actions/fehlerliste/api-fehlerliste.ts +++ b/src/actions/fehlerliste/api-fehlerliste.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { FehlerTable } from '@/types/fehlerliste'; -const url = 'http://localhost:3000/rk2/fehlerliste'; +const url = BACKEND_URL + '/rk2/fehlerliste'; async function request(init?: RequestInit): Promise { const response = await fetch(url, { cache: 'no-store', ...init }); const data = await response.json(); diff --git a/src/actions/opcua/api-io-diagnostics.ts b/src/actions/opcua/api-io-diagnostics.ts index 7d3d55f..6ff6aa8 100644 --- a/src/actions/opcua/api-io-diagnostics.ts +++ b/src/actions/opcua/api-io-diagnostics.ts @@ -1,6 +1,7 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import type {IoDiagnosticConfig,DiagnosticReport} from '@/types/io-diagnostics'; -const url='http://localhost:3000/rk2/io-diagnostics'; +const url = BACKEND_URL + '/rk2/io-diagnostics'; async function request(path='',init?:RequestInit):Promise{const r=await fetch(url+path,{cache:'no-store',...init});const data=await r.json();if(!r.ok)throw new Error(data.message??'E/A-Prüfung fehlgeschlagen');return data;} export async function api_ioDiagnosticConfig(){return request();} export async function api_checkIos(anlageId:string,connectionId:string){return request('/check',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({anlageId,connectionId})});} diff --git a/src/actions/opcua/api-io-simulation.ts b/src/actions/opcua/api-io-simulation.ts index 3784b26..df3f772 100644 --- a/src/actions/opcua/api-io-simulation.ts +++ b/src/actions/opcua/api-io-simulation.ts @@ -1,6 +1,7 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import type {SimulationData,SimulationPlan,SimulationProposal,SimulationRuntime,SimulationSelection} from '@/types/io-simulation'; -const url='http://localhost:3000/rk2/io-simulation'; +const url = BACKEND_URL + '/rk2/io-simulation'; async function request(path='',method='GET',body?:unknown):Promise{const r=await fetch(url+path,{method,cache:'no-store',...(body?{headers:{'Content-Type':'application/json'},body:JSON.stringify(body)}:{})});const data=await r.json();if(!r.ok)throw new Error(Array.isArray(data.message)?data.message.join(', '):data.message??'Simulationsanfrage fehlgeschlagen');return data;} export async function api_simulation(id?:string){return request(id?'?connectionId='+encodeURIComponent(id):'');} export async function api_saveSimulation(plan:SimulationPlan){return request('','PUT',plan);} diff --git a/src/actions/opcua/api-opcua.ts b/src/actions/opcua/api-opcua.ts index 7cda3e3..da08978 100644 --- a/src/actions/opcua/api-opcua.ts +++ b/src/actions/opcua/api-opcua.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { OpcConfiguration, OpcEndpoint, OpcNode, OpcValue } from '@/types/opcua'; -const url = 'http://localhost:3000/rk2/opcua'; +const url = BACKEND_URL + '/rk2/opcua'; async function request(path = '', init?: RequestInit): Promise { const response = await fetch(url + path, { cache: 'no-store', ...init }); const data = await response.json(); @@ -11,7 +12,7 @@ async function request(path = '', init?: RequestInit): Promise { export async function api_opcConfiguration() { return request(); } export async function api_saveOpcConfiguration(data: OpcConfiguration) { const saved = await request('', { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); - revalidatePath('/sps/opcua'); return saved; + revalidatePath('/anlagen/einstellungen/opcua'); return saved; } async function operation(id: string, action: string, data: object) { return request('/' + encodeURIComponent(id) + '/' + action, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }); diff --git a/src/actions/opcua/api-structures.ts b/src/actions/opcua/api-structures.ts index 8c783e6..43ed7e5 100644 --- a/src/actions/opcua/api-structures.ts +++ b/src/actions/opcua/api-structures.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { OpcStructure, StructuresData, StructureWriteResult } from '@/types/opcua-structures'; -const url = 'http://localhost:3000/rk2/opcua-structures'; +const url = BACKEND_URL + '/rk2/opcua-structures'; async function request(path = '', method = 'GET', body?: unknown): Promise { const response = await fetch(url + path, { method, cache: 'no-store', ...(body ? { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : {}) }); const result = await response.json(); diff --git a/src/actions/parameter/api-element-parameter.ts b/src/actions/parameter/api-element-parameter.ts index c553f01..575a909 100644 --- a/src/actions/parameter/api-element-parameter.ts +++ b/src/actions/parameter/api-element-parameter.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import {revalidatePath} from 'next/cache'; import type {ElementParameterTable,ElementParameterComparison,ParameterKind} from '@/types/element-parameter'; -const url='http://localhost:3000/rk2/element-parameter/'; +const url = BACKEND_URL + '/rk2/element-parameter/'; async function request(kind:ParameterKind,path='',method='GET',body?:unknown):Promise{const r=await fetch(url+kind+path,{method,cache:'no-store',...(body?{headers:{'Content-Type':'application/json'},body:JSON.stringify(body)}:{})});const data=await r.json();if(!r.ok)throw new Error(Array.isArray(data.message)?data.message.join(', '):data.message??'Parameteranfrage fehlgeschlagen');return data;} function revalidate(kind:ParameterKind){revalidatePath(kind==='beschriftungen'?'/parameter-beschriftungen':'/parameter/'+kind);} export async function api_elementParameters(kind:ParameterKind){return request(kind);} diff --git a/src/actions/parameter/api-parameter.ts b/src/actions/parameter/api-parameter.ts index 815427b..4db71dc 100644 --- a/src/actions/parameter/api-parameter.ts +++ b/src/actions/parameter/api-parameter.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { ParameterTable, ParameterComparison, ParameterBulkComparison, ProconParameterValues } from '@/types/parameter'; -const url = 'http://localhost:3000/rk2/parameter'; +const url = BACKEND_URL + '/rk2/parameter'; type ParameterResult = { success: true; data: T } | { success: false; error: string }; async function syncRequest(path: string, init?: RequestInit): Promise> { diff --git a/src/actions/procon/api-group-sync.ts b/src/actions/procon/api-group-sync.ts index b26af07..a016b1b 100644 --- a/src/actions/procon/api-group-sync.ts +++ b/src/actions/procon/api-group-sync.ts @@ -1,8 +1,9 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import type { GroupSyncData } from '@/types/procon/group-sync'; import type { GroupSyncValues } from '@/types/procon/group-sync'; import type { GrafikGeneratorDaten } from '@/types/anlagen/procon-view-aggregate'; -const url = (id: number) => 'http://localhost:3000/procon/aggregate/' + id + '/arbeitsflaeche'; +const url = (id: number) => BACKEND_URL + '/procon/aggregate/' + id + '/arbeitsflaeche'; export async function api_groupCompare(id: number): Promise { const response = await fetch(url(id), { cache: 'no-store' }); if (!response.ok) { const error = await response.json(); throw new Error(error.message ?? 'Arbeitsfläche konnte nicht geladen werden'); } diff --git a/src/actions/procon/api-procon-aggregate.ts b/src/actions/procon/api-procon-aggregate.ts index d3f641d..028ef05 100644 --- a/src/actions/procon/api-procon-aggregate.ts +++ b/src/actions/procon/api-procon-aggregate.ts @@ -1,11 +1,12 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from "next/cache"; import { Sites } from "@/_config/sites"; import { ProConAggregate, ProConAggVisu } from "@/types/procon"; -const url = "http://localhost:3000/procon/"; +const url = BACKEND_URL + "/procon/"; const url_aggrgate = url + "aggregate" export async function api_ProconAggregate_Visualisierungen(id: number): Promise<{ diff --git a/src/actions/procon/api-procon-anzeigen.ts b/src/actions/procon/api-procon-anzeigen.ts index a5acf7a..e280c96 100644 --- a/src/actions/procon/api-procon-anzeigen.ts +++ b/src/actions/procon/api-procon-anzeigen.ts @@ -1,9 +1,10 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import { ProConAnzeige, ProConAnzeigeVisuElement } from "@/types/procon/anzeigen"; -const url = "http://localhost:3000/procon/"; +const url = BACKEND_URL + "/procon/"; const url_anzeigen = url + "anzeigen" //----------------------------------------------------------------------------- diff --git a/src/actions/procon/api-procon-meldungen.ts b/src/actions/procon/api-procon-meldungen.ts index 25f9267..d12a01b 100644 --- a/src/actions/procon/api-procon-meldungen.ts +++ b/src/actions/procon/api-procon-meldungen.ts @@ -1,10 +1,11 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import { ProConMeldung } from "@/types/procon/meldungen"; -const url = "http://localhost:3000/procon/"; +const url = BACKEND_URL + "/procon/"; const url_meldungen = url + "meldungen" //----------------------------------------------------------------------------- diff --git a/src/actions/procon/api-procon-sensoren.ts b/src/actions/procon/api-procon-sensoren.ts index a39cffe..ea62747 100644 --- a/src/actions/procon/api-procon-sensoren.ts +++ b/src/actions/procon/api-procon-sensoren.ts @@ -1,9 +1,10 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import { ProConSensor, ProConSensorVisuElement } from "@/types/procon/sensoren"; -const url = "http://localhost:3000/procon/"; +const url = BACKEND_URL + "/procon/"; const url_sensoren = url + "sensoren" const digital ="digital"; const analog = "analog"; diff --git a/src/actions/procon/api-procon-texte.ts b/src/actions/procon/api-procon-texte.ts index 28be9a0..80b4767 100644 --- a/src/actions/procon/api-procon-texte.ts +++ b/src/actions/procon/api-procon-texte.ts @@ -1,9 +1,10 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import { ProConText } from "@/types/procon/texte"; -const url = "http://localhost:3000/procon/"; +const url = BACKEND_URL + "/procon/"; const url_texte = url + "texte" export async function api_ProconTexte_getTexte(): Promise { diff --git a/src/actions/procon/api-procon-views.ts b/src/actions/procon/api-procon-views.ts index 3749afb..67be0ba 100644 --- a/src/actions/procon/api-procon-views.ts +++ b/src/actions/procon/api-procon-views.ts @@ -1,10 +1,11 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from "next/cache"; import { Sites } from "@/_config/sites"; -const url = "http://localhost:3000/procon/"; +const url = BACKEND_URL + "/procon/"; const url_views = url + "views" export async function api_ProconViews_UpdateXAML(id: string, xamlBase64: string): Promise> { diff --git a/src/actions/procon/api-procon-visualisierungen.ts b/src/actions/procon/api-procon-visualisierungen.ts index 980cdf0..a995dbd 100644 --- a/src/actions/procon/api-procon-visualisierungen.ts +++ b/src/actions/procon/api-procon-visualisierungen.ts @@ -1,11 +1,12 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from "next/cache"; import { Sites } from "@/_config/sites"; import { ProConAggregate, ProConView } from "@/types/procon"; -const url = "http://localhost:3000/procon/"; +const url = BACKEND_URL + "/procon/"; const url_visualisierungen = url + "visu" export async function api_ProconVisualisierungen_Update(id: number, data: Partial): Promise> { diff --git a/src/actions/procon/api-project-import.ts b/src/actions/procon/api-project-import.ts index 7eeaaf6..7375600 100644 --- a/src/actions/procon/api-project-import.ts +++ b/src/actions/procon/api-project-import.ts @@ -1,8 +1,9 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { ProjectImportContext, ProjectImportPreview, ProjectImportResult } from '@/types/procon/project-import'; -const url = 'http://localhost:3000/procon/project-import'; +const url = BACKEND_URL + '/procon/project-import'; async function request(action: string, input: unknown): Promise { const response = await fetch(`${url}/${action}`, { method: 'POST', cache: 'no-store', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(input) }); const data = await response.json(); diff --git a/src/actions/procon/api-sync.ts b/src/actions/procon/api-sync.ts index ce141ea..552344b 100644 --- a/src/actions/procon/api-sync.ts +++ b/src/actions/procon/api-sync.ts @@ -1,9 +1,14 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import type { SyncData, SyncRequest } from '@/types/procon/sync'; import { api_groupCompare } from './api-group-sync'; import { api_savedAggregateLinks } from './api-zuordnung'; import { api_viewAggregate_exportXaml } from '@/actions/rk2/api-procon-view-aggregate'; -const url = (id: number, visuId: number) => 'http://localhost:3000/procon/aggregate/' + id + '/visualisierungen/' + visuId + '/sync'; + +function url(id: number, visuId: number): string { + return `${BACKEND_URL}/procon/aggregate/${id}/visualisierungen/${visuId}/sync`; +} + export async function api_exportAggregateXaml(id: number, version: string) { try { const group = await api_groupCompare(id); diff --git a/src/actions/procon/api-zuordnung.ts b/src/actions/procon/api-zuordnung.ts index 3fd04c4..8ca930f 100644 --- a/src/actions/procon/api-zuordnung.ts +++ b/src/actions/procon/api-zuordnung.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import type { MappingPreview } from '@/types/procon/zuordnung'; import type { SavedAggregateLinks } from '@/types/procon/zuordnung'; -const url = 'http://localhost:3000/procon/aggregate/zuordnung'; +const url = BACKEND_URL + '/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.'); diff --git a/src/actions/rk/api-anlage.ts b/src/actions/rk/api-anlage.ts index fa9b1bc..baefc11 100644 --- a/src/actions/rk/api-anlage.ts +++ b/src/actions/rk/api-anlage.ts @@ -1,62 +1,85 @@ 'use server' +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import { Anlage } from "@/types/rk"; import { revalidatePath } from "next/cache"; +function toAnlageSummary(anlage: Anlage): Anlage { + return { + id: anlage.id, + name: anlage.name, + anlageNr: anlage.anlageNr, + selected: anlage.selected, + }; +} + export async function api_anlage_create(input: { name: string; anlageNr: number }): Promise { - const response = await fetch('http://localhost:3000/anlage', { - method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(input), - }); - const data = await response.json(); - if (!response.ok) throw new Error(data.message ?? 'Anlage konnte nicht angelegt werden.'); - revalidatePath(Sites.anlagen.url); - return data; + const response = await fetch(`${BACKEND_URL}/anlage`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(input), + }); + + const data = await response.json(); + + if (!response.ok) { + throw new Error(data.message ?? 'Anlage konnte nicht angelegt werden.'); + } + + revalidatePath(Sites.anlagen.url); + revalidatePath('/projekte'); + + return toAnlageSummary(data); } export async function api_anlagen_getAll(): Promise { + const result = await fetch(`${BACKEND_URL}/anlage`, { + cache: 'no-store', + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); - const result = await fetch(`http://localhost:3000/anlage`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' } - }); + const data = await result.json(); - const data = await result.json(); + if (!result.ok || !Array.isArray(data)) { + throw new Error('Die Anlagenliste konnte nicht geladen werden.'); + } - return data; + return data.map(toAnlageSummary); } export async function api_anlage_getSelected(): Promise { + const result = await fetch(`${BACKEND_URL}/anlage/selected`, { + cache: 'no-store', + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); - const result = await fetch(`http://localhost:3000/anlage/selected`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' } - }); + const data = await result.json(); - const data = await result.json(); - - return data; + return data; } export async function api_anlage_setSelected(id: string): Promise { - console.log(`http://localhost:3000/anlage/selected/${id}`); + const requestUrl = `${BACKEND_URL}/anlage/selected/${id}`; - const result = await fetch(`http://localhost:3000/anlage/selected/${id}`, { - method: 'PATCH', - headers: { 'Content-Type': 'application/json' } - }); + console.log(requestUrl); - const data = await result.json(); + const result = await fetch(requestUrl, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + }); + const data = await result.json(); - console.log(result.status, result.statusText); + console.log(result.status, result.statusText); - if (!result.ok) { - throw new Error(data.message ?? `Anlage konnte nicht ausgewählt werden (${result.status}).`); - } + if (!result.ok) { + throw new Error(data.message ?? `Anlage konnte nicht ausgewählt werden (${result.status}).`); + } - revalidatePath('/', 'layout'); - return data; + revalidatePath('/', 'layout'); + return toAnlageSummary(data); } - diff --git a/src/actions/rk/api-draw.ts b/src/actions/rk/api-draw.ts index 794f3d2..f6ba9f4 100644 --- a/src/actions/rk/api-draw.ts +++ b/src/actions/rk/api-draw.ts @@ -1,28 +1,29 @@ -import { DrawShapeData, DrawShapeOptionen } from "@/types/draw/draw.types"; -import { Anlage } from "@/types/rk"; - -export async function drawGetSvg(name: string, optionen?: DrawShapeOptionen): Promise { - - let optionenStr = ''; - if (optionen) { - optionenStr = '?' - - let separator = '' - for (const [key, value] of Object.entries(optionen)) { - - optionenStr += separator + key + "=" + value; - separator = '&' - } - console.log(optionenStr) - - } - - const result = await fetch(`http://localhost:3000/draw/gurtfoerderer${optionenStr}`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' } - }); - - const data = await result.json() as DrawShapeData; - - return data; -} \ No newline at end of file +import { BACKEND_URL } from '@/_config/backend'; +import { DrawShapeData, DrawShapeOptionen } from "@/types/draw/draw.types"; +import { Anlage } from "@/types/rk"; + +export async function drawGetSvg(name: string, optionen?: DrawShapeOptionen): Promise { + let optionenStr = ''; + + if (optionen) { + optionenStr = '?'; + + let separator = ''; + + for (const [key, value] of Object.entries(optionen)) { + optionenStr += separator + key + "=" + value; + separator = '&'; + } + + console.log(optionenStr); + } + + const result = await fetch(`${BACKEND_URL}/draw/gurtfoerderer${optionenStr}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); + + const data = await result.json() as DrawShapeData; + + return data; +} \ No newline at end of file diff --git a/src/actions/rk/api-element.ts b/src/actions/rk/api-element.ts index 1692d92..3063848 100644 --- a/src/actions/rk/api-element.ts +++ b/src/actions/rk/api-element.ts @@ -1,96 +1,101 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import { Element, ElementCreate, ElementFilterOptionen, ElementUpdate } from "@/types/rk"; import { revalidatePath } from "next/cache"; export async function api_ElementsGet(filter?: ElementFilterOptionen): Promise { + let filterStr = ''; - let filterStr = ''; + if (filter) { + filterStr = '?'; - if (filter) { - filterStr = '?' + let separator = ''; - let separator = '' - for (const [key, value] of Object.entries(filter)) { + for (const [key, value] of Object.entries(filter)) { + filterStr += separator + key + "=" + value; + separator = '&'; + } + } - filterStr += separator + key + "=" + value; - separator = '&' - } - } + const result = await fetch(`${BACKEND_URL}/element${filterStr}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); + const data = await result.json(); - const result = await fetch(`http://localhost:3000/element${filterStr}`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' } - }); - - const data = await result.json(); - - return data; + return data; } export async function elementCreate(data: ElementCreate): Promise> { + const result = await fetch(`${BACKEND_URL}/element`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); - const result = await fetch('http://localhost:3000/element', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data), - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } + revalidatePath(Sites.elements.url + "/"); - revalidatePath(Sites.elements.url+"/") - return { success: true, data: resultData }; + return { + success: true, + data: resultData, + }; } export async function elementUpdate(id: string, data: ElementUpdate): Promise> { + const result = await fetch(`${BACKEND_URL}/element/${id}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); - const result = await fetch(`http://localhost:3000/element/${id}`, { - method: 'PATCH', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data), - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } - - revalidatePath(Sites.elements.url); - return { success: true, data: resultData }; + revalidatePath(Sites.elements.url); + return { + success: true, + data: resultData, + }; } - export async function api_elementDelete(id: string): Promise> { + const result = await fetch(`${BACKEND_URL}/element/${id}`, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + }); - const result = await fetch(`http://localhost:3000/element/${id}`, { - method: 'DELETE', - headers: { 'Content-Type': 'application/json' } - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } + revalidatePath(Sites.elements.url); - revalidatePath(Sites.elements.url); - return { success: true, data: resultData }; - -} \ No newline at end of file + return { + success: true, + data: resultData, + }; +} diff --git a/src/actions/rk/api-file-uplaod.ts b/src/actions/rk/api-file-uplaod.ts index 75d38a1..d5bcb78 100644 --- a/src/actions/rk/api-file-uplaod.ts +++ b/src/actions/rk/api-file-uplaod.ts @@ -1,24 +1,26 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; + export async function uploadFile(formData: FormData) { - const file = formData.get('file') as File; + const file = formData.get('file') as File; - if (!file) { - throw new Error('Keine Datei'); - } + if (!file) { + throw new Error('Keine Datei'); + } - // Neues FormData für NestJS - const backendForm = new FormData(); - backendForm.append('file', file); + // Neues FormData für NestJS + const backendForm = new FormData(); + backendForm.append('file', file); - const res = await fetch('http://localhost:3000/draw/upload', { - method: 'POST', - body: backendForm, - }); + const res = await fetch(`${BACKEND_URL}/draw/upload`, { + method: 'POST', + body: backendForm, + }); - if (!res.ok) { - throw new Error('Upload fehlgeschlagen'); - } + if (!res.ok) { + throw new Error('Upload fehlgeschlagen'); + } - return await res.json(); + return await res.json(); } \ No newline at end of file diff --git a/src/actions/rk/api-groups.ts b/src/actions/rk/api-groups.ts index ae00618..1ae01f5 100644 --- a/src/actions/rk/api-groups.ts +++ b/src/actions/rk/api-groups.ts @@ -1,97 +1,106 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import { Group, GroupCreate, GroupFilterOptionen, GroupUpdate } from "@/types/rk"; import { revalidatePath } from "next/cache"; export async function api_GroupAll(filter?: GroupFilterOptionen): Promise { - - let filterStr = ''; - - if (filter) { - filterStr = '?' + let filterStr = ''; - let separator = '' - for (const [key, value] of Object.entries(filter)) { + if (filter) { + filterStr = '?'; - filterStr += separator + key + "=" + value; - separator = '&' - } - console.log(filterStr) - console.log(`http://localhost:3000/group${filter}`); - } + let separator = ''; - - const result = await fetch(`http://localhost:3000/group${filterStr}`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' } - }); + for (const [key, value] of Object.entries(filter)) { + filterStr += separator + key + "=" + value; + separator = '&'; + } - const data = await result.json(); + console.log(filterStr); + console.log(`${BACKEND_URL}/group${filter}`); + } - return data; + const result = await fetch(`${BACKEND_URL}/group${filterStr}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); + + const data = await result.json(); + + return data; } export async function groupCreate(data: GroupCreate): Promise> { + const result = await fetch(`${BACKEND_URL}/group`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); - const result = await fetch('http://localhost:3000/group', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data), - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } + revalidatePath(Sites.groups.url); - revalidatePath(Sites.groups.url) - return { success: true,data:resultData }; + return { + success: true, + data: resultData, + }; } export async function groupUpdate(id: string, data: GroupUpdate): Promise> { + const result = await fetch(`${BACKEND_URL}/group/${id}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); - const result = await fetch(`http://localhost:3000/group/${id}`, { - method: 'PATCH', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data), - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } - - revalidatePath(Sites.groups.url); - return { success: true,data:resultData }; + revalidatePath(Sites.groups.url); + return { + success: true, + data: resultData, + }; } export async function api_groupDelete(id: string): Promise> { - console.log('delete Group') - const result = await fetch(`http://localhost:3000/group/${id}`, { - method: 'DELETE', - headers: { 'Content-Type': 'application/json' } - }) + console.log('delete Group'); - const resultData = await result.json(); + const result = await fetch(`${BACKEND_URL}/group/${id}`, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + }); - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } + const resultData = await result.json(); - revalidatePath(Sites.groups.url); - return { success: true,data:resultData }; + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } -} \ No newline at end of file + revalidatePath(Sites.groups.url); + + return { + success: true, + data: resultData, + }; +} diff --git a/src/actions/rk/api-logNote.ts b/src/actions/rk/api-logNote.ts index ac8d7ac..6b81015 100644 --- a/src/actions/rk/api-logNote.ts +++ b/src/actions/rk/api-logNote.ts @@ -1,97 +1,103 @@ "use server" +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import { LogNote, LogNoteCreate, LogNoteFilterOptionen, LogNoteUpdate } from "@/types/rk"; import { revalidatePath } from "next/cache"; -const path ="log-note" +const path = "log-note"; + export async function api_LogNoteGet(filter?: LogNoteFilterOptionen): Promise { + let filterStr = ''; - let filterStr = ''; + if (filter) { + filterStr = '?'; - if (filter) { - filterStr = '?' + let separator = ''; - let separator = '' - for (const [key, value] of Object.entries(filter)) { + for (const [key, value] of Object.entries(filter)) { + filterStr += separator + key + "=" + value; + separator = '&'; + } + } - filterStr += separator + key + "=" + value; - separator = '&' - } - } + const result = await fetch(`${BACKEND_URL}/${path}${filterStr}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); + const data = await result.json(); - const result = await fetch(`http://localhost:3000/${path}${filterStr}`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' } - }); - - const data = await result.json(); - - return data; + return data; } export async function api_logNoteCreate(data: LogNoteCreate): Promise> { + const result = await fetch(`${BACKEND_URL}/${path}`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); - const result = await fetch(`http://localhost:3000/${path}`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data), - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } + // revalidatePath(Sites.elements.url) - // revalidatePath(Sites.elements.url) - return { success: true, data: resultData }; + return { + success: true, + data: resultData, + }; } export async function api_logNoteUpdate(id: string, data: LogNoteUpdate): Promise> { + const result = await fetch(`${BACKEND_URL}/${path}/${id}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); - const result = await fetch(`http://localhost:3000/${path}/${id}`, { - method: 'PATCH', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data), - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } - - revalidatePath(Sites.logNote.url); - return { success: true, data: resultData }; + revalidatePath(Sites.logNote.url); + return { + success: true, + data: resultData, + }; } - export async function api_logNoteDelete(id: string): Promise> { + const result = await fetch(`${BACKEND_URL}/${path}/${id}`, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + }); - const result = await fetch(`http://localhost:3000/${path}/${id}`, { - method: 'DELETE', - headers: { 'Content-Type': 'application/json' } - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } + revalidatePath(Sites.logNote.url); - revalidatePath(Sites.logNote.url); - return { success: true, data: resultData }; - -} \ No newline at end of file + return { + success: true, + data: resultData, + }; +} diff --git a/src/actions/rk/api-peripherie.ts b/src/actions/rk/api-peripherie.ts index 5590e1c..7ea61c7 100644 --- a/src/actions/rk/api-peripherie.ts +++ b/src/actions/rk/api-peripherie.ts @@ -1,60 +1,74 @@ "use server"; +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import { Group, Peripherie, PeripherieFilterOptionen, PeripherieUpdate } from "@/types/rk"; import { revalidatePath } from "next/cache"; - - export async function PeripherieFindApi(filter?: PeripherieFilterOptionen): Promise { - let filterStr = ''; - if (filter && (filter.adrByte || filter.elementId || filter.groupId)) { - filterStr = '?' - if (filter.adrByte) filterStr += 'adrByte=' + filter.adrByte; - if (filter.groupId) filterStr += 'groupId=' + filter.groupId; - if (filter.elementId) filterStr += 'elementId=' + filter.elementId; - } - console.log(`http://localhost:3000/peripherie` + filterStr) - const result = await fetch(`http://localhost:3000/peripherie` + filterStr, { - method: 'GET', - headers: { 'Content-Type': 'application/json' } - }); + // URLSearchParams setzt die "&"-Trenner und kodiert die Werte. + const query = new URLSearchParams(); - const data = await result.json(); + if (filter?.adrByte) { + query.set('adrByte', String(filter.adrByte)); + } - return data; + if (filter?.groupId) { + query.set('groupId', filter.groupId); + } + + if (filter?.elementId) { + query.set('elementId', filter.elementId); + } + + const queryString = query.toString(); + const filterStr = queryString ? '?' + queryString : ''; + + const requestUrl = `${BACKEND_URL}/peripherie${filterStr}`; + + console.log(requestUrl); + + const result = await fetch(requestUrl, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); + + const data = await result.json(); + + return data; } export async function GetEA_Differences(): Promise { + const result = await fetch(`${BACKEND_URL}/peripherie/differences`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); - const result = await fetch(`http://localhost:3000/peripherie/differences`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' } - }); + const data = await result.json(); - const data = await result.json(); - - return data; + return data; } export async function api_peripherieUpdate(id: string, data: PeripherieUpdate): Promise> { + const result = await fetch(`${BACKEND_URL}/peripherie/${id}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); - const result = await fetch(`http://localhost:3000/peripherie/${id}`, { - method: 'PATCH', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data), - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } + revalidatePath(Sites.peripheries.url); - revalidatePath(Sites.peripheries.url); - return { success: true, data: resultData }; - -} \ No newline at end of file + return { + success: true, + data: resultData, + }; +} diff --git a/src/actions/rk/api-procon-verbindungen.ts b/src/actions/rk/api-procon-verbindungen.ts index b5c015e..daa40f1 100644 --- a/src/actions/rk/api-procon-verbindungen.ts +++ b/src/actions/rk/api-procon-verbindungen.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import type { ProConConnections } from '@/types/rk/procon-verbindungen'; -const url = (id: string) => 'http://localhost:3000/anlage/' + encodeURIComponent(id) + '/procon-verbindungen'; +const url = (id: string) => BACKEND_URL + '/anlage/' + encodeURIComponent(id) + '/procon-verbindungen'; export async function api_connections(id: string): Promise { const response = await fetch(url(id), { cache: 'no-store' }); if (!response.ok) throw new Error('Verbindungen konnten nicht geladen werden.'); diff --git a/src/actions/rk/api-visuElements.ts b/src/actions/rk/api-visuElements.ts index b9616b0..1f6942b 100644 --- a/src/actions/rk/api-visuElements.ts +++ b/src/actions/rk/api-visuElements.ts @@ -1,64 +1,65 @@ 'use server' +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import { VisuElement, VisuElementCreate, VisuElementUpdate } from "@/types/visu/visuElements.types"; import { revalidatePath } from "next/cache"; export async function api_VisuElementsAll(): Promise { + const result = await fetch(`${BACKEND_URL}/visu-elements`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + }); + const data = await result.json() as VisuElement[]; - - const result = await fetch(`http://localhost:3000/visu-elements`, { - method: 'GET', - headers: { 'Content-Type': 'application/json' } - }); - - const data = await result.json() as VisuElement[]; - - return data; + return data; } + export async function api_VisuElementCreate(data: VisuElementCreate): Promise> { + const result = await fetch(`${BACKEND_URL}/visu-elements/`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); - - const result = await fetch(`http://localhost:3000/visu-elements/`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data), - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } + revalidatePath(Sites.visu.url); - revalidatePath(Sites.visu.url); - return { success: true, data: resultData }; - + return { + success: true, + data: resultData, + }; } export async function api_VisuElementUpdate(id: string, data: VisuElementUpdate): Promise> { + const result = await fetch(`${BACKEND_URL}/visu-elements/${id}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(data), + }); - - const result = await fetch(`http://localhost:3000/visu-elements/${id}`, { - method: 'PATCH', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(data), - }) + const resultData = await result.json(); - const resultData = await result.json(); + if (!result.ok) { + return { + success: false, + errors: resultData.message, // kommt aus NestJS + }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } + revalidatePath(Sites.visu.url); - revalidatePath(Sites.visu.url); - return { success: true, data: resultData }; - + return { + success: true, + data: resultData, + }; } diff --git a/src/actions/rk2/api-ablaeufe.ts b/src/actions/rk2/api-ablaeufe.ts new file mode 100644 index 0000000..ec999e8 --- /dev/null +++ b/src/actions/rk2/api-ablaeufe.ts @@ -0,0 +1,24 @@ +'use server'; +import { BACKEND_URL } from '@/_config/backend'; +import { revalidatePath } from 'next/cache'; +import type { AblaufData, AblaufTable, AblaufSource, AblaufCheck } from '@/types/anlagen/ablaeufe'; +import type { PlanCatalog, BoxSimulation, GraphProposal, BoxPreview } from '@/types/anlagen/materialfluss'; +const url = BACKEND_URL + '/rk2/ablaeufe'; +async function request(path = '', method = 'GET', table?: AblaufTable): Promise { + const response = await fetch(url + path, { method, cache: 'no-store', headers: { 'Content-Type': 'application/json' }, + ...(table ? { body: JSON.stringify({ anlageId: table.anlageId, version: table.version, workflows: table.workflows }) } : {}) }); + const data = await response.json(); + if (!response.ok) throw new Error(Array.isArray(data.message) ? data.message.join('; ') : data.message ?? 'Abläufe konnten nicht geladen werden.'); + return data; +} +export async function api_ablaeufe(): Promise { return request(); } +export async function api_checkAblaeufe(table: AblaufTable): Promise<{ sources: AblaufSource[]; excludedSources: AblaufSource[]; checks: AblaufCheck[]; catalog: PlanCatalog }> { return request('/check', 'POST', table); } +export async function api_previewMaterialPlan(table: AblaufTable, workflowId: string, boxState?: BoxSimulation): Promise<{ graph?: GraphProposal; box?: BoxPreview }> { + const response = await fetch(url + '/preview-plan', { method: 'POST', cache: 'no-store', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ table: { anlageId: table.anlageId, version: table.version, workflows: table.workflows }, workflowId, boxState }) }); + const result = await response.json(); + if (!response.ok) throw new Error(Array.isArray(result.message) ? result.message.join('; ') : result.message ?? 'Vorschau fehlgeschlagen.'); + return result; +} +export async function api_saveAblaeufe(table: AblaufTable): Promise> { + const result = await request>('', 'PUT', table); revalidatePath('/ablaeufe'); return result; +} diff --git a/src/actions/rk2/api-component.ts b/src/actions/rk2/api-component.ts index 3de1e3c..72c4f5d 100644 --- a/src/actions/rk2/api-component.ts +++ b/src/actions/rk2/api-component.ts @@ -1,11 +1,12 @@ 'use server' +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import { ComponentCreate, ComponentOfUnit, ComponentResponse, ComponentUpdate } from "@/types/anlagen/components"; import { UnitResponse } from "@/types/anlagen/units"; import { revalidatePath } from "next/cache"; -const url = "http://localhost:3000/rk2/"; +const url = BACKEND_URL + "/rk2/"; const url_component = url + "components" diff --git a/src/actions/rk2/api-group-overview.ts b/src/actions/rk2/api-group-overview.ts new file mode 100644 index 0000000..2fbbcc2 --- /dev/null +++ b/src/actions/rk2/api-group-overview.ts @@ -0,0 +1,81 @@ +'use server'; + +import { api_units } from './api-units'; +import { api_signals } from './api-signals'; +import { api_visuAggregate } from './api-visu-aggregate'; +import { api_analog } from '@/actions/sensoren/api-analog'; +import { api_digital } from '@/actions/sensoren/api-digital'; +import { api_displays } from '@/actions/anzeigen/api-anzeigewerte'; +import { api_texte } from '@/actions/texte/api-texte'; +import { api_fehlerliste } from '@/actions/fehlerliste/api-fehlerliste'; +import { api_aggregatMeldungen } from '@/actions/fehlerliste/api-aggregat-meldungen'; +import { api_parameters } from '@/actions/parameter/api-parameter'; +import { api_elementParameters } from '@/actions/parameter/api-element-parameter'; +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; +import { createGroupContent } from '@/lib/groups/content'; +import type { GroupResponse } from '@/types/anlagen/groups'; + +export async function api_groupOverview(groups: GroupResponse[], anlageId: string) { + const warnings: string[] = []; + + async function optional(label: string, task: Promise, fallback: T): Promise { + try { + return await task; + } catch { + warnings.push(`${label} konnten nicht geladen werden.`); + return fallback; + } + } + + async function rows(task: Promise<{ anlageId: string; rows: T[] }>): Promise { + const table = await task; + if (table.anlageId !== anlageId) { + throw new Error('Die aktive Anlage wurde geändert.'); + } + return table.rows; + } + + const [units, signals, analog, digital, aggregates, displays, texts, messages, aggregateMessages, parameters, aggregateParameters, analogParameters, digitalParameters, labels] = await Promise.all([ + api_units(), + optional('Signale', api_signals(), []), + optional('Analogsensoren', rows(api_analog()), []), + optional('Digitalsensoren', rows(api_digital()), []), + optional('VisuAggregate', api_visuAggregate(), []), + optional('Anzeigen', rows(api_displays()), []), + optional('Texte', rows(api_texte()), []), + optional('Allgemeine Meldungen', rows(api_fehlerliste()), []), + optional('Aggregatmeldungen', rows(api_aggregatMeldungen()), []), + optional('Allgemeine Parameter', rows(api_parameters()), []), + optional('Aggregatparameter', rows(api_elementParameters('aggregate')), []), + optional('Analogsensorparameter', rows(api_elementParameters('analog')), []), + optional('Digitalsensorparameter', rows(api_elementParameters('digital')), []), + optional('Parameterbeschriftungen', rows(api_elementParameters('beschriftungen')), []), + ]); + + const selected = await api_anlage_getSelected(); + const plantChanged = selected.id !== anlageId || units.some(unit => unit.anlageId && unit.anlageId !== anlageId); + if (plantChanged) { + throw new Error('Die aktive Anlage wurde geändert. Bitte die Gruppenansicht neu laden.'); + } + + const sections = createGroupContent(groups, { + units, + signals, + analog, + digital, + aggregates, + displays, + texts, + messages, + aggregateMessages, + parameters, + elementParameters: { + aggregate: aggregateParameters, + analog: analogParameters, + digital: digitalParameters, + beschriftungen: labels, + }, + }); + + return { sections, warnings: warnings.sort() }; +} diff --git a/src/actions/rk2/api-groups.ts b/src/actions/rk2/api-groups.ts index aff5ab2..b7355c7 100644 --- a/src/actions/rk2/api-groups.ts +++ b/src/actions/rk2/api-groups.ts @@ -1,10 +1,12 @@ 'use server' +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import { GroupCreate, GroupResponse } from "@/types/anlagen/groups"; import { revalidatePath } from "next/cache"; +import { api_units } from './api-units'; -const url = "http://localhost:3000/rk2/"; +const url = BACKEND_URL + "/rk2/"; const url_groups = url + "groups" //----------------------------------------------------------------------------- @@ -98,22 +100,32 @@ export async function api_groups_update(id:string,data: GroupCreate): Promise> { - console.log('Update group' + id); - const result = await fetch(`${url_groups}/${id}`, { - method: 'DELETE', - headers: { 'Content-Type': 'application/json' }, - }) +export async function api_groups_delete(id: string): Promise> { + try { + // Auch vor dem nächsten Backend-Deployment keine belegten Gruppen löschen. + const [groups, units] = await Promise.all([api_groups(), api_units()]); + if (!groups.some(group => group.id === id)) { + return { success: false, errors: ['Gruppe in der aktiven Anlage nicht gefunden.'] }; + } + if (groups.some(group => group.parentId === id) || units.some(unit => unit.groupId === id)) { + return { + success: false, + errors: ['Die Gruppe enthält noch Units oder Untergruppen. Bitte zuerst verschieben oder entfernen.'], + }; + } - const resultData = await result.json(); + const response = await fetch(`${url_groups}/${encodeURIComponent(id)}`, { method: 'DELETE' }); + const data = await response.json(); + if (!response.ok) { + const errors = Array.isArray(data.message) ? data.message : [data.message ?? 'Löschen fehlgeschlagen.']; + return { success: false, errors }; + } - if (!result.ok) { - return { - success: false, - errors: resultData.message, // kommt aus NestJS - }; - } - - revalidatePath(Sites.rk2.groups.url) - return { success: true, data:resultData }; + revalidatePath('/groups'); + revalidatePath('/units'); + revalidatePath('/anlagen/[id]', 'page'); + return { success: true, data }; + } catch { + return { success: false, errors: ['Keine Verbindung zum Backend. Bitte die Gruppenliste prüfen.'] }; + } } diff --git a/src/actions/rk2/api-ios.ts b/src/actions/rk2/api-ios.ts index d20ba43..04195c1 100644 --- a/src/actions/rk2/api-ios.ts +++ b/src/actions/rk2/api-ios.ts @@ -1,10 +1,11 @@ 'use server' +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import type { IoBulkUpdateResult, IoCreate, IoResponse, IoUpdate } from "@/types/anlagen/ios"; import { revalidatePath } from "next/cache"; -const url_ios = "http://localhost:3000/rk2/ios"; +const url_ios = BACKEND_URL + "/rk2/ios"; function getErrors(data: unknown, status: number): string[] { if (typeof data === 'object' && data !== null && 'message' in data) { diff --git a/src/actions/rk2/api-procon-view-aggregate.ts b/src/actions/rk2/api-procon-view-aggregate.ts index f6b72e2..e76030d 100644 --- a/src/actions/rk2/api-procon-view-aggregate.ts +++ b/src/actions/rk2/api-procon-view-aggregate.ts @@ -1,6 +1,7 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { ProConViewAggregateData, ViewElement, ViewAggregateOverview } from '@/types/anlagen/procon-view-aggregate'; -const url = 'http://localhost:3000/rk2/procon-view-aggregate/'; +const url = BACKEND_URL + '/rk2/procon-view-aggregate/'; export async function api_viewAggregate_exportXaml(anlageId: string, auswahl: { componentId: string; elementKeys: string[] }[]) { try { diff --git a/src/actions/rk2/api-signals.ts b/src/actions/rk2/api-signals.ts index 5117ba1..7b080d1 100644 --- a/src/actions/rk2/api-signals.ts +++ b/src/actions/rk2/api-signals.ts @@ -1,10 +1,11 @@ 'use server' +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import { SignalCreate, IoExcelData, SignalResponse } from "@/types/anlagen/signals"; import { revalidatePath } from "next/cache"; -const url = "http://localhost:3000/rk2/"; +const url = BACKEND_URL + "/rk2/"; const url_signals = url + "signals" //----------------------------------------------------------------------------- @@ -21,14 +22,14 @@ export async function api_signal_assignIo(id: string, ioId: string | null): Prom if (!response.ok) { const data: unknown = await response.json().catch(() => null); const message = typeof data === 'object' && data !== null && 'message' in data ? data.message : undefined; - return { success: false, errors: [typeof message === 'string' ? message : 'IO-Zuordnung fehlgeschlagen.'] }; + return { success: false, errors: [typeof message === 'string' ? message : 'Zuordnung IOs fehlgeschlagen.'] }; } const data: SignalResponse = await response.json(); - revalidatePath('/signals/assignment'); - revalidatePath('/signals/assignments'); + revalidatePath('/hardware/io-zuordnung'); + revalidatePath('/hardware/zuordnung-uebersicht'); return { success: true, data }; } catch { - return { success: false, errors: ['IO-Zuordnung konnte nicht gespeichert werden.'] }; + return { success: false, errors: ['Zuordnung IOs konnte nicht gespeichert werden.'] }; } } @@ -43,8 +44,8 @@ export async function api_signals_assignIos(assignments: { signalId: string; ioI return { success: false, errors: [typeof message === 'string' ? message : 'Zuordnungen konnten nicht gespeichert werden.'] }; } const data: SignalResponse[] = await response.json(); - revalidatePath('/signals/assignment'); - revalidatePath('/signals/assignments'); + revalidatePath('/hardware/io-zuordnung'); + revalidatePath('/hardware/zuordnung-uebersicht'); return { success: true, data }; } catch { return { success: false, errors: ['Zuordnungen konnten nicht gespeichert werden.'] }; } } @@ -147,8 +148,8 @@ export async function api_signals_update(id:string,data: SignalCreate): Promise< revalidatePath(Sites.rk2.signals.url) if (data.componentId) revalidatePath(`${Sites.rk2.signals.url}/${data.componentId}`); - revalidatePath('/signals/assignment'); - revalidatePath('/signals/assignments'); + revalidatePath('/hardware/io-zuordnung'); + revalidatePath('/hardware/zuordnung-uebersicht'); return { success: true, data:resultData }; } @@ -162,8 +163,8 @@ export async function api_signals_delete(id: string): Promise { + const requestUrl = `${BACKEND_URL}/rk2/units/${encodeURIComponent(id)}/materialfluss`; + const method = data ? 'PUT' : 'GET'; + + const body = data + ? JSON.stringify({ + anlageId: data.anlageId, + version: data.version, + settings: data.settings, + }) + : undefined; + + const response = await fetch(requestUrl, { + method, + cache: 'no-store', + headers: { 'Content-Type': 'application/json' }, + body, + }); + + const result = await response.json(); + + if (!response.ok) { + throw new Error(result.message ?? 'Unit-Materialfluss konnte nicht gespeichert werden.'); + } + + return result; +} + +export async function api_unitMaterial(id: string) { + return request(id); +} + +export async function api_saveUnitMaterial(id: string, data: UnitMaterialData) { + const result = await request(id, data); + + revalidatePath('/ablaeufe'); + + return result; +} diff --git a/src/actions/rk2/api-unit-templates.ts b/src/actions/rk2/api-unit-templates.ts index f51aabf..e83bdb0 100644 --- a/src/actions/rk2/api-unit-templates.ts +++ b/src/actions/rk2/api-unit-templates.ts @@ -1,10 +1,11 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import { UnitTemplate, UnitTemplateData } from '@/types/anlagen/unit-templates'; import { UnitCopy, UnitResponse } from '@/types/anlagen/units'; -const url = 'http://localhost:3000/rk2/unit-templates'; +const url = BACKEND_URL + '/rk2/unit-templates'; async function request(path: string, method: string, data?: unknown): Promise> { try { const response = await fetch(url + path, { @@ -32,8 +33,8 @@ export async function api_templates_insert(id: string, data: UnitCopy) { if (result.success) { revalidatePath('/units'); revalidatePath('/signals'); - revalidatePath('/signals/assignment'); - revalidatePath('/signals/assignments'); + revalidatePath('/hardware/io-zuordnung'); + revalidatePath('/hardware/zuordnung-uebersicht'); } return result; } diff --git a/src/actions/rk2/api-units.ts b/src/actions/rk2/api-units.ts index 305d692..1731bb4 100644 --- a/src/actions/rk2/api-units.ts +++ b/src/actions/rk2/api-units.ts @@ -1,11 +1,12 @@ 'use server' +import { BACKEND_URL } from '@/_config/backend'; import { Sites } from "@/_config/sites"; import { ComponentCreate, ComponentUpdate } from "@/types/anlagen/components"; import { UnitCopy, UnitCreate, UnitResponse } from "@/types/anlagen/units"; import { revalidatePath } from "next/cache"; -const url = "http://localhost:3000/rk2/"; +const url = BACKEND_URL + "/rk2/"; const url_units = url + "units" const comp_update = "component" const comp_add = "addComponent" @@ -17,8 +18,8 @@ export async function api_units_delete(id: string): Promise(action: string, input: unknown): Promise { const response = await fetch(`${url}/sync/${action}`, { method: 'POST', cache: 'no-store', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(input) }); diff --git a/src/actions/sensoren/api-analog.ts b/src/actions/sensoren/api-analog.ts index bdbf799..0d9b842 100644 --- a/src/actions/sensoren/api-analog.ts +++ b/src/actions/sensoren/api-analog.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { AnalogTable, AnalogSource, AnalogComparison, AnalogSlot } from '@/types/sensoren/analog'; -const url = 'http://localhost:3000/rk2/sensoren-analog'; +const url = BACKEND_URL + '/rk2/sensoren-analog'; async function request(path = '', init?: RequestInit): Promise { const response = await fetch(url + path, { cache: 'no-store', ...init }); const result = await response.json(); if (!response.ok) throw new Error(Array.isArray(result.message) ? result.message.join(', ') : result.message ?? 'Sensoren konnten nicht verarbeitet werden'); diff --git a/src/actions/sensoren/api-digital-opc.ts b/src/actions/sensoren/api-digital-opc.ts index 661c5c5..78559be 100644 --- a/src/actions/sensoren/api-digital-opc.ts +++ b/src/actions/sensoren/api-digital-opc.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { DigitalOpcData, DigitalOpcBinding, DigitalSensorLive, StructureReference } from '@/types/digital-opc'; -const url = 'http://localhost:3000/rk2/digital-opc'; +const url = BACKEND_URL + '/rk2/digital-opc'; async function request(path = '', init?: RequestInit): Promise { const response = await fetch(url + path, { cache: 'no-store', ...init }); const data = await response.json(); if (!response.ok) throw new Error(Array.isArray(data.message) ? data.message.join(', ') : data.message ?? 'OPC-Zuordnung fehlgeschlagen'); return data; diff --git a/src/actions/sensoren/api-digital.ts b/src/actions/sensoren/api-digital.ts index b89e54a..60226e2 100644 --- a/src/actions/sensoren/api-digital.ts +++ b/src/actions/sensoren/api-digital.ts @@ -1,8 +1,9 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { DigitalTable, DigitalComparison, DigitalSlot } from '@/types/sensoren/digital'; import type { AnalogSource } from '@/types/sensoren/analog'; -const url = 'http://localhost:3000/rk2/sensoren-digital'; +const url = BACKEND_URL + '/rk2/sensoren-digital'; async function request(path = '', init?: RequestInit): Promise { const response = await fetch(url + path, { cache: 'no-store', ...init }); const data = await response.json(); diff --git a/src/actions/sensoren/api-motor-opc.ts b/src/actions/sensoren/api-motor-opc.ts index 3db06ea..b313700 100644 --- a/src/actions/sensoren/api-motor-opc.ts +++ b/src/actions/sensoren/api-motor-opc.ts @@ -1,6 +1,7 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import type {MotorOpcData,MotorBinding} from '@/types/motor-opc'; -const url='http://localhost:3000/rk2/motor-opc'; +const url = BACKEND_URL + '/rk2/motor-opc'; async function request(path='',init?:RequestInit):Promise{const r=await fetch(url+path,{cache:'no-store',...init});const d=await r.json();if(!r.ok)throw new Error(d.message??'Motorzuordnung fehlgeschlagen');return d;} export async function api_motorOpc(){return request();} export async function api_motorCommand(componentId:string,input:{anlageId:string;revision:number;controlId:string;command:string}){return request<{results:{field:string;good:boolean;status:string}[]}>('/'+encodeURIComponent(componentId)+'/command',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(input)});} diff --git a/src/actions/steuerbuttons/api-steuerbuttons.ts b/src/actions/steuerbuttons/api-steuerbuttons.ts index 085f6cb..4dc6a35 100644 --- a/src/actions/steuerbuttons/api-steuerbuttons.ts +++ b/src/actions/steuerbuttons/api-steuerbuttons.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { SteuerbuttonTable, SteuerbuttonComparison } from '@/types/steuerbuttons'; -const url = 'http://localhost:3000/rk2/steuerbuttons'; +const url = BACKEND_URL + '/rk2/steuerbuttons'; async function request(init?: RequestInit): Promise { const response = await fetch(url, { cache: 'no-store', ...init }); const data = await response.json(); diff --git a/src/actions/texte/api-texte.ts b/src/actions/texte/api-texte.ts index 4b76f87..bce8142 100644 --- a/src/actions/texte/api-texte.ts +++ b/src/actions/texte/api-texte.ts @@ -1,7 +1,8 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { TextTable, TextComparison } from '@/types/texte'; -const url = 'http://localhost:3000/rk2/texte'; +const url = BACKEND_URL + '/rk2/texte'; async function request(init?: RequestInit): Promise { const response = await fetch(url, { cache: 'no-store', ...init }); const data = await response.json(); diff --git a/src/actions/visualisierung/api-library.ts b/src/actions/visualisierung/api-library.ts index 5a425c3..833fe7b 100644 --- a/src/actions/visualisierung/api-library.ts +++ b/src/actions/visualisierung/api-library.ts @@ -1,8 +1,9 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import { revalidatePath } from 'next/cache'; import type { GraphicLibrary, LibraryGraphic } from '@/types/visualisierung/library'; import type { GrafikGeneratorDaten } from '@/types/visualisierung/graphic'; -const url = 'http://localhost:3000/visualisierung/grafik-bibliothek'; +const url = BACKEND_URL + '/visualisierung/grafik-bibliothek'; async function request(path = '', init?: RequestInit): Promise { const response = await fetch(url + path, { cache: 'no-store', ...init }); const result = await response.json(); diff --git a/src/actions/visualisierung/api-settings.ts b/src/actions/visualisierung/api-settings.ts index 9065bc4..04f6e43 100644 --- a/src/actions/visualisierung/api-settings.ts +++ b/src/actions/visualisierung/api-settings.ts @@ -1,6 +1,7 @@ 'use server'; +import { BACKEND_URL } from '@/_config/backend'; import type { VisualizationSettings } from '@/types/visualisierung/settings'; -const url = (anlageId: string) => `http://localhost:3000/visualisierung/${encodeURIComponent(anlageId)}/settings`; +const url = (anlageId: string) => `${BACKEND_URL}/visualisierung/${encodeURIComponent(anlageId)}/settings`; export async function api_visualizationSettings(anlageId: string): Promise { const response = await fetch(url(anlageId), { cache: 'no-store' }); diff --git a/src/app/(pages)/alt/page.tsx b/src/app/(pages)/alt/page.tsx index 461c056..f8b64df 100644 --- a/src/app/(pages)/alt/page.tsx +++ b/src/app/(pages)/alt/page.tsx @@ -1,7 +1,7 @@ import { Sites } from '@/_config/sites'; import Link from 'next/link'; -const entries = [Sites.anlagen, Sites.groups, Sites.elements, Sites.peripheries, +const entries = [Sites.groups, Sites.elements, Sites.peripheries, Sites.visu, Sites.visu.create, Sites.visu.selectGroups, Sites.visu.elements, Sites.logNote]; export default function AltPage() { diff --git a/src/app/(pages)/alt/rk/anlagen/[id]/verbindungen/page.tsx b/src/app/(pages)/alt/rk/anlagen/[id]/verbindungen/page.tsx index c46494c..8dcbfe8 100644 --- a/src/app/(pages)/alt/rk/anlagen/[id]/verbindungen/page.tsx +++ b/src/app/(pages)/alt/rk/anlagen/[id]/verbindungen/page.tsx @@ -1,8 +1,13 @@ -import { api_connections } from '@/actions/rk/api-procon-verbindungen'; -import ProConConnectionsForm from '@/components/rk/anlage/proconConnections'; -export default async function Page({ params }: { params: Promise<{ id: string }> }) { - const { id } = await params; - try { return
; } - catch { return

Verbindungen konnten nicht geladen werden.

; } -} +import { redirect } from 'next/navigation'; +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; +export default async function PreviousPlantConnectionsPage({ params }: { + params: Promise<{ id: string }>; +}) { + const { id } = await params; + const anlage = await api_anlage_getSelected(); + if (anlage?.id !== id) { + redirect('/projekte'); + } + redirect('/anlagen/einstellungen/procon'); +} diff --git a/src/app/(pages)/alt/rk/anlagen/new/page.tsx b/src/app/(pages)/alt/rk/anlagen/new/page.tsx index 60fd9cd..896de71 100644 --- a/src/app/(pages)/alt/rk/anlagen/new/page.tsx +++ b/src/app/(pages)/alt/rk/anlagen/new/page.tsx @@ -1,3 +1,5 @@ -import AnlageCreate from '@/components/rk/anlage/anlageCreate'; +import { redirect } from 'next/navigation'; -export default function NeueAnlagePage() { return ; } +export default function NeueAnlagePage() { + redirect('/projekte/neu'); +} diff --git a/src/app/(pages)/alt/rk/anlagen/page.tsx b/src/app/(pages)/alt/rk/anlagen/page.tsx index 272fb2b..f001a9d 100644 --- a/src/app/(pages)/alt/rk/anlagen/page.tsx +++ b/src/app/(pages)/alt/rk/anlagen/page.tsx @@ -1,27 +1,5 @@ +import { redirect } from 'next/navigation'; -import { Sites } from "@/_config/sites"; -import { api_anlagen_getAll } from "@/actions/rk/api-anlage"; -import AnlageColumn from "@/components/rk/anlage/anlageColumn"; -import Link from "next/link"; - - -export default async function PageAnlagen() { - const anlagen = await api_anlagen_getAll(); - const currentAnlage = anlagen.find(anlage => anlage.selected); - - return ( -
- {Sites.main.name} -
-

Anlagen

- Neue Anlage anlegen -
-
- {anlagen.map((anlage) => - - )} - -
-
- ) +export default function AnlagenPage() { + redirect('/projekte'); } diff --git a/src/app/(pages)/procon/aggregate/page.tsx b/src/app/(pages)/procon/aggregate/page.tsx index 0e4f988..6005584 100644 --- a/src/app/(pages)/procon/aggregate/page.tsx +++ b/src/app/(pages)/procon/aggregate/page.tsx @@ -11,6 +11,6 @@ export default async function PageAggregate() { } catch (error) { return

Aggregate

{error instanceof Error ? error.message : 'Aggregate konnten nicht geladen werden.'}

- ProCon-Verbindung prüfen
; + ProCon-Verbindung prüfen; } } diff --git a/src/app/(pages)/procon/gesamtabgleich/page.tsx b/src/app/(pages)/procon/gesamtabgleich/page.tsx index 7a450b6..079820f 100644 --- a/src/app/(pages)/procon/gesamtabgleich/page.tsx +++ b/src/app/(pages)/procon/gesamtabgleich/page.tsx @@ -4,6 +4,6 @@ import BulkSyncDashboard from '@/components/procon/bulkSyncDashboard'; export default async function Page() { const result = await api_bulkSyncContext(); - if (!result.ok) return

ProCon-Gesamtabgleich

{result.error}

ProCon-Verbindung prüfen
; + if (!result.ok) return

ProCon-Gesamtabgleich

{result.error}

ProCon-Verbindung prüfen
; return ; } diff --git a/src/app/ablaeufe/page.tsx b/src/app/ablaeufe/page.tsx new file mode 100644 index 0000000..bc0abf9 --- /dev/null +++ b/src/app/ablaeufe/page.tsx @@ -0,0 +1,12 @@ +import { api_ablaeufe } from '@/actions/rk2/api-ablaeufe'; +import AblaeufeEditor from '@/components/ablaeufe/ablaeufeEditor'; + +export default async function AblaeufePage() { + try { + const data = await api_ablaeufe(); + return ; + } catch (cause) { + return

Abläufe und Materialfluss

+

{cause instanceof Error ? cause.message : 'Abläufe konnten nicht geladen werden.'}

; + } +} diff --git a/src/app/anlagen/[id]/page.tsx b/src/app/anlagen/[id]/page.tsx new file mode 100644 index 0000000..489ae2c --- /dev/null +++ b/src/app/anlagen/[id]/page.tsx @@ -0,0 +1,65 @@ +import Link from 'next/link'; +import { notFound, redirect } from 'next/navigation'; +import { api_anlagen_getAll, api_anlage_getSelected } from '@/actions/rk/api-anlage'; +import { api_units } from '@/actions/rk2/api-units'; +import { api_groups } from '@/actions/rk2/api-groups'; +import AnlageUnitSummary from '@/components/rk/anlage/anlageUnitSummary'; + +const sections = [ + { href: '/units', title: 'Units' }, + { href: '/groups', title: 'Gruppen' }, + { href: '/ablaeufe', title: 'Abläufe' }, + { href: '/procon', title: 'ProCon' }, + { href: '/visualisierung', title: 'Visualisierung' }, +]; + +export default async function AnlagenOverviewPage({ + params, +}: { + params: Promise<{ id: string }>; +}) { + const { id } = await params; + const anlagen = await api_anlagen_getAll(); + const anlage = anlagen.find(item => item.id === id); + + if (!anlage) { + notFound(); + } + + const selected = await api_anlage_getSelected(); + + // Ein alter Link darf keine Daten einer inzwischen anderen aktiven Anlage zeigen. + if (selected?.id !== id) { + redirect('/projekte'); + } + + const [units, groups] = await Promise.all([api_units(), api_groups()]); + const current = await api_anlage_getSelected(); + if (current?.id !== id || units.some(unit => unit.anlageId && unit.anlageId !== id)) { + redirect('/projekte'); + } + + return ( +
+
+

Anlage {anlage.anlageNr}

+

Übersicht

+

{anlage.name}

+
+ + + + +
+ ); +} diff --git a/src/app/anlagen/einstellungen/layout.tsx b/src/app/anlagen/einstellungen/layout.tsx new file mode 100644 index 0000000..0611859 --- /dev/null +++ b/src/app/anlagen/einstellungen/layout.tsx @@ -0,0 +1,12 @@ +import type { ReactNode } from 'react'; +import { redirect } from 'next/navigation'; +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; + +export default async function SettingsLayout({ children }: { children: ReactNode }) { + const anlage = await api_anlage_getSelected(); + if (!anlage?.id) { + redirect('/projekte'); + } + + return children; +} diff --git a/src/app/anlagen/einstellungen/opcua/certificate/route.ts b/src/app/anlagen/einstellungen/opcua/certificate/route.ts new file mode 100644 index 0000000..d38de18 --- /dev/null +++ b/src/app/anlagen/einstellungen/opcua/certificate/route.ts @@ -0,0 +1,34 @@ +import { BACKEND_URL } from '@/_config/backend'; + +export async function GET(request: Request) { + const params = new URL(request.url).searchParams; + const id = params.get('id'); + const anlageId = params.get('anlageId'); + + if (!id || !anlageId) { + return new Response('Verbindung fehlt', { status: 400 }); + } + + const certificateUrl = `${BACKEND_URL}/rk2/opcua/${encodeURIComponent(id)}/certificate` + + `?anlageId=${encodeURIComponent(anlageId)}`; + + try { + const response = await fetch(certificateUrl, { cache: 'no-store' }); + + if (!response.ok) { + return new Response('Zertifikat konnte nicht geladen werden. Anlage und Verbindung pruefen.', { + status: response.status, + }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': 'application/x-pem-file', + 'Content-Disposition': 'attachment; filename="RK-OpcUaClient.pem"', + 'Cache-Control': 'no-store', + }, + }); + } catch { + return new Response('Backend nicht erreichbar', { status: 502 }); + } +} diff --git a/src/app/anlagen/einstellungen/opcua/page.tsx b/src/app/anlagen/einstellungen/opcua/page.tsx new file mode 100644 index 0000000..5551dbb --- /dev/null +++ b/src/app/anlagen/einstellungen/opcua/page.tsx @@ -0,0 +1,11 @@ +import { api_opcConfiguration } from '@/actions/opcua/api-opcua'; +import OpcPanel from '@/components/opcua/opcPanel'; + +export default async function OpcSettingsPage() { + try { + const configuration = await api_opcConfiguration(); + return ; + } catch { + return

OPC-Konfiguration konnte nicht geladen werden.

; + } +} diff --git a/src/app/anlagen/einstellungen/page.tsx b/src/app/anlagen/einstellungen/page.tsx new file mode 100644 index 0000000..c975788 --- /dev/null +++ b/src/app/anlagen/einstellungen/page.tsx @@ -0,0 +1,49 @@ +import Link from 'next/link'; +import { redirect } from 'next/navigation'; +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; + +const settings = [ + { + href: '/anlagen/einstellungen/pdf', + title: 'Anlagen-PDF', + description: 'PDF auswählen, hochladen oder ersetzen und Seiten den Units zuordnen.', + }, + { + href: '/anlagen/einstellungen/procon', + title: 'ProCon-Verbindungen', + description: 'Datenbankverbindungen der aktiven Anlage verwalten.', + }, + { + href: '/anlagen/einstellungen/opcua', + title: 'OPC-Verbindungen', + description: 'OPC-UA-Verbindungen und Sicherheit konfigurieren und die Verbindung prüfen.', + }, +]; + +export default async function AnlagenEinstellungenPage() { + const anlage = await api_anlage_getSelected(); + if (!anlage?.id) { + redirect('/projekte'); + } + + return ( +
+
+

Anlageneinstellungen

+

Anlage {anlage.anlageNr} · {anlage.name}

+
+
+ {settings.map(setting => ( + +

{setting.title}

+

{setting.description}

+ + ))} +
+
+ ); +} diff --git a/src/app/anlagen/einstellungen/pdf/page.tsx b/src/app/anlagen/einstellungen/pdf/page.tsx new file mode 100644 index 0000000..6a48db9 --- /dev/null +++ b/src/app/anlagen/einstellungen/pdf/page.tsx @@ -0,0 +1,11 @@ +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; +import { AnlagePdfViewer } from '@/components/rk/anlage/anlagePdfViewer'; + +export default async function AnlagenPdfSettingsPage({ searchParams }: { + searchParams: Promise<{ unit?: string }>; +}) { + const anlage = await api_anlage_getSelected(); + const { unit } = await searchParams; + + return ; +} diff --git a/src/app/anlagen/einstellungen/procon/page.tsx b/src/app/anlagen/einstellungen/procon/page.tsx new file mode 100644 index 0000000..7e305b4 --- /dev/null +++ b/src/app/anlagen/einstellungen/procon/page.tsx @@ -0,0 +1,13 @@ +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; +import { api_connections } from '@/actions/rk/api-procon-verbindungen'; +import ProConConnectionsForm from '@/components/rk/anlage/proconConnections'; + +export default async function ProConSettingsPage() { + try { + const anlage = await api_anlage_getSelected(); + const connections = await api_connections(anlage.id); + return ; + } catch { + return

ProCon-Verbindungen konnten nicht geladen werden.

; + } +} diff --git a/src/app/anlagen/page.tsx b/src/app/anlagen/page.tsx new file mode 100644 index 0000000..5d4934a --- /dev/null +++ b/src/app/anlagen/page.tsx @@ -0,0 +1,7 @@ +import { redirect } from 'next/navigation'; +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; + +export default async function SelectedAnlagePage() { + const anlage = await api_anlage_getSelected(); + redirect(anlage?.id ? `/anlagen/${anlage.id}` : '/projekte'); +} diff --git a/src/app/anlagen/pdf/page.tsx b/src/app/anlagen/pdf/page.tsx index 2fd3eab..1f01b88 100644 --- a/src/app/anlagen/pdf/page.tsx +++ b/src/app/anlagen/pdf/page.tsx @@ -1,9 +1,9 @@ -import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; -import { AnlagePdfViewer } from '@/components/rk/anlage/anlagePdfViewer'; +import { redirect } from 'next/navigation'; -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 ; +export default async function PreviousPdfPage({ searchParams }: { + searchParams: Promise<{ unit?: string }>; +}) { + const { unit } = await searchParams; + const query = unit ? '?unit=' + encodeURIComponent(unit) : ''; + redirect('/anlagen/einstellungen/pdf' + query); } diff --git a/src/app/anzeigewerte/export/route.ts b/src/app/anzeigewerte/export/route.ts index 15a443d..1b3903f 100644 --- a/src/app/anzeigewerte/export/route.ts +++ b/src/app/anzeigewerte/export/route.ts @@ -1,8 +1,23 @@ +import { BACKEND_URL } from '@/_config/backend'; + +const EXCEL_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + export async function GET() { - try { - 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="AllgemeinAnlagenVisualisierung.xlsx"', 'Cache-Control': 'no-store' } }); - } catch { return new Response('Keine Verbindung zum Backend', { status: 502 }); } + try { + const response = await fetch(`${BACKEND_URL}/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': EXCEL_CONTENT_TYPE, + '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/anzeigewerte/page.tsx b/src/app/anzeigewerte/page.tsx index ccc8566..bc63513 100644 --- a/src/app/anzeigewerte/page.tsx +++ b/src/app/anzeigewerte/page.tsx @@ -10,7 +10,7 @@ export default async function Page() { } catch (error) { return

Anzeigen

{error instanceof Error ? error.message : 'Anzeigen konnten nicht geladen werden'}

-
ProCon-Verbindung prüfen +
ProCon-Verbindung prüfen Anzeigen und Grafiken bearbeiten
; } } diff --git a/src/app/api/anlagen/[id]/pdf/[[...path]]/route.ts b/src/app/api/anlagen/[id]/pdf/[[...path]]/route.ts index 3cf42aa..0b99d70 100644 --- a/src/app/api/anlagen/[id]/pdf/[[...path]]/route.ts +++ b/src/app/api/anlagen/[id]/pdf/[[...path]]/route.ts @@ -1,3 +1,4 @@ +import { BACKEND_URL } from '@/_config/backend'; import { NextRequest } from 'next/server'; export const runtime = 'nodejs'; @@ -5,33 +6,84 @@ 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); +const OBJECT_ID_PATTERN = /^[a-f\d]{24}$/i; + +const FORWARDED_REQUEST_HEADERS = [ + 'content-type', + 'range', + 'if-range', +]; + +const FORWARDED_RESPONSE_HEADERS = [ + 'content-type', + 'content-length', + 'content-range', + 'accept-ranges', +]; + +// Erlaubt sind nur: "", "file", "units" und "units/". +function isAllowedPdfPath(path: string[]): boolean { + if (path.length === 0) { + return true; + } + + if (path.length === 1) { + return ['file', 'units'].includes(path[0]); + } + + if (path.length === 2) { + return path[0] === 'units' && OBJECT_ID_PATTERN.test(path[1]); + } + + return false; +} + +function copyHeaders(source: Headers, target: Headers, names: string[]): void { + for (const name of names) { + const value = source.get(name); + + if (value) { + target.set(name, value); + } + } +} + +async function proxy(request: NextRequest, context: Context) { + const { id, path = [] } = await context.params; + + if (!OBJECT_ID_PATTERN.test(id) || !isAllowedPdfPath(path)) { + return Response.json({ message: 'Ungültiger PDF-Pfad' }, { status: 400 }); + } + + const pathSuffix = path.length ? '/' + path.join('/') : ''; + const url = new URL(`${BACKEND_URL}/anlage/${id}/pdf${pathSuffix}`); + url.search = request.nextUrl.search; + + const headers = new Headers(); + copyHeaders(request.headers, headers, FORWARDED_REQUEST_HEADERS); + + try { + const body = request.method === 'GET' + ? undefined + : await request.arrayBuffer(); + + const response = await fetch(url, { + method: request.method, + headers, + cache: 'no-store', + body, + }); + + const outgoing = new Headers({ 'Cache-Control': 'no-store' }); + copyHeaders(response.headers, outgoing, FORWARDED_RESPONSE_HEADERS); + + return new Response(response.body, { + status: response.status, + headers: outgoing, + }); + } catch { + return Response.json({ message: 'Keine Verbindung zum Backend' }, { status: 502 }); } - 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/datensicherung/[id]/datei/route.ts b/src/app/datensicherung/[id]/datei/route.ts index 157b842..21b1266 100644 --- a/src/app/datensicherung/[id]/datei/route.ts +++ b/src/app/datensicherung/[id]/datei/route.ts @@ -1,8 +1 @@ -export async function GET(request:Request,{params}:{params:Promise<{id:string}>}){ - const {id}=await params,file=new URL(request.url).searchParams.get('file')??'manifest.json'; - try{const response=await fetch('http://localhost:3000/rk2/backups/'+encodeURIComponent(id)+'/file?file='+encodeURIComponent(file),{cache:'no-store'}); - if(!response.ok)return new Response('Sicherungsdatei nicht verfügbar',{status:response.status}); - const filename=file.split('/').pop()?.replace(/[^A-Za-z0-9_.-]/g,'_')??'backup.json'; - return new Response(response.body,{headers:{'Content-Type':response.headers.get('Content-Type')??'application/json','Content-Disposition':'attachment; filename="'+filename+'"','Cache-Control':'no-store'}}); - }catch{return new Response('Keine Verbindung zum Backend',{status:502});} -} +export { GET } from '@/app/projekte/system/datensicherung/[id]/datei/route'; diff --git a/src/app/datensicherung/page.tsx b/src/app/datensicherung/page.tsx index fb8d636..b1d875c 100644 --- a/src/app/datensicherung/page.tsx +++ b/src/app/datensicherung/page.tsx @@ -1,3 +1,5 @@ -import {api_backups} from '@/actions/backup/api-backup'; -import BackupPanel from '@/components/backup/backupPanel'; -export default async function Page(){try{return ;}catch(cause){return

{cause instanceof Error?cause.message:'Datensicherungen konnten nicht geladen werden.'}

;}} +import { redirect } from 'next/navigation'; + +export default function PreviousBackupPage() { + redirect('/projekte/system/datensicherung'); +} diff --git a/src/app/fehlerliste/export/route.ts b/src/app/fehlerliste/export/route.ts index cf6d1f8..9010b04 100644 --- a/src/app/fehlerliste/export/route.ts +++ b/src/app/fehlerliste/export/route.ts @@ -1,8 +1,23 @@ +import { BACKEND_URL } from '@/_config/backend'; + +const EXCEL_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + export async function GET() { - try { - const response = await fetch('http://localhost:3000/rk2/fehlerliste/export', { cache: 'no-store' }); - if (!response.ok) return new Response('Fehlerlisten-Export fehlgeschlagen', { status: 502 }); - return new Response(response.body, { headers: { 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'Content-Disposition': 'attachment; filename="Fehlerliste.xlsx"', 'Cache-Control': 'no-store' } }); - } catch { return new Response('Keine Verbindung zum Backend', { status: 502 }); } + try { + const response = await fetch(`${BACKEND_URL}/rk2/fehlerliste/export`, { cache: 'no-store' }); + + if (!response.ok) { + return new Response('Fehlerlisten-Export fehlgeschlagen', { status: 502 }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': EXCEL_CONTENT_TYPE, + 'Content-Disposition': 'attachment; filename="Fehlerliste.xlsx"', + 'Cache-Control': 'no-store', + }, + }); + } catch { + return new Response('Keine Verbindung zum Backend', { status: 502 }); + } } diff --git a/src/app/groups/edit/[id]/page.tsx b/src/app/groups/edit/[id]/page.tsx index 5cb6a2e..7d5f7a1 100644 --- a/src/app/groups/edit/[id]/page.tsx +++ b/src/app/groups/edit/[id]/page.tsx @@ -1,50 +1,42 @@ +import { notFound, redirect } from 'next/navigation'; +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; +import { api_groups, api_groups_byId } from '@/actions/rk2/api-groups'; +import Breadcrumbs from '@/components/ui/navigation/breadcrumbs'; +import { GroupEdit } from '@/components/rk2/groups/groupEdit'; -import { Sites } from "@/_config/sites"; -import { api_units_byId } from "@/actions/rk2/api-units"; +export default async function GroupEditPage({ + params, +}: { + params: Promise<{ id: string }>; +}) { + const { id } = await params; + const anlage = await api_anlage_getSelected(); + if (!anlage?.id) { + redirect('/projekte'); + } -import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; -import { UnitCreateForm } from "@/components/rk2/units/unit_createForm"; + const groups = await api_groups(); + let group; + if (id !== 'new') { + const result = await api_groups_byId(id); + if (!result.success || !result.data) { + notFound(); + } + group = result.data; + } -import Link from "next/link"; -import { UnitEdit } from "@/components/rk2/units/unitEdit"; -import { api_groups, api_groups_byId } from "@/actions/rk2/api-groups"; -import { componentDefaults, componentTypeDefinitions } from "@/actions/rk2/api-compTypes"; + const breadcrumb = [ + { label: 'Anlage', href: '/' }, + { label: 'Gruppen', href: '/groups' }, + { label: group?.name ?? 'Neue Gruppe' }, + ]; -import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; -import { GroupForm } from "@/components/rk2/groups/groupForm"; -import { GroupEdit } from "@/components/rk2/groups/groupEdit"; - -type Props = { - params: Promise<{ - id: string; - }>; -}; - - - -export default async function PageGroupEdit({ params }: Props) { - - const { id } = await params; - const resultFindGroupById = await api_groups_byId(id); - const anlage = await api_anlage_getSelected(); - const group = resultFindGroupById.data; - const groups = await api_groups(); - - const breadcrumb = [{ label: "RK", href: "/" },{ label: "Anlage", href: "/" },{ label: "Groups", href: "/groups" }, { label: "Edit" }, { label: group.name }] - - if (!resultFindGroupById.success) return
Grouppe nicht gefunden {resultFindGroupById.errors} {id}
- - return ( -
-
- -
- -
- - - -
-
- ); + return ( +
+ +
+ +
+
+ ); } diff --git a/src/app/groups/page.tsx b/src/app/groups/page.tsx index a49d4a5..5e178b2 100644 --- a/src/app/groups/page.tsx +++ b/src/app/groups/page.tsx @@ -1,29 +1,27 @@ -import { Sites } from "@/_config/sites"; -import { api_groups } from "@/actions/rk2/api-groups"; -import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; -import { GroupViewList } from "@/components/rk2/groups/groupViewList"; +import { redirect } from 'next/navigation'; +import { api_groups } from '@/actions/rk2/api-groups'; +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; +import { api_groupOverview } from '@/actions/rk2/api-group-overview'; +import Breadcrumbs from '@/components/ui/navigation/breadcrumbs'; +import GroupOverview from '@/components/rk2/groups/groupOverview'; +export default async function GroupsPage() { + const anlage = await api_anlage_getSelected(); + if (!anlage?.id) { + redirect('/projekte'); + } + const groups = await api_groups(); + const { sections, warnings } = await api_groupOverview(groups, anlage.id); + const breadcrumb = [ + { label: 'Anlage', href: '/' }, + { label: 'Gruppen' }, + ]; -import Link from "next/link"; -import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; - - -export default async function PageGroups() { - const currentAnlage= await api_anlage_getSelected(); - const groups = await api_groups(); - - const breadcrumb = [{ label: "RK", href: "/" },{ label: "Anlage", href: "/" },{ label: "Groups" }] - - - return ( -
-
- -
-
- -
-
- ); + return ( +
+ + +
+ ); } diff --git a/src/app/hardware/io-import/page.tsx b/src/app/hardware/io-import/page.tsx new file mode 100644 index 0000000..362077e --- /dev/null +++ b/src/app/hardware/io-import/page.tsx @@ -0,0 +1,23 @@ +import { redirect } from 'next/navigation'; +import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; +import Breadcrumbs from '@/components/ui/navigation/breadcrumbs'; +import IoExcelImport from '@/components/hardware/ioExcelImport'; + +export default async function IoImportPage() { + const anlage = await api_anlage_getSelected(); + if (!anlage?.id) { + redirect('/projekte'); + } + const breadcrumb = [ + { label: 'Hardware', href: '/hardware' }, + { label: 'IO Import' }, + ]; + + return ( +
+ +

IO Import

+ +
+ ); +} diff --git a/src/app/hardware/io-uebersicht/page.tsx b/src/app/hardware/io-uebersicht/page.tsx new file mode 100644 index 0000000..1cf6824 --- /dev/null +++ b/src/app/hardware/io-uebersicht/page.tsx @@ -0,0 +1,21 @@ +import Link from "next/link"; +import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; +import { api_ios } from "@/actions/rk2/api-ios"; +import { api_signals } from "@/actions/rk2/api-signals"; +import { api_units } from "@/actions/rk2/api-units"; +import IoOverview from '@/components/hardware/ioOverview'; +import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; + +export default async function IosPage() { + const anlage = await api_anlage_getSelected(); + const [ios, signals, units] = await Promise.all([api_ios(), api_signals(), api_units()]); + + return
+ +

IO-Übersicht

+ IOs zu Signalen zuordnen + io.anlageId === anlage.id)} + signals={signals.filter((signal) => signal.anlageId === anlage.id)} + units={units.filter((unit) => unit.anlageId === anlage.id)} /> +
; +} diff --git a/src/app/hardware/io-zuordnung/page.tsx b/src/app/hardware/io-zuordnung/page.tsx new file mode 100644 index 0000000..135396f --- /dev/null +++ b/src/app/hardware/io-zuordnung/page.tsx @@ -0,0 +1,18 @@ +import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; +import { api_groups } from "@/actions/rk2/api-groups"; +import { api_units } from "@/actions/rk2/api-units"; +import { api_signals } from "@/actions/rk2/api-signals"; +import { api_ios } from "@/actions/rk2/api-ios"; +import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; +import SignalIoAssignment from '@/components/hardware/signalIoAssignment'; + +export default async function AssignmentPage({ searchParams }: { searchParams: Promise<{ unitId?: string }> }) { + const { unitId } = await searchParams; + const anlage = await api_anlage_getSelected(); + const [groups, units, signals, ios] = await Promise.all([api_groups(), api_units(), api_signals(), api_ios()]); + return
+ + unit.anlageId === anlage.id)} + signals={signals} ios={ios.filter((io) => io.anlageId === anlage.id)} anlageId={anlage.id} initialUnitId={unitId} /> +
; +} diff --git a/src/app/hardware/page.tsx b/src/app/hardware/page.tsx new file mode 100644 index 0000000..f580e65 --- /dev/null +++ b/src/app/hardware/page.tsx @@ -0,0 +1,31 @@ +import Link from 'next/link'; + +const entries = [ + { href: '/hardware/io-uebersicht', title: 'IO-Übersicht', description: 'IOs und ihren Zuordnungsstatus anzeigen und filtern.' }, + { href: '/hardware/io-import', title: 'IO Import', description: 'IO-Daten aus Excel importieren und mit vorhandenen IOs vergleichen.' }, + { href: '/hardware/zuordnung-uebersicht', title: 'Zuordnung IOs Übersicht', description: 'MongoDB-IOs und eigene Signale mit ihren Zuordnungen anzeigen.' }, + { href: '/hardware/io-zuordnung', title: 'Zuordnung IOs', description: 'IOs den Signalen der Anlage zuordnen.' }, +]; + +export default function HardwarePage() { + return ( +
+
+

Hardware

+

IO-Import und Signalzuordnungen der ausgewählten Anlage

+
+ +
+ ); +} diff --git a/src/app/hardware/zuordnung-uebersicht/page.tsx b/src/app/hardware/zuordnung-uebersicht/page.tsx new file mode 100644 index 0000000..7a4ceb3 --- /dev/null +++ b/src/app/hardware/zuordnung-uebersicht/page.tsx @@ -0,0 +1,78 @@ +import Link from "next/link"; +import AssignmentsTable, { type AssignmentRow } from '@/components/hardware/assignmentsTable'; +import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; +import { api_groups } from "@/actions/rk2/api-groups"; +import { api_units } from "@/actions/rk2/api-units"; +import { api_signals } from "@/actions/rk2/api-signals"; +import { api_ios } from "@/actions/rk2/api-ios"; +import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; +import { formatComponentName } from "@/lib/componentName"; +import { eaName } from "@/lib/ioEaExport"; + +export default async function AssignmentsPage() { + const anlage = await api_anlage_getSelected(); + const [groups, units, signals, ios] = await Promise.all([api_groups(), api_units(), api_signals(), api_ios()]); + const groupMap = new Map(groups.map((group) => [group.id, group])); + const ioMap = new Map(ios.filter((io) => io.anlageId === anlage.id).map((io) => [io.id, io])); + const componentMap = new Map(units.filter((unit) => unit.anlageId === anlage.id).flatMap((unit) => + unit.components.map((component) => [component.id, { unit, component }] as const))); + + const groupPath = (id?: string) => { + const names: string[] = []; + const seen = new Set(); + let group = id ? groupMap.get(id) : undefined; + while (group && !seen.has(group.id)) { + seen.add(group.id); + names.unshift(group.name); + group = group.parentId ? groupMap.get(group.parentId) : undefined; + } + return names; + }; + + 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 { + id: signal.id, + group: context ? groupPath(context.unit.groupId).join('.') || 'Ohne Gruppe' : 'Zuordnung zu Unit fehlt', + exportName: context ? eaName(context.unit, context.component, signal.name) : '', + variableTable: context ? groupPath(context.unit.groupId)[1] ?? '' : '', + exportComment: [context?.unit.bmk, io?.seiteName, io?.functionText].filter(Boolean).join(' '), + bmk: context?.unit.bmk ?? '', + unit: context?.unit.name ?? 'Nicht verfügbar', + unitId: context?.unit.id, + component: context ? formatComponentName(context.component) : 'Nicht verfügbar', + componentId: context?.component.id, + signal: signal.name, + type: io?.adrType ?? 'IO nicht verfügbar', + 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
+ +

Zuordnung IOs Übersicht

+

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

+ Zuordnungen bearbeiten + +
; +} diff --git a/src/app/ios/page.tsx b/src/app/ios/page.tsx index 8ce22cf..e56fa08 100644 --- a/src/app/ios/page.tsx +++ b/src/app/ios/page.tsx @@ -1,21 +1,5 @@ -import Link from "next/link"; -import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; -import { api_ios } from "@/actions/rk2/api-ios"; -import { api_signals } from "@/actions/rk2/api-signals"; -import { api_units } from "@/actions/rk2/api-units"; -import IoOverview from "@/components/rk2/ios/ioOverview"; -import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; +import { redirect } from 'next/navigation'; -export default async function IosPage() { - const anlage = await api_anlage_getSelected(); - const [ios, signals, units] = await Promise.all([api_ios(), api_signals(), api_units()]); - - return
- -

IO-Übersicht

- IOs zu Signalen zuordnen - io.anlageId === anlage.id)} - signals={signals.filter((signal) => signal.anlageId === anlage.id)} - units={units.filter((unit) => unit.anlageId === anlage.id)} /> -
; +export default function PreviousIosPage() { + redirect('/hardware/io-uebersicht'); } diff --git a/src/app/live-anlage/events/route.ts b/src/app/live-anlage/events/route.ts index 9196dff..3bbe495 100644 --- a/src/app/live-anlage/events/route.ts +++ b/src/app/live-anlage/events/route.ts @@ -1,11 +1,43 @@ +import { BACKEND_URL } from '@/_config/backend'; + export const dynamic = 'force-dynamic'; export const runtime = 'nodejs'; + +const SCENE_TOKEN_PATTERN = /^[a-f0-9]{64}$/; + export async function GET(request: Request) { - const params = new URL(request.url).searchParams, anlageId = params.get('anlageId'), token = params.get('token'); - if (!anlageId || !token || !/^[a-f0-9]{64}$/.test(token)) return new Response('Anlagenbild fehlt', { status: 400 }); - try { - const response = await fetch('http://localhost:3000/rk2/digital-opc/scene/events?anlageId=' + encodeURIComponent(anlageId) + '&token=' + encodeURIComponent(token), { cache: 'no-store', signal: request.signal }); - if (!response.ok) return new Response('Live-Verbindung nicht erreichbar', { status: response.status }); - return new Response(response.body, { headers: { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache, no-transform', 'X-Accel-Buffering': 'no' } }); - } catch { return new Response('Backend nicht erreichbar', { status: 502 }); } + const params = new URL(request.url).searchParams; + const anlageId = params.get('anlageId'); + const token = params.get('token'); + + const hasValidRequest = anlageId && token && SCENE_TOKEN_PATTERN.test(token); + + if (!hasValidRequest) { + return new Response('Anlagenbild fehlt', { status: 400 }); + } + + const eventsUrl = `${BACKEND_URL}/rk2/digital-opc/scene/events` + + `?anlageId=${encodeURIComponent(anlageId)}` + + `&token=${encodeURIComponent(token)}`; + + try { + const response = await fetch(eventsUrl, { + cache: 'no-store', + signal: request.signal, + }); + + if (!response.ok) { + return new Response('Live-Verbindung nicht erreichbar', { status: response.status }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache, no-transform', + 'X-Accel-Buffering': 'no', + }, + }); + } catch { + return new Response('Backend nicht erreichbar', { status: 502 }); + } } diff --git a/src/app/page.tsx b/src/app/page.tsx index b74dd07..7d3abed 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,52 +1,5 @@ -import { formatComponentName } from "@/lib/componentName"; -import { Sites } from "@/_config/sites"; -import { api_units } from "@/actions/rk2/api-units"; +import { redirect } from 'next/navigation'; -import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; - - -import Link from "next/link"; -import { List, ListItem, ListItemAction } from "@/components/ui/list"; -import { Button } from "@/components/ui/button"; -import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; - - - -export default async function PageUnits() { - - const currentAnlage = await api_anlage_getSelected(); - const units = await api_units(); - const breadcrumb = [{ label: "RK", href: "/" },{ label: "Anlage" }] - - return ( - <> - {/* Main-Nav */} - - -
- - - {units.map((unit) => ( - -
- {unit.name} -
-
- {unit.type} -
-
- {unit.components?.map((comp) =>
{formatComponentName(comp)}
)} -
- - - -
- - ))} -
-
- - ); +export default function HomePage() { + redirect('/projekte'); } diff --git a/src/app/parameter/export/route.ts b/src/app/parameter/export/route.ts index 1c63db0..ad53e25 100644 --- a/src/app/parameter/export/route.ts +++ b/src/app/parameter/export/route.ts @@ -1,8 +1,23 @@ +import { BACKEND_URL } from '@/_config/backend'; + +const EXCEL_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + export async function GET() { - try { - const response = await fetch('http://localhost:3000/rk2/parameter/export', { cache: 'no-store' }); - if (!response.ok) return new Response('Parameter-Export fehlgeschlagen', { status: 502 }); - return new Response(response.body, { headers: { 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'Content-Disposition': 'attachment; filename="AllgemeineAnlageParameter.xlsx"', 'Cache-Control': 'no-store' } }); - } catch { return new Response('Keine Verbindung zum Backend', { status: 502 }); } + try { + const response = await fetch(`${BACKEND_URL}/rk2/parameter/export`, { cache: 'no-store' }); + + if (!response.ok) { + return new Response('Parameter-Export fehlgeschlagen', { status: 502 }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': EXCEL_CONTENT_TYPE, + 'Content-Disposition': 'attachment; filename="AllgemeineAnlageParameter.xlsx"', + 'Cache-Control': 'no-store', + }, + }); + } catch { + return new Response('Keine Verbindung zum Backend', { status: 502 }); + } } diff --git a/src/app/projekte/error.tsx b/src/app/projekte/error.tsx new file mode 100644 index 0000000..3c2f9c2 --- /dev/null +++ b/src/app/projekte/error.tsx @@ -0,0 +1,13 @@ +'use client'; + +import { Button } from '@/components/ui/button'; + +export default function ProjekteError({ reset }: { reset: () => void }) { + return ( +
+

Projekte konnten nicht geladen werden

+

Prüfe, ob das Backend erreichbar ist, und versuche es erneut.

+ +
+ ); +} diff --git a/src/app/projekte/neu/page.tsx b/src/app/projekte/neu/page.tsx new file mode 100644 index 0000000..8225159 --- /dev/null +++ b/src/app/projekte/neu/page.tsx @@ -0,0 +1,5 @@ +import AnlageCreate from '@/components/rk/anlage/anlageCreate'; + +export default function NeueAnlagePage() { + return ; +} diff --git a/src/app/projekte/page.tsx b/src/app/projekte/page.tsx new file mode 100644 index 0000000..05dd6fc --- /dev/null +++ b/src/app/projekte/page.tsx @@ -0,0 +1,8 @@ +import { api_anlagen_getAll } from '@/actions/rk/api-anlage'; +import ProjectList from '@/components/rk/anlage/projectList'; + +export default async function ProjektePage() { + const anlagen = await api_anlagen_getAll(); + + return ; +} diff --git a/src/app/projekte/system/datensicherung/[id]/datei/route.ts b/src/app/projekte/system/datensicherung/[id]/datei/route.ts new file mode 100644 index 0000000..ac4950c --- /dev/null +++ b/src/app/projekte/system/datensicherung/[id]/datei/route.ts @@ -0,0 +1,43 @@ +import { BACKEND_URL } from '@/_config/backend'; + +type BackupFileRouteContext = { + params: Promise<{ id: string }>; +}; + +const UNSAFE_FILENAME_CHARACTERS = /[^A-Za-z0-9_.-]/g; + +// Nur der letzte Pfadteil wird als Download-Name verwendet, +// unsichere Zeichen werden ersetzt. +function toDownloadFilename(file: string): string { + const lastPathPart = file.split('/').pop(); + + return lastPathPart?.replace(UNSAFE_FILENAME_CHARACTERS, '_') ?? 'backup.json'; +} + +export async function GET(request: Request, { params }: BackupFileRouteContext) { + const { id } = await params; + const file = new URL(request.url).searchParams.get('file') ?? 'manifest.json'; + + const backupFileUrl = `${BACKEND_URL}/rk2/backups/${encodeURIComponent(id)}/file` + + `?file=${encodeURIComponent(file)}`; + + try { + const response = await fetch(backupFileUrl, { cache: 'no-store' }); + + if (!response.ok) { + return new Response('Sicherungsdatei nicht verfügbar', { status: response.status }); + } + + const filename = toDownloadFilename(file); + + return new Response(response.body, { + headers: { + 'Content-Type': response.headers.get('Content-Type') ?? 'application/json', + 'Content-Disposition': 'attachment; filename="' + filename + '"', + 'Cache-Control': 'no-store', + }, + }); + } catch { + return new Response('Keine Verbindung zum Backend', { status: 502 }); + } +} diff --git a/src/app/projekte/system/datensicherung/page.tsx b/src/app/projekte/system/datensicherung/page.tsx new file mode 100644 index 0000000..16a53f3 --- /dev/null +++ b/src/app/projekte/system/datensicherung/page.tsx @@ -0,0 +1,17 @@ +import Link from 'next/link'; +import { api_backups } from '@/actions/backup/api-backup'; +import BackupPanel from '@/components/backup/backupPanel'; + +export default async function DatensicherungPage() { + try { + const backups = await api_backups(); + return ( +
+ Zurück zu System + +
+ ); + } catch { + return

Datensicherungen konnten nicht geladen werden.

; + } +} diff --git a/src/app/projekte/system/page.tsx b/src/app/projekte/system/page.tsx new file mode 100644 index 0000000..e0096fd --- /dev/null +++ b/src/app/projekte/system/page.tsx @@ -0,0 +1,17 @@ +import Link from 'next/link'; + +export default function SystemPage() { + return ( +
+ Zur Projektliste +

System

+ +

Datensicherung

+

Sicherungen erstellen, herunterladen und wiederherstellen.

+ +
+ ); +} diff --git a/src/app/sensoren-analog/export/route.ts b/src/app/sensoren-analog/export/route.ts index 4a5998e..394b91c 100644 --- a/src/app/sensoren-analog/export/route.ts +++ b/src/app/sensoren-analog/export/route.ts @@ -1,8 +1,23 @@ +import { BACKEND_URL } from '@/_config/backend'; + +const EXCEL_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + export async function GET() { - try { - const response = await fetch('http://localhost:3000/rk2/sensoren-analog/export', { cache: 'no-store' }); - if (!response.ok) return new Response('Sensoren-Export fehlgeschlagen', { status: 502 }); - return new Response(response.body, { headers: { 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'Content-Disposition': 'attachment; filename="Sensoren_Analog.xlsx"', 'Cache-Control': 'no-store' } }); - } catch { return new Response('Keine Verbindung zum Backend', { status: 502 }); } + try { + const response = await fetch(`${BACKEND_URL}/rk2/sensoren-analog/export`, { cache: 'no-store' }); + + if (!response.ok) { + return new Response('Sensoren-Export fehlgeschlagen', { status: 502 }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': EXCEL_CONTENT_TYPE, + 'Content-Disposition': 'attachment; filename="Sensoren_Analog.xlsx"', + 'Cache-Control': 'no-store', + }, + }); + } catch { + return new Response('Keine Verbindung zum Backend', { status: 502 }); + } } diff --git a/src/app/sensoren-analog/page.tsx b/src/app/sensoren-analog/page.tsx index 1ba26d8..9139dcc 100644 --- a/src/app/sensoren-analog/page.tsx +++ b/src/app/sensoren-analog/page.tsx @@ -10,7 +10,7 @@ export default async function Page() { } catch (error) { return

Sensoren Analog

{error instanceof Error ? error.message : 'Sensoren konnten nicht geladen werden'}

-
ProCon-Verbindung prüfen +
ProCon-Verbindung prüfen Sensoren und Grafiken bearbeiten
; } } diff --git a/src/app/sensoren-analog/xaml/route.ts b/src/app/sensoren-analog/xaml/route.ts index 99ce54c..fe39cf0 100644 --- a/src/app/sensoren-analog/xaml/route.ts +++ b/src/app/sensoren-analog/xaml/route.ts @@ -1,7 +1,21 @@ +import { BACKEND_URL } from '@/_config/backend'; + export async function GET() { - try { - const response = await fetch('http://localhost:3000/rk2/sensoren-analog/xaml-zip', { cache: 'no-store' }); - if (!response.ok) return new Response('XAML-Export fehlgeschlagen', { status: 502 }); - return new Response(response.body, { headers: { 'Content-Type': 'application/zip', 'Content-Disposition': 'attachment; filename="Sensoren_Analog-XAML.zip"', 'Cache-Control': 'no-store' } }); - } catch { return new Response('Keine Verbindung zum Backend', { status: 502 }); } + try { + const response = await fetch(`${BACKEND_URL}/rk2/sensoren-analog/xaml-zip`, { cache: 'no-store' }); + + if (!response.ok) { + return new Response('XAML-Export fehlgeschlagen', { status: 502 }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': 'application/zip', + 'Content-Disposition': 'attachment; filename="Sensoren_Analog-XAML.zip"', + 'Cache-Control': 'no-store', + }, + }); + } catch { + return new Response('Keine Verbindung zum Backend', { status: 502 }); + } } diff --git a/src/app/sensoren-digital/export/route.ts b/src/app/sensoren-digital/export/route.ts index f6798a4..5664a48 100644 --- a/src/app/sensoren-digital/export/route.ts +++ b/src/app/sensoren-digital/export/route.ts @@ -1,8 +1,23 @@ +import { BACKEND_URL } from '@/_config/backend'; + +const EXCEL_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + export async function GET() { - try { - const response = await fetch('http://localhost:3000/rk2/sensoren-digital/export', { cache: 'no-store' }); - if (!response.ok) return new Response('Sensoren-Export fehlgeschlagen', { status: 502 }); - return new Response(response.body, { headers: { 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'Content-Disposition': 'attachment; filename="Sensoren_Digital.xlsx"', 'Cache-Control': 'no-store' } }); - } catch { return new Response('Keine Verbindung zum Backend', { status: 502 }); } + try { + const response = await fetch(`${BACKEND_URL}/rk2/sensoren-digital/export`, { cache: 'no-store' }); + + if (!response.ok) { + return new Response('Sensoren-Export fehlgeschlagen', { status: 502 }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': EXCEL_CONTENT_TYPE, + 'Content-Disposition': 'attachment; filename="Sensoren_Digital.xlsx"', + 'Cache-Control': 'no-store', + }, + }); + } catch { + return new Response('Keine Verbindung zum Backend', { status: 502 }); + } } diff --git a/src/app/sensoren-digital/page.tsx b/src/app/sensoren-digital/page.tsx index 5f5c75b..c7087f4 100644 --- a/src/app/sensoren-digital/page.tsx +++ b/src/app/sensoren-digital/page.tsx @@ -11,7 +11,7 @@ export default async function Page() { } catch (error) { return

Sensoren Digital

{error instanceof Error ? error.message : 'Digitalsensoren konnten nicht geladen werden'}

-
ProCon-Verbindung prüfen +
ProCon-Verbindung prüfen Digitalsensoren und Grafiken bearbeiten
; } } diff --git a/src/app/signals/[componentId]/page.tsx b/src/app/signals/[componentId]/page.tsx index 7e5586c..61ef9c9 100644 --- a/src/app/signals/[componentId]/page.tsx +++ b/src/app/signals/[componentId]/page.tsx @@ -39,7 +39,7 @@ export default async function PageSignalsEdit({ params }: { params: Promise<{ co ]} />

Signale: {unit.name} / {formatComponentName(component)}

Zurück zur Komponente {formatComponentName(component)} - IOs zuordnen + IOs zuordnen

Neues Signal

diff --git a/src/app/signals/assignment/page.tsx b/src/app/signals/assignment/page.tsx index 88b0b72..b474beb 100644 --- a/src/app/signals/assignment/page.tsx +++ b/src/app/signals/assignment/page.tsx @@ -1,18 +1,17 @@ -import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; -import { api_groups } from "@/actions/rk2/api-groups"; -import { api_units } from "@/actions/rk2/api-units"; -import { api_signals } from "@/actions/rk2/api-signals"; -import { api_ios } from "@/actions/rk2/api-ios"; -import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; -import SignalIoAssignment from "@/components/rk2/signals/signalIoAssignment"; +import { redirect } from 'next/navigation'; -export default async function AssignmentPage({ searchParams }: { searchParams: Promise<{ unitId?: string }> }) { - const { unitId } = await searchParams; - const anlage = await api_anlage_getSelected(); - const [groups, units, signals, ios] = await Promise.all([api_groups(), api_units(), api_signals(), api_ios()]); - return
- - unit.anlageId === anlage.id)} - signals={signals} ios={ios.filter((io) => io.anlageId === anlage.id)} anlageId={anlage.id} initialUnitId={unitId} /> -
; +export default async function PreviousHardwarePage({ searchParams }: { + searchParams: Promise>; +}) { + const params = await searchParams; + const query = new URLSearchParams(); + for (const [key, value] of Object.entries(params)) { + if (Array.isArray(value)) { + value.forEach(item => query.append(key, item)); + } else if (value !== undefined) { + query.append(key, value); + } + } + const suffix = query.size ? '?' + query.toString() : ''; + redirect('/hardware/io-zuordnung' + suffix); } diff --git a/src/app/signals/assignments/page.tsx b/src/app/signals/assignments/page.tsx index 3493ff7..0a4fb2f 100644 --- a/src/app/signals/assignments/page.tsx +++ b/src/app/signals/assignments/page.tsx @@ -1,78 +1,17 @@ -import Link from "next/link"; -import AssignmentsTable, { type AssignmentRow } from "@/components/rk2/signals/assignmentsTable"; -import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; -import { api_groups } from "@/actions/rk2/api-groups"; -import { api_units } from "@/actions/rk2/api-units"; -import { api_signals } from "@/actions/rk2/api-signals"; -import { api_ios } from "@/actions/rk2/api-ios"; -import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; -import { formatComponentName } from "@/lib/componentName"; -import { eaName } from "@/lib/ioEaExport"; +import { redirect } from 'next/navigation'; -export default async function AssignmentsPage() { - const anlage = await api_anlage_getSelected(); - const [groups, units, signals, ios] = await Promise.all([api_groups(), api_units(), api_signals(), api_ios()]); - const groupMap = new Map(groups.map((group) => [group.id, group])); - const ioMap = new Map(ios.filter((io) => io.anlageId === anlage.id).map((io) => [io.id, io])); - const componentMap = new Map(units.filter((unit) => unit.anlageId === anlage.id).flatMap((unit) => - unit.components.map((component) => [component.id, { unit, component }] as const))); - - const groupPath = (id?: string) => { - const names: string[] = []; - const seen = new Set(); - let group = id ? groupMap.get(id) : undefined; - while (group && !seen.has(group.id)) { - seen.add(group.id); - names.unshift(group.name); - group = group.parentId ? groupMap.get(group.parentId) : undefined; +export default async function PreviousHardwarePage({ searchParams }: { + searchParams: Promise>; +}) { + const params = await searchParams; + const query = new URLSearchParams(); + for (const [key, value] of Object.entries(params)) { + if (Array.isArray(value)) { + value.forEach(item => query.append(key, item)); + } else if (value !== undefined) { + query.append(key, value); } - return names; - }; - - 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 { - id: signal.id, - group: context ? groupPath(context.unit.groupId).join('.') || 'Ohne Gruppe' : 'Zuordnung zu Unit fehlt', - exportName: context ? eaName(context.unit, context.component, signal.name) : '', - variableTable: context ? groupPath(context.unit.groupId)[1] ?? '' : '', - exportComment: [context?.unit.bmk, io?.seiteName, io?.functionText].filter(Boolean).join(' '), - bmk: context?.unit.bmk ?? '', - unit: context?.unit.name ?? 'Nicht verfügbar', - unitId: context?.unit.id, - component: context ? formatComponentName(context.component) : 'Nicht verfügbar', - componentId: context?.component.id, - signal: signal.name, - type: io?.adrType ?? 'IO nicht verfügbar', - 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
- -

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 - -
; + const suffix = query.size ? '?' + query.toString() : ''; + redirect('/hardware/zuordnung-uebersicht' + suffix); } diff --git a/src/app/signals/import/page.tsx b/src/app/signals/import/page.tsx index c87feca..d8c0f8a 100644 --- a/src/app/signals/import/page.tsx +++ b/src/app/signals/import/page.tsx @@ -1,32 +1,17 @@ -import { Sites } from "@/_config/sites"; -import { api_units } from "@/actions/rk2/api-units"; +import { redirect } from 'next/navigation'; -import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; - - -import Link from "next/link"; -import { List, ListItem, ListItemAction } from "@/components/ui/list"; -import { Button } from "@/components/ui/button"; -import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; -import IoExcelImport from "@/components/rk2/ios/ioExcelImport"; - - - -export default async function PageImport() { - - const currentAnlage = await api_anlage_getSelected(); - const units = await api_units(); - const breadcrumb = [{ label: "RK", href: "/" },{ label: `${Sites.rk2.signals.name}`, href:`${Sites.rk2.signals.url}` },{ label: `${Sites.rk2.signals.import.name}` },{ label: `${currentAnlage.anlageNr+" "+currentAnlage.name}` }] - - return ( - <> - {/* Main-Nav */} - - -
- - -
- - ); +export default async function PreviousHardwarePage({ searchParams }: { + searchParams: Promise>; +}) { + const params = await searchParams; + const query = new URLSearchParams(); + for (const [key, value] of Object.entries(params)) { + if (Array.isArray(value)) { + value.forEach(item => query.append(key, item)); + } else if (value !== undefined) { + query.append(key, value); + } + } + const suffix = query.size ? '?' + query.toString() : ''; + redirect('/hardware/io-import' + suffix); } diff --git a/src/app/signals/page.tsx b/src/app/signals/page.tsx index 0247c15..6459b37 100644 --- a/src/app/signals/page.tsx +++ b/src/app/signals/page.tsx @@ -25,13 +25,10 @@ export default async function PageSignale() {
- MongoDB-IOs / meine Signale vergleichen + Zuordnung IOs Übersicht - Alle IO-Zuordnungen - - - IO-Zuordnung + Zuordnung IOs {Sites.rk2.signals.import.name} diff --git a/src/app/sps/io-diagnose/events/route.ts b/src/app/sps/io-diagnose/events/route.ts index 93c6d35..98a0521 100644 --- a/src/app/sps/io-diagnose/events/route.ts +++ b/src/app/sps/io-diagnose/events/route.ts @@ -1,8 +1,56 @@ -export const dynamic='force-dynamic'; -export const runtime='nodejs'; -export async function GET(request:Request){ - const params=new URL(request.url).searchParams; - if(!['anlageId','connectionId','unitId','token'].every(k=>params.get(k))||!/^[a-f0-9]{64}$/.test(params.get('token')??''))return new Response('Prüfung und Unit fehlen',{status:400}); - const query=new URLSearchParams();for(const key of ['anlageId','connectionId','unitId','token'])query.set(key,params.get(key)!); - try{const r=await fetch('http://localhost:3000/rk2/io-diagnostics/events?'+query,{cache:'no-store',signal:request.signal});if(!r.ok)return new Response('Live-Verbindung nicht verfügbar',{status:r.status});return new Response(r.body,{headers:{'Content-Type':'text/event-stream','Cache-Control':'no-cache, no-transform','X-Accel-Buffering':'no'}});}catch{return new Response('Backend nicht erreichbar',{status:502});} +import { BACKEND_URL } from '@/_config/backend'; + +export const dynamic = 'force-dynamic'; +export const runtime = 'nodejs'; + +const REQUIRED_PARAMS = [ + 'anlageId', + 'connectionId', + 'unitId', + 'token', +]; + +const DIAGNOSE_TOKEN_PATTERN = /^[a-f0-9]{64}$/; + +function hasValidParams(params: URLSearchParams): boolean { + const hasAllParams = REQUIRED_PARAMS.every((key) => params.get(key)); + const hasValidToken = DIAGNOSE_TOKEN_PATTERN.test(params.get('token') ?? ''); + + return hasAllParams && hasValidToken; +} + +export async function GET(request: Request) { + const params = new URL(request.url).searchParams; + + if (!hasValidParams(params)) { + return new Response('Prüfung und Unit fehlen', { status: 400 }); + } + + // Nur die erwarteten Parameter an das Backend weitergeben + const query = new URLSearchParams(); + + for (const key of REQUIRED_PARAMS) { + query.set(key, params.get(key)!); + } + + try { + const response = await fetch(`${BACKEND_URL}/rk2/io-diagnostics/events?${query}`, { + cache: 'no-store', + signal: request.signal, + }); + + if (!response.ok) { + return new Response('Live-Verbindung nicht verfügbar', { status: response.status }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache, no-transform', + 'X-Accel-Buffering': 'no', + }, + }); + } catch { + return new Response('Backend nicht erreichbar', { status: 502 }); + } } diff --git a/src/app/sps/opcua-strukturen/live/route.ts b/src/app/sps/opcua-strukturen/live/route.ts index 8ae2a19..21d84e4 100644 --- a/src/app/sps/opcua-strukturen/live/route.ts +++ b/src/app/sps/opcua-strukturen/live/route.ts @@ -1,15 +1,60 @@ +import { BACKEND_URL } from '@/_config/backend'; + export const dynamic = 'force-dynamic'; export const runtime = 'nodejs'; -export async function GET(request: Request) { - const params = new URL(request.url).searchParams; - const name = params.get('name'), anlageId = params.get('anlageId'); - if (!name || !anlageId || !/^[A-Za-z_][A-Za-z0-9_]{0,79}$/.test(name)) return new Response('Struktur fehlt', { status: 400 }); - const sensorId = params.get('sensorId'), expectedId = params.get('expectedId'); - if (sensorId && !/^[\w-]{1,80}$/.test(sensorId)) return new Response('Ungültiger Sensor', { status: 400 }); - try { - const target = sensorId ? 'http://localhost:3000/rk2/digital-opc/' + encodeURIComponent(sensorId) + '/events?anlageId=' + encodeURIComponent(anlageId) + '&expectedId=' + encodeURIComponent(expectedId ?? '') : 'http://localhost:3000/rk2/opcua-structures/' + encodeURIComponent(name) + '/live?anlageId=' + encodeURIComponent(anlageId) + '&expectedId=' + encodeURIComponent(expectedId ?? ''); - const response = await fetch(target, { cache: 'no-store', signal: request.signal }); - if (!response.ok) return new Response('Live-Verbindung fehlgeschlagen', { status: response.status }); - return new Response(response.body, { headers: { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache, no-transform', 'X-Accel-Buffering': 'no' } }); - } catch { return new Response('Backend nicht erreichbar', { status: 502 }); } + +const STRUCTURE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,79}$/; +const SENSOR_ID_PATTERN = /^[\w-]{1,80}$/; + +// Mit Sensor-ID kommen die Live-Werte vom Digital-OPC-Endpunkt, +// sonst direkt von der OPC-UA-Struktur. +function getLiveUrl(name: string, anlageId: string, sensorId: string | null, expectedId: string | null): string { + const query = `?anlageId=${encodeURIComponent(anlageId)}` + + `&expectedId=${encodeURIComponent(expectedId ?? '')}`; + + if (sensorId) { + return `${BACKEND_URL}/rk2/digital-opc/${encodeURIComponent(sensorId)}/events${query}`; + } + + return `${BACKEND_URL}/rk2/opcua-structures/${encodeURIComponent(name)}/live${query}`; +} + +export async function GET(request: Request) { + const params = new URL(request.url).searchParams; + const name = params.get('name'); + const anlageId = params.get('anlageId'); + + if (!name || !anlageId || !STRUCTURE_NAME_PATTERN.test(name)) { + return new Response('Struktur fehlt', { status: 400 }); + } + + const sensorId = params.get('sensorId'); + const expectedId = params.get('expectedId'); + + if (sensorId && !SENSOR_ID_PATTERN.test(sensorId)) { + return new Response('Ungültiger Sensor', { status: 400 }); + } + + try { + const liveUrl = getLiveUrl(name, anlageId, sensorId, expectedId); + + const response = await fetch(liveUrl, { + cache: 'no-store', + signal: request.signal, + }); + + if (!response.ok) { + return new Response('Live-Verbindung fehlgeschlagen', { status: response.status }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache, no-transform', + 'X-Accel-Buffering': 'no', + }, + }); + } catch { + return new Response('Backend nicht erreichbar', { status: 502 }); + } } diff --git a/src/app/sps/opcua/certificate/route.ts b/src/app/sps/opcua/certificate/route.ts index c9bf2e1..10e49f8 100644 --- a/src/app/sps/opcua/certificate/route.ts +++ b/src/app/sps/opcua/certificate/route.ts @@ -1,10 +1 @@ -export async function GET(request: Request) { - const params = new URL(request.url).searchParams; - const id = params.get('id'), anlageId = params.get('anlageId'); - if (!id || !anlageId) return new Response('Verbindung fehlt', { status: 400 }); - try { - const response = await fetch('http://localhost:3000/rk2/opcua/' + encodeURIComponent(id) + '/certificate?anlageId=' + encodeURIComponent(anlageId), { cache: 'no-store' }); - if (!response.ok) return new Response('Zertifikat konnte nicht geladen werden. Anlage und Verbindung pruefen.', { status: response.status }); - return new Response(response.body, { headers: { 'Content-Type': 'application/x-pem-file', 'Content-Disposition': 'attachment; filename="RK-OpcUaClient.pem"', 'Cache-Control': 'no-store' } }); - } catch { return new Response('Backend nicht erreichbar', { status: 502 }); } -} +export { GET } from '@/app/anlagen/einstellungen/opcua/certificate/route'; diff --git a/src/app/sps/opcua/page.tsx b/src/app/sps/opcua/page.tsx index 3972f45..e8c08ee 100644 --- a/src/app/sps/opcua/page.tsx +++ b/src/app/sps/opcua/page.tsx @@ -1,6 +1,5 @@ -import { api_opcConfiguration } from '@/actions/opcua/api-opcua'; -import OpcPanel from '@/components/opcua/opcPanel'; -export default async function Page() { - try { return ; } - catch (cause) { return

{cause instanceof Error ? cause.message : 'OPC-Konfiguration nicht erreichbar'}

; } +import { redirect } from 'next/navigation'; + +export default function PreviousOpcPage() { + redirect('/anlagen/einstellungen/opcua'); } diff --git a/src/app/steuerbuttons/export/route.ts b/src/app/steuerbuttons/export/route.ts index 491004d..73c7f3f 100644 --- a/src/app/steuerbuttons/export/route.ts +++ b/src/app/steuerbuttons/export/route.ts @@ -1,8 +1,23 @@ +import { BACKEND_URL } from '@/_config/backend'; + +const EXCEL_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + export async function GET() { - try { - const response = await fetch('http://localhost:3000/rk2/steuerbuttons/export', { cache: 'no-store' }); - if (!response.ok) return new Response('Steuertaster-Export fehlgeschlagen', { status: 502 }); - return new Response(response.body, { headers: { 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'Content-Disposition': 'attachment; filename="AllgemeinSteuerButton.xlsx"', 'Cache-Control': 'no-store' } }); - } catch { return new Response('Keine Verbindung zum Backend', { status: 502 }); } + try { + const response = await fetch(`${BACKEND_URL}/rk2/steuerbuttons/export`, { cache: 'no-store' }); + + if (!response.ok) { + return new Response('Steuertaster-Export fehlgeschlagen', { status: 502 }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': EXCEL_CONTENT_TYPE, + 'Content-Disposition': 'attachment; filename="AllgemeinSteuerButton.xlsx"', + 'Cache-Control': 'no-store', + }, + }); + } catch { + return new Response('Keine Verbindung zum Backend', { status: 502 }); + } } diff --git a/src/app/texte/export/route.ts b/src/app/texte/export/route.ts index 3b0b5e8..055ffad 100644 --- a/src/app/texte/export/route.ts +++ b/src/app/texte/export/route.ts @@ -1,8 +1,23 @@ +import { BACKEND_URL } from '@/_config/backend'; + +const EXCEL_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + export async function GET() { - try { - const response = await fetch('http://localhost:3000/rk2/texte/export', { cache: 'no-store' }); - if (!response.ok) return new Response('Texte-Export fehlgeschlagen', { status: 502 }); - return new Response(response.body, { headers: { 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'Content-Disposition': 'attachment; filename="Texte.xlsx"', 'Cache-Control': 'no-store' } }); - } catch { return new Response('Keine Verbindung zum Backend', { status: 502 }); } + try { + const response = await fetch(`${BACKEND_URL}/rk2/texte/export`, { cache: 'no-store' }); + + if (!response.ok) { + return new Response('Texte-Export fehlgeschlagen', { status: 502 }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': EXCEL_CONTENT_TYPE, + 'Content-Disposition': 'attachment; filename="Texte.xlsx"', + 'Cache-Control': 'no-store', + }, + }); + } catch { + return new Response('Keine Verbindung zum Backend', { status: 502 }); + } } diff --git a/src/app/units/edit/[id]/page.tsx b/src/app/units/edit/[id]/page.tsx index 4f96d45..ccbfd03 100644 --- a/src/app/units/edit/[id]/page.tsx +++ b/src/app/units/edit/[id]/page.tsx @@ -34,7 +34,7 @@ export default async function PageUnitsEdit({ params, searchParams }: Props) { return (
- {from === 'io-assignment' && Zurück zur IO-Zuordnung} + {from === 'io-assignment' && Zurück zur Zuordnung IOs}
diff --git a/src/app/units/page.tsx b/src/app/units/page.tsx index d635bbf..1c4867d 100644 --- a/src/app/units/page.tsx +++ b/src/app/units/page.tsx @@ -1,85 +1,22 @@ -import { formatComponentName } from "@/lib/componentName"; -import { Sites } from "@/_config/sites"; -import { api_units } from "@/actions/rk2/api-units"; -import { api_anlage_getSelected } from "@/actions/rk/api-anlage"; -import Link from "next/link"; -import { List, ListHeader, ListHeaderItem, ListItem, ListItemAction, ListItemContent, ListItemDescription, ListItemTitle } from "@/components/ui/list"; -import { Button } from "@/components/ui/button"; -import Breadcrumbs from "@/components/ui/navigation/breadcrumbs"; -import { Card, CardContent, CardHeader } from "@/components/ui/card"; -import { GroupPath } from "@/components/rk2/groups/groupPath"; -import { api_groups } from "@/actions/rk2/api-groups"; -import { AusgabeUnitInfo } from "@/components/rk2/ausgabe/ausgabeUnitInfo"; +import { api_units } from '@/actions/rk2/api-units'; +import { api_groups } from '@/actions/rk2/api-groups'; +import Breadcrumbs from '@/components/ui/navigation/breadcrumbs'; +import UnitOverview from '@/components/rk2/units/unitOverview'; +export default async function UnitsPage() { + const [units, groups] = await Promise.all([ + api_units(), + api_groups(), + ]); + const breadcrumb = [ + { label: 'Anlage', href: '/' }, + { label: 'Units' }, + ]; - -export default async function PageUnits() { - - const units = await api_units(); - const groups = await api_groups(); - const breadcrumb = [{ label: "RK", href: "/" }, { label: "Anlage", href: "/" }, { label: "Units" }] - - return ( - <> - {/* Main-Nav */} -
- -
- - - Units - Unit-Vorlagen / Aus Vorlage hinzufügen - - - - - - - Gruppe - Unit - Typ - - {units.map((unit) => ( - - - -
- -
-
- {unit.prefix}_{unit.bmk}_{unit.name}{unit.postfix ? "_"+unit.postfix:""} -
-
- {unit.type} -
-
- - {unit.components?.map((comp) =>
- {comp.prefix && comp.prefix} - {formatComponentName(comp)} - {comp.postfix && comp.postfix} - {comp.index && comp.index>0 ? comp.index:""} -
)} -
-
- - - -
- - ))} -
-
- - Ausgabe - - - - - - ); + return ( +
+ + +
+ ); } diff --git a/src/app/verbindungen/page.tsx b/src/app/verbindungen/page.tsx index 5039ac9..a226aa4 100644 --- a/src/app/verbindungen/page.tsx +++ b/src/app/verbindungen/page.tsx @@ -1,10 +1,5 @@ -import { api_connections } from '@/actions/rk/api-procon-verbindungen'; -import { api_anlage_getSelected } from '@/actions/rk/api-anlage'; -import ProConConnectionsForm from '@/components/rk/anlage/proconConnections'; -export default async function Page() { - try { - const anlage = await api_anlage_getSelected(); - return ; - } catch { return

Verbindungen konnten nicht geladen werden. Bitte eine Anlage auswählen.

; } -} +import { redirect } from 'next/navigation'; +export default function PreviousConnectionsPage() { + redirect('/anlagen/einstellungen/procon'); +} diff --git a/src/app/visu-aggregate/export/route.ts b/src/app/visu-aggregate/export/route.ts index 91cb3e7..26c6658 100644 --- a/src/app/visu-aggregate/export/route.ts +++ b/src/app/visu-aggregate/export/route.ts @@ -1,15 +1,23 @@ +import { BACKEND_URL } from '@/_config/backend'; + +const EXCEL_CONTENT_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + export async function GET() { - try { - const response = await fetch('http://localhost:3000/rk2/visu-aggregate/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="VisuAggregate.xlsx"', - 'Cache-Control': 'no-store', - }, - }); - } catch { - return new Response('Keine Verbindung zum Backend.', { status: 502 }); - } + try { + const response = await fetch(`${BACKEND_URL}/rk2/visu-aggregate/export`, { cache: 'no-store' }); + + if (!response.ok) { + return new Response('Excel-Export fehlgeschlagen.', { status: 502 }); + } + + return new Response(response.body, { + headers: { + 'Content-Type': EXCEL_CONTENT_TYPE, + 'Content-Disposition': 'attachment; filename="VisuAggregate.xlsx"', + 'Cache-Control': 'no-store', + }, + }); + } catch { + return new Response('Keine Verbindung zum Backend.', { status: 502 }); + } } diff --git a/src/components/ablaeufe/ablaeufeEditor.tsx b/src/components/ablaeufe/ablaeufeEditor.tsx new file mode 100644 index 0000000..4c2fe47 --- /dev/null +++ b/src/components/ablaeufe/ablaeufeEditor.tsx @@ -0,0 +1,171 @@ +'use client'; +import { useRef, useState } from 'react'; +import Link from 'next/link'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Select } from '@/components/ui/select'; +import { useNavigationGuard } from '@/hooks/useNavigationGuard'; +import { api_checkAblaeufe, api_saveAblaeufe } from '@/actions/rk2/api-ablaeufe'; +import type { Ablauf, AblaufData, AblaufStep, AblaufCheck, WaitKind } from '@/types/anlagen/ablaeufe'; +import AblaufPreview from './ablaufPreview'; +import MaterialGraph from './materialGraph'; +import BoxPlanEditor, { newBoxPlan } from './boxPlan'; +import type { DriveDirection } from '@/types/anlagen/materialfluss'; + +function move(rows: T[], index: number, delta: number): T[] { + const next = index + delta; if (next < 0 || next >= rows.length) return rows; + const result = [...rows]; [result[index], result[next]] = [result[next], result[index]]; return result; +} +const step = (id: string): AblaufStep => ({ id: crypto.randomUUID(), aggregateIds: [id], wait: { kind: 'running', seconds: null } }); +const withMembers = (s: AblaufStep, ids: string[]): AblaufStep => ({ ...s, aggregateIds: ids, + ...(s.directions ? { directions: Object.fromEntries(Object.entries(s.directions).filter(([id]) => ids.includes(id))) } : {}) }); +function uniqueName(base: string, flows: Ablauf[]) { + const used = new Set(flows.map(f => f.name.trim().toLocaleLowerCase('de'))); + let name = base, n = 2; while (used.has(name.toLocaleLowerCase('de'))) name = `${base} ${n++}`; return name; +} + +export default function AblaeufeEditor({ initial }: { initial: AblaufData }) { + const [data, setData] = useState(initial); + const saved = useRef(JSON.stringify(initial.workflows)); + const [selectedId, setSelectedId] = useState(initial.workflows[0]?.id ?? ''); + const [filter, setFilter] = useState(''), [aggregateId, setAggregateId] = useState(''); + const [newStepId, setNewStepId] = useState(''); + const [busy, setBusy] = useState(false), [error, setError] = useState(''), [message, setMessage] = useState(''); + const [checks, setChecks] = useState(initial.checks); + const working = useRef(false); + const dirty = JSON.stringify(data.workflows) !== saved.current; + useNavigationGuard(dirty, busy); + const flow = data.workflows.find(f => f.id === selectedId); + const displaySources = [...data.sources, ...(data.excludedSources ?? []).map(s => ({ ...s, name: `${s.name} (Slave – parallel)` }))]; + const label = (id: string) => { const s = displaySources.find(s => s.id === id); return s ? `${s.antriebId} · ${s.name}` : `Fehlendes Aggregat (${id})`; }; + const unassigned = flow?.materialFlow.filter(id => data.sources.some(s => s.id === id) && !flow.steps.some(s => s.aggregateIds.includes(id))) ?? []; + const updateFlows = (workflows: Ablauf[]) => { setData(old => ({ ...old, workflows })); setChecks(null); setError(''); setMessage(''); }; + const edit = (change: (f: Ablauf) => Ablauf) => { if (!busy && flow) updateFlows(data.workflows.map(f => f.id === flow.id ? change(f) : f)); }; + const editStep = (id: string, change: (s: AblaufStep) => AblaufStep) => edit(f => ({ ...f, steps: f.steps.map(s => s.id === id ? change(s) : s) })); + function add(copy = false, box = false) { + const id = crypto.randomUUID(); + const next: Ablauf = copy && flow ? { ...structuredClone(flow), id, name: uniqueName(`${flow.name} Kopie`, data.workflows), + steps: flow.steps.map(s => ({ ...structuredClone(s), id: crypto.randomUUID() })) } + : { id, name: uniqueName(box ? 'Boxenbeschickung' : 'Neuer Ablauf', data.workflows), description: '', materialFlow: [], steps: [], ...(box ? { kind: 'box' as const, boxPlan: newBoxPlan() } : {}) }; + updateFlows([...data.workflows, next]); setSelectedId(id); setAggregateId(''); setNewStepId(''); setFilter(''); + } + async function run(save: boolean) { + if (working.current) return; working.current = true; setBusy(true); setError(''); setMessage(''); + try { + if (save) { + const result = await api_saveAblaeufe(data); + saved.current = JSON.stringify(result.workflows); setData(old => ({ ...old, ...result })); setChecks(result.checks); + setMessage('Alle Abläufe dieser Anlage gespeichert.'); + } else { + const result = await api_checkAblaeufe(data); setData(old => ({ ...old, sources: result.sources, excludedSources: result.excludedSources, catalog: result.catalog })); setChecks(result.checks); setMessage('Alle Abläufe geprüft.'); + } + } catch (cause) { setError(cause instanceof Error ? cause.message : 'Abläufe konnten nicht verarbeitet werden.'); } + finally { working.current = false; setBusy(false); } + } + function removeAggregate(id: string) { + edit(f => ({ ...f, materialFlow: f.materialFlow.filter(ref => ref !== id), + steps: f.steps.map(s => withMembers(s, s.aggregateIds.filter(ref => ref !== id))).filter(s => s.aggregateIds.length) })); + } + function transfer(ref: string, target: string) { + edit(f => { + const current = f.steps.find(s => s.aggregateIds.includes(ref)); + if (current?.id === target) return f; + return { ...f, steps: f.steps.map(s => s.id === target ? { ...s, aggregateIds: [...s.aggregateIds, ref], directions: { ...s.directions, [ref]: current?.directions?.[ref] ?? 'forward' } } + : withMembers(s, s.aggregateIds.filter(id => id !== ref))).filter(s => s.aggregateIds.length) }; + }); + } + function graphMode() { + if (!flow) return; + const ids = [...new Set(flow.materialFlow.map(ref => data.sources.find(s => s.id === ref)?.unitId))]; + if (ids.some(id => !id)) { setError('Ein Aggregat hat keine gültige Unit-Zuordnung. Zuerst die Unit-Komponenten prüfen.'); return; } + const unitIds = ids as string[]; + edit(f => ({ ...f, graph: { nodes: unitIds.map(unitId => ({ unitId, storageUse: 'fill' })), edges: unitIds.slice(0, -1).map((from, i) => ({ id: crypto.randomUUID(), from, to: unitIds[i + 1], label: '', active: true, + outletId: data.catalog?.units.find(u => u.id === from)?.settings.outlets.length === 1 ? data.catalog.units.find(u => u.id === from)!.settings.outlets[0].id : null })) } })); + } + const warnings = checks?.find(c => c.id === selectedId)?.warnings; + return
+

Abläufe und Materialfluss

{data.anlageName} · Planung und Dokumentation der Einschaltfolgen. Es werden keine Aggregate geschaltet.

+
+ + + + + {dirty ? 'Ungespeicherte Änderungen' : 'Gespeicherter Stand'} +
+ {error &&

{error}

} + {message &&

{message}

} + {!data.sources.length &&

In dieser Anlage sind noch keine gespeicherten Aggregate vorhanden. Unter VisuAggregate anlegen oder das Projekt aus ProCon importieren.

} +
+ + {flow &&
+
Ablauf + +