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 arrayDer 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 @@ @endifEin neues Modul legst du im Aufbau an. Du kehrst danach hierher zurück.
@endif @@ -570,28 +573,4 @@