diff --git a/app/Domain/Catalog/CompositionRelease.php b/app/Domain/Catalog/CompositionRelease.php index 42730dd..d44b2b6 100644 --- a/app/Domain/Catalog/CompositionRelease.php +++ b/app/Domain/Catalog/CompositionRelease.php @@ -174,13 +174,13 @@ private function inspectElement( $kind = $this->outputLabel((string) $version->element->output_class); if ($version->status === ContentVersionStatus::Bereit) { - $ready[] = $this->line($title, $kind.' · '.$role.' · Fassung '.$version->number.', bleibt unverändert', $depth); + $ready[] = $this->line($title, $this->kindAndRole($kind, $role).' · Fassung '.$version->number.', bleibt unverändert', $depth); return; } if ($version->status === ContentVersionStatus::Gesperrt) { - $blocked[] = $this->block($title, $kind.' · '.$role.'. Diese Fassung ist deaktiviert und kann nicht freigegeben werden.', $depth, $edit); + $blocked[] = $this->block($title, $this->kindAndRole($kind, $role).'. Diese Fassung ist deaktiviert und kann nicht freigegeben werden.', $depth, $edit); return; } @@ -188,18 +188,18 @@ private function inspectElement( $problem = app(ContentService::class)->elementReleaseProblem($version); if ($frozen) { - $blocked[] = $this->block($title, $kind.' · '.$role.'. Eine bereits freigegebene Fassung verweist auf diesen Entwurf. Sie bleibt unverändert.', $depth, $edit); + $blocked[] = $this->block($title, $this->kindAndRole($kind, $role).'. Eine bereits freigegebene Fassung verweist auf diesen Entwurf. Sie bleibt unverändert.', $depth, $edit); return; } if ($problem !== null) { - $blocked[] = $this->block($title, $kind.' · '.$role.'. '.$problem, $depth, $edit); + $blocked[] = $this->block($title, $this->kindAndRole($kind, $role).'. '.$problem, $depth, $edit); return; } - $pending[] = $this->line($title, $kind.' · '.$role.'. Der Entwurf wird freigegeben. Es entsteht keine weitere Fassung.', $depth); + $pending[] = $this->line($title, $this->kindAndRole($kind, $role).'. Der Entwurf wird freigegeben. Es entsteht keine weitere Fassung.', $depth); } /** @@ -230,18 +230,18 @@ private function inspectReleasedComposition( $kind = $this->label($version->composition); if (in_array($version->composition_id, $stack, true)) { - $blocked[] = $this->block($title, $kind.' · '.$role.'. Der Aufbau verweist auf sich selbst. So kann nichts freigegeben werden.', $depth, ['type' => 'composition', 'id' => $version->composition_id]); + $blocked[] = $this->block($title, $this->kindAndRole($kind, $role).'. Der Aufbau verweist auf sich selbst. So kann nichts freigegeben werden.', $depth, ['type' => 'composition', 'id' => $version->composition_id]); return; } if ($version->status !== ContentVersionStatus::Bereit) { - $blocked[] = $this->block($title, $kind.' · '.$role.'. Diese Fassung ist nicht freigegeben.', $depth, ['type' => 'composition', 'id' => $version->composition_id]); + $blocked[] = $this->block($title, $this->kindAndRole($kind, $role).'. Diese Fassung ist nicht freigegeben.', $depth, ['type' => 'composition', 'id' => $version->composition_id]); return; } - $ready[] = $this->line($title, $kind.' · '.$role.' · Fassung '.$version->number.', bleibt unverändert', $depth); + $ready[] = $this->line($title, $this->kindAndRole($kind, $role).' · Fassung '.$version->number.', bleibt unverändert', $depth); $nested = []; foreach ($version->members()->orderBy('position')->get() as $member) { @@ -284,7 +284,7 @@ private function inspectDraftComposition( $kind = $this->label($composition); if ($frozen || in_array($id, $stack, true)) { - $blocked[] = $this->block($title, $kind.' · '.$role.'. Der Aufbau verweist auf sich selbst. So kann nichts freigegeben werden.', $depth, $edit); + $blocked[] = $this->block($title, $this->kindAndRole($kind, $role).'. Der Aufbau verweist auf sich selbst. So kann nichts freigegeben werden.', $depth, $edit); return; } @@ -293,7 +293,7 @@ private function inspectDraftComposition( $members = is_array($draft['members'] ?? null) ? $draft['members'] : []; if ($members === []) { - $blocked[] = $this->block($title, $kind.' · '.$role.'. Der gespeicherte Entwurf hat keinen Bestandteil.', $depth, $edit); + $blocked[] = $this->block($title, $this->kindAndRole($kind, $role).'. Der gespeicherte Entwurf hat keinen Bestandteil.', $depth, $edit); return; } @@ -301,14 +301,14 @@ private function inspectDraftComposition( $minutes = $draft['duration_minutes'] ?? null; if ($minutes !== null && $minutes !== '' && ! is_int($minutes)) { - $blocked[] = $this->block($title, $kind.' · '.$role.'. Der Zeitbedarf ist keine Zahl von Minuten.', $depth, $edit); + $blocked[] = $this->block($title, $this->kindAndRole($kind, $role).'. Der Zeitbedarf ist keine Zahl von Minuten.', $depth, $edit); return; } $nestedDraft = true; $number = ((int) $composition->versions()->max('number')) + 1; - $pending[] = $this->line($title, $kind.' · '.$role.'. Es entsteht Fassung '.$number.'.', $depth); + $pending[] = $this->line($title, $this->kindAndRole($kind, $role).'. Es entsteht Fassung '.$number.'.', $depth); $this->inspectMembers($members, $depth + 1, [...$stack, $id], false, $ready, $pending, $blocked, $nestedDraft); } @@ -442,6 +442,17 @@ private function block(string $title, string $detail, int $depth, ?array $edit): return ['title' => $title, 'detail' => $detail, 'depth' => $depth, 'edit' => $edit]; } + private function kindAndRole(string $kind, string $role): string + { + $role = trim($role); + + if ($role === '' || mb_strtolower($role) === mb_strtolower($kind)) { + return $kind; + } + + return $kind.' · '.$role; + } + private function title(Composition $composition): string { return filled($composition->display_title) ? (string) $composition->display_title : (string) $composition->designation; diff --git a/app/Filament/Resources/Compositions/Pages/EditComposition.php b/app/Filament/Resources/Compositions/Pages/EditComposition.php index e1b51d7..38b73c1 100644 --- a/app/Filament/Resources/Compositions/Pages/EditComposition.php +++ b/app/Filament/Resources/Compositions/Pages/EditComposition.php @@ -676,7 +676,7 @@ public function childrenOf(string $target): string continue; } - $row = app(EditorialCatalog::class)->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true, allowDraft: true); + $row = app(EditorialCatalog::class)->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true, allowDraft: true, allowBlocked: true); $lines[] = trim((string) ($member['role'] ?? '')).': '.($row['title'] ?? 'Bestandteil'); } @@ -1622,7 +1622,7 @@ protected function applyDraft(array $draft): void } $requested++; - $row = $catalog->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true, allowDraft: true); + $row = $catalog->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true, allowDraft: true, allowBlocked: true); if ($row === null) { continue; diff --git a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php index 7afb1d0..33dcb35 100644 --- a/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php +++ b/app/Filament/Resources/ContentElements/Pages/ViewContentElement.php @@ -281,11 +281,22 @@ protected function getHeaderActions(): array ->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(fn (): bool => ContentElementResource::editor()) + ->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 { - $version = $this->ownedVersion((int) ($arguments['version'] ?? 0)); + /** @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); diff --git a/app/Filament/Support/EditorialCatalog.php b/app/Filament/Support/EditorialCatalog.php index 0b6970b..383ce08 100644 --- a/app/Filament/Support/EditorialCatalog.php +++ b/app/Filament/Support/EditorialCatalog.php @@ -40,7 +40,7 @@ public function rows(CompositionVersion $version, int $exceptCompositionId): arr $target = $member->content_element_version_id ? 'element:'.$member->content_element_version_id : 'composition:'.$member->nested_composition_version_id; - $row = $this->rowForTarget($target, $exceptCompositionId, allowSelf: true, allowDraft: true); + $row = $this->rowForTarget($target, $exceptCompositionId, allowSelf: true, allowDraft: true, allowBlocked: true); if ($row === null) { continue; @@ -57,7 +57,7 @@ public function rows(CompositionVersion $version, int $exceptCompositionId): arr /** * @return array|null */ - public function rowForTarget(string $target, int $exceptCompositionId, bool $allowSelf = false, bool $allowDraft = false): ?array + public function rowForTarget(string $target, int $exceptCompositionId, bool $allowSelf = false, bool $allowDraft = false, bool $allowBlocked = false): ?array { if (preg_match('/^composition-draft:(\d+)$/', $target, $draftMatch) === 1) { return $this->draftCompositionRow((int) $draftMatch[1], $exceptCompositionId, $allowSelf); @@ -77,6 +77,10 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all $acceptable[] = ContentVersionStatus::Entwurf; } + if ($allowBlocked) { + $acceptable[] = ContentVersionStatus::Gesperrt; + } + if (! $version instanceof ContentElementVersion || ! in_array($version->status, $acceptable, true)) { return null; } @@ -98,7 +102,11 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all 'license_note' => (string) ($element->license_note ?? ''), 'tone' => $this->tone((string) $element->output_class, $kind), 'image' => $this->cardUrl('element', $element->id, $element->thumbnail_path), - 'version_label' => $version->status === ContentVersionStatus::Entwurf ? 'Entwurf' : 'Fassung '.$version->number, + 'version_label' => match ($version->status) { + ContentVersionStatus::Entwurf => 'Entwurf', + ContentVersionStatus::Gesperrt => 'deaktiviert', + default => 'Fassung '.$version->number, + }, 'committed' => app(ContentService::class)->isCommitted($version), 'identity' => 'medium:'.$element->id, 'open_url' => route('content.preview', $version), @@ -111,7 +119,13 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all ->with('composition.editorialContentKind') ->find($match[2]); - if (! $version instanceof CompositionVersion || $version->status !== ContentVersionStatus::Bereit) { + $acceptable = [ContentVersionStatus::Bereit]; + + if ($allowBlocked) { + $acceptable[] = ContentVersionStatus::Gesperrt; + } + + if (! $version instanceof CompositionVersion || ! in_array($version->status, $acceptable, true)) { return null; } @@ -130,7 +144,9 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all 'summary' => (string) ($composition->summary ?? ''), 'tone' => $this->tone('', $kind), 'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path), - 'version_label' => 'Fassung '.$version->number, + 'version_label' => $version->status === ContentVersionStatus::Gesperrt + ? 'deaktiviert' + : 'Fassung '.$version->number, 'identity' => 'zusammenstellung:'.$composition->id, 'open_url' => route('editorial.preview', ['composition' => $composition, 'version' => $version]), 'open_label' => 'Aufbau ansehen', diff --git a/resources/views/filament/editorial/editor.blade.php b/resources/views/filament/editorial/editor.blade.php index b5bf42a..0567680 100644 --- a/resources/views/filament/editorial/editor.blade.php +++ b/resources/views/filament/editorial/editor.blade.php @@ -16,7 +16,7 @@

Dieser Eintrag wurde aus einem anderen Aufbau geöffnet.

@endif @@ -218,7 +218,7 @@

Freigegebene Fassungen

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

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

+

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

@else