Fasse die Bearbeitung in Dialoge und übernimm eine Filmstelle als Titelbild.
Deploy Test / test (push) Successful in 23s
Deploy Test / deploy (push) Successful in 22s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-16 18:58:26 +01:00
1 parent 9195cdcd15
commit c47c3b9b32
9 files changed
+1052 -228

No files matched your search

@@ -20,6 +20,8 @@
use App\Domain\Catalog\IdentityProfile;
use App\Domain\Catalog\StructureNode;
use App\Filament\Support\EditorialCatalog;
use App\Http\Controllers\ContentPreviewController;
use App\Jobs\DeriveCompositionFrame;
use App\Jobs\DeriveThumbnail;
use App\Models\User;
use Filament\Actions\Action;
@@ -101,6 +103,26 @@ abstract class EditComposition extends EditRecord
public string $imageQuery = '';
public bool $moduleOpen = false;
public string $moduleTab = 'beschreibung';
public bool $partOpen = false;
public string $imageMode = 'film';
public string $imagePick = '';
public ?int $frameVersionId = null;
public string $frameSecond = '';
/** @var array<string, mixed> */
public array $moduleSnapshot = [];
/** @var list<array<string, mixed>> */
public array $partSnapshot = [];
/** @var list<array<string, string|null>> */
public array $members = [];
@@ -260,6 +282,14 @@ public function hits(): array
public function openPicker(): void
{
if ($this->moduleOpen) {
$this->closeModule();
}
if ($this->partOpen) {
$this->closePart();
}
$this->pickerOpen = true;
$this->textOpen = false;
$this->pickerSelected = '';
@@ -296,15 +326,67 @@ public function pickerDetail(): ?array
return null;
}
return app(EditorialCatalog::class)->rowForTarget(
$row = app(EditorialCatalog::class)->rowForTarget(
$this->pickerSelected,
(int) $this->getRecord()->getKey(),
);
if ($row === null) {
return null;
}
$row['file_url'] = null;
if (preg_match('/^element:(\d+)$/', (string) $row['target'], $match) === 1) {
$version = ContentElementVersion::query()->find($match[1]);
$row['file_url'] = $version instanceof ContentElementVersion
? app(ContentPreviewController::class)->fileUrl($version)
: null;
}
return $row;
}
/**
* @return list<array{target: string, label: string, current: bool}>
*/
public function pickerVersions(): array
{
$detail = $this->pickerDetail();
if ($detail === null) {
return [];
}
$options = app(EditorialCatalog::class)->alternatives(
(string) ($detail['identity'] ?? ''),
(int) $this->getRecord()->getKey(),
);
if ($options === []) {
return [];
}
$current = $options[array_key_last($options)]['target'];
return array_map(
fn (array $option): array => $option + ['current' => $option['target'] === $current],
$options,
);
}
public function pickerMatches(string $identity): bool
{
$detail = $this->pickerDetail();
return $detail !== null && ($detail['identity'] ?? '') === $identity;
}
public function openText(): void
{
$this->pickerOpen = false;
$this->moduleOpen = false;
$this->partOpen = false;
$this->textOpen = true;
}
@@ -611,7 +693,12 @@ public function addPart(string $target): void
$this->search = '';
$this->pickerOpen = false;
$this->pickerSelected = '';
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die Datei wird nicht kopiert. Gespeichert ist das erst mit „Entwurf speichern“.';
if (! $this->persistDraft()) {
return;
}
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die Datei wird nicht kopiert. Der Entwurf ist gespeichert. Es entsteht keine neue Fassung.';
}
public function removePart(int $index): void
@@ -625,7 +712,9 @@ public function removePart(int $index): void
$this->selected = null;
$this->roleDraft = '';
$this->panel = 'angaben';
$this->feedback = 'Der Bestandteil ist aus dem Arbeitsstand genommen. Gespeichert ist das erst mit einer neuen Fassung.';
$this->partOpen = false;
$this->partSnapshot = [];
$this->feedback = 'Der Bestandteil ist aus dem Arbeitsstand genommen. Entwurf speichern hält das fest. Eine freigegebene Fassung bleibt unverändert.';
}
public function movePart(int $index, int $direction): void
@@ -663,7 +752,7 @@ public function useVersion(int $index, string $target): void
$row['role'] = $this->members[$index]['role'] ?? $row['kind'];
$this->members[$index] = $row;
$this->syncRoleDraft();
$this->feedback = $row['version_label'].' ist für diese Stelle ausgewählt. Übernehmen legt dafür eine neue Fassung an.';
$this->feedback = $row['version_label'].' ist für diese Stelle ausgewählt. Der Entwurf speichert das. Eine freigegebene Fassung bleibt unverändert.';
}
public function loadTemplate(int $versionId): void
@@ -678,7 +767,7 @@ public function loadTemplate(int $versionId): void
$this->applyVersion($version);
$this->templateNumber = $version->number;
$this->feedback = 'Fassung '.$version->number.' ist als Arbeitsstand geladen. Übernehmen legt eine neue Fassung an und lässt die geladene Fassung unverändert.';
$this->feedback = 'Fassung '.$version->number.' ist als Arbeitsstand geladen. Die geladene Fassung bleibt unverändert.';
}
public function addText(): void
@@ -706,7 +795,7 @@ public function addText(): void
$this->newTextBody = '';
$this->textOpen = false;
$this->addPart('element:'.$version->id);
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Derselbe Text kann später woanders wiederverwendet werden. Gespeichert ist das erst mit „Entwurf speichern“.';
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Derselbe Text kann später woanders wiederverwendet werden. Der Entwurf ist gespeichert. Es entsteht keine neue Fassung dieses Eintrags.';
}
public function startModule(): void
@@ -727,27 +816,197 @@ public function startModule(): void
public function saveDisplay(): void
{
/** @var Composition $record */
$record = $this->getRecord();
$name = trim($this->designation);
if (! $this->persistPresentation()) {
return;
}
if ($name === '') {
$this->feedback = 'Der Name fehlt.';
$this->feedback = 'Die Anzeige ist gespeichert. Die Fassung bleibt unverändert.';
}
public function openModule(): void
{
$this->moduleSnapshot = [
'designation' => $this->designation,
'displayTitle' => $this->displayTitle,
'summary' => $this->summary,
'description' => $this->description,
'learningGoal' => $this->learningGoal,
'durationMinutes' => $this->durationMinutes,
'materialNote' => $this->materialNote,
'revisionNote' => $this->revisionNote,
'thumbnailAlt' => $this->thumbnailAlt,
'dimensionIds' => $this->dimensionIds,
'imageMode' => $this->imageMode,
'imagePick' => $this->imagePick,
'frameVersionId' => $this->frameVersionId,
'frameSecond' => $this->frameSecond,
];
$this->pickerOpen = false;
$this->partOpen = false;
$this->textOpen = false;
$this->moduleTab = 'beschreibung';
$films = $this->frameFilms();
$this->imageMode = $films === [] ? 'bestand' : 'film';
if ($films !== [] && $this->frameVersionId === null) {
$this->frameVersionId = $films[0]['version_id'];
}
$this->moduleOpen = true;
}
public function closeModule(): void
{
foreach ($this->moduleSnapshot as $key => $value) {
$this->{$key} = $value;
}
$this->moduleOpen = false;
$this->moduleSnapshot = [];
$this->previewUpload = null;
}
public function saveModule(): void
{
if ($this->minutes($this->durationMinutes) === false) {
$this->feedback = 'Der Zeitbedarf ist eine Zahl von Minuten oder bleibt leer.';
return;
}
$record->designation = $name;
app(IdentityProfile::class)->fill($record, [
'display_title' => $this->displayTitle,
'summary' => $this->summary,
'description' => $this->description,
'thumbnail_alt' => $this->thumbnailAlt,
], $this->actor());
$this->syncDimensions($record, array_map(intval(...), $this->dimensionIds));
$record->refresh();
$this->getRecord()->setRawAttributes($record->getAttributes());
$this->feedback = 'Die Anzeige ist gespeichert. Die Fassung bleibt unverändert.';
if (! $this->persistPresentation()) {
return;
}
$image = $this->applyChosenImage();
if ($image === false) {
return;
}
/** @var Composition $record */
$record = $this->getRecord();
if ($this->needsRevision() || app(EditorialWorkingDraft::class)->read($record) !== null) {
$this->persistDraft();
}
$this->moduleOpen = false;
$this->moduleSnapshot = [];
$this->previewUpload = null;
$this->imagePick = '';
$this->feedback = trim('Die Angaben sind übernommen. Es entsteht keine neue Fassung.'.($image === '' ? '' : ' '.$image));
}
public function openPart(int $index): void
{
$this->selectPart($index);
$this->partSnapshot = $this->members;
$this->moduleOpen = false;
$this->pickerOpen = false;
$this->textOpen = false;
$this->partOpen = true;
}
public function closePart(): void
{
if ($this->partSnapshot !== []) {
$this->members = $this->partSnapshot;
}
$this->partOpen = false;
$this->partSnapshot = [];
$this->syncRoleDraft();
}
public function savePart(): void
{
if (trim($this->roleDraft) === '') {
$this->feedback = 'Die Rolle fehlt.';
return;
}
$this->commitRoleDraft();
if (! $this->persistDraft()) {
return;
}
$this->partOpen = false;
$this->partSnapshot = [];
$this->feedback = 'Die Angaben zum Bestandteil sind im Entwurf. Es entsteht keine neue Fassung.';
}
/**
* @return list<array{version_id: int, title: string, label: string, file_url: ?string}>
*/
public function frameFilms(): array
{
$preview = app(ContentPreviewController::class);
$films = [];
foreach ($this->members as $member) {
if (preg_match('/^element:(\d+)$/', (string) ($member['target'] ?? ''), $match) !== 1) {
continue;
}
$version = ContentElementVersion::query()->with('element')->find($match[1]);
if (! $version instanceof ContentElementVersion || $version->element?->output_class !== 'film') {
continue;
}
$films[] = [
'version_id' => $version->id,
'title' => (string) ($member['title'] ?? $version->element->working_title),
'label' => 'Fassung '.$version->number,
'file_url' => $preview->fileUrl($version),
];
}
return $films;
}
public function framePreviewUrl(): ?string
{
if ($this->frameVersionId === null || ! is_numeric($this->frameSecond) || trim($this->frameSecond) === '') {
return null;
}
return route('editorial.frame', [
'version' => $this->frameVersionId,
'sekunde' => $this->frameSecond,
]);
}
public function imageCaption(): ?string
{
/** @var Composition $composition */
$composition = $this->getRecord();
$composition->refresh();
$source = $composition->thumbnail_source;
if (! is_string($source) || $source === '') {
return null;
}
if (preg_match('/^frame:(\d+)@([\d.]+)$/', $source, $match) === 1) {
$version = ContentElementVersion::query()->with('element')->find($match[1]);
$title = $version?->element?->working_title ?: 'dem Film';
return 'Titelbild aus '.$title.' bei '.$match[2].' Sekunden.';
}
if ($source === 'eigen') {
return 'Eigenes Titelbild.';
}
if (str_starts_with($source, 'element:')) {
return 'Titelbild aus einem vorhandenen Bild.';
}
return null;
}
public function savePreview(): void
@@ -1228,6 +1487,120 @@ protected function syncDimensions(Composition $composition, array $ids): void
}
}
protected function persistPresentation(): bool
{
/** @var Composition $record */
$record = $this->getRecord();
$name = trim($this->designation);
if ($name === '') {
$this->feedback = 'Der Name fehlt.';
return false;
}
$record->designation = $name;
app(IdentityProfile::class)->fill($record, [
'display_title' => $this->displayTitle,
'summary' => $this->summary,
'description' => $this->description,
'thumbnail_alt' => $this->thumbnailAlt,
], $this->actor());
$this->syncDimensions($record, array_map(intval(...), $this->dimensionIds));
$record->refresh();
$this->getRecord()->setRawAttributes($record->getAttributes());
return true;
}
protected function persistDraft(): bool
{
if ($this->minutes($this->durationMinutes) === false) {
$this->feedback = 'Der Zeitbedarf ist eine Zahl von Minuten oder bleibt leer.';
return false;
}
/** @var Composition $record */
$record = $this->getRecord();
app(EditorialWorkingDraft::class)->write($record, $this->payload());
return true;
}
protected function applyChosenImage(): string|false
{
if ($this->imageMode === 'upload' && $this->previewUpload instanceof TemporaryUploadedFile) {
$extension = strtolower($this->previewUpload->getClientOriginalExtension());
if (! in_array($extension, ['png', 'jpg', 'jpeg', 'webp'], true)) {
$this->feedback = 'Das Vorschaubild muss eine Bilddatei sein.';
return false;
}
$path = $this->previewUpload->storeAs(
'vorschau',
'karte-'.bin2hex(random_bytes(4)).'.'.$extension,
'cms_incoming',
);
$this->previewUpload = null;
if (! is_string($path)) {
$this->feedback = 'Das Vorschaubild wurde nicht übernommen.';
return false;
}
$this->storePreview($path);
return str_contains($this->feedback, 'unverändert') ? $this->feedback : false;
}
if ($this->imageMode === 'bestand' && ctype_digit($this->imagePick)) {
$this->adoptPicture((int) $this->imagePick);
return str_contains($this->feedback, 'unverändert') ? $this->feedback : false;
}
if ($this->imageMode === 'film' && $this->frameVersionId !== null && trim($this->frameSecond) !== '') {
if (! is_numeric($this->frameSecond) || (float) $this->frameSecond < 0 || (float) $this->frameSecond > 7200) {
$this->feedback = 'Die Zeitposition muss eine Zahl in Sekunden sein.';
return false;
}
$version = ContentElementVersion::query()->with('element')->find($this->frameVersionId);
$target = 'element:'.(int) $this->frameVersionId;
$known = array_map(fn (array $member): string => (string) ($member['target'] ?? ''), $this->members);
if (! $version instanceof ContentElementVersion || $version->element?->output_class !== 'film' || ! in_array($target, $known, true)) {
$this->feedback = 'Die Filmfassung gehört nicht zu diesem Aufbau.';
return false;
}
/** @var Composition $record */
$record = $this->getRecord();
$before = $record->versions()->count();
DeriveCompositionFrame::dispatch($record->id, $version->id, (float) $this->frameSecond);
$record->refresh();
$this->thumbnailPath = $record->thumbnail_path;
$this->thumbnailError = $record->thumbnail_error;
$note = $this->previewFeedback($record, $before);
if (! str_contains($note, 'unverändert')) {
$this->feedback = $note;
return false;
}
return $note;
}
return '';
}
protected function storePreview(string $path): void
{
if (! str_starts_with($path, 'vorschau/') || str_contains($path, '..')) {