From 07fd48425f610cc32018825036b672fd18fed83b Mon Sep 17 00:00:00 2001 From: janis steiner Date: Thu, 7 May 2026 18:35:08 +0200 Subject: [PATCH] imrpove network map --- backend/api/index.php | 58 ++++++++++++++++++++++++++++++++++++++++++- docker/init.sql | 15 +++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/backend/api/index.php b/backend/api/index.php index 8161c0d..9137913 100644 --- a/backend/api/index.php +++ b/backend/api/index.php @@ -39,6 +39,9 @@ try { case 'links': handleLinks($method, $id, $db); break; + case 'shapes': + handleShapes($method, $id, $db); + break; default: http_response_code(404); echo json_encode(['error' => 'Not found']); @@ -207,7 +210,7 @@ function handleLinks($method, $id, $db) { switch ($method) { case 'GET': echo json_encode($db->query(" - SELECT l.*, s.label AS source_label, t.label AS target_label + SELECT l.*, s.label AS source_label, s.node_type AS source_type, t.label AS target_label, t.node_type AS target_type FROM network_links l JOIN network_nodes s ON l.source_id = s.id JOIN network_nodes t ON l.target_id = t.id @@ -234,4 +237,57 @@ function handleLinks($method, $id, $db) { } break; } +} + +function handleShapes($method, $id, $db) { + switch ($method) { + case 'GET': + echo json_encode($db->query("SELECT * FROM network_shapes ORDER BY z_index ASC")->fetchAll(PDO::FETCH_ASSOC)); + break; + case 'POST': + $data = json_decode(file_get_contents('php://input'), true); + $stmt = $db->prepare(" + INSERT INTO network_shapes (label, shape_type, pos_x, pos_y, width, height, color, border_color, opacity, z_index) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + "); + $stmt->execute([ + $data['label'] ?? '', + $data['shape_type'] ?? 'rectangle', + $data['pos_x'] ?? 0, + $data['pos_y'] ?? 0, + $data['width'] ?? 200, + $data['height'] ?? 150, + $data['color'] ?? '#1e3a5f', + $data['border_color'] ?? '#3b82f6', + $data['opacity'] ?? 0.15, + $data['z_index'] ?? 0 + ]); + echo json_encode(['id' => $db->lastInsertId()]); + break; + case 'PUT': + if ($id) { + $data = json_decode(file_get_contents('php://input'), true); + $fields = []; + $params = []; + foreach (['label','shape_type','pos_x','pos_y','width','height','color','border_color','opacity','z_index'] as $f) { + if (isset($data[$f])) { + $fields[] = "$f = ?"; + $params[] = $data[$f]; + } + } + if ($fields) { + $params[] = $id; + $stmt = $db->prepare("UPDATE network_shapes SET " . implode(', ', $fields) . " WHERE id = ?"); + $stmt->execute($params); + } + echo json_encode(['updated' => true]); + } + break; + case 'DELETE': + if ($id) { + $db->prepare("DELETE FROM network_shapes WHERE id = ?")->execute([$id]); + echo json_encode(['deleted' => true]); + } + break; + } } \ No newline at end of file diff --git a/docker/init.sql b/docker/init.sql index 8ed4bfd..e02c25b 100644 --- a/docker/init.sql +++ b/docker/init.sql @@ -49,6 +49,21 @@ CREATE TABLE IF NOT EXISTS network_links ( FOREIGN KEY (target_id) REFERENCES network_nodes(id) ON DELETE CASCADE ); +CREATE TABLE IF NOT EXISTS network_shapes ( + id INT AUTO_INCREMENT PRIMARY KEY, + label VARCHAR(255) NOT NULL DEFAULT '', + shape_type ENUM('rectangle','ellipse','zone') DEFAULT 'rectangle', + pos_x FLOAT DEFAULT 0, + pos_y FLOAT DEFAULT 0, + width FLOAT DEFAULT 200, + height FLOAT DEFAULT 150, + color VARCHAR(7) DEFAULT '#1e3a5f', + border_color VARCHAR(7) DEFAULT '#3b82f6', + opacity FLOAT DEFAULT 0.15, + z_index INT DEFAULT 0, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + INSERT IGNORE INTO teams (name, color) VALUES ('Blue Team', '#0d6efd'), ('Red Team', '#dc3545'),