145 lines
5.6 KiB
PHP
145 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Livewire\PlayerCalculator;
|
|
use App\Models\SofaScoreRosa;
|
|
use App\Models\User;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Concerns\InteractsWithForms;
|
|
use Filament\Support\Enums\SlideOverPosition;
|
|
use Filament\Support\Enums\Width;
|
|
use Filament\Tables\Columns\ViewColumn;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Filament\Widgets\TableWidget;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\HtmlString;
|
|
use Livewire\Attributes\On;
|
|
use Livewire\Attributes\Reactive;
|
|
|
|
class PlayerPropsTable extends TableWidget
|
|
{
|
|
use InteractsWithForms;
|
|
|
|
protected int|string|array $columnSpan = 2;
|
|
|
|
public string $team_name = '';
|
|
|
|
// #[Reactive]
|
|
public array $sourceRecords = [];
|
|
|
|
#[On('refreshFilters')]
|
|
public function refreshTable(?int $team_id = 0): void
|
|
{
|
|
if ($team_id) {
|
|
$this->team_name = SofaScoreRosa::where('ss_team_id', $team_id)->value('ss_team_name');
|
|
$this->sourceRecords = PlayerCalculator::load($team_id);
|
|
$this->resetTable();
|
|
}
|
|
}
|
|
|
|
public function getHeadingTable(): HtmlString
|
|
{
|
|
return new HtmlString('<div class="text-[11px] p-0 flex flex-row gap-4 font-bold font-mono" style="position: relative; left: -2px; bottom: -13px;">
|
|
<div>Gls</div>
|
|
<div>Fls</div>
|
|
<div>Ofs</div>
|
|
<div>Snt</div>
|
|
<div>Tsh</div>
|
|
<div>Crd</div>
|
|
<div>Foot</div>
|
|
<div>Evt</div>
|
|
<div>Min Ø</div>
|
|
</div>');
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->headerActions([
|
|
Action::make('esc')
|
|
->hiddenLabel()
|
|
->tooltip('Clear all (esc)')
|
|
->icon('phosphor-x-circle')
|
|
->color('gray')
|
|
->keyBindings(['esc'])
|
|
->action(fn () => $this->resetFilters()),
|
|
Action::make('lineups')
|
|
->tooltip('Lineups explanation')
|
|
->color('success')
|
|
->hiddenLabel()
|
|
->icon('phosphor-question-mark')
|
|
->slideOver()
|
|
->slideOverPosition(SlideOverPosition::Start)
|
|
->modalWidth(Width::ExtraLarge)
|
|
->modalSubmitAction(false)
|
|
->modalCancelAction(false)
|
|
->modalContent(fn () => view('filament.modals.position-abbreviation')),
|
|
Action::make('reset')
|
|
->hiddenLabel()
|
|
->tooltip('Remove all')
|
|
->icon('phosphor-arrows-clockwise')
|
|
->action(fn () => $this->clearResultTable()),
|
|
Action::make('calculate')
|
|
->tooltip('Calculate')
|
|
->hiddenLabel()
|
|
->icon('phosphor-calculator')
|
|
->action(fn () => $this->calculateAspg()),
|
|
Action::make('copy_results')
|
|
->tooltip('Copy results for pasting into a spread sheet')
|
|
->hiddenLabel()
|
|
->icon('phosphor-copy')
|
|
->action(fn () => $this->copyResult()),
|
|
Action::make('copy_development')
|
|
->tooltip('Copy calculation variables')
|
|
->hiddenLabel()
|
|
->hidden(fn () => ! in_array(Auth::user()->id, [1, 2]))
|
|
->color('warning')
|
|
->icon('phosphor-copy')
|
|
->action(fn () => $this->copyDevelopment()),
|
|
])
|
|
->heading($this->team_name)
|
|
->query(User::query()->whereRaw('1 = 0')) // Verhindert DB-Abfragen
|
|
->striped()
|
|
->defaultSort('name')
|
|
->emptyStateHeading('No team selected')
|
|
->columns([
|
|
ViewColumn::make('drag_card')
|
|
->label(fn () => $this->getHeadingTable())
|
|
->view('filament.tables.columns.drag-card'),
|
|
])->extraAttributes([
|
|
'id' => 'playerdragtable',
|
|
])
|
|
->filters([
|
|
SelectFilter::make('area')
|
|
->columnSpanFull()
|
|
->native(false)
|
|
->options([
|
|
'attack' => '<span class="text-amber-500">Attack</span>',
|
|
'midfield' => '<span class="text-blue-500">Midfield</span>',
|
|
'defence' => '<span class="text-green-500">Defence</span>',
|
|
'goalkeeper' => '<span class="text-gray-500">Goalkeeper</span>',
|
|
])->modifyFormFieldUsing(fn (Select $component) => $component->allowHtml())
|
|
->query(function ($query) {
|
|
return $query;
|
|
})->indicateUsing(function (array $data): array {
|
|
// WICHTIG: Ein leeres Array sorgt dafür, dass kein Indicator-Badge erzeugt wird
|
|
return [];
|
|
}),
|
|
], layout: FiltersLayout::AboveContent)
|
|
->deferFilters(false)
|
|
->records(function () {
|
|
$collection = collect($this->sourceRecords);
|
|
$selectedPosition = $this->tableFilters['area']['value'] ?? null;
|
|
if (! empty($selectedPosition)) {
|
|
$collection = $collection->where('area', $selectedPosition);
|
|
}
|
|
|
|
return $collection;
|
|
});
|
|
}
|
|
}
|