imrpove network map
Deploy / deploy (push) Successful in 38s

This commit is contained in:
2026-05-07 18:35:08 +02:00
parent d96606c9a4
commit 07fd48425f
2 changed files with 72 additions and 1 deletions
+57 -1
View File
@@ -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;
}
}
+15
View File
@@ -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'),