This commit is contained in:
2026-03-31 10:22:22 +02:00
parent dec5a0bcce
commit f95563b233
3 changed files with 519 additions and 8 deletions

View File

@@ -37,7 +37,7 @@ $buildings = $sql->get(
);
$floors = $sql->get(
"SELECT f.id, f.building_id, f.name, f.level,
"SELECT f.id, f.building_id, f.name, f.level, f.svg_path,
COUNT(r.id) AS room_count
FROM floors f
LEFT JOIN rooms r ON r.floor_id = f.id
@@ -47,8 +47,15 @@ $floors = $sql->get(
[]
);
foreach ($floors as &$floor) {
$rawPath = trim((string)($floor['svg_path'] ?? ''));
$floor['svg_url'] = $rawPath !== '' ? '/' . ltrim($rawPath, '/\\') : '';
}
unset($floor);
$rooms = $sql->get(
"SELECT r.id, r.floor_id, r.name, r.number, r.comment,
r.x, r.y, r.width, r.height, r.polygon_points,
COUNT(no.id) AS outlet_count
FROM rooms r
LEFT JOIN network_outlets no ON no.room_id = r.id
@@ -193,11 +200,59 @@ foreach ($rooms as $room) {
<?php endif; ?>
<span class="hierarchy-meta"> | <?php echo (int)$floor['room_count']; ?> Raeume</span>
</td>
<td class="actions hierarchy-actions">
<a href="?module=floors&action=edit&id=<?php echo (int)$floor['id']; ?>" class="button button-small">Bearbeiten</a>
<button type="button" class="button button-small button-danger js-delete-floor" data-floor-id="<?php echo (int)$floor['id']; ?>">Loeschen</button>
<a href="?module=rooms&action=edit&floor_id=<?php echo (int)$floor['id']; ?>" class="button button-small">+ Raum</a>
</td>
<?php
$roomPreviewData = [];
foreach ($floorRooms as $room) {
$rawPolygon = trim((string)($room['polygon_points'] ?? ''));
$polygonPoints = [];
if ($rawPolygon !== '') {
$decodedPoints = json_decode($rawPolygon, true);
if (is_array($decodedPoints)) {
foreach ($decodedPoints as $point) {
$x = $point['x'] ?? null;
$y = $point['y'] ?? null;
if (is_numeric($x) && is_numeric($y)) {
$polygonPoints[] = [
'x' => (float)$x,
'y' => (float)$y,
];
}
}
}
}
$roomPreviewData[] = [
'id' => (int)$room['id'],
'number' => (string)($room['number'] ?? ''),
'name' => (string)($room['name'] ?? ''),
'polygon' => $polygonPoints,
'bounds' => [
'x' => isset($room['x']) ? (float)$room['x'] : null,
'y' => isset($room['y']) ? (float)$room['y'] : null,
'width' => isset($room['width']) ? (float)$room['width'] : null,
'height' => isset($room['height']) ? (float)$room['height'] : null,
],
];
}
$roomPreviewPayload = json_encode($roomPreviewData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$roomPreviewPayload = ($roomPreviewPayload === false) ? '[]' : $roomPreviewPayload;
$roomPreviewPayload = htmlspecialchars($roomPreviewPayload, ENT_QUOTES, 'UTF-8');
$hasRoomsForPreview = !empty($roomPreviewData);
?>
<td class="actions hierarchy-actions">
<button type="button"
class="button button-small button-secondary js-preview-floor"
data-floor-id="<?php echo (int)$floor['id']; ?>"
data-floor-name="<?php echo htmlspecialchars((string)$floor['name']); ?>"
data-floor-rooms="<?php echo $roomPreviewPayload; ?>"
data-floor-svg="<?php echo htmlspecialchars((string)($floor['svg_url'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>"
<?php if (!$hasRoomsForPreview): ?>disabled title="Keine Raeume vorhanden"<?php endif; ?>>
Stockwerk als PNG
</button>
<a href="?module=floors&action=edit&id=<?php echo (int)$floor['id']; ?>" class="button button-small">Bearbeiten</a>
<button type="button" class="button button-small button-danger js-delete-floor" data-floor-id="<?php echo (int)$floor['id']; ?>">Loeschen</button>
<a href="?module=rooms&action=edit&floor_id=<?php echo (int)$floor['id']; ?>" class="button button-small">+ Raum</a>
</td>
</tr>
<?php if (!empty($floorRooms)): ?>
@@ -247,7 +302,26 @@ foreach ($rooms as $room) {
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<?php else: ?>
<p>Keine Standorte gefunden.</p>
<?php endif; ?>
</section>
<div class="floor-preview-overlay" data-floor-preview-overlay aria-hidden="true">
<div class="floor-preview-card">
<div class="floor-preview-header">
<div>
<p class="floor-preview-label">Stockwerk-Vorschau</p>
<h3 data-floor-preview-title>Stockwerk</h3>
</div>
<button type="button" class="button button-small floor-preview-close" data-floor-preview-close>Schließen</button>
</div>
<div class="floor-preview-body">
<canvas data-floor-preview-canvas width="900" height="600" aria-label="Stockwerk mit Raeumen"></canvas>
<p class="floor-preview-empty" data-floor-preview-message hidden>Keine Raeume vorhanden.</p>
</div>
<div class="floor-preview-footer">
<button type="button" class="button js-floor-preview-download" disabled>Als PNG speichern</button>
</div>
</div>
</div>