-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Events a separate entity in management app (#3024)
- Loading branch information
Showing
27 changed files
with
1,273 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ enum ImageUploadType | |
{ | ||
case News; | ||
case HubBadge; | ||
case GameBadge; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Extensions\Resources\Resource; | ||
use App\Filament\Resources\EventAchievementResource\Pages; | ||
use App\Models\Achievement; | ||
use App\Models\EventAchievement; | ||
use App\Models\Game; | ||
use App\Models\User; | ||
use Filament\Forms; | ||
use Filament\Forms\Form; | ||
use Filament\Infolists; | ||
use Filament\Infolists\Infolist; | ||
use Filament\Pages\Page; | ||
|
||
class EventAchievementResource extends Resource | ||
{ | ||
protected static ?string $model = EventAchievement::class; | ||
|
||
protected static ?string $recordTitleAttribute = 'title'; | ||
|
||
protected static bool $shouldRegisterNavigation = false; | ||
|
||
public static function infolist(Infolist $infolist): Infolist | ||
{ | ||
return $infolist | ||
->columns(1) | ||
->schema([ | ||
Infolists\Components\Section::make() | ||
->schema([ | ||
Infolists\Components\TextEntry::make('source_achievement_id') | ||
->label('Source Achievement') | ||
->formatStateUsing(function (int $state): string { | ||
$achievement = Achievement::find($state); | ||
|
||
return "[{$achievement->id}] {$achievement->title}"; | ||
}), | ||
Infolists\Components\TextEntry::make('active_from') | ||
->label('Active From') | ||
->date(), | ||
Infolists\Components\TextEntry::make('active_through') | ||
->label('Active Through') | ||
->date(), | ||
]) | ||
->columns(['xl' => 4, 'md' => 2]), | ||
|
||
Infolists\Components\Section::make('Source Achievement') | ||
->relationship('sourceAchievement') | ||
->columns(['xl' => 2, '2xl' => 3]) | ||
->schema([ | ||
Infolists\Components\Group::make() | ||
->schema([ | ||
Infolists\Components\ImageEntry::make('badge_url') | ||
->label('Badge') | ||
->size(config('media.icon.lg.width')), | ||
Infolists\Components\ImageEntry::make('badge_locked_url') | ||
->label('Badge (locked)') | ||
->size(config('media.icon.lg.width')), | ||
]), | ||
|
||
Infolists\Components\Group::make() | ||
->schema([ | ||
Infolists\Components\TextEntry::make('Title'), | ||
|
||
Infolists\Components\TextEntry::make('Description'), | ||
|
||
Infolists\Components\TextEntry::make('game') | ||
->label('Game') | ||
->formatStateUsing(fn (Game $state) => '[' . $state->id . '] ' . $state->title) | ||
->url(fn (EventAchievement $record): string => $record->sourceAchievement->game->getCanonicalUrlAttribute()), | ||
|
||
Infolists\Components\TextEntry::make('developer') | ||
->label('Author') | ||
->formatStateUsing(fn (User $state) => $state->display_name), | ||
]), | ||
|
||
Infolists\Components\Group::make() | ||
->schema([ | ||
Infolists\Components\TextEntry::make('canonical_url') | ||
->label('Canonical URL') | ||
->url(fn (EventAchievement $record): string => $record->sourceAchievement->getCanonicalUrlAttribute()), | ||
Infolists\Components\TextEntry::make('permalink') | ||
->url(fn (EventAchievement $record): string => $record->sourceAchievement->getPermalinkAttribute()), | ||
]), | ||
]) | ||
->hidden(fn ($record) => !$record->sourceAchievement), | ||
]); | ||
} | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->columns(1) | ||
->schema([ | ||
Forms\Components\Section::make() | ||
->columns(['xl' => 4, 'md' => 2]) | ||
->schema([ | ||
Forms\Components\Select::make('source_achievement_id') | ||
->label('Source Achievement') | ||
->columnSpan(2) | ||
->searchable() | ||
->getSearchResultsUsing(function (string $search): array { | ||
return Achievement::where('Title', 'like', "%{$search}%") | ||
->orWhere('ID', 'like', "%{$search}%") | ||
->limit(50) | ||
->get() | ||
->mapWithKeys(function ($achievement) { | ||
return [$achievement->id => "[{$achievement->id}] {$achievement->title}"]; | ||
}) | ||
->toArray(); | ||
}) | ||
->getOptionLabelUsing(function (int $value): string { | ||
$achievement = Achievement::find($value); | ||
|
||
return "[{$achievement->id}] {$achievement->title}"; | ||
}), | ||
|
||
Forms\Components\DatePicker::make('active_from') | ||
->label('Active From') | ||
->native(false) | ||
->date(), | ||
|
||
Forms\Components\DatePicker::make('active_through') | ||
->label('Active Through') | ||
->native(false) | ||
->date(), | ||
]), | ||
]); | ||
} | ||
|
||
public static function getRecordSubNavigation(Page $page): array | ||
{ | ||
return $page->generateNavigationItems([ | ||
Pages\Details::class, | ||
Pages\AuditLog::class, | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\Index::route('/'), | ||
'view' => Pages\Details::route('/{record}'), | ||
'edit' => Pages\Edit::route('/{record}/edit'), | ||
'audit-log' => Pages\AuditLog::route('/{record}/audit-log'), | ||
]; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/Filament/Resources/EventAchievementResource/Pages/AuditLog.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\EventAchievementResource\Pages; | ||
|
||
use App\Filament\Pages\ResourceAuditLog; | ||
use App\Filament\Resources\EventAchievementResource; | ||
use App\Models\EventAchievement; | ||
use Illuminate\Support\Collection; | ||
|
||
class AuditLog extends ResourceAuditLog | ||
{ | ||
protected static string $resource = EventAchievementResource::class; | ||
|
||
protected function createFieldLabelMap(): Collection | ||
{ | ||
$fieldLabelMap = parent::createFieldLabelMap(); | ||
|
||
$fieldLabelMap['active_until'] = 'Active Until'; | ||
|
||
return $fieldLabelMap; | ||
} | ||
|
||
public function getBreadcrumbs(): array | ||
{ | ||
/** @var EventAchievement $eventAchievement */ | ||
$eventAchievement = $this->record; | ||
$game = $eventAchievement->achievement->game; | ||
$event = $game->event; | ||
|
||
return [ | ||
route('filament.admin.resources.events.index') => 'Events', | ||
route('filament.admin.resources.events.view', $event) => $game->title, | ||
route('filament.admin.resources.event-achievements.view', $eventAchievement) => $eventAchievement->achievement->title, | ||
'Audit Log', | ||
]; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/Filament/Resources/EventAchievementResource/Pages/Details.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\EventAchievementResource\Pages; | ||
|
||
use App\Filament\Resources\EventAchievementResource; | ||
use App\Models\EventAchievement; | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ViewRecord; | ||
|
||
class Details extends ViewRecord | ||
{ | ||
protected static string $resource = EventAchievementResource::class; | ||
|
||
public function getBreadcrumbs(): array | ||
{ | ||
/** @var EventAchievement $eventAchievement */ | ||
$eventAchievement = $this->record; | ||
$game = $eventAchievement->achievement->game; | ||
$event = $game->event; | ||
|
||
return [ | ||
route('filament.admin.resources.events.index') => 'Events', | ||
route('filament.admin.resources.events.view', $event) => $game->title, | ||
route('filament.admin.resources.event-achievements.view', $eventAchievement) => $eventAchievement->achievement->title, | ||
'View', | ||
]; | ||
} | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\EditAction::make(), | ||
]; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/Filament/Resources/EventAchievementResource/Pages/Edit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\EventAchievementResource\Pages; | ||
|
||
use App\Filament\Concerns\HasFieldLevelAuthorization; | ||
use App\Filament\Resources\EventAchievementResource; | ||
use App\Models\EventAchievement; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class Edit extends EditRecord | ||
{ | ||
use HasFieldLevelAuthorization; | ||
|
||
protected static string $resource = EventAchievementResource::class; | ||
|
||
public function getBreadcrumbs(): array | ||
{ | ||
/** @var EventAchievement $eventAchievement */ | ||
$eventAchievement = $this->record; | ||
$game = $eventAchievement->achievement->game; | ||
$event = $game->event; | ||
|
||
return [ | ||
route('filament.admin.resources.events.index') => 'Events', | ||
route('filament.admin.resources.events.view', $event) => $game->title, | ||
route('filament.admin.resources.event-achievements.view', $eventAchievement) => $eventAchievement->achievement->title, | ||
'Edit', | ||
]; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Filament/Resources/EventAchievementResource/Pages/Index.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\EventAchievementResource\Pages; | ||
|
||
use App\Filament\Resources\EventAchievementResource; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class Index extends ListRecords | ||
{ | ||
protected static string $resource = EventAchievementResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
]; | ||
} | ||
} |
Oops, something went wrong.