feat: add StationResource with poll action and view page
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
118
app/Filament/Resources/StationResource.php
Normal file
118
app/Filament/Resources/StationResource.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\StationResource\Pages\ListStations;
|
||||
use App\Filament\Resources\StationResource\Pages\ViewStation;
|
||||
use App\Models\Station;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class StationResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Station::class;
|
||||
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-map-pin';
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Data';
|
||||
|
||||
protected static ?string $navigationLabel = 'Stations';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('trading_name')->searchable()->sortable(),
|
||||
TextColumn::make('brand_name')->searchable()->placeholder('—'),
|
||||
TextColumn::make('postcode')->searchable(),
|
||||
TextColumn::make('city'),
|
||||
IconColumn::make('is_supermarket')->label('Supermarket')->boolean(),
|
||||
IconColumn::make('is_motorway_service_station')->label('Motorway')->boolean(),
|
||||
IconColumn::make('temporary_closure')
|
||||
->label('Temp closed')
|
||||
->boolean()
|
||||
->trueColor('warning')
|
||||
->falseColor('success'),
|
||||
TextColumn::make('last_seen_at')->dateTime('d M Y H:i')->sortable(),
|
||||
])
|
||||
->searchPlaceholder('Search name, brand, or postcode...')
|
||||
->defaultSort('last_seen_at', 'desc')
|
||||
->filters([
|
||||
TernaryFilter::make('is_supermarket')->label('Supermarket'),
|
||||
TernaryFilter::make('is_motorway_service_station')->label('Motorway'),
|
||||
TernaryFilter::make('temporary_closure')->label('Temporarily closed'),
|
||||
TernaryFilter::make('permanent_closure')->label('Permanently closed'),
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Section::make('Location')->schema([
|
||||
TextEntry::make('trading_name'),
|
||||
TextEntry::make('brand_name')->placeholder('—'),
|
||||
TextEntry::make('address_line_1'),
|
||||
TextEntry::make('address_line_2')->placeholder('—'),
|
||||
TextEntry::make('city'),
|
||||
TextEntry::make('county')->placeholder('—'),
|
||||
TextEntry::make('postcode'),
|
||||
TextEntry::make('country'),
|
||||
])->columns(3),
|
||||
Section::make('Status')->schema([
|
||||
TextEntry::make('is_supermarket')
|
||||
->label('Supermarket')
|
||||
->badge()
|
||||
->formatStateUsing(fn (bool $state) => $state ? 'Yes' : 'No')
|
||||
->color(fn (bool $state) => $state ? 'success' : 'gray'),
|
||||
TextEntry::make('is_motorway_service_station')
|
||||
->label('Motorway')
|
||||
->badge()
|
||||
->formatStateUsing(fn (bool $state) => $state ? 'Yes' : 'No')
|
||||
->color(fn (bool $state) => $state ? 'success' : 'gray'),
|
||||
TextEntry::make('temporary_closure')
|
||||
->label('Temp Closed')
|
||||
->badge()
|
||||
->formatStateUsing(fn (bool $state) => $state ? 'Yes' : 'No')
|
||||
->color(fn (bool $state) => $state ? 'warning' : 'success'),
|
||||
TextEntry::make('permanent_closure')
|
||||
->label('Permanently Closed')
|
||||
->badge()
|
||||
->formatStateUsing(fn (bool $state) => $state ? 'Yes' : 'No')
|
||||
->color(fn (bool $state) => $state ? 'danger' : 'success'),
|
||||
TextEntry::make('permanent_closure_date')->date()->placeholder('—'),
|
||||
TextEntry::make('last_seen_at')->dateTime('d M Y H:i'),
|
||||
])->columns(3),
|
||||
Section::make('Fuel Types')->schema([
|
||||
TextEntry::make('fuel_types')
|
||||
->listWithLineBreaks()
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Section::make('Amenities')->schema([
|
||||
TextEntry::make('amenities')
|
||||
->listWithLineBreaks()
|
||||
->placeholder('None recorded')
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListStations::route('/'),
|
||||
'view' => ViewStation::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\StationResource\Pages;
|
||||
|
||||
use App\Filament\Resources\StationResource;
|
||||
use App\Jobs\PollFuelPricesJob;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListStations extends ListRecords
|
||||
{
|
||||
protected static string $resource = StationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('triggerFullPoll')
|
||||
->label('Trigger Full Poll')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Trigger full station refresh?')
|
||||
->modalDescription('This dispatches a background job to refresh all ~14,500 stations from the Fuel Finder API. Results will appear in API Logs once complete.')
|
||||
->action(function () {
|
||||
PollFuelPricesJob::dispatch();
|
||||
|
||||
Notification::make()
|
||||
->title('Poll dispatched to queue')
|
||||
->body('Check API Logs once the job completes.')
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
16
app/Filament/Resources/StationResource/Pages/ViewStation.php
Normal file
16
app/Filament/Resources/StationResource/Pages/ViewStation.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\StationResource\Pages;
|
||||
|
||||
use App\Filament\Resources\StationResource;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewStation extends ViewRecord
|
||||
{
|
||||
protected static string $resource = StationResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user