diff --git a/app/Filament/Resources/Pages/PageResource.php b/app/Filament/Resources/Pages/PageResource.php index 11e1f25..7d3a298 100644 --- a/app/Filament/Resources/Pages/PageResource.php +++ b/app/Filament/Resources/Pages/PageResource.php @@ -38,11 +38,9 @@ public static function form(Schema $schema): Schema return $schema->components([ Section::make('Seite und Suchmaschinen') ->description('Adresse, Titel für Suchmaschinen und Zuordnung zu Themenbereichen.') - ->collapsible() - ->collapsed(fn (string $operation): bool => $operation === 'edit') - ->persistCollapsed() ->columns(2) ->columnSpanFull() + ->extraAttributes(fn ($livewire): array => ['class' => self::registerClass($livewire, 'einstellungen')]) ->schema([ TextInput::make('path') ->label('Pfad') @@ -65,13 +63,22 @@ public static function form(Schema $schema): Schema Section::make('Inhalt der Seite') ->description('Abschnitt hinzufügen, Raster wählen, Widgets in die Plätze einsetzen. Ein Klick auf die Vorschau eines Widgets öffnet seinen Dialog; Hintergrund, Breite, Abstand und Trenner stehen unter „Gestaltung des Abschnitts“. Speichern legt einen Entwurf an; veröffentlicht wird erst über „Veröffentlichen“.') ->columnSpanFull() - ->extraAttributes(['class' => 'luf-page-content']) + ->extraAttributes(fn ($livewire): array => ['class' => 'luf-page-content '.self::registerClass($livewire, 'inhalt')]) ->schema([ SectionEditor::repeater('sections'), ]), ]); } + /** + * Im Seiten-Arbeitsplatz (EditPage) zeigt jedes Register nur seinen Teil; ausgeblendete Felder bleiben im + * Formularzustand und werden mitgespeichert. Beim Anlegen ist alles sichtbar. + */ + public static function registerClass(mixed $livewire, string $register): string + { + return is_object($livewire) && property_exists($livewire, 'register') && $livewire->register !== $register ? 'vw-ausgeblendet' : ''; + } + public static function table(Table $table): Table { return $table diff --git a/app/Filament/Resources/Pages/Pages/EditPage.php b/app/Filament/Resources/Pages/Pages/EditPage.php index e72805d..de59bbf 100644 --- a/app/Filament/Resources/Pages/Pages/EditPage.php +++ b/app/Filament/Resources/Pages/Pages/EditPage.php @@ -11,9 +11,13 @@ use Filament\Actions\Action; use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; +use Filament\Schemas\Components\Group; +use Filament\Schemas\Schema; use Filament\Support\Enums\Width; +use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Model; use Illuminate\Validation\ValidationException; +use Livewire\Attributes\Url; class EditPage extends EditRecord { @@ -27,50 +31,128 @@ class EditPage extends EditRecord /** Warnt vor dem Verlassen oder Neuladen, wenn Änderungen noch nicht gespeichert sind. */ protected ?bool $hasUnsavedDataChangesAlert = true; + /** Register des Seiten-Arbeitsplatzes: inhalt, einstellungen, verlauf (Dokument 12, CMS-R01). */ + #[Url(as: 'bereich', except: 'inhalt')] + public string $register = 'inhalt'; + + /** Fingerabdruck des zuletzt geladenen oder gespeicherten Stands; Grundlage für „nicht gespeichert“. */ + public string $gespeicherterStand = ''; + + public function showRegister(string $register): void + { + $this->register = in_array($register, ['inhalt', 'einstellungen', 'verlauf'], true) ? $register : 'inhalt'; + } + + /** + * Gemeinsamer Objektkopf statt Filaments Titel, Pfad und Kopfaktionen. + */ + public function getHeader(): ?View + { + return view('filament.cms.seite-kopf', ['seite' => $this->record, 'ungespeichert' => $this->hasUnsavedEditorChanges()]); + } + + /** + * Weicht der Editorstand vom geladenen oder gespeicherten Stand ab? Verglichen wird derselbe normalisierte + * Zustand, der auch gespeichert würde; Vorschaubreiten zählen nicht. + */ + public function hasUnsavedEditorChanges(): bool + { + return $this->gespeicherterStand !== '' && $this->editorFingerprint() !== $this->gespeicherterStand; + } + + protected function afterFill(): void + { + $this->gespeicherterStand = $this->editorFingerprint(); + } + + private function editorFingerprint(): string + { + $data = is_array($this->data ?? null) ? $this->data : []; + $pillars = array_map('intval', (array) ($data['pillars'] ?? [])); + sort($pillars); + + return md5(json_encode([ + self::withoutPreviewKeys(SectionEditor::fromEditorState(is_array($data['sections'] ?? null) ? $data['sections'] : [])), + (string) ($data['path'] ?? ''), + (string) ($data['seo_title'] ?? ''), + (string) ($data['seo_description'] ?? ''), + $pillars, + ], JSON_UNESCAPED_UNICODE) ?: ''); + } + + private static function withoutPreviewKeys(mixed $value): mixed + { + if (! is_array($value)) { + return $value; + } + + unset($value['_preview_width']); + + return array_map(self::withoutPreviewKeys(...), $value); + } + + /** + * Formular und Verlauf (Revisionen) als Register; ausgeblendete Teile bleiben im Formularzustand. + */ + public function content(Schema $schema): Schema + { + return $schema->components([ + $this->getFormContentComponent(), + Group::make([$this->getRelationManagersContentComponent()]) + ->extraAttributes(fn (): array => ['class' => $this->register === 'verlauf' ? '' : 'vw-ausgeblendet']), + ]); + } + + /** + * Speichern steht im Kopf; die Leiste unter dem Formular entfällt. + */ + protected function getFormActions(): array + { + return []; + } + + /** + * Ein Fehler in einem gerade ausgeblendeten Register zeigt dieses Register. + */ + public function save(bool $shouldRedirect = true, bool $shouldSendSavedNotification = true): void + { + try { + parent::save($shouldRedirect, $shouldSendSavedNotification); + } catch (ValidationException $exception) { + $keys = implode(' ', array_keys($exception->errors())); + $this->register = str_contains($keys, 'data.sections') ? 'inhalt' : (preg_match('/data\.(path|seo_|pillars)/', $keys) === 1 ? 'einstellungen' : $this->register); + + throw $exception; + } + } + protected function getHeaderActions(): array { - return [ - Action::make('preview') - ->label('Vorschau') - ->icon('heroicon-o-device-phone-mobile') - ->color('gray') - ->tooltip('Zuletzt gespeicherten Entwurf in Smartphone-, Tablet- und Desktopbreite ansehen') - ->url(function (): string { - $revision = $this->record->latestRevision; + return []; + } - return $revision === null - ? '#' - : route('pages.preview.devices', $revision); - }) - ->openUrlInNewTab(), - Action::make('publish') - ->label('Veröffentlichen') - ->icon('heroicon-o-globe-alt') - ->requiresConfirmation() - ->modalHeading('Seite veröffentlichen?') - ->modalDescription('Der aktuelle Stand im Editor wird als Entwurf gespeichert und genau dieser Stand wird veröffentlicht. Enthält er Fehler, wird nichts veröffentlicht.') - ->modalSubmitActionLabel('Speichern und veröffentlichen') - ->visible(fn (): bool => auth()->user()?->can('publish', $this->record) ?? false) - ->action(function (PageService $service): void { - // Ungespeicherte Änderungen (zum Beispiel ein eben gewähltes Bild) gingen sonst beim Veröffentlichen verloren. - $this->save(shouldRedirect: false, shouldSendSavedNotification: false); + public function publishAction(): Action + { + return Action::make('publish') + ->label('Veröffentlichen') + ->icon('heroicon-o-globe-alt') + ->requiresConfirmation() + ->modalHeading('Seite veröffentlichen?') + ->modalDescription('Der aktuelle Stand im Editor wird als Entwurf gespeichert und genau dieser Stand wird veröffentlicht. Enthält er Fehler, wird nichts veröffentlicht.') + ->modalSubmitActionLabel('Speichern und veröffentlichen') + ->visible(fn (): bool => auth()->user()?->can('publish', $this->record) ?? false) + ->action(function (PageService $service): void { + // Ungespeicherte Änderungen (zum Beispiel ein eben gewähltes Bild) gingen sonst beim Veröffentlichen verloren. + $this->save(shouldRedirect: false, shouldSendSavedNotification: false); - $this->record->unsetRelation('latestRevision'); - $revision = $this->record->latestRevision; - abort_if($revision === null, 404); - $service->publish($this->record, $revision); - $this->record->refresh(); + $this->record->unsetRelation('latestRevision'); + $revision = $this->record->latestRevision; + abort_if($revision === null, 404); + $service->publish($this->record, $revision); + $this->record->refresh(); - Notification::make()->title('Seite veröffentlicht')->success()->send(); - }), - Action::make('open') - ->label('Live-Seite') - ->icon('heroicon-o-arrow-top-right-on-square') - ->color('gray') - ->visible(fn (): bool => $this->record->isPublished()) - ->url(fn (): string => $this->record->publicUrl()) - ->openUrlInNewTab(), - ]; + Notification::make()->title('Seite veröffentlicht')->success()->send(); + }); } protected function getSaveFormAction(): Action diff --git a/app/Filament/Resources/Pages/RelationManagers/RevisionsRelationManager.php b/app/Filament/Resources/Pages/RelationManagers/RevisionsRelationManager.php index 0318e80..6be0f39 100644 --- a/app/Filament/Resources/Pages/RelationManagers/RevisionsRelationManager.php +++ b/app/Filament/Resources/Pages/RelationManagers/RevisionsRelationManager.php @@ -17,6 +17,9 @@ class RevisionsRelationManager extends RelationManager protected static ?string $title = 'Revisionen'; + /** Steht im Register „Verlauf“ zunächst ausgeblendet; verzögertes Laden würde dort nie ausgelöst. */ + protected static ?bool $isLazyLoaded = false; + public function table(Table $table): Table { return $table diff --git a/resources/views/filament/cms/seite-kopf.blade.php b/resources/views/filament/cms/seite-kopf.blade.php new file mode 100644 index 0000000..fed2187 --- /dev/null +++ b/resources/views/filament/cms/seite-kopf.blade.php @@ -0,0 +1,54 @@ +{{-- Kopf des Seiten-Arbeitsplatzes (Dokument 12, CMS-R01): Speicherzustand und öffentliche Revision getrennt. --}} +@php + /** @var \App\Domain\Cms\Page $seite */ + $neueste = $seite->latestRevision; + $oeffentlich = $seite->publishedRevision; + $entwurfStatus = match (true) { + $ungespeichert => ['text' => 'Änderungen nicht gespeichert', 'ton' => 'offen'], + $neueste === null => ['text' => 'Noch kein gespeicherter Entwurf', 'ton' => 'neutral'], + $oeffentlich !== null && $neueste->id === $oeffentlich->id => ['text' => 'Gespeicherter Stand ist veröffentlicht (Revision '.$neueste->id.')', 'ton' => 'gut'], + default => ['text' => 'Entwurf gespeichert (Revision '.$neueste->id.')', 'ton' => 'neutral'], + }; + $oeffentlichStatus = $oeffentlich !== null + ? ['text' => 'Öffentlich: Revision '.$oeffentlich->id.($neueste !== null && $neueste->id !== $oeffentlich->id ? ' · der gespeicherte Entwurf ist neuer' : ''), 'ton' => 'gut'] + : ['text' => 'Noch nicht veröffentlicht', 'ton' => 'neutral']; + $aktionen = []; + if ($neueste !== null) { + $aktionen[] = ['label' => 'Seitenvorschau', 'href' => route('pages.preview.devices', $neueste), 'neu' => true, 'icon' => 'auge', 'art' => 'line']; + } + $aktionen[] = ['label' => 'Entwurf speichern', 'wire' => 'save', 'art' => 'primary']; + if (auth()->user()?->can('publish', $seite)) { + $aktionen[] = ['label' => 'Veröffentlichen …', 'wire' => "mountAction('publish')"]; + } + $mehr = []; + if ($seite->isPublished()) { + $mehr[] = ['label' => 'Live-Seite öffnen', 'href' => $seite->publicUrl(), 'neu' => true, 'hinweis' => 'Zeigt die veröffentlichte Revision.']; + } + $titel = $neueste?->contentTitle() ?: $seite->path; + $anzahlRevisionen = $seite->revisions()->count(); +@endphp +
Adresse, Suchmaschinentexte und Themenbereiche gehören zum Seitenentwurf und werden mit „Entwurf speichern“ gesichert.
+ @elseif ($this->register === 'verlauf') +Jede Speicherung legt eine Revision an. Öffnen verändert keine Revision; „Wiederherstellen“ legt eine neue Revision mit dem alten Stand an.
+ @endif +