diff --git a/extensions/Servers/Proxmox/Livewire/Statistics.php b/extensions/Servers/Proxmox/Livewire/Statistics.php index 104cebe7b..92b76e30c 100644 --- a/extensions/Servers/Proxmox/Livewire/Statistics.php +++ b/extensions/Servers/Proxmox/Livewire/Statistics.php @@ -8,6 +8,7 @@ use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Livewire\Attributes\On; +use Livewire\WithPagination; use Paymenter\Extensions\Servers\Proxmox\Models\Server; use Paymenter\Extensions\Servers\Proxmox\Models\ServerStatistics; use Paymenter\Extensions\Servers\Proxmox\Proxmox; @@ -15,6 +16,8 @@ use Paymenter\Extensions\Servers\Proxmox\Services\CoreRouterClient; class Statistics extends Component { + use WithPagination; + public Server $server; public $selectedStatisticId = null; public $statisticToDeleteId = null; @@ -58,7 +61,6 @@ class Statistics extends Component // Statistics History Pagination public int $statisticsPerPage = 25; - public int $statisticsCurrentPage = 1; // Task History Pagination public int $taskHistoryPerPage = 25; @@ -635,65 +637,13 @@ class Statistics extends Component // ========================================== /** - * Get all statistics for pagination (raw data) - */ - public function getAllStatisticsProperty(): \Illuminate\Database\Eloquent\Collection - { - return ServerStatistics::where('server_id', $this->server->id) - ->orderBy('DateTime', 'desc') - ->get(); - } - - /** - * Get paginated statistics for display - */ - public function getPaginatedStatisticsProperty(): array - { - $statistics = $this->allStatistics; - $offset = ($this->statisticsCurrentPage - 1) * $this->statisticsPerPage; - - return $statistics->slice($offset, $this->statisticsPerPage)->values()->all(); - } - - /** - * Get total pages for statistics - */ - public function getStatisticsTotalPagesProperty(): int - { - $total = $this->allStatistics->count(); - return max(1, (int) ceil($total / $this->statisticsPerPage)); - } - - /** - * Reset page to 1 when perPage changes for statistics + * Reset to page 1 when perPage changes for statistics + * (Laravel paginator will automatically handle this with the paginate() method) */ public function updatedStatisticsPerPage(): void { - $this->statisticsCurrentPage = 1; - } - - /** - * Navigate to a specific page for statistics - */ - public function goToStatisticsPage(int $page): void - { - $this->statisticsCurrentPage = max(1, min($page, $this->statisticsTotalPages)); - } - - /** - * Navigate to previous page for statistics - */ - public function previousStatisticsPage(): void - { - $this->goToStatisticsPage($this->statisticsCurrentPage - 1); - } - - /** - * Navigate to next page for statistics - */ - public function nextStatisticsPage(): void - { - $this->goToStatisticsPage($this->statisticsCurrentPage + 1); + // Reset to page 1 when changing per-page (handled by Livewire automatically) + $this->resetPage(); } // ========================================== diff --git a/extensions/Servers/Proxmox/views/statistics.blade.php b/extensions/Servers/Proxmox/views/statistics.blade.php index 7cd07ccdc..133d17436 100644 --- a/extensions/Servers/Proxmox/views/statistics.blade.php +++ b/extensions/Servers/Proxmox/views/statistics.blade.php @@ -1062,7 +1062,7 @@ - @forelse($this->taskHistory as $task) + @forelse($this->paginatedTaskHistory as $task) @php $startTime = isset($task['starttime']) ? \Carbon\Carbon::createFromTimestamp($task['starttime']) : null; $endTime = isset($task['endtime']) && $task['endtime'] > 0 ? \Carbon\Carbon::createFromTimestamp($task['endtime']) : null; @@ -1321,6 +1321,88 @@ + +
+
+ +
+ Show + + entries + ({{ count($this->taskHistory) }} total) +
+ + + @if($this->taskHistoryTotalPages > 1) +
+ + + + + @php + $totalPages = $this->taskHistoryTotalPages; + $currentPage = $taskHistoryCurrentPage; + $pages = []; + + // Always show first page + $pages[] = 1; + + // Calculate range around current page + $start = max(2, $currentPage - 1); + $end = min($totalPages - 1, $currentPage + 1); + + // Add ellipsis after first page if needed + if ($start > 2) { + $pages[] = '...'; + } + + // Add pages around current + for ($i = $start; $i <= $end; $i++) { + $pages[] = $i; + } + + // Add ellipsis before last page if needed + if ($end < $totalPages - 1) { + $pages[] = '...'; + } + + // Always show last page if more than 1 page + if ($totalPages > 1) { + $pages[] = $totalPages; + } + @endphp + + @foreach($pages as $page) + @if($page === '...') + ... + @else + + @endif + @endforeach + + + +
+ @endif +
+