From ef13ddbd850230d5b1d21d5e39c1593c61766166 Mon Sep 17 00:00:00 2001 From: Benjamin Takats Date: Fri, 20 Jan 2023 16:01:49 +0100 Subject: [PATCH] library with grid --- app/Http/Livewire/Library/LibraryTable.php | 15 ++++- .../Livewire/Library/SearchByTagComponent.php | 4 +- app/Http/Livewire/News/InternArticleView.php | 7 -- app/Observers/LibraryItemObserver.php | 4 +- resources/lang/de.json | 2 +- .../livewire/library/library-table.blade.php | 53 ++++++++++++++- .../library/search-by-tag-component.blade.php | 4 +- .../livewire/news/article-overview.blade.php | 18 ++--- .../news/intern-article-view.blade.php | 65 +++++++++++++++++-- 9 files changed, 140 insertions(+), 32 deletions(-) diff --git a/app/Http/Livewire/Library/LibraryTable.php b/app/Http/Livewire/Library/LibraryTable.php index 448d6402..86e11d45 100644 --- a/app/Http/Livewire/Library/LibraryTable.php +++ b/app/Http/Livewire/Library/LibraryTable.php @@ -3,17 +3,20 @@ namespace App\Http\Livewire\Library; use App\Models\Country; +use App\Models\LibraryItem; use Livewire\Component; use RalphJSmit\Laravel\SEO\Support\SEOData; class LibraryTable extends Component { public Country $country; + public array $filters = []; public $currentTab = '*'; protected $queryString = [ 'currentTab' => ['except' => '*'], + 'filters' => ['except' => ''], ]; public function render() @@ -42,7 +45,17 @@ class LibraryTable extends Component } return view('livewire.library.library-table', [ - 'libraries' => $tabs, + 'libraries' => $tabs, + 'libraryItems' => LibraryItem::query() + ->with([ + 'lecturer', + 'tags', + ]) + ->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)) + ->get(), ])->layout('layouts.app', [ 'SEOData' => new SEOData( title: __('Library'), diff --git a/app/Http/Livewire/Library/SearchByTagComponent.php b/app/Http/Livewire/Library/SearchByTagComponent.php index 3c63d2e3..b9deee91 100644 --- a/app/Http/Livewire/Library/SearchByTagComponent.php +++ b/app/Http/Livewire/Library/SearchByTagComponent.php @@ -8,10 +8,10 @@ use Livewire\Component; class SearchByTagComponent extends Component { public string $country = 'de'; - public ?array $library_items = []; + public array $filters = []; protected $queryString = [ - 'library_items', + 'filters' => ['except' => ''], ]; public function render() diff --git a/app/Http/Livewire/News/InternArticleView.php b/app/Http/Livewire/News/InternArticleView.php index 83ce4f7e..4c09c3e1 100644 --- a/app/Http/Livewire/News/InternArticleView.php +++ b/app/Http/Livewire/News/InternArticleView.php @@ -11,13 +11,6 @@ class InternArticleView extends Component { public LibraryItem $libraryItem; - public function mount() - { - if (!$this->libraryItem->createdBy->hasRole('news-editor')) { - abort(403, 'This article is not available for viewing.'); - } - } - public function render() { return view('livewire.news.intern-article-view')->layout('layouts.app', [ diff --git a/app/Observers/LibraryItemObserver.php b/app/Observers/LibraryItemObserver.php index c0040722..dc63afa2 100644 --- a/app/Observers/LibraryItemObserver.php +++ b/app/Observers/LibraryItemObserver.php @@ -37,8 +37,8 @@ class LibraryItemObserver if ($libraryItem->type !== 'markdown_article') { $text = sprintf("Es gibt was Neues zum Anschauen oder Anhören:\n\n%s\n\n%s\n\n#Bitcoin #Event #Einundzwanzig #gesundesgeld", $libraryItemName, - url()->route('library.table.libraryItems', - ['country' => 'de', 'library_items' => ['filters' => ['id' => $libraryItem->id]]]), + url()->route('article.view', + ['libraryItem' => $libraryItem->slug]), ); } else { $text = sprintf("Ein neuer News-Artikel wurde verfasst:\n\n%s\n\n%s\n\n#Bitcoin #News #Einundzwanzig #gesundesgeld", diff --git a/resources/lang/de.json b/resources/lang/de.json index 840e9d78..a419054a 100644 --- a/resources/lang/de.json +++ b/resources/lang/de.json @@ -678,7 +678,7 @@ "Main image caption": "Hauptbildunterschrift", "Time to read": "Zeit zum Lesen", "How many minutes to read?": "Wie viele Minuten zum Lesen?", - "Read": "Lesedauer", + "Read": "Lesen", "News": "", "Dezentral News": "", "min read": "Minuten Lesedauer", diff --git a/resources/views/livewire/library/library-table.blade.php b/resources/views/livewire/library/library-table.blade.php index 5bde007d..27b9dcfb 100644 --- a/resources/views/livewire/library/library-table.blade.php +++ b/resources/views/livewire/library/library-table.blade.php @@ -43,7 +43,58 @@
- +
+ + @foreach($libraryItems as $libraryItem) +
+
+ + {{ $libraryItem->name }} + +
+
+
+

+

{{ $libraryItem->tags->pluck('name')->join(', ') }}
+

+ +

{{ $libraryItem->name }}

+

{{ $libraryItem->excerpt }}

+
+
+
+
+
+ {{ $libraryItem->lecturer->name }} + {{ $libraryItem->lecturer->name }} +
+
+
+

+

{{ $libraryItem->lecturer->name }}
+

+
+ + @if($libraryItem->read_time) + + {{ $libraryItem->read_time }} {{ __('min read') }} + @endif +
+
+
+
+
+ @endforeach + +
+
diff --git a/resources/views/livewire/library/search-by-tag-component.blade.php b/resources/views/livewire/library/search-by-tag-component.blade.php index 472a88b1..84cd07d4 100644 --- a/resources/views/livewire/library/search-by-tag-component.blade.php +++ b/resources/views/livewire/library/search-by-tag-component.blade.php @@ -8,12 +8,12 @@ style="font-size: 128%; background-position: 0px center; list-style: outside;" > @php - $isActive = collect($library_items)->pluck('tag')->collapse()->contains($tag->name); + $isActive = in_array($tag->id, $filters['tag'] ?? [], false); $activeClass = $isActive ? 'text-amber-500 bg-amber-500' : 'bg-blue-50 text-white hover:text-amber-500'; @endphp
+ class="flex flex-col overflow-hidden rounded-lg shadow-[#F7931A] shadow-sm"> -
+
-

+

{{ $libraryItem->tags->pluck('name')->join(', ') }}
+ class="text-amber-500">{{ $libraryItem->tags->pluck('name')->join(', ') }}

-

{{ $libraryItem->name }}

-

{{ $libraryItem->excerpt }}

+

{{ $libraryItem->name }}

+

{{ $libraryItem->excerpt }}

- {{ $libraryItem->lecturer->name }} + {{ $libraryItem->lecturer->name }} {{ $libraryItem->lecturer->name }}
-

-

{{ $libraryItem->lecturer->name }}
+

+

{{ $libraryItem->lecturer->name }}

diff --git a/resources/views/livewire/news/intern-article-view.blade.php b/resources/views/livewire/news/intern-article-view.blade.php index d83000e9..afb9b7e1 100644 --- a/resources/views/livewire/news/intern-article-view.blade.php +++ b/resources/views/livewire/news/intern-article-view.blade.php @@ -2,10 +2,17 @@
- - - {{ __('Back to overview') }} - + @if($libraryItem->type === 'markdown_article') + + + {{ __('Back to overview') }} + + @else + + + {{ __('Back to overview') }} + + @endif
@@ -55,9 +62,53 @@
- - {!! $libraryItem->value !!} - +
+ @if(str($libraryItem->value)->contains('http')) + + + {{ __('Open') }} + + @endif + @if($libraryItem->type === 'downloadable_file') + + + {{ __('Download') }} + + @endif + @if($libraryItem->type === 'podcast_episode') + + + {{ __('Listen') }} + + @endif + @if($libraryItem->type !== 'markdown_article') + + + {{ __('Share link') }} + + @else + + + {{ __('Share link') }} + + @endif +
+ + @if($libraryItem->type === 'markdown_article') + + {!! $libraryItem->value !!} + + @endif