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
@@ -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