From 44b8d485a86dac463ee4bd06025382ee25cfaabb Mon Sep 17 00:00:00 2001 From: Benjamin Takats Date: Tue, 6 Dec 2022 20:19:52 +0100 Subject: [PATCH] LibraryItemType enum added --- app/Enums/LibraryItemType.php | 50 ++++++ app/Http/Livewire/Tables/LibraryItemTable.php | 31 +++- app/Nova/LibraryItem.php | 14 +- composer.json | 2 + composer.lock | 166 +++++++++++++----- config/options.php | 13 ++ lang/de.json | 7 + tailwind.config.js | 2 + 8 files changed, 226 insertions(+), 59 deletions(-) create mode 100644 app/Enums/LibraryItemType.php create mode 100644 config/options.php diff --git a/app/Enums/LibraryItemType.php b/app/Enums/LibraryItemType.php new file mode 100644 index 00000000..6e616e53 --- /dev/null +++ b/app/Enums/LibraryItemType.php @@ -0,0 +1,50 @@ + __('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', + ]; + } +} diff --git a/app/Http/Livewire/Tables/LibraryItemTable.php b/app/Http/Livewire/Tables/LibraryItemTable.php index bd45a480..fa8d2e75 100644 --- a/app/Http/Livewire/Tables/LibraryItemTable.php +++ b/app/Http/Livewire/Tables/LibraryItemTable.php @@ -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 '' + .LibraryItemType::labels()[$value] + .''; + }) + ->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)) diff --git a/app/Nova/LibraryItem.php b/app/Nova/LibraryItem.php index 27bfda1b..9bdabc26 100644 --- a/app/Nova/LibraryItem.php +++ b/app/Nova/LibraryItem.php @@ -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), diff --git a/composer.json b/composer.json index 83212a3b..c6a206e2 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "require": { "php": "^8.1", "akuechler/laravel-geoly": "^1.0", + "archtechx/enums": "^0.3.1", "ebess/advanced-nova-media-library": "^4.0", "ezadr/lnurl-php": "^1.0", "guzzlehttp/guzzle": "^7.2", @@ -30,6 +31,7 @@ "spatie/laravel-google-fonts": "^1.2", "spatie/laravel-markdown": "^2.2", "spatie/laravel-medialibrary": "^10.0.0", + "spatie/laravel-options": "^1.0", "spatie/laravel-ray": "^1.31", "spatie/laravel-sluggable": "^3.4", "spatie/laravel-tags": "^4.3", diff --git a/composer.lock b/composer.lock index f33b9562..65c72316 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9c4898684e578e46bb709340edf618e8", + "content-hash": "bdaacd0e3b0592028578169251930b7a", "packages": [ { "name": "akuechler/laravel-geoly", @@ -64,6 +64,52 @@ }, "time": "2021-04-20T07:17:32+00:00" }, + { + "name": "archtechx/enums", + "version": "v0.3.1", + "source": { + "type": "git", + "url": "https://github.com/archtechx/enums.git", + "reference": "373a86a16e7233a56dd942d422af2cc59a2becb3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/archtechx/enums/zipball/373a86a16e7233a56dd942d422af2cc59a2becb3", + "reference": "373a86a16e7233a56dd942d422af2cc59a2becb3", + "shasum": "" + }, + "require": { + "php": "^8.1" + }, + "require-dev": { + "nunomaduro/larastan": "^1.0|^2.0", + "orchestra/testbench": "^6.9|^7.0", + "pestphp/pest": "^1.2", + "pestphp/pest-plugin-laravel": "^1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "ArchTech\\Enums\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Samuel Štancl", + "email": "samuel@archte.ch" + } + ], + "description": "Helpers for making PHP enums more lovable.", + "support": { + "issues": "https://github.com/archtechx/enums/issues", + "source": "https://github.com/archtechx/enums/tree/v0.3.1" + }, + "time": "2022-08-24T22:27:44+00:00" + }, { "name": "bacon/bacon-qr-code", "version": "2.0.7", @@ -6918,6 +6964,78 @@ ], "time": "2022-12-06T07:29:40+00:00" }, + { + "name": "spatie/laravel-options", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-options.git", + "reference": "7631d2bb99b5b4b507293a4d8823c9244b4c18cb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-options/zipball/7631d2bb99b5b4b507293a4d8823c9244b4c18cb", + "reference": "7631d2bb99b5b4b507293a4d8823c9244b4c18cb", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^8.81|^9.0", + "php": "^8.1", + "spatie/laravel-package-tools": "^1.9.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.8", + "myclabs/php-enum": "^1.6", + "nunomaduro/collision": "^6.0|^5.0", + "nunomaduro/larastan": "^2.0.1|^1.0.3", + "orchestra/testbench": "^7.0|^v6.24.1", + "pestphp/pest": "^v1.21.3", + "pestphp/pest-plugin-laravel": "^1.1", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^9.5", + "spatie/enum": "^3.13", + "spatie/laravel-model-states": "^2.0", + "spatie/laravel-ray": "^1.26" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\LaravelOptions\\OptionsServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Spatie\\LaravelOptions\\": "src", + "Spatie\\LaravelOptions\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ruben Van Assche", + "email": "ruben@spatie.be", + "role": "Developer" + } + ], + "description": "Create arrays of options from different sources", + "homepage": "https://github.com/spatie/laravel-options", + "keywords": [ + "laravel", + "options", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/laravel-options/tree/1.0.3" + }, + "time": "2022-07-29T08:14:50+00:00" + }, { "name": "spatie/laravel-package-tools", "version": "1.13.7", @@ -11373,52 +11491,6 @@ } ], "packages-dev": [ - { - "name": "archtechx/enums", - "version": "v0.3.1", - "source": { - "type": "git", - "url": "https://github.com/archtechx/enums.git", - "reference": "373a86a16e7233a56dd942d422af2cc59a2becb3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/archtechx/enums/zipball/373a86a16e7233a56dd942d422af2cc59a2becb3", - "reference": "373a86a16e7233a56dd942d422af2cc59a2becb3", - "shasum": "" - }, - "require": { - "php": "^8.1" - }, - "require-dev": { - "nunomaduro/larastan": "^1.0|^2.0", - "orchestra/testbench": "^6.9|^7.0", - "pestphp/pest": "^1.2", - "pestphp/pest-plugin-laravel": "^1.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "ArchTech\\Enums\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Samuel Štancl", - "email": "samuel@archte.ch" - } - ], - "description": "Helpers for making PHP enums more lovable.", - "support": { - "issues": "https://github.com/archtechx/enums/issues", - "source": "https://github.com/archtechx/enums/tree/v0.3.1" - }, - "time": "2022-08-24T22:27:44+00:00" - }, { "name": "composer/semver", "version": "3.3.2", diff --git a/config/options.php b/config/options.php new file mode 100644 index 00000000..ba0b872e --- /dev/null +++ b/config/options.php @@ -0,0 +1,13 @@ + 'label', + + /* + * The key used in an option to describe the value of the option + */ + 'value_key' => 'value', +]; diff --git a/lang/de.json b/lang/de.json index 7f8f9eff..3b931524 100644 --- a/lang/de.json +++ b/lang/de.json @@ -1,4 +1,11 @@ { + "Book": "Buch", + "Article": "Artikel", + "Markdown Article": "Interner Artikel", + "Youtube Video": "Youtube Video", + "Vimeo Video": "Vimeo Video", + "Podcast Episode": "Podcast", + "Downloadable File": "Download", "Done": "Fertig", "Registration": "Anmeldung", "Lecturer": "Dozent", diff --git a/tailwind.config.js b/tailwind.config.js index 58d4f95f..87d8c667 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -12,6 +12,8 @@ module.exports = { './storage/framework/views/*.php', './resources/views/**/*.blade.php', + './app/Http/Livewire/**/*.php', + './vendor/rappasoft/laravel-livewire-tables/resources/views/**/*.blade.php', './vendor/wireui/wireui/resources/**/*.blade.php',