- Gemeinsame Katalog-Objektseite (catalog/objekt): Kopf, Hauptabschnitte, Begleitinformation. Angebot, Paket und Rechteprofil nutzen sie; lesbare Bezeichnungen zentral in CatalogLabels. - Paket: eine Maske für erste und geänderte Fassung, bei einer Änderung mit der neuesten veröffentlichten Fassung vorbelegt; Wirkung unverändert BundleService::publish (frühere Fassungen bleiben veröffentlicht). - Rechteprofil: erlaubte Handlungen lesbar, Verwendung in Angeboten, Fassungen; der doppelte Titel „… ansehen ansehen“ entfällt. - Fachliche Säulen, Fachliche Kombinationen und Benutzer in der gemeinsamen Bestandsliste; Säulen mit Website-Zustand und Medienzahl, Konten mit Status und Rollen. - Gefüllte Filament-Hauptknöpfe überall im Verwaltungsgrün (auch Formularfuß, etwa „Speichern“ der Säule). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
198 lines
8.1 KiB
PHP
198 lines
8.1 KiB
PHP
<?php
|
|
|
|
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\BundleVersion;
|
|
use App\Domain\Catalog\LicenseArticle;
|
|
use App\Domain\Catalog\StatusValue;
|
|
use App\Filament\Resources\Bundles\BundleResource;
|
|
use App\Filament\Support\CatalogOptions;
|
|
use App\Filament\Support\CatalogReading;
|
|
use App\Filament\Support\ReportsDomainRules;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\CheckboxList;
|
|
use Filament\Resources\Pages\ViewRecord;
|
|
use Filament\Schemas\Components\View;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Enums\Width;
|
|
use Illuminate\Contracts\Support\Htmlable;
|
|
|
|
/**
|
|
* Paket in der gemeinsamen Katalog-Objektseite. Erste und geänderte Fassung nutzen dieselbe Maske; eine Änderung
|
|
* ist mit der neuesten veröffentlichten Fassung vorbelegt. Wirkung unverändert BundleService::publish.
|
|
*/
|
|
class ViewBundle extends ViewRecord
|
|
{
|
|
use ReportsDomainRules;
|
|
|
|
protected static string $resource = BundleResource::class;
|
|
|
|
public function getTitle(): string|Htmlable
|
|
{
|
|
return (string) $this->getRecord()->name;
|
|
}
|
|
|
|
public function getHeading(): string|Htmlable
|
|
{
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
public function getBreadcrumbs(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function getMaxContentWidth(): Width|string|null
|
|
{
|
|
return Width::Full;
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public function infolist(Schema $schema): Schema
|
|
{
|
|
return $schema->components([
|
|
View::make('filament.catalog.objekt')->viewData(fn (): array => $this->paketDaten())->columnSpanFull(),
|
|
])->columns(1);
|
|
}
|
|
|
|
public function publishedVersion(): ?BundleVersion
|
|
{
|
|
/** @var Bundle $bundle */
|
|
$bundle = $this->getRecord();
|
|
|
|
return $bundle->versions()
|
|
->where('status', BundleStatus::Veroeffentlicht)
|
|
->orderByDesc('number')
|
|
->with(['items.article', 'items.nestedBundle'])
|
|
->first();
|
|
}
|
|
|
|
public function publishAction(): Action
|
|
{
|
|
return Action::make('publish')
|
|
->label(fn (): string => $this->publishedVersion() !== null ? 'Geänderte Fassung veröffentlichen' : 'Fassung veröffentlichen')
|
|
->modalHeading(fn (): string => $this->publishedVersion() !== null
|
|
? 'Paket ändern: Fassung '.$this->nextNumber().' veröffentlichen'
|
|
: 'Erste Fassung veröffentlichen')
|
|
->modalDescription(fn (): string => ($published = $this->publishedVersion()) !== null
|
|
? 'Die Maske ist mit Fassung '.$published->number.' vorbelegt. Fassung '.$published->number.' bleibt veröffentlicht und unverändert; Angebote verweisen weiter auf die Paketfassung, die sie nennen.'
|
|
: 'Die gewählten Lizenzartikel und Pakete bilden die erste Fassung. Sie ist danach unveränderlich.')
|
|
->modalSubmitActionLabel(fn (): string => 'Fassung '.$this->nextNumber().' veröffentlichen')
|
|
->fillForm(fn (): array => $this->formFromPublished())
|
|
->schema([
|
|
CheckboxList::make('articles')->label('Lizenzartikel')->options(fn (): array => CatalogOptions::articles()),
|
|
CheckboxList::make('bundles')->label('Enthaltene Pakete')
|
|
->options(function (): array {
|
|
$options = CatalogOptions::bundles();
|
|
unset($options[$this->getRecord()->getKey()]);
|
|
|
|
return $options;
|
|
}),
|
|
])
|
|
->action(function (array $data): void {
|
|
$this->report(function () use ($data): string {
|
|
/** @var Bundle $bundle */
|
|
$bundle = $this->getRecord();
|
|
$items = [];
|
|
|
|
foreach ($data['articles'] ?? [] as $id) {
|
|
$items[] = LicenseArticle::query()->findOrFail($id);
|
|
}
|
|
|
|
foreach ($data['bundles'] ?? [] as $id) {
|
|
$items[] = Bundle::query()->findOrFail($id);
|
|
}
|
|
|
|
$version = app(BundleService::class)->publish($bundle, $items);
|
|
|
|
return 'Fassung '.$version->number.' ist veröffentlicht.';
|
|
}, 'Die Paketfassung ist veröffentlicht.');
|
|
$this->getRecord()->unsetRelations();
|
|
$this->getRecord()->refresh();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @return array{articles: list<int>, bundles: list<int>}
|
|
*/
|
|
private function formFromPublished(): array
|
|
{
|
|
$published = $this->publishedVersion();
|
|
|
|
return [
|
|
'articles' => $published?->items->pluck('license_article_id')->filter()->values()->all() ?? [],
|
|
'bundles' => $published?->items->pluck('nested_bundle_id')->filter()->values()->all() ?? [],
|
|
];
|
|
}
|
|
|
|
private function nextNumber(): int
|
|
{
|
|
return ((int) $this->getRecord()->versions()->max('number')) + 1;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private function paketDaten(): array
|
|
{
|
|
/** @var Bundle $bundle */
|
|
$bundle = $this->getRecord();
|
|
$published = $this->publishedVersion();
|
|
$articles = $published !== null ? app(CatalogReading::class)->bundleArticles($bundle) : [];
|
|
|
|
return [
|
|
'kopf' => [
|
|
'brot' => [['label' => 'Pakete', 'href' => BundleResource::getUrl('index')], $bundle->name],
|
|
'titel' => $bundle->name,
|
|
'typ' => 'Paket',
|
|
'status' => $published !== null
|
|
? ['text' => 'Fassung '.$published->number.' veröffentlicht', 'ton' => 'gut']
|
|
: ['text' => 'Noch keine veröffentlichte Fassung. Bestandteile werden mit der Fassung festgeschrieben.', 'ton' => 'offen'],
|
|
'aktionen' => [[
|
|
'label' => $published !== null ? 'Geänderte Fassung veröffentlichen' : 'Fassung veröffentlichen',
|
|
'wire' => "mountAction('publish')",
|
|
'art' => 'primary',
|
|
]],
|
|
],
|
|
'haupt' => [
|
|
[
|
|
'titel' => 'Bestandteile',
|
|
'zusatz' => $published !== null ? 'Fassung '.$published->number : null,
|
|
'hilfe' => 'Was diese Fassung direkt enthält.',
|
|
'zeilen' => $published === null ? [] : $published->items->sortBy('position')->map(fn ($item): array => [
|
|
'text' => $item->article !== null ? 'Lizenzartikel '.$item->article->code : 'Paket '.($item->nestedBundle?->name ?? 'fehlt'),
|
|
])->values()->all(),
|
|
'leer' => ['titel' => 'Noch keine Bestandteile', 'text' => 'Mit „Fassung veröffentlichen“ wählst du Lizenzartikel und andere Pakete.'],
|
|
],
|
|
...($published !== null ? [[
|
|
'titel' => 'Aufgelöste Lizenzartikel',
|
|
'hilfe' => 'Darauf werden beim Erwerb die Berechtigungen vergeben.',
|
|
'zeilen' => array_map(fn (string $code): array => ['text' => $code], $articles),
|
|
]] : []),
|
|
],
|
|
'seite' => [[
|
|
'titel' => 'Fassungen',
|
|
'zeilen' => $bundle->versions()->withCount('items')->orderByDesc('number')->get()->map(fn (BundleVersion $version): array => [
|
|
'text' => 'Fassung '.$version->number,
|
|
'zustand' => StatusValue::of($version->status) === BundleStatus::Veroeffentlicht->value
|
|
? ['label' => 'Veröffentlicht', 'ton' => 'gut']
|
|
: ['label' => 'Entwurf', 'ton' => 'offen'],
|
|
'neben' => $version->items_count === 1 ? '1 Bestandteil' : $version->items_count.' Bestandteile',
|
|
])->all(),
|
|
'leer' => 'Noch keine Fassung.',
|
|
'hilfe' => 'Veröffentlichte Fassungen bleiben unverändert; ein Angebot nennt die Paketfassung, auf die es sich bezieht.',
|
|
]],
|
|
];
|
|
}
|
|
}
|