Loheide-eu-mitarbeiterplatt.../app/Filament/Resources/DashboardTiles/DashboardTileResource.php
Friederich Loheide f1202bea08
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m50s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m34s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m45s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m30s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m9s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m8s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m5s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m5s
Sicherheitsupdate nach Audit (0.29.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 11:34:54 +00:00

105 lines
5.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Filament\Resources\DashboardTiles;
use App\Filament\Clusters\HomepageCluster;
use App\Filament\Components\AudienceSection;
use App\Filament\Components\SafeUpload;
use App\Filament\Resources\DashboardTiles\Pages\ManageDashboardTiles;
use App\Models\DashboardTile;
use BackedEnum;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Get;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
/**
* Eigene Kacheln der Startseite. Reihenfolge und Ein-/Ausblenden unter „Startseite“.
*/
class DashboardTileResource extends Resource
{
protected static ?string $model = DashboardTile::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleGroup;
protected static ?string $cluster = HomepageCluster::class;
protected static ?int $navigationSort = 4;
protected static ?string $modelLabel = 'Eigene Kachel';
protected static ?string $pluralModelLabel = 'Eigene Kacheln';
protected static ?string $slug = 'kacheln';
public static function canAccess(): bool
{
return auth()->user()?->can('appearance.manage') ?? false;
}
public static function form(Schema $schema): Schema
{
$type = fn (string ...$types) => fn (Get $get) => in_array($get('type'), $types, true);
return $schema->columns(2)->components([
TextInput::make('name')->label('Name (nur im Admin)')->required()->maxLength(100),
Select::make('type')->label('Art')->options(DashboardTile::TYPES)->default('image')->required()->live()->native(false),
Select::make('area')->label('Bereich')->options(DashboardTile::AREAS)->default('aside')->required()->native(false)
->helperText('Die Reihenfolge innerhalb des Bereichs legen Sie unter „Startseite“ fest.'),
TextInput::make('title')->label(fn (Get $get) => $get('type') === 'image' ? 'Bildunterschrift (optional)' : 'Überschrift')->maxLength(150),
SafeUpload::apply(FileUpload::make('image_path'))->label('Bild')->image()->disk('uploads')->directory('dashboard')->visibility('public')
->maxSize(8 * 1024)->required($type('image'))->visible($type('image'))->columnSpanFull()
->helperText('Für die Seitenleiste z. B. 800 × 600 Pixel, für „ganz oben“ ein breites Banner (z. B. 2400 × 500).'),
TextInput::make('alt')->label('Alternativtext')->maxLength(200)->visible($type('image'))->helperText('Beschreibt das Bild für Screenreader.'),
RichEditor::make('body')->label('Text')->toolbarButtons([['bold', 'italic', 'link'], ['bulletList', 'orderedList'], ['undo', 'redo']])
->required($type('text', 'notice'))->visible($type('text', 'notice'))->columnSpanFull(),
Select::make('variant')->label('Farbe')->options(DashboardTile::VARIANTS)->default('brand')->visible($type('notice'))->native(false),
TextInput::make('url')->label('Link')->placeholder('https://… oder /seiten/…')->maxLength(2000),
Toggle::make('new_tab')->label('In neuem Tab öffnen')->inline(false),
Section::make('Anzeige')->columnSpanFull()->columns(3)->schema([
Toggle::make('is_active')->label('Aktiv')->default(true)->inline(false),
DateTimePicker::make('starts_at')->label('Ab')->native(false)->seconds(false)->displayFormat('d.m.Y H:i'),
DateTimePicker::make('ends_at')->label('Bis')->native(false)->seconds(false)->displayFormat('d.m.Y H:i')->after('starts_at'),
]),
AudienceSection::make('dashboard_tile', 'Wer die Kachel sieht. Leer lassen = alle.')->columnSpanFull(),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
ImageColumn::make('image_path')->label('')->disk('uploads')->width(64)->height(40),
TextColumn::make('name')->label('Name')->weight('medium')->searchable(),
TextColumn::make('type')->label('Art')->formatStateUsing(fn (string $state) => DashboardTile::TYPES[$state] ?? $state),
TextColumn::make('area')->label('Bereich')->formatStateUsing(fn (string $state) => DashboardTile::AREAS[$state] ?? $state),
IconColumn::make('is_active')->label('Aktiv')->boolean(),
TextColumn::make('ends_at')->label('Bis')->dateTime('d.m.Y H:i')->placeholder('–'),
])
->recordActions([EditAction::make(), DeleteAction::make()])
->emptyStateHeading('Noch keine eigenen Kacheln')
->emptyStateDescription('Zum Beispiel ein verlinktes Bild in der Seitenleiste oder ein Hinweis ganz oben.');
}
public static function getPages(): array
{
return ['index' => ManageDashboardTiles::route('/')];
}
}