diff --git a/examples/ServerManager/UI/ServerListTab.php b/examples/ServerManager/UI/ServerListTab.php index 10417fa..545bbc8 100644 --- a/examples/ServerManager/UI/ServerListTab.php +++ b/examples/ServerManager/UI/ServerListTab.php @@ -87,8 +87,18 @@ class ServerListTab ['key' => 'type', 'title' => 'Typ', 'width' => 80], ['key' => 'ipv4', 'title' => 'IPv4', 'width' => 160], ['key' => 'docker_status', 'title' => 'Docker', 'width' => 90], - ['key' => 'needs_reboot', 'title' => 'Neustart', 'width' => 90], - ['key' => 'updates_available', 'title' => 'Updates', 'width' => 130], + [ + 'key' => 'needs_reboot', + 'title' => 'Neustart', + 'width' => 150, + 'render' => [$this, 'renderNeedsRebootCell'], + ], + [ + 'key' => 'updates_available', + 'title' => 'Updates', + 'width' => 150, + 'render' => [$this, 'renderUpdatesCell'], + ], ]); // Load initial test data @@ -277,19 +287,13 @@ class ServerListTab echo "Error: {$result['error']}\n"; } elseif (isset($result['success'], $result['servers'])) { // Basisdaten setzen, Docker-Status initial auf "pending" - $serverListTab->currentServerData = array_map( - static fn($row) => array_merge( - [ - 'docker_status' => 'pending', - 'docker' => null, - 'docker_error' => null, - 'needs_reboot' => 'unbekannt', - 'updates_available' => 'unbekannt', - ], - $row, - ), - $result['servers'], - ); + $serverListTab->currentServerData = array_map(static fn($row) => array_merge([ + 'docker_status' => 'pending', + 'docker' => null, + 'docker_error' => null, + 'needs_reboot' => 'unbekannt', + 'updates_available' => 'unbekannt', + ], $row), $result['servers']); $serverListTab->table->setData($serverListTab->currentServerData); $serverListTab->statusLabel->setText('Server geladen: ' . $result['count'] . ' gefunden'); @@ -299,8 +303,7 @@ class ServerListTab $ip = $row['ipv4'] ?? ''; if (empty($ip) || empty($currentPrivateKeyPath) || !file_exists($currentPrivateKeyPath)) { - $serverListTab->currentServerData[$index]['docker_error'] = - 'Kein gültiger Private-Key oder IP'; + $serverListTab->currentServerData[$index]['docker_error'] = 'Kein gültiger Private-Key oder IP'; $serverListTab->currentServerData[$index]['docker_status'] = 'error'; continue; } @@ -329,13 +332,13 @@ class ServerListTab $rebootOutput = trim($ssh->exec( '[ -f /var/run/reboot-required ] && echo yes || echo no', )); - $needsReboot = ($rebootOutput === 'yes'); + $needsReboot = $rebootOutput === 'yes'; // Check number of available package updates (Ubuntu) $updatesOutput = trim($ssh->exec( 'apt-get -s upgrade 2>/dev/null | grep -c "^Inst " || echo 0', )); - $updatesCount = is_numeric($updatesOutput) ? (int) $updatesOutput : 0; + $updatesCount = is_numeric($updatesOutput) ? ((int) $updatesOutput) : 0; // Docker status for main application container $output = $ssh->exec('docker inspect psc-web-1'); @@ -421,15 +424,17 @@ class ServerListTab if ($needsReboot === null) { $serverListTab->currentServerData[$i]['needs_reboot'] = 'unbekannt'; } else { - $serverListTab->currentServerData[$i]['needs_reboot'] = - $needsReboot ? 'ja' : 'nein'; + $serverListTab->currentServerData[$i]['needs_reboot'] = $needsReboot + ? 'ja' + : 'nein'; } } if (array_key_exists('updates', $dockerResult)) { $updates = (int) ($dockerResult['updates'] ?? 0); - $serverListTab->currentServerData[$i]['updates_available'] = - $updates > 0 ? ('ja (' . $updates . ')') : 'nein'; + $serverListTab->currentServerData[$i]['updates_available'] = $updates > 0 + ? ('ja (' . $updates . ')') + : 'nein'; } if (array_key_exists('docker_error', $dockerResult)) { @@ -481,6 +486,42 @@ class ServerListTab return $this->sftpButton; } + public function renderNeedsRebootCell(array $rowData, int $rowIndex): Label + { + $value = (string) ($rowData['needs_reboot'] ?? ''); + $normalized = strtolower(trim($value)); + + $baseStyle = 'px-4 py-2 border-r border-gray-300 text-sm '; + + if ($normalized === 'nein') { + $style = $baseStyle . 'text-green-600'; + } elseif ($normalized === 'ja') { + $style = $baseStyle . 'text-red-600'; + } else { + $style = $baseStyle . 'text-gray-600'; + } + + return new Label($value, $style); + } + + public function renderUpdatesCell(array $rowData, int $rowIndex): Label + { + $value = (string) ($rowData['updates_available'] ?? ''); + $normalized = strtolower(trim($value)); + + $baseStyle = 'px-4 py-2 border-r border-gray-300 text-sm '; + + if ($normalized === 'nein' || $normalized === 'nein (0)') { + $style = $baseStyle . 'text-green-600'; + } elseif (str_starts_with($normalized, 'ja')) { + $style = $baseStyle . 'text-red-600'; + } else { + $style = $baseStyle . 'text-gray-600'; + } + + return new Label($value, $style); + } + private function updateDomainDetails(array $domains): void { $this->detailDomainsContainer->clearChildren();