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:
135
app/Filament/Resources/Repositories/RepositoryResource.php
Normal file
135
app/Filament/Resources/Repositories/RepositoryResource.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Repositories;
|
||||
|
||||
use App\Enums\GitProvider;
|
||||
use App\Filament\Resources\Repositories\Pages\CreateRepository;
|
||||
use App\Filament\Resources\Repositories\Pages\EditRepository;
|
||||
use App\Filament\Resources\Repositories\Pages\ListRepositories;
|
||||
use App\Filament\Resources\Repositories\Tables\RepositoriesTable;
|
||||
use App\Models\Repository;
|
||||
use BackedEnum;
|
||||
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\Table;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Git repositories connected to the collective's projects.
|
||||
*
|
||||
* The form is intentionally tiny: a repository is identified by its provider
|
||||
* and "owner/repo", and everything else — stars, languages, contributors,
|
||||
* newcomer-friendly issues — arrives from the provider on each sync. Nothing
|
||||
* synced is editable, because a hand-typed star count is a lie waiting to
|
||||
* happen.
|
||||
*/
|
||||
class RepositoryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Repository::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCodeBracketSquare;
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'full_name';
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('panel.repositories.label');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('panel.repositories.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([
|
||||
Select::make('provider')
|
||||
->label(__('panel.repositories.fields.provider'))
|
||||
->options(GitProvider::class)
|
||||
->default(GitProvider::default())
|
||||
->required()
|
||||
// Only providers with a driver registered in
|
||||
// config/git.php can actually be synced.
|
||||
->disableOptionWhen(fn (string $value) => ! GitProvider::from($value)->isSupported()),
|
||||
|
||||
TextInput::make('full_name')
|
||||
->label(__('panel.repositories.fields.full_name'))
|
||||
->placeholder('colectivo/mi-proyecto')
|
||||
->helperText(__('panel.repositories.fields.full_name_hint'))
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->rules(['regex:/^[\w.-]+\/[\w.-]+$|^[\w.-]+$/']),
|
||||
|
||||
Select::make('project_id')
|
||||
->label(__('panel.repositories.fields.project'))
|
||||
->relationship('project', 'title->'.config('locales.default'))
|
||||
->searchable()
|
||||
->preload(),
|
||||
|
||||
Toggle::make('is_primary')
|
||||
->label(__('panel.repositories.fields.is_primary'))
|
||||
->helperText(__('panel.repositories.fields.is_primary_hint')),
|
||||
|
||||
Toggle::make('show_publicly')
|
||||
->label(__('panel.repositories.fields.show_publicly'))
|
||||
->default(true),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return RepositoriesTable::configure($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['full_name'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListRepositories::route('/'),
|
||||
'create' => CreateRepository::route('/create'),
|
||||
'edit' => EditRepository::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags repositories whose sync keeps failing — usually renamed or deleted
|
||||
* upstream — so stale numbers do not sit on the public site unnoticed.
|
||||
*/
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
$failing = static::getModel()::query()->failing()->count();
|
||||
|
||||
return $failing > 0 ? (string) $failing : null;
|
||||
}
|
||||
|
||||
public static function getNavigationBadgeColor(): ?string
|
||||
{
|
||||
return 'danger';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user