removed invitelayout resources

This commit is contained in:
Codex Agent
2025-12-12 11:48:31 +01:00
parent 7cf7c4b8df
commit bbf8d4a0f4
17 changed files with 941 additions and 1260 deletions

View File

@@ -1,141 +0,0 @@
<?php
namespace App\Filament\Resources\InviteLayouts;
use App\Filament\Resources\InviteLayouts\Pages\CreateInviteLayout;
use App\Filament\Resources\InviteLayouts\Pages\EditInviteLayout;
use App\Filament\Resources\InviteLayouts\Pages\ListInviteLayouts;
use App\Filament\Resources\InviteLayouts\Schemas\InviteLayoutForm;
use App\Filament\Resources\InviteLayouts\Tables\InviteLayoutsTable;
use App\Models\InviteLayout;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use UnitEnum;
class InviteLayoutResource extends Resource
{
protected static ?string $model = InviteLayout::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
protected static string|UnitEnum|null $navigationGroup = null;
protected static ?int $navigationSort = 8;
public static function getNavigationLabel(): string
{
return __('admin.nav.invite_layouts') ?? 'Layout-Vorlagen';
}
public static function getNavigationGroup(): UnitEnum|string|null
{
return __('admin.nav.branding') ?? 'Branding & Assets';
}
public static function form(Schema $schema): Schema
{
return InviteLayoutForm::configure($schema);
}
public static function table(Table $table): Table
{
return InviteLayoutsTable::configure($table);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListInviteLayouts::route('/'),
'create' => CreateInviteLayout::route('/create'),
'edit' => EditInviteLayout::route('/{record}/edit'),
];
}
public static function normalizePayload(array $data): array
{
$data['slug'] = Str::slug($data['slug'] ?? $data['name'] ?? 'layout');
$preview = $data['preview'] ?? [];
$qrSize = Arr::get($preview, 'qr.size_px', Arr::get($preview, 'qr_size_px'));
$svgWidth = Arr::get($preview, 'svg.width', Arr::get($preview, 'svg_width'));
$svgHeight = Arr::get($preview, 'svg.height', Arr::get($preview, 'svg_height'));
$data['preview'] = array_filter([
'background' => $preview['background'] ?? null,
'background_gradient' => $preview['background_gradient'] ?? null,
'accent' => $preview['accent'] ?? null,
'secondary' => $preview['secondary'] ?? null,
'text' => $preview['text'] ?? null,
'badge' => $preview['badge'] ?? null,
'qr' => array_filter([
'size_px' => $qrSize !== null ? (int) $qrSize : null,
]),
'svg' => array_filter([
'width' => $svgWidth !== null ? (int) $svgWidth : null,
'height' => $svgHeight !== null ? (int) $svgHeight : null,
]),
], fn ($value) => $value !== null && (! is_array($value) || ! empty($value)));
if (empty($data['preview']['qr'])) {
unset($data['preview']['qr']);
}
if (empty($data['preview']['svg'])) {
unset($data['preview']['svg']);
}
$layoutOptions = $data['layout_options'] ?? [];
$formats = $layoutOptions['formats'] ?? ['pdf', 'png'];
if (is_string($formats)) {
$formats = array_values(array_filter(array_map('trim', explode(',', $formats))));
}
$normalizedFormats = [];
foreach ($formats ?: ['pdf', 'png'] as $format) {
$value = strtolower((string) $format);
if ($value === 'svg') {
$value = 'png';
}
if (in_array($value, ['pdf', 'png'], true) && ! in_array($value, $normalizedFormats, true)) {
$normalizedFormats[] = $value;
}
}
$layoutOptions['formats'] = $normalizedFormats ?: ['pdf', 'png'];
$data['layout_options'] = array_filter([
'badge_label' => $layoutOptions['badge_label'] ?? null,
'instructions_heading' => $layoutOptions['instructions_heading'] ?? null,
'link_heading' => $layoutOptions['link_heading'] ?? null,
'cta_label' => $layoutOptions['cta_label'] ?? null,
'cta_caption' => $layoutOptions['cta_caption'] ?? null,
'link_label' => $layoutOptions['link_label'] ?? null,
'logo_url' => $layoutOptions['logo_url'] ?? null,
'formats' => $layoutOptions['formats'],
], fn ($value) => $value !== null && $value !== []);
if (empty($data['layout_options']['logo_url'])) {
unset($data['layout_options']['logo_url']);
}
$instructions = $data['instructions'] ?? [];
if (is_array($instructions) && isset($instructions[0]) && is_array($instructions[0]) && array_key_exists('value', $instructions[0])) {
$instructions = array_map(fn ($item) => $item['value'] ?? null, $instructions);
}
$data['instructions'] = array_values(array_filter(array_map(fn ($value) => is_string($value) ? trim($value) : null, $instructions)));
return $data;
}
}

View File

@@ -1,20 +0,0 @@
<?php
namespace App\Filament\Resources\InviteLayouts\Pages;
use App\Filament\Resources\InviteLayouts\InviteLayoutResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Auth;
class CreateInviteLayout extends CreateRecord
{
protected static string $resource = InviteLayoutResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
$data = InviteLayoutResource::normalizePayload($data);
$data['created_by'] = Auth::id();
return $data;
}
}

View File

@@ -1,24 +0,0 @@
<?php
namespace App\Filament\Resources\InviteLayouts\Pages;
use App\Filament\Resources\InviteLayouts\InviteLayoutResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;
class EditInviteLayout extends EditRecord
{
protected static string $resource = InviteLayoutResource::class;
protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
protected function mutateFormDataBeforeSave(array $data): array
{
return InviteLayoutResource::normalizePayload($data);
}
}

View File

@@ -1,19 +0,0 @@
<?php
namespace App\Filament\Resources\InviteLayouts\Pages;
use App\Filament\Resources\InviteLayouts\InviteLayoutResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListInviteLayouts extends ListRecords
{
protected static string $resource = InviteLayoutResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View File

@@ -1,158 +0,0 @@
<?php
namespace App\Filament\Resources\InviteLayouts\Schemas;
use Filament\Forms\Components\ColorPicker;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Schema;
use Filament\Schemas\Components\Section;
use Illuminate\Support\Str;
class InviteLayoutForm
{
public static function configure(Schema $schema): Schema
{
return $schema->schema([
Section::make('Grunddaten')
->columns(2)
->schema([
TextInput::make('name')
->label('Name')
->required()
->maxLength(255)
->afterStateUpdated(fn (callable $set, $state) => $set('slug', Str::slug((string) $state ?? '')))
->reactive(),
TextInput::make('slug')
->label('Slug')
->required()
->maxLength(191)
->unique(ignoreRecord: true),
TextInput::make('subtitle')
->label('Unterzeile')
->maxLength(255)
->columnSpanFull(),
Textarea::make('description')
->label('Beschreibung')
->rows(4)
->columnSpanFull(),
Toggle::make('is_active')
->label('Aktiv')
->default(true),
]),
Section::make('Papier & Format')
->columns(3)
->schema([
Select::make('paper')
->label('Papierformat')
->options([
'a4' => 'A4 (210 × 297 mm)',
'a5' => 'A5 (148 × 210 mm)',
'a3' => 'A3 (297 × 420 mm)',
'custom' => 'Benutzerdefiniert',
])
->default('a4'),
Select::make('orientation')
->label('Ausrichtung')
->options([
'portrait' => 'Hochformat',
'landscape' => 'Querformat',
])
->default('portrait'),
TextInput::make('layout_options.formats')
->label('Formate (Komma getrennt)')
->default('pdf,svg')
->helperText('Bestimmt, welche Downloads angeboten werden.')
->dehydrateStateUsing(fn ($state) => collect(explode(',', (string) $state))
->map(fn ($value) => trim((string) $value))
->filter()
->values()
->all())
->afterStateHydrated(function (TextInput $component, $state) {
if (is_array($state)) {
$component->state(implode(',', $state));
}
}),
]),
Section::make('Farben')
->columns(5)
->schema([
ColorPicker::make('preview.background')
->label('Hintergrund')
->default('#F9FAFB'),
ColorPicker::make('preview.accent')
->label('Akzent')
->default('#6366F1'),
ColorPicker::make('preview.text')
->label('Text')
->default('#0F172A'),
ColorPicker::make('preview.secondary')
->label('Sekundär')
->default('#CBD5F5'),
ColorPicker::make('preview.badge')
->label('Badge')
->default('#2563EB'),
TextInput::make('preview.qr.size_px')
->label('QR-Größe (px)')
->numeric()
->default(320)
->columnSpan(2),
TextInput::make('preview.svg.width')
->label('SVG Breite')
->numeric()
->default(1080),
TextInput::make('preview.svg.height')
->label('SVG Höhe')
->numeric()
->default(1520),
]),
Section::make('Texte & Hinweise')
->columns(2)
->schema([
TextInput::make('layout_options.badge_label')
->label('Badge-Label')
->default('Digitale Gästebox'),
TextInput::make('layout_options.instructions_heading')
->label('Anleitungstitel')
->default("So funktioniert's"),
TextInput::make('layout_options.link_heading')
->label('Link-Titel')
->default('Alternative zum Einscannen'),
TextInput::make('layout_options.cta_label')
->label('CTA Label')
->default('Scan mich & starte direkt'),
TextInput::make('layout_options.cta_caption')
->label('CTA Untertitel')
->default('Scan mich & starte direkt'),
TextInput::make('layout_options.link_label')
->label('Link Text (optional)')
->helperText('Überschreibt den standardmäßigen Einladungslink.'),
TextInput::make('layout_options.logo_url')
->label('Logo URL')
->columnSpanFull(),
Repeater::make('instructions')
->label('Hinweise')
->maxItems(6)
->schema([
Textarea::make('value')
->label('Hinweistext')
->rows(2)
->required()
->maxLength(180),
])
->afterStateHydrated(function (Repeater $component, $state): void {
if (is_array($state) && ! empty($state) && ! is_array(current($state))) {
$component->state(array_map(fn ($value) => ['value' => $value], $state));
}
})
->dehydrateStateUsing(fn ($state) => collect($state)->pluck('value')->filter()->values()->all()),
]),
]);
}
}

View File

@@ -1,73 +0,0 @@
<?php
namespace App\Filament\Resources\InviteLayouts\Tables;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\BadgeColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
class InviteLayoutsTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label('Name')
->searchable()
->sortable(),
TextColumn::make('slug')
->label('Slug')
->copyable()
->searchable()
->sortable(),
TextColumn::make('paper')
->label('Papier')
->sortable(),
TextColumn::make('orientation')
->label('Ausrichtung')
->sortable(),
BadgeColumn::make('is_active')
->label('Status')
->colors([
'success' => fn ($state) => $state === true,
'gray' => fn ($state) => $state === false,
])
->getStateUsing(fn ($record) => $record->is_active)
->formatStateUsing(fn ($state) => $state ? 'Aktiv' : 'Inaktiv'),
TextColumn::make('updated_at')
->label('Aktualisiert')
->dateTime('d.m.Y H:i')
->sortable(),
])
->filters([
SelectFilter::make('is_active')
->label('Status')
->options([
'1' => 'Aktiv',
'0' => 'Inaktiv',
])
->query(function ($query, $state) {
if ($state === '1') {
$query->where('is_active', true);
} elseif ($state === '0') {
$query->where('is_active', false);
}
}),
])
->recordActions([
EditAction::make(),
DeleteAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}