mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
feat: added description field to playlists (#680)
This commit is contained in:
@@ -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),
|
||||
|
||||
|
||||
@@ -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']),
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Api\Field\List\Playlist;
|
||||
|
||||
use App\Contracts\Http\Api\Field\CreatableField;
|
||||
use App\Contracts\Http\Api\Field\UpdatableField;
|
||||
use App\Http\Api\Field\StringField;
|
||||
use App\Http\Api\Schema\Schema;
|
||||
use App\Models\List\Playlist;
|
||||
use App\Rules\ModerationRule;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Class PlaylistDescriptionField.
|
||||
*/
|
||||
class PlaylistDescriptionField extends StringField implements CreatableField, UpdatableField
|
||||
{
|
||||
/**
|
||||
* Create a new field instance.
|
||||
*
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function __construct(Schema $schema)
|
||||
{
|
||||
parent::__construct($schema, Playlist::ATTRIBUTE_DESCRIPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the creation validation rules for the field.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function getCreationRules(Request $request): array
|
||||
{
|
||||
return [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:1000',
|
||||
new ModerationRule(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the update validation rules for the field.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function getUpdateRules(Request $request): array
|
||||
{
|
||||
return [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:1000',
|
||||
new ModerationRule(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace App\Http\Api\Schema\List;
|
||||
|
||||
use App\Contracts\Http\Api\Schema\SearchableSchema;
|
||||
use App\Http\Api\Field\Field;
|
||||
use App\Http\Api\Field\List\Playlist\PlaylistDescriptionField;
|
||||
use App\Http\Api\Field\List\Playlist\PlaylistFirstIdField;
|
||||
use App\Http\Api\Field\List\Playlist\PlaylistHashidsField;
|
||||
use App\Http\Api\Field\List\Playlist\PlaylistIdField;
|
||||
@@ -82,6 +83,7 @@ class PlaylistSchema extends EloquentSchema implements SearchableSchema
|
||||
new PlaylistFirstIdField($this),
|
||||
new PlaylistLastIdField($this),
|
||||
new PlaylistNameField($this),
|
||||
new PlaylistDescriptionField($this),
|
||||
new PlaylistUserIdField($this),
|
||||
new PlaylistVisibilityField($this),
|
||||
new PlaylistViewCountField($this),
|
||||
|
||||
@@ -29,6 +29,7 @@ use Laravel\Nova\Actions\Actionable;
|
||||
/**
|
||||
* Class Playlist.
|
||||
*
|
||||
* @property string|null $description
|
||||
* @property PlaylistTrack|null $first
|
||||
* @property int $first_id
|
||||
* @property Collection<int, Image> $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<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
Playlist::ATTRIBUTE_DESCRIPTION,
|
||||
Playlist::ATTRIBUTE_NAME,
|
||||
Playlist::ATTRIBUTE_USER,
|
||||
Playlist::ATTRIBUTE_VISIBILITY,
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scout\Elasticsearch\Api\Field\List\Playlist;
|
||||
|
||||
use App\Models\List\Playlist;
|
||||
use App\Scout\Elasticsearch\Api\Field\StringField;
|
||||
use App\Scout\Elasticsearch\Api\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Class PlaylistDescriptionField.
|
||||
*/
|
||||
class PlaylistDescriptionField extends StringField
|
||||
{
|
||||
/**
|
||||
* Create a new field instance.
|
||||
*
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function __construct(Schema $schema)
|
||||
{
|
||||
parent::__construct($schema, Playlist::ATTRIBUTE_DESCRIPTION);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use App\Http\Api\Schema\Wiki\ImageSchema;
|
||||
use App\Http\Resources\List\Resource\PlaylistResource;
|
||||
use App\Models\List\Playlist;
|
||||
use App\Scout\Elasticsearch\Api\Field\Field;
|
||||
use App\Scout\Elasticsearch\Api\Field\List\Playlist\PlaylistDescriptionField;
|
||||
use App\Scout\Elasticsearch\Api\Field\List\Playlist\PlaylistHashidsField;
|
||||
use App\Scout\Elasticsearch\Api\Field\List\Playlist\PlaylistNameField;
|
||||
use App\Scout\Elasticsearch\Api\Field\List\Playlist\PlaylistVisibilityField;
|
||||
@@ -71,6 +72,7 @@ class PlaylistSchema extends Schema
|
||||
[
|
||||
new PlaylistHashidsField($this),
|
||||
new PlaylistNameField($this),
|
||||
new PlaylistDescriptionField($this),
|
||||
new PlaylistVisibilityField($this),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -39,6 +39,7 @@ class PlaylistFactory extends Factory
|
||||
|
||||
return [
|
||||
Playlist::ATTRIBUTE_NAME => fake()->words(3, true),
|
||||
Playlist::ATTRIBUTE_DESCRIPTION => fake()->words(10, true),
|
||||
Playlist::ATTRIBUTE_VISIBILITY => $visibility->value,
|
||||
];
|
||||
}
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Models\List\Playlist;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasColumn(Playlist::TABLE, Playlist::ATTRIBUTE_DESCRIPTION)) {
|
||||
Schema::table(Playlist::TABLE, function (Blueprint $table) {
|
||||
$table->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);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -33,6 +33,13 @@ final class CreatePlaylistIndex implements MigrationInterface
|
||||
],
|
||||
],
|
||||
]);
|
||||
$mapping->text('description', [
|
||||
'fields' => [
|
||||
'keyword' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$mapping->date('updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user