components([ Tabs::make('Tabs') ->tabs([ Tab::make('Überschrift') ->hidden(fn ($record) => $record->name == 'DECKBLATT' ? true : false) ->schema([ Checkbox::make('neue_seite') ->label('Start neuer Seite'), Checkbox::make('ueberschrift_anzeigen') ->label('Überschrift angezeigen'), Textarea::make('name') ->required() ->label('Überschrift in der Inhaltsangabe') ->columnSpan(2), Textarea::make('name2') ->label('Überschrift im Dokument') ->belowContent([ 'Bei abweichender Überschrift im Dokument', ]) ->columnSpan(2), TextInput::make('ordnungszahl') ->label('Kapitel Index') ->placeholder('3.21') ->numeric() ->default(0) ->belowContent([ 'Bei "0" wird der Index im PDF nicht angezeigt', ]) ->columnSpan(1), TextInput::make('seite') ->label('Seitenzahl') ->numeric() ->default(0) ->belowContent([ 'Bei "0" wird die Seitenzahl automatisch generiert', ]) ->columnSpan(1), ]), Tab::make('Textblock') ->schema([ Grid::make() ->columns(6) ->schema([ TextInput::make('konto_textblock_id')->hidden(), RichEditor::make('textblock') ->aboveLabel('Ausgabe Textblock vor Tabelle') ->columnSpan(5) ->extraInputAttributes(['style' => 'min-height: 20rem; max-height: 50vh; overflow-y: auto;']) ->toolbarButtons([ ['bold', 'italic', 'underline', 'strike', 'subscript', 'superscript', 'horizontalRule', 'table'], ])->floatingToolbars([ 'paragraph' => [ 'bold', 'italic', 'underline', 'strike', 'subscript', 'superscript', ], 'heading' => [ 'h1', 'h2', 'h3', ], 'table' => [ 'tableAddColumnBefore', 'tableAddColumnAfter', 'tableDeleteColumn', 'tableAddRowBefore', 'tableAddRowAfter', 'tableDeleteRow', 'tableMergeCells', 'tableSplitCell', 'tableToggleHeaderRow', 'tableDelete', ], ]), Fieldset::make('') ->contained(false) ->schema([ Action::make('sichern') ->iconButton() ->tooltip('Änderungen in der Vorlage speichern') ->icon('phosphor-floppy-disk') ->schema([ TextInput::make('name')->required() ->label('Ändern sie gegebeben Falls den Namen') ->default(function ($record) { return KontoTextblock::where('id', $record['konto_textblock_id'])->pluck('name')->first(); }), ]) ->hidden(function ($record) { return (bool) ! $record['konto_textblock_id']; }) ->action(function (array $mountedActions, array $data) { $record = $mountedActions[0]->getRawData(); KontoTextblock::where('id', $record['konto_textblock_id']) ->update(['name' => $data['name'], 'textblock' => RichContentRenderer::make($record['textblock'])->toHtml()]); }), Action::make('neu') ->iconButton() ->icon('phosphor-file-plus') ->schema([ TextInput::make('name')->required() ->label('Geben sie der Vorlage einen eindeutigen Namen') ->default(function ($record) { return $record['name']; }), ]) ->modalSubmitActionLabel('Sichern') ->tooltip('Neue Vorlage erstellen') ->action(function (array $mountedActions, array $data) { $record = $mountedActions[0]->getRawData(); $block = new KontoTextblock; $block->konto_id = auth()->user()->konto_id; $block->name = $data['name']; $block->textblock = RichContentRenderer::make($record['textblock'])->toHtml(); $block->save(); ProjektInhaltsverzeichnis::where('id', $record['id'])->update(['konto_textblock_id' => $block->id]); }), Action::make('laden') ->iconButton() ->icon('phosphor-article') ->schema([ Select::make('konto_textblock_id') ->hiddenLabel() ->searchable() ->options(KontoTextblock::where('konto_id', auth()->user()->konto_id)->pluck('name', 'id')) ->belowLabel([ 'Bitte eine Vorlage auswählen', ]), ]) ->modalSubmitActionLabel('Einsetzen') ->tooltip('Vorlage laden.') ->action(function (Set $set, array $mountedActions, array $data) { $record = $mountedActions[0]->getRawData(); ProjektInhaltsverzeichnis::where('id', $record['id'])->update(['konto_textblock_id' => $data['konto_textblock_id']]); $set('konto_textblock_id', $data['konto_textblock_id']); $set('textblock', KontoTextblock::where('id', $data['konto_textblock_id'])->pluck('textblock')->first()); }), ])->columns(1), ]), ]), Tab::make('Tabellen') ->schema([ Select::make('tabellen_id')->label('Tabelle') ->aboveLabel('Ausgabe Textblock vor Tabelle') ->prefixIcon('phosphor-table') ->prefixIconColor( fn ($record): string => $record->tabellen_id == 0 ? 'gray' : 'primary' ) ->default(0) ->options(function () { $res = Tabellen::all()->pluck('name', 'id')->toArray(); array_unshift($res, 'Ohne Tabelle'); return $res; }), ]), ])->columnSpanFull(), ]); } public function table(Table $table): Table { return $table ->emptyStateHeading('Kein Inhaltsverzeichnis') ->emptyStateDescription('Generiere ein Inhaltsverzeichnis um zu beginnen.') ->recordTitleAttribute('text') // ->recordClasses(fn ($record) => $record->part == 'gutachten' ? 'border-l border-primary-500' : 'border-l border-success-500') ->columns([ TextColumn::make('ordnungszahl') ->alignCenter() ->width('2rem') ->label('Index') ->getStateUsing(fn ($record): string => $record->ordnungszahl == '0' ? '' : number_format($record->ordnungszahl, 2)) ->extraCellAttributes(function ($record) { if ($record->part == 1) { return ['class' => 'bg-primary-500/10']; } else { return ['class' => 'bg-success-500/10']; } }), IconColumn::make('neue_seite') ->label('Seite') ->tooltip('Start einer neue Seite') ->icon(fn (string $state): string => match ($state) { '1' => 'phosphor-file-plus', default => '' }), IconColumn::make('ueberschrift_anzeigen') ->label('') ->tooltip('Überschrift anzeigen') ->icon(fn (string $state): Heroicon => match ($state) { '1' => Heroicon::OutlinedEye, '0' => Heroicon::OutlinedEyeSlash, }), TextColumn::make('name') ->wrap() ->searchable() ->weight(fn ($record): FontWeight => match ($record->ueberschrift_anzeigen) { 1 => FontWeight::SemiBold, default => FontWeight::Thin, }) ->description(fn ($record): string => $record->textblock_kennung->name ?? ''), TextColumn::make('tabellen.name')->wrap()->label('Tabelle'), IconColumn::make('textblock') ->alignCenter() ->icon('phosphor-article') ->color(fn (string $state): string => match ($state) { '0' => 'gray', default => 'info', }), TextColumn::make('seite') ->alignCenter() ->badge() ->color('info') ->getStateUsing(function ($record) { if ($record->seitenzahl_anzeige) { if ($record->seite > 0) { return (string) $record->seite; } else { return (string) 'auto'; } } }), ]) ->defaultSort('sort', direction: 'asc') ->reorderable('sort') ->headerActions([ Action::make('generate') ->action(fn (CreateProjektInhaltsverzeichnis $createInhaltsverzeichnis) => $createInhaltsverzeichnis->create($this->ownerRecord)) ->requiresConfirmation() ->modalHeading('Inhaltsverzeichnis neu generieren') ->modalDescription('Bestehende Daten werden gelöscht.') ->modalSubmitActionLabel('Ja, neu generieren') ->label('Generieren') ->tooltip('Inhaltsverzeichnis wird neu erstellt.') ->icon('phosphor-gear'), CreateAction::make() ->icon('phosphor-file-plus') ->createAnother(false), ]) ->recordActions([ EditAction::make()->iconButton()->hidden(fn ($record) => (bool) $record->no_edit), DeleteAction::make()->iconButton(), ]) ->toolbarActions([ BulkActionGroup::make([ DeleteBulkAction::make(), ]), ]); } }