Skip to content

Commit

Permalink
feat(filament): added video-script relationship (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrch committed May 8, 2024
1 parent 134c4cd commit d819f08
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 43 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ FFMPEG_BINARIES=
FFPROBE_BINARIES=

# filament
FILAMENT_DOMAIN_NAME=
FILAMENT_PATH=/admin

# filesystems
Expand Down
4 changes: 4 additions & 0 deletions .env.example-sail
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ ELASTIC_MIGRATIONS_TABLE=elastic_migrations
FFMPEG_BINARIES=
FFPROBE_BINARIES=

# filament
FILAMENT_DOMAIN_NAME=
FILAMENT_PATH=/admin

# filesystems
FILESYSTEM_DISK=local

Expand Down
23 changes: 2 additions & 21 deletions app/Filament/Resources/Wiki/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Filament\Resources\Wiki\Video\Pages\ListVideos;
use App\Filament\Resources\Wiki\Video\Pages\ViewVideo;
use App\Filament\Resources\Wiki\Video\RelationManagers\EntryVideoRelationManager;
use App\Filament\Resources\Wiki\Video\RelationManagers\ScriptVideoRelationManager;
use App\Filament\Resources\Wiki\Video\RelationManagers\TrackVideoRelationManager;
use App\Filament\TableActions\Repositories\Storage\Wiki\Video\ReconcileVideoTableAction;
use App\Filament\TableActions\Storage\Wiki\Video\UploadVideoTableAction;
Expand Down Expand Up @@ -178,27 +179,6 @@ public static function form(Form $form): Form
->label(__('filament.resources.singularLabel.audio'))
->relationship(VideoModel::RELATION_AUDIO, AudioModel::ATTRIBUTE_FILENAME)
->searchable(),

TextInput::make(VideoModel::ATTRIBUTE_BASENAME)
->label(__('filament.fields.video.basename.name'))
->hiddenOn(['create', 'edit']),

TextInput::make(VideoModel::ATTRIBUTE_FILENAME)
->label(__('filament.fields.video.filename.name'))
->hiddenOn(['create', 'edit']),

TextInput::make(VideoModel::ATTRIBUTE_PATH)
->label(__('filament.fields.video.path.name'))
->hiddenOn(['create', 'edit']),

TextInput::make(VideoModel::ATTRIBUTE_SIZE)
->label(__('filament.fields.video.size.name'))
->numeric()
->hiddenOn(['create', 'edit']),

TextInput::make(VideoModel::ATTRIBUTE_MIMETYPE)
->label(__('filament.fields.video.mimetype.name'))
->hiddenOn(['create', 'edit']),
])
->columns(1);
}
Expand Down Expand Up @@ -313,6 +293,7 @@ public static function getRelations(): array
return [
RelationGroup::make(static::getLabel(), [
EntryVideoRelationManager::class,
ScriptVideoRelationManager::class,
TrackVideoRelationManager::class,
]),
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\Wiki\Video\RelationManagers;

use App\Filament\Resources\BaseRelationManager;
use App\Filament\Resources\Wiki\Video\Script as ScriptResource;
use App\Models\Wiki\Video;
use App\Models\Wiki\Video\VideoScript;
use Filament\Forms\Form;
use Filament\Tables\Table;

/**
* Class ScriptVideoRelationManager.
*/
class ScriptVideoRelationManager extends BaseRelationManager
{
/**
* The relationship the relation manager corresponds to.
*
* @return string
*/
protected static string $relationship = Video::RELATION_SCRIPT;

/**
* The form to the actions.
*
* @param Form $form
* @return Form
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function form(Form $form): Form
{
return ScriptResource::form($form);
}

/**
* The index page of the resource.
*
* @param Table $table
* @return Table
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public function table(Table $table): Table
{
return $table
->heading(ScriptResource::getLabel())
->modelLabel(ScriptResource::getLabel())
->recordTitleAttribute(VideoScript::ATTRIBUTE_PATH)
->inverseRelationship(VideoScript::RELATION_VIDEO)
->columns(ScriptResource::table($table)->getColumns())
->filters(static::getFilters())
->headerActions(static::getHeaderActions())
->actions(static::getActions())
->bulkActions(static::getBulkActions());
}

/**
* Get the filters available for the relation.
*
* @return array
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getFilters(): array
{
return array_merge(
parent::getFilters(),
[],
);
}

/**
* Get the actions available for the relation.
*
* @return array
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getActions(): array
{
return array_merge(
parent::getActions(),
[],
);
}

/**
* Get the bulk actions available for the relation.
*
* @return array
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getBulkActions(): array
{
return array_merge(
parent::getBulkActions(),
[],
);
}

/**
* Get the header actions available for the relation.
*
* @return array
*
* @noinspection PhpMissingParentCallCommonInspection
*/
public static function getHeaderActions(): array
{
return ScriptResource::getHeaderActions();
}
}
4 changes: 1 addition & 3 deletions app/Filament/TableActions/Storage/Base/UploadTableAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

/**
Expand Down Expand Up @@ -49,11 +48,10 @@ public function getForm(Form $form): Form
/**
* Get the underlying storage action.
*
* @param Model $model
* @param array $fields
* @return BaseUploadAction
*/
abstract protected function storageAction(Model $model, array $fields): BaseUploadAction;
abstract protected function storageAction(array $fields): BaseUploadAction;

/**
* Get the file validation rules.
Expand Down
11 changes: 4 additions & 7 deletions app/Filament/TableActions/Storage/StorageTableAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use App\Contracts\Actions\Storage\StorageAction as BaseStorageAction;
use Filament\Tables\Actions\Action;
use Illuminate\Database\Eloquent\Model;

/**
* Class StorageTableAction.
Expand All @@ -22,28 +21,26 @@ protected function setUp(): void
{
parent::setUp();

$this->action(fn (Model $record, array $data) => $this->handle($record, $data));
$this->action(fn (array $data) => $this->handle($data));
}

/**
* Get the underlying storage action.
*
* @param Model $model
* @param array $fields
* @return BaseStorageAction
*/
abstract protected function storageAction(Model $model, array $fields): BaseStorageAction;
abstract protected function storageAction(array $fields): BaseStorageAction;

/**
* Perform the action on the given models.
*
* @param Model $model
* @param array $fields
* @return void
*/
public function handle(Model $model, array $fields): void
public function handle(array $fields): void
{
$action = $this->storageAction($model, $fields);
$action = $this->storageAction($fields);

$storageResults = $action->handle();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use App\Rules\Wiki\Submission\Format\ExtraneousMetadataFormatRule;
use App\Rules\Wiki\Submission\Format\FormatNameFormatRule;
use App\Rules\Wiki\Submission\Format\TotalStreamsFormatRule;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Config;
Expand All @@ -35,11 +34,10 @@ class UploadAudioTableAction extends UploadTableAction
/**
* Get the underlying storage action.
*
* @param Model $model
* @param array $fields
* @return UploadAudio
*/
protected function storageAction(Model $model, array $fields): UploadAudio
protected function storageAction(array $fields): UploadAudio
{
/** @var UploadedFile $file */
$file = Arr::get($fields, 'file');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

use App\Actions\Storage\Wiki\Video\Script\UploadScriptAction as UploadScript;
use App\Constants\Config\VideoConstants;
use App\Filament\Resources\BaseRelationManager;
use App\Filament\Resources\Wiki\Video\Script\Pages\ListScripts;
use App\Models\Wiki\Video;
use App\Filament\TableActions\Storage\Base\UploadTableAction;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Form;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Config;
Expand Down Expand Up @@ -38,7 +39,7 @@ public function getForm(Form $form): Form
[
Hidden::make(Video::ATTRIBUTE_ID)
->label(__('filament.resources.singularLabel.video'))
->default(fn () => $model instanceof Video ? $model->getKey() : null),
->default(fn (BaseRelationManager|ListScripts $livewire) => $livewire instanceof BaseRelationManager ? $livewire->getOwnerRecord()->getKey() : null),
],
)
);
Expand All @@ -47,11 +48,10 @@ public function getForm(Form $form): Form
/**
* Get the underlying storage action.
*
* @param Model $model
* @param array $fields
* @return UploadScript
*/
protected function storageAction(Model $model, array $fields): UploadScript
protected function storageAction(array $fields): UploadScript
{
/** @var UploadedFile $file */
$file = Arr::get($fields, 'file');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -129,11 +128,10 @@ public function getForm(Form $form): Form
/**
* Get the underlying storage action.
*
* @param Model $model
* @param array $fields
* @return UploadVideo
*/
protected function storageAction(Model $model, array $fields): UploadVideo
protected function storageAction(array $fields): UploadVideo
{
/** @var string|null $path */
$path = Arr::get($fields, 'path');
Expand Down
6 changes: 4 additions & 2 deletions app/Providers/FilamentPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\Support\Facades\Config;
use Illuminate\View\Middleware\ShareErrorsFromSession;

class FilamentPanelProvider extends PanelProvider
Expand All @@ -43,8 +44,9 @@ public function panel(Panel $panel): Panel

return $panel
->default()
->id('admin')
->path('admin')
->id(Config::get('filament.path'))
->path(Config::get('filament.path'))
->domain(Config::get('filament.domain'))
->login()
->databaseNotifications()
->sidebarCollapsibleOnDesktop()
Expand Down
14 changes: 14 additions & 0 deletions config/filament.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [

/*
Expand Down Expand Up @@ -30,6 +32,18 @@

],

/*
|--------------------------------------------------------------------------
| Filament Domain Name
|--------------------------------------------------------------------------
|
| This value is the "domain name" associated with your application. This
| can be used to prevent Filament's internal routes from being registered
| on subdomains which do not need access to your admin application.
|
*/
'domain' => env('FILAMENT_DOMAIN_NAME'),

/*
|--------------------------------------------------------------------------
| Filament Path
Expand Down
Loading

0 comments on commit d819f08

Please sign in to comment.