From e1fd59491cc36745ab1679d6298128dc413ac2b1 Mon Sep 17 00:00:00 2001 From: Lars Date: Thu, 19 Nov 2026 22:46:43 +0100 Subject: [PATCH] Baue den Redaktionsmanager auf gemeinsame Bausteine um. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Medium, Modul, Programm und Lizenzartikel nutzen denselben Objektkopf, dieselben Register (Texte, Präsentationsmedien, Einordnung) und denselben visuellen Picker. Präsentationsmedien, Abweichungen und Texte bilden einen Arbeitsstand, den nur „Redaktion speichern“ schreibt; Austausch behält die Position, Sortierung bleibt in der Rolle. Der Wechsel zur Redaktion und zurück erhält offene Eingaben des Ausgangseditors. Entfernt versteckte Mitspeicherungen: Der Didaktikdialog schreibt keine Redaktionstexte mehr, die Website-Freigabe keine offenen Quellenzeilen, Entwurf verwerfen setzt keine offenen Redaktionseingaben zurück. Tests, die alte Orte oder CSS-Zeichenketten prüften, sind auf die neue Bedienung umgestellt; neue Tests decken Arbeitsstand, Austausch, Abbrechen und Rückweg ab. Datenmodell, Fassungen und Rechte bleiben unverändert. Co-Authored-By: Claude Opus 5.5 --- app/Domain/Catalog/PresentationMedia.php | 219 ++- app/Domain/Catalog/PresentationRole.php | 16 + .../Compositions/Pages/EditComposition.php | 535 +++---- .../Pages/ViewContentElement.php | 318 ++-- .../LicenseArticleResource.php | 19 +- .../Pages/ViewLicenseArticle.php | 292 +++- app/Filament/Support/EditorialCatalog.php | 19 +- .../Support/ManagesEditorialSurface.php | 1321 +++++++++++++---- app/Providers/Filament/AdminPanelProvider.php | 2 +- .../views/filament/editorial/editor.blade.php | 325 +--- .../filament/editorial/license-desk.blade.php | 107 +- .../editorial/presentation-picker.blade.php | 64 - .../filament/editorial/presentation.blade.php | 108 -- .../views/filament/editorial/styles.blade.php | 300 ---- .../filament/media/editor-panels.blade.php | 83 -- .../filament/media/preview-frame.blade.php | 18 +- .../views/filament/media/viewer.blade.php | 488 +++--- .../filament/verwaltung/abschnitt.blade.php | 48 - .../filament/verwaltung/chipgruppe.blade.php | 11 - .../verwaltung/einordnung-artikel.blade.php | 22 - .../einordnung-komposition.blade.php | 14 - .../verwaltung/einordnung-medium.blade.php | 35 - .../filament/verwaltung/einordnung.blade.php | 42 + .../views/filament/verwaltung/icon.blade.php | 26 + .../views/filament/verwaltung/kopf.blade.php | 90 ++ .../filament/verwaltung/picker.blade.php | 261 ++++ .../verwaltung/praesentation.blade.php | 129 ++ .../filament/verwaltung/redaktion.blade.php | 159 +- .../filament/verwaltung/styles.blade.php | 350 +++++ .../verwaltung/texte-artikel.blade.php | 33 - .../verwaltung/texte-komposition.blade.php | 30 - .../verwaltung/texte-medium.blade.php | 35 - .../views/filament/verwaltung/texte.blade.php | 47 + .../filament/verwaltung/textfeld.blade.php | 72 + .../filament/verwaltung/varianten.blade.php | 59 + .../verwaltung/zuordnung-menue.blade.php | 32 + tests/Feature/CatalogAdministrationTest.php | 8 +- tests/Feature/EditorialDeskTest.php | 41 +- tests/Feature/EditorialEditorTest.php | 25 +- tests/Feature/MediaAdministrationTest.php | 10 +- tests/Feature/MediaEditorTest.php | 5 +- tests/Feature/PresentationMediaTest.php | 11 +- tests/Feature/VerwaltungArbeitsplatzTest.php | 257 +++- tests/Feature/WebsiteReleaseTest.php | 4 + 44 files changed, 3917 insertions(+), 2173 deletions(-) delete mode 100644 resources/views/filament/editorial/presentation-picker.blade.php delete mode 100644 resources/views/filament/editorial/presentation.blade.php delete mode 100644 resources/views/filament/media/editor-panels.blade.php delete mode 100644 resources/views/filament/verwaltung/abschnitt.blade.php delete mode 100644 resources/views/filament/verwaltung/chipgruppe.blade.php delete mode 100644 resources/views/filament/verwaltung/einordnung-artikel.blade.php delete mode 100644 resources/views/filament/verwaltung/einordnung-komposition.blade.php delete mode 100644 resources/views/filament/verwaltung/einordnung-medium.blade.php create mode 100644 resources/views/filament/verwaltung/einordnung.blade.php create mode 100644 resources/views/filament/verwaltung/icon.blade.php create mode 100644 resources/views/filament/verwaltung/kopf.blade.php create mode 100644 resources/views/filament/verwaltung/picker.blade.php create mode 100644 resources/views/filament/verwaltung/praesentation.blade.php create mode 100644 resources/views/filament/verwaltung/styles.blade.php delete mode 100644 resources/views/filament/verwaltung/texte-artikel.blade.php delete mode 100644 resources/views/filament/verwaltung/texte-komposition.blade.php delete mode 100644 resources/views/filament/verwaltung/texte-medium.blade.php create mode 100644 resources/views/filament/verwaltung/texte.blade.php create mode 100644 resources/views/filament/verwaltung/textfeld.blade.php create mode 100644 resources/views/filament/verwaltung/varianten.blade.php create mode 100644 resources/views/filament/verwaltung/zuordnung-menue.blade.php diff --git a/app/Domain/Catalog/PresentationMedia.php b/app/Domain/Catalog/PresentationMedia.php index 375b091..0a83c0c 100644 --- a/app/Domain/Catalog/PresentationMedia.php +++ b/app/Domain/Catalog/PresentationMedia.php @@ -6,6 +6,7 @@ use App\Domain\Media\WebsiteMedia; use App\Models\User; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\DB; /** * Präsentationsmedien sind Referenzen auf Inhaltselemente. @@ -60,6 +61,215 @@ public function rows(Model $subject): array return $rows; } + /** + * Gespeicherte Zuordnungen als bearbeitbarer Arbeitsstand, nach Rolle und Position geordnet. + * + * @return list + */ + public function staged(Model $subject): array + { + $assignments = PresentationAssignment::query() + ->with('role') + ->where('subject_type', $subject->getMorphClass()) + ->where('subject_id', $subject->getKey()) + ->get() + ->sortBy(fn (PresentationAssignment $row): string => sprintf('%05d-%05d-%08d', (int) $row->role?->sort_order, (int) $row->position, (int) $row->id)) + ->values(); + + $rows = []; + + foreach ($assignments as $assignment) { + $rows[] = [ + 'key' => 'a'.$assignment->id, + 'id' => (int) $assignment->id, + 'role' => (string) $assignment->role?->slug, + 'element_id' => (int) $assignment->content_element_id, + 'source' => $assignment->source_version_id !== null ? (int) $assignment->source_version_id : null, + ]; + } + + return $rows; + } + + /** + * Anzeigezeilen für einen Arbeitsstand, gruppiert nach Rolle. Liest nur, schreibt nichts. + * + * @param list $staged + * @return list>}> + */ + public function describe(array $staged): array + { + $roles = PresentationRole::query()->orderBy('sort_order')->get()->keyBy('slug'); + $elements = ContentElement::query() + ->with('editorialContentKind') + ->whereIn('id', array_values(array_unique(array_map(fn (array $row): int => (int) $row['element_id'], $staged)))) + ->get() + ->keyBy('id'); + $sources = ContentElementVersion::query() + ->whereIn('id', array_values(array_filter(array_map(fn (array $row): ?int => $row['source'] ?? null, $staged)))) + ->get() + ->keyBy('id'); + $groups = []; + + foreach ($roles as $slug => $role) { + $rows = array_values(array_filter($staged, fn (array $row): bool => $row['role'] === $slug)); + + if ($rows === []) { + continue; + } + + $described = []; + + foreach ($rows as $row) { + $element = $elements->get((int) $row['element_id']); + $released = $element instanceof ContentElement && $this->website->present($element) !== null; + $source = $row['source'] !== null ? $sources->get((int) $row['source']) : null; + + $described[] = [ + 'key' => $row['key'], + 'id' => $row['id'], + 'element_id' => (int) $row['element_id'], + 'title' => $element instanceof ContentElement + ? (string) ($element->display_title ?: $element->working_title) + : 'Medium fehlt', + 'image' => $element instanceof ContentElement + ? ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path) + : null, + 'kind' => $element?->editorialContentKind?->label, + 'output' => $element instanceof ContentElement ? (string) $element->output_class : '', + 'released' => $released, + 'release_label' => $released ? 'Für die Website freigegeben' : 'Nicht für die Website freigegeben', + 'binding' => $source instanceof ContentElementVersion ? $this->bindingFor($source) : null, + 'new' => $row['id'] === null, + ]; + } + + $groups[] = [ + 'role' => (string) $slug, + 'label' => PresentationRole::displayLabel((string) $slug, (string) $role->label), + 'multiple' => (bool) $role->multiple, + 'ordered' => (bool) $role->ordered, + 'rows' => $described, + ]; + } + + return $groups; + } + + /** + * Prüft, ob ein Medium im Arbeitsstand einer Rolle zugeordnet werden darf. Liefert den Ablehnungsgrund oder null. + */ + public function refusal(Model $subject, string $roleSlug, int $elementId): ?string + { + $role = PresentationRole::query()->where('slug', $roleSlug)->first(); + $element = ContentElement::query()->find($elementId); + + if (! $role instanceof PresentationRole || ! $element instanceof ContentElement) { + return 'Rolle oder Medium fehlt.'; + } + + if ($element->archived_at !== null) { + return 'Ein archiviertes Medium wird nicht zugeordnet.'; + } + + if ($subject instanceof ContentElement && (int) $subject->getKey() === (int) $element->id) { + return 'Ein Medium kann nicht seine eigene Präsentation sein.'; + } + + return null; + } + + /** + * Schreibt einen Arbeitsstand: entfernte Zuordnungen lösen, neue anlegen, Bindung und Reihenfolge je Rolle setzen. + * Medien, Fassungen und Website-Freigaben bleiben unberührt. + * + * @param list $staged + */ + public function commit(Model $subject, array $staged, ?User $actor = null): void + { + $roles = PresentationRole::query()->get()->keyBy('slug'); + $seen = []; + + foreach ($staged as $row) { + $role = $roles->get($row['role']); + + if (! $role instanceof PresentationRole) { + throw new DomainRuleException('Diese Rolle gibt es nicht.'); + } + + $refusal = $this->refusal($subject, $row['role'], (int) $row['element_id']); + + if ($refusal !== null) { + throw new DomainRuleException($refusal); + } + + $pair = $row['role'].':'.$row['element_id']; + + if (isset($seen[$pair])) { + throw new DomainRuleException('Ein Medium steht in derselben Rolle nur einmal.'); + } + + $seen[$pair] = true; + $count = count(array_filter($staged, fn (array $other): bool => $other['role'] === $row['role'])); + + if (! $role->multiple && $count > 1) { + throw new DomainRuleException($role->label.' hat nur eine Zuordnung.'); + } + + $element = ContentElement::query()->findOrFail((int) $row['element_id']); + $this->checkedSource($subject, $element, $row['source']); + } + + DB::transaction(function () use ($subject, $staged, $roles, $actor): void { + $existing = PresentationAssignment::query() + ->with(['role', 'element']) + ->where('subject_type', $subject->getMorphClass()) + ->where('subject_id', $subject->getKey()) + ->get() + ->keyBy('id'); + $kept = array_filter(array_map(fn (array $row): ?int => $row['id'], $staged)); + + foreach ($existing as $id => $assignment) { + if (! in_array((int) $id, $kept, true)) { + $this->record($subject, ($assignment->role?->label ?? 'Präsentation').': '.($assignment->element?->working_title ?? ''), null, $actor); + $assignment->delete(); + } + } + + $positions = []; + + foreach ($staged as $row) { + $role = $roles->get($row['role']); + $position = $positions[$row['role']] = ($positions[$row['role']] ?? 0) + 1; + $assignment = $row['id'] !== null ? $existing->get($row['id']) : null; + + if ($assignment instanceof PresentationAssignment) { + $changed = (int) $assignment->position !== $position + || (int) ($assignment->source_version_id ?? 0) !== (int) ($row['source'] ?? 0); + $assignment->position = $position; + $assignment->source_version_id = $row['source']; + + if ($changed) { + $assignment->save(); + } + + continue; + } + + $element = ContentElement::query()->findOrFail((int) $row['element_id']); + PresentationAssignment::query()->create([ + 'subject_type' => $subject->getMorphClass(), + 'subject_id' => $subject->getKey(), + 'content_element_id' => $element->id, + 'presentation_role_id' => $role->id, + 'position' => $position, + 'source_version_id' => $row['source'], + ]); + $this->record($subject, null, $role->label.': '.$element->working_title, $actor); + } + }); + } + public function assign(Model $subject, string $roleSlug, int $elementId, ?int $sourceVersionId, ?User $actor = null): string { $role = PresentationRole::query()->where('slug', $roleSlug)->first(); @@ -242,7 +452,14 @@ private function binding(PresentationAssignment $assignment): ?array return null; } - $version = $assignment->sourceVersion; + return $this->bindingFor($assignment->sourceVersion); + } + + /** + * @return array{label: string, stale: bool} + */ + private function bindingFor(ContentElementVersion $version): array + { $latestId = ContentElementVersion::query() ->where('content_element_id', $version->content_element_id) ->where('status', ContentVersionStatus::Bereit) diff --git a/app/Domain/Catalog/PresentationRole.php b/app/Domain/Catalog/PresentationRole.php index 7284b9b..37638bf 100644 --- a/app/Domain/Catalog/PresentationRole.php +++ b/app/Domain/Catalog/PresentationRole.php @@ -41,4 +41,20 @@ public static function selectOptions(): array { return static::query()->orderBy('sort_order')->pluck('label', 'slug')->all(); } + + /** + * Kurze Bezeichnung für Überschriften und Auswahl in der Verwaltung. + */ + public static function displayLabel(string $slug, string $label): string + { + return match ($slug) { + 'titelbild' => 'Titelbild', + 'titelbild_alternativ' => 'Alternative Titelbilder', + 'trailer' => 'Trailer', + 'vorschauclip' => 'Vorschauclips', + 'interview' => 'Interviews', + 'galerie' => 'Galerie', + default => $label, + }; + } } diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index 0ca3337..2bdaaf0 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -19,11 +19,13 @@ use App\Domain\Catalog\IdentityDimensionValue; use App\Domain\Catalog\IdentityProfile; use App\Domain\Catalog\StructureNode; -use App\Domain\Cms\Catalog\PublicMaterialReader; +use App\Domain\Cms\Catalog\PublicCatalogReader; +use App\Domain\Cms\Widgets\RenderContext; use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Support\EditorialCatalog; use App\Filament\Support\ManagesEditorialSurface; use App\Filament\Support\MediumForm; +use App\Filament\Support\WidgetEditor; use App\Http\Controllers\ContentPreviewController; use App\Jobs\DeriveCompositionFrame; use App\Jobs\DeriveThumbnail; @@ -87,22 +89,6 @@ abstract class EditComposition extends EditRecord public string $panel = 'angaben'; - public bool $pickerOpen = false; - - public string $pickerPurpose = 'aufbau'; - - public string $pickerQuery = ''; - - public string $pickerKind = 'alle'; - - public string $pickerLayout = 'liste'; - - public string $pickerDimension = ''; - - public string $pickerSelected = ''; - - public string $pickerInspected = ''; - public bool $textOpen = false; public bool $releaseArmed = false; @@ -139,7 +125,7 @@ abstract class EditComposition extends EditRecord public bool $moduleOpen = false; - public string $moduleTab = 'beschreibung'; + public string $moduleTab = 'didaktik'; public bool $partOpen = false; @@ -182,24 +168,11 @@ public function mount(int|string $record): void } } - public function getHeading(): string|Htmlable|null + public function getTitle(): string|Htmlable { - if ($this->redaktionOpen) { - return null; - } + $title = trim((string) $this->getRecord()->display_title) !== '' ? (string) $this->getRecord()->display_title : (string) $this->getRecord()->designation; - $title = trim($this->displayTitle) !== '' ? trim($this->displayTitle) : trim($this->designation); - - return $title !== '' ? $title : parent::getHeading(); - } - - public function getSubheading(): string|Htmlable|null - { - if ($this->redaktionOpen) { - return null; - } - - return $this->hostKind()->deskExplanation().' '.$this->statusSentence(); + return $title !== '' ? $title : $this->hostLabel(); } public function getMaxContentWidth(): Width|string|null @@ -214,47 +187,53 @@ protected function mutateFormDataBeforeFill(array $data): array protected function getHeaderActions(): array { - if ($this->redaktionOpen) { - return []; - } + return []; + } - return [ - Action::make('preview') - ->label('Vorschau für Trainer') - ->url(fn (): ?string => $this->previewUrl()) - ->openUrlInNewTab() - ->visible(fn (): bool => $this->previewUrl() !== null), - Action::make('displayRelease') - ->label('In Mitgliederbibliothek anzeigen') - ->requiresConfirmation() - ->modalHeading('In der Mitgliederbibliothek anzeigen') - ->modalDescription('Sichtbar wird die zuletzt übernommene Fassung. Das ist keine Website-Veröffentlichung und kein aktives Angebot. Eine frühere Fassung bleibt unverändert. Ungespeicherte Änderungen am Aufbau sind nicht Teil dieser Freigabe.') - ->visible(function (): bool { - $version = $this->currentReadyVersion(); + public function displayReleaseAction(): Action + { + return Action::make('displayRelease') + ->label('In Mitgliederbibliothek anzeigen') + ->requiresConfirmation() + ->modalHeading('In der Mitgliederbibliothek anzeigen') + ->modalDescription('Sichtbar wird die zuletzt übernommene Fassung. Das ist keine Website-Veröffentlichung und kein aktives Angebot. Eine frühere Fassung bleibt unverändert. Ungespeicherte Änderungen am Aufbau sind nicht Teil dieser Freigabe.') + ->visible(function (): bool { + $version = $this->currentReadyVersion(); - return $version !== null && ! app(CompositionDisplayRelease::class)->isReleased($version); - }) - ->action(function (): void { - $this->releaseDisplay(); - }), - Action::make('displayRevoke') - ->label('Aus Mitgliederbibliothek ausblenden') - ->color('danger') - ->requiresConfirmation() - ->modalDescription('Die Fassung verschwindet aus der Mitgliederbibliothek. Der fachliche Inhalt bleibt gespeichert. Website und Angebot sind davon unabhängig.') - ->visible(function (): bool { - $version = $this->currentReadyVersion(); + return $version !== null && ! app(CompositionDisplayRelease::class)->isReleased($version); + }) + ->action(function (): void { + $this->releaseDisplay(); + }); + } - return $version !== null && app(CompositionDisplayRelease::class)->isReleased($version); - }) - ->action(function (): void { - $version = $this->currentReadyVersion(); - $actor = $this->actor(); - abort_unless($version !== null && $actor instanceof User, 403); - app(CompositionDisplayRelease::class)->revoke($version, $actor); - $this->feedback = 'Die Fassung ist aus der Mitgliederbibliothek ausgeblendet. Der Inhalt bleibt gespeichert.'; - }), - ]; + public function displayRevokeAction(): Action + { + return Action::make('displayRevoke') + ->label('Aus Mitgliederbibliothek ausblenden') + ->color('danger') + ->requiresConfirmation() + ->modalHeading('Aus der Mitgliederbibliothek ausblenden') + ->modalDescription('Die Fassung verschwindet aus der Mitgliederbibliothek. Der fachliche Inhalt bleibt gespeichert. Website und Angebot sind davon unabhängig.') + ->visible(function (): bool { + $version = $this->currentReadyVersion(); + + return $version !== null && app(CompositionDisplayRelease::class)->isReleased($version); + }) + ->action(function (): void { + $version = $this->currentReadyVersion(); + $actor = $this->actor(); + abort_unless($version !== null && $actor instanceof User, 403); + app(CompositionDisplayRelease::class)->revoke($version, $actor); + $this->feedback = 'Die Fassung ist aus der Mitgliederbibliothek ausgeblendet. Der Inhalt bleibt gespeichert.'; + }); + } + + public function isInLibrary(): bool + { + $version = $this->currentReadyVersion(); + + return $version !== null && app(CompositionDisplayRelease::class)->isReleased($version); } public function hostKind(): CompositionKind @@ -336,58 +315,158 @@ public function openPicker(): void $this->closePart(); } - $this->pickerPurpose = 'aufbau'; - $this->pickerOpen = true; $this->textOpen = false; - $this->pickerSelected = ''; - $this->pickerInspected = ''; + $this->resetPicker('aufbau'); + $this->pickerKind = 'alle'; } - public function openRedaktion(): void + /** + * Schließt die Dialoge des Aufbaus, ohne deren offene Eingaben zu verwerfen. + */ + protected function redaktionWillOpen(): void + { + $this->moduleOpen = false; + $this->partOpen = false; + $this->textOpen = false; + $this->releaseArmed = false; + } + + protected function saveRedaktionTexte(): bool { $this->guardEditorial(); - $this->moduleOpen = false; - $this->moduleSnapshot = []; - $this->partOpen = false; - $this->pickerOpen = false; - $this->textOpen = false; - $this->redaktionOpen = true; - $this->redaktionTab = 'texte'; - } - public function closeRedaktion(): void - { - $this->redaktionOpen = false; - $this->pickerOpen = false; - $this->replacingAssignment = null; - $this->presentationInspect = ''; - } + if (trim($this->designation) === '') { + $this->deskFeedback = 'Der Name fehlt. Er bezeichnet den Eintrag in der Verwaltung.'; + $this->redaktionFehlerFeld = 'designation'; - public function saveRedaktion(): void - { - if (! $this->persistPresentation()) { - return; + return false; } - $this->feedback = 'Die Redaktion ist gespeichert. Aufbau, Lernziel, Zeit und Fassungen bleiben unverändert.'; + return $this->persistRedaktion(); } - public function redaktionUnsaved(): bool + protected function redaktionSavedMessage(): string + { + $this->feedback = 'Die Redaktion ist gespeichert. Aufbau, Lernziel, Zeit und Fassungen bleiben unverändert.'; + + return $this->feedback; + } + + protected function resetRedaktionTexte(): void + { + $this->fillRedaktion(); + } + + /** + * @return array{art: string, fuer: string, liste: string, zurueck: string, typ: ?string, umfang: string} + */ + public function redaktionKopf(): array + { + $program = $this->isProgram(); + + return [ + 'art' => $this->hostLabel(), + 'fuer' => $program ? 'das Programm' : 'das Modul', + 'liste' => $program ? 'Programme' : 'Module', + 'zurueck' => 'Zurück zum Aufbau', + 'typ' => null, + 'umfang' => '„Redaktion speichern“ sichert Name, Texte, Präsentationsmedien und Einordnung. Aufbau, Lernziel, Zeit und Fassungen bleiben unverändert; offene Änderungen am Aufbau bleiben offen.', + ]; + } + + public function redaktionTitel(): string + { + $title = trim($this->displayTitle) !== '' ? trim($this->displayTitle) : trim($this->designation); + + return $title !== '' ? $title : $this->hostLabel(); + } + + /** + * @return list> + */ + public function redaktionFelder(): array + { + /** @var Composition $record */ + $record = $this->getRecord(); + $stored = fn (string $column): string => (string) ($record->getAttribute($column) ?? ''); + + return [ + ['id' => 'name', 'label' => 'Name in der Verwaltung', 'model' => 'designation', 'kind' => 'text', 'stored' => $stored('designation'), 'required' => true, 'hilfe' => 'Pflichtangabe. Erscheint in Listen der Verwaltung.'], + ['id' => 'titel', 'label' => 'Titel', 'model' => 'displayTitle', 'kind' => 'text', 'stored' => $stored('display_title'), 'hilfe' => 'Erscheint auf Karten und in der Bibliothek. Leer zeigt den Namen.'], + ['id' => 'teaser', 'label' => 'Teaser', 'model' => 'teaser', 'kind' => 'textarea', 'rows' => 2, 'stored' => $stored('teaser')], + ['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'textarea', 'rows' => 3, 'stored' => $stored('summary')], + ['id' => 'beschreibung', 'label' => 'Ausführliche Beschreibung', 'model' => 'description', 'kind' => 'textarea', 'rows' => 8, 'stored' => $stored('description'), 'hilfe' => 'Beschreibt das Angebot. Kein Lehrtext und kein Lernziel.'], + ['id' => 'suche', 'label' => 'Suchbegriffe', 'model' => 'searchTerms', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('search_terms'), 'placeholder' => 'Begriffe, durch Komma getrennt'], + ]; + } + + public function redaktionTexteHinweis(): string + { + return 'Lernziel, Zeit und Material gehören zum fachlichen Stand. Sie stehen im Aufbau unter „Didaktik und Katalogbild“ und entstehen mit der nächsten Fassung.'; + } + + /** + * @return list}> + */ + public function einordnungGruppen(): array + { + return array_map(fn (array $group): array => [ + 'legend' => $group['label'], + 'model' => 'dimensionIds', + 'values' => $group['values'], + ], $this->dimensionGroups()); + } + + /** + * @return array{html: string, stand: string}|null + */ + public function redaktionAusgabe(): ?array + { + $subject = app(PublicCatalogReader::class)->subject($this->getRecord()->getKey(), true); + + if ($subject === null) { + return null; + } + + $card = view('widgets.premium_card', [ + 'subject' => $subject, + 'context' => RenderContext::preview(), + 'cardStyle' => $subject->style ?? 'program', + 'imageUrl' => null, + 'alt' => '', + 'focus' => ['x' => 50, 'y' => 45], + 'format' => 'landscape', + 'fit' => 'cover', + 'headingTag' => 'h3', + 'show' => ['summary' => true, 'kind' => true, 'meta' => true, 'action' => true], + 'actionLabel' => 'Ansehen', + 'note' => null, + 'stacked' => false, + ])->render(); + + return [ + 'html' => view('filament.cms.widget-live-preview', [ + 'html' => $card, + 'stylesheets' => WidgetEditor::previewStylesheets(), + 'width' => 640, + 'bodyClass' => '', + 'caption' => 'Website-Karte bei 640 px, wie im öffentlichen Auftritt.', + ])->render(), + 'stand' => $this->redaktionOffen() + ? 'Gezeigt wird der gespeicherte Stand. Deine ungespeicherten Änderungen erscheinen erst nach „Redaktion speichern“.' + : 'Gezeigt wird der gespeicherte Stand der Redaktion.', + ]; + } + + protected function pickerExceptId(): int + { + return (int) $this->getRecord()->getKey(); + } + + public function einordnungUnsaved(): bool { /** @var Composition $record */ $record = $this->getRecord()->fresh() ?? $this->getRecord(); - $text = trim($this->designation) !== trim((string) $record->designation) - || trim($this->displayTitle) !== trim((string) ($record->display_title ?? '')) - || trim($this->teaser) !== trim((string) ($record->teaser ?? '')) - || trim($this->summary) !== trim((string) ($record->summary ?? '')) - || trim($this->description) !== trim((string) ($record->description ?? '')) - || trim($this->searchTerms) !== trim((string) ($record->search_terms ?? '')) - || trim($this->thumbnailAlt) !== trim((string) ($record->thumbnail_alt ?? '')); - - if ($text) { - return true; - } - $stored = IdentityDimensionValue::query() ->where('subject_type', $record->getMorphClass()) ->where('subject_id', $record->getKey()) @@ -402,174 +481,6 @@ public function redaktionUnsaved(): bool return $stored !== $current; } - public function openPresentationPicker(): void - { - $this->guardEditorial(); - - if ($this->partOpen) { - $this->closePart(); - } - - $this->pickerPurpose = 'praesentation'; - $this->pickerOpen = true; - $this->moduleOpen = false; - $this->textOpen = false; - $this->pickerSelected = ''; - $this->pickerInspected = ''; - } - - public function assignFromPicker(string $target): void - { - $this->guardEditorial(); - - if (preg_match('/^medium:(\d+)$/', $target, $mediumMatch) === 1) { - $element = ContentElement::query()->find((int) $mediumMatch[1]); - - if (! $element instanceof ContentElement - || $element->archived_at !== null - || ! in_array($element->output_class, ['bild', 'film', 'audio'], true)) { - $this->deskFeedback = 'Dieses Präsentationsmedium ist nicht verfügbar.'; - - return; - } - - $this->rememberAssignment($element->id, null); - $this->pickerOpen = false; - $this->pickerPurpose = 'aufbau'; - $this->pickerSelected = ''; - - return; - } - - if (preg_match('/^element:(\d+)$/', $target, $match) !== 1) { - $this->deskFeedback = 'Präsentationsmedien sind Medien aus dem Bestand. Ein Modul bleibt Bestandteil des Aufbaus.'; - - return; - } - - $version = ContentElementVersion::query()->find((int) $match[1]); - - if (! $version instanceof ContentElementVersion) { - $this->deskFeedback = 'Dieses Medium ist nicht verfügbar.'; - - return; - } - - $this->rememberAssignment((int) $version->content_element_id, $target); - $this->pickerOpen = false; - $this->pickerPurpose = 'aufbau'; - $this->pickerSelected = ''; - } - - public function closePicker(): void - { - $this->pickerOpen = false; - $this->pickerSelected = ''; - $this->pickerInspected = ''; - $this->replacingAssignment = null; - } - - public function inspectPicker(string $target, bool $mark = false): void - { - $this->pickerInspected = $target; - - if ($mark) { - $this->pickerSelected = $target; - } - } - - /** - * @return array{items: list>, more: bool} - */ - public function pickerResult(): array - { - if (! $this->pickerOpen) { - return ['items' => [], 'more' => false]; - } - - if ($this->pickerPurpose === 'praesentation') { - return app(EditorialCatalog::class)->presentationBrowse($this->pickerQuery); - } - - return app(EditorialCatalog::class)->browse( - $this->pickerQuery, - $this->pickerKind, - $this->pickerDimension, - (int) $this->getRecord()->getKey(), - ); - } - - /** - * @return array|null - */ - public function pickerDetail(): ?array - { - $target = $this->pickerInspected !== '' ? $this->pickerInspected : $this->pickerSelected; - - if ($target === '') { - return null; - } - - $row = app(EditorialCatalog::class)->rowForTarget( - $target, - (int) $this->getRecord()->getKey(), - allowDraft: true, - ); - - if ($row === null) { - return null; - } - - $row['playback'] = null; - - if (preg_match('/^element:(\d+)$/', (string) $row['target'], $match) === 1) { - $version = ContentElementVersion::query()->with('element.editorialContentKind')->find($match[1]); - $row['playback'] = $version instanceof ContentElementVersion - ? app(ContentPreviewController::class)->playback($version) - : null; - if ($version?->element !== null) { - $row['visibility'] = app(PublicMaterialReader::class)->visibilityNote($version->element); - } - } - - return $row; - } - - /** - * @return list - */ - 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; @@ -673,8 +584,8 @@ public function discardDraft(): void $record = $this->getRecord(); app(EditorialWorkingDraft::class)->clear($record); $this->releaseArmed = false; - $this->loadEditor(); - $this->feedback = 'Der Entwurf ist verworfen. Eine freigegebene Fassung bleibt unverändert.'; + $this->loadAufbau(); + $this->feedback = 'Der Entwurf ist verworfen. Eine freigegebene Fassung bleibt unverändert. Offene Eingaben der Redaktion bleiben erhalten.'; } public function editorStatus(): string @@ -1150,7 +1061,7 @@ public function startModule(): void public function saveDisplay(): void { - if (! $this->persistPresentation()) { + if (! $this->persistRedaktion()) { return; } @@ -1160,18 +1071,11 @@ public function saveDisplay(): void public function openModule(): void { $this->moduleSnapshot = [ - 'designation' => $this->designation, - 'displayTitle' => $this->displayTitle, - 'teaser' => $this->teaser, - 'summary' => $this->summary, - 'searchTerms' => $this->searchTerms, - '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, @@ -1180,7 +1084,7 @@ public function openModule(): void $this->pickerOpen = false; $this->partOpen = false; $this->textOpen = false; - $this->moduleTab = 'beschreibung'; + $this->moduleTab = in_array($this->moduleTab, ['didaktik', 'titelbild'], true) ? $this->moduleTab : 'didaktik'; $this->frameFilmChoices = $this->frameFilms(); $films = $this->frameFilmChoices; $this->imageMode = $films === [] ? 'bestand' : 'film'; @@ -1203,6 +1107,9 @@ public function closeModule(): void $this->previewUpload = null; } + /** + * Übernimmt Didaktik und Katalogbild. Texte, Name und Einordnung gehören zur Redaktion und werden hier nicht gespeichert. + */ public function saveModule(): void { if ($this->minutes($this->durationMinutes) === false) { @@ -1211,19 +1118,16 @@ public function saveModule(): void return; } - if (! $this->persistPresentation()) { - return; - } - + /** @var Composition $record */ + $record = $this->getRecord(); + app(IdentityProfile::class)->fill($record, ['thumbnail_alt' => trim($this->thumbnailAlt)], $this->actor()); + $record->refresh(); $image = $this->applyChosenImage(); if ($image === false) { return; } - /** @var Composition $record */ - $record = $this->getRecord(); - if ($this->needsRevision() || app(EditorialWorkingDraft::class)->read($record) !== null) { $this->persistDraft(); } @@ -1232,7 +1136,7 @@ public function saveModule(): void $this->moduleSnapshot = []; $this->previewUpload = null; $this->imagePick = ''; - $this->feedback = trim('Die Angaben sind übernommen. Es entsteht keine neue Fassung.'.($image === '' ? '' : ' '.$image)); + $this->feedback = trim('Didaktik und Katalogbild sind übernommen. Es entsteht keine neue Fassung.'.($image === '' ? '' : ' '.$image)); } public function openPart(int $index): void @@ -1728,22 +1632,25 @@ public function selectedMember(): ?array } protected function loadEditor(): void + { + $this->fillRedaktion(); + $this->loadAufbau(); + } + + /** + * Liest die Angaben der Redaktion (Name, Texte, Einordnung) aus dem gespeicherten Stand. + */ + protected function fillRedaktion(): void { /** @var Composition $composition */ $composition = $this->getRecord(); $composition->refresh(); - $version = $this->currentReadyVersion(); $this->designation = $composition->designation; $this->displayTitle = (string) ($composition->display_title ?? ''); $this->teaser = (string) ($composition->teaser ?? ''); $this->summary = (string) ($composition->summary ?? ''); $this->searchTerms = (string) ($composition->search_terms ?? ''); $this->description = (string) ($composition->description ?? ''); - $this->thumbnailPath = $composition->thumbnail_path; - $this->thumbnailAlt = (string) ($composition->thumbnail_alt ?? ''); - $this->thumbnailError = $composition->thumbnail_error; - $this->thumbnailSource = $composition->thumbnail_source; - $this->imageCaptionText = $this->captionFor($composition->thumbnail_source); $this->dimensionIds = IdentityDimensionValue::query() ->where('subject_type', $composition->getMorphClass()) ->where('subject_id', $composition->id) @@ -1751,6 +1658,22 @@ protected function loadEditor(): void ->pluck('editorial_dimension_value_id') ->map(fn (mixed $id): string => (string) (int) $id) ->all(); + } + + /** + * Liest Aufbau, Didaktik und Katalogbild aus Entwurf oder letzter freigegebener Fassung. + */ + protected function loadAufbau(): void + { + /** @var Composition $composition */ + $composition = $this->getRecord(); + $composition->refresh(); + $version = $this->currentReadyVersion(); + $this->thumbnailPath = $composition->thumbnail_path; + $this->thumbnailAlt = (string) ($composition->thumbnail_alt ?? ''); + $this->thumbnailError = $composition->thumbnail_error; + $this->thumbnailSource = $composition->thumbnail_source; + $this->imageCaptionText = $this->captionFor($composition->thumbnail_source); $this->catalogScope = match ($this->hostKind()) { CompositionKind::Kurs => 'module', CompositionKind::Uebung => 'medien', @@ -1968,7 +1891,10 @@ protected function syncDimensions(Composition $composition, array $ids): void app(IdentityDimension::class)->replaceOffered($composition, $ids); } - protected function persistPresentation(): bool + /** + * Schreibt Name, Texte und Einordnung. Aufbau, Didaktik, Katalogbild und Fassungen bleiben unberührt. + */ + protected function persistRedaktion(): bool { /** @var Composition $record */ $record = $this->getRecord(); @@ -1987,7 +1913,6 @@ protected function persistPresentation(): bool 'summary' => $this->summary, 'search_terms' => $this->searchTerms, 'description' => $this->description, - 'thumbnail_alt' => $this->thumbnailAlt, ], $this->actor()); $this->syncDimensions($record, array_map(intval(...), $this->dimensionIds)); $record->refresh(); diff --git a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php index bced865..59cefae 100644 --- a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php @@ -6,10 +6,13 @@ use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentService; use App\Domain\Catalog\ContentVersionStatus; +use App\Domain\Catalog\EditorialContentKind; +use App\Domain\Catalog\EditorialDimension; use App\Domain\Catalog\IdentityChange; use App\Domain\Catalog\IdentityDimension; use App\Domain\Catalog\IdentityDimensionValue; use App\Domain\Catalog\IdentityProfile; +use App\Domain\Catalog\Pillar; use App\Domain\Catalog\PillarService; use App\Domain\Cms\Catalog\PublicMaterialReader; use App\Domain\Cms\WebsiteImageUsage; @@ -91,18 +94,16 @@ class ViewContentElement extends ViewRecord public string $editorialFeedback = ''; + public int $versionsBeforeSave = 0; + public string $previewWidth = '640'; public string $previewSurface = 'website'; - public string $pickerQuery = ''; - public string $pickerContext = 'modul'; public string $pickerLayout = 'kacheln'; - public string $pickerSelected = ''; - public function mount(int|string $record): void { parent::mount($record); @@ -113,33 +114,40 @@ public function mount(int|string $record): void $this->fassung = $requested; } - $bereich = (string) request()->query('bereich', 'beschreibung'); - $this->bereich = in_array($bereich, ['beschreibung', 'inhalt', 'fassungen', 'praesentation', 'verwendung', 'vorschau'], true) - ? $bereich - : 'beschreibung'; + $bereich = (string) request()->query('bereich', 'inhalt'); + $this->bereich = $this->normalBereich($bereich); $this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? ''); $this->fillEditorial(); $this->syncBodyDraft(); + + if (in_array($bereich, ['praesentation', 'redaktion'], true) && $this->canEditEditorial()) { + $this->openRedaktion($bereich === 'praesentation' ? 'medien' : 'texte'); + } } - public function getHeading(): string|Htmlable|null + public function updatedBereich(string $value): void { - if ($this->redaktionOpen) { - return null; - } + $this->bereich = $this->normalBereich($value); + } + /** + * Bereiche des Medieneditors. Die früheren Werte „beschreibung“ und „praesentation“ führen zur Website-Ansicht, + * weil Texte und Präsentationsmedien in der gemeinsamen Redaktion bearbeitet werden. + */ + public function normalBereich(string $value): string + { + return match ($value) { + 'inhalt', 'fassungen', 'verwendung', 'vorschau', 'website' => $value, + 'beschreibung', 'praesentation', 'redaktion' => 'website', + default => 'inhalt', + }; + } + + public function getTitle(): string|Htmlable + { return (string) $this->getRecord()->working_title; } - public function getSubheading(): string|Htmlable|null - { - if ($this->redaktionOpen) { - return null; - } - - return 'Texte und Vorschaubild ändern keine Fassung. Eine neue Datei oder ein geänderter Lehrtext braucht eine neue Fassung.'; - } - public function getMaxContentWidth(): Width|string|null { return Width::Full; @@ -148,14 +156,15 @@ public function getMaxContentWidth(): Width|string|null public function infolist(Schema $schema): Schema { return $schema->components([ - View::make('filament.media.viewer')->viewData(fn (): array => $this->viewerData()), - ]); + View::make('filament.media.viewer')->viewData(fn (): array => $this->viewerData())->columnSpanFull(), + ])->columns(1); } public function showVersion(int $version): void { abort_unless($this->ownedVersion($version) instanceof ContentElementVersion, 404); $this->fassung = $version; + $this->bereich = 'inhalt'; $this->syncBodyDraft(); } @@ -320,53 +329,64 @@ public function deactivateAction(): Action protected function getHeaderActions(): array { - if ($this->redaktionOpen) { - return []; - } + return []; + } - return [ - Action::make('releaseVersion') - ->label('Fassung freigeben') - ->modalHeading('Fassung freigeben') - ->modalDescription('Diese Fassung wird freigegeben. Sie erscheint dadurch nicht in der Mitgliederbibliothek, nicht auf der Website und nicht in einem Angebot. Eine deaktivierte Fassung bleibt unverändert.') - ->modalSubmitActionLabel('Freigeben') - ->visible(function (): bool { + public function releaseVersionAction(): Action + { + return Action::make('releaseVersion') + ->label('Fassung freigeben') + ->modalHeading('Fassung freigeben') + ->modalDescription('Diese Fassung wird freigegeben. Sie erscheint dadurch nicht in der Mitgliederbibliothek, nicht auf der Website und nicht in einem Angebot. Eine deaktivierte Fassung bleibt unverändert.') + ->modalSubmitActionLabel('Freigeben') + ->visible(function (): bool { + /** @var ContentElement $element */ + $element = $this->getRecord(); + + return ContentElementResource::editor() + && $element->versions()->where('status', ContentVersionStatus::Entwurf)->exists(); + }) + ->action(function (array $arguments): void { + abort_unless(ContentElementResource::editor(), 403); + $this->report(function () use ($arguments): string { + /** @var ContentElement $element */ + $element = $this->getRecord(); + $versionId = (int) ($arguments['version'] ?? 0); + $version = $versionId > 0 + ? $this->ownedVersion($versionId) + : $element->versions()->where('status', ContentVersionStatus::Entwurf)->orderByDesc('number')->first(); + abort_unless($version instanceof ContentElementVersion, 404); + $released = app(ContentService::class)->releaseElementVersion($version); + + return 'Fassung '.$released->number.' ist freigegeben.'; + }, 'Die Fassung ist freigegeben.'); + $this->getRecord()->unsetRelation('versions'); + }); + } + + public function reviseAction(): Action + { + return Action::make('revise') + ->label('Neue Fassung anlegen') + ->visible(fn (): bool => ContentElementResource::editor()) + ->schema(fn (): array => ElementRevision::fields($this->getRecord())) + ->action(function (array $data): void { + $this->report(function () use ($data): string { /** @var ContentElement $element */ $element = $this->getRecord(); - return ContentElementResource::editor() - && $element->versions()->where('status', ContentVersionStatus::Entwurf)->exists(); - }) - ->action(function (array $arguments): void { - abort_unless(ContentElementResource::editor(), 403); - $this->report(function () use ($arguments): string { - /** @var ContentElement $element */ - $element = $this->getRecord(); - $versionId = (int) ($arguments['version'] ?? 0); - $version = $versionId > 0 - ? $this->ownedVersion($versionId) - : $element->versions()->where('status', ContentVersionStatus::Entwurf)->orderByDesc('number')->first(); - abort_unless($version instanceof ContentElementVersion, 404); - $released = app(ContentService::class)->releaseElementVersion($version); + return ElementRevision::publish($element, $data); + }, 'Die neue Fassung ist angelegt.'); + $this->getRecord()->unsetRelation('versions'); + }); + } - return 'Fassung '.$released->number.' ist freigegeben.'; - }, 'Die Fassung ist freigegeben.'); - $this->getRecord()->unsetRelation('versions'); - }), - Action::make('revise') - ->label('Neue Fassung anlegen') - ->visible(fn (): bool => ContentElementResource::editor()) - ->schema(fn (): array => ElementRevision::fields($this->getRecord())) - ->action(function (array $data): void { - $this->report(function () use ($data): string { - /** @var ContentElement $element */ - $element = $this->getRecord(); + public function hasDraftVersion(): bool + { + /** @var ContentElement $element */ + $element = $this->getRecord(); - return ElementRevision::publish($element, $data); - }, 'Die neue Fassung ist angelegt.'); - $this->getRecord()->unsetRelation('versions'); - }), - ]; + return $element->versions()->where('status', ContentVersionStatus::Entwurf)->exists(); } /** @@ -457,7 +477,15 @@ private function ownedVersion(int $id): ?ContentElementVersion return $element->versions()->whereKey($id)->first(); } + /** + * Speichert die Redaktion: Texte, Einordnung, Präsentationsmedien und Abweichungen. Datei und Fassungen bleiben. + */ public function saveEditorial(): void + { + $this->saveRedaktion(); + } + + protected function saveRedaktionTexte(): bool { abort_unless(ContentElementResource::editor(), 403); @@ -466,12 +494,13 @@ public function saveEditorial(): void $title = trim($this->workingTitle); if ($title === '') { - $this->editorialFeedback = 'Der Arbeitstitel fehlt.'; + $this->deskFeedback = 'Der Arbeitstitel fehlt. Er bezeichnet das Medium in der Verwaltung.'; + $this->redaktionFehlerFeld = 'workingTitle'; - return; + return false; } - $versions = $element->versions()->count(); + $this->versionsBeforeSave = $element->versions()->count(); app(IdentityProfile::class)->fill($element, [ 'working_title' => $title, 'display_title' => $this->displayTitle, @@ -483,7 +512,6 @@ public function saveEditorial(): void 'license_note' => $this->licenseNote, 'website_credit' => $this->websiteCredit, 'website_alt' => $this->websiteAlt, - 'thumbnail_alt' => $this->thumbnailAlt, 'editorial_content_kind_id' => filled($this->kindId) ? (int) $this->kindId : null, ], auth()->user()); app(PillarService::class)->assign($element, array_map(intval(...), $this->pillarIds)); @@ -491,31 +519,34 @@ public function saveEditorial(): void $element->refresh(); $this->fillEditorial(); - $this->editorialFeedback = $element->versions()->count() === $versions - ? 'Gespeichert. Es gibt keine neue Fassung.' - : 'Gespeichert. Prüfe die Fassungen, ihre Zahl hat sich geändert.'; - $this->deskFeedback = $this->editorialFeedback; + + return true; } - public function redaktionUnsaved(): bool + protected function redaktionSavedMessage(): string + { + /** @var ContentElement $element */ + $element = $this->getRecord(); + $this->editorialFeedback = $element->versions()->count() === $this->versionsBeforeSave + ? 'Gespeichert. Es gibt keine neue Fassung.' + : 'Gespeichert. Prüfe die Fassungen, ihre Zahl hat sich geändert.'; + + return $this->editorialFeedback.' Datei, Inhaltsfassung und Website-Freigabe bleiben unverändert.'; + } + + protected function resetRedaktionTexte(): void + { + $this->fillEditorial(); + } + + public function einordnungUnsaved(): bool { /** @var ContentElement $element */ $element = $this->getRecord()->fresh() ?? $this->getRecord(); $kind = filled($this->kindId) ? (int) $this->kindId : null; $storedKind = $element->editorial_content_kind_id !== null ? (int) $element->editorial_content_kind_id : null; - $text = trim($this->workingTitle) !== trim((string) $element->working_title) - || trim($this->displayTitle) !== trim((string) ($element->display_title ?? '')) - || trim($this->teaser) !== trim((string) ($element->teaser ?? '')) - || trim($this->summary) !== trim((string) ($element->summary ?? '')) - || trim($this->searchTerms) !== trim((string) ($element->search_terms ?? '')) - || trim($this->descriptionText) !== trim((string) ($element->description ?? '')) - || trim($this->usageNote) !== trim((string) ($element->usage_note ?? '')) - || trim($this->licenseNote) !== trim((string) ($element->license_note ?? '')) - || trim($this->websiteCredit) !== trim((string) ($element->website_credit ?? '')) - || trim($this->websiteAlt) !== trim((string) ($element->website_alt ?? '')) - || $kind !== $storedKind; - if ($text) { + if ($kind !== $storedKind) { return true; } @@ -542,20 +573,112 @@ public function redaktionUnsaved(): bool return $stored !== $current; } + /** + * @return array{art: string, fuer: string, liste: string, zurueck: string, typ: ?string, umfang: string} + */ + public function redaktionKopf(): array + { + /** @var ContentElement $element */ + $element = $this->getRecord(); + + return [ + 'art' => 'Medium', + 'fuer' => 'das Medium', + 'liste' => 'Medien', + 'zurueck' => 'Zurück zur Medienbearbeitung', + 'typ' => $element->editorialContentKind?->label ?? PublicMaterialReader::outputLabel((string) $element->output_class), + 'umfang' => '„Redaktion speichern“ sichert Texte, Präsentationsmedien und Einordnung dieses Mediums. Verwendende Ansichten übernehmen die Angaben. Datei, Inhaltsfassung und Website-Freigabe bleiben unverändert.', + ]; + } + + public function redaktionTitel(): string + { + $title = trim($this->displayTitle) !== '' ? trim($this->displayTitle) : trim($this->workingTitle); + + return $title !== '' ? $title : (string) $this->getRecord()->working_title; + } + + /** + * @return list> + */ + public function redaktionFelder(): array + { + /** @var ContentElement $element */ + $element = $this->getRecord(); + $stored = fn (string $column): string => (string) ($element->getAttribute($column) ?? ''); + + return [ + ['id' => 'arbeitstitel', 'label' => 'Arbeitstitel', 'model' => 'workingTitle', 'kind' => 'text', 'stored' => $stored('working_title'), 'required' => true, 'hilfe' => 'Bezeichnung in der Verwaltung. Pflichtangabe.'], + ['id' => 'anzeigename', 'label' => 'Anzeigename', 'model' => 'displayTitle', 'kind' => 'text', 'stored' => $stored('display_title'), 'hilfe' => 'Erscheint auf Karten und in der Bibliothek. Leer zeigt den Arbeitstitel.'], + ['id' => 'teaser', 'label' => 'Teaser', 'model' => 'teaser', 'kind' => 'textarea', 'rows' => 2, 'stored' => $stored('teaser')], + ['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'textarea', 'rows' => 3, 'stored' => $stored('summary'), 'hilfe' => 'Erscheint auf Website- und Bibliothekskarten.'], + ['id' => 'beschreibung', 'label' => 'Ausführliche Beschreibung', 'model' => 'descriptionText', 'kind' => 'textarea', 'rows' => 8, 'stored' => $stored('description'), 'hilfe' => 'Bleibt in der Verwaltung und in Detailansichten. Kein Lehrtext.'], + ['id' => 'suche', 'label' => 'Suchbegriffe', 'model' => 'searchTerms', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('search_terms'), 'placeholder' => 'Begriffe, durch Komma getrennt'], + ['id' => 'einsatz', 'label' => 'Hinweise für den Einsatz', 'model' => 'usageNote', 'kind' => 'textarea', 'rows' => 3, 'gruppe' => 'weitere', 'stored' => $stored('usage_note')], + ['id' => 'lizenz', 'label' => 'Interner Lizenzvermerk', 'model' => 'licenseNote', 'kind' => 'textarea', 'rows' => 3, 'gruppe' => 'weitere', 'stored' => $stored('license_note'), 'hilfe' => 'Nur intern sichtbar.'], + ['id' => 'quelle', 'label' => 'Quellenzeile für die Website', 'model' => 'websiteCredit', 'kind' => 'textarea', 'rows' => 2, 'gruppe' => 'weitere', 'stored' => $stored('website_credit')], + ['id' => 'alt', 'label' => 'Alternativtext für die Website', 'model' => 'websiteAlt', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('website_alt'), 'hilfe' => 'Beschreibt das Bild für Menschen, die es nicht sehen.'], + ]; + } + + /** + * @return array{model: string, options: array, hilfe: string} + */ + public function einordnungArt(): array + { + return [ + 'model' => 'kindId', + 'options' => EditorialContentKind::selectOptions(), + 'hilfe' => 'Fachliche Materialart, unabhängig von der Dateiart.', + ]; + } + + /** + * @return list}> + */ + public function einordnungGruppen(): array + { + $groups = [[ + 'legend' => 'Fachliche Säulen', + 'model' => 'pillarIds', + 'values' => Pillar::query()->orderBy('name')->get(['id', 'name']) + ->map(fn (Pillar $pillar): array => ['id' => (int) $pillar->id, 'label' => (string) $pillar->name])->all(), + ]]; + + foreach (EditorialDimension::forSubject($this->getRecord()) as $dimension) { + $groups[] = [ + 'legend' => (string) $dimension->label, + 'model' => 'dimensionIds', + 'values' => collect($dimension->values)->map(fn ($value): array => ['id' => (int) $value->id, 'label' => (string) $value->label])->all(), + ]; + } + + return array_values(array_filter($groups, fn (array $group): bool => $group['values'] !== [])); + } + + /** + * @return array{view: string, stand: string} + */ + public function redaktionAusgabe(): ?array + { + return [ + 'view' => 'filament.media.preview-frame', + 'stand' => 'Website- und Bibliothekskarte mit deinen aktuellen Eingaben, auch den noch nicht gespeicherten.', + ]; + } + + /** + * Gibt das Medium für die Website frei. Quellenzeile und Alternativtext gelten im gespeicherten Stand der Redaktion; + * offene Eingaben in der Redaktion werden dabei weder gespeichert noch zurückgesetzt. + */ public function releaseForWebsite(): void { abort_unless(ContentElementResource::editor(), 403); /** @var ContentElement $element */ $element = $this->getRecord(); - app(IdentityProfile::class)->fill($element, [ - 'website_credit' => $this->websiteCredit, - 'website_alt' => $this->websiteAlt, - ], auth()->user()); - $element->refresh(); $this->websiteFeedback = app(WebsiteRelease::class)->release($element, auth()->user()); $element->refresh(); - $this->fillEditorial(); } public function withdrawWebsite(): void @@ -566,7 +689,18 @@ public function withdrawWebsite(): void $element = $this->getRecord(); $this->websiteFeedback = app(WebsiteRelease::class)->withdraw($element, auth()->user()); $element->refresh(); - $this->fillEditorial(); + } + + public function saveThumbnailAlt(): void + { + abort_unless(ContentElementResource::editor(), 403); + + /** @var ContentElement $element */ + $element = $this->getRecord(); + app(IdentityProfile::class)->fill($element, ['thumbnail_alt' => trim($this->thumbnailAlt)], auth()->user()); + $element->refresh(); + $this->thumbnailAlt = (string) ($element->thumbnail_alt ?? ''); + $this->pictureFeedback = 'Der Alternativtext des Vorschaubilds ist gespeichert. Die Fassung bleibt unverändert.'; } /** diff --git a/app/Filament/Resources/LicenseArticles/LicenseArticleResource.php b/app/Filament/Resources/LicenseArticles/LicenseArticleResource.php index f67db8f..5508c6f 100644 --- a/app/Filament/Resources/LicenseArticles/LicenseArticleResource.php +++ b/app/Filament/Resources/LicenseArticles/LicenseArticleResource.php @@ -9,9 +9,7 @@ use App\Filament\Support\CatalogReading; use App\Models\User; use Filament\Facades\Filament; -use Filament\Infolists\Components\TextEntry; use Filament\Resources\Resource; -use Filament\Schemas\Components\Section; use Filament\Schemas\Components\View; use Filament\Schemas\Schema; use Filament\Tables\Columns\TextColumn; @@ -54,16 +52,13 @@ public static function getViewAuthorizationResponse(Model $record): Response public static function infolist(Schema $schema): Schema { - return $schema->components([ - Section::make('Aktueller Stand')->schema([ - TextEntry::make('stand')->hiddenLabel()->listWithLineBreaks() - ->state(fn (LicenseArticle $record): array => app(CatalogReading::class)->articleStand($record)), - ]), - Section::make('Pakete und Angebote')->description('Wo dieser Artikel lizenziert wird.')->schema([ - TextEntry::make('context')->hiddenLabel()->listWithLineBreaks() - ->state(fn (LicenseArticle $record): array => app(CatalogReading::class)->articleContext($record)), - ]), - View::make('filament.editorial.license-desk'), + return $schema->columns(1)->components([ + View::make('filament.editorial.license-desk') + ->viewData(fn (LicenseArticle $record): array => [ + 'stand' => app(CatalogReading::class)->articleStand($record), + 'kontext' => app(CatalogReading::class)->articleContext($record), + ]) + ->columnSpanFull(), ]); } diff --git a/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php b/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php index 0d1df91..3199fd7 100644 --- a/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php +++ b/app/Filament/Resources/LicenseArticles/Pages/ViewLicenseArticle.php @@ -3,15 +3,22 @@ namespace App\Filament\Resources\LicenseArticles\Pages; use App\Domain\Catalog\ArticleService; +use App\Domain\Catalog\Composition; +use App\Domain\Catalog\CompositionKind; use App\Domain\Catalog\CompositionVersion; +use App\Domain\Catalog\ContentElement; use App\Domain\Catalog\ContentElementVersion; +use App\Domain\Catalog\EditorialContentKind; use App\Domain\Catalog\EditorialDimension; +use App\Domain\Catalog\EditorialProfileReader; use App\Domain\Catalog\IdentityDimension; use App\Domain\Catalog\IdentityDimensionValue; use App\Domain\Catalog\IdentityProfile; use App\Domain\Catalog\LicenseArticle; +use App\Filament\Resources\ContentElements\ContentElementResource; use App\Filament\Resources\LicenseArticles\LicenseArticleResource; use App\Filament\Support\CatalogOptions; +use App\Filament\Support\EditorialCatalog; use App\Filament\Support\ManagesEditorialSurface; use App\Filament\Support\ReportsDomainRules; use Filament\Actions\Action; @@ -19,6 +26,8 @@ use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Filament\Resources\Pages\ViewRecord; +use Illuminate\Contracts\Support\Htmlable; +use Illuminate\Database\Eloquent\Model; class ViewLicenseArticle extends ViewRecord { @@ -41,6 +50,10 @@ class ViewLicenseArticle extends ViewRecord public int|string|null $kindId = null; + public ?int $releaseBeforeSave = null; + + public int $releaseCountBeforeSave = 0; + /** @var list */ public array $dimensionIds = []; @@ -55,14 +68,29 @@ public function canEditEditorial(): bool return LicenseArticleResource::keeper(); } + public function canViewEditorial(): bool + { + return LicenseArticleResource::keeper(); + } + + public function getTitle(): string|Htmlable + { + return $this->redaktionTitel(); + } + public function saveLicenseEditorial(): void + { + $this->saveRedaktion(); + } + + protected function saveRedaktionTexte(): bool { $this->guardEditorial(); /** @var LicenseArticle $article */ $article = $this->getRecord(); - $releaseId = $article->current_release_id; - $releases = $article->releases()->count(); + $this->releaseBeforeSave = $article->current_release_id; + $this->releaseCountBeforeSave = $article->releases()->count(); app(IdentityProfile::class)->fill($article, [ 'working_title' => $this->workingTitle, @@ -78,25 +106,164 @@ public function saveLicenseEditorial(): void $article->refresh(); $this->fillLicenseEditorial(); - $this->deskFeedback = $article->current_release_id === $releaseId && $article->releases()->count() === $releases + + return true; + } + + protected function redaktionSavedMessage(): string + { + /** @var LicenseArticle $article */ + $article = $this->getRecord(); + + return $article->current_release_id === $this->releaseBeforeSave && $article->releases()->count() === $this->releaseCountBeforeSave ? 'Gespeichert. Stand, Preis und Rechte bleiben unverändert.' : 'Gespeichert. Prüfe den Artikelstand, er hat sich geändert.'; } - public function redaktionUnsaved(): bool + protected function resetRedaktionTexte(): void + { + $this->fillLicenseEditorial(); + } + + public function einordnungUnsaved(): bool { /** @var LicenseArticle $article */ $article = $this->getRecord()->fresh() ?? $this->getRecord(); $kind = filled($this->kindId) ? (int) $this->kindId : null; $storedKind = $article->editorial_content_kind_id !== null ? (int) $article->editorial_content_kind_id : null; - return trim($this->workingTitle) !== trim((string) ($article->working_title ?? '')) - || trim($this->displayTitle) !== trim((string) ($article->display_title ?? '')) - || trim($this->teaser) !== trim((string) ($article->teaser ?? '')) - || trim($this->summary) !== trim((string) ($article->summary ?? '')) - || trim($this->descriptionText) !== trim((string) ($article->description ?? '')) - || trim($this->searchTerms) !== trim((string) ($article->search_terms ?? '')) - || $kind !== $storedKind; + if ($kind !== $storedKind) { + return true; + } + + $stored = IdentityDimensionValue::query() + ->where('subject_type', $article->getMorphClass()) + ->where('subject_id', $article->getKey()) + ->where('origin', 'direkt') + ->pluck('editorial_dimension_value_id') + ->map(fn ($id): int => (int) $id) + ->all(); + $current = array_map(intval(...), $this->dimensionIds); + sort($stored); + sort($current); + + return $stored !== $current; + } + + /** + * @return array{art: string, fuer: string, liste: string, zurueck: string, typ: ?string, umfang: string} + */ + public function redaktionKopf(): array + { + return [ + 'art' => 'Lizenzartikel', + 'fuer' => 'den Lizenzartikel', + 'liste' => 'Lizenzartikel', + 'zurueck' => 'Zurück zum Lizenzartikel', + 'typ' => null, + 'umfang' => '„Redaktion speichern“ sichert die eigenen Texte, Präsentationsmedien und Einordnung dieses Lizenzartikels. Leere Angaben übernehmen weiter die fachliche Quelle. Stand, Preis und Rechte bleiben unverändert.', + ]; + } + + public function redaktionTitel(): string + { + foreach ([$this->displayTitle, $this->workingTitle] as $title) { + if (trim($title) !== '') { + return trim($title); + } + } + + $profile = $this->editorialProfile('artikel'); + + return (string) ($profile->value('display_title') ?? $this->getRecord()->code); + } + + /** + * @return list> + */ + public function redaktionFelder(): array + { + /** @var LicenseArticle $article */ + $article = $this->getRecord(); + $source = app(EditorialProfileReader::class)->sourceOf($article); + $sourceTitle = $source !== null ? $this->sourceTitle($source) : null; + $stored = fn (string $column): string => (string) ($article->getAttribute($column) ?? ''); + $quelle = fn (string $column): ?array => $sourceTitle === null ? null : [ + 'titel' => $sourceTitle, + 'wert' => (string) ($source->getAttribute($column) ?? ''), + ]; + + return [ + ['id' => 'arbeitstitel', 'label' => 'Interner Arbeitstitel', 'model' => 'workingTitle', 'kind' => 'text', 'stored' => $stored('working_title'), 'hilfe' => 'Nur in der Verwaltung sichtbar.'], + ['id' => 'anzeigename', 'label' => 'Name', 'model' => 'displayTitle', 'kind' => 'text', 'stored' => $stored('display_title'), 'quelle' => $quelle('display_title')], + ['id' => 'teaser', 'label' => 'Teaser', 'model' => 'teaser', 'kind' => 'textarea', 'rows' => 2, 'stored' => $stored('teaser'), 'quelle' => $quelle('teaser')], + ['id' => 'kurz', 'label' => 'Kurzbeschreibung', 'model' => 'summary', 'kind' => 'textarea', 'rows' => 4, 'stored' => $stored('summary'), 'quelle' => $quelle('summary')], + ['id' => 'beschreibung', 'label' => 'Beschreibung', 'model' => 'descriptionText', 'kind' => 'textarea', 'rows' => 6, 'stored' => $stored('description'), 'quelle' => $quelle('description')], + ['id' => 'suche', 'label' => 'Suchbegriffe', 'model' => 'searchTerms', 'kind' => 'text', 'gruppe' => 'weitere', 'stored' => $stored('search_terms'), 'quelle' => $quelle('search_terms')], + ]; + } + + /** + * @return array{titel: string, art: string, fuer: string, url: ?string}|null + */ + public function redaktionQuelle(): ?array + { + /** @var LicenseArticle $article */ + $article = $this->getRecord(); + $source = app(EditorialProfileReader::class)->sourceOf($article); + + if ($source === null) { + return null; + } + + $url = match (true) { + $source instanceof Composition => EditorialCatalog::editUrl($source), + $source instanceof ContentElement => ContentElementResource::getUrl('view', ['record' => $source]), + default => null, + }; + + return [ + 'titel' => $this->sourceTitle($source), + 'art' => $source instanceof ContentElement ? 'Medium' : ($source instanceof Composition && $source->kind === CompositionKind::Kurs ? 'Programm' : 'Modul'), + 'fuer' => 'diesen Lizenzartikel', + 'url' => $url, + ]; + } + + public function redaktionOhneQuelle(): string + { + return 'Keine eindeutige fachliche Quelle. Es wird nichts aus einem Modul, Programm oder Medium übernommen.'; + } + + /** + * @return array{model: string, options: array, hilfe: string} + */ + public function einordnungArt(): array + { + return [ + 'model' => 'kindId', + 'options' => EditorialContentKind::selectOptions(), + 'hilfe' => 'Die Einordnung des Artikels ändert weder die Quelle noch den Preis.', + ]; + } + + /** + * @return list}> + */ + public function einordnungGruppen(): array + { + return array_map(fn (array $group): array => [ + 'legend' => $group['label'], + 'model' => 'dimensionIds', + 'values' => $group['values'], + ], $this->licenseDimensionGroups()); + } + + private function sourceTitle(Model $source): string + { + $title = $source->getAttribute('display_title') ?: ($source->getAttribute('working_title') ?? $source->getAttribute('designation')); + + return (string) $title; } /** @@ -142,56 +309,63 @@ private function fillLicenseEditorial(): void protected function getHeaderActions(): array { - return [ - Action::make('release') - ->label('Stand veröffentlichen') - ->schema([ - Select::make('root')->label('Wurzel')->options(fn (): array => CatalogOptions::readyTargets())->required(), - Textarea::make('classification')->label('Einordnung')->required() - ->helperText('Warum dies derselbe Lizenzartikel bleibt und kein neues Produkt ist.'), - TextInput::make('change_note')->label('Änderungshinweis'), - ]) - ->action(function (array $data): void { - $this->report(function () use ($data): string { - /** @var LicenseArticle $article */ - $article = $this->getRecord(); - [$type, $id] = explode(':', $data['root'], 2); - $root = $type === 'composition' - ? CompositionVersion::query()->findOrFail($id) - : ContentElementVersion::query()->findOrFail($id); - $release = app(ArticleService::class)->publishRelease( - $article, - $root, - $data['classification'], - $data['change_note'] ?? null, - ); - $report = $release->impact_report ?? []; - $offers = $report['offers'] ?? []; + return []; + } - return 'Stand '.$release->number.' ist veröffentlicht. Inhalte: '.($report['contents'] ?? 0) - .', Inhaber: '.($report['holders'] ?? 0) - .', Angebote: '.(implode(', ', $offers) !== '' ? implode(', ', $offers) : 'keins').'.'; - }, 'Der Artikel-Stand ist veröffentlicht.'); - $this->refreshRecord(); - }), - Action::make('withdraw') - ->label('Stand zurückziehen') - ->schema([ - Textarea::make('reason')->label('Begründung')->required(), - ]) - ->action(function (array $data): void { - $this->report(function () use ($data): string { - $result = app(ArticleService::class)->withdraw($this->getRecord(), $data['reason']); - $current = $result['fallback_number'] === null - ? 'Es gibt keinen früheren Stand.' - : 'Aktuell ist wieder Stand '.$result['fallback_number'].'.'; - $holders = $result['holders'] === [] ? 'niemand' : implode(', ', $result['holders']); + public function releaseAction(): Action + { + return Action::make('release') + ->label('Stand veröffentlichen') + ->schema([ + Select::make('root')->label('Wurzel')->options(fn (): array => CatalogOptions::readyTargets())->required(), + Textarea::make('classification')->label('Einordnung')->required() + ->helperText('Warum dies derselbe Lizenzartikel bleibt und kein neues Produkt ist.'), + TextInput::make('change_note')->label('Änderungshinweis'), + ]) + ->action(function (array $data): void { + $this->report(function () use ($data): string { + /** @var LicenseArticle $article */ + $article = $this->getRecord(); + [$type, $id] = explode(':', $data['root'], 2); + $root = $type === 'composition' + ? CompositionVersion::query()->findOrFail($id) + : ContentElementVersion::query()->findOrFail($id); + $release = app(ArticleService::class)->publishRelease( + $article, + $root, + $data['classification'], + $data['change_note'] ?? null, + ); + $report = $release->impact_report ?? []; + $offers = $report['offers'] ?? []; - return 'Der Stand ist zurückgezogen. '.$current.' Betroffen: '.$holders.'.'; - }, 'Der Stand ist zurückgezogen.'); - $this->refreshRecord(); - }), - ]; + return 'Stand '.$release->number.' ist veröffentlicht. Inhalte: '.($report['contents'] ?? 0) + .', Inhaber: '.($report['holders'] ?? 0) + .', Angebote: '.(implode(', ', $offers) !== '' ? implode(', ', $offers) : 'keins').'.'; + }, 'Der Artikel-Stand ist veröffentlicht.'); + $this->refreshRecord(); + }); + } + + public function withdrawAction(): Action + { + return Action::make('withdraw') + ->label('Stand zurückziehen') + ->schema([ + Textarea::make('reason')->label('Begründung')->required(), + ]) + ->action(function (array $data): void { + $this->report(function () use ($data): string { + $result = app(ArticleService::class)->withdraw($this->getRecord(), $data['reason']); + $current = $result['fallback_number'] === null + ? 'Es gibt keinen früheren Stand.' + : 'Aktuell ist wieder Stand '.$result['fallback_number'].'.'; + $holders = $result['holders'] === [] ? 'niemand' : implode(', ', $result['holders']); + + return 'Der Stand ist zurückgezogen. '.$current.' Betroffen: '.$holders.'.'; + }, 'Der Stand ist zurückgezogen.'); + $this->refreshRecord(); + }); } private function refreshRecord(): void diff --git a/app/Filament/Support/EditorialCatalog.php b/app/Filament/Support/EditorialCatalog.php index aa07d4a..f764ea7 100644 --- a/app/Filament/Support/EditorialCatalog.php +++ b/app/Filament/Support/EditorialCatalog.php @@ -398,9 +398,21 @@ public function browse(string $query, string $kind, string $dimension, int $exce * * @return array{items: list>, more: bool} */ - public function presentationBrowse(string $query): array + public function presentationBrowse(string $query, string $kind = 'alle'): array { - $catalog = $this->browse($query, 'alle', '', 0, elementsOnly: true); + $catalog = $this->browse($query, $kind, '', 0, elementsOnly: true); + $outputs = match ($kind) { + 'bild' => ['bild'], + 'film' => ['film'], + 'audio' => ['audio'], + 'dokument' => [], + default => ['bild', 'film', 'audio'], + }; + // Reine Texte sind Lehrinhalt oder Beschreibung, keine Präsentationsmedien. + $catalog['items'] = array_values(array_filter( + $catalog['items'], + fn (array $item): bool => ($item['output'] ?? '') !== 'text', + )); $seen = []; foreach ($catalog['items'] as $item) { @@ -413,7 +425,7 @@ public function presentationBrowse(string $query): array $like = '%'.str_replace(['%', '_'], ['', ''], $query).'%'; $elements = ContentElement::query() ->with('editorialContentKind') - ->whereIn('output_class', ['bild', 'film', 'audio']) + ->whereIn('output_class', $outputs) ->whereNull('archived_at') ->whereDoesntHave('versions') ->where(function ($builder): void { @@ -558,6 +570,7 @@ private function constrainElement($builder, string $query, string $like, string 'film' => ['film'], 'text' => ['text'], 'bild' => ['bild'], + 'audio' => ['audio'], 'dokument' => ['pdf', 'document'], default => null, }; diff --git a/app/Filament/Support/ManagesEditorialSurface.php b/app/Filament/Support/ManagesEditorialSurface.php index 31fe19c..107ec6f 100644 --- a/app/Filament/Support/ManagesEditorialSurface.php +++ b/app/Filament/Support/ManagesEditorialSurface.php @@ -3,71 +3,103 @@ namespace App\Filament\Support; use App\Domain\Catalog\ContentElement; +use App\Domain\Catalog\ContentElementVersion; use App\Domain\Catalog\ContentVersionStatus; use App\Domain\Catalog\DomainRuleException; use App\Domain\Catalog\EditorialProfile; use App\Domain\Catalog\EditorialProfileReader; use App\Domain\Catalog\EditorialTextVariant; -use App\Domain\Catalog\PresentationAssignment; use App\Domain\Catalog\PresentationMedia; use App\Domain\Catalog\PresentationRole; +use App\Domain\Cms\Catalog\PublicMaterialReader; use App\Domain\Media\WebsiteRelease; use App\Filament\Resources\ContentElements\ContentElementResource; +use App\Http\Controllers\ContentPreviewController; use App\Models\User; use Illuminate\Database\Eloquent\Model; /** - * Gemeinsame Bedienung für Präsentationsmedien und abweichende Formulierungen. - * Die Texte selbst bleiben an den vorhandenen Feldern der jeweiligen Seite. + * Gemeinsamer Redaktionsmanager für Medien, Module, Programme und Lizenzartikel. + * + * Der Manager läuft in derselben Livewire-Komponente wie der Ausgangseditor. Dessen offene Eingaben bleiben dadurch + * beim Wechsel erhalten. Texte, Einordnung, Präsentationsmedien und abweichende Formulierungen sind ein Arbeitsstand, + * den nur „Redaktion speichern“ schreibt. Website-Freigaben eines Mediums wirken dagegen sofort und global. + * + * Die Seite liefert die objektspezifischen Teile: redaktionKopf(), redaktionFelder(), einordnungGruppen(), + * einordnungUnsaved(), saveRedaktionTexte() und resetRedaktionTexte(). */ trait ManagesEditorialSurface { - public string $presentationRole = 'titelbild'; - - public string $presentationQuery = ''; - - public string $presentationPick = ''; - - public string $presentationInspect = ''; - - public bool $bindToVersion = false; - public bool $redaktionOpen = false; - public function getBreadcrumbs(): array - { - if ($this->redaktionOpen) { - return []; - } - - return parent::getBreadcrumbs(); - } - - public function getCachedHeaderActions(): array - { - if ($this->redaktionOpen) { - return []; - } - - if ($this->cachedHeaderActions === []) { - $this->cacheInteractsWithHeaderActions(); - } - - return $this->cachedHeaderActions; - } - public string $redaktionTab = 'texte'; - public ?int $replacingAssignment = null; - public string $deskFeedback = ''; + public bool $deskFeedbackError = false; + + public string $redaktionFehlerFeld = ''; + + /** @var list */ + public array $praesentation = []; + + /** @var list|null */ + public ?array $praesentationGespeichert = null; + + public ?string $praesentationFokus = null; + + /** @var list */ + public array $varianten = []; + + /** @var list|null */ + public ?array $variantenGespeichert = null; + public string $variantAudience = 'kachel'; public string $variantField = 'teaser'; public string $variantBody = ''; + public bool $ausgabeOpen = false; + + public bool $pickerOpen = false; + + public string $pickerPurpose = 'praesentation'; + + public string $pickerQuery = ''; + + public string $pickerKind = 'alle'; + + public string $pickerDimension = ''; + + public string $pickerInspected = ''; + + public string $pickerSelected = ''; + + /** @var array Ziel => Titel; bleibt bei Suche und Filter erhalten */ + public array $pickerMarked = []; + + public string $presentationRole = 'titelbild'; + + public bool $bindToVersion = false; + + public ?string $replacingKey = null; + + public function getBreadcrumbs(): array + { + return []; + } + + public function getHeading(): string + { + return ''; + } + + public function getSubheading(): ?string + { + return null; + } + public function editorialSubject(): Model { return $this->getRecord(); @@ -78,34 +110,214 @@ public function editorialProfile(?string $audience = null): EditorialProfile return app(EditorialProfileReader::class)->read($this->editorialSubject(), $audience); } - /** - * @return list - */ - public function editorialGaps(): array + public function canEditEditorial(): bool { - $profile = $this->editorialProfile(); - $gaps = []; + return ContentElementResource::editor(); + } - foreach ([ - 'display_title' => 'Anzeigename', - 'teaser' => 'Teaser', - 'summary' => 'Kurzbeschreibung', - 'description' => 'Ausführliche Beschreibung', - ] as $field => $label) { - if ($profile->value($field) === null) { - $gaps[] = $label; - } - } + public function canReleasePresentation(): bool + { + return ContentElementResource::editor(); + } - return $gaps; + // ---------------------------------------------------------------- Wechsel, Status und Speichern + + public function openRedaktion(string $tab = 'texte'): void + { + abort_unless($this->canViewEditorial(), 403); + $this->redaktionWillOpen(); + $this->loadRedaktionStaging(); + $this->redaktionOpen = true; + $this->redaktionTab = in_array($tab, ['texte', 'medien', 'einordnung'], true) ? $tab : 'texte'; + $this->ausgabeOpen = false; + $this->deskFeedback = ''; } /** - * @return list> + * Für Seiten, die beim Wechsel eigene Dialoge schließen. Offene Eingaben bleiben dabei erhalten. */ - public function presentationRows(): array + protected function redaktionWillOpen(): void {} + + public function closeRedaktion(): void { - return app(PresentationMedia::class)->rows($this->editorialSubject()); + $this->redaktionOpen = false; + $this->ausgabeOpen = false; + $this->closePicker(); + $this->deskFeedback = ''; + } + + public function showRedaktionTab(string $tab): void + { + if (in_array($tab, ['texte', 'medien', 'einordnung'], true)) { + $this->redaktionTab = $tab; + } + } + + public function canViewEditorial(): bool + { + return $this->canEditEditorial() || ContentElementResource::editor(); + } + + public function saveRedaktion(): void + { + $this->guardEditorial(); + $this->loadRedaktionStaging(); + $this->deskFeedbackError = false; + $this->redaktionFehlerFeld = ''; + + if (! $this->saveRedaktionTexte()) { + $this->deskFeedbackError = true; + $this->redaktionTab = 'texte'; + + return; + } + + try { + if ($this->presentationUnsaved()) { + app(PresentationMedia::class)->commit($this->editorialSubject(), $this->praesentation, $this->deskActor()); + } + + if ($this->variantsUnsaved()) { + $this->commitVariants(); + } + } catch (DomainRuleException $exception) { + $this->deskFeedback = 'Die Texte sind gespeichert. '.$exception->getMessage(); + $this->deskFeedbackError = true; + + return; + } + + $this->praesentationGespeichert = null; + $this->variantenGespeichert = null; + $this->praesentationFokus = null; + $this->loadRedaktionStaging(); + $this->deskFeedback = $this->redaktionSavedMessage(); + } + + public function discardRedaktion(): void + { + $this->resetRedaktionTexte(); + $this->praesentationGespeichert = null; + $this->variantenGespeichert = null; + $this->praesentationFokus = null; + $this->loadRedaktionStaging(); + $this->closePicker(); + $this->deskFeedbackError = false; + $this->deskFeedback = 'Die ungespeicherten Änderungen der Redaktion sind verworfen. Die übrige Bearbeitung bleibt unverändert.'; + } + + public function redaktionOffen(): bool + { + return $this->redaktionUnsaved() || $this->presentationUnsaved() || $this->variantsUnsaved(); + } + + /** + * Welche Register ungespeicherte Änderungen enthalten. + * + * @return array{texte: bool, medien: bool, einordnung: bool} + */ + public function redaktionOffeneRegister(): array + { + $texte = $this->variantsUnsaved(); + + foreach ($this->redaktionFelder() as $feld) { + if ($this->feldGeaendert($feld)) { + $texte = true; + } + } + + return [ + 'texte' => $texte, + 'medien' => $this->presentationUnsaved(), + 'einordnung' => $this->einordnungUnsaved(), + ]; + } + + public function redaktionUnsaved(): bool + { + return $this->textFieldsChanged() || $this->einordnungUnsaved(); + } + + /** + * @param array $feld + */ + public function feldGeaendert(array $feld): bool + { + $model = (string) $feld['model']; + + return trim((string) $this->{$model}) !== trim((string) ($feld['stored'] ?? '')); + } + + public function textFieldsChanged(): bool + { + foreach ($this->redaktionFelder() as $feld) { + if ($this->feldGeaendert($feld)) { + return true; + } + } + + return false; + } + + protected function redaktionSavedMessage(): string + { + return 'Die Redaktion ist gespeichert. Es entsteht keine neue Fassung.'; + } + + protected function loadRedaktionStaging(): void + { + if ($this->praesentationGespeichert === null) { + $this->praesentation = app(PresentationMedia::class)->staged($this->editorialSubject()); + $this->praesentationGespeichert = $this->praesentation; + } + + if ($this->variantenGespeichert === null) { + $this->varianten = $this->storedVariants(); + $this->variantenGespeichert = $this->varianten; + } + } + + // ---------------------------------------------------------------- Ausgabe prüfen + + public function openAusgabe(): void + { + $this->ausgabeOpen = $this->redaktionAusgabe() !== null; + } + + public function closeAusgabe(): void + { + $this->ausgabeOpen = false; + } + + /** + * Ausgabe des Objekts für „Ausgabe prüfen“. Null, wenn es für diese Objektart keine Ausgabe gibt. + * + * @return array{html?: string, view?: string, stand: string}|null + */ + public function redaktionAusgabe(): ?array + { + return null; + } + + // ---------------------------------------------------------------- Präsentationsmedien (Arbeitsstand) + + public function presentationUnsaved(): bool + { + if ($this->praesentationGespeichert === null) { + return false; + } + + return $this->stagingFingerprint($this->praesentation) !== $this->stagingFingerprint($this->praesentationGespeichert); + } + + /** + * @return list>}> + */ + public function presentationGroups(): array + { + $this->loadRedaktionStaging(); + + return app(PresentationMedia::class)->describe($this->praesentation); } /** @@ -113,217 +325,721 @@ public function presentationRows(): array */ public function presentationRoleOptions(): array { - return PresentationRole::selectOptions(); + $options = []; + + foreach (PresentationRole::selectOptions() as $slug => $label) { + $options[$slug] = PresentationRole::displayLabel((string) $slug, (string) $label); + } + + return $options; + } + + public function removePresentation(string $key): void + { + $this->guardEditorial(); + $before = count($this->praesentation); + $this->praesentation = array_values(array_filter($this->praesentation, fn (array $row): bool => $row['key'] !== $key)); + + if (count($this->praesentation) === $before) { + $this->feedback('Diese Zuordnung gibt es nicht mehr.', true); + + return; + } + + $this->praesentationFokus = null; + $this->feedback('Die Zuordnung ist entfernt. Das Medium bleibt im Bestand. Wirksam wird das mit „Redaktion speichern“.'); + } + + public function movePresentation(string $key, int $direction): void + { + $this->guardEditorial(); + $index = $this->stagingIndex($key); + + if ($index === null || $direction === 0) { + return; + } + + $role = $this->praesentation[$index]['role']; + + if (! $this->roleIsOrdered($role)) { + $this->feedback('Diese Rolle hat eine einzelne Zuordnung und wird nicht sortiert.', true); + + return; + } + + $siblings = $this->stagingIndexesOfRole($role); + $position = array_search($index, $siblings, true); + $target = $position + ($direction < 0 ? -1 : 1); + + if ($position === false || ! isset($siblings[$target])) { + return; + } + + $other = $siblings[$target]; + [$this->praesentation[$index], $this->praesentation[$other]] = [$this->praesentation[$other], $this->praesentation[$index]]; + $this->praesentationFokus = $key; + $this->deskFeedback = ''; + } + + public function placePresentation(string $key, string $beforeKey): void + { + $this->guardEditorial(); + $from = $this->stagingIndex($key); + $to = $this->stagingIndex($beforeKey); + + if ($from === null || $to === null || $from === $to) { + return; + } + + $role = $this->praesentation[$from]['role']; + + if ($this->praesentation[$to]['role'] !== $role || ! $this->roleIsOrdered($role)) { + $this->feedback('Die Reihenfolge gilt nur innerhalb einer Rolle.', true); + + return; + } + + $siblings = $this->stagingIndexesOfRole($role); + $fromPosition = array_search($from, $siblings, true); + $toPosition = array_search($to, $siblings, true); + $direction = $toPosition < $fromPosition ? -1 : 1; + + for ($step = 0; $step < abs($toPosition - $fromPosition); $step++) { + $this->movePresentation($key, $direction); + } + } + + public function releaseAssigned(int $elementId): void + { + abort_unless($this->canReleasePresentation(), 403); + $element = ContentElement::query()->find($elementId); + + if (! $element instanceof ContentElement) { + $this->feedback('Das Medium fehlt.', true); + + return; + } + + $this->feedback(app(WebsiteRelease::class)->release($element, $this->deskActor())); + } + + public function withdrawAssigned(int $elementId): void + { + abort_unless($this->canReleasePresentation(), 403); + $element = ContentElement::query()->find($elementId); + + if (! $element instanceof ContentElement) { + $this->feedback('Das Medium fehlt.', true); + + return; + } + + $this->feedback(app(WebsiteRelease::class)->withdraw($element, $this->deskActor())); + } + + // ---------------------------------------------------------------- Gemeinsamer Picker + + public function openPresentationPicker(?string $role = null): void + { + $this->guardEditorial(); + $this->loadRedaktionStaging(); + $roles = $this->presentationRoleOptions(); + $this->presentationRole = $role !== null && isset($roles[$role]) ? $role : (isset($roles[$this->presentationRole]) ? $this->presentationRole : (string) array_key_first($roles)); + $this->resetPicker('praesentation'); + $this->pickerKind = $this->defaultKindForRole($this->presentationRole); + } + + public function beginExchange(string $key): void + { + $this->guardEditorial(); + $index = $this->stagingIndex($key); + + if ($index === null) { + $this->feedback('Diese Zuordnung gibt es nicht mehr.', true); + + return; + } + + $this->presentationRole = $this->praesentation[$index]['role']; + $this->resetPicker('austausch'); + $this->replacingKey = $key; + $this->pickerKind = $this->defaultKindForRole($this->presentationRole); + } + + public function updatedPresentationRole(string $value): void + { + if ($this->pickerPurpose === 'praesentation') { + $this->pickerKind = $this->defaultKindForRole($value); + } + + if (! in_array($value, PresentationRole::BOUND_ROLES, true)) { + $this->bindToVersion = false; + } + + if (! $this->pickerAllowsMany() && count($this->pickerMarked) > 1) { + $first = array_key_first($this->pickerMarked); + $this->pickerMarked = [$first => $this->pickerMarked[$first]]; + } + } + + public function closePicker(): void + { + $wasExchange = $this->pickerPurpose === 'austausch' && $this->pickerOpen; + $this->pickerOpen = false; + $this->pickerSelected = ''; + $this->pickerInspected = ''; + $this->pickerMarked = []; + $this->replacingKey = null; + + if ($wasExchange) { + $this->feedback('Die vorhandene Zuordnung bleibt unverändert.'); + } + } + + public function inspectPicker(string $target, bool $mark = false): void + { + $this->pickerInspected = $target; + + if ($mark) { + $this->markPicker($target, true); + } + } + + public function togglePick(string $target): void + { + $this->markPicker($target, ! isset($this->pickerMarked[$target])); + } + + public function markPicker(string $target, bool $on): void + { + if (! $on) { + unset($this->pickerMarked[$target]); + + if ($this->pickerSelected === $target) { + $this->pickerSelected = ''; + } + + return; + } + + $row = app(EditorialCatalog::class)->rowForTarget($target, $this->pickerExceptId(), allowDraft: true); + + if ($row === null) { + return; + } + + if (! $this->pickerAllowsMany()) { + $this->pickerMarked = []; + $this->pickerSelected = $target; + } + + $this->pickerMarked[$target] = (string) $row['title']; + + if ($this->pickerInspected === '') { + $this->pickerInspected = $target; + } + } + + public function pickerAllowsMany(): bool + { + return $this->pickerPurpose === 'praesentation' && $this->roleAllowsMany($this->presentationRole); + } + + public function confirmPicker(): void + { + $marked = array_keys($this->pickerMarked); + + if ($marked === []) { + return; + } + + if ($this->pickerPurpose === 'aufbau') { + $target = $marked[0]; + $this->closePicker(); + + if (method_exists($this, 'addPart')) { + $this->addPart($target); + } + + return; + } + + $this->guardEditorial(); + + if ($this->pickerPurpose === 'austausch') { + $this->exchangeStaged($marked[0]); + + return; + } + + $added = []; + $notes = []; + + foreach ($marked as $target) { + $result = $this->stageTarget($target); + + if ($result === true) { + $added[] = $this->pickerMarked[$target]; + } else { + $notes[] = $result; + } + } + + $this->pickerOpen = false; + $this->pickerMarked = []; + $this->pickerSelected = ''; + $this->pickerInspected = ''; + $this->redaktionTab = 'medien'; + $label = $this->presentationRoleOptions()[$this->presentationRole] ?? 'Rolle'; + $message = $added === [] + ? '' + : (count($added) === 1 ? '„'.$added[0].'“ ist' : count($added).' Medien sind').' als '.$label.' vorgemerkt. Wirksam wird das mit „Redaktion speichern“.'; + $this->feedback(trim($message.' '.implode(' ', $notes)), $added === []); + } + + /** + * Einzelnes Ziel direkt übernehmen (Tastatur- und Testpfad für den Picker). + */ + public function assignFromPicker(string $target): void + { + if (! $this->pickerOpen) { + $this->openPresentationPicker($this->presentationRole); + } + + $this->pickerMarked = []; + $this->markPicker($target, true); + $this->confirmPicker(); } /** * @return array{items: list>, more: bool} */ - public function presentationChoices(): array + public function pickerResult(): array { - return app(EditorialCatalog::class)->presentationBrowse($this->presentationQuery); - } - - public function assignPickedPresentation(): void - { - $this->guardEditorial(); - $row = app(EditorialCatalog::class)->rowForTarget($this->presentationPick, 0, allowDraft: true); - - if ($row === null || ! isset($row['element_id'])) { - $this->deskFeedback = 'Bitte ein Medium aus dem Bestand wählen.'; - - return; + if (! $this->pickerOpen) { + return ['items' => [], 'more' => false]; } - $this->rememberAssignment((int) $row['element_id'], isset($row['target']) ? (string) $row['target'] : null); - $this->presentationPick = ''; - $this->presentationInspect = ''; - } - - public function openRedaktion(): void - { - $this->guardEditorial(); - $this->redaktionOpen = true; - $this->redaktionTab = 'texte'; - } - - public function closeRedaktion(): void - { - $this->redaktionOpen = false; - $this->presentationInspect = ''; - $this->replacingAssignment = null; - } - - public function cancelPresentationPick(): void - { - $this->presentationPick = ''; - $this->presentationInspect = ''; - $this->replacingAssignment = null; - $this->deskFeedback = 'Die vorhandene Zuordnung bleibt unverändert.'; - } - - public function beginExchange(int $assignmentId): void - { - $this->guardEditorial(); - - foreach ($this->presentationRows() as $row) { - if ((int) $row['id'] !== $assignmentId) { - continue; - } - - $this->presentationRole = (string) $row['role']; - $this->replacingAssignment = $assignmentId; - $this->presentationPick = ''; - $this->presentationInspect = ''; - $this->redaktionTab = 'medien'; - $this->deskFeedback = 'Wähle das neue Medium und übernimm es. Abbrechen lässt die bisherige Zuordnung stehen.'; - - if (method_exists($this, 'openPresentationPicker')) { - $this->openPresentationPicker(); - } - - return; + if ($this->pickerPurpose === 'aufbau') { + return app(EditorialCatalog::class)->browse( + $this->pickerQuery, + $this->pickerKind, + $this->pickerDimension, + $this->pickerExceptId(), + ); } - $this->deskFeedback = 'Diese Zuordnung gibt es nicht mehr.'; - } - - public function placePresentation(int $assignmentId, int $beforeId): void - { - $this->guardEditorial(); - $rows = $this->presentationRows(); - $moving = null; - - foreach ($rows as $row) { - if ((int) $row['id'] === $assignmentId) { - $moving = $row; - } - } - - if ($moving === null || ! $moving['ordered']) { - $this->deskFeedback = 'Diese Rolle hat eine feste einzelne Zuordnung und wird nicht umsortiert.'; - - return; - } - - $ids = []; - - foreach ($rows as $row) { - if ($row['role'] === $moving['role']) { - $ids[] = (int) $row['id']; - } - } - - $from = array_search($assignmentId, $ids, true); - $to = array_search($beforeId, $ids, true); - - if ($from === false || $to === false || $from === $to) { - return; - } - - $direction = $to < $from ? -1 : 1; - - for ($step = 0; $step < abs($to - $from); $step++) { - app(PresentationMedia::class)->move($this->editorialSubject(), $assignmentId, $direction, $this->deskActor()); - } - - $this->deskFeedback = 'Die Reihenfolge gilt nur in dieser Rolle.'; - } - - public function detachPresentation(int $assignmentId): void - { - $this->guardEditorial(); - $this->deskFeedback = $this->reportPresentation( - fn (): string => app(PresentationMedia::class)->detach($this->editorialSubject(), $assignmentId, $this->deskActor()), - ); - } - - public function movePresentation(int $assignmentId, int $direction): void - { - $this->guardEditorial(); - $this->deskFeedback = $this->reportPresentation(function () use ($assignmentId, $direction): string { - app(PresentationMedia::class)->move($this->editorialSubject(), $assignmentId, $direction, $this->deskActor()); - - return 'Die Reihenfolge ist gespeichert.'; - }); - } - - public function releaseAssigned(int $elementId): void - { - abort_unless(ContentElementResource::editor(), 403); - $element = ContentElement::query()->find($elementId); - - if (! $element instanceof ContentElement) { - $this->deskFeedback = 'Das Medium fehlt.'; - - return; - } - - $this->deskFeedback = app(WebsiteRelease::class)->release($element, $this->deskActor()); - } - - public function withdrawAssigned(int $elementId): void - { - abort_unless(ContentElementResource::editor(), 403); - $element = ContentElement::query()->find($elementId); - - if (! $element instanceof ContentElement) { - $this->deskFeedback = 'Das Medium fehlt.'; - - return; - } - - $this->deskFeedback = app(WebsiteRelease::class)->withdraw($element, $this->deskActor()); + return app(EditorialCatalog::class)->presentationBrowse($this->pickerQuery, $this->pickerKind); } /** - * @return list + * @return array|null + */ + public function pickerDetail(): ?array + { + $target = $this->pickerInspected !== '' ? $this->pickerInspected : $this->pickerSelected; + + if ($target === '') { + return null; + } + + $row = app(EditorialCatalog::class)->rowForTarget($target, $this->pickerExceptId(), allowDraft: true); + + if ($row === null) { + return null; + } + + $row['playback'] = null; + $row['file_url'] = null; + $elementId = isset($row['element_id']) ? (int) $row['element_id'] : 0; + + if (preg_match('/^element:(\d+)$/', (string) $row['target'], $match) === 1) { + $version = ContentElementVersion::query()->with('element.editorialContentKind')->find($match[1]); + + if ($version instanceof ContentElementVersion) { + $row['playback'] = app(ContentPreviewController::class)->playback($version); + } + } + + $element = $elementId > 0 ? ContentElement::query()->with(['editorialContentKind', 'pillars'])->find($elementId) : null; + + if ($element instanceof ContentElement) { + $row['visibility'] = app(PublicMaterialReader::class)->visibilityNote($element); + $row['released'] = $element->website_released_at !== null; + $row['output_label'] = PublicMaterialReader::outputLabel((string) $element->output_class); + $row['pillars'] = $element->pillars->pluck('name')->all(); + $row['usage'] = app(CatalogReading::class)->elementUsage($element); + } + + return $row; + } + + /** + * @return list + */ + public function pickerVersions(): array + { + $detail = $this->pickerDetail(); + + if ($detail === null) { + return []; + } + + $options = app(EditorialCatalog::class)->alternatives((string) ($detail['identity'] ?? ''), $this->pickerExceptId()); + + if ($options === []) { + return []; + } + + $current = $options[array_key_last($options)]['target']; + + return array_map(fn (array $option): array => $option + ['current' => $option['target'] === $current], $options); + } + + /** + * @return array + */ + public function pickerKinds(): array + { + if ($this->pickerPurpose === 'aufbau') { + return ['alle' => 'Alle Inhalte', 'film' => 'Filme', 'bild' => 'Bilder', 'audio' => 'Hörstücke', 'dokument' => 'Dokumente', 'text' => 'Texte', 'modul' => 'Module']; + } + + return ['alle' => 'Alle Medien', 'bild' => 'Bilder', 'film' => 'Filme', 'audio' => 'Hörstücke', 'dokument' => 'Dokumente']; + } + + /** + * @return array{art: string, titel: string} + */ + public function pickerKontext(): array + { + return ['art' => (string) ($this->redaktionKopf()['fuer'] ?? 'das Objekt'), 'titel' => $this->redaktionTitel()]; + } + + public function pickerTitle(): string + { + return match ($this->pickerPurpose) { + 'aufbau' => 'Bestandteil auswählen', + 'austausch' => 'Medium austauschen', + default => 'Medien auswählen', + }; + } + + public function pickerConfirmLabel(): string + { + $count = count($this->pickerMarked); + + return match ($this->pickerPurpose) { + 'aufbau' => 'In den Aufbau übernehmen', + 'austausch' => 'Austauschen', + default => $count === 1 ? '1 Medium übernehmen' : ($count === 0 ? 'Medien übernehmen' : $count.' Medien übernehmen'), + }; + } + + public function pickerReplacing(): ?array + { + if ($this->replacingKey === null) { + return null; + } + + foreach ($this->presentationGroups() as $group) { + foreach ($group['rows'] as $row) { + if ($row['key'] === $this->replacingKey) { + return $row + ['role_label' => $group['label']]; + } + } + } + + return null; + } + + protected function pickerExceptId(): int + { + return 0; + } + + protected function resetPicker(string $purpose): void + { + $this->pickerPurpose = $purpose; + $this->pickerOpen = true; + $this->pickerQuery = ''; + $this->pickerDimension = ''; + $this->pickerInspected = ''; + $this->pickerSelected = ''; + $this->pickerMarked = []; + $this->replacingKey = null; + $this->bindToVersion = false; + } + + protected function defaultKindForRole(string $role): string + { + return match ($role) { + 'titelbild', 'titelbild_alternativ', 'hero', 'hover', 'galerie' => 'bild', + 'trailer', 'vorschauclip', 'interview' => 'film', + 'audiovorschau' => 'audio', + default => 'alle', + }; + } + + /** + * Ein Ziel in den Arbeitsstand der gewählten Rolle aufnehmen. + */ + protected function stageTarget(string $target): true|string + { + $elementId = $this->elementIdOf($target); + + if ($elementId === null) { + return 'Präsentationsmedien sind Medien aus dem Bestand.'; + } + + $refusal = app(PresentationMedia::class)->refusal($this->editorialSubject(), $this->presentationRole, $elementId); + + if ($refusal !== null) { + return $refusal; + } + + foreach ($this->praesentation as $row) { + if ($row['role'] === $this->presentationRole && $row['element_id'] === $elementId) { + return '„'.($this->pickerMarked[$target] ?? 'Dieses Medium').'“ ist in dieser Rolle bereits zugeordnet.'; + } + } + + $row = [ + 'key' => 'n'.bin2hex(random_bytes(4)), + 'id' => null, + 'role' => $this->presentationRole, + 'element_id' => $elementId, + 'source' => $this->sourceFor($target), + ]; + + if (! $this->roleAllowsMany($this->presentationRole)) { + $existing = $this->stagingIndexesOfRole($this->presentationRole); + + if ($existing !== []) { + $this->praesentation[$existing[0]] = $row; + $this->praesentationFokus = $row['key']; + + return true; + } + } + + $this->insertStaged($row); + $this->praesentationFokus = $row['key']; + + return true; + } + + protected function exchangeStaged(string $target): void + { + $index = $this->replacingKey !== null ? $this->stagingIndex($this->replacingKey) : null; + $elementId = $this->elementIdOf($target); + + if ($index === null || $elementId === null) { + $this->closePicker(); + $this->feedback('Diese Zuordnung gibt es nicht mehr.', true); + + return; + } + + $old = $this->praesentation[$index]; + $refusal = app(PresentationMedia::class)->refusal($this->editorialSubject(), $old['role'], $elementId); + + foreach ($this->praesentation as $other) { + if ($other['key'] !== $old['key'] && $other['role'] === $old['role'] && $other['element_id'] === $elementId) { + $refusal = 'Dieses Medium ist in dieser Rolle bereits zugeordnet.'; + } + } + + if ($refusal !== null) { + $this->feedback($refusal, true); + + return; + } + + $title = $this->pickerMarked[$target] ?? 'Das neue Medium'; + $this->praesentation[$index] = [ + 'key' => $old['element_id'] === $elementId ? $old['key'] : 'n'.bin2hex(random_bytes(4)), + 'id' => $old['element_id'] === $elementId ? $old['id'] : null, + 'role' => $old['role'], + 'element_id' => $elementId, + 'source' => $old['element_id'] === $elementId ? $old['source'] : $this->sourceFor($target, $old['role']), + ]; + $this->praesentationFokus = $this->praesentation[$index]['key']; + $this->pickerOpen = false; + $this->pickerMarked = []; + $this->pickerSelected = ''; + $this->pickerInspected = ''; + $this->replacingKey = null; + $this->feedback('„'.$title.'“ ersetzt die bisherige Zuordnung an derselben Stelle. Wirksam wird das mit „Redaktion speichern“.'); + } + + protected function insertStaged(array $row): void + { + $order = array_keys($this->presentationRoleOptions()); + $rank = array_search($row['role'], $order, true); + $insertAt = count($this->praesentation); + + foreach ($this->praesentation as $index => $existing) { + $existingRank = array_search($existing['role'], $order, true); + + if ($existingRank !== false && $rank !== false && $existingRank > $rank) { + $insertAt = $index; + + break; + } + } + + array_splice($this->praesentation, $insertAt, 0, [$row]); + $this->praesentation = array_values($this->praesentation); + } + + protected function elementIdOf(string $target): ?int + { + if (preg_match('/^medium:(\d+)$/', $target, $match) === 1) { + return (int) $match[1]; + } + + if (preg_match('/^element:(\d+)$/', $target, $match) === 1) { + $id = ContentElementVersion::query()->whereKey((int) $match[1])->value('content_element_id'); + + return $id !== null ? (int) $id : null; + } + + return null; + } + + protected function sourceFor(string $target, ?string $role = null): ?int + { + $role ??= $this->presentationRole; + + if (! $this->bindToVersion || ! in_array($role, PresentationRole::BOUND_ROLES, true)) { + return null; + } + + $subject = $this->editorialSubject(); + + if ($subject instanceof ContentElement) { + $id = $subject->versions()->where('status', ContentVersionStatus::Bereit)->orderByDesc('number')->value('id'); + + return $id !== null ? (int) $id : null; + } + + return preg_match('/^element:(\d+)$/', $target, $match) === 1 ? (int) $match[1] : null; + } + + protected function stagingIndex(string $key): ?int + { + foreach ($this->praesentation as $index => $row) { + if ($row['key'] === $key) { + return $index; + } + } + + return null; + } + + /** + * @return list + */ + protected function stagingIndexesOfRole(string $role): array + { + $indexes = []; + + foreach ($this->praesentation as $index => $row) { + if ($row['role'] === $role) { + $indexes[] = $index; + } + } + + return $indexes; + } + + protected function roleIsOrdered(string $role): bool + { + return (bool) PresentationRole::query()->where('slug', $role)->value('ordered'); + } + + protected function roleAllowsMany(string $role): bool + { + return (bool) PresentationRole::query()->where('slug', $role)->value('multiple'); + } + + /** + * @param list> $rows + */ + protected function stagingFingerprint(array $rows): string + { + return json_encode(array_map( + fn (array $row): array => [$row['id'], $row['role'], (int) $row['element_id'], $row['source']], + $rows, + ), JSON_THROW_ON_ERROR); + } + + // ---------------------------------------------------------------- Abweichende Formulierungen (Arbeitsstand) + + /** + * @return list */ public function variantRows(): array { - $subject = $this->editorialSubject(); + $this->loadRedaktionStaging(); - return EditorialTextVariant::query() - ->where('subject_type', $subject->getMorphClass()) - ->where('subject_id', $subject->getKey()) - ->orderBy('audience') - ->orderBy('field') - ->get() - ->all(); + return $this->varianten; + } + + public function variantsUnsaved(): bool + { + if ($this->variantenGespeichert === null) { + return false; + } + + return $this->variantFingerprint($this->varianten) !== $this->variantFingerprint($this->variantenGespeichert); } public function saveVariant(): void { $this->guardEditorial(); - $this->deskFeedback = $this->reportPresentation( - fn (): string => app(EditorialProfileReader::class)->putVariant( - $this->editorialSubject(), - $this->variantField, - $this->variantAudience, - $this->variantBody, - $this->deskActor(), - ), - ); - $this->variantBody = ''; - } + $this->loadRedaktionStaging(); + $body = trim($this->variantBody); - public function forgetVariant(int $variantId): void - { - $this->guardEditorial(); - $variant = EditorialTextVariant::query()->find($variantId); - - if (! $variant instanceof EditorialTextVariant) { - $this->deskFeedback = 'Diese Abweichung gibt es nicht mehr.'; + if (! in_array($this->variantField, EditorialProfileReader::TEXT_FIELDS, true) || ! array_key_exists($this->variantAudience, EditorialProfileReader::AUDIENCES)) { + $this->feedback('Diese Abweichung ist nicht vorgesehen.', true); return; } - $this->reportPresentation(function () use ($variant): string { - app(EditorialProfileReader::class)->forgetVariant($this->editorialSubject(), $variant, $this->deskActor()); + $this->varianten = array_values(array_filter( + $this->varianten, + fn (array $row): bool => ! ($row['field'] === $this->variantField && $row['audience'] === $this->variantAudience), + )); - return 'Die abweichende Formulierung ist entfernt.'; - }); - $this->deskFeedback = 'Die abweichende Formulierung ist entfernt. Es gilt wieder die zentrale Angabe.'; + if ($body !== '') { + $this->varianten[] = ['field' => $this->variantField, 'audience' => $this->variantAudience, 'body' => $body]; + } + + $this->variantBody = ''; + $this->deskFeedback = ''; + } + + public function editVariant(string $field, string $audience): void + { + foreach ($this->varianten as $row) { + if ($row['field'] === $field && $row['audience'] === $audience) { + $this->variantField = $field; + $this->variantAudience = $audience; + $this->variantBody = $row['body']; + } + } + } + + public function forgetVariant(string $field, string $audience): void + { + $this->guardEditorial(); + $this->loadRedaktionStaging(); + $this->varianten = array_values(array_filter( + $this->varianten, + fn (array $row): bool => ! ($row['field'] === $field && $row['audience'] === $audience), + )); } public function variantFieldLabel(string $field): string @@ -337,75 +1053,84 @@ public function variantFieldLabel(string $field): string }; } - public function canReleasePresentation(): bool + /** + * @return list + */ + protected function storedVariants(): array { - return ContentElementResource::editor(); + $subject = $this->editorialSubject(); + + return EditorialTextVariant::query() + ->where('subject_type', $subject->getMorphClass()) + ->where('subject_id', $subject->getKey()) + ->orderBy('audience') + ->orderBy('field') + ->get() + ->map(fn (EditorialTextVariant $variant): array => [ + 'field' => (string) $variant->field, + 'audience' => (string) $variant->audience, + 'body' => (string) $variant->body, + ]) + ->all(); } - public function canEditEditorial(): bool + protected function commitVariants(): void { - return ContentElementResource::editor(); + $reader = app(EditorialProfileReader::class); + $subject = $this->editorialSubject(); + $wanted = []; + + foreach ($this->varianten as $row) { + $wanted[$row['field'].'|'.$row['audience']] = $row; + } + + foreach ($this->variantenGespeichert ?? [] as $row) { + if (! isset($wanted[$row['field'].'|'.$row['audience']])) { + $reader->putVariant($subject, $row['field'], $row['audience'], null, $this->deskActor()); + } + } + + foreach ($wanted as $row) { + $reader->putVariant($subject, $row['field'], $row['audience'], $row['body'], $this->deskActor()); + } } - protected function rememberAssignment(int $elementId, ?string $target): void + /** + * @param list $rows + */ + protected function variantFingerprint(array $rows): string { - $sourceId = null; + $keys = array_map(fn (array $row): string => $row['field'].'|'.$row['audience'].'|'.trim($row['body']), $rows); + sort($keys); - if ($this->bindToVersion && in_array($this->presentationRole, PresentationRole::BOUND_ROLES, true)) { - $subject = $this->editorialSubject(); - $sourceId = $subject instanceof ContentElement - ? $subject->versions()->where('status', ContentVersionStatus::Bereit)->orderByDesc('number')->value('id') - : $this->versionIdFromTarget($target); - } - - $this->deskFeedback = $this->reportPresentation( - fn (): string => app(PresentationMedia::class)->assign( - $this->editorialSubject(), - $this->presentationRole, - $elementId, - $sourceId !== null ? (int) $sourceId : null, - $this->deskActor(), - ), - ); - $this->finishExchange(); + return implode("\n", $keys); } - protected function finishExchange(): void + // ---------------------------------------------------------------- Hilfen + + /** + * Fehlende zentrale Texte, für den Hinweis im Register Texte. + * + * @return list + */ + public function editorialGaps(): array { - $previous = $this->replacingAssignment; + $profile = $this->editorialProfile(); + $gaps = []; - if ($previous === null || ! str_contains($this->deskFeedback, 'zugeordnet')) { - return; + foreach (['display_title' => 'Anzeigename', 'teaser' => 'Teaser', 'summary' => 'Kurzbeschreibung', 'description' => 'Ausführliche Beschreibung'] as $field => $label) { + if ($profile->value($field) === null) { + $gaps[] = $label; + } } - $this->replacingAssignment = null; - $still = PresentationAssignment::query()->find($previous); - - if (! $still instanceof PresentationAssignment) { - $this->deskFeedback = 'Die Zuordnung ist ausgetauscht. '.$this->deskFeedback; - - return; - } - - if (str_contains($this->deskFeedback, 'bereits')) { - return; - } - - $removed = $this->reportPresentation( - fn (): string => app(PresentationMedia::class)->detach($this->editorialSubject(), $previous, $this->deskActor()), - ); - $this->deskFeedback = str_contains($removed, 'entfernt') - ? 'Die bisherige Zuordnung ist ersetzt. '.$this->deskFeedback - : $removed; + return $gaps; } - protected function versionIdFromTarget(?string $target): ?int + protected function feedback(string $message, bool $error = false): void { - if (is_string($target) && preg_match('/^element:(\d+)$/', $target, $match) === 1) { - return (int) $match[1]; - } - - return null; + $this->deskFeedback = $message; + $this->deskFeedbackError = $error; } protected function guardEditorial(): void @@ -419,16 +1144,4 @@ protected function deskActor(): ?User return $user instanceof User ? $user : null; } - - /** - * @param callable(): string $action - */ - protected function reportPresentation(callable $action): string - { - try { - return $action(); - } catch (DomainRuleException $exception) { - return $exception->getMessage(); - } - } } diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index 8f103f7..89f9729 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -69,7 +69,7 @@ public function panel(Panel $panel): Panel ]) ->renderHook( PanelsRenderHook::STYLES_AFTER, - fn (): string => view('filament.cms.styles')->render(), + fn (): string => view('filament.cms.styles')->render().view('filament.verwaltung.styles')->render(), ) ->renderHook( PanelsRenderHook::BODY_END, diff --git a/resources/views/filament/editorial/editor.blade.php b/resources/views/filament/editorial/editor.blade.php index 630bc26..41ddb0a 100644 --- a/resources/views/filament/editorial/editor.blade.php +++ b/resources/views/filament/editorial/editor.blade.php @@ -1,38 +1,53 @@ +@if ($this->redaktionOpen) + @include('filament.verwaltung.redaktion') +@else
- @if (! $this->redaktionOpen) -
-
- Zum Arbeitsplatz -

{{ $this->hostLabel() }}

-

{{ trim($this->displayTitle) !== '' ? $this->displayTitle : $this->designation }}

-

- - {{ $this->editorStatus() }} + @php + $titel = trim($this->displayTitle) !== '' ? trim($this->displayTitle) : trim($this->designation); + $statusSatz = $this->editorStatus(); + $aufbauOffen = str_starts_with($statusSatz, 'Es gibt ungespeicherte'); + $redaktionOffen = $this->redaktionOffen(); + $aktionen = []; + if ($url = $this->previewUrl()) { + $aktionen[] = ['label' => 'Vorschau für Trainer', 'href' => $url, 'neu' => true, 'icon' => 'auge']; + } + $aktionen[] = ['label' => 'Redaktion bearbeiten', 'wire' => "openRedaktion('texte')", 'art' => 'line', 'icon' => 'stift']; + $aktionen[] = ['label' => 'Fassung freigeben', 'wire' => 'armRelease']; + $aktionen[] = ['label' => 'Entwurf speichern', 'wire' => 'saveDraft', 'art' => 'primary']; + $mehr = []; + if ($this->currentReadyVersion() !== null) { + $mehr[] = $this->isInLibrary() + ? ['label' => 'Aus Mitgliederbibliothek ausblenden', 'wire' => "mountAction('displayRevoke')", 'hinweis' => 'Der Inhalt bleibt gespeichert.'] + : ['label' => 'In Mitgliederbibliothek anzeigen', 'wire' => "mountAction('displayRelease')", 'hinweis' => 'Zeigt die letzte freigegebene Fassung.']; + } + $mehr[] = ['label' => 'Entwurf verwerfen', 'wire' => 'discardDraft', 'hinweis' => 'Zurück zum letzten freigegebenen Aufbau.']; + @endphp +

+ @include('filament.verwaltung.kopf', [ + 'zurueck' => ['label' => 'Zum Arbeitsplatz', 'href' => \App\Filament\Pages\EditorialDesk::getUrl()], + 'brot' => [$this->isProgram() ? 'Programme' : 'Module', $titel], + 'titel' => $titel, + 'typ' => $this->hostLabel(), + 'status' => [ + ['text' => $statusSatz, 'ton' => $aufbauOffen ? 'offen' : ($this->currentReadyVersion() !== null ? 'gut' : 'neutral')], + $redaktionOffen ? ['text' => 'Die Redaktion hat ungespeicherte Änderungen.', 'ton' => 'offen', 'aktion' => ['label' => 'Zur Redaktion', 'wire' => "openRedaktion('".$this->redaktionTab."')"]] : null, + ], + 'aktionen' => $aktionen, + 'mehr' => $mehr, + ]) + @if ($this->returnUrl !== '') +

+ @include('filament.verwaltung.icon', ['name' => 'info']) + Dieser Eintrag wurde aus einem anderen Aufbau geöffnet. +

-
-
- @if ($url = $this->previewUrl()) - Vorschau für Trainer - @endif - - - - -
-
- @endif - - @if ($this->returnUrl !== '') -

- Dieser Eintrag wurde aus einem anderen Aufbau geöffnet. - -

- @endif - @if ($this->feedback !== '' && ! $this->moduleOpen && ! $this->partOpen) -

{{ $this->feedback }}

- @endif + @endif + @foreach (array_unique(array_filter([$this->feedback !== '' && ! $this->moduleOpen && ! $this->partOpen ? $this->feedback : '', $this->deskFeedback])) as $meldung) +

{{ $meldung }}

+ @endforeach +
@if ($this->releaseArmed) @php($review = $this->releaseReview()) @endif - @if ($this->redaktionOpen) - @include('filament.verwaltung.redaktion', [ - 'objektTitel' => trim($this->displayTitle) !== '' ? $this->displayTitle : $this->designation, - 'objektArt' => $this->hostLabel(), - 'zurueckAktion' => 'closeRedaktion', - 'zurueckLabel' => 'Zurück zum Aufbau', - 'speichernAktion' => 'saveRedaktion', - 'speichernHinweis' => 'Speichert Titel, Texte und Einordnung. Der Aufbau, das Lernziel und die Fassungen bleiben unverändert.', - 'pickerAktion' => 'openPresentationPicker', - 'texte' => 'filament.verwaltung.texte-komposition', - 'einordnung' => 'filament.verwaltung.einordnung-komposition', - ]) - @else
@@ -200,7 +202,7 @@

{{ $usage['title'] }}

Verwendung in diesem Aufbau

- + @if (! empty($usage['edit_url'])) Quelle @endif @@ -208,7 +210,7 @@ Vorschau @endif
-

Gilt nur hier. Die Quelle bleibt unverändert.

+

Gilt nur hier. Die Quelle bleibt unverändert.

{{ $usage['kind'] }} · {{ $usage['version_label'] }}

@if (filled($usage['role'] ?? null))

Rolle im {{ $this->hostLabel() }}
{{ $usage['role'] }}

@@ -217,15 +219,14 @@

Hinweis an dieser Stelle
{{ $usage['note'] }}

@endif @endif -

{{ $this->hostLabel() }}

-

{{ trim($this->displayTitle) !== '' ? $this->displayTitle : $this->designation }}

+

Überblick

@foreach ($this->presentationChips() as $chip) {{ $chip['label'] }} @endforeach
@php($cover = $this->coverPicture()) -

Katalogvorschau

+

Katalogbild

@if ($cover['url']) {{ $this->thumbnailAlt !== '' ? $this->thumbnailAlt : '' }} @@ -239,35 +240,19 @@ {{ $cover['note'] }} @endif
-

{{ trim($this->summary) !== '' ? \Illuminate\Support\Str::limit(trim($this->summary), 180) : 'Noch keine Kurzbeschreibung' }}

- @if (trim($this->learningGoal) !== '') -

Lernziel: {{ \Illuminate\Support\Str::limit(trim($this->learningGoal), 140) }}

- @endif - @if (trim($this->durationMinutes) !== '' || trim($this->materialNote) !== '') -

- @if (trim($this->durationMinutes) !== '') - {{ $this->durationMinutes }} Minuten - @endif - @if (trim($this->materialNote) !== '') - · {{ \Illuminate\Support\Str::limit(trim($this->materialNote), 80) }} - @endif -

- @endif @if ($caption = $this->imageCaption())

{{ $caption }}

@endif +

{{ trim($this->summary) !== '' ? \Illuminate\Support\Str::limit(trim($this->summary), 180) : 'Noch keine Kurzbeschreibung' }}

+
+
Lernziel
{{ trim($this->learningGoal) !== '' ? \Illuminate\Support\Str::limit(trim($this->learningGoal), 140) : 'Keine Angabe' }}
+
Zeit
{{ trim($this->durationMinutes) !== '' ? $this->durationMinutes.' Minuten' : 'Keine Angabe' }}
+
Material
{{ trim($this->materialNote) !== '' ? \Illuminate\Support\Str::limit(trim($this->materialNote), 80) : 'Keine Angabe' }}
+
- +
-

Präsentationsmedien

- @include('filament.editorial.presentation') - @if ($this->canEditEditorial()) -
- -
- @endif -

Freigegebene Fassungen

@if ($this->versionChoices() === [])

Noch keine freigegebene Fassung. Sie entsteht mit „Fassung freigeben“, nicht beim Speichern des Entwurfs.

@@ -315,54 +300,31 @@
- @endif @if ($this->moduleOpen)