Lege Medien über eine gemeinsame Maske mit Upload-Fortschritt an.
Beschreibung, Hinweise und Vorschaubild bleiben danach in derselben Maske bearbeitbar, im Bestand wie im Modul und Programm. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
c73207f2c3
commit
89c574106f
8 files changed
+407
-160
No files matched your search
@@ -20,15 +20,17 @@
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
use App\Domain\Catalog\StructureNode;
|
||||
use App\Filament\Support\EditorialCatalog;
|
||||
use App\Filament\Support\IncomingFile;
|
||||
use App\Filament\Support\MediumForm;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
use App\Jobs\DeriveCompositionFrame;
|
||||
use App\Jobs\DeriveThumbnail;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\Exceptions\Halt;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
@@ -89,8 +91,6 @@ abstract class EditComposition extends EditRecord
|
||||
|
||||
public bool $textOpen = false;
|
||||
|
||||
public bool $fileOpen = false;
|
||||
|
||||
public bool $releaseArmed = false;
|
||||
|
||||
public string $returnUrl = '';
|
||||
@@ -103,10 +103,6 @@ abstract class EditComposition extends EditRecord
|
||||
|
||||
public string $newTextBody = '';
|
||||
|
||||
public string $newFileTitle = '';
|
||||
|
||||
public mixed $incomingFile = null;
|
||||
|
||||
public string $partTitle = '';
|
||||
|
||||
public string $partBody = '';
|
||||
@@ -312,7 +308,6 @@ public function openPicker(): void
|
||||
|
||||
$this->pickerOpen = true;
|
||||
$this->textOpen = false;
|
||||
$this->fileOpen = false;
|
||||
$this->pickerSelected = '';
|
||||
}
|
||||
|
||||
@@ -408,7 +403,6 @@ public function openText(): void
|
||||
$this->pickerOpen = false;
|
||||
$this->moduleOpen = false;
|
||||
$this->partOpen = false;
|
||||
$this->fileOpen = false;
|
||||
$this->textOpen = true;
|
||||
}
|
||||
|
||||
@@ -419,22 +413,6 @@ 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();
|
||||
@@ -850,54 +828,71 @@ public function addText(): void
|
||||
$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
|
||||
public function createMediumAction(): Action
|
||||
{
|
||||
$title = trim($this->newFileTitle);
|
||||
$stored = IncomingFile::store($this->incomingFile);
|
||||
return Action::make('createMedium')
|
||||
->label('Medium anlegen')
|
||||
->modalHeading('Medium anlegen')
|
||||
->modalDescription('Dieselbe Maske gilt im Medienbestand, im Modul und im Programm. Der Upload zeigt seinen Fortschritt. Beschreibung, Hinweise und Vorschaubild trägst du danach in dieser Maske ein.')
|
||||
->modalSubmitActionLabel('Anlegen und übernehmen')
|
||||
->modalWidth(Width::Large)
|
||||
->schema(fn (): array => MediumForm::fields(creating: true))
|
||||
->action(function (array $data): void {
|
||||
try {
|
||||
$element = MediumForm::create($data, hold: true);
|
||||
} catch (DomainRuleException $exception) {
|
||||
Notification::make()->title($exception->getMessage())->danger()->send();
|
||||
|
||||
if ($title === '' || $stored === null) {
|
||||
$this->feedback = 'Das Medium braucht einen Titel und eine Datei.';
|
||||
throw new Halt;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
$version = $element->versions()->orderByDesc('number')->first();
|
||||
|
||||
$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 (! $version instanceof ContentElementVersion || ! $this->includePart('element:'.$version->id, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($shape === null) {
|
||||
$this->feedback = 'Diese Dateiart lässt sich hier nicht anlegen.';
|
||||
$this->feedback = $element->working_title.' ist angelegt und in den Aufbau übernommen. Die Datei liegt bei den Medien. Beschreibung und Vorschaubild sind gespeichert.';
|
||||
});
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
public function editMediumAction(): Action
|
||||
{
|
||||
return Action::make('editMedium')
|
||||
->modalHeading('Medium bearbeiten')
|
||||
->modalDescription('Titel, Beschreibung, Hinweise und Vorschaubild gelten für das Medium. Eine neue Fassung entsteht nur, wenn der Text bereits freigegeben und verwendet wird.')
|
||||
->modalSubmitActionLabel('Speichern')
|
||||
->modalWidth(Width::Large)
|
||||
->fillForm(function (array $arguments): array {
|
||||
$element = ContentElement::query()->find($arguments['element'] ?? 0);
|
||||
|
||||
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 $element instanceof ContentElement ? MediumForm::fill($element) : [];
|
||||
})
|
||||
->schema(function (array $arguments): array {
|
||||
$element = ContentElement::query()->find($arguments['element'] ?? 0);
|
||||
|
||||
return;
|
||||
}
|
||||
return MediumForm::fields(creating: false, element: $element instanceof ContentElement ? $element : null);
|
||||
})
|
||||
->action(function (array $data, array $arguments): void {
|
||||
$element = ContentElement::query()->find($arguments['element'] ?? 0);
|
||||
|
||||
$this->newFileTitle = '';
|
||||
$this->incomingFile = null;
|
||||
$this->fileOpen = false;
|
||||
if (! $element instanceof ContentElement) {
|
||||
Notification::make()->title('Dieses Medium ist nicht mehr vorhanden.')->danger()->send();
|
||||
|
||||
if (! $this->includePart('element:'.$version->id, true)) {
|
||||
return;
|
||||
}
|
||||
throw new Halt;
|
||||
}
|
||||
|
||||
$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.';
|
||||
try {
|
||||
$revised = MediumForm::update($element, $data);
|
||||
} catch (DomainRuleException $exception) {
|
||||
Notification::make()->title($exception->getMessage())->danger()->send();
|
||||
|
||||
throw new Halt;
|
||||
}
|
||||
|
||||
$this->retargetContainedElement($element, $revised);
|
||||
$this->feedback = 'Die Angaben des Mediums sind gespeichert.';
|
||||
});
|
||||
}
|
||||
|
||||
public function startModule(): void
|
||||
@@ -946,7 +941,6 @@ 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;
|
||||
@@ -1012,7 +1006,6 @@ public function openPart(int $index): void
|
||||
$this->moduleOpen = false;
|
||||
$this->pickerOpen = false;
|
||||
$this->textOpen = false;
|
||||
$this->fileOpen = false;
|
||||
$this->partOpen = true;
|
||||
}
|
||||
|
||||
@@ -1200,6 +1193,37 @@ public function adoptPicture(int $elementId): void
|
||||
$this->feedback = $this->previewFeedback($record, $before);
|
||||
}
|
||||
|
||||
private function retargetContainedElement(ContentElement $element, ?ContentElementVersion $revised): void
|
||||
{
|
||||
$element->refresh();
|
||||
|
||||
foreach ($this->members as $index => $member) {
|
||||
if ((int) ($member['element_id'] ?? 0) !== $element->id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$target = $revised instanceof ContentElementVersion
|
||||
? 'element:'.$revised->id
|
||||
: (string) ($member['target'] ?? '');
|
||||
$row = app(EditorialCatalog::class)->rowForTarget(
|
||||
$target,
|
||||
(int) $this->getRecord()->getKey(),
|
||||
allowSelf: true,
|
||||
allowDraft: true,
|
||||
);
|
||||
|
||||
if ($row === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$row['role'] = (string) ($member['role'] ?? $row['kind']);
|
||||
$row['note'] = (string) ($member['note'] ?? '');
|
||||
$this->members[$index] = $row;
|
||||
}
|
||||
|
||||
$this->persistDraft();
|
||||
}
|
||||
|
||||
private function writePartText(): string|false
|
||||
{
|
||||
$index = $this->selected;
|
||||
|
||||
Reference in new issue
Block a user