Initial commit: Pireon Admin — headless admin panel and public API
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>
This commit is contained in:
13
app/Filament/Resources/Redirects/Pages/CreateRedirect.php
Normal file
13
app/Filament/Resources/Redirects/Pages/CreateRedirect.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Redirects\Pages;
|
||||
|
||||
use App\Filament\Resources\Redirects\RedirectResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateRedirect extends CreateRecord
|
||||
{
|
||||
protected static string $resource = RedirectResource::class;
|
||||
}
|
||||
24
app/Filament/Resources/Redirects/Pages/EditRedirect.php
Normal file
24
app/Filament/Resources/Redirects/Pages/EditRedirect.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Redirects\Pages;
|
||||
|
||||
use App\Filament\Concerns\WarnsOfConcurrentEditing;
|
||||
use App\Filament\Resources\Redirects\RedirectResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditRedirect extends EditRecord
|
||||
{
|
||||
use WarnsOfConcurrentEditing;
|
||||
|
||||
protected static string $resource = RedirectResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
21
app/Filament/Resources/Redirects/Pages/ListRedirects.php
Normal file
21
app/Filament/Resources/Redirects/Pages/ListRedirects.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Redirects\Pages;
|
||||
|
||||
use App\Filament\Resources\Redirects\RedirectResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListRedirects extends ListRecords
|
||||
{
|
||||
protected static string $resource = RedirectResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
210
app/Filament/Resources/Redirects/RedirectResource.php
Normal file
210
app/Filament/Resources/Redirects/RedirectResource.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Redirects;
|
||||
|
||||
use App\Filament\Resources\Redirects\Pages\CreateRedirect;
|
||||
use App\Filament\Resources\Redirects\Pages\EditRedirect;
|
||||
use App\Filament\Resources\Redirects\Pages\ListRedirects;
|
||||
use App\Models\Redirect;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* URLs that used to work, and where they go now.
|
||||
*
|
||||
* Most of this list is never typed by anybody: renaming a slug writes an entry
|
||||
* on the way past, because that is the only moment the old address is still
|
||||
* known. The rest is for the links that existed before this application did.
|
||||
*/
|
||||
class RedirectResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Redirect::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArrowsRightLeft;
|
||||
|
||||
protected static ?int $navigationSort = 85;
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('panel.redirects.label');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('panel.redirects.plural');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): string|UnitEnum|null
|
||||
{
|
||||
return __('panel.groups.administration');
|
||||
}
|
||||
|
||||
public static function getRecordTitle(?Model $record): ?string
|
||||
{
|
||||
return $record?->from;
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Section::make()
|
||||
->description(__('panel.redirects.hint'))
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('from')
|
||||
->label(__('panel.redirects.fields.from'))
|
||||
->helperText(__('panel.redirects.fields.from_hint'))
|
||||
->required()
|
||||
->maxLength(500)
|
||||
->placeholder('/proyectos/nombre-viejo')
|
||||
// Normalised on the way in so a rule typed by hand
|
||||
// matches one written automatically.
|
||||
->dehydrateStateUsing(fn (string $state) => Redirect::normalise($state)),
|
||||
|
||||
TextInput::make('to')
|
||||
->label(__('panel.redirects.fields.to'))
|
||||
->required()
|
||||
->maxLength(500)
|
||||
->placeholder('/proyectos/nombre-nuevo')
|
||||
->dehydrateStateUsing(fn (string $state) => Redirect::normalise($state))
|
||||
->different('from'),
|
||||
|
||||
Select::make('status')
|
||||
->label(__('panel.redirects.fields.status'))
|
||||
->helperText(__('panel.redirects.fields.status_hint'))
|
||||
->options([
|
||||
301 => __('panel.redirects.statuses.301'),
|
||||
302 => __('panel.redirects.statuses.302'),
|
||||
])
|
||||
->default(301)
|
||||
->required(),
|
||||
|
||||
Select::make('locale')
|
||||
->label(__('panel.redirects.fields.locale'))
|
||||
->helperText(__('panel.redirects.fields.locale_hint'))
|
||||
->options(fn () => collect(config('locales.supported'))
|
||||
->map(fn (array $meta, string $code) => $meta['native'] ?? $code)
|
||||
->all())
|
||||
->placeholder(__('panel.redirects.every_locale')),
|
||||
|
||||
Toggle::make('is_enabled')
|
||||
->label(__('panel.redirects.fields.is_enabled'))
|
||||
->default(true),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('from')
|
||||
->label(__('panel.redirects.fields.from'))
|
||||
->fontFamily('mono')
|
||||
->searchable()
|
||||
->wrap(),
|
||||
|
||||
TextColumn::make('to')
|
||||
->label(__('panel.redirects.fields.to'))
|
||||
->fontFamily('mono')
|
||||
->searchable()
|
||||
->wrap()
|
||||
// A rule pointing at its own source would send a browser
|
||||
// round in circles.
|
||||
->color(fn (Redirect $record) => $record->isCircular() ? 'danger' : null),
|
||||
|
||||
TextColumn::make('status')
|
||||
->label(__('panel.redirects.fields.status'))
|
||||
->badge()
|
||||
->color(fn (int $state) => $state === 301 ? 'gray' : 'info'),
|
||||
|
||||
TextColumn::make('locale')
|
||||
->label(__('panel.redirects.fields.locale'))
|
||||
->badge()
|
||||
->color('gray')
|
||||
->placeholder(__('panel.redirects.every_locale'))
|
||||
->toggleable(),
|
||||
|
||||
// The number that decides whether a rule can ever be deleted:
|
||||
// is anybody still following it?
|
||||
TextColumn::make('hits')
|
||||
->label(__('panel.redirects.fields.hits'))
|
||||
->badge()
|
||||
->color(fn (int $state) => $state > 0 ? 'success' : 'gray')
|
||||
->description(fn (Redirect $record) => $record->last_used_at?->diffForHumans())
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('source_type')
|
||||
->label(__('panel.redirects.fields.origin'))
|
||||
->badge()
|
||||
->color('gray')
|
||||
->formatStateUsing(fn (?string $state) => $state
|
||||
? __('panel.redirects.automatic')
|
||||
: __('panel.redirects.manual'))
|
||||
->toggleable(),
|
||||
|
||||
IconColumn::make('is_enabled')
|
||||
->label(__('panel.redirects.fields.is_enabled'))
|
||||
->boolean(),
|
||||
])
|
||||
->filters([
|
||||
TernaryFilter::make('is_enabled')->label(__('panel.redirects.fields.is_enabled')),
|
||||
|
||||
Filter::make('automatic')
|
||||
->label(__('panel.redirects.automatic'))
|
||||
->query(fn (Builder $query) => $query->whereNotNull('source_type')),
|
||||
|
||||
Filter::make('unused')
|
||||
->label(__('panel.redirects.filters.unused'))
|
||||
->query(fn (Builder $query) => $query->where('hits', 0)),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([DeleteBulkAction::make()]),
|
||||
])
|
||||
->emptyStateHeading(__('panel.redirects.empty.heading'))
|
||||
->emptyStateDescription(__('panel.redirects.empty.description'))
|
||||
->emptyStateIcon('heroicon-o-arrows-right-left');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['from', 'to'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListRedirects::route('/'),
|
||||
'create' => CreateRedirect::route('/create'),
|
||||
'edit' => EditRedirect::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user