wip event mapper

This commit is contained in:
salam committed 2026-02-04 12:47:48 +01:00
1 parent 75b8c6c3ab
commit 3a289dd776
17 files changed
+273 -157

No files matched your search

+114 -24
View File
@@ -10,6 +10,7 @@ use App\Models\Country;
use App\Models\Event;
use App\Models\Mapper;
use Carbon\Carbon;
use CodeWithKyrian\FilamentDateRange\Forms\Components\DateRangePicker;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
@@ -18,7 +19,10 @@ use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Support\Enums\Alignment;
use Filament\Support\Enums\FontWeight;
use Filament\Support\Enums\Size;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Filament\Tables\Enums\FiltersLayout;
@@ -68,10 +72,74 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
return $table
->query(LoadEvents::load($this->search_left, auth()->user()->sport_id))
->columns([
TextColumn::make('starttime')
->sortable()
->time('H:i')
->alignCenter()
->description(fn ($record): string => Carbon::parse($record->starttime)->format('d. M. y')),
IconColumn::make('country.icon')->icon(fn (string $state): string => $state)->label(''),
TextColumn::make('competition_group.name')->label('Group')
->wrap()
->tooltip('Click to filter by this group')
->description(fn ($record): string => $record->country->name)
->action(function ($record) {
if (! in_array($record->competition_group_id, $this->tableFilters['events']['competition_group_id'])) {
$this->tableFilters['events']['competition_group_id'][] = (string) $record->competition_group_id;
$this->dispatch('refreshMapperRight');
}
}),
TextColumn::make('home.name')
->label('Home')
->color('home')
->weight(FontWeight::Bold)
->alignRight(),
IconColumn::make('id')->icon('phosphor-minus')->label('')->color('black'),
TextColumn::make('away.name')
->color('away')
->label('Away')
->weight(FontWeight::Bold),
MapperLeftColumn::make('left')->label(''),
])->recordActions([
Action::make('search_home')
->iconButton()
->icon('phosphor-magnifying-glass')
->color('home')
->action(function ($record) {
$this->dispatch('search_right', $record->home->name);
}),
Action::make('search_away')
->icon('phosphor-magnifying-glass')
->iconButton()
->color('away')
->action(function ($record) {
$this->dispatch('search_right', $record->away->name);
}),
// Action::make('drag_left')
// ->icon('phosphor-arrows-out')
// ->iconButton()
// ->extraAttributes([
// 'x-data' => '{ moveoverleft: false }',
// 'x-on' => '{
// dragstart = {
// self: dragging = true;
// event.dataTransfer.effectAllowed = "move;
// event.dataTransfer.setData("text/plain", event.target.id)
// },
// dragover = {
// prevent: "moveoverleft = true"
// },
// dragleave = {
// prevent: "moveoverleft = false"
// }
// }',
// ])
// ->action(function ($record) {
// $this->dispatch('search_right', $record->away->name);
// }),
])
->defaultSort('starttime')
->searchable(['home.name', 'away.name'])
->defaultPaginationPageOption(5)
->defaultPaginationPageOption(10)
->filters([
Filter::make('events')
->schema([
@@ -79,7 +147,6 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
->placeholder('Country')
->hiddenLabel()
// ->multiple()
->columnSpan(2)
->searchable()
->preload()
->options(function () {
@@ -96,31 +163,25 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
->placeholder('League')
->hiddenLabel()
->label('')
->columnSpan(2)
->multiple()
->searchable()
->options(function (Get $get) {
if ($get('country_id')) {
$res = Event::query()->where('sport_id', auth()->user()->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->where('country_id', $get('country_id'))->groupBy('competition_group_id')->pluck('competition_group_id')->toArray();
} else {
$res = Event::query()->where('sport_id', auth()->user()->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->pluck('competition_group_id')->toArray();
}
$comps = CompetitionGroup::with('country')->where('id', $res)->get();
$arr = [];
foreach ($comps as $val) {
if (isset($val->country->name)) {
$arr[$val->id] = $val->country->name.' - '.$val->name;
} else {
$arr[$val->id] = $val->name;
}
}
asort($arr);
return $arr;
return CompetitionGroup::where('sport_id', auth()->user()->sport_id)
->whereHas('event', function ($query) {
$query->where('starttime', '>', now())
->where('betradar_id', 0);
})
->orderBy('name')
->pluck('name', 'id');
})
->live(),
DateRangePicker::make('starttime_period')
->columnSpan(2)
->displayFormat('d M Y')
->minDate(now())
->hiddenLabel()
->label('')
->live(),
])
->query(function (Builder $query, array $data): Builder {
return $query
@@ -129,8 +190,36 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
fn (Builder $query, $country_id) => $query->where('country_id', $country_id)
)->when(
$data['competition_group_id'],
fn (Builder $query, $competition_group_id) => $query->whereIn('competition_group_id', $competition_group_id)
);
function (Builder $query, $competition_group_id) {
$this->setPage(1);
return $query->whereIn('competition_group_id', $competition_group_id);
}
)->when(
$data['starttime_period'],
function (Builder $query, $starttime_period) {
// dd($starttime_period);
if (isset($starttime_period['start']) && isset($starttime_period['end'])) {
$from = Carbon::createFromDate($starttime_period['start']);
$end = Carbon::createFromDate($starttime_period['end']);
return $query
->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00'))
->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00'));
} elseif (isset($starttime_period['start'])) {
$from = Carbon::createFromDate($starttime_period['start']);
return $query
->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00'));
} elseif (isset($starttime_period['end'])) {
$end = Carbon::createFromDate($starttime_period['end']);
return $query
->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00'));
}
});
})->indicateUsing(function (): array {
$indicators = [];
if ($this->search_left) {
@@ -150,6 +239,7 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
->toolbarActions([
Action::make('refreshMapperLeft')
->hiddenLabel()
->color('gray')
->icon('phosphor-x')
->size(Size::Small)
->action(function (Component $livewire) {