From 7f0011441591b2dd2e0dcd0dba65c81083e332c2 Mon Sep 17 00:00:00 2001 From: Kyrch Date: Fri, 24 May 2024 17:44:38 -0300 Subject: [PATCH] feat: added description field to playlists (#680) --- app/Filament/Resources/List/Playlist.php | 21 ++++++- app/Filament/Resources/Wiki/Anime/Theme.php | 1 - .../Resources/Wiki/Anime/Theme/Entry.php | 5 +- .../Playlist/PlaylistDescriptionField.php | 61 +++++++++++++++++++ app/Http/Api/Schema/List/PlaylistSchema.php | 2 + app/Models/List/Playlist.php | 3 + app/Nova/Resources/List/Playlist.php | 11 ++++ .../Playlist/PlaylistDescriptionField.php | 25 ++++++++ .../Api/Schema/List/PlaylistSchema.php | 2 + database/factories/List/PlaylistFactory.php | 1 + ...scription_attribute_to_playlists_table.php | 35 +++++++++++ ...022_10_19_050811_create_playlist_index.php | 7 +++ lang/en/filament.php | 4 ++ lang/en/nova.php | 4 ++ 14 files changed, 177 insertions(+), 5 deletions(-) create mode 100644 app/Http/Api/Field/List/Playlist/PlaylistDescriptionField.php create mode 100644 app/Scout/Elasticsearch/Api/Field/List/Playlist/PlaylistDescriptionField.php create mode 100644 database/migrations/2024_05_24_201025_add_description_attribute_to_playlists_table.php diff --git a/app/Filament/Resources/List/Playlist.php b/app/Filament/Resources/List/Playlist.php index aee3e4430..a2a5689c8 100644 --- a/app/Filament/Resources/List/Playlist.php +++ b/app/Filament/Resources/List/Playlist.php @@ -21,6 +21,7 @@ use App\Filament\Resources\List\Playlist\RelationManagers\TrackPlaylistRelationM use App\Models\Auth\User as UserModel; use App\Models\List\Playlist as PlaylistModel; use App\Models\List\Playlist\PlaylistTrack as TrackModel; +use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Filament\Forms\Form; use Filament\Infolists\Components\Section; @@ -158,8 +159,16 @@ class Playlist extends BaseResource ->label(__('filament.fields.playlist.last.name')) ->relationship(PlaylistModel::RELATION_LAST, TrackModel::ATTRIBUTE_HASHID) ->searchable(), + + Textarea::make(PlaylistModel::ATTRIBUTE_DESCRIPTION) + ->label(__('filament.fields.playlist.description.name')) + ->helperText(__('filament.fields.playlist.description.help')) + ->nullable() + ->maxLength(1000) + ->rules(['nullable', 'max:1000']) + ->columnSpanFull(), ]) - ->columns(1); + ->columns(2); } /** @@ -215,6 +224,10 @@ class Playlist extends BaseResource ->toggleable() ->placeholder('-') ->urlToRelated(Track::class, PlaylistModel::RELATION_LAST), + + TextColumn::make(PlaylistModel::ATTRIBUTE_DESCRIPTION) + ->label(__('filament.fields.playlist.description.name')) + ->hidden(), ]) ->searchable() ->defaultSort(PlaylistModel::ATTRIBUTE_ID, 'desc') @@ -268,6 +281,12 @@ class Playlist extends BaseResource TextEntry::make(PlaylistModel::ATTRIBUTE_ID) ->label(__('filament.fields.base.id')), + + TextEntry::make(PlaylistModel::ATTRIBUTE_DESCRIPTION) + ->label(__('filament.fields.playlist.description.name')) + ->placeholder('-') + ->copyableWithMessage() + ->columnSpanFull(), ]) ->columns(3), diff --git a/app/Filament/Resources/Wiki/Anime/Theme.php b/app/Filament/Resources/Wiki/Anime/Theme.php index e06059050..bd79f67fd 100644 --- a/app/Filament/Resources/Wiki/Anime/Theme.php +++ b/app/Filament/Resources/Wiki/Anime/Theme.php @@ -184,7 +184,6 @@ class Theme extends BaseResource ->helperText(__('filament.fields.anime_theme.slug.help')) ->required() ->readOnly() - ->disabled() ->maxLength(192) ->rules(['required', 'max:192', 'alpha_dash']), diff --git a/app/Filament/Resources/Wiki/Anime/Theme/Entry.php b/app/Filament/Resources/Wiki/Anime/Theme/Entry.php index 0b3b39b08..75bf20a10 100644 --- a/app/Filament/Resources/Wiki/Anime/Theme/Entry.php +++ b/app/Filament/Resources/Wiki/Anime/Theme/Entry.php @@ -32,7 +32,6 @@ use Filament\Tables\Columns\IconColumn; use Filament\Tables\Filters\Filter; use Filament\Tables\Table; use Illuminate\Database\Eloquent\Model; -use Illuminate\Support\Facades\Log; /** * Class Entry. @@ -158,7 +157,7 @@ class Entry extends BaseResource ->label(__('filament.resources.singularLabel.anime')) ->relationship(EntryModel::RELATION_ANIME_SHALLOW, AnimeModel::ATTRIBUTE_NAME) ->searchable() - ->disabledOn(BaseRelationManager::class) + ->hiddenOn(BaseRelationManager::class) ->formatStateUsing(function ($livewire, $state) { if ($livewire instanceof BaseRelationManager) { /** @var EntryModel */ @@ -173,7 +172,7 @@ class Entry extends BaseResource ->label(__('filament.resources.singularLabel.anime_theme')) ->relationship(EntryModel::RELATION_THEME, ThemeModel::ATTRIBUTE_ID) ->searchable() - ->disabledOn(BaseRelationManager::class) + ->hiddenOn(BaseRelationManager::class) ->formatStateUsing(function ($livewire, $state, $record) { if ($record->animetheme !== null) return $record->animetheme->getName(); if ($livewire instanceof BaseRelationManager) { diff --git a/app/Http/Api/Field/List/Playlist/PlaylistDescriptionField.php b/app/Http/Api/Field/List/Playlist/PlaylistDescriptionField.php new file mode 100644 index 000000000..3cfc07186 --- /dev/null +++ b/app/Http/Api/Field/List/Playlist/PlaylistDescriptionField.php @@ -0,0 +1,61 @@ + $images @@ -51,6 +52,7 @@ class Playlist extends BaseModel implements HasHashids, Viewable final public const TABLE = 'playlists'; + final public const ATTRIBUTE_DESCRIPTION = 'description'; final public const ATTRIBUTE_FIRST = 'first_id'; final public const ATTRIBUTE_ID = 'playlist_id'; final public const ATTRIBUTE_LAST = 'last_id'; @@ -71,6 +73,7 @@ class Playlist extends BaseModel implements HasHashids, Viewable * @var array */ protected $fillable = [ + Playlist::ATTRIBUTE_DESCRIPTION, Playlist::ATTRIBUTE_NAME, Playlist::ATTRIBUTE_USER, Playlist::ATTRIBUTE_VISIBILITY, diff --git a/app/Nova/Resources/List/Playlist.php b/app/Nova/Resources/List/Playlist.php index a3b65150c..c5017cecc 100644 --- a/app/Nova/Resources/List/Playlist.php +++ b/app/Nova/Resources/List/Playlist.php @@ -23,6 +23,7 @@ use Laravel\Nova\Fields\HasMany; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Select; use Laravel\Nova\Fields\Text; +use Laravel\Nova\Fields\Textarea; use Laravel\Nova\Http\Requests\NovaRequest; use Laravel\Nova\Panel; use Laravel\Nova\Query\Search\Column; @@ -206,6 +207,16 @@ class Playlist extends BaseResource ->filterable() ->showWhenPeeking(), + Textarea::make(__('nova.fields.playlist.description.name'), PlaylistModel::ATTRIBUTE_DESCRIPTION) + ->sortable() + ->nullable() + ->rules(['max:1000']) + ->help(__('nova.fields.playlist.description.help')) + ->showOnPreview() + ->maxlength(1000) + ->enforceMaxlength() + ->showWhenPeeking(), + BelongsTo::make(__('nova.fields.playlist.first.name'), PlaylistModel::RELATION_FIRST, Track::class) ->hideFromIndex() ->sortable() diff --git a/app/Scout/Elasticsearch/Api/Field/List/Playlist/PlaylistDescriptionField.php b/app/Scout/Elasticsearch/Api/Field/List/Playlist/PlaylistDescriptionField.php new file mode 100644 index 000000000..1518fe3ca --- /dev/null +++ b/app/Scout/Elasticsearch/Api/Field/List/Playlist/PlaylistDescriptionField.php @@ -0,0 +1,25 @@ + fake()->words(3, true), + Playlist::ATTRIBUTE_DESCRIPTION => fake()->words(10, true), Playlist::ATTRIBUTE_VISIBILITY => $visibility->value, ]; } diff --git a/database/migrations/2024_05_24_201025_add_description_attribute_to_playlists_table.php b/database/migrations/2024_05_24_201025_add_description_attribute_to_playlists_table.php new file mode 100644 index 000000000..54e5ce42d --- /dev/null +++ b/database/migrations/2024_05_24_201025_add_description_attribute_to_playlists_table.php @@ -0,0 +1,35 @@ +text(Playlist::ATTRIBUTE_DESCRIPTION)->nullable(); + }); + } + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + if (Schema::hasColumn(Playlist::TABLE, Playlist::ATTRIBUTE_DESCRIPTION)) { + Schema::table(Playlist::TABLE, function (Blueprint $table) { + $table->dropColumn(Playlist::ATTRIBUTE_DESCRIPTION); + }); + } + } +}; diff --git a/elastic/migrations/2022_10_19_050811_create_playlist_index.php b/elastic/migrations/2022_10_19_050811_create_playlist_index.php index 4fa3df1db..b160511cb 100644 --- a/elastic/migrations/2022_10_19_050811_create_playlist_index.php +++ b/elastic/migrations/2022_10_19_050811_create_playlist_index.php @@ -33,6 +33,13 @@ final class CreatePlaylistIndex implements MigrationInterface ], ], ]); + $mapping->text('description', [ + 'fields' => [ + 'keyword' => [ + 'type' => 'keyword', + ], + ], + ]); $mapping->date('updated_at'); }); } diff --git a/lang/en/filament.php b/lang/en/filament.php index d4acc5dcb..b7dda2ff5 100644 --- a/lang/en/filament.php +++ b/lang/en/filament.php @@ -669,6 +669,10 @@ return [ 'help' => 'The display title of the Playlist', 'name' => 'Name', ], + 'description' => [ + 'help' => 'The description of the Playlist', + 'name' => 'Description', + ], 'visibility' => [ 'help' => 'Who can view this playlist? Private: only the owner. Unlisted: anyone directly linked to the playlist. Public: anyone can search for the playlist.', 'name' => 'Visibility', diff --git a/lang/en/nova.php b/lang/en/nova.php index fdefa94d5..08f909b36 100644 --- a/lang/en/nova.php +++ b/lang/en/nova.php @@ -641,6 +641,10 @@ return [ 'help' => 'The display title of the Playlist', 'name' => 'Name', ], + 'description' => [ + 'help' => 'The description of the Playlist', + 'name' => 'Description', + ], 'visibility' => [ 'help' => 'Who can view this playlist? Private: only the owner. Unlisted: anyone directly linked to the playlist. Public: anyone can search for the playlist.', 'name' => 'Visibility',