115 lines
4.2 KiB
PHP
115 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\EventResource\Pages;
|
|
use App\Models\Event;
|
|
use App\Models\Tenant;
|
|
use App\Models\EventType;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Filament\Actions;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\DatePicker;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Forms\Components\KeyValue;
|
|
use UnitEnum;
|
|
use BackedEnum;
|
|
|
|
class EventResource extends Resource
|
|
{
|
|
protected static ?string $model = Event::class;
|
|
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-calendar';
|
|
protected static UnitEnum|string|null $navigationGroup = 'Platform';
|
|
protected static ?int $navigationSort = 20;
|
|
|
|
public static function form(Schema $form): Schema
|
|
{
|
|
return $form->schema([
|
|
Select::make('tenant_id')
|
|
->label('Tenant')
|
|
->options(Tenant::all()->pluck('name', 'id'))
|
|
->searchable()
|
|
->required(),
|
|
TextInput::make('name')
|
|
->label('Event Name')
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('slug')
|
|
->label('Slug')
|
|
->required()
|
|
->unique(ignoreRecord: true)
|
|
->maxLength(255),
|
|
DatePicker::make('date')
|
|
->label('Event Date')
|
|
->required(),
|
|
Select::make('event_type_id')
|
|
->label('Event Type')
|
|
->options(EventType::all()->pluck('name', 'id'))
|
|
->searchable(),
|
|
TextInput::make('default_locale')
|
|
->label('Default Locale')
|
|
->default('de')
|
|
->maxLength(5),
|
|
Toggle::make('is_active')
|
|
->label('Is Active')
|
|
->default(true),
|
|
KeyValue::make('settings')
|
|
->label('Settings')
|
|
->keyLabel('Key')
|
|
->valueLabel('Value'),
|
|
])->columns(2);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('id')->sortable(),
|
|
Tables\Columns\TextColumn::make('tenant_id')->label('Tenant')->sortable(),
|
|
Tables\Columns\TextColumn::make('name')->limit(30),
|
|
Tables\Columns\TextColumn::make('slug')->searchable(),
|
|
Tables\Columns\TextColumn::make('date')->date(),
|
|
Tables\Columns\IconColumn::make('is_active')->boolean(),
|
|
Tables\Columns\TextColumn::make('default_locale'),
|
|
Tables\Columns\TextColumn::make('join')->label('Join')
|
|
->getStateUsing(fn($record) => url("/e/{$record->slug}"))
|
|
->copyable()
|
|
->copyMessage('Join link copied'),
|
|
Tables\Columns\TextColumn::make('created_at')->since(),
|
|
])
|
|
->filters([])
|
|
->actions([
|
|
Actions\EditAction::make(),
|
|
Actions\Action::make('toggle')
|
|
->label('Toggle Active')
|
|
->icon('heroicon-o-power')
|
|
->action(fn($record) => $record->update(['is_active' => !$record->is_active])),
|
|
Actions\Action::make('join_link')
|
|
->label('Join Link / QR')
|
|
->icon('heroicon-o-qr-code')
|
|
->modalHeading('Event Join Link')
|
|
->modalSubmitActionLabel('Close')
|
|
->modalContent(fn($record) => view('filament.events.join-link', [
|
|
'link' => url("/e/{$record->slug}"),
|
|
])),
|
|
])
|
|
->bulkActions([
|
|
Actions\DeleteBulkAction::make(),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListEvents::route('/'),
|
|
'view' => Pages\ViewEvent::route('/{record}'),
|
|
'edit' => Pages\EditEvent::route('/{record}/edit'),
|
|
];
|
|
}
|
|
} |