Halte ungenutzte Medien bearbeitbar und lege Dateien direkt im Modul an.
Eine Fassung wird erst unveränderlich, wenn sie freigegeben und verwendet wird. Das Auge am Listeneintrag öffnet die Vorschau. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
1fb48783bf
commit
c73207f2c3
11 files changed
+547
-25
No files matched your search
@@ -20,6 +20,7 @@
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Filament\Support\IncomingFile;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
use App\Jobs\DeriveCompositionFrame;
|
||||
use App\Jobs\DeriveThumbnail;
|
||||
@@ -88,6 +89,8 @@ abstract class EditComposition extends EditRecord
|
||||
|
||||
public bool $textOpen = false;
|
||||
|
||||
public bool $fileOpen = false;
|
||||
|
||||
public bool $releaseArmed = false;
|
||||
|
||||
public string $returnUrl = '';
|
||||
@@ -100,6 +103,14 @@ abstract class EditComposition extends EditRecord
|
||||
|
||||
public string $newTextBody = '';
|
||||
|
||||
public string $newFileTitle = '';
|
||||
|
||||
public mixed $incomingFile = null;
|
||||
|
||||
public string $partTitle = '';
|
||||
|
||||
public string $partBody = '';
|
||||
|
||||
public string $newModuleName = '';
|
||||
|
||||
public mixed $previewUpload = null;
|
||||
@@ -301,6 +312,7 @@ public function openPicker(): void
|
||||
|
||||
$this->pickerOpen = true;
|
||||
$this->textOpen = false;
|
||||
$this->fileOpen = false;
|
||||
$this->pickerSelected = '';
|
||||
}
|
||||
|
||||
@@ -396,6 +408,7 @@ public function openText(): void
|
||||
$this->pickerOpen = false;
|
||||
$this->moduleOpen = false;
|
||||
$this->partOpen = false;
|
||||
$this->fileOpen = false;
|
||||
$this->textOpen = true;
|
||||
}
|
||||
|
||||
@@ -406,6 +419,22 @@ public function cancelText(): void
|
||||
$this->newTextBody = '';
|
||||
}
|
||||
|
||||
public function openFile(): void
|
||||
{
|
||||
$this->pickerOpen = false;
|
||||
$this->moduleOpen = false;
|
||||
$this->partOpen = false;
|
||||
$this->textOpen = false;
|
||||
$this->fileOpen = true;
|
||||
}
|
||||
|
||||
public function cancelFile(): void
|
||||
{
|
||||
$this->fileOpen = false;
|
||||
$this->newFileTitle = '';
|
||||
$this->incomingFile = null;
|
||||
}
|
||||
|
||||
public function saveDraft(): void
|
||||
{
|
||||
$this->commitRoleDraft();
|
||||
@@ -668,11 +697,16 @@ public function selectPart(int $index): void
|
||||
}
|
||||
|
||||
public function addPart(string $target): void
|
||||
{
|
||||
$this->includePart($target, false);
|
||||
}
|
||||
|
||||
private function includePart(string $target, bool $allowDraft): bool
|
||||
{
|
||||
if (preg_match('/^(element|composition):\d+$/', $target) !== 1) {
|
||||
$this->feedback = 'Dieser Bestandteil ist nicht verfügbar.';
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->members as $index => $member) {
|
||||
@@ -681,16 +715,16 @@ public function addPart(string $target): void
|
||||
$this->panel = 'bestandteil';
|
||||
$this->feedback = 'Diese Fassung ist schon enthalten.';
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$row = app(EditorialCatalog::class)->rowForTarget($target, (int) $this->getRecord()->getKey());
|
||||
$row = app(EditorialCatalog::class)->rowForTarget($target, (int) $this->getRecord()->getKey(), allowDraft: $allowDraft);
|
||||
|
||||
if ($row === null) {
|
||||
$this->feedback = 'Diese Fassung ist nicht bereit oder gehört zu diesem Eintrag.';
|
||||
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$row['role'] = app(EditorialCatalog::class)->defaultRole((string) $row['kind']);
|
||||
@@ -705,10 +739,12 @@ public function addPart(string $target): void
|
||||
$this->pickerSelected = '';
|
||||
|
||||
if (! $this->persistDraft()) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->feedback = $row['title'].' ist in den Aufbau übernommen. Die Datei wird nicht kopiert. Der Entwurf ist gespeichert. Es entsteht keine neue Fassung.';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function removePart(int $index): void
|
||||
@@ -796,7 +832,7 @@ public function addText(): void
|
||||
try {
|
||||
$service = app(ContentService::class);
|
||||
$element = $service->createElement('text', 'text', $title);
|
||||
$version = $service->publishElementVersion($element, $body);
|
||||
$version = $service->draftElementVersion($element, $body);
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->feedback = $exception->getMessage();
|
||||
|
||||
@@ -806,8 +842,62 @@ 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. Der Entwurf ist gespeichert. Es entsteht keine neue Fassung dieses Eintrags.';
|
||||
|
||||
if (! $this->includePart('element:'.$version->id, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Der Text bleibt bearbeitbar, solange diese Fassung nicht freigegeben und verwendet wird. Es entsteht keine neue Fassung dieses Eintrags.';
|
||||
}
|
||||
|
||||
public function addFile(): void
|
||||
{
|
||||
$title = trim($this->newFileTitle);
|
||||
$stored = IncomingFile::store($this->incomingFile);
|
||||
|
||||
if ($title === '' || $stored === null) {
|
||||
$this->feedback = 'Das Medium braucht einen Titel und eine Datei.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$extension = strtolower(pathinfo($stored, PATHINFO_EXTENSION));
|
||||
$shape = match ($extension) {
|
||||
'mp4', 'webm', 'mov', 'm4v' => ['film', 'film'],
|
||||
'mp3', 'm4a', 'wav', 'ogg' => ['audio', 'audio'],
|
||||
'png', 'jpg', 'jpeg', 'webp', 'gif' => ['bild', 'bild'],
|
||||
'pdf' => ['dokument', 'document'],
|
||||
default => null,
|
||||
};
|
||||
|
||||
if ($shape === null) {
|
||||
$this->feedback = 'Diese Dateiart lässt sich hier nicht anlegen.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$service = app(ContentService::class);
|
||||
$element = $service->createElement($shape[0], $shape[1], $title);
|
||||
$version = $service->draftElementVersion($element, null, [
|
||||
'incoming' => $stored,
|
||||
'hold' => true,
|
||||
]);
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->feedback = $exception->getMessage();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->newFileTitle = '';
|
||||
$this->incomingFile = null;
|
||||
$this->fileOpen = false;
|
||||
|
||||
if (! $this->includePart('element:'.$version->id, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->feedback = $title.' ist angelegt und in den Aufbau übernommen. Die Datei liegt bei den Medien. Eine neue Fassung entsteht erst, wenn diese Fassung freigegeben und verwendet wird.';
|
||||
}
|
||||
|
||||
public function startModule(): void
|
||||
@@ -856,6 +946,7 @@ public function openModule(): void
|
||||
$this->pickerOpen = false;
|
||||
$this->partOpen = false;
|
||||
$this->textOpen = false;
|
||||
$this->fileOpen = false;
|
||||
$this->moduleTab = 'beschreibung';
|
||||
$this->frameFilmChoices = $this->frameFilms();
|
||||
$films = $this->frameFilmChoices;
|
||||
@@ -914,10 +1005,14 @@ public function saveModule(): void
|
||||
public function openPart(int $index): void
|
||||
{
|
||||
$this->selectPart($index);
|
||||
$member = $this->selectedMember();
|
||||
$this->partTitle = (string) ($member['title'] ?? '');
|
||||
$this->partBody = (string) ($member['body'] ?? '');
|
||||
$this->partSnapshot = $this->members;
|
||||
$this->moduleOpen = false;
|
||||
$this->pickerOpen = false;
|
||||
$this->textOpen = false;
|
||||
$this->fileOpen = false;
|
||||
$this->partOpen = true;
|
||||
}
|
||||
|
||||
@@ -941,6 +1036,11 @@ public function savePart(): void
|
||||
}
|
||||
|
||||
$this->commitRoleDraft();
|
||||
$textNote = $this->writePartText();
|
||||
|
||||
if ($textNote === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->persistDraft()) {
|
||||
return;
|
||||
@@ -948,7 +1048,9 @@ public function savePart(): void
|
||||
|
||||
$this->partOpen = false;
|
||||
$this->partSnapshot = [];
|
||||
$this->feedback = 'Die Angaben zum Bestandteil sind im Entwurf. Es entsteht keine neue Fassung.';
|
||||
$this->feedback = $textNote !== ''
|
||||
? $textNote
|
||||
: 'Die Angaben zum Bestandteil sind im Entwurf. Es entsteht keine neue Fassung.';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1098,6 +1200,118 @@ public function adoptPicture(int $elementId): void
|
||||
$this->feedback = $this->previewFeedback($record, $before);
|
||||
}
|
||||
|
||||
private function writePartText(): string|false
|
||||
{
|
||||
$index = $this->selected;
|
||||
$member = $this->selectedMember();
|
||||
|
||||
if ($index === null || $member === null || ($member['output'] ?? '') !== 'text') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$title = trim($this->partTitle);
|
||||
$body = trim($this->partBody);
|
||||
|
||||
if ($title === '' || $body === '') {
|
||||
$this->feedback = 'Der Text braucht einen Titel und einen Inhalt.';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (preg_match('/^element:(\d+)$/', (string) ($member['target'] ?? ''), $match) !== 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$version = ContentElementVersion::query()->with('element')->find($match[1]);
|
||||
|
||||
if (! $version instanceof ContentElementVersion || $version->element === null) {
|
||||
$this->feedback = 'Dieser Text ist nicht mehr vorhanden.';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$changed = $title !== (string) ($member['title'] ?? '') || $body !== trim((string) $version->body);
|
||||
|
||||
if (! $changed) {
|
||||
return '';
|
||||
}
|
||||
|
||||
try {
|
||||
$service = app(ContentService::class);
|
||||
$service->describe($version->element, $title, $version->element->description);
|
||||
$updated = $service->reviseElementContent($version, $body);
|
||||
} catch (DomainRuleException $exception) {
|
||||
$this->feedback = $exception->getMessage();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($updated->id === $version->id) {
|
||||
$this->members[$index]['title'] = $title;
|
||||
$this->members[$index]['body'] = $body;
|
||||
|
||||
return 'Der Text ist in derselben Fassung geändert. Eine neue Fassung entsteht, sobald diese Fassung freigegeben und verwendet wird.';
|
||||
}
|
||||
|
||||
$row = app(EditorialCatalog::class)->rowForTarget(
|
||||
'element:'.$updated->id,
|
||||
(int) $this->getRecord()->getKey(),
|
||||
allowSelf: true,
|
||||
allowDraft: true,
|
||||
);
|
||||
|
||||
if ($row === null) {
|
||||
$this->feedback = 'Die neue Fassung ließ sich nicht in den Aufbau übernehmen.';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$row['role'] = (string) ($this->members[$index]['role'] ?? $row['kind']);
|
||||
$row['note'] = (string) ($this->members[$index]['note'] ?? '');
|
||||
$this->members[$index] = $row;
|
||||
|
||||
return 'Die Änderung liegt in einer neuen Fassung. Die bisherige Fassung bleibt in den freigegebenen Aufbauten.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<array{role: string, target: ContentElementVersion|CompositionVersion, note: string}> $payload
|
||||
*/
|
||||
private function promoteDraftElements(array $payload): bool
|
||||
{
|
||||
foreach ($payload as $member) {
|
||||
$target = $member['target'];
|
||||
|
||||
if (! $target instanceof ContentElementVersion || $target->status !== ContentVersionStatus::Entwurf) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta = is_array($target->metadata) ? $target->metadata : [];
|
||||
|
||||
if (isset($meta['incoming']) && ! isset($meta['file'])) {
|
||||
$this->feedback = 'Eine Datei wird noch übernommen. Gib den Aufbau frei, sobald die Datei bereitsteht.';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($meta['error'])) {
|
||||
$this->feedback = (string) $meta['error'];
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
unset($meta['held']);
|
||||
$target->metadata = $meta === [] ? null : $meta;
|
||||
$target->content_hash = hash('sha256', json_encode([
|
||||
'body' => $target->body,
|
||||
'metadata' => $meta,
|
||||
], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
|
||||
$target->status = ContentVersionStatus::Bereit;
|
||||
$target->save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{url: ?string, note: ?string, own: bool}
|
||||
*/
|
||||
@@ -1210,6 +1424,10 @@ public function publishRevision(): bool
|
||||
];
|
||||
}
|
||||
|
||||
if (! $this->promoteDraftElements($payload)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var Composition $record */
|
||||
$record = $this->getRecord();
|
||||
$note = trim($this->revisionNote);
|
||||
@@ -1343,7 +1561,7 @@ protected function applyDraft(array $draft): void
|
||||
}
|
||||
|
||||
$requested++;
|
||||
$row = $catalog->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true);
|
||||
$row = $catalog->rowForTarget((string) ($member['target'] ?? ''), (int) $this->getRecord()->getKey(), allowSelf: true, allowDraft: true);
|
||||
|
||||
if ($row === null) {
|
||||
continue;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Resources\ContentElements;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentVersionStatus;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
||||
use App\Filament\Resources\ContentElements\Pages\ListContentElements;
|
||||
@@ -85,8 +86,11 @@ public static function table(Table $table): Table
|
||||
}
|
||||
|
||||
$file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
|
||||
$label = $version->status === ContentVersionStatus::Entwurf
|
||||
? 'Entwurf'
|
||||
: 'Fassung '.$version->number;
|
||||
|
||||
return 'Fassung '.$version->number.(is_string($file) && $file !== '' ? ' · mit Datei' : ' · ohne Datei');
|
||||
return $label.(is_string($file) && $file !== '' ? ' · mit Datei' : ' · ohne Datei');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,8 @@ class ViewContentElement extends ViewRecord
|
||||
|
||||
public string $frameSecond = '';
|
||||
|
||||
public string $bodyDraft = '';
|
||||
|
||||
public string $thumbnailAlt = '';
|
||||
|
||||
public string $pictureFeedback = '';
|
||||
@@ -56,6 +58,7 @@ public function mount(int|string $record): void
|
||||
}
|
||||
|
||||
$this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? '');
|
||||
$this->syncBodyDraft();
|
||||
}
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
@@ -74,6 +77,25 @@ public function showVersion(int $version): void
|
||||
{
|
||||
abort_unless($this->ownedVersion($version) instanceof ContentElementVersion, 404);
|
||||
$this->fassung = $version;
|
||||
$this->syncBodyDraft();
|
||||
}
|
||||
|
||||
public function saveShownText(): void
|
||||
{
|
||||
$shown = $this->shownVersion();
|
||||
|
||||
if (! ContentElementResource::editor() || ! $shown instanceof ContentElementVersion || $shown->element?->output_class !== 'text') {
|
||||
return;
|
||||
}
|
||||
|
||||
$created = app(ContentService::class)->isCommitted($shown);
|
||||
$this->report(function () use ($shown): void {
|
||||
app(ContentService::class)->reviseElementContent($shown, $this->bodyDraft);
|
||||
}, $created
|
||||
? 'Die neue Fassung ist angelegt. Die bisherige bleibt erhalten.'
|
||||
: 'Der Text ist in derselben Fassung gespeichert.');
|
||||
$this->getRecord()->unsetRelation('versions');
|
||||
$this->syncBodyDraft();
|
||||
}
|
||||
|
||||
public function adoptFrame(): void
|
||||
@@ -282,6 +304,7 @@ private function viewerData(): array
|
||||
?? $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Bereit)
|
||||
?? $versions->first();
|
||||
$preview = app(ContentPreviewController::class);
|
||||
$committed = $shown instanceof ContentElementVersion && app(ContentService::class)->isCommitted($shown);
|
||||
|
||||
return [
|
||||
'element' => $element,
|
||||
@@ -292,11 +315,21 @@ private function viewerData(): array
|
||||
'pillars' => $element->pillars->pluck('name')->all(),
|
||||
'usage' => app(CatalogReading::class)->elementUsage($element),
|
||||
'canRevise' => ContentElementResource::editor(),
|
||||
'canEditBody' => ContentElementResource::editor()
|
||||
&& $shown instanceof ContentElementVersion
|
||||
&& $element->output_class === 'text'
|
||||
&& $shown->status !== ContentVersionStatus::Gesperrt,
|
||||
'bodyCommitted' => $committed,
|
||||
'pictureUrl' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
|
||||
'pictureCaption' => $this->pictureCaption($element),
|
||||
];
|
||||
}
|
||||
|
||||
private function syncBodyDraft(): void
|
||||
{
|
||||
$this->bodyDraft = (string) ($this->shownVersion()?->body ?? '');
|
||||
}
|
||||
|
||||
private function shownVersion(): ?ContentElementVersion
|
||||
{
|
||||
/** @var ContentElement $element */
|
||||
|
||||
@@ -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);
|
||||
$row = $this->rowForTarget($target, $exceptCompositionId, allowSelf: true, allowDraft: true);
|
||||
|
||||
if ($row === null) {
|
||||
continue;
|
||||
@@ -57,7 +57,7 @@ public function rows(CompositionVersion $version, int $exceptCompositionId): arr
|
||||
/**
|
||||
* @return array<string, string|null>|null
|
||||
*/
|
||||
public function rowForTarget(string $target, int $exceptCompositionId, bool $allowSelf = false): ?array
|
||||
public function rowForTarget(string $target, int $exceptCompositionId, bool $allowSelf = false, bool $allowDraft = false): ?array
|
||||
{
|
||||
if (preg_match('/^(element|composition):(\d+)$/', $target, $match) !== 1) {
|
||||
return null;
|
||||
@@ -67,8 +67,13 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
$version = ContentElementVersion::query()
|
||||
->with('element.editorialContentKind')
|
||||
->find($match[2]);
|
||||
$acceptable = [ContentVersionStatus::Bereit];
|
||||
|
||||
if (! $version instanceof ContentElementVersion || $version->status !== ContentVersionStatus::Bereit) {
|
||||
if ($allowDraft) {
|
||||
$acceptable[] = ContentVersionStatus::Entwurf;
|
||||
}
|
||||
|
||||
if (! $version instanceof ContentElementVersion || ! in_array($version->status, $acceptable, true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -80,13 +85,16 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
'target' => 'element:'.$version->id,
|
||||
'title' => $title,
|
||||
'kind' => $kind,
|
||||
'output' => (string) $element->output_class,
|
||||
'body' => (string) ($version->body ?? ''),
|
||||
'summary' => (string) ($element->summary ?: $element->description ?: ''),
|
||||
'medium_description' => (string) ($element->description ?? ''),
|
||||
'usage_note' => (string) ($element->usage_note ?? ''),
|
||||
'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' => 'Fassung '.$version->number,
|
||||
'version_label' => $version->status === ContentVersionStatus::Entwurf ? 'Entwurf' : 'Fassung '.$version->number,
|
||||
'committed' => app(ContentService::class)->isCommitted($version),
|
||||
'identity' => 'medium:'.$element->id,
|
||||
'open_url' => route('content.preview', $version),
|
||||
'open_label' => 'Medium ansehen',
|
||||
@@ -119,8 +127,8 @@ public function rowForTarget(string $target, int $exceptCompositionId, bool $all
|
||||
'image' => $this->cardUrl('komposition', $composition->id, $composition->thumbnail_path),
|
||||
'version_label' => 'Fassung '.$version->number,
|
||||
'identity' => 'zusammenstellung:'.$composition->id,
|
||||
'open_url' => null,
|
||||
'open_label' => null,
|
||||
'open_url' => route('editorial.preview', ['composition' => $composition, 'version' => $version]),
|
||||
'open_label' => 'Aufbau ansehen',
|
||||
'edit_url' => self::editUrl($composition),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user