Lege Medien über eine gemeinsame Maske mit Upload-Fortschritt an.
Deploy Test / test (push) Successful in 26s
Deploy Test / deploy (push) Successful in 28s

Beschreibung, Hinweise und Vorschaubild bleiben danach in derselben Maske bearbeitbar, im Bestand wie im Modul und Programm.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-17 10:56:03 +01:00
1 parent c73207f2c3
commit 89c574106f
8 files changed
+407 -160

No files matched your search

+7
View File
@@ -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;
@@ -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;
@@ -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('<a href="'.e($url).'">Medium und Fassungen ansehen</a>');
}),
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('<img src="'.e($url).'" alt="" style="width: 16rem; height: auto;">'.($caption !== '' ? '<p>'.e($caption).'</p>' : ''));
}),
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']
@@ -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) {
@@ -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,
+241
View File
@@ -0,0 +1,241 @@
<?php
namespace App\Filament\Support;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\IdentityProfile;
use App\Jobs\DeriveThumbnail;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Illuminate\Support\Facades\Storage;
class MediumForm
{
/**
* @return list<FileUpload|Select|Textarea|TextInput>
*/
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<string, mixed> $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<string, mixed> $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<string, string|null>
*/
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<string, mixed> $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<string, mixed> $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;
}
}
@@ -41,7 +41,7 @@
<div class="luf-actions">
<button type="button" class="luf-primary" wire:click="openPicker">Bestandteil hinzufügen</button>
<button type="button" class="luf-quiet" wire:click="openText">Text erstellen</button>
<button type="button" class="luf-quiet" wire:click="openFile">Medium anlegen</button>
<button type="button" class="luf-quiet" wire:click="mountAction('createMedium')">Medium anlegen</button>
</div>
</div>
<p class="luf-note">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.</p>
@@ -419,6 +419,9 @@
@if ($member['edit_url'])
<a class="luf-link" href="{{ $member['edit_url'] }}?zurueck={{ urlencode($this->selfUrl()) }}">Im eigenen Editor öffnen</a>
@endif
@if (! empty($member['element_id']))
<button type="button" class="luf-quiet" wire:click="mountAction('editMedium', { element: {{ (int) $member['element_id'] }} })">Angaben und Vorschaubild</button>
@endif
<button type="button" class="luf-quiet" wire:click="removePart({{ $this->selected }})">Aus dem Aufbau nehmen</button>
</div>
</div>
@@ -530,7 +533,7 @@
@endif
<div class="luf-actions">
<button type="button" class="luf-quiet" wire:click="openText">Neuen Text erstellen</button>
<button type="button" class="luf-quiet" wire:click="openFile">Medium anlegen</button>
<button type="button" class="luf-quiet" wire:click="mountAction('createMedium')">Medium anlegen</button>
@if ($this->isProgram())
<p class="luf-note">Ein neues Modul legst du im Aufbau an. Du kehrst danach hierher zurück.</p>
@endif
@@ -570,28 +573,4 @@
</div>
@endif
@if ($this->fileOpen)
<div class="luf-modal" role="dialog" aria-modal="true" aria-labelledby="datei-titel-ueberschrift">
<form class="luf-modal-card luf-modal-narrow" wire:submit="addFile">
<div class="luf-pane-head">
<h2 id="datei-titel-ueberschrift">Medium anlegen</h2>
<button type="button" class="luf-quiet" wire:click="cancelFile">Abbrechen</button>
</div>
<p class="luf-note">Die Datei wird bei den Medien gespeichert und in diesen Aufbau übernommen. Sie wird nicht kopiert. Solange die Fassung nicht freigegeben und verwendet wird, bleibt sie ein Entwurf.</p>
<div class="luf-field">
<label for="datei-titel">Titel</label>
<input id="datei-titel" type="text" wire:model="newFileTitle" required>
</div>
<div class="luf-field">
<label for="datei-datei">Datei</label>
<input id="datei-datei" type="file" wire:model="incomingFile" accept=".mp4,.webm,.mov,.m4v,.mp3,.m4a,.wav,.ogg,.png,.jpg,.jpeg,.webp,.gif,.pdf" required>
<span class="luf-meta">Film, Hörstück, Bild oder PDF.</span>
</div>
<div class="luf-actions">
<button class="luf-primary" type="submit">Medium anlegen und übernehmen</button>
<button type="button" class="luf-quiet" wire:click="cancelFile">Abbrechen</button>
</div>
</form>
</div>
@endif
</div>
+43 -8
View File
@@ -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);
}