Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(manage): add in-line display order editing for leaderboards and achievements #2710

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/Filament/Resources/AchievementResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ public static function table(Table $table): Table
->searchable()
->toggleable(isToggledHiddenByDefault: true),

Tables\Columns\TextColumn::make('DisplayOrder')
->numeric()
Tables\Columns\TextInputColumn::make('DisplayOrder')
->label('Display Order')
->sortable()
->alignEnd()
->rules(['required', 'integer'])
->toggleable(isToggledHiddenByDefault: true),

Tables\Columns\TextColumn::make('DateCreated')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;

class AchievementsRelationManager extends RelationManager
Expand All @@ -29,7 +30,7 @@ class AchievementsRelationManager extends RelationManager
public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
{
/** @var User $user */
$user = auth()->user();
$user = Auth::user();

if ($ownerRecord instanceof Game) {
return $user->can('manage', $ownerRecord);
Expand All @@ -51,7 +52,7 @@ public function form(Form $form): Form
public function table(Table $table): Table
{
/** @var User $user */
$user = auth()->user();
$user = Auth::user();

return $table
->recordTitleAttribute('title')
Expand Down Expand Up @@ -95,7 +96,9 @@ public function table(Table $table): Table
->date()
->toggleable(),

Tables\Columns\TextColumn::make('DisplayOrder')
Tables\Columns\TextInputColumn::make('DisplayOrder')
->label('Display Order')
->rules(['required', 'integer'])
->toggleable(),
])
->filters([
Expand Down Expand Up @@ -223,7 +226,7 @@ public function table(Table $table): Table
])
->recordUrl(function (Achievement $record): string {
/** @var User $user */
$user = auth()->user();
$user = Auth::user();

if ($user->can('update', $record)) {
return route('filament.admin.resources.achievements.edit', ['record' => $record]);
Expand Down Expand Up @@ -254,7 +257,7 @@ public function reorderTable(array $order): void
parent::reorderTable($order);

/** @var User $user */
$user = auth()->user();
$user = Auth::user();
/** @var Game $game */
$game = $this->getOwnerRecord();

Expand All @@ -272,7 +275,7 @@ public function reorderTable(array $order): void
if (!$recentReorderingActivity) {
activity()
->useLog('default')
->causedBy(auth()->user())
->causedBy($user)
->performedOn($game)
->event('reorderedAchievements')
->log('Reordered Achievements');
Expand All @@ -287,7 +290,7 @@ public function reorderTable(array $order): void
private function canReorderAchievements(): bool
{
/** @var User $user */
$user = auth()->user();
$user = Auth::user();

/** @var Game $game */
$game = $this->getOwnerRecord();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ public function table(Table $table): Table
->label('Lower Is Better')
->toggleable(isToggledHiddenByDefault: true),

Tables\Columns\TextColumn::make('DisplayOrder')
Tables\Columns\TextInputColumn::make('DisplayOrder')
->label('Display Order')
->color(fn ($record) => $record->DisplayOrder < 0 ? 'danger' : null)
->toggleable(),
->rules(['required', 'integer']),
])
->searchPlaceholder('Search (ID, Title)')
->filters([
Expand Down Expand Up @@ -114,7 +113,7 @@ public function table(Table $table): Table
->bulkActions([

])
->paginated([25, 50, 100])
->paginated([50, 100, 150])
->defaultSort(function (Builder $query): Builder {
return $query
->orderBy('DisplayOrder')
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Resources/LeaderboardResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ public static function table(Table $table): Table
});
}),

Tables\Columns\TextColumn::make('DisplayOrder')
Tables\Columns\TextInputColumn::make('DisplayOrder')
->label('Display Order')
->rules(['required', 'integer'])
->sortable()
->toggleable(),
])
Expand Down
1 change: 1 addition & 0 deletions app/Models/Achievement.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function getActivitylogOptions(): LogOptions
'Points',
'Title',
'type',
'DisplayOrder',
])
->logOnlyDirty()
->dontSubmitEmptyLogs();
Expand Down
1 change: 1 addition & 0 deletions app/Models/Leaderboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function getActivitylogOptions(): LogOptions
'Description',
'Format',
'LowerIsBetter',
'DisplayOrder',
])
->logOnlyDirty()
->dontSubmitEmptyLogs();
Expand Down