120 lines
4.5 KiB
PHP
120 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use App\Filament\Tables\Columns\MapperRightColumn;
|
|
use App\Models\Event;
|
|
use App\Models\Mapper;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\Concerns\InteractsWithActions;
|
|
use Filament\Actions\Contracts\HasActions;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
|
use Filament\Schemas\Contracts\HasSchemas;
|
|
use Filament\Support\Enums\Alignment;
|
|
use Filament\Tables\Concerns\InteractsWithTable;
|
|
use Filament\Tables\Contracts\HasTable;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\Filter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Livewire\Component;
|
|
|
|
class MapperRight extends Component implements HasActions, HasSchemas, HasTable
|
|
{
|
|
use InteractsWithActions;
|
|
use InteractsWithSchemas;
|
|
use InteractsWithTable;
|
|
|
|
protected $listeners = [
|
|
'reload_data' => '$refresh',
|
|
];
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->query(Mapper::query())
|
|
->columns([
|
|
MapperRightColumn::make('right')->label(''),
|
|
])->searchable(['home', 'away'])
|
|
->defaultPaginationPageOption(5)
|
|
->filters([
|
|
Filter::make('events')
|
|
->schema([
|
|
Select::make('group_cc')
|
|
->placeholder('Country')
|
|
->hiddenLabel()
|
|
->label('')
|
|
->relationship('country_betsapi', 'name')
|
|
->searchable()
|
|
->preload()
|
|
->multiple()
|
|
->columnSpan(2)
|
|
->live()
|
|
->reactive()
|
|
->placeholder('Country')
|
|
->label('Countries'),
|
|
Select::make('group_id')
|
|
->placeholder('League')
|
|
->hiddenLabel()
|
|
->label('')
|
|
->options(fn () => Mapper::groupBy('group_id')->pluck('group', 'group_id'))
|
|
->columnSpan(2)
|
|
->searchable()
|
|
->preload()
|
|
->multiple()
|
|
->live()
|
|
->placeholder('League')
|
|
->label('Leagues'),
|
|
])
|
|
->query(function (Builder $query, array $data): Builder {
|
|
return $query
|
|
->when(
|
|
$data['group_cc'],
|
|
fn (Builder $query, $group_cc) => $query->where('group_cc', $group_cc)
|
|
)->when(
|
|
$data['group_id'],
|
|
fn (Builder $query, $group_id) => $query->whereIn('group_id', $group_id)
|
|
);
|
|
})
|
|
->columns(4)->columnSpan(4),
|
|
], layout: FiltersLayout::AboveContent)
|
|
// ->hiddenFilterIndicators()
|
|
->filtersFormColumns(3)
|
|
->deferFilters(false)
|
|
->toolbarActions([
|
|
Action::make('reload_data')
|
|
->hiddenLabel()
|
|
->color('gray')
|
|
->icon('phosphor-x')
|
|
->action(function (Component $livewire) {
|
|
$livewire->resetTableFiltersForm(); // Clears all filters
|
|
$livewire->tableSearch = ''; // Clears the main search bar
|
|
$this->dispatch('reload_data');
|
|
}),
|
|
]);
|
|
}
|
|
|
|
public function rightAction(): Action
|
|
{
|
|
return Action::make('right')
|
|
->modalHeading('Event Mapper')
|
|
->modalContent(function (array $arguments) {
|
|
$event = Event::where('id', $arguments['match_id'])->first();
|
|
$mapper = Mapper::where('event_id', $arguments['event_id'])->first();
|
|
|
|
return view('livewire.confirm-mapping', ['event' => $event, 'mapper' => $mapper, 'mappermode' => 'linear']);
|
|
})
|
|
->modalAlignment(Alignment::Center)
|
|
->modalFooterActionsAlignment(Alignment::Center)
|
|
->modalWidth('2xl')
|
|
->modalSubmitActionLabel('Confirm')
|
|
->modalSubmitAction();
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.mapper-left');
|
|
}
|
|
}
|