Es gibt nun task collections und vordefinierte tasks für alle. Onboarding verfeinert und webseite-carousel gefixt (logging später entfernen!)
210 lines
9.0 KiB
PHP
210 lines
9.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Resources;
|
|
|
|
use App\Filament\Tenant\Resources\EventResource\Pages;
|
|
use App\Support\JoinTokenLayoutRegistry;
|
|
use App\Support\TenantOnboardingState;
|
|
use App\Models\Event;
|
|
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\Toggle;
|
|
use Filament\Forms\Components\KeyValue;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Hidden;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use UnitEnum;
|
|
use BackedEnum;
|
|
|
|
use App\Filament\Tenant\Resources\EventResource\RelationManagers\EventPackagesRelationManager;
|
|
|
|
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 = null;
|
|
|
|
public static function getNavigationGroup(): UnitEnum|string|null
|
|
{
|
|
return __('admin.nav.platform');
|
|
}
|
|
protected static ?int $navigationSort = 20;
|
|
|
|
public static function shouldRegisterNavigation(): bool
|
|
{
|
|
return TenantOnboardingState::completed();
|
|
}
|
|
|
|
public static function form(Schema $form): Schema
|
|
{
|
|
$tenantId = Auth::user()?->tenant_id;
|
|
|
|
return $form->schema([
|
|
Hidden::make('tenant_id')
|
|
->default($tenantId)
|
|
->dehydrated(),
|
|
TextInput::make('name')
|
|
->label(__('admin.events.fields.name'))
|
|
->required()
|
|
->maxLength(255),
|
|
TextInput::make('slug')
|
|
->label(__('admin.events.fields.slug'))
|
|
->required()
|
|
->unique(ignoreRecord: true)
|
|
->maxLength(255),
|
|
DatePicker::make('date')
|
|
->label(__('admin.events.fields.date'))
|
|
->required(),
|
|
Select::make('event_type_id')
|
|
->label(__('admin.events.fields.type'))
|
|
->options(EventType::all()->pluck('name', 'id'))
|
|
->searchable(),
|
|
Select::make('package_id')
|
|
->label(__('admin.events.fields.package'))
|
|
->options(\App\Models\Package::where('type', 'endcustomer')->pluck('name', 'id'))
|
|
->searchable()
|
|
->preload()
|
|
->required(),
|
|
TextInput::make('default_locale')
|
|
->label(__('admin.events.fields.default_locale'))
|
|
->default('de')
|
|
->maxLength(5),
|
|
Toggle::make('is_active')
|
|
->label(__('admin.events.fields.is_active'))
|
|
->default(true),
|
|
KeyValue::make('settings')
|
|
->label(__('admin.events.fields.settings'))
|
|
->keyLabel(__('admin.common.key'))
|
|
->valueLabel(__('admin.common.value')),
|
|
])->columns(2);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('id')->sortable(),
|
|
Tables\Columns\TextColumn::make('eventPackage.package.name')
|
|
->label(__('admin.events.table.package'))
|
|
->badge()
|
|
->color('success'),
|
|
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('eventPackage.used_photos')
|
|
->label(__('admin.events.table.used_photos'))
|
|
->badge(),
|
|
Tables\Columns\TextColumn::make('eventPackage.remaining_photos')
|
|
->label(__('admin.events.table.remaining_photos'))
|
|
->badge()
|
|
->color(fn ($state) => $state < 1 ? 'danger' : 'success')
|
|
->getStateUsing(fn ($record) => $record->eventPackage?->remaining_photos ?? 0),
|
|
Tables\Columns\TextColumn::make('primary_join_token')
|
|
->label(__('admin.events.table.join'))
|
|
->getStateUsing(function ($record) {
|
|
$token = $record->joinTokens()->orderByDesc('created_at')->first();
|
|
|
|
return $token ? url('/e/'.$token->token) : __('admin.events.table.no_join_tokens');
|
|
})
|
|
->description(function ($record) {
|
|
$total = $record->joinTokens()->count();
|
|
|
|
return $total > 0
|
|
? __('admin.events.table.join_tokens_total', ['count' => $total])
|
|
: __('admin.events.table.join_tokens_missing');
|
|
})
|
|
->copyable()
|
|
->copyMessage(__('admin.events.messages.join_link_copied')),
|
|
Tables\Columns\TextColumn::make('created_at')->since(),
|
|
])
|
|
->modifyQueryUsing(function (Builder $query) {
|
|
if ($tenantId = Auth::user()?->tenant_id) {
|
|
$query->where('tenant_id', $tenantId);
|
|
}
|
|
})
|
|
->filters([])
|
|
->actions([
|
|
Actions\EditAction::make(),
|
|
Actions\Action::make('toggle')
|
|
->label(__('admin.events.actions.toggle_active'))
|
|
->icon('heroicon-o-power')
|
|
->action(fn($record) => $record->update(['is_active' => !$record->is_active])),
|
|
Actions\Action::make('join_tokens')
|
|
->label(__('admin.events.actions.join_link_qr'))
|
|
->icon('heroicon-o-qr-code')
|
|
->modalHeading(__('admin.events.modal.join_link_heading'))
|
|
->modalSubmitActionLabel(__('admin.common.close'))
|
|
->modalWidth('xl')
|
|
->modalContent(function ($record) {
|
|
$tokens = $record->joinTokens()
|
|
->orderByDesc('created_at')
|
|
->get()
|
|
->map(function ($token) use ($record) {
|
|
$layouts = JoinTokenLayoutRegistry::toResponse(function (string $layoutId, string $format) use ($record, $token) {
|
|
return route('tenant.events.join-tokens.layouts.download', [
|
|
'event' => $record->slug,
|
|
'joinToken' => $token->getKey(),
|
|
'layout' => $layoutId,
|
|
'format' => $format,
|
|
]);
|
|
});
|
|
|
|
return [
|
|
'id' => $token->id,
|
|
'label' => $token->label,
|
|
'token' => $token->token,
|
|
'url' => url('/e/'.$token->token),
|
|
'usage_limit' => $token->usage_limit,
|
|
'usage_count' => $token->usage_count,
|
|
'expires_at' => optional($token->expires_at)->toIso8601String(),
|
|
'revoked_at' => optional($token->revoked_at)->toIso8601String(),
|
|
'is_active' => $token->isActive(),
|
|
'created_at' => optional($token->created_at)->toIso8601String(),
|
|
'layouts' => $layouts,
|
|
'layouts_url' => route('tenant.events.join-tokens.layouts.index', [
|
|
'event' => $record->slug,
|
|
'joinToken' => $token->getKey(),
|
|
]),
|
|
];
|
|
});
|
|
|
|
return view('filament.events.join-link', [
|
|
'event' => $record,
|
|
'tokens' => $tokens,
|
|
]);
|
|
}),
|
|
])
|
|
->bulkActions([
|
|
Actions\DeleteBulkAction::make(),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListEvents::route('/'),
|
|
'create' => Pages\CreateEvent::route('/create'),
|
|
'view' => Pages\ViewEvent::route('/{record}'),
|
|
'edit' => Pages\EditEvent::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
EventPackagesRelationManager::class,
|
|
];
|
|
}
|
|
}
|