Implement pagination for task history in Proxmox statistics view
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
|
||||
Reference in New Issue
Block a user