97 lines
3.5 KiB
PHP
97 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Projektes\RelationManagers;
|
|
|
|
use App\Models\TextblockKennung;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\CreateAction;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\RichEditor;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Components\Utilities\Get;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
class ProjektInhaltsverzeichnisRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'projekt_inhaltsverzeichnis';
|
|
|
|
protected static ?string $title = 'Inhaltsverzeichnis';
|
|
|
|
protected static ?string $navigationLabel = 'Inhaltsverzeichnis';
|
|
|
|
protected static ?string $modelLabel = 'Inhaltsverzeichnis';
|
|
|
|
protected static ?string $pluralModelLabel = 'Inhaltsverzeichnis';
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
TextInput::make('ordnungszahl')->numeric(),
|
|
TextInput::make('name'),
|
|
Select::make('textblock_kennung_id')
|
|
->label('Textblock Art')
|
|
->options(function () {
|
|
$relatedOptions = TextblockKennung::all()->pluck('name', 'id')->toArray();
|
|
|
|
return ['0' => 'ohne Textblock'] + $relatedOptions;
|
|
})
|
|
->live(),
|
|
RichEditor::make('textblock')
|
|
->hidden(fn (Get $get): bool => ! $get('textblock_kennung_id'))
|
|
->toolbarButtons([
|
|
['bold', 'italic', 'underline', 'strike', 'subscript', 'superscript'],
|
|
]),
|
|
])->columns(1);
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('text')
|
|
->columns([
|
|
// TextColumn::make('sort'),
|
|
TextColumn::make('ordnungszahl')
|
|
->getStateUsing(fn ($record): string => $record->ordnungszahl == '0' ? '' : number_format($record->ordnungszahl, 2)),
|
|
IconColumn::make('textblock_kennung_id')
|
|
->label('Text')
|
|
->alignCenter()
|
|
->icon('phosphor-article')
|
|
->color(fn (string $state): string => match ($state) {
|
|
'0' => 'gray',
|
|
default => 'info',
|
|
}),
|
|
TextColumn::make('name')
|
|
->description(fn ($record): string => $record->textblock_kennung->name ?? ''),
|
|
TextColumn::make('seite')
|
|
->alignCenter()
|
|
->badge()
|
|
->color('info')
|
|
->getStateUsing(fn ($record): string => $record->seite == '0' ? '...' : $record->seite),
|
|
])
|
|
->reorderable('sort')
|
|
->filters([
|
|
//
|
|
])
|
|
->headerActions([
|
|
CreateAction::make(),
|
|
])
|
|
->recordActions([
|
|
EditAction::make()->iconButton()->color('gray'),
|
|
DeleteAction::make()->iconButton(),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
}
|