filters changed

This commit is contained in:
Benjamin Takats
2022-12-13 15:26:45 +01:00
parent 45c8bca808
commit 06c027fe01
12 changed files with 103 additions and 38 deletions

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Http\Livewire\BookCase;
use App\Models\Country;
use Livewire\Component;
class CityTable extends Component
{
public Country $country;
public function render()
{
return view('livewire.book-case.city-table');
}
}

View File

@@ -3,6 +3,7 @@
namespace App\Http\Livewire\Tables; namespace App\Http\Livewire\Tables;
use App\Models\BitcoinEvent; use App\Models\BitcoinEvent;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent; use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column; use Rappasoft\LaravelLivewireTables\Views\Column;
@@ -56,4 +57,10 @@ class BitcoinEventTable extends DataTableComponent
->sortable(), ->sortable(),
]; ];
} }
public function builder(): Builder
{
return BitcoinEvent::query()
->whereHas('venue.city.country', fn($query) => $query->where('code', $this->country));
}
} }

View File

@@ -49,6 +49,7 @@ class BookCaseTable extends DataTableComponent
{ {
return [ return [
TextFilter::make('By IDs', 'byids') TextFilter::make('By IDs', 'byids')
->hiddenFromMenus()
->filter(function (Builder $builder, string $value) { ->filter(function (Builder $builder, string $value) {
$builder->whereIn('id', str($value)->explode(',')); $builder->whereIn('id', str($value)->explode(','));
}), }),

View File

@@ -14,6 +14,7 @@ class CityTable extends DataTableComponent
use Actions; use Actions;
public string $country; public string $country;
public string $type;
protected $model = City::class; protected $model = City::class;
@@ -39,10 +40,9 @@ class CityTable extends DataTableComponent
public function columns(): array public function columns(): array
{ {
return [ $columns = collect([]);
Column::make("Stadt Name", "name") if($this->type === 'school') {
->sortable() $columns = $columns->merge([
->searchable(),
Column::make('Veranstaltungs-Orte') Column::make('Veranstaltungs-Orte')
->label( ->label(
fn($row, Column $column) => $row->venues_count fn($row, Column $column) => $row->venues_count
@@ -53,11 +53,23 @@ class CityTable extends DataTableComponent
fn($row, Column $column) => $row->events_count fn($row, Column $column) => $row->events_count
) )
->collapseOnMobile(), ->collapseOnMobile(),
]);
}
if ($this->type === 'bookCase') {
$columns = $columns->merge([
Column::make("Stadt Name", "name")
->sortable()
->searchable(),
Column::make('') Column::make('')
->label( ->label(
fn($row, Column $column) => view('columns.cities.action')->withRow($row) fn($row, Column $column) => view('columns.cities.action')
->withRow($row)
->withType($this->type)
), ),
]; ]);
}
return $columns->toArray();
} }
public function builder(): Builder public function builder(): Builder
@@ -94,13 +106,18 @@ class CityTable extends DataTableComponent
$city = City::query() $city = City::query()
->find($id); ->find($id);
$query = BookCase::radius($city->latitude, $city->longitude, 5); $query = BookCase::radius($city->latitude, $city->longitude, 5);
$ids = $query->pluck('id');
if ($ids->isEmpty()) {
$this->notification()
->error(__('No bookcases found in the radius of 5km'));
return;
}
return to_route('bookCases.table.bookcases', [ return to_route('bookCases.table.bookcases', [
'#table', '#table',
'country' => $this->country,
'table' => [ 'table' => [
'filters' => [ 'filters' => [
'byids' => $query->pluck('id') 'byids' => $ids->implode(',')
->implode(',')
], ],
] ]
]); ]);

View File

@@ -71,6 +71,7 @@ class MeetupEventTable extends DataTableComponent
public function builder(): Builder public function builder(): Builder
{ {
return MeetupEvent::query() return MeetupEvent::query()
->whereHas('meetup.city.country', fn($query) => $query->where('code', $this->country))
->with([ ->with([
'meetup', 'meetup',
]); ]);

View File

@@ -55,6 +55,7 @@ class MeetupTable extends DataTableComponent
public function builder(): Builder public function builder(): Builder
{ {
return Meetup::query() return Meetup::query()
->whereHas('city.country', fn($query) => $query->where('code', $this->country))
->withCount([ ->withCount([
'meetupEvents', 'meetupEvents',
]); ]);

View File

@@ -1,14 +1,18 @@
<div class="flex flex-col space-y-1"> <div class="flex flex-col space-y-1">
@if($type === 'school')
<div> <div>
<x-button amber wire:click="proximitySearch({{ $row->id }})" class="text-21gray"> <x-button amber wire:click="proximitySearch({{ $row->id }})" class="text-21gray">
<i class="fa fa-thin fa-person-chalkboard mr-2"></i> <i class="fa fa-thin fa-person-chalkboard mr-2"></i>
Umkreis-Suche Kurs-Termin {{ $row->name }} (100km) Umkreis-Suche Kurs-Termin {{ $row->name }} (100km)
</x-button> </x-button>
</div> </div>
{{--<div> @endif
@if($type === 'bookCase')
<div>
<x-button amber wire:click="proximitySearchForBookCases({{ $row->id }})" class="text-21gray"> <x-button amber wire:click="proximitySearchForBookCases({{ $row->id }})" class="text-21gray">
<i class="fa fa-thin fa-book mr-2"></i> <i class="fa fa-thin fa-book mr-2"></i>
Umkreis-Suche Bücher-Schrank {{ $row->name }} (5km) Umkreis-Suche Bücher-Schrank {{ $row->name }} (5km)
</x-button> </x-button>
</div>--}} </div>
@endif
</div> </div>

View File

@@ -0,0 +1,12 @@
<div class="bg-21gray flex flex-col h-screen justify-between">
{{-- HEADER --}}
<livewire:frontend.header :country="$country"/>
{{-- MAIN --}}
<section class="w-full mb-12">
<div class="max-w-screen-2xl mx-auto px-2 sm:px-10 space-y-4" id="table">
<livewire:tables.city-table :country="$country->code" type="bookCase"/>
</div>
</section>
{{-- FOOTER --}}
<livewire:frontend.footer/>
</div>

View File

@@ -51,6 +51,10 @@
@endif @endif
@endif @endif
@if(str(request()->route()->getName())->contains('bookCases.')) @if(str(request()->route()->getName())->contains('bookCases.'))
<a href="{{ route('bookCases.table.city', ['country' => $c]) }}"
class="{{ request()->routeIs('bookCases.table.city') ? 'text-amber-500 underline' : 'text-gray-400' }} mr-5 font-medium leading-6 hover:text-gray-300">
Stadt-Suche
</a>
<a href="{{ route('bookCases.table.bookcases', ['country' => $c]) }}" <a href="{{ route('bookCases.table.bookcases', ['country' => $c]) }}"
class="{{ request()->routeIs('bookCases.table.bookcases') ? 'text-amber-500 underline' : 'text-gray-400' }} mr-5 font-medium leading-6 hover:text-gray-300"> class="{{ request()->routeIs('bookCases.table.bookcases') ? 'text-amber-500 underline' : 'text-gray-400' }} mr-5 font-medium leading-6 hover:text-gray-300">
Bücher-Schränke Bücher-Schränke

View File

@@ -121,7 +121,7 @@
</div> </div>
<div <div
class="row-span-2 col-span-full sm:col-span-1 md:col-start-3 xl:col-start-3 sm:row-start-3 md:row-start-1 xl:row-start-3"> class="row-span-2 col-span-full sm:col-span-1 md:col-start-3 xl:col-start-3 sm:row-start-3 md:row-start-1 xl:row-start-3">
<a href="{{ route('bookCases.table.bookcases', ['country' => $c]) }}" <a href="{{ route('bookCases.table.city', ['country' => $c]) }}"
class="relative flex flex-col items-start justify-end w-full h-full overflow-hidden bg-black shadow-lg rounded-xl group" class="relative flex flex-col items-start justify-end w-full h-full overflow-hidden bg-black shadow-lg rounded-xl group"
style="aspect-ratio: 1/1;"> style="aspect-ratio: 1/1;">
<div class="absolute inset-0 w-full h-full"> <div class="absolute inset-0 w-full h-full">

View File

@@ -4,7 +4,7 @@
{{-- MAIN --}} {{-- MAIN --}}
<section class="w-full mb-12"> <section class="w-full mb-12">
<div class="max-w-screen-2xl mx-auto px-2 sm:px-10 space-y-4" id="table"> <div class="max-w-screen-2xl mx-auto px-2 sm:px-10 space-y-4" id="table">
<livewire:tables.city-table :country="$country->code"/> <livewire:tables.city-table :country="$country->code" type="school"/>
</div> </div>
</section> </section>
{{-- FOOTER --}} {{-- FOOTER --}}

View File

@@ -53,6 +53,9 @@ Route::middleware([])
->as('bookCases.') ->as('bookCases.')
->prefix('book-cases') ->prefix('book-cases')
->group(function () { ->group(function () {
Route::get('/{country:code}/table/city', \App\Http\Livewire\BookCase\CityTable::class)
->name('table.city');
Route::get('/table/book-case', \App\Http\Livewire\BookCase\BookCaseTable::class) Route::get('/table/book-case', \App\Http\Livewire\BookCase\BookCaseTable::class)
->name('table.bookcases'); ->name('table.bookcases');