MVP 1.0 (ohne Shop) #1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
<div class="vw vw-seitenkopf" x-data x-on:keydown.window.ctrl.s.prevent="$wire.save()">
|
||||
@include('filament.verwaltung.kopf', [
|
||||
'brot' => [['label' => 'Seiten', 'href' => \App\Filament\Resources\Pages\PageResource::getUrl('index')], $seite->path],
|
||||
'titel' => $titel,
|
||||
'typ' => 'Seite · '.$seite->path,
|
||||
'status' => [$entwurfStatus, $oeffentlichStatus],
|
||||
'aktionen' => $aktionen,
|
||||
'mehr' => $mehr,
|
||||
])
|
||||
<div class="vw-register" role="tablist" aria-label="Bereiche der Seite">
|
||||
@foreach (['inhalt' => 'Seiteninhalt', 'einstellungen' => 'Seiteneinstellungen', 'verlauf' => 'Verlauf'] as $wert => $label)
|
||||
<button type="button" role="tab" aria-selected="{{ $this->register === $wert ? 'true' : 'false' }}" tabindex="{{ $this->register === $wert ? '0' : '-1' }}"
|
||||
wire:click="showRegister('{{ $wert }}')"
|
||||
x-on:keydown.right.prevent="$el.nextElementSibling?.focus()" x-on:keydown.left.prevent="$el.previousElementSibling?.focus()">
|
||||
{{ $label }}
|
||||
@if ($wert === 'verlauf')<span class="vw-zahl">{{ $anzahlRevisionen }}</span>@endif
|
||||
</button>
|
||||
@endforeach
|
||||
</div>
|
||||
@if ($this->register === 'einstellungen')
|
||||
<p class="vw-feld-hilfe vw-seiten-hinweis">Adresse, Suchmaschinentexte und Themenbereiche gehören zum Seitenentwurf und werden mit „Entwurf speichern“ gesichert.</p>
|
||||
@elseif ($this->register === 'verlauf')
|
||||
<p class="vw-feld-hilfe vw-seiten-hinweis">Jede Speicherung legt eine Revision an. Öffnen verändert keine Revision; „Wiederherstellen“ legt eine neue Revision mit dem alten Stand an.</p>
|
||||
@endif
|
||||
</div>
|
||||
@@ -42,6 +42,9 @@
|
||||
.vw h1, .vw h2, .vw h3, .vw h4 { color: var(--vw-ink); font-weight: 750; letter-spacing: -0.01em; margin: 0; line-height: 1.2; }
|
||||
.vw p { margin: 0; }
|
||||
.vw [x-cloak] { display: none !important; }
|
||||
.vw-ausgeblendet { display: none !important; }
|
||||
.vw-seitenkopf { display: grid; gap: 0.75rem; margin-bottom: 0.5rem; }
|
||||
.vw-seiten-hinweis { max-width: 60rem; }
|
||||
.vw-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
|
||||
.vw :is(button, a, input, textarea, select, summary, [tabindex]):focus-visible { outline: 3px solid var(--vw-focus); outline-offset: 2px; }
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Seiten-Arbeitsplatz (Teil C, Dokument 12): Kopf mit getrennten Zuständen, Register, Speichern im Kopf.
|
||||
*/
|
||||
class CmsArbeitsplatzTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
|
||||
}
|
||||
|
||||
public function test_the_head_separates_the_saved_draft_from_the_public_revision(): void
|
||||
{
|
||||
$page = Page::query()->where('path', '/praevention')->firstOrFail();
|
||||
$live = $page->published_revision_id;
|
||||
|
||||
$component = Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(EditPage::class, ['record' => $page->id])
|
||||
->assertSee('Öffentlich: Revision '.$live)
|
||||
->assertDontSee('Änderungen nicht gespeichert')
|
||||
->assertSee('Entwurf speichern')
|
||||
->assertSee('Seitenvorschau')
|
||||
->assertSee('Seiteninhalt')
|
||||
->assertSee('Seiteneinstellungen')
|
||||
->assertSee('Verlauf')
|
||||
->set('data.seo_title', 'Neuer Suchmaschinentitel')
|
||||
->assertSee('Änderungen nicht gespeichert')
|
||||
->call('save')
|
||||
->assertHasNoErrors()
|
||||
->assertDontSee('Änderungen nicht gespeichert');
|
||||
|
||||
$page->refresh();
|
||||
$component->assertSee('Entwurf gespeichert (Revision '.$page->latestRevision->id.')')
|
||||
->assertSee('der gespeicherte Entwurf ist neuer');
|
||||
$this->assertSame($live, $page->published_revision_id, 'Speichern veröffentlicht nicht.');
|
||||
}
|
||||
|
||||
public function test_hidden_registers_keep_their_fields_and_save_with_the_draft(): void
|
||||
{
|
||||
$page = Page::query()->where('path', '/praevention')->firstOrFail();
|
||||
|
||||
Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(EditPage::class, ['record' => $page->id])
|
||||
->call('showRegister', 'einstellungen')
|
||||
->assertSet('register', 'einstellungen')
|
||||
->set('data.seo_title', 'Titel aus den Einstellungen')
|
||||
->call('showRegister', 'inhalt')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
$this->assertSame('Titel aus den Einstellungen', $page->fresh()->latestRevision->seo_title);
|
||||
}
|
||||
|
||||
public function test_an_error_in_a_hidden_register_shows_that_register(): void
|
||||
{
|
||||
$page = Page::query()->where('path', '/praevention')->firstOrFail();
|
||||
|
||||
Livewire::actingAs($this->editor(), 'staff')
|
||||
->test(EditPage::class, ['record' => $page->id])
|
||||
->assertSet('register', 'inhalt')
|
||||
->set('data.path', '')
|
||||
->call('save')
|
||||
->assertHasErrors(['data.path'])
|
||||
->assertSet('register', 'einstellungen');
|
||||
}
|
||||
|
||||
public function test_the_history_register_is_reachable_by_address(): void
|
||||
{
|
||||
$page = Page::query()->where('path', '/praevention')->firstOrFail();
|
||||
|
||||
Livewire::withQueryParams(['bereich' => 'verlauf'])
|
||||
->actingAs($this->editor(), 'staff')
|
||||
->test(EditPage::class, ['record' => $page->id])
|
||||
->assertSet('register', 'verlauf')
|
||||
->assertSee('Jede Speicherung legt eine Revision an.');
|
||||
}
|
||||
|
||||
private function editor(): User
|
||||
{
|
||||
$editor = User::factory()->redakteur()->create();
|
||||
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
return $editor;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user