mapper ok
This commit is contained in:
1 parent
2e57e49f08
commit
c617935e2f
18 files changed
+227
-97
No files matched your search
@@ -16,16 +16,21 @@ 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\Size;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\Indicator;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Lazy;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
|
||||
#[Lazy]
|
||||
class MapperRight extends Component implements HasActions, HasSchemas, HasTable
|
||||
{
|
||||
use InteractsWithActions;
|
||||
@@ -34,14 +39,33 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable
|
||||
|
||||
public $elements_swopped = false;
|
||||
|
||||
public $search_right = false;
|
||||
|
||||
protected $listeners = [
|
||||
'reload_data' => '$refresh',
|
||||
'reload_data_right' => '$refresh',
|
||||
];
|
||||
|
||||
public function removeTableFilter(string $filterName, ?string $field = null, bool $shouldTriggerUpdatedFiltersHook = true): void
|
||||
{
|
||||
$searchValues = preg_split('/\s+/', $this->search_right, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
if (($key = array_search($field, $searchValues)) !== false) {
|
||||
unset($searchValues[$key]);
|
||||
}
|
||||
|
||||
if ($searchValues) {
|
||||
$this->search_right = implode(' ', $searchValues);
|
||||
} else {
|
||||
$this->search_right = '';
|
||||
}
|
||||
|
||||
$this->dispatch('reload_data_right');
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(LoadProvider::load())
|
||||
->query(LoadProvider::load($this->search_right))
|
||||
->columns([
|
||||
MapperRightColumn::make('right')->label(''),
|
||||
])->searchable(['home', 'away'])
|
||||
@@ -119,6 +143,16 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable
|
||||
$data['group_id'],
|
||||
fn (Builder $query, $group_id) => $query->whereIn('group_id', $group_id)
|
||||
);
|
||||
})->indicateUsing(function (): array {
|
||||
$indicators = [];
|
||||
if ($this->search_right) {
|
||||
$searchValues = preg_split('/\s+/', $this->search_right, -1, PREG_SPLIT_NO_EMPTY);
|
||||
foreach ($searchValues as $value) {
|
||||
$indicators[] = Indicator::make($value)->removeField($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
->columns(4)->columnSpan(4),
|
||||
], layout: FiltersLayout::AboveContent)
|
||||
@@ -127,13 +161,17 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable
|
||||
->filtersFormColumns(3)
|
||||
->deferFilters(false)
|
||||
->toolbarActions([
|
||||
Action::make('reload_data')
|
||||
Action::make('reload_data_right')
|
||||
->hiddenLabel()
|
||||
->color('gray')
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->icon('phosphor-x')
|
||||
->color('danger')
|
||||
->size(Size::Small)
|
||||
->action(function (Component $livewire) {
|
||||
$livewire->resetTableFiltersForm(); // Clears all filters
|
||||
$this->search_right = '';
|
||||
$this->tableSearch = ''; // Clears the main search bar
|
||||
$livewire->fill(['tableSearch' => '']);
|
||||
$livewire->resetTableFiltersForm(); // Clears all filters
|
||||
$this->dispatch('reload_data_right');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
@@ -143,6 +181,29 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable
|
||||
$this->elements_swopped = ! $this->elements_swopped;
|
||||
}
|
||||
|
||||
#[On('search_right')]
|
||||
public function searchRight($str)
|
||||
{
|
||||
$this->search_right = $str;
|
||||
|
||||
$this->dispatch('reload_data_right');
|
||||
}
|
||||
|
||||
// In the same Table class
|
||||
protected function removeTableFilters(): void
|
||||
{
|
||||
// Custom logic before or after removing filters
|
||||
// Example: Log the action
|
||||
\Log::info('Custom filter removal logic triggered.');
|
||||
|
||||
// Call the parent method to perform the default removal
|
||||
parent::removeTableFilters();
|
||||
|
||||
// Or, if you want full control, you can manually clear:
|
||||
// $this->tableFilters = [];
|
||||
// $this->dispatch('refresh-table');
|
||||
}
|
||||
|
||||
public function rightAction(): Action
|
||||
{
|
||||
return Action::make('right')
|
||||
@@ -156,6 +217,10 @@ class MapperRight extends Component implements HasActions, HasSchemas, HasTable
|
||||
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('reload_data_left');
|
||||
$this->dispatch('reload_data_right');
|
||||
})
|
||||
->closeModalByEscaping(false)
|
||||
->modalCloseButton(false)
|
||||
|
||||
Reference in new issue
Block a user