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:
@@ -5,6 +5,8 @@ namespace App\Http\Livewire\Library;
|
||||
use App\Models\Country;
|
||||
use App\Models\Library;
|
||||
use App\Models\LibraryItem;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Livewire\Component;
|
||||
use RalphJSmit\Laravel\SEO\Support\SEOData;
|
||||
|
||||
@@ -12,15 +14,24 @@ class LibraryTable extends Component
|
||||
{
|
||||
public Country $country;
|
||||
public array $filters = [];
|
||||
public Collection $libraryItems;
|
||||
|
||||
public string $search = '';
|
||||
|
||||
public $currentTab = '*';
|
||||
|
||||
protected $queryString = [
|
||||
'currentTab' => ['except' => '*'],
|
||||
'filters' => ['except' => ''],
|
||||
'search' => ['except' => ''],
|
||||
];
|
||||
|
||||
public function render()
|
||||
public function mount()
|
||||
{
|
||||
$this->loadLibraryItems($this->search);
|
||||
}
|
||||
|
||||
public function loadLibraryItems($term = null)
|
||||
{
|
||||
$shouldBePublic = request()
|
||||
->route()
|
||||
@@ -29,6 +40,59 @@ class LibraryTable extends Component
|
||||
abort(403);
|
||||
}
|
||||
|
||||
if ($this->currentTab !== '*') {
|
||||
$parentLibrary = Library::query()
|
||||
->where('name', $this->currentTab)
|
||||
->first();
|
||||
}
|
||||
|
||||
$searchTags = [];
|
||||
if ($term) {
|
||||
$searchTags = Tag::where('name', 'ilike', '%'.$term.'%')
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
}
|
||||
|
||||
$this->libraryItems = LibraryItem::query()
|
||||
->with([
|
||||
'lecturer',
|
||||
'tags',
|
||||
])
|
||||
->when($term, fn($query) => $query
|
||||
->where('name', 'ilike', '%'.$term.'%')
|
||||
->orWhere(fn($query) => $query
|
||||
->when(count($searchTags) > 0, fn($query) => $query->whereHas('tags',
|
||||
fn($query) => $query->whereIn('tags.id', $searchTags)))
|
||||
)
|
||||
)
|
||||
->when($this->currentTab !== '*', fn($query) => $query
|
||||
->whereHas('libraries',
|
||||
fn($query) => $query
|
||||
->where('libraries.name', $this->currentTab)
|
||||
)
|
||||
->orWhereHas('libraries',
|
||||
fn($query) => $query
|
||||
->where('libraries.parent_id', $parentLibrary->id)
|
||||
)
|
||||
)
|
||||
->when(count($this->filters) > 0, fn($query) => $query->whereHas('tags',
|
||||
fn($query) => $query->whereIn('tags.id', $this->filters)))
|
||||
->whereHas('libraries',
|
||||
fn($query) => $query->where('libraries.is_public', $shouldBePublic))
|
||||
->orderByDesc('library_items.created_at')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function updatedSearch($value)
|
||||
{
|
||||
$this->loadLibraryItems($value);
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$shouldBePublic = request()
|
||||
->route()
|
||||
->getName() !== 'library.table.lecturer';
|
||||
$libraries = \App\Models\Library::query()
|
||||
->whereNull('parent_id')
|
||||
->where('is_public', $shouldBePublic)
|
||||
@@ -45,35 +109,8 @@ class LibraryTable extends Component
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->currentTab !== '*') {
|
||||
$parentLibrary = Library::query()
|
||||
->where('name', $this->currentTab)
|
||||
->first();
|
||||
}
|
||||
|
||||
return view('livewire.library.library-table', [
|
||||
'libraries' => $tabs,
|
||||
'libraryItems' => LibraryItem::query()
|
||||
->with([
|
||||
'lecturer',
|
||||
'tags',
|
||||
])
|
||||
->when($this->currentTab !== '*', fn($query) => $query
|
||||
->whereHas('libraries',
|
||||
fn($query) => $query
|
||||
->where('libraries.name', $this->currentTab)
|
||||
)
|
||||
->orWhereHas('libraries',
|
||||
fn($query) => $query
|
||||
->where('libraries.parent_id', $parentLibrary->id)
|
||||
)
|
||||
)
|
||||
->when(count($this->filters) > 0, fn($query) => $query->whereHas('tags',
|
||||
fn($query) => $query->whereIn('tags.id', $this->filters)))
|
||||
->whereHas('libraries',
|
||||
fn($query) => $query->where('libraries.is_public', $shouldBePublic))
|
||||
->orderByDesc('library_items.created_at')
|
||||
->get(),
|
||||
])->layout('layouts.app', [
|
||||
'SEOData' => new SEOData(
|
||||
title: __('Library'),
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
</div>
|
||||
</section>
|
||||
<section class="h-auto">
|
||||
<div class="px-10 py-6 mx-auto max-w-7xl">
|
||||
<div class="px-10 py-2 sm:py-6 mx-auto max-w-7xl">
|
||||
<div class="w-full mx-auto text-left md:text-center">
|
||||
|
||||
@if(str(request()->route()->getName())->contains('school.'))
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<div class="bg-21gray flex flex-col h-screen justify-between">
|
||||
{{-- HEADER --}}
|
||||
<livewire:frontend.header :country="$country"/>
|
||||
<div class="max-w-screen-2xl mx-auto">
|
||||
<div class="w-full mb-6 sm:my-6">
|
||||
<x-input class="sm:min-w-[900px]" placeholder="Suche..." wire:model.debounce="search"/>
|
||||
</div>
|
||||
</div>
|
||||
{{-- MAIN --}}
|
||||
<section class="w-full mb-12">
|
||||
<div class="max-w-screen-2xl mx-auto px-2 sm:px-10" id="table">
|
||||
@@ -32,8 +37,15 @@
|
||||
@php
|
||||
$currentLibraryClass = $currentTab === $library['name'] ? 'border-amber-500 text-amber-600' : 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300';
|
||||
@endphp
|
||||
<a href="{{ route(request()->route()->getName(), ['country' => $country, 'currentTab' => $library['name']]) }}"
|
||||
@if(!request()->isXmlHttpRequest())
|
||||
@if(str(request()->route()->getName())->contains(['.lecturer']))
|
||||
<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>
|
||||
@else
|
||||
<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>
|
||||
@endif
|
||||
@endif
|
||||
@endforeach
|
||||
</nav>
|
||||
</div>
|
||||
@@ -43,7 +55,8 @@
|
||||
<livewire:library.search-by-tag-component/>
|
||||
<div class="my-12">
|
||||
|
||||
<div class="mx-auto mt-12 grid max-w-lg gap-5 lg:max-w-none lg:grid-cols-3">
|
||||
<div wire:loading.class="opacity-25"
|
||||
class="mx-auto mt-12 grid max-w-lg gap-5 lg:max-w-none lg:grid-cols-3">
|
||||
|
||||
@foreach($libraryItems as $libraryItem)
|
||||
<div wire:key="library_item_{{ $libraryItem->id }}"
|
||||
@@ -70,7 +83,8 @@
|
||||
<div class="mt-6 flex items-center">
|
||||
<div class="flex-shrink-0">
|
||||
<div>
|
||||
<span class="sr-only text-gray-200">{{ $libraryItem->lecturer->name }}</span>
|
||||
<span
|
||||
class="sr-only text-gray-200">{{ $libraryItem->lecturer->name }}</span>
|
||||
<img class="h-10 w-10 rounded"
|
||||
src="{{ $libraryItem->lecturer->getFirstMediaUrl('avatar') }}"
|
||||
alt="{{ $libraryItem->lecturer->name }}">
|
||||
@@ -81,7 +95,8 @@
|
||||
<div class="text-gray-200">{{ $libraryItem->lecturer->name }}</div>
|
||||
</p>
|
||||
<div class="flex space-x-1 text-sm text-gray-400">
|
||||
<time datetime="2020-03-16">{{ $libraryItem->created_at->asDateTime() }}</time>
|
||||
<time
|
||||
datetime="2020-03-16">{{ $libraryItem->created_at->asDateTime() }}</time>
|
||||
@if($libraryItem->read_time)
|
||||
<span aria-hidden="true">·</span>
|
||||
<span>{{ $libraryItem->read_time }} {{ __('min read') }}</span>
|
||||
|
||||
Reference in New Issue
Block a user