Zeige den Medienbestand als Kacheln und Liste mit Fassung, Freigabe und Verwendung.
Deploy Test / test (push) Successful in 45s
Deploy Test / deploy (push) Successful in 30s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-11-18 19:44:51 +01:00
1 parent 8a6678aad7
commit 3e56314cf9
8 files changed
+1511 -1

No files matched your search

@@ -3,11 +3,18 @@
namespace App\Filament\Resources\ContentElements\Pages;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Support\MediaLibrary;
use App\Filament\Support\MediumForm;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Resources\Pages\ListRecords;
use Filament\Schemas\Components\RenderHook;
use Filament\Schemas\Components\View;
use Filament\Schemas\Schema;
use Filament\Support\Enums\Width;
use Filament\View\PanelsRenderHook;
use Illuminate\Contracts\Support\Htmlable;
use Livewire\Attributes\Url;
class ListContentElements extends ListRecords
{
@@ -15,9 +22,141 @@ class ListContentElements extends ListRecords
protected static string $resource = ContentElementResource::class;
#[Url(as: 'suche', except: '')]
public string $suche = '';
#[Url(as: 'ansicht', except: 'kacheln')]
public string $ansicht = 'kacheln';
#[Url(as: 'art', except: '')]
public string $art = '';
#[Url(as: 'freigabe', except: '')]
public string $freigabe = '';
#[Url(as: 'entwurf', except: '')]
public string $entwurf = '';
#[Url(as: 'fassung', except: '')]
public string $fassung = '';
#[Url(as: 'nutzung', except: '')]
public string $nutzung = '';
#[Url(as: 'saeule', except: '')]
public string $saeule = '';
#[Url(as: 'einordnung', except: '')]
public string $einordnung = '';
#[Url(as: 'verarbeitung', except: '')]
public string $verarbeitung = '';
#[Url(as: 'archiv', except: 'aktiv')]
public string $archiv = 'aktiv';
public function getSubheading(): string|Htmlable|null
{
return 'Die Dateien und Texte. Eine Übung, ein Kurs oder eine fachliche Kombination verweist darauf; die Datei wird nicht für jede Verwendung neu hochgeladen.';
return 'Die Dateien und Texte. Ein Modul oder ein Programm verweist auf eine Fassung; die Datei wird nicht für jede Verwendung neu hochgeladen.';
}
public function getMaxContentWidth(): Width|string|null
{
return Width::Full;
}
public function content(Schema $schema): Schema
{
return $schema->components([
$this->getTabsContentComponent(),
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_BEFORE),
View::make('filament.media.library'),
RenderHook::make(PanelsRenderHook::RESOURCE_PAGES_LIST_RECORDS_TABLE_AFTER),
]);
}
public function showingList(): bool
{
return $this->ansicht === 'liste';
}
/**
* @return list<array<string, mixed>>
*/
public function cards(): array
{
return app(MediaLibrary::class)->cards($this->libraryFilters(), ContentElementResource::editor());
}
/**
* @return list<array{value: string, label: string}>
*/
public function typeOptions(): array
{
return app(MediaLibrary::class)->types();
}
/**
* @return list<array{id: int, name: string}>
*/
public function pillarOptions(): array
{
return app(MediaLibrary::class)->pillars();
}
/**
* @return list<array{id: int, label: string}>
*/
public function classificationOptions(): array
{
return app(MediaLibrary::class)->classifications();
}
public function filtersActive(): bool
{
return trim($this->suche) !== ''
|| $this->art !== ''
|| $this->freigabe !== ''
|| $this->entwurf !== ''
|| $this->fassung !== ''
|| $this->nutzung !== ''
|| $this->saeule !== ''
|| $this->einordnung !== ''
|| $this->verarbeitung !== ''
|| $this->archiv !== 'aktiv';
}
public function resetFilters(): void
{
$this->suche = '';
$this->art = '';
$this->freigabe = '';
$this->entwurf = '';
$this->fassung = '';
$this->nutzung = '';
$this->saeule = '';
$this->einordnung = '';
$this->verarbeitung = '';
$this->archiv = 'aktiv';
}
/**
* @return array<string, string>
*/
private function libraryFilters(): array
{
return [
'suche' => $this->suche,
'art' => $this->art,
'freigabe' => $this->freigabe,
'entwurf' => $this->entwurf,
'fassung' => $this->fassung,
'nutzung' => $this->nutzung,
'saeule' => $this->saeule,
'einordnung' => $this->einordnung,
'verarbeitung' => $this->verarbeitung,
'archiv' => $this->archiv,
];
}
protected function getHeaderActions(): array
+549
View File
@@ -0,0 +1,549 @@
<?php
namespace App\Filament\Support;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\CompositionMember;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\ContentElementVersion;
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\IdentityDimensionValue;
use App\Domain\Catalog\Pillar;
use App\Domain\Catalog\ReleaseContent;
use App\Domain\Media\ThumbnailRef;
use App\Filament\Resources\ContentElements\ContentElementResource;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
class MediaLibrary
{
public function __construct(private readonly EditorialCatalog $catalog) {}
/**
* @return list<array{value: string, label: string}>
*/
public function types(): array
{
return [
['value' => 'film', 'label' => 'Film'],
['value' => 'text', 'label' => 'Text'],
['value' => 'document', 'label' => 'Dokument'],
['value' => 'bild', 'label' => 'Bild'],
['value' => 'audio', 'label' => 'Hörstück'],
];
}
/**
* @return list<array{id: int, name: string}>
*/
public function pillars(): array
{
return Pillar::query()
->orderBy('name')
->get(['id', 'name'])
->map(fn (Pillar $pillar): array => ['id' => $pillar->id, 'name' => $pillar->name])
->all();
}
/**
* @return list<array{id: int, label: string}>
*/
public function classifications(): array
{
$options = [];
foreach (EditorialDimension::query()->with('values')->orderBy('label')->get() as $dimension) {
foreach ($dimension->values->sortBy('label') as $value) {
$options[] = [
'id' => $value->id,
'label' => $dimension->label.': '.$value->label,
];
}
}
return $options;
}
/**
* @param array<string, string> $filters
* @return list<array<string, mixed>>
*/
public function cards(array $filters, bool $canEdit): array
{
$filters = $this->normalize($filters);
$elements = ContentElement::query()
->with(['versions', 'pillars'])
->orderBy('working_title')
->get();
$versionIds = $elements->flatMap(fn (ContentElement $element) => $element->versions->pluck('id'))->all();
$placements = $this->placements($versionIds);
$licenses = $this->licenses($versionIds);
$classified = $this->classifiedIds();
$needle = mb_strtolower($filters['suche']);
$cards = [];
foreach ($elements as $element) {
$portrait = $this->portrait($element);
$uses = $placements[$element->id] ?? [];
$codes = $licenses[$element->id] ?? [];
if (! $this->matches($element, $portrait, $uses, $filters, $needle, $classified)) {
continue;
}
$cards[] = $this->card($element, $portrait, $uses, $codes, $canEdit);
}
usort($cards, fn (array $left, array $right): int => strcasecmp(
mb_strtolower($left['title']),
mb_strtolower($right['title']),
));
return $cards;
}
/**
* @param array<string, string> $filters
* @return array<string, string>
*/
private function normalize(array $filters): array
{
return [
'suche' => trim($filters['suche'] ?? ''),
'art' => $this->choice($filters['art'] ?? '', ['film', 'text', 'document', 'bild', 'audio']),
'freigabe' => $this->choice($filters['freigabe'] ?? '', ['freigegeben', 'entwurf', 'ohne']),
'entwurf' => $this->choice($filters['entwurf'] ?? '', ['offen', 'keiner']),
'fassung' => $this->choice($filters['fassung'] ?? '', ['mit', 'nur']),
'nutzung' => $this->choice($filters['nutzung'] ?? '', ['verwendet', 'unbenutzt']),
'saeule' => ctype_digit($filters['saeule'] ?? '') ? $filters['saeule'] : '',
'einordnung' => ctype_digit($filters['einordnung'] ?? '') ? $filters['einordnung'] : '',
'verarbeitung' => $this->choice($filters['verarbeitung'] ?? '', ['fehler', 'uebernahme']),
'archiv' => $this->choice($filters['archiv'] ?? '', ['aktiv', 'archiviert', 'alle'], 'aktiv'),
];
}
/**
* @param list<string> $allowed
*/
private function choice(string $value, array $allowed, string $fallback = ''): string
{
return in_array($value, $allowed, true) ? $value : $fallback;
}
/**
* @param list<int> $versionIds
* @return array<int, list<array<string, mixed>>>
*/
private function placements(array $versionIds): array
{
if ($versionIds === []) {
return [];
}
$grouped = [];
$members = CompositionMember::query()
->whereIn('content_element_version_id', $versionIds)
->with(['compositionVersion.composition', 'contentElementVersion'])
->orderBy('id')
->get();
foreach ($members as $member) {
$version = $member->contentElementVersion;
$compositionVersion = $member->compositionVersion;
$composition = $compositionVersion?->composition;
if (! $version instanceof ContentElementVersion || $compositionVersion === null || ! $composition instanceof Composition) {
continue;
}
$elementId = $version->content_element_id;
$key = $composition->id.'-'.$compositionVersion->id.'-'.$version->id;
$role = trim((string) $member->role);
if (! isset($grouped[$elementId][$key])) {
$grouped[$elementId][$key] = [
'compositionId' => $composition->id,
'name' => $this->catalog->compositionTitle($composition),
'type' => $this->kindLabel($composition),
'mediumVersion' => $this->versionLabel($version),
'hostVersion' => 'Fassung '.$compositionVersion->number,
'url' => EditorialCatalog::editUrl($composition),
'roles' => [],
];
}
if ($role !== '' && ! in_array($role, $grouped[$elementId][$key]['roles'], true)) {
$grouped[$elementId][$key]['roles'][] = $role;
}
}
$placements = [];
foreach ($grouped as $elementId => $rows) {
$list = array_values($rows);
usort($list, fn (array $left, array $right): int => [$left['type'], $left['name'], $left['hostVersion']]
<=> [$right['type'], $right['name'], $right['hostVersion']]);
$placements[$elementId] = $list;
}
return $placements;
}
/**
* @param list<int> $versionIds
* @return array<int, list<string>>
*/
private function licenses(array $versionIds): array
{
if ($versionIds === []) {
return [];
}
$codes = [];
$contents = ReleaseContent::query()
->whereIn('content_element_version_id', $versionIds)
->with(['release.article', 'elementVersion'])
->orderBy('id')
->get();
foreach ($contents as $content) {
$version = $content->elementVersion;
$code = $content->release?->article?->code;
if (! $version instanceof ContentElementVersion || ! is_string($code) || $code === '') {
continue;
}
$codes[$version->content_element_id][$code] = $code;
}
return array_map(fn (array $row): array => array_values($row), $codes);
}
/**
* @return array<int, list<int>>
*/
private function classifiedIds(): array
{
$map = [];
$rows = IdentityDimensionValue::query()
->where('subject_type', (new ContentElement)->getMorphClass())
->where('origin', 'direkt')
->get(['subject_id', 'editorial_dimension_value_id']);
foreach ($rows as $row) {
$map[(int) $row->subject_id][] = (int) $row->editorial_dimension_value_id;
}
return $map;
}
/**
* @return array{
* ready: ?ContentElementVersion,
* draft: ?ContentElementVersion,
* blocked: ?ContentElementVersion,
* versionCount: int,
* archived: bool,
* processing: ?string,
* stand: string,
* standTone: string,
* draftNote: ?string,
* blockedNote: ?string
* }
*/
private function portrait(ContentElement $element): array
{
/** @var Collection<int, ContentElementVersion> $versions */
$versions = $element->versions->sortByDesc('number')->values();
$ready = $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Bereit);
$draft = $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Entwurf);
$blocked = $versions->first(fn (ContentElementVersion $version): bool => $version->status === ContentVersionStatus::Gesperrt);
$processing = $this->processing($versions);
if ($ready instanceof ContentElementVersion) {
$stand = 'Fassung '.$ready->number.' freigegeben';
$tone = 'ready';
} elseif ($draft instanceof ContentElementVersion) {
$stand = 'Entwurf, noch nicht freigegeben';
$tone = 'draft';
} elseif ($blocked instanceof ContentElementVersion) {
$stand = 'Fassung '.$blocked->number.' deaktiviert';
$tone = 'blocked';
} else {
$stand = 'Noch keine Fassung';
$tone = 'quiet';
}
return [
'ready' => $ready instanceof ContentElementVersion ? $ready : null,
'draft' => $draft instanceof ContentElementVersion ? $draft : null,
'blocked' => $blocked instanceof ContentElementVersion ? $blocked : null,
'versionCount' => $versions->count(),
'archived' => $element->archived_at !== null,
'processing' => $processing,
'stand' => $stand,
'standTone' => $tone,
'draftNote' => $ready instanceof ContentElementVersion && $draft instanceof ContentElementVersion
? 'Entwurf offen'
: null,
'blockedNote' => $blocked instanceof ContentElementVersion && ($ready instanceof ContentElementVersion || $draft instanceof ContentElementVersion)
? 'Fassung '.$blocked->number.' deaktiviert'
: null,
];
}
/**
* @param Collection<int, ContentElementVersion> $versions
*/
private function processing(Collection $versions): ?string
{
foreach ($versions as $version) {
$meta = is_array($version->metadata) ? $version->metadata : [];
if (is_string($meta['error'] ?? null) && trim($meta['error']) !== '') {
return 'Verarbeitungsfehler';
}
}
foreach ($versions as $version) {
$meta = is_array($version->metadata) ? $version->metadata : [];
$incoming = $meta['incoming'] ?? null;
$hasIncoming = (is_string($incoming) && $incoming !== '') || (is_array($incoming) && $incoming !== []);
if ($hasIncoming && ! is_string($meta['file'] ?? null)) {
return 'Datei wird übernommen';
}
}
return null;
}
/**
* @param array<string, mixed> $portrait
* @param list<array<string, mixed>> $uses
* @param array<string, string> $filters
* @param array<int, list<int>> $classified
*/
private function matches(ContentElement $element, array $portrait, array $uses, array $filters, string $needle, array $classified): bool
{
if ($needle !== '' && ! str_contains($this->haystack($element), $needle)) {
return false;
}
if (! $this->matchesArt($element, $filters['art'])) {
return false;
}
$onlyBlocked = $portrait['ready'] === null && $portrait['draft'] === null && $portrait['blocked'] !== null;
if ($onlyBlocked && $filters['fassung'] === '' && $filters['archiv'] === 'aktiv') {
return false;
}
if ($filters['archiv'] === 'aktiv' && $portrait['archived']) {
return false;
}
if ($filters['archiv'] === 'archiviert' && ! $portrait['archived']) {
return false;
}
if ($filters['freigabe'] === 'freigegeben' && $portrait['ready'] === null) {
return false;
}
if ($filters['freigabe'] === 'entwurf' && ($portrait['draft'] === null || $portrait['ready'] !== null)) {
return false;
}
if ($filters['freigabe'] === 'ohne' && $portrait['ready'] !== null) {
return false;
}
if ($filters['entwurf'] === 'offen' && $portrait['draft'] === null) {
return false;
}
if ($filters['entwurf'] === 'keiner' && $portrait['draft'] !== null) {
return false;
}
if ($filters['fassung'] === 'mit' && $portrait['blocked'] === null) {
return false;
}
if ($filters['fassung'] === 'nur' && ($portrait['blocked'] === null || $portrait['ready'] !== null || $portrait['draft'] !== null)) {
return false;
}
$used = $this->usageCount($uses) > 0;
if ($filters['nutzung'] === 'verwendet' && ! $used) {
return false;
}
if ($filters['nutzung'] === 'unbenutzt' && $used) {
return false;
}
if ($filters['saeule'] !== '' && ! $element->pillars->contains('id', (int) $filters['saeule'])) {
return false;
}
if ($filters['einordnung'] !== '' && ! in_array((int) $filters['einordnung'], $classified[$element->id] ?? [], true)) {
return false;
}
if ($filters['verarbeitung'] === 'fehler' && $portrait['processing'] !== 'Verarbeitungsfehler') {
return false;
}
if ($filters['verarbeitung'] === 'uebernahme' && $portrait['processing'] !== 'Datei wird übernommen') {
return false;
}
return true;
}
private function matchesArt(ContentElement $element, string $art): bool
{
if ($art === '') {
return true;
}
$class = (string) $element->output_class;
if ($art === 'document') {
return in_array($class, ['document', 'pdf'], true);
}
return $class === $art;
}
private function haystack(ContentElement $element): string
{
return mb_strtolower(implode("\n", array_filter([
$element->working_title,
$element->display_title,
$element->description,
$element->summary,
$element->usage_note,
], fn (mixed $value): bool => is_string($value) && trim($value) !== '')));
}
/**
* @param array<string, mixed> $portrait
* @param list<array<string, mixed>> $uses
* @param list<string> $codes
* @return array<string, mixed>
*/
private function card(ContentElement $element, array $portrait, array $uses, array $codes, bool $canEdit): array
{
$description = trim((string) ($element->description ?: $element->summary ?: ''));
$usageNote = trim((string) $element->usage_note);
$licenseNote = trim((string) $element->license_note);
$typeKey = $this->typeKey((string) $element->output_class);
$count = $this->usageCount($uses);
return [
'id' => $element->id,
'title' => $element->working_title,
'type' => $this->catalog->outputLabel((string) $element->output_class),
'typeKey' => $typeKey,
'description' => $description === '' ? null : $description,
'usageNote' => $usageNote === '' ? null : $usageNote,
'licenseNote' => $licenseNote === '' ? null : $licenseNote,
'image' => ThumbnailRef::url('editorial.card', 'element', $element->id, $element->thumbnail_path),
'imageAlt' => trim((string) ($element->thumbnail_alt ?: $element->working_title)),
'imageNote' => $this->imageNote($element),
'stand' => $portrait['stand'],
'standTone' => $portrait['standTone'],
'draftNote' => $portrait['draftNote'],
'blockedNote' => $portrait['blockedNote'],
'processing' => $portrait['processing'],
'archived' => $portrait['archived'],
'versionCount' => $portrait['versionCount'],
'versionLabel' => $this->versionCountLabel($portrait['versionCount']),
'usageCount' => $count,
'usageLabel' => $count === 0
? 'In keinem Modul oder Programm verwendet'
: ($count === 1 ? '1 Verwendung' : $count.' Verwendungen'),
'usages' => $uses,
'licenseText' => $this->licenseText($codes),
'url' => ContentElementResource::getUrl('view', ['record' => $element]),
'editUrl' => $canEdit ? ContentElementResource::getUrl('edit', ['record' => $element]) : null,
];
}
/**
* @param list<array<string, mixed>> $uses
*/
private function usageCount(array $uses): int
{
return count(array_unique(array_column($uses, 'compositionId')));
}
private function versionCountLabel(int $count): ?string
{
return match ($count) {
0 => null,
1 => '1 Fassung',
default => $count.' Fassungen',
};
}
/**
* @param list<string> $codes
*/
private function licenseText(array $codes): ?string
{
if ($codes === []) {
return null;
}
$named = count($codes) === 1
? 'Im Lizenzartikel '.$codes[0].' genannt.'
: 'In den Lizenzartikeln '.implode(', ', $codes).' genannt.';
return $named.' Das belegt keinen Zugriff in der Bibliothek.';
}
private function imageNote(ContentElement $element): ?string
{
if (is_string($element->thumbnail_error) && trim($element->thumbnail_error) !== '') {
return Str::limit(trim($element->thumbnail_error), 180);
}
return null;
}
private function typeKey(string $outputClass): string
{
return match ($outputClass) {
'film' => 'film',
'audio' => 'audio',
'bild' => 'bild',
'document', 'pdf' => 'document',
default => 'text',
};
}
private function kindLabel(Composition $composition): string
{
$kind = $composition->kind;
return ($kind instanceof CompositionKind ? $kind : CompositionKind::from((string) $kind))->deskLabel();
}
private function versionLabel(ContentElementVersion $version): string
{
return match ($version->status) {
ContentVersionStatus::Entwurf => 'Entwurf',
ContentVersionStatus::Gesperrt => 'Fassung '.$version->number.', deaktiviert',
default => 'Fassung '.$version->number,
};
}
}
@@ -0,0 +1,50 @@
<article class="luf-medium luf-tone-{{ $card['typeKey'] }} {{ $list ? 'is-list' : 'is-tile' }}">
<a class="luf-medium-figure" href="{{ $card['url'] }}" aria-label="{{ $card['title'] }} ansehen">
@if ($card['image'])
<img src="{{ $card['image'] }}" alt="{{ $card['imageAlt'] }}">
@else
@include('filament.media.mark', ['typeKey' => $card['typeKey'], 'type' => $card['type']])
@endif
@if ($card['imageNote'])
<span class="luf-medium-figure-note">{{ $card['imageNote'] }}</span>
@endif
</a>
<div class="luf-medium-body">
<p class="luf-medium-kind">{{ $card['type'] }}</p>
<a class="luf-medium-title" href="{{ $card['url'] }}">{{ $card['title'] }}</a>
@if ($card['description'])
<p class="luf-medium-copy">{{ $card['description'] }}</p>
@endif
@if ($card['usageNote'])
<p class="luf-medium-copy luf-medium-note"><span class="luf-medium-kicker">Einsatz</span> {{ $card['usageNote'] }}</p>
@endif
@if ($card['licenseNote'])
<p class="luf-medium-copy luf-medium-note"><span class="luf-medium-kicker">Interner Lizenzvermerk</span> {{ $card['licenseNote'] }}</p>
@endif
<div class="luf-medium-flags">
<span class="luf-flag luf-flag-{{ $card['standTone'] }}">{{ $card['stand'] }}</span>
@if ($card['draftNote'])
<span class="luf-flag luf-flag-draft">{{ $card['draftNote'] }}</span>
@endif
@if ($card['blockedNote'])
<span class="luf-flag luf-flag-blocked">{{ $card['blockedNote'] }}</span>
@endif
@if ($card['processing'])
<span class="luf-flag luf-flag-wait">{{ $card['processing'] }}</span>
@endif
@if ($card['archived'])
<span class="luf-flag luf-flag-quiet">Archiviert</span>
@endif
@if ($card['versionLabel'])
<span class="luf-flag luf-flag-quiet">{{ $card['versionLabel'] }}</span>
@endif
</div>
@include('filament.media.usages', ['card' => $card])
<div class="luf-medium-actions">
<a class="luf-medium-link" href="{{ $card['url'] }}">Ansehen</a>
@if ($card['editUrl'])
<a class="luf-medium-link" href="{{ $card['editUrl'] }}">Bearbeiten</a>
@endif
</div>
</div>
</article>
@@ -0,0 +1,259 @@
<style>
.luf-media {
--luf-ink: #1b2838;
--luf-pine: #0f6e56;
--luf-paper: #f4f7f5;
--luf-line: #c5d2cb;
--luf-yellow: #e2b43a;
--luf-quiet: #3e4c5c;
color: var(--luf-ink);
font-size: 1rem;
line-height: 1.45;
min-width: 0;
}
.luf-media * { box-sizing: border-box; }
.luf-media a:focus-visible,
.luf-media button:focus-visible,
.luf-media input:focus-visible,
.luf-media select:focus-visible,
.luf-media summary:focus-visible {
outline: 3px solid #1769aa;
outline-offset: 2px;
}
.luf-media-bar,
.luf-media-reset {
display: flex;
flex-wrap: wrap;
gap: 0.75rem 1rem;
align-items: center;
justify-content: space-between;
margin: 0 0 0.85rem;
}
.luf-media-switch { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.luf-media-quiet {
font: inherit;
color: var(--luf-ink);
background: #fff;
border: 1px solid var(--luf-line);
min-height: 2.75rem;
padding: 0.35rem 0.8rem;
cursor: pointer;
}
.luf-media-quiet[aria-pressed="true"] {
background: var(--luf-ink);
color: #fff;
border-color: var(--luf-ink);
}
.luf-media-count { margin: 0; color: var(--luf-quiet); }
.luf-media-filters {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 12.5rem), 1fr));
gap: 0.7rem 0.8rem;
margin: 0 0 0.75rem;
}
.luf-media-field { display: grid; gap: 0.3rem; min-width: 0; }
.luf-media-field.is-wide { grid-column: 1 / -1; }
@media (min-width: 52rem) {
.luf-media-field.is-wide { grid-column: span 2; }
}
.luf-media-field label { font-weight: 650; }
.luf-media input,
.luf-media select {
width: 100%;
min-height: 2.75rem;
font: inherit;
color: inherit;
background: #fff;
border: 1px solid var(--luf-line);
padding: 0.45rem 0.65rem;
}
.luf-media-hint,
.luf-media-loading {
margin: 0 0 0.9rem;
color: var(--luf-quiet);
}
.luf-media-empty {
margin: 0 0 0.9rem;
padding: 1rem 1.1rem;
background: #fff;
border: 1px dashed var(--luf-line);
color: var(--luf-ink);
}
.luf-media-grid,
.luf-media-rows {
list-style: none;
margin: 0;
padding: 0;
min-width: 0;
}
.luf-media-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(100%, 18.5rem), 1fr));
gap: 1rem;
align-items: stretch;
}
.luf-media-rows { display: grid; gap: 0.7rem; }
.luf-medium {
background: #fff;
border: 1px solid var(--luf-line);
border-top: 4px solid var(--luf-pine);
min-width: 0;
height: 100%;
}
.luf-medium.is-tile { display: flex; flex-direction: column; }
.luf-medium.is-list {
display: grid;
grid-template-columns: 7.5rem minmax(0, 1fr);
gap: 0.8rem;
align-items: start;
height: auto;
}
.luf-tone-film { border-top-color: #1b2838; }
.luf-tone-document { border-top-color: #1769aa; }
.luf-tone-text { border-top-color: #c4962a; }
.luf-tone-audio { border-top-color: #6d4c7d; }
.luf-tone-bild { border-top-color: var(--luf-pine); }
.luf-medium-figure {
display: block;
position: relative;
aspect-ratio: 16 / 9;
background: var(--luf-paper);
color: var(--luf-pine);
overflow: hidden;
text-decoration: none;
}
.luf-medium.is-list .luf-medium-figure { aspect-ratio: 16 / 10; }
.luf-medium-figure img,
.luf-medium-mark,
.luf-medium-mark svg {
width: 100%;
height: 100%;
display: block;
}
.luf-medium-figure img { object-fit: cover; }
.luf-medium-mark {
display: flex;
align-items: center;
justify-content: center;
}
.luf-medium-mark svg { height: 72%; }
.luf-medium-figure-note {
position: absolute;
left: 0;
right: 0;
bottom: 0;
padding: 0.35rem 0.55rem;
background: rgba(27, 40, 56, 0.88);
color: #fff;
font-size: 0.82rem;
}
.luf-medium-body {
display: grid;
gap: 0.4rem;
padding: 0.8rem 0.9rem 0.95rem;
min-width: 0;
}
.luf-medium-kind {
margin: 0;
font-size: 0.78rem;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
color: var(--luf-pine);
}
.luf-medium-title {
color: inherit;
font-family: Georgia, "Source Serif 4", serif;
font-size: 1.28rem;
font-weight: 650;
letter-spacing: -0.02em;
line-height: 1.25;
text-decoration: none;
overflow-wrap: anywhere;
}
.luf-medium-title:hover { text-decoration: underline; }
.luf-medium-copy {
margin: 0;
overflow-wrap: anywhere;
}
.luf-medium.is-tile .luf-medium-copy {
display: -webkit-box;
-webkit-line-clamp: 4;
-webkit-box-orient: vertical;
overflow: hidden;
}
.luf-medium-note { color: var(--luf-quiet); font-size: 0.92rem; }
.luf-medium-kicker { font-weight: 700; color: var(--luf-ink); }
.luf-medium-flags {
display: flex;
flex-wrap: wrap;
gap: 0.35rem;
}
.luf-flag {
display: inline-flex;
align-items: center;
min-height: 1.7rem;
padding: 0.1rem 0.45rem;
border: 1px solid var(--luf-line);
background: #fff;
font-size: 0.86rem;
}
.luf-flag-ready { background: #e7f3ee; border-color: var(--luf-pine); }
.luf-flag-draft { background: #fff8e6; border-color: #c4962a; }
.luf-flag-blocked { background: #f8f1ea; border-color: #8a5a2a; }
.luf-flag-wait { background: #eef5fb; border-color: #1769aa; }
.luf-flag-quiet { color: var(--luf-quiet); }
.luf-medium-usage { display: grid; gap: 0.35rem; }
.luf-medium-unused,
.luf-medium-license { margin: 0; color: var(--luf-quiet); font-size: 0.92rem; }
.luf-medium-usage summary {
cursor: pointer;
min-height: 2.4rem;
display: flex;
align-items: center;
font-weight: 650;
}
.luf-medium-usage ul {
list-style: none;
margin: 0.2rem 0 0;
padding: 0;
display: grid;
gap: 0.45rem;
}
.luf-medium-usage li {
display: grid;
gap: 0.1rem;
padding-top: 0.35rem;
border-top: 1px solid var(--luf-line);
min-width: 0;
}
.luf-medium-usage a { color: var(--luf-pine); overflow-wrap: anywhere; }
.luf-medium-actions {
display: flex;
flex-wrap: wrap;
gap: 0.75rem 1rem;
margin-top: 0.15rem;
}
.luf-medium-link {
color: var(--luf-ink);
font-weight: 650;
text-underline-offset: 0.18em;
}
.luf-sr {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
@media (max-width: 40rem) {
.luf-medium.is-list { grid-template-columns: 5.5rem minmax(0, 1fr); }
.luf-medium-title { font-size: 1.12rem; }
}
@media (prefers-reduced-motion: reduce) {
.luf-media * { scroll-behavior: auto; }
}
</style>
@@ -0,0 +1,135 @@
@php
$cards = $this->cards();
$list = $this->showingList();
$count = count($cards);
@endphp
@include('filament.media.library-styles')
<div class="luf-media">
<div class="luf-media-bar">
<div class="luf-media-switch" role="group" aria-label="Ansicht">
<button type="button" class="luf-media-quiet" wire:click="$set('ansicht', 'kacheln')" aria-pressed="{{ $list ? 'false' : 'true' }}">Kacheln</button>
<button type="button" class="luf-media-quiet" wire:click="$set('ansicht', 'liste')" aria-pressed="{{ $list ? 'true' : 'false' }}">Liste</button>
</div>
<p class="luf-media-count" aria-live="polite">{{ $count === 1 ? '1 Medium' : $count.' Medien' }}</p>
</div>
<div class="luf-media-filters">
<div class="luf-media-field is-wide">
<label for="medien-suche">Suche</label>
<input id="medien-suche" type="search" wire:model.live.debounce.300ms="suche" placeholder="Titel oder Beschreibung">
</div>
<div class="luf-media-field">
<label for="medien-art">Art</label>
<select id="medien-art" wire:model.live="art">
<option value="">Alle Arten</option>
@foreach ($this->typeOptions() as $type)
<option value="{{ $type['value'] }}">{{ $type['label'] }}</option>
@endforeach
</select>
</div>
<div class="luf-media-field">
<label for="medien-freigabe">Freigabe</label>
<select id="medien-freigabe" wire:model.live="freigabe">
<option value="">Alle Freigaben</option>
<option value="freigegeben">Freigegebene Fassung</option>
<option value="entwurf">Nur offener Entwurf</option>
<option value="ohne">Keine freigegebene Fassung</option>
</select>
</div>
<div class="luf-media-field">
<label for="medien-entwurf">Entwurf</label>
<select id="medien-entwurf" wire:model.live="entwurf">
<option value="">Entwurf egal</option>
<option value="offen">Offener Entwurf</option>
<option value="keiner">Kein offener Entwurf</option>
</select>
</div>
<div class="luf-media-field">
<label for="medien-fassung">Deaktivierte Fassungen</label>
<select id="medien-fassung" wire:model.live="fassung">
<option value="">Regulärer Bestand</option>
<option value="mit">Mit deaktivierter Fassung</option>
<option value="nur">Nur deaktivierte Fassungen</option>
</select>
</div>
<div class="luf-media-field">
<label for="medien-nutzung">Verwendung</label>
<select id="medien-nutzung" wire:model.live="nutzung">
<option value="">Verwendung egal</option>
<option value="verwendet">Verwendet</option>
<option value="unbenutzt">Nicht verwendet</option>
</select>
</div>
@if ($pillars = $this->pillarOptions())
<div class="luf-media-field">
<label for="medien-saeule">Fachliche Säule</label>
<select id="medien-saeule" wire:model.live="saeule">
<option value="">Alle Säulen</option>
@foreach ($pillars as $pillar)
<option value="{{ $pillar['id'] }}">{{ $pillar['name'] }}</option>
@endforeach
</select>
</div>
@endif
@if ($classes = $this->classificationOptions())
<div class="luf-media-field">
<label for="medien-einordnung">Einordnung</label>
<select id="medien-einordnung" wire:model.live="einordnung">
<option value="">Alle Einordnungen</option>
@foreach ($classes as $class)
<option value="{{ $class['id'] }}">{{ $class['label'] }}</option>
@endforeach
</select>
</div>
@endif
<div class="luf-media-field">
<label for="medien-verarbeitung">Verarbeitung</label>
<select id="medien-verarbeitung" wire:model.live="verarbeitung">
<option value="">Verarbeitung egal</option>
<option value="fehler">Verarbeitungsfehler</option>
<option value="uebernahme">Datei wird übernommen</option>
</select>
</div>
<div class="luf-media-field">
<label for="medien-archiv">Archiv</label>
<select id="medien-archiv" wire:model.live="archiv">
<option value="aktiv">Aktive Medien</option>
<option value="archiviert">Archivierte Medien</option>
<option value="alle">Auch archivierte</option>
</select>
</div>
</div>
<p class="luf-media-hint">Freigabe meint die Fassung des Mediums. Sie ist weder die Veröffentlichung auf der Website noch ein Nachweis, dass jemand das Medium öffnen darf. Medien, die nur noch deaktivierte Fassungen haben, und archivierte Medien bleiben über die Filter auffindbar.</p>
@if ($this->filtersActive())
<p class="luf-media-reset">
<button type="button" class="luf-media-quiet" wire:click="resetFilters">Filter zurücksetzen</button>
</p>
@endif
<p class="luf-media-loading" wire:loading.delay role="status">Die Übersicht wird aktualisiert.</p>
<div wire:loading.delay.class="is-pending" aria-busy="false">
@if ($cards === [])
<div class="luf-media-empty">
@if ($this->filtersActive())
<p>Keine Medien entsprechen der Auswahl.</p>
<button type="button" class="luf-media-quiet" wire:click="resetFilters">Filter zurücksetzen</button>
@else
<p>Noch keine Medien im regulären Bestand.</p>
@endif
</div>
@else
<ul class="{{ $list ? 'luf-media-rows' : 'luf-media-grid' }}" data-ansicht="{{ $list ? 'liste' : 'kacheln' }}">
@foreach ($cards as $card)
<li wire:key="medium-{{ $card['id'] }}">
@include('filament.media.card', ['card' => $card, 'list' => $list])
</li>
@endforeach
</ul>
@endif
</div>
</div>
@@ -0,0 +1,34 @@
<span class="luf-medium-mark" data-fallback="{{ $typeKey }}" aria-hidden="true">
@switch($typeKey)
@case('film')
<svg viewBox="0 0 160 90">
<rect x="18" y="22" width="124" height="46" fill="none" stroke="currentColor" stroke-width="3"/>
<path d="M72 35 L98 45 L72 55 Z" fill="currentColor"/>
</svg>
@break
@case('audio')
<svg viewBox="0 0 160 90">
<path d="M30 45 H46 L66 28 V62 L46 45 Z" fill="none" stroke="currentColor" stroke-width="3"/>
<path d="M80 34 Q96 45 80 56 M96 26 Q122 45 96 64" fill="none" stroke="currentColor" stroke-width="3"/>
</svg>
@break
@case('bild')
<svg viewBox="0 0 160 90">
<rect x="22" y="18" width="116" height="54" fill="none" stroke="currentColor" stroke-width="3"/>
<circle cx="58" cy="38" r="7" fill="none" stroke="currentColor" stroke-width="3"/>
<path d="M34 62 L62 44 L84 58 L104 40 L126 62" fill="none" stroke="currentColor" stroke-width="3"/>
</svg>
@break
@case('document')
<svg viewBox="0 0 160 90">
<path d="M58 16 H96 L112 32 V74 H58 Z" fill="none" stroke="currentColor" stroke-width="3"/>
<path d="M96 16 V32 H112 M70 46 H100 M70 58 H100" fill="none" stroke="currentColor" stroke-width="3"/>
</svg>
@break
@default
<svg viewBox="0 0 160 90">
<path d="M36 28 H124 M36 45 H124 M36 62 H96" fill="none" stroke="currentColor" stroke-width="3"/>
</svg>
@endswitch
<span class="luf-sr">{{ $type }}</span>
</span>
@@ -0,0 +1,21 @@
<div class="luf-medium-usage">
@if ($card['usages'] === [])
<p class="luf-medium-unused">{{ $card['usageLabel'] }}</p>
@else
<details>
<summary>{{ $card['usageLabel'] }}</summary>
<ul>
@foreach ($card['usages'] as $usage)
<li>
<span class="luf-medium-kicker">{{ $usage['type'] }}</span>
<a href="{{ $usage['url'] }}">{{ $usage['name'] }}</a>
<span>Medium {{ $usage['mediumVersion'] }}, eingesetzt in {{ $usage['hostVersion'] }}@if ($usage['roles'] !== []) · {{ implode(', ', $usage['roles']) }}@endif</span>
</li>
@endforeach
</ul>
</details>
@endif
@if ($card['licenseText'])
<p class="luf-medium-license">{{ $card['licenseText'] }}</p>
@endif
</div>
+323
View File
@@ -0,0 +1,323 @@
<?php
namespace Tests\Feature;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\ContentVersionStatus;
use App\Domain\Catalog\EditorialDimension;
use App\Domain\Catalog\IdentityDimension;
use App\Domain\Catalog\PillarService;
use App\Filament\Resources\ContentElements\ContentElementResource;
use App\Filament\Resources\ContentElements\Pages\ListContentElements;
use App\Filament\Resources\Courses\CourseResource;
use App\Filament\Resources\Exercises\ExerciseResource;
use App\Filament\Support\MediaLibrary;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Queue;
use Livewire\Livewire;
use Tests\TestCase;
class MediaLibraryTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
}
public function test_the_library_opens_as_tiles_and_keeps_filters_when_the_view_changes(): void
{
$content = app(ContentService::class);
$film = $content->createElement('film', 'film', 'Lara im Park');
$film->description = 'Lara spielt im Park.';
$film->thumbnail_path = 'vorschau/element-'.$film->id.'.jpg';
$film->thumbnail_alt = 'Lara auf dem Weg';
$film->save();
$content->publishElementVersion($film, 'Film');
$content->createElement('text', 'text', 'Trainerhinweis');
Livewire::actingAs($this->editor(), 'staff')
->test(ListContentElements::class)
->assertOk()
->assertSee('data-ansicht="kacheln"', false)
->assertDontSee('data-ansicht="liste"', false)
->assertDontSee('Arbeitstitel')
->assertSee('Lara im Park')
->assertSee('Film')
->assertSee('Lara spielt im Park.')
->assertSee('Fassung 1 freigegeben')
->assertSee('Lara auf dem Weg')
->assertSee(route('editorial.card', ['kind' => 'element', 'subject' => $film->id]), false)
->assertSee('Trainerhinweis')
->assertSee('Text')
->set('suche', 'Park')
->assertSee('Lara im Park')
->assertDontSee('Trainerhinweis')
->set('ansicht', 'liste')
->assertSet('suche', 'Park')
->assertSee('data-ansicht="liste"', false)
->assertDontSee('data-ansicht="kacheln"', false)
->assertSee('Lara im Park')
->assertDontSee('Trainerhinweis')
->assertSee('Ansehen')
->assertSee('Bearbeiten')
->call('resetFilters')
->assertSet('suche', '')
->assertSet('ansicht', 'liste')
->assertSee('Trainerhinweis');
}
public function test_a_text_medium_is_not_shown_as_a_film_or_as_a_released_version(): void
{
$content = app(ContentService::class);
$text = $content->createElement('text', 'text', 'Felix beim Onkel');
$content->draftElementVersion($text, 'Erst vorlesen.');
Livewire::actingAs($this->editor(), 'staff')
->test(ListContentElements::class)
->assertSee('Felix beim Onkel')
->assertSee('Text')
->assertSee('Entwurf, noch nicht freigegeben')
->assertSee('data-fallback="text"', false)
->assertDontSee('Fassung 1 freigegeben')
->assertDontSee('/redaktion/karte/', false);
}
public function test_filters_combine_and_a_draft_stays_distinct_from_a_released_version(): void
{
$content = app(ContentService::class);
$film = $content->createElement('film', 'film', 'Felix und der Autofahrer');
$content->publishElementVersion($film, 'Erste Fassung');
$content->draftElementVersion($film, 'Neue Schnittfassung');
$sheet = $content->createElement('dokument', 'document', 'Traineranleitung Abstand');
$content->publishElementVersion($sheet, 'Bitte vorlesen.');
$broken = $content->createElement('film', 'film', 'Unlesbare Datei');
$content->draftElementVersion($broken, null, ['error' => 'Die Datei ließ sich nicht lesen.']);
Livewire::actingAs($this->editor(), 'staff')
->test(ListContentElements::class)
->assertSee('Fassung 1 freigegeben')
->assertSee('Entwurf offen')
->assertDontSee('Fassung 2 freigegeben')
->set('suche', 'Autofahrer')
->set('art', 'film')
->set('freigabe', 'freigegeben')
->set('entwurf', 'offen')
->assertSee('Felix und der Autofahrer')
->assertDontSee('Traineranleitung Abstand')
->assertDontSee('Unlesbare Datei')
->set('art', 'document')
->assertDontSee('Felix und der Autofahrer')
->call('resetFilters')
->set('verarbeitung', 'fehler')
->assertSee('Unlesbare Datei')
->assertSee('Verarbeitungsfehler')
->assertDontSee('Felix und der Autofahrer');
}
public function test_a_blocked_version_does_not_mark_the_whole_medium_and_stays_findable(): void
{
$content = app(ContentService::class);
$film = $content->createElement('film', 'film', 'Lara im Park');
$first = $content->publishElementVersion($film, 'Alt');
$content->publishElementVersion($film, 'Neu');
$content->block($first, 'Veraltet');
$retired = $content->createElement('film', 'film', 'Alter Take');
$only = $content->publishElementVersion($retired, 'Take');
$content->block($only, 'Nicht verwenden');
$this->assertSame(ContentVersionStatus::Gesperrt, $first->fresh()->status);
$this->assertSame(ContentVersionStatus::Bereit, $film->versions()->where('number', 2)->first()->status);
Livewire::actingAs($this->editor(), 'staff')
->test(ListContentElements::class)
->assertSee('Lara im Park')
->assertSee('Fassung 2 freigegeben')
->assertSee('Fassung 1 deaktiviert')
->assertDontSee('Medium deaktiviert')
->assertDontSee('Alter Take')
->set('fassung', 'nur')
->assertSee('Alter Take')
->assertSee('Fassung 1 deaktiviert')
->assertDontSee('Lara im Park');
}
public function test_usage_follows_older_versions_to_the_module_and_the_program(): void
{
$content = app(ContentService::class);
$film = $content->createElement('film', 'film', 'Felix beim Onkel');
$first = $content->publishElementVersion($film, 'Erste Fassung');
$content->publishElementVersion($film, 'Zweite Fassung');
$module = $content->publishComposition(
$content->createComposition('Abstand üben', CompositionKind::Uebung),
[['role' => 'Film', 'target' => $first]],
);
$program = $content->publishComposition(
$content->createComposition('Vormittag', CompositionKind::Kurs),
[['role' => 'Film', 'target' => $first]],
);
$moduleUrl = ExerciseResource::getUrl('edit', ['record' => $module->composition_id]);
$programUrl = CourseResource::getUrl('edit', ['record' => $program->composition_id]);
Livewire::actingAs($this->editor(), 'staff')
->test(ListContentElements::class)
->assertSee('2 Verwendungen')
->assertSee('Modul')
->assertSee('Programm')
->assertSee('Abstand üben')
->assertSee('Vormittag')
->assertSee('Medium Fassung 1', false)
->assertSee($moduleUrl, false)
->assertSee($programUrl, false);
$this->assertSame($first->id, $module->members()->first()->content_element_version_id);
$this->assertSame($first->id, $program->members()->first()->content_element_version_id);
$this->assertSame(2, $film->versions()->count());
}
public function test_a_license_article_is_not_treated_as_library_access_or_as_usage(): void
{
$content = app(ContentService::class);
$sheet = $content->publishElementVersion(
$content->createElement('text', 'text', 'Merkblatt Grenzen'),
'Den Abstand ansprechen.',
);
$article = app(ArticleService::class)->create('grenzen-'.str()->lower(str()->random(4)));
app(ArticleService::class)->publishRelease($article, $sheet, 'Dieselbe Ausgabe.');
Livewire::actingAs($this->editor(), 'staff')
->test(ListContentElements::class)
->assertSee('In keinem Modul oder Programm verwendet')
->assertSee('Im Lizenzartikel '.$article->code.' genannt. Das belegt keinen Zugriff in der Bibliothek.')
->set('nutzung', 'verwendet')
->assertDontSee('Merkblatt Grenzen')
->set('nutzung', 'unbenutzt')
->assertSee('Merkblatt Grenzen');
}
public function test_a_pending_file_is_not_shown_as_released_and_archived_media_stay_behind_a_filter(): void
{
Queue::fake();
$content = app(ContentService::class);
$film = $content->createElement('film', 'film', 'Felix und der Autofahrer');
$content->draftElementVersion($film, null, ['incoming' => 'inhalte/fahrer.mp4', 'hold' => true]);
$archived = $content->createElement('text', 'text', 'Alte Anleitung');
$content->publishElementVersion($archived, 'Text');
$archived->archived_at = now();
$archived->save();
Livewire::actingAs($this->editor(), 'staff')
->test(ListContentElements::class)
->assertSee('Datei wird übernommen')
->assertSee('Entwurf, noch nicht freigegeben')
->assertDontSee('Alte Anleitung')
->set('archiv', 'archiviert')
->assertSee('Alte Anleitung')
->assertSee('Archiviert')
->assertDontSee('Felix und der Autofahrer');
}
public function test_pillar_and_classification_filters_narrow_the_same_library(): void
{
$content = app(ContentService::class);
$film = $content->createElement('film', 'film', 'Lara im Park');
$content->publishElementVersion($film, 'Film');
$other = $content->createElement('text', 'text', 'Ohne Säule');
$content->publishElementVersion($other, 'Text');
$pillar = app(PillarService::class)->create('Meine Grenzen');
app(PillarService::class)->assign($film, [$pillar->id]);
$dimension = EditorialDimension::query()->create(['slug' => 'zielgruppe', 'label' => 'Zielgruppe']);
$value = $dimension->values()->create(['slug' => 'grundschule', 'label' => 'Grundschule']);
app(IdentityDimension::class)->assign($film, $value);
Livewire::actingAs($this->editor(), 'staff')
->test(ListContentElements::class)
->set('saeule', (string) $pillar->id)
->assertSee('Lara im Park')
->assertDontSee('Ohne Säule')
->set('saeule', '')
->set('einordnung', (string) $value->id)
->assertSee('Lara im Park')
->assertDontSee('Ohne Säule');
}
public function test_a_catalog_keeper_can_open_the_library_but_cannot_edit(): void
{
app(ContentService::class)->publishElementVersion(
app(ContentService::class)->createElement('text', 'text', 'Hinweis'),
'Text',
);
$keeper = User::factory()->katalogverwalter()->create();
$keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
Livewire::actingAs($keeper, 'staff')
->test(ListContentElements::class)
->assertOk()
->assertSee('Hinweis')
->assertSee('Ansehen')
->assertDontSee('Bearbeiten')
->assertDontSee('Medium anlegen');
}
public function test_usage_counts_are_loaded_without_a_query_per_card(): void
{
$content = app(ContentService::class);
foreach (['Lara im Park', 'Felix beim Onkel', 'Felix und der Autofahrer'] as $title) {
$version = $content->publishElementVersion($content->createElement('film', 'film', $title), 'Film');
$content->publishComposition(
$content->createComposition('Modul '.$title, CompositionKind::Uebung),
[['role' => 'Film', 'target' => $version]],
);
}
DB::flushQueryLog();
DB::enableQueryLog();
$cards = app(MediaLibrary::class)->cards([
'suche' => '',
'art' => '',
'freigabe' => '',
'entwurf' => '',
'fassung' => '',
'nutzung' => '',
'saeule' => '',
'einordnung' => '',
'verarbeitung' => '',
'archiv' => 'aktiv',
], true);
$queries = count(DB::getQueryLog());
$this->assertCount(3, $cards);
$this->assertSame(1, $cards[0]['usageCount']);
$this->assertLessThan(12, $queries);
}
public function test_an_editor_can_open_a_medium_from_the_library(): void
{
$element = app(ContentService::class)->createElement('film', 'film', 'Lara im Park');
app(ContentService::class)->publishElementVersion($element, 'Film');
$editor = $this->editor();
$this->actingAs($editor, 'staff')
->get(ContentElementResource::getUrl('index'))
->assertOk()
->assertSee(ContentElementResource::getUrl('view', ['record' => $element]), false)
->assertSee(ContentElementResource::getUrl('edit', ['record' => $element]), false);
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();
$editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $editor;
}
}