Stelle die Kataloglisten und das Angebot auf die gemeinsamen Muster um.
CI Feature / test (push) Successful in 1m0s
Deploy Test / test (push) Successful in 54s
Deploy Test / deploy (push) Successful in 23s

- Lizenzartikel, Pakete, Rechteprofile und Angebote nutzen die gemeinsame
  Bestandsliste (ListsCatalog): Suche, Zustandsfilter, lesbare Zustände aus
  vorhandenen Daten statt „Aktueller Stand: 1“ oder „Fassungen: aktiv“
  (Stand veröffentlicht/in Arbeit/gesperrt, in aktivem Angebot, Fassung aktiv
  mit Vergabe und Preis, Bestandteile, Zweck und Fähigkeiten). Lizenzartikel
  zeigen ihr Titelbild.
- Anlegedialoge benennen Zweck und Bestätigung und öffnen danach den neuen
  Eintrag, statt in der Liste stehen zu bleiben.
- Angebot im gemeinsamen Rahmen (Kopf, Positionen, aufgelöster
  Leistungsumfang, Fassungsverlauf). Eine Maske für Anlegen und Ändern
  (FACH-20): „Fassung aktivieren“ bzw. „Geänderte Fassung aktivieren“, bei einer
  Änderung mit der aktiven Fassung vorbelegt (FACH-08). Wirkung unverändert
  OfferService::activate: die bisherige Fassung wird beendet und bleibt
  gespeichert. „Als Vorlage verwenden“ (FACH-09) bleibt offen (OFF-04).
- Entfernt: editorial/catalog-card (ersetzt).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-20 08:29:28 +01:00
1 parent 532979aa86
commit 660b50f418
10 files changed
+828 -80

No files matched your search

@@ -2,8 +2,12 @@
namespace App\Filament\Resources\Bundles\Pages;
use App\Domain\Catalog\Bundle;
use App\Domain\Catalog\BundleService;
use App\Domain\Catalog\BundleStatus;
use App\Domain\Catalog\StatusValue;
use App\Filament\Resources\Bundles\BundleResource;
use App\Filament\Support\ListsCatalog;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
@@ -12,6 +16,7 @@
class ListBundles extends ListRecords
{
use ListsCatalog;
use ReportsDomainRules;
protected static string $resource = BundleResource::class;
@@ -24,13 +29,83 @@ public function getSubheading(): string|Htmlable|null
protected function getHeaderActions(): array
{
return [
Action::make('create')->label('Paket anlegen')->schema([
TextInput::make('name')->label('Name')->required(),
])->action(function (array $data): void {
$this->report(function () use ($data): void {
app(BundleService::class)->create($data['name']);
}, 'Das Paket ist angelegt.');
}),
Action::make('create')->label('Paket anlegen')
->modalHeading('Neues Paket')
->modalDescription('Der Name genügt. Bestandteile stellst du danach am Paket zusammen.')
->modalSubmitActionLabel('Paket anlegen')
->schema([
TextInput::make('name')->label('Name')->required(),
])->action(function (array $data): void {
$bundle = null;
$this->report(function () use ($data, &$bundle): void {
$bundle = app(BundleService::class)->create($data['name']);
}, 'Das Paket ist angelegt.');
if ($bundle instanceof Bundle) {
$this->redirect(BundleResource::getUrl('view', ['record' => $bundle]));
}
}),
];
}
protected function catalogRows(): array
{
$rows = [];
foreach (Bundle::query()->with(['versions.items'])->orderBy('name')->get() as $bundle) {
$versions = $bundle->versions->sortByDesc('number');
$published = $versions->first(fn ($version): bool => StatusValue::of($version->status) === BundleStatus::Veroeffentlicht->value);
$draft = $versions->first(fn ($version): bool => StatusValue::of($version->status) === BundleStatus::Entwurf->value);
$chips = [];
$zustand = [];
if ($published !== null) {
$chips[] = ['label' => 'Fassung '.$published->number.' veröffentlicht', 'ton' => 'gut'];
$chips[] = ['label' => $published->items->count() === 1 ? '1 Bestandteil' : $published->items->count().' Bestandteile', 'ton' => 'leise'];
$zustand[] = 'veroeffentlicht';
} else {
$chips[] = ['label' => $versions->isEmpty() ? 'Noch keine Fassung' : 'Noch nicht veröffentlicht', 'ton' => 'offen'];
$zustand[] = 'ohne';
}
if ($draft !== null) {
$chips[] = ['label' => 'Fassung '.$draft->number.' in Arbeit', 'ton' => 'offen'];
$zustand[] = 'entwurf';
}
if ($bundle->archived_at !== null) {
$chips[] = ['label' => 'Archiviert', 'ton' => 'leise'];
$zustand[] = 'archiviert';
}
$url = BundleResource::getUrl('view', ['record' => $bundle]);
$rows[] = [
'schluessel' => 'p'.$bundle->id,
'titel' => $bundle->name,
'meta' => 'Paket',
'symbol' => 'modul',
'url' => $url,
'chips' => $chips,
'zustand' => $zustand,
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
];
}
return $rows;
}
protected function zustandOptionen(): array
{
return ['alle' => 'Jeder Zustand', 'veroeffentlicht' => 'Veröffentlicht', 'ohne' => 'Noch nicht veröffentlicht', 'entwurf' => 'Fassung in Arbeit', 'archiviert' => 'Archiviert'];
}
protected function einheit(): array
{
return ['Paket', 'Pakete'];
}
protected function leer(): array
{
return ['titel' => 'Noch keine Pakete', 'text' => 'Mit „Paket anlegen“ oben entsteht das erste Paket.'];
}
}
@@ -3,15 +3,24 @@
namespace App\Filament\Resources\LicenseArticles\Pages;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\ContentElement;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\PresentationMedia;
use App\Domain\Catalog\ReleaseStatus;
use App\Domain\Catalog\StatusValue;
use App\Domain\Media\ThumbnailRef;
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
use App\Filament\Support\ListsCatalog;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Facades\DB;
class ListLicenseArticles extends ListRecords
{
use ListsCatalog;
use ReportsDomainRules;
protected static string $resource = LicenseArticleResource::class;
@@ -26,15 +35,118 @@ protected function getHeaderActions(): array
return [
Action::make('create')
->label('Artikel anlegen')
->modalHeading('Neuer Lizenzartikel')
->modalDescription('Kennung und Produktlinie genügen. Titel, Texte und Stand pflegst du danach am Artikel.')
->modalSubmitActionLabel('Artikel anlegen')
->schema([
TextInput::make('code')->label('Kennung')->required(),
TextInput::make('product_line')->label('Produktlinie'),
])
->action(function (array $data): void {
$this->report(function () use ($data): void {
app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null);
$article = null;
$this->report(function () use ($data, &$article): void {
$article = app(ArticleService::class)->create($data['code'], $data['product_line'] ?? null);
}, 'Der Lizenzartikel ist angelegt.');
if ($article instanceof LicenseArticle) {
$this->redirect(LicenseArticleResource::getUrl('view', ['record' => $article]));
}
}),
];
}
protected function catalogRows(): array
{
$offered = DB::table('resolved_scopes')
->join('offer_versions', 'offer_versions.id', '=', 'resolved_scopes.offer_version_id')
->where('offer_versions.status', 'aktiv')
->distinct()
->pluck('resolved_scopes.license_article_id')
->map(fn (mixed $id): int => (int) $id)
->all();
$presentation = app(PresentationMedia::class);
$rows = [];
foreach (LicenseArticle::query()->with(['currentRelease', 'releases'])->orderBy('code')->get() as $article) {
$current = $article->currentRelease;
$currentStatus = $current !== null ? StatusValue::of($current->status) : null;
$draft = $article->releases->first(fn ($release): bool => StatusValue::of($release->status) === ReleaseStatus::Entwurf->value);
$chips = [];
$zustand = [];
if ($current === null) {
$chips[] = ['label' => 'Noch kein Stand', 'ton' => 'offen'];
$zustand[] = 'ohne';
} elseif ($currentStatus === ReleaseStatus::Gesperrt->value) {
$chips[] = ['label' => 'Stand '.$current->number.' gesperrt', 'ton' => 'achtung'];
$zustand[] = 'gesperrt';
} else {
$chips[] = ['label' => 'Stand '.$current->number.' veröffentlicht', 'ton' => 'gut'];
$zustand[] = 'stand';
}
if ($draft !== null) {
$chips[] = ['label' => 'Stand '.$draft->number.' in Arbeit', 'ton' => 'offen'];
$zustand[] = 'entwurf';
}
$inOffer = in_array($article->id, $offered, true);
$chips[] = $inOffer ? ['label' => 'In einem aktiven Angebot', 'ton' => 'gut'] : ['label' => 'In keinem aktiven Angebot', 'ton' => 'leise'];
$zustand[] = $inOffer ? 'angebot' : 'ohne-angebot';
if ($article->archived_at !== null) {
$chips[] = ['label' => 'Archiviert', 'ton' => 'leise'];
$zustand[] = 'archiviert';
}
$coverId = $presentation->coverElementId($article);
$cover = $coverId !== null ? ContentElement::query()->find($coverId) : null;
$title = trim((string) ($article->display_title ?: $article->working_title)) ?: $article->code;
$url = LicenseArticleResource::getUrl('view', ['record' => $article]);
$rows[] = [
'schluessel' => 'a'.$article->id,
'titel' => $title,
'meta' => 'Lizenzartikel · '.$article->code.(filled($article->product_line) ? ' · '.$article->product_line : ''),
'text' => trim((string) ($article->teaser ?: $article->summary)),
'bild' => $cover !== null ? ThumbnailRef::url('editorial.card', 'element', $cover->id, $cover->thumbnail_path) : null,
'symbol' => 'dokument',
'url' => $url,
'chips' => $chips,
'zustand' => $zustand,
'suchtext' => implode(' ', array_filter([$article->code, $article->working_title, $article->display_title, $article->summary, $article->product_line, $article->search_terms])),
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
];
}
return $rows;
}
protected function zustandOptionen(): array
{
return [
'alle' => 'Jeder Zustand',
'stand' => 'Mit veröffentlichtem Stand',
'ohne' => 'Noch ohne Stand',
'entwurf' => 'Stand in Arbeit',
'gesperrt' => 'Gesperrter Stand',
'angebot' => 'In einem aktiven Angebot',
'ohne-angebot' => 'In keinem aktiven Angebot',
'archiviert' => 'Archiviert',
];
}
protected function einheit(): array
{
return ['Lizenzartikel', 'Lizenzartikel'];
}
protected function leer(): array
{
return ['titel' => 'Noch keine Lizenzartikel', 'text' => 'Mit „Artikel anlegen“ oben entsteht der erste Artikel.'];
}
protected function suchPlatzhalter(): string
{
return 'Kennung, Titel oder Produktlinie';
}
}
@@ -2,8 +2,13 @@
namespace App\Filament\Resources\Offers\Pages;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\OfferStatus;
use App\Domain\Catalog\OfferVersion;
use App\Domain\Catalog\StatusValue;
use App\Filament\Resources\Offers\OfferResource;
use App\Filament\Support\ListsCatalog;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
@@ -12,6 +17,7 @@
class ListOffers extends ListRecords
{
use ListsCatalog;
use ReportsDomainRules;
protected static string $resource = OfferResource::class;
@@ -24,13 +30,94 @@ public function getSubheading(): string|Htmlable|null
protected function getHeaderActions(): array
{
return [
Action::make('create')->label('Angebot anlegen')->schema([
TextInput::make('name')->label('Name')->required(),
])->action(function (array $data): void {
$this->report(function () use ($data): void {
app(OfferService::class)->create($data['name']);
}, 'Das Angebot ist angelegt.');
}),
Action::make('create')->label('Angebot anlegen')
->modalHeading('Neues Angebot')
->modalDescription('Der Name genügt. Positionen, Vergabe und Preis legst du danach am Angebot fest.')
->modalSubmitActionLabel('Angebot anlegen')
->schema([
TextInput::make('name')->label('Name')->required(),
])->action(function (array $data): void {
$offer = null;
$this->report(function () use ($data, &$offer): void {
$offer = app(OfferService::class)->create($data['name']);
}, 'Das Angebot ist angelegt.');
if ($offer instanceof Offer) {
$this->redirect(OfferResource::getUrl('view', ['record' => $offer]));
}
}),
];
}
protected function catalogRows(): array
{
$rows = [];
foreach (Offer::query()->with(['versions.lines.article', 'versions.lines.bundleVersion.bundle', 'versions.lines.rights.profile'])->orderBy('name')->get() as $offer) {
$versions = $offer->versions->sortByDesc('number');
$active = $versions->first(fn ($version): bool => StatusValue::of($version->status) === OfferStatus::Aktiv->value);
$ended = $versions->filter(fn ($version): bool => StatusValue::of($version->status) === OfferStatus::Beendet->value)->count();
$chips = [];
$zustand = [];
$text = '';
if ($active !== null) {
$chips[] = ['label' => 'Fassung '.$active->number.' aktiv', 'ton' => 'gut'];
$chips[] = ['label' => $this->vergabe($active), 'ton' => 'neutral'];
$zustand[] = 'aktiv';
$text = $active->lines->map(fn ($line): string => ($line->article !== null
? 'Lizenzartikel '.$line->article->code
: 'Paket '.($line->bundleVersion?->bundle?->name ?? '–')).' · '.($line->rights?->profile?->name ?? ''))->implode('; ');
} else {
$chips[] = ['label' => 'Keine aktive Fassung', 'ton' => 'offen'];
$zustand[] = 'ohne';
}
if ($ended > 0) {
$chips[] = ['label' => $ended === 1 ? '1 beendete Fassung' : $ended.' beendete Fassungen', 'ton' => 'leise'];
}
$url = OfferResource::getUrl('view', ['record' => $offer]);
$rows[] = [
'schluessel' => 'o'.$offer->id,
'titel' => $offer->name,
'meta' => 'Angebot',
'text' => $text,
'symbol' => 'etikett',
'url' => $url,
'chips' => $chips,
'zustand' => $zustand,
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
];
}
return $rows;
}
private function vergabe(OfferVersion $version): string
{
$kind = match ($version->grant_kind) {
'kauf' => 'Kauf',
'auf_abruf' => 'Auf Abruf',
'bei_registrierung' => 'Bei Registrierung',
default => (string) $version->grant_kind,
};
return $version->price_cents === null ? $kind : $kind.' · '.number_format($version->price_cents / 100, 2, ',', '.').' €';
}
protected function zustandOptionen(): array
{
return ['alle' => 'Jeder Zustand', 'aktiv' => 'Mit aktiver Fassung', 'ohne' => 'Ohne aktive Fassung'];
}
protected function einheit(): array
{
return ['Angebot', 'Angebote'];
}
protected function leer(): array
{
return ['titel' => 'Noch keine Angebote', 'text' => 'Mit „Angebot anlegen“ oben entsteht das erste Angebot.'];
}
}
@@ -7,9 +7,13 @@
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\Offer;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\OfferStatus;
use App\Domain\Catalog\OfferVersion;
use App\Domain\Catalog\RightsProfileVersion;
use App\Domain\Catalog\StatusValue;
use App\Filament\Resources\Offers\OfferResource;
use App\Filament\Support\CatalogOptions;
use App\Filament\Support\CatalogReading;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\Repeater;
@@ -17,17 +21,75 @@
use Filament\Forms\Components\TextInput;
use Filament\Resources\Pages\ViewRecord;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Components\View;
use Filament\Schemas\Schema;
use Filament\Support\Enums\Width;
use Illuminate\Contracts\Support\Htmlable;
/**
* Angebot im gemeinsamen Rahmen. Anlegen und Ändern nutzen dieselbe Maske (FACH-20): „Fassung aktivieren“ legt die
* nächste, danach unveränderliche Angebotsfassung an; bei einer Änderung ist die Maske mit der aktiven Fassung
* vorbelegt (FACH-08). Die Wirkung bleibt die bestehende von OfferService::activate.
*/
class ViewOffer extends ViewRecord
{
use ReportsDomainRules;
protected static string $resource = OfferResource::class;
public function getTitle(): string|Htmlable
{
return (string) $this->getRecord()->name;
}
public function getHeading(): string|Htmlable
{
return '';
}
public function getMaxContentWidth(): Width|string|null
{
return Width::Full;
}
protected function getHeaderActions(): array
{
return [
Action::make('activate')->label('Fassung aktivieren')->schema([
return [];
}
public function infolist(Schema $schema): Schema
{
return $schema->components([
View::make('filament.catalog.angebot')->viewData(fn (): array => $this->angebotDaten())->columnSpanFull(),
])->columns(1);
}
public function activeVersion(): ?OfferVersion
{
/** @var Offer $offer */
$offer = $this->getRecord();
return $offer->versions()
->where('status', OfferStatus::Aktiv)
->orderByDesc('number')
->with(['lines.article', 'lines.bundleVersion.bundle', 'lines.rights.profile'])
->first();
}
public function activateAction(): Action
{
return Action::make('activate')
->label(fn (): string => $this->activeVersion() !== null ? 'Geänderte Fassung aktivieren' : 'Fassung aktivieren')
->modalHeading(fn (): string => $this->activeVersion() !== null
? 'Angebot ändern: Fassung '.$this->nextNumber().' aktivieren'
: 'Erste Fassung aktivieren')
->modalDescription(fn (): string => ($active = $this->activeVersion()) !== null
? 'Die Maske ist mit Fassung '.$active->number.' vorbelegt. Beim Aktivieren wird Fassung '.$active->number.' beendet und bleibt unverändert gespeichert; neue Erwerbe nutzen Fassung '.$this->nextNumber().'. Bereits begründete Berechtigungen ändern sich dadurch nicht.'
: 'Positionen, Vergabe und Preis bilden die erste Fassung. Nach dem Aktivieren ist sie unveränderlich; Änderungen ergeben eine weitere Fassung.')
->modalSubmitActionLabel(fn (): string => 'Fassung '.$this->nextNumber().' aktivieren')
->modalWidth('4xl')
->fillForm(fn (): array => $this->formFromActive())
->schema([
Select::make('grant_kind')->label('Vergabe')->options([
'kauf' => 'Kauf',
'auf_abruf' => 'Auf Abruf',
@@ -57,9 +119,10 @@ protected function getHeaderActions(): array
Select::make('bundle_version_id')->label('Paketfassung')->options(fn (): array => CatalogOptions::bundleVersions())
->visible(fn (Get $get): bool => $get('kind') === 'bundle'),
Select::make('rights_id')->label('Rechte')->options(fn (): array => CatalogOptions::rights())->required(),
])->minItems(1),
])->action(function (array $data): void {
$this->report(function () use ($data): void {
])->minItems(1)->addActionLabel('Position hinzufügen'),
])
->action(function (array $data): void {
$this->report(function () use ($data): string {
/** @var Offer $offer */
$offer = $this->getRecord();
$lines = [];
@@ -74,16 +137,93 @@ protected function getHeaderActions(): array
];
}
app(OfferService::class)->activate($offer, $lines, [
$version = app(OfferService::class)->activate($offer, $lines, [
'grant_kind' => $data['grant_kind'],
'price_cents' => $data['price_cents'] === null || $data['price_cents'] === '' ? null : (int) $data['price_cents'],
'holder_kind' => 'person',
'composition_version_id' => filled($data['composition_version_id'] ?? null) ? (int) $data['composition_version_id'] : null,
]);
return 'Fassung '.$version->number.' ist aktiv.';
}, 'Die Angebotsfassung ist aktiv.');
$this->getRecord()->unsetRelations();
$this->getRecord()->refresh();
}),
});
}
/**
* Vorbelegung aus der aktiven Fassung; ohne aktive Fassung eine leere Position.
*
* @return array<string, mixed>
*/
private function formFromActive(): array
{
$active = $this->activeVersion();
if ($active === null) {
return ['grant_kind' => 'kauf', 'lines' => [['kind' => 'article']]];
}
return [
'grant_kind' => $active->grant_kind,
'price_cents' => $active->price_cents,
'lines' => $active->lines->sortBy('position')->map(fn ($line): array => [
'kind' => $line->license_article_id !== null ? 'article' : 'bundle',
'article_id' => $line->license_article_id,
'bundle_version_id' => $line->bundle_version_id,
'rights_id' => $line->rights_profile_version_id,
])->values()->all(),
];
}
private function nextNumber(): int
{
return ((int) $this->getRecord()->versions()->max('number')) + 1;
}
/**
* @return array<string, mixed>
*/
private function angebotDaten(): array
{
/** @var Offer $offer */
$offer = $this->getRecord();
$active = $this->activeVersion();
$reading = app(CatalogReading::class);
$versions = $offer->versions()->orderByDesc('number')->get();
return [
'offer' => $offer,
'active' => $active,
'grants' => $active !== null ? $reading->offerGrants($offer) : [],
'versions' => $versions->map(fn (OfferVersion $version): array => [
'number' => $version->number,
'status' => match (StatusValue::of($version->status)) {
'aktiv' => 'Aktiv',
'beendet' => 'Beendet',
default => 'Entwurf',
},
'ton' => match (StatusValue::of($version->status)) {
'aktiv' => 'gut',
'beendet' => 'leise',
default => 'offen',
},
'vergabe' => $this->vergabe($version),
'wann' => $version->activated_at?->format('d.m.Y'),
])->all(),
'vergabe' => $active !== null ? $this->vergabe($active) : null,
];
}
private function vergabe(OfferVersion $version): string
{
$kind = match ($version->grant_kind) {
'kauf' => 'Kauf',
'auf_abruf' => 'Auf Abruf',
'bei_registrierung' => 'Bei Registrierung',
default => (string) $version->grant_kind,
};
return $version->price_cents === null ? $kind : $kind.' · '.number_format($version->price_cents / 100, 2, ',', '.').' €';
}
}
@@ -3,7 +3,9 @@
namespace App\Filament\Resources\RightsProfiles\Pages;
use App\Domain\Catalog\OfferService;
use App\Domain\Catalog\RightsProfile;
use App\Filament\Resources\RightsProfiles\RightsProfileResource;
use App\Filament\Support\ListsCatalog;
use App\Filament\Support\ReportsDomainRules;
use Filament\Actions\Action;
use Filament\Forms\Components\CheckboxList;
@@ -14,8 +16,22 @@
class ListRightsProfiles extends ListRecords
{
use ListsCatalog;
use ReportsDomainRules;
/** Lesbare Fähigkeiten; dieselben Werte wie im Anlegedialog. */
public const FAEHIGKEITEN = [
'film:streamen' => 'Film ansehen',
'film:laden' => 'Film herunterladen',
'audio:streamen' => 'Hörstück ansehen',
'document:ansehen' => 'Dokument ansehen',
'document:laden' => 'Dokument herunterladen',
'pdf:ansehen' => 'PDF ansehen',
'pdf:laden' => 'PDF herunterladen',
'text:ansehen' => 'Text ansehen',
'bild:ansehen' => 'Bild ansehen',
];
protected static string $resource = RightsProfileResource::class;
public function getSubheading(): string|Htmlable|null
@@ -26,36 +42,90 @@ public function getSubheading(): string|Htmlable|null
protected function getHeaderActions(): array
{
return [
Action::make('create')->label('Rechteprofil anlegen')->schema([
TextInput::make('name')->label('Name')->required(),
Select::make('purpose')->label('Zweck')->options([
'ehrenamtlich' => 'Ehrenamtlich',
'kommerziell' => 'Kommerziell',
'institutionell' => 'Institutionell',
])->required(),
CheckboxList::make('capabilities')->label('Fähigkeiten')->options([
'film:streamen' => 'Film ansehen',
'film:laden' => 'Film herunterladen',
'audio:streamen' => 'Hörstück ansehen',
'document:ansehen' => 'Dokument ansehen',
'document:laden' => 'Dokument herunterladen',
'pdf:ansehen' => 'PDF ansehen',
'pdf:laden' => 'PDF herunterladen',
'text:ansehen' => 'Text ansehen',
'bild:ansehen' => 'Bild ansehen',
])->required(),
])->action(function (array $data): void {
$this->report(function () use ($data): void {
$capabilities = [];
Action::make('create')->label('Rechteprofil anlegen')
->modalHeading('Neues Rechteprofil')
->modalDescription('Zweck und erlaubte Handlungen. Ein Angebot verbindet das Profil später mit Artikeln.')
->modalSubmitActionLabel('Rechteprofil anlegen')
->schema([
TextInput::make('name')->label('Name')->required(),
Select::make('purpose')->label('Zweck')->options([
'ehrenamtlich' => 'Ehrenamtlich',
'kommerziell' => 'Kommerziell',
'institutionell' => 'Institutionell',
])->required(),
CheckboxList::make('capabilities')->label('Fähigkeiten')->options(self::FAEHIGKEITEN)->required(),
])->action(function (array $data): void {
$this->report(function () use ($data): void {
$capabilities = [];
foreach ($data['capabilities'] as $entry) {
[$class, $action] = explode(':', $entry, 2);
$capabilities[$class][] = $action;
}
foreach ($data['capabilities'] as $entry) {
[$class, $action] = explode(':', $entry, 2);
$capabilities[$class][] = $action;
}
app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities);
}, 'Das Rechteprofil ist angelegt.');
}),
app(OfferService::class)->createRightsProfile($data['name'], $data['purpose'], $capabilities);
}, 'Das Rechteprofil ist angelegt.');
}),
];
}
protected function catalogRows(): array
{
$rows = [];
foreach (RightsProfile::query()->with('versions')->orderBy('name')->get() as $profile) {
$version = $profile->versions->sortByDesc('number')->first();
$faehigkeiten = [];
foreach ($version?->capabilities ?? [] as $class => $actions) {
foreach ((array) $actions as $action) {
$faehigkeiten[] = self::FAEHIGKEITEN[$class.':'.$action] ?? $class.': '.$action;
}
}
$purpose = match ((string) $version?->purpose) {
'ehrenamtlich' => 'Ehrenamtlich',
'kommerziell' => 'Kommerziell',
'institutionell' => 'Institutionell',
default => (string) $version?->purpose,
};
$chips = $version === null
? [['label' => 'Noch keine Fassung', 'ton' => 'offen']]
: [['label' => 'Fassung '.$version->number, 'ton' => 'neutral'], ['label' => $purpose, 'ton' => 'leise']];
if ($version?->locked_at !== null) {
$chips[] = ['label' => 'Festgeschrieben', 'ton' => 'leise'];
}
$url = RightsProfileResource::getUrl('view', ['record' => $profile]);
$rows[] = [
'schluessel' => 'r'.$profile->id,
'titel' => $profile->name,
'meta' => 'Rechteprofil',
'text' => $faehigkeiten === [] ? 'Keine Fähigkeiten' : implode(', ', $faehigkeiten),
'symbol' => 'schluessel',
'url' => $url,
'chips' => $chips,
'zustand' => [(string) $version?->purpose],
'aktionen' => [['label' => 'Öffnen', 'href' => $url]],
];
}
return $rows;
}
protected function zustandOptionen(): array
{
return ['alle' => 'Jeder Zweck', 'ehrenamtlich' => 'Ehrenamtlich', 'kommerziell' => 'Kommerziell', 'institutionell' => 'Institutionell'];
}
protected function einheit(): array
{
return ['Rechteprofil', 'Rechteprofile'];
}
protected function leer(): array
{
return ['titel' => 'Noch keine Rechteprofile', 'text' => 'Mit „Rechteprofil anlegen“ oben entsteht das erste Profil.'];
}
}
+90
View File
@@ -0,0 +1,90 @@
<?php
namespace App\Filament\Support;
use Filament\Schemas\Components\View;
use Filament\Schemas\Schema;
use Filament\Support\Enums\Width;
use Livewire\Attributes\Url;
/**
* Kataloglisten (Lizenzartikel, Pakete, Rechteprofile, Angebote) in der gemeinsamen Bestandsliste. Die Seite liefert
* Zeilen mit 'suchtext' und 'zustand' (Liste von Zustandsschlüsseln) sowie die Zustandsoptionen.
*/
trait ListsCatalog
{
use ShowsBestand;
#[Url(as: 'suche', except: '')]
public string $suche = '';
#[Url(as: 'zustand', except: 'alle')]
public string $zustand = 'alle';
/**
* @return list<array<string, mixed>>
*/
abstract protected function catalogRows(): array;
/**
* @return array<string, string> Zustandsschlüssel => Bezeichnung, beginnend mit 'alle'
*/
abstract protected function zustandOptionen(): array;
/**
* @return array{0: string, 1: string}
*/
abstract protected function einheit(): array;
/**
* @return array{titel: string, text: string}
*/
abstract protected function leer(): array;
protected function suchPlatzhalter(): string
{
return 'Name oder Beschreibung';
}
public function getMaxContentWidth(): Width|string|null
{
return Width::Full;
}
public function content(Schema $schema): Schema
{
return $schema->components([View::make('filament.verwaltung.bestand')]);
}
public function resetFilters(): void
{
$this->suche = '';
$this->zustand = 'alle';
$this->bestandGrenze = Bestand::SCHRITT;
}
/**
* @return array<string, mixed>
*/
public function bestand(): array
{
$needle = mb_strtolower(trim($this->suche));
$rows = array_values(array_filter($this->catalogRows(), function (array $row) use ($needle): bool {
if ($this->zustand !== 'alle' && ! in_array($this->zustand, $row['zustand'] ?? [], true)) {
return false;
}
return $needle === '' || str_contains(mb_strtolower(implode(' ', array_filter([
$row['titel'], $row['meta'] ?? '', $row['text'] ?? '', $row['suchtext'] ?? '',
]))), $needle);
}));
return [
'suche' => ['eigenschaft' => 'suche', 'label' => 'Suche', 'platzhalter' => $this->suchPlatzhalter()],
'filter' => [['eigenschaft' => 'zustand', 'label' => 'Zustand', 'vorgabe' => 'alle', 'optionen' => $this->zustandOptionen()]],
'zeilen' => $rows,
'einheit' => $this->einheit(),
'leer' => $this->leer(),
];
}
}
@@ -0,0 +1,67 @@
{{-- Angebot im gemeinsamen Rahmen: Kopf, aktive Fassung (Positionen, Leistungsumfang), Fassungsverlauf. --}}
@php
$kopfStatus = $active !== null
? ['text' => 'Fassung '.$active->number.' aktiv · '.$vergabe, 'ton' => 'gut']
: ['text' => 'Noch keine aktive Fassung. Ein Angebot ohne aktive Fassung kann niemand erwerben.', 'ton' => 'offen'];
$aktionen = [[
'label' => $active !== null ? 'Geänderte Fassung aktivieren' : 'Fassung aktivieren',
'wire' => "mountAction('activate')",
'art' => 'primary',
]];
@endphp
<div class="vw">
@include('filament.verwaltung.kopf', [
'brot' => [['label' => 'Angebote', 'href' => \App\Filament\Resources\Offers\OfferResource::getUrl('index')], $offer->name],
'titel' => $offer->name,
'typ' => 'Angebot',
'status' => $kopfStatus,
'aktionen' => $aktionen,
])
<div class="vw-medien-raster" style="margin-top: 1.25rem;">
<section class="vw-medien-haupt" aria-labelledby="positionen-titel">
<h2 id="positionen-titel" class="vw-abschnitt-titel">Positionen @if ($active)<span class="vw-rolle-zahl">· Fassung {{ $active->number }}</span>@endif</h2>
@if ($active === null)
<div class="vw-leer">
<strong>Noch keine Positionen</strong>
<p>Mit „Fassung aktivieren“ legst du fest, welche Lizenzartikel oder Paketfassungen mit welchem Rechteprofil angeboten werden, wie vergeben wird und zu welchem Preis.</p>
</div>
@else
<p class="vw-feld-hilfe">Vergabe: {{ $vergabe }}. Diese Fassung ist unveränderlich; eine Änderung aktiviert die nächste Fassung.</p>
<ul class="vw-verwendungsliste">
@foreach ($active->lines->sortBy('position') as $line)
<li>
<strong>{{ $line->article !== null ? 'Lizenzartikel '.$line->article->code : 'Paket '.($line->bundleVersion?->bundle?->name ?? '–').' · Fassung '.($line->bundleVersion?->number ?? '–') }}</strong>
<span class="vw-feld-hilfe">Rechte: {{ $line->rights?->profile?->name ?? '–' }}</span>
</li>
@endforeach
</ul>
<h3 class="vw-abschnitt-titel" style="font-size: 1.05rem; margin-top: 0.75rem;">Aufgelöster Leistungsumfang</h3>
<p class="vw-feld-hilfe">Diese Artikel-Rechte entstehen beim Erwerb dieser Fassung.</p>
<ul class="vw-verwendungsliste">
@foreach ($grants as $grant)
<li><span>{{ $grant }}</span></li>
@endforeach
</ul>
@endif
</section>
<aside class="vw-medien-seite" aria-labelledby="fassungen-titel">
<h2 id="fassungen-titel" class="vw-abschnitt-titel">Fassungen</h2>
@if ($versions === [])
<p class="vw-feld-hilfe">Noch keine Fassung.</p>
@else
<ul class="vw-verwendungsliste">
@foreach ($versions as $version)
<li>
<strong>Fassung {{ $version['number'] }}</strong>
<span @class(['vw-zustand', 'is-'.$version['ton']])>{{ $version['status'] }}</span>
<span class="vw-feld-hilfe">{{ $version['vergabe'] }}@if ($version['wann']) · aktiviert am {{ $version['wann'] }}@endif</span>
</li>
@endforeach
</ul>
@endif
<p class="vw-feld-hilfe">Beendete Fassungen bleiben gespeichert; Erwerbe verweisen auf ihre Fassung. Ob ein Angebot künftig auch als Vorlage für ein weiteres dienen soll, ist fachlich noch offen (OFF-04).</p>
</aside>
</div>
</div>
@@ -1,29 +0,0 @@
@php
$summary = \Illuminate\Support\Str::limit(trim((string) ($card['summary'] ?? '')), 160);
@endphp
<a class="luf-catalog luf-tone-{{ $card['tone'] }}" href="{{ $card['url'] }}">
<span class="luf-figure">
@if (! empty($card['image']))
<img src="{{ $card['image'] }}" alt="">
@else
<svg class="luf-mark" viewBox="0 0 160 90" aria-hidden="true">
<rect x="8" y="12" width="144" height="66" fill="none" stroke="currentColor" stroke-width="3"/>
<path d="M28 58 V32 H52 V58 M68 58 V24 H92 V58 M108 58 V38 H132 V58" fill="none" stroke="currentColor" stroke-width="3"/>
</svg>
<span class="luf-sr">Kein Titelbild</span>
@endif
@if (! empty($card['image_note']))
<span class="luf-figure-note">{{ $card['image_note'] }}</span>
@endif
</span>
<span class="luf-catalog-body">
<span class="luf-kind">{{ $card['kind'] }}</span>
<strong>{{ $card['title'] }}</strong>
<span class="luf-summary">{{ $summary !== '' ? $summary : 'Noch keine Kurzbeschreibung' }}</span>
<span class="luf-chips">
@foreach ($card['chips'] as $chip)
<span class="luf-chip luf-chip-{{ $chip['tone'] }}">{{ $chip['label'] }}</span>
@endforeach
</span>
</span>
</a>
@@ -20,6 +20,8 @@
'audio' => '<path d="M9 18V6l10-2v12"/><circle cx="6.5" cy="18" r="2.5"/><circle cx="16.5" cy="16" r="2.5"/>',
'extern' => '<path d="M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"/>',
'modul' => '<rect x="2.5" y="4.5" width="19" height="15" rx="1.5"/><path d="M6 16v-6h3.5v6M10.5 16V8H14v8M15 16v-4.5h3.5V16"/>',
'schluessel' => '<circle cx="8" cy="14" r="4.5"/><path d="M11.3 10.8L20 2.5M16.5 6l2.5 2.5M14 8.5l2 2"/>',
'etikett' => '<path d="M3 12V4h8l10 10-8 8z"/><circle cx="7.5" cy="8.5" r="1.4"/>',
'filter' => '<path d="M4 5h16l-6.2 7.4V19l-3.6-1.8v-4.8z"/>',
'zuruecksetzen' => '<path d="M4 12a8 8 0 1 0 2.4-5.7L4 8.5M4 4v4.5h4.5"/>',
];
+134
View File
@@ -2,14 +2,25 @@
namespace Tests\Feature;
use App\Domain\Catalog\ArticleService;
use App\Domain\Catalog\BundleService;
use App\Domain\Catalog\Composition;
use App\Domain\Catalog\CompositionKind;
use App\Domain\Catalog\ContentService;
use App\Domain\Catalog\LicenseArticle;
use App\Domain\Catalog\OfferService;
use App\Filament\Pages\EditorialDesk;
use App\Filament\Resources\Bundles\Pages\ListBundles;
use App\Filament\Resources\ContentElements\Pages\ListContentElements;
use App\Filament\Resources\Courses\Pages\ListCourses;
use App\Filament\Resources\Exercises\ExerciseResource;
use App\Filament\Resources\Exercises\Pages\ListExercises;
use App\Filament\Resources\LicenseArticles\LicenseArticleResource;
use App\Filament\Resources\LicenseArticles\Pages\ListLicenseArticles;
use App\Filament\Resources\Offers\OfferResource;
use App\Filament\Resources\Offers\Pages\ListOffers;
use App\Filament\Resources\Offers\Pages\ViewOffer;
use App\Filament\Resources\RightsProfiles\Pages\ListRightsProfiles;
use App\Filament\Support\Bestand;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -140,6 +151,129 @@ public function test_only_editors_reach_the_composition_lists(): void
$this->actingAs($keeper, 'staff')->get(EditorialDesk::getUrl())->assertForbidden();
}
public function test_catalog_lists_show_readable_states_and_filter_them(): void
{
$content = app(ContentService::class);
$articles = app(ArticleService::class);
$offers = app(OfferService::class);
$sheet = $content->publishElementVersion($content->createElement('pdf', 'pdf', 'Merkblatt Alltag'), 'Hinweis');
$released = $articles->create('demo-merkblatt', 'Erprobung');
$articles->publishRelease($released, $sheet, 'Eigenständiges Merkblatt.');
$articles->create('demo-leer', 'Erprobung');
$bundle = app(BundleService::class)->create('Demo Basis');
app(BundleService::class)->publish($bundle, [$released->fresh()]);
$rights = $offers->createRightsProfile('Erprobung lesen', 'ehrenamtlich', ['pdf' => ['ansehen', 'laden']]);
$offer = $offers->create('Kostenloses Merkblatt');
$offers->activate($offer, [['target' => $released->fresh(), 'rights' => $rights]], ['grant_kind' => 'auf_abruf']);
$offers->create('Noch leer');
$keeper = $this->keeper();
Livewire::actingAs($keeper, 'staff')
->test(ListLicenseArticles::class)
->assertSee('demo-merkblatt')
->assertSee('Stand 1 veröffentlicht')
->assertSee('In einem aktiven Angebot')
->assertSee('Noch kein Stand')
->assertSeeHtml('wire:partial="action-modals"')
->set('zustand', 'ohne')
->assertSee('Zustand: Noch ohne Stand')
->assertSee('demo-leer')
->assertDontSee('demo-merkblatt')
->set('suche', 'merkblatt')
->assertSee('Nichts gefunden');
Livewire::actingAs($keeper, 'staff')
->test(ListOffers::class)
->assertSee('Fassung 1 aktiv')
->assertSee('Auf Abruf')
->assertSee('Lizenzartikel demo-merkblatt · Erprobung lesen')
->assertSee('Keine aktive Fassung')
->assertDontSee('>aktiv<', false);
Livewire::actingAs($keeper, 'staff')
->test(ListBundles::class)
->assertSee('Demo Basis')
->assertSee('Fassung 1 veröffentlicht')
->assertSee('1 Bestandteil');
Livewire::actingAs($keeper, 'staff')
->test(ListRightsProfiles::class)
->assertSee('Erprobung lesen')
->assertSee('PDF ansehen, PDF herunterladen')
->assertSee('Ehrenamtlich');
}
public function test_creating_a_catalog_object_opens_it_and_editors_without_the_keeper_role_stay_out(): void
{
$keeper = $this->keeper();
Livewire::actingAs($keeper, 'staff')
->test(ListLicenseArticles::class)
->callAction('create', ['code' => 'neuer-artikel', 'product_line' => 'Erprobung'])
->assertRedirect(LicenseArticleResource::getUrl('view', ['record' => LicenseArticle::query()->where('code', 'neuer-artikel')->firstOrFail()]));
Livewire::actingAs($keeper, 'staff')
->test(ListOffers::class)
->callAction('create', ['name' => 'Neues Angebot'])
->assertRedirectContains('/verwaltung/offers/');
$this->actingAs($this->editor(), 'staff')->get(OfferResource::getUrl('index'))->assertForbidden();
$this->actingAs($this->editor(), 'staff')->get(LicenseArticleResource::getUrl('index'))->assertForbidden();
}
public function test_one_offer_mask_activates_the_first_version_and_is_prefilled_for_a_change(): void
{
$content = app(ContentService::class);
$articles = app(ArticleService::class);
$offers = app(OfferService::class);
$sheet = $content->publishElementVersion($content->createElement('pdf', 'pdf', 'Merkblatt'), 'Hinweis');
$article = $articles->create('demo-merkblatt', 'Erprobung');
$articles->publishRelease($article, $sheet, 'Eigenständig.');
$rights = $offers->createRightsProfile('Lesen', 'ehrenamtlich', ['pdf' => ['ansehen']]);
$offer = $offers->create('Merkblatt kostenlos');
$keeper = $this->keeper();
$component = Livewire::actingAs($keeper, 'staff')
->test(ViewOffer::class, ['record' => $offer->getKey()])
->assertSee('Noch keine aktive Fassung')
->assertSee('Fassung aktivieren')
->mountAction('activate');
$this->assertSame('Erste Fassung aktivieren', $component->instance()->getMountedAction()->getModalHeading());
$component
->fillForm(['grant_kind' => 'auf_abruf', 'lines' => [['kind' => 'article', 'article_id' => $article->id, 'rights_id' => $rights->id]]])
->callMountedAction()
->assertHasNoFormErrors()
->assertSee('Fassung 1 aktiv · Auf Abruf')
->assertSee('Lizenzartikel demo-merkblatt');
$component = Livewire::actingAs($keeper, 'staff')
->test(ViewOffer::class, ['record' => $offer->getKey()])
->assertSee('Geänderte Fassung aktivieren')
->mountAction('activate');
$this->assertSame('Angebot ändern: Fassung 2 aktivieren', $component->instance()->getMountedAction()->getModalHeading());
$data = $component->get('mountedActions.0.data');
$this->assertSame('auf_abruf', $data['grant_kind']);
$this->assertSame((string) $article->id, (string) array_values($data['lines'])[0]['article_id']);
$this->assertSame((string) $rights->id, (string) array_values($data['lines'])[0]['rights_id']);
$component->fillForm(['grant_kind' => 'kauf', 'price_cents' => 500])
->callMountedAction()
->assertHasNoFormErrors()
->assertSee('Fassung 2 aktiv · Kauf · 5,00 €')
->assertSee('Beendet');
$statuses = $offer->versions()->orderBy('number')->pluck('status')->map(fn ($status) => $status instanceof \BackedEnum ? $status->value : $status)->all();
$this->assertSame(['beendet', 'aktiv'], $statuses);
}
private function keeper(): User
{
$keeper = User::factory()->katalogverwalter()->create();
$keeper->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
return $keeper;
}
private function editor(): User
{
$editor = User::factory()->redakteur()->create();