wip
This commit is contained in:
1 parent
965c7fca90
commit
d077b6a429
26 files changed
+134
-123
No files matched your search
+22
-26
@@ -4,6 +4,7 @@ namespace App\Livewire;
|
||||
|
||||
use App\Filament\Tables\Columns\MapperLeftColumn;
|
||||
use App\Livewire\Mapper\LoadEvents;
|
||||
use App\Livewire\Mapper\SearchString;
|
||||
use App\Livewire\Mapper\StoreMapped;
|
||||
use App\Models\CompetitionGroup;
|
||||
use App\Models\Country;
|
||||
@@ -43,7 +44,7 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
|
||||
|
||||
public $elements_swopped = false;
|
||||
|
||||
public $search_left = false;
|
||||
public $search_values = [];
|
||||
|
||||
protected $listeners = [
|
||||
'refreshMapperLeft' => '$refresh',
|
||||
@@ -51,26 +52,18 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
|
||||
|
||||
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 = '';
|
||||
if (($key = array_search($field, $this->search_values)) !== false) {
|
||||
unset($this->search_values[$key]);
|
||||
}
|
||||
|
||||
$this->dispatch('refreshMapperLeft');
|
||||
}
|
||||
|
||||
#[Lazy]
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(LoadEvents::load($this->search_left, auth()->user()->sport_id))
|
||||
->query(LoadEvents::load($this->search_values))
|
||||
->striped()
|
||||
->columns([
|
||||
IconColumn::make('country.icon')->icon(fn (string $state): string => $state)->label(''),
|
||||
TextColumn::make('competition_group.name')->label('Group')
|
||||
@@ -100,6 +93,7 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
|
||||
FusedGroup::make([
|
||||
Select::make('country_id')
|
||||
->placeholder('Country')
|
||||
->visible(fn () => auth()->user()->sport_id != 5)
|
||||
->hiddenLabel()
|
||||
->searchable()
|
||||
->preload()
|
||||
@@ -139,7 +133,6 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
|
||||
->label('')
|
||||
->searchable()
|
||||
->options(function (Get $get) {
|
||||
$map = Country::all()->pluck('name', 'id')->toArray();
|
||||
|
||||
$query = CompetitionGroup::where('sport_id', auth()->user()->sport_id)
|
||||
->whereHas('event', function ($query) {
|
||||
@@ -150,6 +143,7 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
|
||||
if ($get('country_id') ?? null) {
|
||||
$res = $query->where('country_id', $get('country_id'))->get();
|
||||
} else {
|
||||
|
||||
$timeframe = $get('starttime_period') ?? null;
|
||||
|
||||
if ($timeframe['start'] || $timeframe['end']) {
|
||||
@@ -170,9 +164,14 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
|
||||
}
|
||||
});
|
||||
}
|
||||
$res = $query->groupBy('country_id')->get();
|
||||
if (auth()->user()->sport_id != 5) {
|
||||
$res = $query->groupBy('country_id')->get();
|
||||
} else {
|
||||
$res = $query->get();
|
||||
}
|
||||
}
|
||||
$arr = [];
|
||||
$map = Country::all()->pluck('name', 'id')->toArray();
|
||||
foreach ($res as $value) {
|
||||
if (isset($map[$value->country_id])) {
|
||||
$arr[$value->id] = $map[$value->country_id].' '.$value->name;
|
||||
@@ -233,9 +232,8 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
|
||||
});
|
||||
})->indicateUsing(function (): array {
|
||||
$indicators = [];
|
||||
if ($this->search_left) {
|
||||
$searchValues = preg_split('/\s+/', $this->search_left, -1, PREG_SPLIT_NO_EMPTY);
|
||||
foreach ($searchValues as $value) {
|
||||
if ($this->search_values) {
|
||||
foreach ($this->search_values as $value) {
|
||||
$indicators[] = Indicator::make($value)->removeField($value)->color('info');
|
||||
}
|
||||
}
|
||||
@@ -254,7 +252,7 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
|
||||
->icon('phosphor-x')
|
||||
->size(Size::Small)
|
||||
->action(function (Component $livewire) {
|
||||
$this->search_left = '';
|
||||
$this->search_values = [];
|
||||
$this->tableSearch = ''; // Clears the main search bar
|
||||
$livewire->fill(['tableSearch' => '']);
|
||||
$livewire->resetTableFiltersForm(); // Clears all filters
|
||||
@@ -271,12 +269,11 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
|
||||
#[On('search_left')]
|
||||
public function searchLeft($str)
|
||||
{
|
||||
$this->search_values = SearchString::explode($str);
|
||||
|
||||
foreach ($this->tableFilters['events'] as $key => $value) {
|
||||
$this->tableFilters['events'][$key] = null;
|
||||
}
|
||||
|
||||
$this->search_left = $str;
|
||||
// foreach ($this->search_values as $key => $value) {
|
||||
// $this->tableFilters['events'][$key] = null;
|
||||
// }
|
||||
|
||||
$this->dispatch('refreshMapperLeft');
|
||||
}
|
||||
@@ -295,8 +292,7 @@ class MapperLeft extends Component implements HasActions, HasSchemas, HasTable
|
||||
})
|
||||
->action(function ($arguments) {
|
||||
StoreMapped::store($arguments, $this->elements_swopped);
|
||||
$this->search_right = '';
|
||||
$this->search_left = '';
|
||||
$this->search_values = [];
|
||||
$this->dispatch('refreshMapperLeft');
|
||||
$this->dispatch('refreshMapperRight');
|
||||
|
||||
|
||||
Reference in new issue
Block a user