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:
291
app/Filament/Resources/Calls/CallResource.php
Normal file
291
app/Filament/Resources/Calls/CallResource.php
Normal file
@@ -0,0 +1,291 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Calls;
|
||||
|
||||
use App\Enums\CallStatus;
|
||||
use App\Filament\RelationManagers\RevisionsRelationManager;
|
||||
use App\Filament\Resources\Calls\Pages\CreateCall;
|
||||
use App\Filament\Resources\Calls\Pages\EditCall;
|
||||
use App\Filament\Resources\Calls\Pages\ListCalls;
|
||||
use App\Filament\Resources\Calls\RelationManagers\ApplicationsRelationManager;
|
||||
use App\Filament\Support\PreviewAction;
|
||||
use App\Filament\Support\TranslatableTabs;
|
||||
use App\Models\Call;
|
||||
use App\Rules\UniqueTranslatedSlug;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ReplicateAction;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
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\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Calls for contributors — the conversion point of the whole site.
|
||||
*
|
||||
* The hours-per-week and duration fields are what make this worth having as a
|
||||
* model of its own: a volunteer weighs time, and "~4h/week for 8 weeks" is a
|
||||
* decision someone can make in seconds.
|
||||
*/
|
||||
class CallResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Call::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedHandRaised;
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('panel.calls.label');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('panel.calls.plural');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): string|UnitEnum|null
|
||||
{
|
||||
return __('panel.groups.collective');
|
||||
}
|
||||
|
||||
public static function getRecordTitle(?Model $record): ?string
|
||||
{
|
||||
return $record?->getTranslation('title', app()->getLocale());
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Section::make()->schema([
|
||||
TranslatableTabs::make(fn (string $locale, bool $isDefault) => [
|
||||
TextInput::make("title.{$locale}")
|
||||
->label(__('panel.calls.fields.title'))
|
||||
->required($isDefault)
|
||||
->maxLength(255)
|
||||
->columnSpanFull()
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(function (?string $state, callable $get, callable $set) use ($locale) {
|
||||
if (blank($get("slug.{$locale}"))) {
|
||||
$set("slug.{$locale}", Str::slug((string) $state));
|
||||
}
|
||||
}),
|
||||
|
||||
TextInput::make("slug.{$locale}")
|
||||
->label(__('panel.calls.fields.slug'))
|
||||
->required($isDefault)
|
||||
->maxLength(255)
|
||||
->columnSpanFull()
|
||||
->rules(fn ($record) => [new UniqueTranslatedSlug(Call::class, $record?->id)]),
|
||||
|
||||
Textarea::make("description.{$locale}")
|
||||
->label(__('panel.calls.fields.description'))
|
||||
->rows(4)
|
||||
->columnSpanFull(),
|
||||
|
||||
// Unpaid work needs an explicit exchange. Saying it out
|
||||
// loud attracts more people than leaving it implied.
|
||||
Textarea::make("what_you_get.{$locale}")
|
||||
->label(__('panel.calls.fields.what_you_get'))
|
||||
->helperText(__('panel.calls.fields.what_you_get_hint'))
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
]),
|
||||
|
||||
Section::make(__('panel.calls.sections.commitment'))
|
||||
->description(__('panel.calls.sections.commitment_hint'))
|
||||
->columns(3)
|
||||
->schema([
|
||||
TextInput::make('hours_per_week')
|
||||
->label(__('panel.calls.fields.hours_per_week'))
|
||||
->numeric()
|
||||
->minValue(1)
|
||||
->maxValue(40)
|
||||
->suffix('h'),
|
||||
|
||||
TextInput::make('duration_weeks')
|
||||
->label(__('panel.calls.fields.duration_weeks'))
|
||||
->numeric()
|
||||
->minValue(1),
|
||||
|
||||
Select::make('seniority')
|
||||
->label(__('panel.calls.fields.seniority'))
|
||||
->options([
|
||||
'any' => __('panel.calls.seniority.any'),
|
||||
'junior' => __('panel.calls.seniority.junior'),
|
||||
'mid' => __('panel.calls.seniority.mid'),
|
||||
'senior' => __('panel.calls.seniority.senior'),
|
||||
]),
|
||||
]),
|
||||
|
||||
Section::make()
|
||||
->columns(2)
|
||||
->schema([
|
||||
Select::make('project_id')
|
||||
->label(__('panel.calls.fields.project'))
|
||||
->relationship('project', 'title->'.config('locales.default'))
|
||||
->searchable()
|
||||
->preload()
|
||||
->helperText(__('panel.calls.fields.project_hint')),
|
||||
|
||||
Select::make('status')
|
||||
->label(__('panel.calls.fields.status'))
|
||||
->options(CallStatus::class)
|
||||
->default(CallStatus::Open)
|
||||
->required(),
|
||||
|
||||
Select::make('technologies')
|
||||
->label(__('panel.calls.fields.technologies'))
|
||||
->relationship('technologies', 'name')
|
||||
->multiple()
|
||||
->preload()
|
||||
->searchable()
|
||||
->columnSpanFull(),
|
||||
|
||||
DatePicker::make('opens_at')->label(__('panel.calls.fields.opens_at')),
|
||||
DatePicker::make('closes_at')->label(__('panel.calls.fields.closes_at')),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
$locale = app()->getLocale();
|
||||
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('title')
|
||||
->label(__('panel.calls.fields.title'))
|
||||
->weight('medium')
|
||||
->wrap()
|
||||
->searchable(query: fn ($q, string $search) => $q
|
||||
->where("title->{$locale}", 'like', "%{$search}%")),
|
||||
|
||||
TextColumn::make('status')
|
||||
->label(__('panel.calls.fields.status'))
|
||||
->badge()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('project.title')
|
||||
->label(__('panel.calls.fields.project'))
|
||||
->badge()
|
||||
->color('gray')
|
||||
->placeholder(__('panel.calls.no_project')),
|
||||
|
||||
// The number that does the work on the public site.
|
||||
TextColumn::make('hours_per_week')
|
||||
->label(__('panel.calls.fields.commitment'))
|
||||
->formatStateUsing(fn ($state, Call $record) => $state
|
||||
? trans_choice('panel.calls.commitment_summary', $record->duration_weeks ?? 0, [
|
||||
'hours' => $state,
|
||||
'weeks' => $record->duration_weeks,
|
||||
])
|
||||
: '—')
|
||||
->badge()
|
||||
->color('info'),
|
||||
|
||||
TextColumn::make('technologies.name')
|
||||
->label(__('panel.calls.fields.technologies'))
|
||||
->badge()
|
||||
->color('gray')
|
||||
->limitList(3)
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('closes_at')
|
||||
->label(__('panel.calls.fields.closes_at'))
|
||||
->date()
|
||||
->placeholder('—')
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')
|
||||
->label(__('panel.calls.fields.status'))
|
||||
->options(CallStatus::options())
|
||||
->multiple(),
|
||||
|
||||
SelectFilter::make('technologies')
|
||||
->label(__('panel.calls.fields.technologies'))
|
||||
->relationship('technologies', 'name')
|
||||
->multiple()
|
||||
->preload(),
|
||||
])
|
||||
->recordActions([
|
||||
// A near-copy is a real workflow: the third similar service,
|
||||
// next year's call. The slug is cleared because two records
|
||||
// cannot answer at the same URL.
|
||||
ReplicateAction::make()
|
||||
->label(__('panel.actions.duplicate'))
|
||||
->icon('heroicon-o-document-duplicate')
|
||||
->excludeAttributes(['slug', 'published_at', 'unpublish_at'])
|
||||
->modalHeading(__('panel.actions.duplicate_heading'))
|
||||
->successNotificationTitle(__('panel.actions.duplicated')),
|
||||
|
||||
PreviewAction::for('call'),
|
||||
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([DeleteBulkAction::make()]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RevisionsRelationManager::class,
|
||||
ApplicationsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['title->'.app()->getLocale()];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListCalls::route('/'),
|
||||
'create' => CreateCall::route('/create'),
|
||||
'edit' => EditCall::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* How many contributor slots are currently open — the number that tells
|
||||
* the collective whether the site is doing its job.
|
||||
*/
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
$open = static::getModel()::query()->open()->count();
|
||||
|
||||
return $open > 0 ? (string) $open : null;
|
||||
}
|
||||
|
||||
public static function getNavigationBadgeColor(): ?string
|
||||
{
|
||||
return 'success';
|
||||
}
|
||||
}
|
||||
13
app/Filament/Resources/Calls/Pages/CreateCall.php
Normal file
13
app/Filament/Resources/Calls/Pages/CreateCall.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Calls\Pages;
|
||||
|
||||
use App\Filament\Resources\Calls\CallResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCall extends CreateRecord
|
||||
{
|
||||
protected static string $resource = CallResource::class;
|
||||
}
|
||||
24
app/Filament/Resources/Calls/Pages/EditCall.php
Normal file
24
app/Filament/Resources/Calls/Pages/EditCall.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Calls\Pages;
|
||||
|
||||
use App\Filament\Concerns\WarnsOfConcurrentEditing;
|
||||
use App\Filament\Resources\Calls\CallResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCall extends EditRecord
|
||||
{
|
||||
use WarnsOfConcurrentEditing;
|
||||
|
||||
protected static string $resource = CallResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
21
app/Filament/Resources/Calls/Pages/ListCalls.php
Normal file
21
app/Filament/Resources/Calls/Pages/ListCalls.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Calls\Pages;
|
||||
|
||||
use App\Filament\Resources\Calls\CallResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListCalls extends ListRecords
|
||||
{
|
||||
protected static string $resource = CallResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Calls\RelationManagers;
|
||||
|
||||
use App\Enums\ApplicationStatus;
|
||||
use App\Filament\Resources\Applications\ApplicationResource;
|
||||
use App\Models\Application;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* Who answered this call, shown on the call itself.
|
||||
*
|
||||
* The inbox is the place to work through everything at once; this is the place
|
||||
* to answer the question you actually have while looking at an opening — is
|
||||
* anybody interested? A call with no replies after a month is telling you
|
||||
* something about the call, not about the people.
|
||||
*/
|
||||
class ApplicationsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'applications';
|
||||
|
||||
public static function getTitle(Model $ownerRecord, string $pageClass): string
|
||||
{
|
||||
return __('panel.applications.plural');
|
||||
}
|
||||
|
||||
public static function getBadge(Model $ownerRecord, string $pageClass): ?string
|
||||
{
|
||||
$pending = $ownerRecord->applications()->pending()->count();
|
||||
|
||||
return $pending > 0 ? (string) $pending : null;
|
||||
}
|
||||
|
||||
public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
|
||||
{
|
||||
// The inbox holds personal data, so it stays behind its own permission
|
||||
// even for someone already allowed to edit the call.
|
||||
return (bool) Auth::user()?->can('applications.view_any');
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label(__('panel.applications.fields.name'))
|
||||
->weight('medium')
|
||||
->description(fn (Application $record) => $record->email),
|
||||
|
||||
TextColumn::make('hours_per_week')
|
||||
->label(__('panel.applications.fields.hours_per_week'))
|
||||
->badge()
|
||||
->color('info')
|
||||
->formatStateUsing(fn (?int $state) => $state ? "{$state} h" : '—'),
|
||||
|
||||
TextColumn::make('status')
|
||||
->label(__('panel.applications.fields.status'))
|
||||
->badge(),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->label(__('panel.applications.fields.received_at'))
|
||||
->since()
|
||||
->dateTimeTooltip(),
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('open')
|
||||
->label(__('panel.applications.actions.open'))
|
||||
->icon('heroicon-o-arrow-top-right-on-square')
|
||||
->url(fn (Application $record) => ApplicationResource::getUrl('view', ['record' => $record])),
|
||||
|
||||
Action::make('mark_contacted')
|
||||
->label(__('panel.applications.actions.contacted'))
|
||||
->icon('heroicon-o-chat-bubble-left-right')
|
||||
->color('info')
|
||||
->authorize('update')
|
||||
->visible(fn (Application $record) => $record->status === ApplicationStatus::New)
|
||||
->action(fn (Application $record) => $record->markAs(
|
||||
ApplicationStatus::Contacted,
|
||||
Auth::user(),
|
||||
)),
|
||||
])
|
||||
->emptyStateHeading(__('panel.applications.empty.call_heading'))
|
||||
->emptyStateIcon('heroicon-o-inbox');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user