From 89c574106fd5fa434cbbbce8a6c8642ed457e98b Mon Sep 17 00:00:00 2001 From: Lars Date: Tue, 17 Nov 2026 10:56:03 +0100 Subject: [PATCH] =?UTF-8?q?Lege=20Medien=20=C3=BCber=20eine=20gemeinsame?= =?UTF-8?q?=20Maske=20mit=20Upload-Fortschritt=20an.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Beschreibung, Hinweise und Vorschaubild bleiben danach in derselben Maske bearbeitbar, im Bestand wie im Modul und Programm. Co-authored-by: Cursor --- app/Domain/Media/ThumbnailDeriver.php | 7 + .../Compositions/Pages/EditComposition.php | 152 ++++++----- .../Pages/EditContentElement.php | 37 ++- .../Pages/ListContentElements.php | 47 +--- app/Filament/Support/EditorialCatalog.php | 1 + app/Filament/Support/MediumForm.php | 241 ++++++++++++++++++ .../views/filament/editorial/editor.blade.php | 31 +-- tests/Feature/EditorialEditorTest.php | 51 +++- 8 files changed, 407 insertions(+), 160 deletions(-) create mode 100644 app/Filament/Support/MediumForm.php diff --git a/app/Domain/Media/ThumbnailDeriver.php b/app/Domain/Media/ThumbnailDeriver.php index fdd7b1b..43bb141 100644 --- a/app/Domain/Media/ThumbnailDeriver.php +++ b/app/Domain/Media/ThumbnailDeriver.php @@ -14,6 +14,13 @@ class ThumbnailDeriver { public function forElement(ContentElement $element): void { + $element->refresh(); + $chosen = $element->thumbnail_source; + + if ($chosen === 'eigen' || (is_string($chosen) && str_starts_with($chosen, 'frame:'))) { + return; + } + $version = $element->versions()->orderByDesc('number')->first(); $file = is_array($version?->metadata) ? ($version->metadata['file'] ?? null) : null; diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index c1f6bb7..2aa2a63 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -20,15 +20,17 @@ use App\Domain\Catalog\IdentityProfile; use App\Domain\Catalog\StructureNode; use App\Filament\Support\EditorialCatalog; -use App\Filament\Support\IncomingFile; +use App\Filament\Support\MediumForm; use App\Http\Controllers\ContentPreviewController; use App\Jobs\DeriveCompositionFrame; use App\Jobs\DeriveThumbnail; use App\Models\User; use Filament\Actions\Action; use Filament\Facades\Filament; +use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; use Filament\Support\Enums\Width; +use Filament\Support\Exceptions\Halt; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Database\Eloquent\Model; use Livewire\Features\SupportFileUploads\TemporaryUploadedFile; @@ -89,8 +91,6 @@ abstract class EditComposition extends EditRecord public bool $textOpen = false; - public bool $fileOpen = false; - public bool $releaseArmed = false; public string $returnUrl = ''; @@ -103,10 +103,6 @@ abstract class EditComposition extends EditRecord public string $newTextBody = ''; - public string $newFileTitle = ''; - - public mixed $incomingFile = null; - public string $partTitle = ''; public string $partBody = ''; @@ -312,7 +308,6 @@ public function openPicker(): void $this->pickerOpen = true; $this->textOpen = false; - $this->fileOpen = false; $this->pickerSelected = ''; } @@ -408,7 +403,6 @@ public function openText(): void $this->pickerOpen = false; $this->moduleOpen = false; $this->partOpen = false; - $this->fileOpen = false; $this->textOpen = true; } @@ -419,22 +413,6 @@ public function cancelText(): void $this->newTextBody = ''; } - public function openFile(): void - { - $this->pickerOpen = false; - $this->moduleOpen = false; - $this->partOpen = false; - $this->textOpen = false; - $this->fileOpen = true; - } - - public function cancelFile(): void - { - $this->fileOpen = false; - $this->newFileTitle = ''; - $this->incomingFile = null; - } - public function saveDraft(): void { $this->commitRoleDraft(); @@ -850,54 +828,71 @@ public function addText(): void $this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Der Text bleibt bearbeitbar, solange diese Fassung nicht freigegeben und verwendet wird. Es entsteht keine neue Fassung dieses Eintrags.'; } - public function addFile(): void + public function createMediumAction(): Action { - $title = trim($this->newFileTitle); - $stored = IncomingFile::store($this->incomingFile); + return Action::make('createMedium') + ->label('Medium anlegen') + ->modalHeading('Medium anlegen') + ->modalDescription('Dieselbe Maske gilt im Medienbestand, im Modul und im Programm. Der Upload zeigt seinen Fortschritt. Beschreibung, Hinweise und Vorschaubild trägst du danach in dieser Maske ein.') + ->modalSubmitActionLabel('Anlegen und übernehmen') + ->modalWidth(Width::Large) + ->schema(fn (): array => MediumForm::fields(creating: true)) + ->action(function (array $data): void { + try { + $element = MediumForm::create($data, hold: true); + } catch (DomainRuleException $exception) { + Notification::make()->title($exception->getMessage())->danger()->send(); - if ($title === '' || $stored === null) { - $this->feedback = 'Das Medium braucht einen Titel und eine Datei.'; + throw new Halt; + } - return; - } + $version = $element->versions()->orderByDesc('number')->first(); - $extension = strtolower(pathinfo($stored, PATHINFO_EXTENSION)); - $shape = match ($extension) { - 'mp4', 'webm', 'mov', 'm4v' => ['film', 'film'], - 'mp3', 'm4a', 'wav', 'ogg' => ['audio', 'audio'], - 'png', 'jpg', 'jpeg', 'webp', 'gif' => ['bild', 'bild'], - 'pdf' => ['dokument', 'document'], - default => null, - }; + if (! $version instanceof ContentElementVersion || ! $this->includePart('element:'.$version->id, true)) { + return; + } - if ($shape === null) { - $this->feedback = 'Diese Dateiart lässt sich hier nicht anlegen.'; + $this->feedback = $element->working_title.' ist angelegt und in den Aufbau übernommen. Die Datei liegt bei den Medien. Beschreibung und Vorschaubild sind gespeichert.'; + }); + } - return; - } + public function editMediumAction(): Action + { + return Action::make('editMedium') + ->modalHeading('Medium bearbeiten') + ->modalDescription('Titel, Beschreibung, Hinweise und Vorschaubild gelten für das Medium. Eine neue Fassung entsteht nur, wenn der Text bereits freigegeben und verwendet wird.') + ->modalSubmitActionLabel('Speichern') + ->modalWidth(Width::Large) + ->fillForm(function (array $arguments): array { + $element = ContentElement::query()->find($arguments['element'] ?? 0); - try { - $service = app(ContentService::class); - $element = $service->createElement($shape[0], $shape[1], $title); - $version = $service->draftElementVersion($element, null, [ - 'incoming' => $stored, - 'hold' => true, - ]); - } catch (DomainRuleException $exception) { - $this->feedback = $exception->getMessage(); + return $element instanceof ContentElement ? MediumForm::fill($element) : []; + }) + ->schema(function (array $arguments): array { + $element = ContentElement::query()->find($arguments['element'] ?? 0); - return; - } + return MediumForm::fields(creating: false, element: $element instanceof ContentElement ? $element : null); + }) + ->action(function (array $data, array $arguments): void { + $element = ContentElement::query()->find($arguments['element'] ?? 0); - $this->newFileTitle = ''; - $this->incomingFile = null; - $this->fileOpen = false; + if (! $element instanceof ContentElement) { + Notification::make()->title('Dieses Medium ist nicht mehr vorhanden.')->danger()->send(); - if (! $this->includePart('element:'.$version->id, true)) { - return; - } + throw new Halt; + } - $this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Die Datei liegt bei den Medien. Eine neue Fassung entsteht erst, wenn diese Fassung freigegeben und verwendet wird.'; + try { + $revised = MediumForm::update($element, $data); + } catch (DomainRuleException $exception) { + Notification::make()->title($exception->getMessage())->danger()->send(); + + throw new Halt; + } + + $this->retargetContainedElement($element, $revised); + $this->feedback = 'Die Angaben des Mediums sind gespeichert.'; + }); } public function startModule(): void @@ -946,7 +941,6 @@ public function openModule(): void $this->pickerOpen = false; $this->partOpen = false; $this->textOpen = false; - $this->fileOpen = false; $this->moduleTab = 'beschreibung'; $this->frameFilmChoices = $this->frameFilms(); $films = $this->frameFilmChoices; @@ -1012,7 +1006,6 @@ public function openPart(int $index): void $this->moduleOpen = false; $this->pickerOpen = false; $this->textOpen = false; - $this->fileOpen = false; $this->partOpen = true; } @@ -1200,6 +1193,37 @@ public function adoptPicture(int $elementId): void $this->feedback = $this->previewFeedback($record, $before); } + private function retargetContainedElement(ContentElement $element, ?ContentElementVersion $revised): void + { + $element->refresh(); + + foreach ($this->members as $index => $member) { + if ((int) ($member['element_id'] ?? 0) !== $element->id) { + continue; + } + + $target = $revised instanceof ContentElementVersion + ? 'element:'.$revised->id + : (string) ($member['target'] ?? ''); + $row = app(EditorialCatalog::class)->rowForTarget( + $target, + (int) $this->getRecord()->getKey(), + allowSelf: true, + allowDraft: true, + ); + + if ($row === null) { + continue; + } + + $row['role'] = (string) ($member['role'] ?? $row['kind']); + $row['note'] = (string) ($member['note'] ?? ''); + $this->members[$index] = $row; + } + + $this->persistDraft(); + } + private function writePartText(): string|false { $index = $this->selected; diff --git a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php index 0039bdb..05c7305 100644 --- a/app/Filament/Resources/ContentElements/Pages/EditContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/EditContentElement.php @@ -4,6 +4,7 @@ use App\Domain\Catalog\Composition; use App\Domain\Catalog\ContentElement; +use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; use App\Domain\Catalog\DomainRuleException; use App\Domain\Catalog\EditorialContentKind; @@ -18,7 +19,7 @@ use App\Domain\Media\ThumbnailRef; use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Support\ElementRevision; -use App\Filament\Support\MediaUploadLimit; +use App\Filament\Support\MediumForm; use App\Filament\Support\ReportsDomainRules; use App\Jobs\DeriveThumbnail; use Filament\Actions\Action; @@ -44,27 +45,24 @@ class EditContentElement extends EditRecord public function getSubheading(): string|Htmlable|null { - return 'Arbeitstitel, Beschreibung und Säulen gehören zum Medium. Speichern legt keine neue Fassung an. Text und Datei änderst du über eine neue Fassung; die bisherige bleibt erhalten.'; + return 'Titel, Beschreibung, Hinweise und Vorschaubild gehören zum Medium. Ein Text bleibt dieselbe Fassung, solange er nicht freigegeben und verwendet wird.'; } public function form(Schema $schema): Schema { + /** @var ContentElement $element */ + $element = $this->getRecord(); + return $schema->columns(1)->components([ Placeholder::make('open')->label('Medium')->content(function (): HtmlString { $url = ContentElementResource::getUrl('view', ['record' => $this->getRecord()]); return new HtmlString('Medium und Fassungen ansehen'); }), - TextInput::make('working_title')->label('Arbeitstitel')->required(), + ...MediumForm::fields(creating: false, element: $element), TextInput::make('display_title')->label('Anzeigetitel') ->helperText('Erscheint in der Bibliothek. Leer lässt den Arbeitstitel stehen. Speichern legt keine Fassung an.'), Textarea::make('summary')->label('Kurzbeschreibung')->rows(3), - Textarea::make('description')->label('Beschreibung')->rows(4) - ->helperText('Allgemeine Beschreibung des Mediums. Gilt nicht für eine einzelne Fassung und nicht nur für ein Modul.'), - Textarea::make('usage_note')->label('Hinweise für den Einsatz')->rows(4) - ->helperText('Gilt für das Medium in jeder Verwendung. Speichern legt keine Fassung an.'), - Textarea::make('license_note')->label('Interner Lizenzvermerk')->rows(3) - ->helperText('Nur in der Verwaltung sichtbar. Erscheint nicht in der Bibliothek und nicht auf der Website.'), Select::make('editorial_content_kind_id') ->label('Inhaltsart') ->options(fn (): array => EditorialContentKind::selectOptions()) @@ -122,9 +120,6 @@ public function form(Schema $schema): Schema return new HtmlString(''.($caption !== '' ? '

'.e($caption).'

' : '')); }), - FileUpload::make('thumbnail_upload')->label('Eigenes Vorschaubild') - ->disk('cms_incoming')->directory('vorschau')->visibility('private')->image() - ->helperText('Gilt für die Anzeige und als Vorschlag in Modulen und Programmen. Eine Filmstelle wählst du beim Ansehen. Speichern legt keine Fassung an.'), CheckboxList::make('pillars') ->label('Fachliche Säulen') ->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all()) @@ -135,13 +130,7 @@ public function form(Schema $schema): Schema public static function uploadField(): FileUpload { - return FileUpload::make('incoming') - ->label('Datei') - ->disk('cms_incoming') - ->directory('inhalte') - ->visibility('private') - ->maxSize(MediaUploadLimit::KILOBYTES) - ->helperText('Film, Audio, Bild oder PDF bis 2 GB.'); + return MediumForm::fileField(); } protected function getHeaderActions(): array @@ -192,6 +181,8 @@ protected function mutateFormDataBeforeFill(array $data): array { return [ 'working_title' => $this->getRecord()->working_title, + 'thumbnail_alt' => $this->getRecord()->thumbnail_alt, + 'body' => $this->getRecord()->versions()->orderByDesc('number')->first()?->body, 'display_title' => $this->getRecord()->display_title, 'description' => $this->getRecord()->description, 'usage_note' => $this->getRecord()->usage_note, @@ -221,7 +212,15 @@ protected function handleRecordUpdate(Model $record, array $data): Model 'summary' => $data['summary'] ?? null, 'usage_note' => $data['usage_note'] ?? null, 'license_note' => $data['license_note'] ?? null, + 'thumbnail_alt' => $data['thumbnail_alt'] ?? null, ], auth()->user()); + if ($record->output_class === 'text' && is_string($data['body'] ?? null)) { + $latest = $record->versions()->orderByDesc('number')->first(); + + if ($latest instanceof ContentElementVersion) { + app(ContentService::class)->reviseElementContent($latest, $data['body']); + } + } if (array_key_exists('editorial_content_kind_id', $data)) { $record->editorial_content_kind_id = filled($data['editorial_content_kind_id'] ?? null) ? (int) $data['editorial_content_kind_id'] diff --git a/app/Filament/Resources/ContentElements/Pages/ListContentElements.php b/app/Filament/Resources/ContentElements/Pages/ListContentElements.php index 3e93458..5816a3d 100644 --- a/app/Filament/Resources/ContentElements/Pages/ListContentElements.php +++ b/app/Filament/Resources/ContentElements/Pages/ListContentElements.php @@ -2,14 +2,10 @@ namespace App\Filament\Resources\ContentElements\Pages; -use App\Domain\Catalog\ContentService; use App\Filament\Resources\ContentElements\ContentElementResource; -use App\Filament\Support\IncomingFile; +use App\Filament\Support\MediumForm; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; -use Filament\Forms\Components\Select; -use Filament\Forms\Components\Textarea; -use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\ListRecords; use Illuminate\Contracts\Support\Htmlable; @@ -30,47 +26,12 @@ protected function getHeaderActions(): array Action::make('create') ->label('Medium anlegen') ->visible(fn (): bool => ContentElementResource::editor()) - ->schema([ - TextInput::make('working_title')->label('Titel')->required(), - Select::make('shape')->label('Was ist das?')->options([ - 'film' => 'Film', - 'audio' => 'Hörstück', - 'bild' => 'Bild', - 'document' => 'Dokument', - 'text' => 'Text', - ])->required()->live(), - Textarea::make('body')->label('Text')->visible(fn ($get): bool => $get('shape') === 'text'), - EditContentElement::uploadField()->visible(fn ($get): bool => $get('shape') !== 'text'), - TextInput::make('change_note')->label('Notiz zur ersten Fassung'), - ]) + ->modalDescription('Dieselbe Maske gilt im Medienbestand, im Modul und im Programm. Der Upload zeigt seinen Fortschritt. Beschreibung, Hinweise und Vorschaubild gehören dazu.') + ->schema(fn (): array => MediumForm::fields(creating: true)) ->action(function (array $data): void { $element = null; $this->report(function () use ($data, &$element): void { - $service = app(ContentService::class); - [$kind, $output] = match ($data['shape']) { - 'audio' => ['audio', 'audio'], - 'bild' => ['bild', 'bild'], - 'document' => ['dokument', 'document'], - 'text' => ['text', 'text'], - default => ['film', 'film'], - }; - $element = $service->createElement($kind, $output, $data['working_title']); - $metadata = []; - $incoming = IncomingFile::store($data['incoming'] ?? null); - - if (is_string($incoming) && $incoming !== '') { - $metadata['incoming'] = $incoming; - } - - if (is_numeric($data['decision_seconds'] ?? null)) { - $metadata['decision_seconds'] = (int) $data['decision_seconds']; - } - - $body = $data['body'] ?? null; - - if ((is_string($body) && $body !== '') || $metadata !== []) { - $service->publishElementVersion($element, is_string($body) ? $body : null, $metadata, $data['change_note'] ?? null); - } + $element = MediumForm::create($data, hold: false); }, 'Das Medium ist angelegt.'); if ($element !== null) { diff --git a/app/Filament/Support/EditorialCatalog.php b/app/Filament/Support/EditorialCatalog.php index 34d4c1f..05deeda 100644 --- a/app/Filament/Support/EditorialCatalog.php +++ b/app/Filament/Support/EditorialCatalog.php @@ -83,6 +83,7 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all return [ 'target' => 'element:'.$version->id, + 'element_id' => (string) $element->id, 'title' => $title, 'kind' => $kind, 'output' => (string) $element->output_class, diff --git a/app/Filament/Support/MediumForm.php b/app/Filament/Support/MediumForm.php new file mode 100644 index 0000000..198439b --- /dev/null +++ b/app/Filament/Support/MediumForm.php @@ -0,0 +1,241 @@ + + */ + public static function fields(bool $creating, ?ContentElement $element = null): array + { + $fields = [ + TextInput::make('working_title')->label('Titel')->required(), + ]; + + if ($creating) { + $fields[] = Select::make('shape')->label('Was ist das?')->options([ + 'film' => 'Film', + 'audio' => 'Hörstück', + 'bild' => 'Bild', + 'document' => 'Dokument', + 'text' => 'Text', + ])->required()->live(); + $fields[] = Textarea::make('body')->label('Text')->rows(8) + ->visible(fn ($get): bool => $get('shape') === 'text') + ->required(fn ($get): bool => $get('shape') === 'text'); + $fields[] = self::fileField() + ->visible(fn ($get): bool => filled($get('shape')) && $get('shape') !== 'text') + ->required(fn ($get): bool => filled($get('shape')) && $get('shape') !== 'text'); + } elseif ($element?->output_class === 'text') { + $fields[] = Textarea::make('body')->label('Text')->rows(8)->required(); + } + + return [ + ...$fields, + Textarea::make('description')->label('Beschreibung')->rows(4) + ->helperText('Gilt für das Medium, nicht nur für diese eine Stelle.'), + Textarea::make('usage_note')->label('Hinweise für den Einsatz')->rows(3), + Textarea::make('license_note')->label('Interner Lizenzvermerk')->rows(3) + ->helperText('Nur in der Verwaltung. Nicht in der Bibliothek und nicht auf der Website.'), + TextInput::make('thumbnail_alt')->label('Alternativtext zum Vorschaubild'), + self::thumbnailField(), + ]; + } + + public static function fileField(): FileUpload + { + return FileUpload::make('incoming') + ->label('Datei') + ->disk('cms_incoming') + ->directory('inhalte') + ->visibility('private') + ->maxSize(MediaUploadLimit::KILOBYTES) + ->panelLayout('integrated') + ->uploadProgressIndicatorPosition('center') + ->helperText('Der Balken zeigt den Upload. Film, Hörstück, Bild oder PDF. Die Übernahme läuft danach im Hintergrund.'); + } + + public static function thumbnailField(): FileUpload + { + return FileUpload::make('thumbnail_upload') + ->label('Vorschaubild') + ->disk('cms_incoming') + ->directory('vorschau') + ->visibility('private') + ->image() + ->panelLayout('integrated') + ->uploadProgressIndicatorPosition('center') + ->helperText('Erscheint in der Anzeige und als Vorschlag in Modulen und Programmen. Eine Filmstelle wählst du beim Ansehen des Mediums. Speichern legt keine Fassung an.'); + } + + /** + * @param array $data + */ + public static function create(array $data, bool $hold): ContentElement + { + $service = app(ContentService::class); + [$kind, $output] = self::shape($data['shape'] ?? null); + $element = $service->createElement($kind, $output, (string) $data['working_title']); + self::remember($element, $data); + + if ($output === 'text') { + $body = trim((string) ($data['body'] ?? '')); + + if ($body === '') { + throw new DomainRuleException('Der Text braucht einen Inhalt.'); + } + + $hold + ? $service->draftElementVersion($element, $body) + : $service->publishElementVersion($element, $body); + } else { + $incoming = IncomingFile::store($data['incoming'] ?? null); + + if ($incoming === null) { + throw new DomainRuleException('Das Medium braucht eine Datei.'); + } + + $extension = strtolower(pathinfo($incoming, PATHINFO_EXTENSION)); + $allowed = match ($data['shape'] ?? '') { + 'audio' => ['mp3', 'm4a', 'wav', 'ogg'], + 'bild' => ['png', 'jpg', 'jpeg', 'webp', 'gif'], + 'document' => ['pdf'], + default => ['mp4', 'webm', 'mov', 'm4v'], + }; + + if (! in_array($extension, $allowed, true)) { + throw new DomainRuleException('Diese Datei passt nicht zur gewählten Art.'); + } + + $metadata = ['incoming' => $incoming]; + + if ($hold) { + $metadata['hold'] = true; + $service->draftElementVersion($element, null, $metadata); + } else { + $service->publishElementVersion($element, null, $metadata); + } + } + + self::queuePreview($element, $data); + + return $element->fresh() ?? $element; + } + + /** + * @param array $data + */ + public static function update(ContentElement $element, array $data): ?ContentElementVersion + { + self::remember($element, $data); + $revised = null; + + if ($element->output_class === 'text') { + $latest = $element->versions()->orderByDesc('number')->first(); + $body = trim((string) ($data['body'] ?? '')); + + if ($latest instanceof ContentElementVersion && $body !== '') { + $revised = app(ContentService::class)->reviseElementContent($latest, $body); + } + } + + self::queuePreview($element, $data); + + return $revised; + } + + /** + * @return array + */ + public static function fill(ContentElement $element): array + { + $latest = $element->versions()->orderByDesc('number')->first(); + + return [ + 'working_title' => $element->working_title, + 'description' => $element->description, + 'usage_note' => $element->usage_note, + 'license_note' => $element->license_note, + 'thumbnail_alt' => $element->thumbnail_alt, + 'body' => $latest?->body, + ]; + } + + /** + * @param array $data + */ + public static function remember(ContentElement $element, array $data): void + { + app(ContentService::class)->describe($element, (string) $data['working_title'], $data['description'] ?? null); + app(IdentityProfile::class)->fill($element, [ + 'usage_note' => $data['usage_note'] ?? null, + 'license_note' => $data['license_note'] ?? null, + 'thumbnail_alt' => $data['thumbnail_alt'] ?? null, + ], auth()->user()); + } + + /** + * @param array $data + */ + public static function queuePreview(ContentElement $element, array $data): void + { + $path = self::previewPath($data['thumbnail_upload'] ?? null); + + if ($path === null) { + return; + } + + $element->thumbnail_error = null; + $element->save(); + DeriveThumbnail::dispatch('element', $element->id, $path); + } + + /** + * @return array{0: string, 1: string} + */ + private static function shape(mixed $shape): array + { + return match ($shape) { + 'audio' => ['audio', 'audio'], + 'bild' => ['bild', 'bild'], + 'document' => ['dokument', 'document'], + 'text' => ['text', 'text'], + 'film' => ['film', 'film'], + default => throw new DomainRuleException('Die Art des Mediums fehlt.'), + }; + } + + private static function previewPath(mixed $value): ?string + { + if (is_array($value)) { + foreach ($value as $item) { + $stored = self::previewPath($item); + + if ($stored !== null) { + return $stored; + } + } + + return null; + } + + if (! is_string($value) || $value === '' || str_contains($value, '..') || ! str_starts_with($value, 'vorschau/')) { + return null; + } + + return Storage::disk('cms_incoming')->exists($value) ? $value : null; + } +} diff --git a/resources/views/filament/editorial/editor.blade.php b/resources/views/filament/editorial/editor.blade.php index 0b66bfc..16fc9f3 100644 --- a/resources/views/filament/editorial/editor.blade.php +++ b/resources/views/filament/editorial/editor.blade.php @@ -41,7 +41,7 @@
- +

Der Aufbau ist die Arbeitsfläche. Das Stiftsymbol bearbeitet den Bestandteil, das Auge öffnet eine Vorschau. Ziehen ändert die Reihenfolge, Nach oben und Nach unten tun dasselbe ohne Ziehen.

@@ -419,6 +419,9 @@ @if ($member['edit_url']) Im eigenen Editor öffnen @endif + @if (! empty($member['element_id'])) + + @endif @@ -530,7 +533,7 @@ @endif
- + @if ($this->isProgram())

Ein neues Modul legst du im Aufbau an. Du kehrst danach hierher zurück.

@endif @@ -570,28 +573,4 @@
@endif - @if ($this->fileOpen) - - @endif diff --git a/tests/Feature/EditorialEditorTest.php b/tests/Feature/EditorialEditorTest.php index 02678fb..96bf5f5 100644 --- a/tests/Feature/EditorialEditorTest.php +++ b/tests/Feature/EditorialEditorTest.php @@ -9,6 +9,7 @@ use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; use App\Domain\Catalog\ContentVersionStatus; +use App\Domain\Media\ThumbnailDeriver; use App\Filament\Pages\EditorialDesk; use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Resources\Courses\CourseResource; @@ -18,7 +19,6 @@ use App\Models\User; use Filament\Facades\Filament; use Illuminate\Foundation\Testing\RefreshDatabase; -use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Livewire\Livewire; use Tests\TestCase; @@ -607,24 +607,59 @@ public function test_a_file_can_be_created_inside_the_module(): void { Storage::fake('cms_incoming'); Storage::fake('media_derived'); + Storage::disk('cms_incoming')->put('inhalte/merkblatt.pdf', 'pdfbytes'); + $image = imagecreatetruecolor(8, 8); + ob_start(); + imagejpeg($image); + Storage::disk('cms_incoming')->put('vorschau/karte.jpg', (string) ob_get_clean()); + imagedestroy($image); $editor = $this->editor(); $module = app(ContentService::class)->createComposition('Datei im Modul', CompositionKind::Uebung); - Livewire::actingAs($editor, 'staff') + $component = Livewire::actingAs($editor, 'staff') ->test(EditExercise::class, ['record' => $module->id]) - ->set('newFileTitle', 'Merkblatt') - ->set('incomingFile', UploadedFile::fake()->create('merkblatt.pdf', 12, 'application/pdf')) - ->call('addFile') - ->assertSee('Merkblatt') - ->call('publishRevision'); + ->mountAction('createMedium') + ->assertMountedActionModalSee('Vorschaubild') + ->fillForm([ + 'working_title' => 'Merkblatt', + 'shape' => 'document', + 'description' => 'Für die Gruppe', + 'usage_note' => 'Vorher lesen', + 'incoming' => ['inhalte/merkblatt.pdf'], + 'thumbnail_upload' => ['vorschau/karte.jpg'], + ]) + ->assertMountedActionModalSee('Datei wird hochgeladen') + ->callMountedAction() + ->assertSee('Merkblatt'); $element = ContentElement::query()->where('working_title', 'Merkblatt')->firstOrFail(); $version = $element->versions()->sole(); $this->assertSame('document', $element->output_class); - $this->assertSame(ContentVersionStatus::Bereit, $version->status); + $this->assertSame('Für die Gruppe', $element->description); + $this->assertSame('Vorher lesen', $element->usage_note); + $this->assertSame(ContentVersionStatus::Entwurf, $version->status); + $this->assertSame('eigen', $element->fresh()->thumbnail_source); + app(ThumbnailDeriver::class)->forElement($element->fresh()); + $this->assertSame('eigen', $element->fresh()->thumbnail_source); $this->assertIsString($version->metadata['file'] ?? null); Storage::disk('media_derived')->assertExists($version->metadata['file']); + + $component + ->mountAction('editMedium', ['element' => $element->id]) + ->assertMountedActionModalSee('Vorschaubild') + ->fillForm([ + 'working_title' => 'Merkblatt', + 'description' => 'Überarbeitet', + 'usage_note' => 'Vorher lesen', + ]) + ->callMountedAction(); + + $this->assertSame('Überarbeitet', $element->fresh()->description); + $this->assertSame(1, $element->versions()->count()); + + $component->call('publishRevision'); + $this->assertSame(ContentVersionStatus::Bereit, $version->fresh()->status); $this->assertSame($version->id, $module->fresh()->versions()->first()->members()->first()->content_element_version_id); }