feat: hunts dashboard

This commit is contained in:
Leon 2026-01-08 12:49:18 +01:00
parent 2b63ff47e9
commit d38e847551
5 changed files with 213 additions and 0 deletions

View File

@ -0,0 +1,106 @@
<?php
namespace App\Filament\Resources\Hunts;
use App\Filament\Resources\Hunts\Pages\CreateHunts;
use App\Filament\Resources\Hunts\Pages\EditHunts;
use App\Filament\Resources\Hunts\Pages\ListHunts;
use App\Models\Hunts;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use App\Enums\HuntStatus;
use Filament\Schemas\Schema;
use BackedEnum;
use App\Enums\HuntDifficulty;
use Filament\Actions\EditAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\BulkActionGroup;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\DateTimePicker;
class HuntsResource extends Resource
{
protected static ?string $model = Hunts::class;
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-map';
public static function form(Schema $schema): Schema
{
return $schema
->components([
TextInput::make('title')
->required()
->maxLength(255),
Textarea::make('description')
->columnSpanFull(),
Select::make('status')
->options(HuntStatus::class)
->required(),
Select::make('difficulty')
->options(HuntDifficulty::class)
->required(),
TextInput::make('city')
->required()
->maxLength(255),
DateTimePicker::make('start_at'),
DateTimePicker::make('end_at'),
TextInput::make('latitude')
->numeric(),
TextInput::make('longitude')
->numeric(),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('title')
->searchable(),
Tables\Columns\TextColumn::make('status')
->searchable(),
Tables\Columns\TextColumn::make('difficulty'),
Tables\Columns\TextColumn::make('city')
->searchable(),
Tables\Columns\TextColumn::make('start_at')
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->actions([
EditAction::make(),
])
->bulkActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListHunts::route('/'),
'create' => CreateHunts::route('/create'),
'edit' => EditHunts::route('/{record}/edit'),
];
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\Hunts\Pages;
use App\Filament\Resources\Hunts\HuntsResource;
use Filament\Resources\Pages\CreateRecord;
class CreateHunts extends CreateRecord
{
protected static string $resource = HuntsResource::class;
}

View File

@ -0,0 +1,11 @@
<?php
namespace App\Filament\Resources\Hunts\Pages;
use App\Filament\Resources\Hunts\HuntsResource;
use Filament\Resources\Pages\EditRecord;
class EditHunts extends EditRecord
{
protected static string $resource = HuntsResource::class;
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\Hunts\Pages;
use App\Filament\Resources\Hunts\HuntsResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListHunts extends ListRecords
{
protected static string $resource = HuntsResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Policies;
use App\Models\Hunts;
use App\Models\User;
use App\Enums\UserRole;
class HuntsPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->role === UserRole::ADMIN || $user->role === UserRole::ORGA;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, Hunts $hunts): bool
{
return $user->role === UserRole::ADMIN || $user->role === UserRole::ORGA;
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->role === UserRole::ADMIN || $user->role === UserRole::ORGA;
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Hunts $hunts): bool
{
return $user->role === UserRole::ADMIN || $user->role === UserRole::ORGA;
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Hunts $hunts): bool
{
return $user->role === UserRole::ADMIN;
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Hunts $hunts): bool
{
return $user->role === UserRole::ADMIN;
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Hunts $hunts): bool
{
return $user->role === UserRole::ADMIN;
}
}