feat: add OilPredictionResource with run-prediction header action
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\OilPredictionResource\Pages;
|
||||
|
||||
use App\Filament\Resources\OilPredictionResource;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class ListOilPredictions extends ListRecords
|
||||
{
|
||||
protected static string $resource = OilPredictionResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('runPrediction')
|
||||
->label('Run Prediction Now')
|
||||
->icon('heroicon-o-cpu-chip')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Run oil price prediction?')
|
||||
->modalDescription('This will fetch the latest FRED prices and generate a new prediction. May take a few seconds.')
|
||||
->action(function () {
|
||||
$result = Artisan::call('oil:predict', ['--fetch' => true]);
|
||||
|
||||
if ($result === 0) {
|
||||
Notification::make()
|
||||
->title('Prediction generated successfully')
|
||||
->success()
|
||||
->send();
|
||||
} else {
|
||||
Notification::make()
|
||||
->title('Prediction failed')
|
||||
->body('Check API Logs for details.')
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\OilPredictionResource\Pages;
|
||||
|
||||
use App\Filament\Resources\OilPredictionResource;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewOilPrediction extends ViewRecord
|
||||
{
|
||||
protected static string $resource = OilPredictionResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user