mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
search
This commit is contained in:
@@ -15,6 +15,7 @@ class LibraryTable extends Component
|
|||||||
public Country $country;
|
public Country $country;
|
||||||
public array $filters = [];
|
public array $filters = [];
|
||||||
public Collection $libraryItems;
|
public Collection $libraryItems;
|
||||||
|
public bool $isLecturerPage = false;
|
||||||
|
|
||||||
public string $search = '';
|
public string $search = '';
|
||||||
|
|
||||||
@@ -23,19 +24,22 @@ class LibraryTable extends Component
|
|||||||
protected $queryString = [
|
protected $queryString = [
|
||||||
'currentTab' => ['except' => '*'],
|
'currentTab' => ['except' => '*'],
|
||||||
'filters' => ['except' => ''],
|
'filters' => ['except' => ''],
|
||||||
'search' => ['except' => ''],
|
'search' => ['except' => ''],
|
||||||
];
|
];
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
{
|
{
|
||||||
|
if (str(request()
|
||||||
|
->route()
|
||||||
|
->getName())->contains(['.lecturer'])) {
|
||||||
|
$this->isLecturerPage = true;
|
||||||
|
}
|
||||||
$this->loadLibraryItems($this->search);
|
$this->loadLibraryItems($this->search);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loadLibraryItems($term = null)
|
public function loadLibraryItems($term = null)
|
||||||
{
|
{
|
||||||
$shouldBePublic = request()
|
$shouldBePublic = !$this->isLecturerPage;
|
||||||
->route()
|
|
||||||
->getName() !== 'library.table.lecturer';
|
|
||||||
if (!$shouldBePublic && !auth()->user()->is_lecturer) {
|
if (!$shouldBePublic && !auth()->user()->is_lecturer) {
|
||||||
abort(403);
|
abort(403);
|
||||||
}
|
}
|
||||||
@@ -61,8 +65,9 @@ class LibraryTable extends Component
|
|||||||
->when($term, fn($query) => $query
|
->when($term, fn($query) => $query
|
||||||
->where('name', 'ilike', '%'.$term.'%')
|
->where('name', 'ilike', '%'.$term.'%')
|
||||||
->orWhere(fn($query) => $query
|
->orWhere(fn($query) => $query
|
||||||
->when(count($searchTags) > 0, fn($query) => $query->whereHas('tags',
|
->when(count($searchTags) > 0 && count($this->filters) < 1,
|
||||||
fn($query) => $query->whereIn('tags.id', $searchTags)))
|
fn($query) => $query->whereHas('tags',
|
||||||
|
fn($query) => $query->whereIn('tags.id', $searchTags)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
->when($this->currentTab !== '*', fn($query) => $query
|
->when($this->currentTab !== '*', fn($query) => $query
|
||||||
@@ -88,11 +93,18 @@ class LibraryTable extends Component
|
|||||||
$this->loadLibraryItems($value);
|
$this->loadLibraryItems($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function resetFiltering($isLecturerPage = false)
|
||||||
|
{
|
||||||
|
if ($isLecturerPage) {
|
||||||
|
return to_route('library.table.lecturer', ['country' => $this->country, 'currentTab' => '*']);
|
||||||
|
} else {
|
||||||
|
return to_route('library.table.libraryItems', ['country' => $this->country, 'currentTab' => '*']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
$shouldBePublic = request()
|
$shouldBePublic = !$this->isLecturerPage;
|
||||||
->route()
|
|
||||||
->getName() !== 'library.table.lecturer';
|
|
||||||
$libraries = \App\Models\Library::query()
|
$libraries = \App\Models\Library::query()
|
||||||
->whereNull('parent_id')
|
->whereNull('parent_id')
|
||||||
->where('is_public', $shouldBePublic)
|
->where('is_public', $shouldBePublic)
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
@else
|
@else
|
||||||
<h3 class="text-2xl font-medium leading-6 text-gray-200">{{ __('Libraries') }}</h3>
|
<h3 class="text-2xl font-medium leading-6 text-gray-200">{{ __('Libraries') }}</h3>
|
||||||
@endif
|
@endif
|
||||||
|
<x-button wire:click="resetFiltering({{ $isLecturerPage }})"
|
||||||
|
xs>{{ __('Reset filtering and search') }}</x-button>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
<!-- Dropdown menu on small screens -->
|
<!-- Dropdown menu on small screens -->
|
||||||
@@ -37,14 +39,12 @@
|
|||||||
@php
|
@php
|
||||||
$currentLibraryClass = $currentTab === $library['name'] ? 'border-amber-500 text-amber-600' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300';
|
$currentLibraryClass = $currentTab === $library['name'] ? 'border-amber-500 text-amber-600' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300';
|
||||||
@endphp
|
@endphp
|
||||||
@if(!request()->isXmlHttpRequest())
|
@if($isLecturerPage)
|
||||||
@if(str(request()->route()->getName())->contains(['.lecturer']))
|
<a href="{{ route('library.table.lecturer', ['country' => $country, 'currentTab' => $library['name']]) }}"
|
||||||
<a href="{{ route('library.table.lecturer', ['country' => $country, 'currentTab' => $library['name']]) }}"
|
class="{{ $currentLibraryClass }} whitespace-nowrap pb-4 px-1 border-b-2 font-medium text-sm">{{ $library['name'] }}</a>
|
||||||
class="{{ $currentLibraryClass }} whitespace-nowrap pb-4 px-1 border-b-2 font-medium text-sm">{{ $library['name'] }}</a>
|
@else
|
||||||
@else
|
<a href="{{ route('library.table.libraryItems', ['country' => $country, 'currentTab' => $library['name']]) }}"
|
||||||
<a href="{{ route('library.table.libraryItems', ['country' => $country, 'currentTab' => $library['name']]) }}"
|
class="{{ $currentLibraryClass }} whitespace-nowrap pb-4 px-1 border-b-2 font-medium text-sm">{{ $library['name'] }}</a>
|
||||||
class="{{ $currentLibraryClass }} whitespace-nowrap pb-4 px-1 border-b-2 font-medium text-sm">{{ $library['name'] }}</a>
|
|
||||||
@endif
|
|
||||||
@endif
|
@endif
|
||||||
@endforeach
|
@endforeach
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
Reference in New Issue
Block a user