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;
|
||||
|
||||
Reference in new issue
Block a user