Mache Auswahl, Aufbau und Entwurf im Redaktionseditor bedienbar.
Deploy Test / test (push) Successful in 22s
Deploy Test / deploy (push) Successful in 23s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-16 16:40:50 +01:00
1 parent 6955830579
commit 053a361801
14 files changed
+1040 -155

No files matched your search

@@ -13,6 +13,7 @@
use App\Domain\Catalog\DomainRuleException;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\EditorialDimensionValue;
use App\Domain\Catalog\EditorialWorkingDraft;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\IdentityProfile;
@@ -61,6 +62,20 @@ abstract class EditComposition extends EditRecord
public string $panel = 'angaben';
public bool $pickerOpen = false;
public string $pickerQuery = '';
public string $pickerKind = 'alle';
public string $pickerDimension = '';
public string $pickerSelected = '';
public bool $textOpen = false;
public bool $releaseArmed = false;
public string $returnUrl = '';
public ?int $templateNumber = null;
@@ -193,13 +208,20 @@ public function selfUrl(): string
public function previewUrl(): ?string
{
/** @var Composition $composition */
$composition = $this->getRecord();
if (is_array($composition->working_draft) && $composition->working_draft !== []) {
return route('editorial.draft-preview', ['composition' => $composition]);
}
$version = $this->currentReadyVersion();
if ($version === null) {
return null;
}
return route('editorial.preview', ['composition' => $this->getRecord(), 'version' => $version]);
return route('editorial.preview', ['composition' => $composition, 'version' => $version]);
}
public function previewUrlFor(int $versionId): ?string
@@ -229,6 +251,188 @@ public function hits(): array
);
}
public function openPicker(): void
{
$this->pickerOpen = true;
$this->textOpen = false;
$this->pickerSelected = '';
}
public function closePicker(): void
{
$this->pickerOpen = false;
}
/**
* @return array{items: list<array<string, string|null>>, more: bool}
*/
public function pickerResult(): array
{
if (! $this->pickerOpen) {
return ['items' => [], 'more' => false];
}
return app(EditorialCatalog::class)->browse(
$this->pickerQuery,
$this->pickerKind,
$this->pickerDimension,
(int) $this->getRecord()->getKey(),
);
}
/**
* @return array<string, string|null>|null
*/
public function pickerDetail(): ?array
{
if ($this->pickerSelected === '') {
return null;
}
return app(EditorialCatalog::class)->rowForTarget(
$this->pickerSelected,
(int) $this->getRecord()->getKey(),
);
}
public function openText(): void
{
$this->pickerOpen = false;
$this->textOpen = true;
}
public function cancelText(): void
{
$this->textOpen = false;
$this->newTextTitle = '';
$this->newTextBody = '';
}
public function saveDraft(): void
{
$this->commitRoleDraft();
$minutes = $this->minutes($this->durationMinutes);
if ($minutes === false) {
$this->feedback = 'Der Zeitbedarf ist eine Zahl von Minuten oder bleibt leer.';
return;
}
/** @var Composition $record */
$record = $this->getRecord();
app(EditorialWorkingDraft::class)->write($record, $this->payload());
$this->feedback = 'Der Entwurf ist gespeichert. Es entsteht keine neue Fassung.';
}
public function armRelease(): void
{
$this->commitRoleDraft();
if ($this->members === []) {
$this->releaseArmed = false;
$this->feedback = 'Eine Fassung braucht mindestens einen Bestandteil. Anzeige und Entwurf kannst du schon speichern.';
return;
}
if (! $this->needsRevision()) {
$this->releaseArmed = false;
$this->feedback = 'Die freigegebene Fassung ist unverändert. Es entsteht keine neue Fassung.';
return;
}
$this->releaseArmed = true;
}
public function cancelRelease(): void
{
$this->releaseArmed = false;
}
public function discardDraft(): void
{
/** @var Composition $record */
$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.';
}
public function editorStatus(): string
{
$current = $this->fingerprint($this->payload());
$stored = $this->storedPayload();
$ready = $this->fingerprint($this->readyPayload());
$version = $this->currentReadyVersion();
$display = $version === null
? ''
: (app(CompositionDisplayRelease::class)->isReleased($version)
? ' Sie ist zur Anzeige freigegeben.'
: ' Sie ist noch nicht zur Anzeige freigegeben.');
$unsaved = $stored === null
? $current !== $ready
: $current !== $this->fingerprint($stored);
if ($unsaved) {
return 'Es gibt ungespeicherte Änderungen. Speichern hält den Entwurf fest und legt keine Fassung an.';
}
if ($stored !== null && $this->fingerprint($stored) !== $ready) {
return $version === null
? 'Der Entwurf ist gespeichert. Noch keine freigegebene Fassung.'
: 'Der Entwurf ist gespeichert. Fassung '.$version->number.' bleibt unverändert.'.$display;
}
if ($version === null) {
return 'Noch keine freigegebene Fassung. Speichern hält einen Entwurf fest.';
}
return 'Fassung '.$version->number.' ist der letzte freigegebene Stand.'.$display.' Kein offener Entwurf.';
}
public function includeNeedsRelease(): bool
{
return $this->needsRevision();
}
public function moveTo(int $from, int $to): void
{
$this->commitRoleDraft();
$count = count($this->members);
if (! isset($this->members[$from]) || $to < 0 || $to >= $count) {
$this->feedback = 'An dieser Stelle kann der Bestandteil nicht abgelegt werden. Die Reihenfolge gilt nur innerhalb dieses Aufbaus.';
return;
}
if ($from === $to) {
$this->feedback = 'Der Bestandteil bleibt an seiner Stelle.';
return;
}
$selectedTarget = $this->selected !== null ? ($this->members[$this->selected]['target'] ?? null) : null;
$item = $this->members[$from];
array_splice($this->members, $from, 1);
array_splice($this->members, $to, 0, [$item]);
$this->members = array_values($this->members);
$this->selected = null;
foreach ($this->members as $index => $member) {
if ($selectedTarget !== null && ($member['target'] ?? null) === $selectedTarget) {
$this->selected = $index;
break;
}
}
$this->syncRoleDraft();
$this->feedback = $item['title'].' steht jetzt an Stelle '.($to + 1).'. Gespeichert ist das erst mit „Entwurf speichern“.';
}
/**
* @return list<array{id: int, number: int, text: string, current: bool}>
*/
@@ -241,13 +445,15 @@ public function versionChoices(): array
$rows = [];
foreach ($composition->versions()->orderByDesc('number')->get() as $version) {
$released = $version->status === ContentVersionStatus::Bereit && $release->isReleased($version);
if ($version->status !== ContentVersionStatus::Bereit) {
continue;
}
$released = $release->isReleased($version);
$rows[] = [
'id' => $version->id,
'number' => $version->number,
'text' => 'Fassung '.$version->number
.($version->status === ContentVersionStatus::Bereit ? '' : ', nicht bereit')
.($released ? ', zur Anzeige freigegeben' : ''),
'text' => 'Fassung '.$version->number.($released ? ', zur Anzeige freigegeben' : ''),
'current' => $latest !== null && $latest->id === $version->id,
];
}
@@ -348,7 +554,7 @@ public function publishHint(): string
return 'Lernziel, Zeit, Material und Aufbau sind unverändert. Es entsteht keine neue Fassung.';
}
return 'Übernehmen legt eine neue Fassung an. Die bisherige Fassung bleibt und wird nicht überschrieben.';
return 'Freigeben legt eine neue unveränderliche Fassung an. Speichern schreibt nur den Entwurf und lässt freigegebene Fassungen unverändert.';
}
public function selectPart(int $index): void
@@ -396,7 +602,9 @@ public function addPart(string $target): void
$this->panel = 'bestandteil';
$this->syncRoleDraft();
$this->search = '';
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die neue Fassung entsteht erst mit „Neue Fassung übernehmen“.';
$this->pickerOpen = false;
$this->pickerSelected = '';
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die Datei wird nicht kopiert. Gespeichert ist das erst mit „Entwurf speichern“.';
}
public function removePart(int $index): void
@@ -489,7 +697,9 @@ public function addText(): void
$this->newTextTitle = '';
$this->newTextBody = '';
$this->textOpen = false;
$this->addPart('element:'.$version->id);
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Derselbe Text kann später woanders wiederverwendet werden. Gespeichert ist das erst mit „Entwurf speichern“.';
}
public function startModule(): void
@@ -579,7 +789,11 @@ public function publishRevision(): bool
}
if (! $this->needsRevision()) {
$this->feedback = 'Die Fassung ist unverändert.';
/** @var Composition $unchanged */
$unchanged = $this->getRecord();
app(EditorialWorkingDraft::class)->clear($unchanged);
$this->releaseArmed = false;
$this->feedback = 'Die freigegebene Fassung ist unverändert. Es entsteht keine neue Fassung.';
return false;
}
@@ -641,6 +855,8 @@ public function publishRevision(): bool
$this->revisionNote = '';
$this->templateNumber = null;
$this->releaseArmed = false;
app(EditorialWorkingDraft::class)->clear($record);
$this->loadEditor();
$this->feedback = 'Die neue Fassung ist übernommen. Die bisherige Fassung bleibt erhalten.';
@@ -709,6 +925,14 @@ protected function loadEditor(): void
default => 'alles',
};
$draft = app(EditorialWorkingDraft::class)->read($composition);
if ($draft !== null) {
$this->applyDraft($draft);
return;
}
if ($version === null) {
$this->members = [];
$this->learningGoal = '';
@@ -721,6 +945,45 @@ protected function loadEditor(): void
$this->applyVersion($version);
}
/**
* @param array<string, mixed> $draft
*/
protected function applyDraft(array $draft): void
{
$catalog = app(EditorialCatalog::class);
$rows = [];
$requested = 0;
foreach ($draft['members'] ?? [] as $member) {
if (! is_array($member)) {
continue;
}
$requested++;
$row = $catalog->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true);
if ($row === null) {
continue;
}
$row['role'] = (string) ($member['role'] ?? $row['kind']);
$rows[] = $row;
}
$this->members = $rows;
$this->learningGoal = (string) ($draft['learning_goal'] ?? '');
$this->durationMinutes = ($draft['duration_minutes'] ?? null) === null ? '' : (string) $draft['duration_minutes'];
$this->materialNote = (string) ($draft['material_note'] ?? '');
$this->revisionNote = (string) ($draft['revision_note'] ?? '');
$this->selected = null;
$this->roleDraft = '';
$this->panel = 'angaben';
if ($requested > count($rows) && $this->feedback === '') {
$this->feedback = 'Ein Bestandteil des Entwurfs ist nicht mehr bereit und wurde nicht geladen.';
}
}
protected function applyVersion(CompositionVersion $version): void
{
$this->members = app(EditorialCatalog::class)->rows($version, (int) $this->getRecord()->getKey());
@@ -899,17 +1162,122 @@ protected function storePreview(string $path): void
}
protected function statusSentence(): string
{
return $this->editorStatus();
}
/**
* @return array{learning_goal: ?string, duration_minutes: int|string|null, material_note: ?string, revision_note: ?string, members: list<array{role: string, target: string}>}
*/
protected function payload(): array
{
$members = $this->members;
if ($this->selected !== null && isset($members[$this->selected]) && trim($this->roleDraft) !== '') {
$members[$this->selected]['role'] = trim($this->roleDraft);
}
$minutes = $this->minutes($this->durationMinutes);
return [
'learning_goal' => $this->blank($this->learningGoal),
'duration_minutes' => $minutes === false ? $this->durationMinutes : $minutes,
'material_note' => $this->blank($this->materialNote),
'revision_note' => $this->blank($this->revisionNote),
'members' => array_values(array_map(
fn (array $member): array => [
'role' => trim((string) ($member['role'] ?? '')),
'target' => (string) ($member['target'] ?? ''),
],
$members,
)),
];
}
/**
* @return array{learning_goal: ?string, duration_minutes: int|null, material_note: ?string, revision_note: ?string, members: list<array{role: string, target: string}>}|null
*/
protected function storedPayload(): ?array
{
/** @var Composition $composition */
$composition = $this->getRecord();
$draft = $composition->working_draft;
if (! is_array($draft) || $draft === []) {
return null;
}
return $this->normalizePayload($draft);
}
/**
* @return array{learning_goal: ?string, duration_minutes: int|null, material_note: ?string, revision_note: ?string, members: list<array{role: string, target: string}>}
*/
protected function readyPayload(): array
{
$version = $this->currentReadyVersion();
if ($version === null) {
return 'Noch keine Fassung.';
return [
'learning_goal' => null,
'duration_minutes' => null,
'material_note' => null,
'revision_note' => null,
'members' => [],
];
}
$released = app(CompositionDisplayRelease::class)->isReleased($version);
$rows = app(EditorialCatalog::class)->rows($version, (int) $this->getRecord()->getKey());
return 'Zuletzt übernommen: Fassung '.$version->number.'. '
.($released ? 'Sie ist zur Anzeige freigegeben.' : 'Sie ist noch nicht zur Anzeige freigegeben.');
return [
'learning_goal' => $version->learning_goal,
'duration_minutes' => $version->duration_minutes === null ? null : (int) $version->duration_minutes,
'material_note' => $version->material_note,
'revision_note' => null,
'members' => array_values(array_map(
fn (array $row): array => [
'role' => trim((string) ($row['role'] ?? '')),
'target' => (string) ($row['target'] ?? ''),
],
$rows,
)),
];
}
/**
* @param array<string, mixed> $payload
* @return array{learning_goal: ?string, duration_minutes: int|string|null, material_note: ?string, revision_note: ?string, members: list<array{role: string, target: string}>}
*/
protected function normalizePayload(array $payload): array
{
$members = [];
foreach ($payload['members'] ?? [] as $member) {
if (! is_array($member)) {
continue;
}
$members[] = [
'role' => trim((string) ($member['role'] ?? '')),
'target' => (string) ($member['target'] ?? ''),
];
}
return [
'learning_goal' => $payload['learning_goal'] ?? null,
'duration_minutes' => $payload['duration_minutes'] ?? null,
'material_note' => $payload['material_note'] ?? null,
'revision_note' => $payload['revision_note'] ?? null,
'members' => $members,
];
}
/**
* @param array<string, mixed> $payload
*/
protected function fingerprint(array $payload): string
{
return json_encode($this->normalizePayload($payload), JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE);
}
protected function actor(): ?User