place calculator an separate page

This commit is contained in:
salam committed 2026-09-14 12:33:40 +02:00
1 parent 26052c6cfd
commit ed8a50d044
14 files changed
+777 -306

No files matched your search

+39 -85
View File
@@ -2,138 +2,92 @@
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\Filters\Filter;
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 int $team_id;
public string $team_name = '';
public array $players;
// #[Reactive]
public array $sourceRecords = [];
#[On('refreshFilters')]
public function refreshTable(?int $team_id = 0): void
#[On('update-players')]
public function updatePlayers(array $players)
{
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();
}
$this->players = $players;
}
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>
return new HtmlString('
<div class="w-full grid grid-cols-15 text-[10px] items-center gap-1" style="position: relative; left: -10px; 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)
->heading(false)
->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())
->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())
Filter::make('positions')
->columnSpan(2)
->schema([
Select::make('area')
->hiddenLabel()
->placeholder('Filter Positions')
->native(false)
->allowHtml()
->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>',
]),
])
->query(function ($query) {
return $query;
})->indicateUsing(function (array $data): array {
// WICHTIG: Ein leeres Array sorgt dafür, dass kein Indicator-Badge erzeugt wird
// empty array disables indicator-badge
return [];
}),
], layout: FiltersLayout::AboveContent)
->deferFilters(false)
->records(function () {
$collection = collect($this->sourceRecords);
$selectedPosition = $this->tableFilters['area']['value'] ?? null;
$collection = collect($this->players);
$selectedPosition = $this->tableFilters['positions']['area'] ?? null;
if (! empty($selectedPosition)) {
$collection = $collection->where('area', $selectedPosition);
}