119 lines
4.9 KiB
PHP
119 lines
4.9 KiB
PHP
<?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}'),
|
|
];
|
|
}
|
|
}
|