refactor: add Enum labels, fix indentation, and add URL links to StatsOverviewWidget
Adds `label()` methods to TrendDirection and PredictionSource enums for cleaner display. Fixes mixed tab/space indentation in StatsOverviewWidget. Links all stats cards to their respective Filament resources (searches, stations, oil-predictions, api-logs). Documents BrentPriceChartWidget's manual registration.
This commit is contained in:
@@ -7,4 +7,13 @@ enum PredictionSource: string
|
||||
case Llm = 'llm';
|
||||
case LlmWithContext = 'llm_with_context';
|
||||
case Ewma = 'ewma';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Llm => 'LLM',
|
||||
self::LlmWithContext => 'LLM+Context',
|
||||
self::Ewma => 'EWMA',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,9 @@ enum TrendDirection: string
|
||||
case Rising = 'rising';
|
||||
case Falling = 'falling';
|
||||
case Flat = 'flat';
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return ucfirst($this->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class BrentPriceChartWidget extends ChartWidget
|
||||
|
||||
protected ?string $pollingInterval = null;
|
||||
|
||||
/** Registered manually in AdminPanelProvider — excluded from auto-discovery to control placement. */
|
||||
protected static bool $isDiscovered = false;
|
||||
|
||||
protected function getData(): array
|
||||
|
||||
@@ -19,7 +19,7 @@ class StatsOverviewWidget extends BaseWidget
|
||||
{
|
||||
return [
|
||||
$this->usersStat(),
|
||||
$this->searchesStat(),
|
||||
$this->searchesStat(),
|
||||
$this->stationsStat(),
|
||||
$this->oilPredictionStat(),
|
||||
$this->apiErrorsStat(),
|
||||
@@ -33,12 +33,13 @@ class StatsOverviewWidget extends BaseWidget
|
||||
->color('primary');
|
||||
}
|
||||
|
||||
private function searchesStat(): Stat
|
||||
{
|
||||
return Stat::make('Total searches', Search::count())
|
||||
->icon('heroicon-o-magnifying-glass')
|
||||
->color('primary');
|
||||
}
|
||||
private function searchesStat(): Stat
|
||||
{
|
||||
return Stat::make('Total searches', Search::count())
|
||||
->icon('heroicon-o-magnifying-glass')
|
||||
->url(route('filament.admin.resources.searches.index'))
|
||||
->color('primary');
|
||||
}
|
||||
|
||||
private function stationsStat(): Stat
|
||||
{
|
||||
@@ -50,6 +51,7 @@ class StatsOverviewWidget extends BaseWidget
|
||||
|
||||
return Stat::make('Stations in DB', number_format($count))
|
||||
->description($description)
|
||||
->url(route('filament.admin.resources.stations.index'))
|
||||
->icon('heroicon-o-map-pin')
|
||||
->color('success');
|
||||
}
|
||||
@@ -66,11 +68,11 @@ class StatsOverviewWidget extends BaseWidget
|
||||
|
||||
$ageHours = $prediction->generated_at->diffInHours(now());
|
||||
$color = $ageHours > 24 ? 'warning' : 'success';
|
||||
$value = ucfirst($prediction->direction->value)
|
||||
.' · '.$prediction->confidence.'%';
|
||||
$value = $prediction->direction->label().' · '.$prediction->confidence.'%';
|
||||
|
||||
return Stat::make('Latest oil prediction', $value)
|
||||
->description('Generated '.$prediction->generated_at->diffForHumans())
|
||||
->url(route('filament.admin.resources.oil-predictions.index'))
|
||||
->icon('heroicon-o-beaker')
|
||||
->color($color);
|
||||
}
|
||||
@@ -87,6 +89,7 @@ class StatsOverviewWidget extends BaseWidget
|
||||
|
||||
return Stat::make('API errors (24h)', $errors)
|
||||
->icon('heroicon-o-exclamation-triangle')
|
||||
->url(route('filament.admin.resources.api-logs.index'))
|
||||
->color($color);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user