'$refresh', ]; public function removeTableFilter(string $filterName, ?string $field = null, bool $shouldTriggerUpdatedFiltersHook = true): void { $searchValues = preg_split('/\s+/', $this->search_left, -1, PREG_SPLIT_NO_EMPTY); if (($key = array_search($field, $searchValues)) !== false) { unset($searchValues[$key]); } if ($searchValues) { $this->search_left = implode(' ', $searchValues); } else { $this->search_left = ''; } $this->dispatch('refreshMapperLeft'); } #[Lazy] public function table(Table $table): Table { return $table ->query(LoadEvents::load($this->search_left, auth()->user()->sport_id)) ->columns([ 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('starttime') ->sortable() ->time('H:i') ->alignCenter() ->description(fn ($record): string => Carbon::parse($record->starttime)->format('d. M. y')), MapperLeftColumn::make('left')->label(''), ]) ->defaultSort('starttime') ->searchable(['home.name', 'away.name']) ->defaultPaginationPageOption(10) ->filters([ Filter::make('events') ->schema([ Select::make('country_id') ->placeholder('Country') ->hiddenLabel() ->searchable() ->preload() ->options(function () { $res = Event::query()->where('sport_id', auth()->user()->sport_id)->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray(); return Country::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id'); }) ->live() ->reactive() ->afterStateUpdated(function (callable $set) { $set('competition_group_id', null); }), Select::make('competition_group_id') ->placeholder('League') ->hiddenLabel() ->label('') ->multiple() ->searchable() ->options(function (Get $get) { 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 ->when( $data['country_id'], fn (Builder $query, $country_id) => $query->where('country_id', $country_id) )->when( $data['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) { $searchValues = preg_split('/\s+/', $this->search_left, -1, PREG_SPLIT_NO_EMPTY); foreach ($searchValues as $value) { $indicators[] = Indicator::make($value)->removeField($value)->color('info'); } } return $indicators; }) ->columns(4)->columnSpan(4), ], layout: FiltersLayout::AboveContent) ->filtersFormColumns(3) ->persistFiltersInSession() ->deferFilters(false) ->toolbarActions([ Action::make('refreshMapperLeft') ->hiddenLabel() ->color('gray') ->icon('phosphor-x') ->size(Size::Small) ->action(function (Component $livewire) { $this->search_left = ''; $this->tableSearch = ''; // Clears the main search bar $livewire->fill(['tableSearch' => '']); $livewire->resetTableFiltersForm(); // Clears all filters $this->dispatch('refreshMapperLeft'); }), ]); } public function toggle() { $this->elements_swopped = ! $this->elements_swopped; } #[On('search_left')] public function searchLeft($str) { $this->search_left = $str; $this->dispatch('refreshMapperLeft'); } public function leftAction(): Action { return Action::make('left') ->modalHeading('Event Mapper') ->modalContent(function (array $arguments) { $event = Event::where('id', $arguments['id'])->first(); $mapper = Mapper::where('event_id', $arguments['event_id'])->first(); return view('livewire.confirm-mapping', ['event' => $event, 'mapper' => $mapper]); }) ->action(function ($arguments) { StoreMapped::store($arguments, $this->elements_swopped); $this->search_right = ''; $this->search_left = ''; $this->dispatch('refreshMapperLeft'); $this->dispatch('refreshMapperRight'); }) ->closeModalByEscaping(false) ->modalCloseButton(false) ->modalCancelAction(fn (Action $action) => $action->keyBindings(['c'])->tooltip('keyboard: "c"')) ->closeModalByClickingAway(false) ->modalAlignment(Alignment::Center) ->modalFooterActionsAlignment(Alignment::Center) ->modalWidth('2xl') ->modalSubmitActionLabel('Save') ->modalSubmitAction( fn (Action $action) => $action->keyBindings(['return'])->tooltip('keyboard: "return"') ); } public function render() { return view('livewire.mapper-left'); } }