Advertisement
svenvg93

Latency.php

Aug 26th, 2024
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | Source Code | 0 0
  1. <?php
  2.  
  3. namespace App\Filament\Pages;
  4.  
  5. use App\Models\PingResult;
  6. use App\Filament\Widgets\LatencyChartWidgetForUrl;
  7. use Filament\Pages\Page;
  8.  
  9. class Latency extends Page
  10. {
  11.     protected static ?string $navigationIcon = 'heroicon-o-chart-bar';
  12.  
  13.     protected static string $view = 'filament.pages.ping-results-page';
  14.  
  15.     public function getData()
  16.     {
  17.         // Retrieve distinct URLs
  18.         $urls = PingResult::distinct()->pluck('url');
  19.         \Log::info("Retrieved URLs: ", $urls->toArray());
  20.  
  21.         return [
  22.             'urls' => $urls,
  23.             'filters' => $this->getFilters(),
  24.         ];
  25.     }
  26.  
  27.     protected function getFilters(): array
  28.     {
  29.         return [
  30.             '24h' => 'Last 24h',
  31.             'week' => 'Last week',
  32.             'month' => 'Last month',
  33.         ];
  34.     }
  35.  
  36.     protected function getHeaderWidgets(): array
  37.     {
  38.         $urls = $this->getData()['urls'];
  39.  
  40.         \Log::info("Creating widgets for URLs: ", $urls->toArray());
  41.  
  42.         $widgets = [];
  43.         foreach ($urls as $url) {
  44.             $widget = LatencyChartWidgetForUrl::make(); // Create widget instance
  45.             $widget->url = $url; // Directly set URL property
  46.             \Log::info("Assigning URL to widget: " . $url . " - Widget URL: " . $widget->url);
  47.             $widgets[] = $widget;
  48.         }
  49.  
  50.         return $widgets;
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement