From 29fc6836752f37518cbb479a0f3096c5aa19d41c Mon Sep 17 00:00:00 2001 From: bigserver Date: Thu, 9 Apr 2026 08:31:52 +0200 Subject: [PATCH] =?UTF-8?q?Ger=C3=A4t-zu-Ger=C3=A4t-Verbindungs-SVG=20im?= =?UTF-8?q?=20Dashboard=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #29 --- app/modules/dashboard/list.php | 145 ++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-) diff --git a/app/modules/dashboard/list.php b/app/modules/dashboard/list.php index ab38b81..24ece00 100644 --- a/app/modules/dashboard/list.php +++ b/app/modules/dashboard/list.php @@ -245,6 +245,106 @@ foreach ($rackLinksByKey as $entry) { 'sample_connection_id' => (int)($entry['sample_connection_id'] ?? 0), ]; } + +$deviceIdByDevicePort = []; +foreach ($sql->get( + "SELECT id, device_id + FROM device_ports", + "", + [] +) as $row) { + $portId = (int)($row['id'] ?? 0); + $deviceId = (int)($row['device_id'] ?? 0); + if ($portId <= 0 || $deviceId <= 0) { + continue; + } + $deviceIdByDevicePort[$portId] = $deviceId; +} + +$deviceIdByModulePort = []; +foreach ($sql->get( + "SELECT mp.id AS port_id, MIN(dp.device_id) AS device_id + FROM module_ports mp + JOIN modules m ON m.id = mp.module_id + JOIN device_port_modules dpm ON dpm.module_id = m.id + JOIN device_ports dp ON dp.id = dpm.device_port_id + GROUP BY mp.id", + "", + [] +) as $row) { + $portId = (int)($row['port_id'] ?? 0); + $deviceId = (int)($row['device_id'] ?? 0); + if ($portId <= 0 || $deviceId <= 0) { + continue; + } + $deviceIdByModulePort[$portId] = $deviceId; +} + +$resolveDeviceId = static function (string $endpointType, int $endpointId) use ($deviceIdByDevicePort, $deviceIdByModulePort): int { + if ($endpointId <= 0) { + return 0; + } + + $type = strtolower(trim($endpointType)); + if ($type === 'device' || $type === 'device_ports') { + return (int)($deviceIdByDevicePort[$endpointId] ?? 0); + } + if ($type === 'module' || $type === 'module_ports') { + return (int)($deviceIdByModulePort[$endpointId] ?? 0); + } + + return 0; +}; + +$deviceLinksByKey = []; +foreach ($sql->get( + "SELECT id, port_a_type, port_a_id, port_b_type, port_b_id + FROM connections", + "", + [] +) as $row) { + $deviceA = $resolveDeviceId((string)($row['port_a_type'] ?? ''), (int)($row['port_a_id'] ?? 0)); + $deviceB = $resolveDeviceId((string)($row['port_b_type'] ?? ''), (int)($row['port_b_id'] ?? 0)); + if ($deviceA <= 0 || $deviceB <= 0 || $deviceA === $deviceB) { + continue; + } + + $from = min($deviceA, $deviceB); + $to = max($deviceA, $deviceB); + $key = $from . ':' . $to; + if (!isset($deviceLinksByKey[$key])) { + $deviceLinksByKey[$key] = [ + 'from_device_id' => $from, + 'to_device_id' => $to, + 'count' => 0, + 'sample_connection_id' => (int)($row['id'] ?? 0) + ]; + } + $deviceLinksByKey[$key]['count']++; +} + +$deviceNameById = []; +foreach ($topologyPayload as $entry) { + $deviceId = (int)($entry['device_id'] ?? 0); + if ($deviceId <= 0 || isset($deviceNameById[$deviceId])) { + continue; + } + $deviceNameById[$deviceId] = (string)($entry['device_name'] ?? ('Gerät #' . $deviceId)); +} + +$deviceLinkPayload = []; +foreach ($deviceLinksByKey as $entry) { + $fromId = (int)($entry['from_device_id'] ?? 0); + $toId = (int)($entry['to_device_id'] ?? 0); + $deviceLinkPayload[] = [ + 'from_device_id' => $fromId, + 'to_device_id' => $toId, + 'count' => (int)($entry['count'] ?? 0), + 'from_device_name' => (string)($deviceNameById[$fromId] ?? ('Gerät #' . $fromId)), + 'to_device_name' => (string)($deviceNameById[$toId] ?? ('Gerät #' . $toId)), + 'sample_connection_id' => (int)($entry['sample_connection_id'] ?? 0), + ]; +} ?>
@@ -343,6 +443,7 @@ foreach ($rackLinksByKey as $entry) { +