feat: complete package 2 delete flows and package 3 port management
This commit is contained in:
@@ -64,6 +64,19 @@ if ($isEdit) {
|
||||
// =========================
|
||||
$deviceTypes = $sql->get("SELECT id, name, category FROM device_types ORDER BY name", "", []);
|
||||
$racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);
|
||||
$devicePorts = [];
|
||||
|
||||
if ($isEdit) {
|
||||
$devicePorts = $sql->get(
|
||||
"SELECT dp.id, dp.name, dp.status, dp.mode, dp.vlan_config, pt.name AS port_type_name
|
||||
FROM device_ports dp
|
||||
LEFT JOIN port_types pt ON pt.id = dp.port_type_id
|
||||
WHERE dp.device_id = ?
|
||||
ORDER BY dp.id",
|
||||
"i",
|
||||
[$deviceId]
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -160,6 +173,67 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend>Ports</legend>
|
||||
<?php if ($isEdit): ?>
|
||||
<?php if (!empty($devicePorts)): ?>
|
||||
<p><small>Portstatus und VLAN-Zuordnung koennen hier direkt gepflegt werden (VLANs kommagetrennt, z. B. 10,20,30).</small></p>
|
||||
<table class="device-port-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Port-Typ</th>
|
||||
<th>Status</th>
|
||||
<th>Modus</th>
|
||||
<th>VLANs</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($devicePorts as $port): ?>
|
||||
<?php
|
||||
$vlanValue = '';
|
||||
if (!empty($port['vlan_config'])) {
|
||||
$decodedVlans = json_decode((string)$port['vlan_config'], true);
|
||||
if (is_array($decodedVlans)) {
|
||||
$vlanValue = implode(', ', array_map('strval', $decodedVlans));
|
||||
} else {
|
||||
$vlanValue = (string)$port['vlan_config'];
|
||||
}
|
||||
}
|
||||
$statusValue = (string)($port['status'] ?? 'active');
|
||||
if (!in_array($statusValue, ['active', 'disabled'], true)) {
|
||||
$statusValue = 'active';
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" name="device_ports[<?php echo (int)$port['id']; ?>][name]" value="<?php echo htmlspecialchars((string)$port['name']); ?>">
|
||||
</td>
|
||||
<td><?php echo htmlspecialchars((string)($port['port_type_name'] ?? '-')); ?></td>
|
||||
<td>
|
||||
<select name="device_ports[<?php echo (int)$port['id']; ?>][status]">
|
||||
<option value="active" <?php echo $statusValue === 'active' ? 'selected' : ''; ?>>aktiv</option>
|
||||
<option value="disabled" <?php echo $statusValue === 'disabled' ? 'selected' : ''; ?>>inaktiv</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="device_ports[<?php echo (int)$port['id']; ?>][mode]" value="<?php echo htmlspecialchars((string)($port['mode'] ?? '')); ?>" placeholder="z. B. access/trunk">
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="device_ports[<?php echo (int)$port['id']; ?>][vlan_config]" value="<?php echo htmlspecialchars($vlanValue); ?>" placeholder="10,20,30">
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php else: ?>
|
||||
<p><small>Zu diesem Geraet sind aktuell keine Ports vorhanden.</small></p>
|
||||
<?php endif; ?>
|
||||
<?php else: ?>
|
||||
<p><small>Ports werden nach dem ersten Speichern automatisch aus dem Geraetetyp erzeugt und koennen dann hier gepflegt werden.</small></p>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
|
||||
<!-- =========================
|
||||
Aktionen
|
||||
========================= -->
|
||||
@@ -264,34 +338,64 @@ $racks = $sql->get("SELECT id, name FROM racks ORDER BY name", "", []);
|
||||
.button:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.device-port-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.device-port-table th,
|
||||
.device-port-table td {
|
||||
border-bottom: 1px solid #ddd;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.device-port-table input,
|
||||
.device-port-table select {
|
||||
width: 100%;
|
||||
min-width: 120px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
function confirmDelete(link, id, connectionCount, portCount, moduleCount) {
|
||||
if (confirm('Dieses Gerät wirklich löschen?')) {
|
||||
const hasDependencies = (connectionCount > 0) || (portCount > 0) || (moduleCount > 0);
|
||||
if (hasDependencies) {
|
||||
const details = [];
|
||||
if (connectionCount > 0) {
|
||||
details.push(connectionCount + ' Verbindungen');
|
||||
}
|
||||
if (portCount > 0) {
|
||||
details.push(portCount + ' Ports');
|
||||
}
|
||||
if (moduleCount > 0) {
|
||||
details.push(moduleCount + ' Port-Module');
|
||||
}
|
||||
const dependencyMessage = 'Es gibt abhängige Daten (' + details.join(', ') + '). Diese auch löschen?';
|
||||
if (!confirm(dependencyMessage)) {
|
||||
return false;
|
||||
}
|
||||
window.location.href = (link && link.href ? link.href : ('?module=devices&action=delete&id=' + encodeURIComponent(id))) + '&force=1';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
if (!confirm('Dieses Geraet wirklich loeschen?')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const requestDelete = (forceDelete) => {
|
||||
const body = ['id=' + encodeURIComponent(id)];
|
||||
if (forceDelete) {
|
||||
body.push('force=1');
|
||||
}
|
||||
|
||||
fetch('?module=devices&action=delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
|
||||
body: body.join('&')
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data && data.success) {
|
||||
window.location.href = '?module=devices&action=list';
|
||||
return;
|
||||
}
|
||||
|
||||
if (data && data.requires_force) {
|
||||
if (confirm(data.message || 'Es gibt abhaengige Daten. Trotzdem loeschen?')) {
|
||||
requestDelete(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
alert((data && data.message) ? data.message : 'Loeschen fehlgeschlagen');
|
||||
})
|
||||
.catch(() => alert('Loeschen fehlgeschlagen'));
|
||||
};
|
||||
|
||||
requestDelete(false);
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user