Mache Medien, Übungen und Kurse in der Verwaltung bearbeitbar.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
4f2e5a5f3b
commit
3ee9f529ca
33 files changed
+1105
-284
No files matched your search
@@ -4,18 +4,16 @@
|
||||
|
||||
use App\Domain\Catalog\ContentElement;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Filament\Resources\ContentElements\Pages\EditContentElement;
|
||||
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\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ContentElementResource extends Resource
|
||||
@@ -24,11 +22,11 @@ class ContentElementResource extends Resource
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Inhalte';
|
||||
|
||||
protected static ?string $navigationLabel = 'Inhaltselemente';
|
||||
protected static ?string $navigationLabel = 'Medien';
|
||||
|
||||
protected static ?string $modelLabel = 'Inhaltselement';
|
||||
protected static ?string $modelLabel = 'Medium';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'Inhaltselemente';
|
||||
protected static ?string $pluralModelLabel = 'Medien';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'working_title';
|
||||
|
||||
@@ -46,25 +44,11 @@ public static function editor(): bool
|
||||
return $user instanceof User && $user->hasStaffRole(StaffRole::Redakteur);
|
||||
}
|
||||
|
||||
public static function getViewAuthorizationResponse(Model $record): Response
|
||||
public static function getEditAuthorizationResponse(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;
|
||||
@@ -75,16 +59,30 @@ public static function table(Table $table): Table
|
||||
return $table->columns([
|
||||
TextColumn::make('working_title')->label('Arbeitstitel')->searchable(),
|
||||
TextColumn::make('kind')->label('Art'),
|
||||
TextColumn::make('output_class')->label('Ausgabeklasse'),
|
||||
TextColumn::make('versions_count')->counts('versions')->label('Fassungen'),
|
||||
TextColumn::make('stand')->label('Aktuelle Fassung')->state(function (ContentElement $record): string {
|
||||
$version = $record->versions->sortByDesc('number')->first();
|
||||
|
||||
if ($version === null) {
|
||||
return 'noch keine Fassung';
|
||||
}
|
||||
|
||||
$file = is_array($version->metadata) ? ($version->metadata['file'] ?? null) : null;
|
||||
|
||||
return 'Fassung '.$version->number.(is_string($file) && $file !== '' ? ' · mit Datei' : ' · ohne Datei');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()->with('versions');
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListContentElements::route('/'),
|
||||
'view' => ViewContentElement::route('/{record}'),
|
||||
'edit' => EditContentElement::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user