Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
235 lines
8.4 KiB
PHP
235 lines
8.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\Technologies;
|
|
|
|
use App\Enums\RadarRing;
|
|
use App\Enums\TechnologyCategory;
|
|
use App\Filament\RelationManagers\RevisionsRelationManager;
|
|
use App\Filament\Resources\Technologies\Pages\CreateTechnology;
|
|
use App\Filament\Resources\Technologies\Pages\EditTechnology;
|
|
use App\Filament\Resources\Technologies\Pages\ListTechnologies;
|
|
use App\Filament\Support\TranslatableTabs;
|
|
use App\Models\Technology;
|
|
use BackedEnum;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\ColorPicker;
|
|
use Filament\Forms\Components\FileUpload;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Filament\Tables\Columns\ColorColumn;
|
|
use Filament\Tables\Columns\ImageColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Support\Str;
|
|
use Illuminate\Validation\Rule;
|
|
use UnitEnum;
|
|
|
|
/**
|
|
* The shared vocabulary of the site, and the source of the tech radar.
|
|
*
|
|
* Names are not translatable — "Rust" is "Rust" in every language. Only the
|
|
* prose explaining a choice is.
|
|
*/
|
|
class TechnologyResource extends Resource
|
|
{
|
|
protected static ?string $model = Technology::class;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCpuChip;
|
|
|
|
protected static ?int $navigationSort = 4;
|
|
|
|
protected static ?string $recordTitleAttribute = 'name';
|
|
|
|
public static function getModelLabel(): string
|
|
{
|
|
return __('panel.technologies.label');
|
|
}
|
|
|
|
public static function getPluralModelLabel(): string
|
|
{
|
|
return __('panel.technologies.plural');
|
|
}
|
|
|
|
public static function getNavigationGroup(): string|UnitEnum|null
|
|
{
|
|
return __('panel.groups.collective');
|
|
}
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
Section::make()
|
|
->columns(2)
|
|
->schema([
|
|
TextInput::make('name')
|
|
->label(__('panel.technologies.fields.name'))
|
|
->required()
|
|
->maxLength(120)
|
|
->live(onBlur: true)
|
|
->afterStateUpdated(function (?string $state, callable $get, callable $set) {
|
|
if (blank($get('slug'))) {
|
|
$set('slug', Str::slug((string) $state));
|
|
}
|
|
}),
|
|
|
|
TextInput::make('slug')
|
|
->label(__('panel.technologies.fields.slug'))
|
|
->required()
|
|
->maxLength(120)
|
|
->rules(fn ($record) => [Rule::unique('technologies', 'slug')->ignore($record?->id)]),
|
|
|
|
Select::make('category')
|
|
->label(__('panel.technologies.fields.category'))
|
|
->options(TechnologyCategory::class)
|
|
->default(TechnologyCategory::Tool)
|
|
->required(),
|
|
|
|
// Leaving the ring empty keeps a technology usable as a tag
|
|
// without putting it on the public radar.
|
|
Select::make('radar_ring')
|
|
->label(__('panel.technologies.fields.radar_ring'))
|
|
->options(RadarRing::class)
|
|
->helperText(__('panel.technologies.fields.radar_ring_hint'))
|
|
->placeholder(__('panel.technologies.off_radar')),
|
|
|
|
ColorPicker::make('color')->label(__('panel.technologies.fields.color')),
|
|
|
|
// A file rather than the name of an icon from a set the
|
|
// frontend may or may not bundle.
|
|
FileUpload::make('logo')
|
|
->label(__('panel.technologies.fields.logo'))
|
|
->helperText(__('panel.technologies.fields.logo_hint'))
|
|
->image()
|
|
->disk(config('media.disk'))
|
|
->directory('technologies')
|
|
->columnSpanFull(),
|
|
|
|
TextInput::make('website')
|
|
->label(__('panel.technologies.fields.website'))
|
|
->url()
|
|
->maxLength(2048),
|
|
|
|
TextInput::make('position')
|
|
->label(__('panel.technologies.fields.position'))
|
|
->numeric()
|
|
->default(0),
|
|
]),
|
|
|
|
Section::make(__('panel.technologies.sections.prose'))
|
|
->collapsed()
|
|
->schema([
|
|
TranslatableTabs::make(fn (string $locale) => [
|
|
Textarea::make("description.{$locale}")
|
|
->label(__('panel.technologies.fields.description'))
|
|
->rows(3)
|
|
->columnSpanFull(),
|
|
|
|
// Why this sits in that ring. The part of a tech radar
|
|
// people actually read.
|
|
Textarea::make("radar_note.{$locale}")
|
|
->label(__('panel.technologies.fields.radar_note'))
|
|
->helperText(__('panel.technologies.fields.radar_note_hint'))
|
|
->rows(3)
|
|
->columnSpanFull(),
|
|
], label: __('panel.technologies.sections.prose')),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->defaultSort('name')
|
|
->columns([
|
|
ImageColumn::make('logo')
|
|
->label('')
|
|
->disk(config('media.disk'))
|
|
->height(24),
|
|
|
|
ColorColumn::make('color')->label(''),
|
|
|
|
TextColumn::make('name')
|
|
->label(__('panel.technologies.fields.name'))
|
|
->weight('medium')
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
TextColumn::make('category')
|
|
->label(__('panel.technologies.fields.category'))
|
|
->badge()
|
|
->sortable(),
|
|
|
|
TextColumn::make('radar_ring')
|
|
->label(__('panel.technologies.fields.radar_ring'))
|
|
->badge()
|
|
->placeholder(__('panel.technologies.off_radar'))
|
|
->sortable(),
|
|
|
|
TextColumn::make('projects_count')
|
|
->label(__('panel.technologies.fields.projects'))
|
|
->counts('projects')
|
|
->badge()
|
|
->color('gray'),
|
|
|
|
TextColumn::make('members_count')
|
|
->label(__('panel.technologies.fields.members'))
|
|
->counts('members')
|
|
->badge()
|
|
->color('gray'),
|
|
])
|
|
->filters([
|
|
SelectFilter::make('category')
|
|
->label(__('panel.technologies.fields.category'))
|
|
->options(TechnologyCategory::options())
|
|
->multiple(),
|
|
|
|
SelectFilter::make('radar_ring')
|
|
->label(__('panel.technologies.fields.radar_ring'))
|
|
->options(RadarRing::options())
|
|
->multiple(),
|
|
])
|
|
->recordActions([
|
|
EditAction::make(),
|
|
DeleteAction::make(),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([DeleteBulkAction::make()]),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string>
|
|
*/
|
|
public static function getGloballySearchableAttributes(): array
|
|
{
|
|
return ['name'];
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
RevisionsRelationManager::class,
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ListTechnologies::route('/'),
|
|
'create' => CreateTechnology::route('/create'),
|
|
'edit' => EditTechnology::route('/{record}/edit'),
|
|
];
|
|
}
|
|
}
|