Direktverbindung fuer unverbundene Ports zum Patchfeld anbieten

closes #25
This commit is contained in:
2026-02-19 11:09:36 +01:00
parent dbe977f62c
commit 96f885efde
3 changed files with 41 additions and 2 deletions

View File

@@ -79,6 +79,26 @@ foreach ($sql->get(
}
$devicePortPreviewByDevice = [];
$connectedDevicePorts = [];
foreach ($sql->get(
"SELECT port_a_type, port_a_id, port_b_type, port_b_id
FROM connections",
"",
[]
) as $row) {
$portAType = strtolower(trim((string)($row['port_a_type'] ?? '')));
$portBType = strtolower(trim((string)($row['port_b_type'] ?? '')));
$portAId = (int)($row['port_a_id'] ?? 0);
$portBId = (int)($row['port_b_id'] ?? 0);
if (($portAType === 'device' || $portAType === 'device_ports') && $portAId > 0) {
$connectedDevicePorts[$portAId] = true;
}
if (($portBType === 'device' || $portBType === 'device_ports') && $portBId > 0) {
$connectedDevicePorts[$portBId] = true;
}
}
foreach ($sql->get(
"SELECT id, device_id, name
FROM device_ports
@@ -98,7 +118,8 @@ foreach ($sql->get(
}
$devicePortPreviewByDevice[$deviceId][] = [
'id' => (int)($row['id'] ?? 0),
'name' => (string)($row['name'] ?? '')
'name' => (string)($row['name'] ?? ''),
'is_connected' => isset($connectedDevicePorts[(int)($row['id'] ?? 0)]),
];
}
@@ -658,7 +679,11 @@ foreach ($rackLinksByKey as $entry) {
overlayMeta.textContent = `Geraet: ${item.device_name} | Rack: ${item.rack_name} | Stockwerk: ${item.floor_name}`;
if (item.device_id > 0) {
overlayRackLink.innerHTML = `<a href="?module=devices&action=edit&id=${item.device_id}">Geraet bearbeiten</a>`;
overlayDeviceLink.innerHTML = `<a href="?module=connections&action=edit">Verbindung fuer Port erstellen</a>`;
if (item.port_id > 0 && !item.is_connected) {
overlayDeviceLink.innerHTML = `<a href="?module=connections&action=edit&port_a_type=device&port_a_id=${item.port_id}&port_b_type=patchpanel">Mit Patchfeld verbinden</a>`;
} else {
overlayDeviceLink.textContent = 'Port ist bereits verbunden';
}
}
if (item.port_id > 0) {
overlayActions.innerHTML = `<a class="button button-small" href="?module=devices&action=edit&id=${item.device_id}">Port im Geraet aendern</a>`;
@@ -853,6 +878,7 @@ foreach ($rackLinksByKey as $entry) {
kind: 'port',
port_id: Number(port.id || 0),
port_name: port.name || `Port ${portIndex + 1}`,
is_connected: !!port.is_connected,
device_id: entry.device_id,
device_name: entry.device_name,
rack_name: entry.rack_name,