Zeige im Katalog, wie Inhalte, Pakete und Rechte zusammenhängen.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
fa706e5080
commit
cd79fb99d7
22 files changed
+1066
-200
No files matched your search
@@ -5,18 +5,24 @@
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Filament\Resources\ContentElements\Pages\ListContentElements;
|
||||
use App\Filament\Resources\ContentElements\Pages\ViewContentElement;
|
||||
use App\Filament\Support\CatalogReading;
|
||||
use App\Models\User;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContentElementResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ContentElement::class;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Redaktion';
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
|
||||
protected static ?string $navigationLabel = 'Inhaltselemente';
|
||||
|
||||
@@ -26,6 +32,8 @@ class ContentElementResource extends Resource
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'working_title';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
return self::editor();
|
||||
@@ -38,6 +46,25 @@ public static function editor(): bool
|
||||
return $user instanceof User && $user->hasStaffRole(StaffRole::Redakteur);
|
||||
}
|
||||
|
||||
public static function getViewAuthorizationResponse(Model $record): Response
|
||||
{
|
||||
return self::editor() ? Response::allow() : Response::deny();
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Section::make('Fassungen')->schema([
|
||||
TextEntry::make('versions')->hiddenLabel()->listWithLineBreaks()
|
||||
->state(fn (ContentElement $record): array => app(CatalogReading::class)->elementVersions($record)),
|
||||
]),
|
||||
Section::make('Verwendung')->description('Kompositionen und Lizenzartikel, die auf dieses Material zeigen.')->schema([
|
||||
TextEntry::make('usage')->hiddenLabel()->listWithLineBreaks()
|
||||
->state(fn (ContentElement $record): array => app(CatalogReading::class)->elementUsage($record)),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema;
|
||||
@@ -50,13 +77,14 @@ public static function table(Table $table): Table
|
||||
TextColumn::make('kind')->label('Art'),
|
||||
TextColumn::make('output_class')->label('Ausgabeklasse'),
|
||||
TextColumn::make('versions_count')->counts('versions')->label('Fassungen'),
|
||||
])->recordUrl(null);
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListContentElements::route('/'),
|
||||
'view' => ViewContentElement::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,14 @@
|
||||
|
||||
namespace App\Filament\Resources\ContentElements\Pages;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\CatalogOptions;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class ListContentElements extends ListRecords
|
||||
{
|
||||
@@ -20,6 +17,11 @@ class ListContentElements extends ListRecords
|
||||
|
||||
protected static string $resource = ContentElementResource::class;
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Das Material selbst: Film, Text, PDF. Kompositionen und Lizenzartikel verweisen darauf.';
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
@@ -49,26 +51,6 @@ protected function getHeaderActions(): array
|
||||
app(ContentService::class)->createElement($data['kind'], $data['output_class'], $data['working_title']);
|
||||
}, 'Das Inhaltselement ist angelegt.');
|
||||
}),
|
||||
Action::make('version')
|
||||
->label('Fassung veröffentlichen')
|
||||
->visible(fn (): bool => ContentElementResource::editor())
|
||||
->schema([
|
||||
Select::make('element_id')->label('Element')->options(fn (): array => CatalogOptions::elements())->required(),
|
||||
Textarea::make('body')->label('Text'),
|
||||
FileUpload::make('incoming')->label('Datei')->disk('cms_incoming')->directory('inhalte'),
|
||||
TextInput::make('change_note')->label('Änderungsnotiz'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
$metadata = filled($data['incoming'] ?? null) ? ['incoming' => $data['incoming']] : [];
|
||||
app(ContentService::class)->publishElementVersion(
|
||||
ContentElement::query()->findOrFail($data['element_id']),
|
||||
$data['body'] ?? null,
|
||||
$metadata,
|
||||
$data['change_note'] ?? null,
|
||||
);
|
||||
}, 'Die Fassung ist gespeichert.');
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ContentElements\Pages;
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Catalog\ContentService;
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Support\ReportsDomainRules;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewContentElement extends ViewRecord
|
||||
{
|
||||
use ReportsDomainRules;
|
||||
|
||||
protected static string $resource = ContentElementResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('version')
|
||||
->label('Fassung veröffentlichen')
|
||||
->schema([
|
||||
Textarea::make('body')->label('Text'),
|
||||
FileUpload::make('incoming')->label('Datei')->disk('cms_incoming')->directory('inhalte'),
|
||||
TextInput::make('change_note')->label('Änderungsnotiz'),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
$this->report(function () use ($data): void {
|
||||
/** @var ContentElement $element */
|
||||
$element = $this->getRecord();
|
||||
$metadata = filled($data['incoming'] ?? null) ? ['incoming' => $data['incoming']] : [];
|
||||
app(ContentService::class)->publishElementVersion(
|
||||
$element,
|
||||
$data['body'] ?? null,
|
||||
$metadata,
|
||||
$data['change_note'] ?? null,
|
||||
);
|
||||
}, 'Die Fassung ist gespeichert.');
|
||||
$this->getRecord()->unsetRelations();
|
||||
$this->getRecord()->refresh();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user