mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
LibraryItemType enum added
This commit is contained in:
50
app/Enums/LibraryItemType.php
Normal file
50
app/Enums/LibraryItemType.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use ArchTech\Enums\From;
|
||||
use ArchTech\Enums\InvokableCases;
|
||||
use ArchTech\Enums\Options;
|
||||
use ArchTech\Enums\Values;
|
||||
|
||||
enum LibraryItemType: string
|
||||
{
|
||||
use InvokableCases;
|
||||
use Values;
|
||||
use Options;
|
||||
use From;
|
||||
|
||||
case Book = 'book';
|
||||
case BlogArticle = 'blog_article';
|
||||
case MarkdownArticle = 'markdown_article';
|
||||
case YoutubeVideo = 'youtube_video';
|
||||
case VimeoVideo = 'vimeo_video';
|
||||
case PodcastEpisode = 'podcast_episode';
|
||||
case DownloadableFile = 'downloadable_file';
|
||||
|
||||
public static function labels(): array
|
||||
{
|
||||
return [
|
||||
'book' => __('Book'),
|
||||
'blog_article' => __('Article'),
|
||||
'markdown_article' => __('Markdown Article'),
|
||||
'youtube_video' => __('Youtube Video'),
|
||||
'vimeo_video' => __('Vimeo Video'),
|
||||
'podcast_episode' => __('Podcast Episode'),
|
||||
'downloadable_file' => __('Downloadable File'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function icons(): array
|
||||
{
|
||||
return [
|
||||
'book' => 'book',
|
||||
'blog_article' => 'newspaper',
|
||||
'markdown_article' => 'newspaper',
|
||||
'youtube_video' => 'video',
|
||||
'vimeo_video' => 'video',
|
||||
'podcast_episode' => 'podcast',
|
||||
'downloadable_file' => 'download',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Livewire\Tables;
|
||||
|
||||
use App\Enums\LibraryItemType;
|
||||
use App\Models\Library;
|
||||
use App\Models\LibraryItem;
|
||||
use App\Models\Tag;
|
||||
@@ -11,6 +12,7 @@ use Rappasoft\LaravelLivewireTables\Views\Column;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Columns\ImageColumn;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter;
|
||||
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
|
||||
use Spatie\LaravelOptions\Options;
|
||||
|
||||
class LibraryItemTable extends DataTableComponent
|
||||
{
|
||||
@@ -78,6 +80,22 @@ class LibraryItemTable extends DataTableComponent
|
||||
fn($query) => $query->where('libraries.name', 'ilike', "%$value%"));
|
||||
}
|
||||
}),
|
||||
SelectFilter::make('Art')
|
||||
->options(
|
||||
collect(
|
||||
Options::forEnum(LibraryItemType::class)
|
||||
->toArray()
|
||||
)
|
||||
->mapWithKeys(fn($value, $key) => [$value['value'] => $value['label']])
|
||||
->prepend('Alle', '')
|
||||
->toArray()
|
||||
)
|
||||
->filter(function (Builder $builder, string $value) {
|
||||
if ($value === 'Alle') {
|
||||
return;
|
||||
}
|
||||
$builder->where('library_items.type', $value);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -102,6 +120,15 @@ class LibraryItemTable extends DataTableComponent
|
||||
Column::make("Name", "name")
|
||||
->sortable(),
|
||||
Column::make("Art", "type")
|
||||
->format(
|
||||
function ($value, $row, Column $column) {
|
||||
return '<span class="inline-flex items-center rounded-full bg-amber-400 px-2.5 py-0.5 text-base font-medium text-gray-900"><i class="mr-2 fa fa-thin fa-'
|
||||
.LibraryItemType::icons()[$value]
|
||||
.'"></i>'
|
||||
.LibraryItemType::labels()[$value]
|
||||
.'</span>';
|
||||
})
|
||||
->html()
|
||||
->sortable(),
|
||||
Column::make("Tags")
|
||||
->label(
|
||||
@@ -117,8 +144,8 @@ class LibraryItemTable extends DataTableComponent
|
||||
public function builder(): Builder
|
||||
{
|
||||
$shouldBePublic = request()
|
||||
->route()
|
||||
->getName() !== 'library.lecturer';
|
||||
->route()
|
||||
->getName() !== 'library.lecturer';
|
||||
|
||||
return LibraryItem::query()
|
||||
->whereHas('libraries', fn($query) => $query->where('libraries.is_public', $shouldBePublic))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Nova;
|
||||
|
||||
use App\Enums\LibraryItemType;
|
||||
use Ebess\AdvancedNovaMediaLibrary\Fields\Files;
|
||||
use Ebess\AdvancedNovaMediaLibrary\Fields\Images;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -11,6 +12,7 @@ use Laravel\Nova\Fields\Code;
|
||||
use Laravel\Nova\Fields\ID;
|
||||
use Laravel\Nova\Fields\Select;
|
||||
use Laravel\Nova\Fields\Text;
|
||||
use Spatie\LaravelOptions\Options;
|
||||
use Spatie\TagsField\Tags;
|
||||
|
||||
class LibraryItem extends Resource
|
||||
@@ -74,15 +76,7 @@ class LibraryItem extends Resource
|
||||
|
||||
Select::make('Type')
|
||||
->options(
|
||||
[
|
||||
'book' => 'book',
|
||||
'blog_article' => 'blog_article',
|
||||
'markdown_article' => 'markdown_article',
|
||||
'youtube_video' => 'youtube_video',
|
||||
'vimeo_video' => 'vimeo_video',
|
||||
'podcast_episode' => 'podcast_episode',
|
||||
'downloadable_file' => 'downloadable_file',
|
||||
]
|
||||
Options::forEnum(LibraryItemType::class)->toArray()
|
||||
)
|
||||
->rules('required', 'string'),
|
||||
|
||||
@@ -92,7 +86,7 @@ class LibraryItem extends Resource
|
||||
|
||||
BelongsTo::make('Lecturer'),
|
||||
|
||||
BelongsTo::make('Episode'),
|
||||
BelongsTo::make('Episode')->rules(['nullable']),
|
||||
|
||||
BelongsToMany::make('Library', 'libraries', Library::class),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user