Wähle das Vorschaubild am Medium und nutze es als Standard in der Anzeige und in Modulen.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
f86032cb5f
commit
8e77defaca
18 files changed
+664
-26
No files matched your search
@@ -15,10 +15,12 @@
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Domain\Catalog\ReleaseContent;
|
||||
use App\Domain\Media\ThumbnailRef;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\ElementRevision;
|
||||
use App\Filament\Support\MediaUploadLimit;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use App\Jobs\DeriveThumbnail;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
@@ -102,9 +104,27 @@ public function form(Schema $schema): Schema
|
||||
return $options;
|
||||
})
|
||||
->helperText('Wirkt auf die Suche und legt keine neue Fassung an.'),
|
||||
FileUpload::make('thumbnail_upload')->label('Vorschaubild')
|
||||
Placeholder::make('thumbnail_current')->label('Aktuelles Vorschaubild')->content(function (): HtmlString {
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
$url = ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path);
|
||||
$caption = match ($element->thumbnail_source) {
|
||||
'eigen' => 'Eigenes Vorschaubild.',
|
||||
'datei' => 'Vorschaubild aus der Datei des Mediums.',
|
||||
default => '',
|
||||
};
|
||||
if (is_string($element->thumbnail_source) && preg_match('/^frame:\d+@([\d.]+)$/', $element->thumbnail_source, $match) === 1) {
|
||||
$caption = 'Vorschaubild aus dem Film bei '.$match[1].' Sekunden.';
|
||||
}
|
||||
if ($url === null) {
|
||||
return new HtmlString('Noch kein Vorschaubild. Eine Filmstelle wählst du beim Ansehen des Mediums.');
|
||||
}
|
||||
|
||||
return new HtmlString('<img src="'.e($url).'" alt="" style="width: 16rem; height: auto;">'.($caption !== '' ? '<p>'.e($caption).'</p>' : ''));
|
||||
}),
|
||||
FileUpload::make('thumbnail_upload')->label('Eigenes Vorschaubild')
|
||||
->disk('cms_incoming')->directory('vorschau')->visibility('private')->image()
|
||||
->helperText('Nur die Karte. Die Inhaltsfassung bleibt unverändert.'),
|
||||
->helperText('Gilt für die Anzeige und als Vorschlag in Modulen und Programmen. Eine Filmstelle wählst du beim Ansehen. Speichern legt keine Fassung an.'),
|
||||
CheckboxList::make('pillars')
|
||||
->label('Fachliche Säulen')
|
||||
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all())
|
||||
@@ -209,10 +229,9 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
$record->save();
|
||||
}
|
||||
if (is_string($data['thumbnail_upload'] ?? null) && $data['thumbnail_upload'] !== '') {
|
||||
$record->thumbnail_path = $data['thumbnail_upload'];
|
||||
$record->thumbnail_error = null;
|
||||
$record->thumbnail_alt = $record->working_title;
|
||||
$record->save();
|
||||
DeriveThumbnail::dispatch('element', $record->id, $data['thumbnail_upload']);
|
||||
}
|
||||
if (array_key_exists('dimension_ids', $data)) {
|
||||
$ids = array_map(intval(...), $data['dimension_ids'] ?? []);
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
use App\Domain\Catalog\IdentityProfile;
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Domain\Media\ThumbnailRef;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\CatalogReading;
|
||||
use App\Filament\Support\ElementRevision;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use App\Http\Controllers\ContentPreviewController;
|
||||
use App\Jobs\DeriveThumbnail;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
@@ -23,15 +25,26 @@
|
||||
use Filament\Schemas\Schema;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
class ViewContentElement extends ViewRecord
|
||||
{
|
||||
use ReportsDomainRules;
|
||||
use WithFileUploads;
|
||||
|
||||
protected static string $resource = ContentElementResource::class;
|
||||
|
||||
public ?int $fassung = null;
|
||||
|
||||
public string $frameSecond = '';
|
||||
|
||||
public string $thumbnailAlt = '';
|
||||
|
||||
public string $pictureFeedback = '';
|
||||
|
||||
public mixed $previewUpload = null;
|
||||
|
||||
public function mount(int|string $record): void
|
||||
{
|
||||
parent::mount($record);
|
||||
@@ -41,6 +54,8 @@ public function mount(int|string $record): void
|
||||
if ($requested > 0) {
|
||||
$this->fassung = $requested;
|
||||
}
|
||||
|
||||
$this->thumbnailAlt = (string) ($this->getRecord()->thumbnail_alt ?? '');
|
||||
}
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
@@ -61,6 +76,125 @@ public function showVersion(int $version): void
|
||||
$this->fassung = $version;
|
||||
}
|
||||
|
||||
public function adoptFrame(): void
|
||||
{
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
$shown = $this->shownVersion();
|
||||
|
||||
if (! $shown instanceof ContentElementVersion || $element->output_class !== 'film') {
|
||||
$this->pictureFeedback = 'Für dieses Medium gibt es keine Filmstelle.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! is_numeric($this->frameSecond) || trim($this->frameSecond) === '') {
|
||||
$this->pictureFeedback = 'Wähle zuerst eine Zeitposition.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$seconds = (float) $this->frameSecond;
|
||||
|
||||
if ($seconds < 0 || $seconds > 7200) {
|
||||
$this->pictureFeedback = 'Die Zeitposition liegt außerhalb des Films.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->keepAlt($element);
|
||||
$element->thumbnail_error = null;
|
||||
$element->save();
|
||||
DeriveThumbnail::dispatch('element', $element->id, null, null, $shown->id, $seconds);
|
||||
$element->refresh();
|
||||
$this->pictureFeedback = $element->thumbnail_error
|
||||
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
|
||||
}
|
||||
|
||||
public function storePreview(): void
|
||||
{
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
|
||||
if (! $this->previewUpload instanceof TemporaryUploadedFile) {
|
||||
$this->pictureFeedback = 'Wähle zuerst eine Bilddatei.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$extension = strtolower($this->previewUpload->getClientOriginalExtension());
|
||||
|
||||
if (! in_array($extension, ['png', 'jpg', 'jpeg', 'webp'], true)) {
|
||||
$this->pictureFeedback = 'Das Vorschaubild muss eine Bilddatei sein.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$path = $this->previewUpload->storeAs(
|
||||
'vorschau',
|
||||
'karte-'.bin2hex(random_bytes(4)).'.'.$extension,
|
||||
'cms_incoming',
|
||||
);
|
||||
$this->previewUpload = null;
|
||||
|
||||
if (! is_string($path)) {
|
||||
$this->pictureFeedback = 'Das Vorschaubild wurde nicht übernommen.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->savePreviewImage($path);
|
||||
}
|
||||
|
||||
public function savePreviewImage(string $path): void
|
||||
{
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
$this->keepAlt($element);
|
||||
$element->thumbnail_error = null;
|
||||
$element->save();
|
||||
DeriveThumbnail::dispatch('element', $element->id, $path);
|
||||
$element->refresh();
|
||||
$this->pictureFeedback = $element->thumbnail_error
|
||||
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
|
||||
}
|
||||
|
||||
public function useOwnImage(): void
|
||||
{
|
||||
abort_unless(ContentElementResource::editor(), 403);
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
|
||||
if ($element->output_class !== 'bild') {
|
||||
$this->pictureFeedback = 'Die Datei dieses Mediums ist kein Bild. Lade ein Vorschaubild hoch.';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->keepAlt($element);
|
||||
$element->thumbnail_error = null;
|
||||
$element->save();
|
||||
DeriveThumbnail::dispatch('element', $element->id);
|
||||
$element->refresh();
|
||||
$this->pictureFeedback = $element->thumbnail_error
|
||||
?: 'Das Vorschaubild ist gespeichert. Die Fassung bleibt unverändert.';
|
||||
}
|
||||
|
||||
public function framePreviewUrl(): ?string
|
||||
{
|
||||
$shown = $this->shownVersion();
|
||||
|
||||
if (! $shown instanceof ContentElementVersion || ! is_numeric($this->frameSecond) || trim($this->frameSecond) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return route('editorial.frame', [
|
||||
'version' => $shown->id,
|
||||
'sekunde' => $this->frameSecond,
|
||||
]);
|
||||
}
|
||||
|
||||
public function deactivateAction(): Action
|
||||
{
|
||||
return Action::make('deactivate')
|
||||
@@ -158,9 +292,52 @@ private function viewerData(): array
|
||||
'pillars' => $element->pillars->pluck('name')->all(),
|
||||
'usage' => app(CatalogReading::class)->elementUsage($element),
|
||||
'canRevise' => ContentElementResource::editor(),
|
||||
'pictureUrl' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
|
||||
'pictureCaption' => $this->pictureCaption($element),
|
||||
];
|
||||
}
|
||||
|
||||
private function shownVersion(): ?ContentElementVersion
|
||||
{
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
$versions = $element->versions()->orderByDesc('number')->get();
|
||||
|
||||
return $versions->firstWhere('id', $this->fassung)
|
||||
?? $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Bereit)
|
||||
?? $versions->first();
|
||||
}
|
||||
|
||||
private function keepAlt(ContentElement $element): void
|
||||
{
|
||||
$alt = trim($this->thumbnailAlt);
|
||||
|
||||
if ($alt === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
$element->thumbnail_alt = $alt;
|
||||
}
|
||||
|
||||
private function pictureCaption(ContentElement $element): string
|
||||
{
|
||||
$source = $element->thumbnail_source;
|
||||
|
||||
if (! is_string($source) || $source === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (preg_match('/^frame:\d+@([\d.]+)$/', $source, $match) === 1) {
|
||||
return 'Vorschaubild aus dem Film bei '.$match[1].' Sekunden.';
|
||||
}
|
||||
|
||||
return match ($source) {
|
||||
'eigen' => 'Eigenes Vorschaubild.',
|
||||
'datei' => 'Vorschaubild aus der Datei des Mediums.',
|
||||
default => '',
|
||||
};
|
||||
}
|
||||
|
||||
private function ownedVersion(int $id): ?ContentElementVersion
|
||||
{
|
||||
/** @var ContentElement $element */
|
||||
|
||||
Reference in new issue
Block a user