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') ->hidden(fn ($record) => in_array($record?->name, ['INHALTSVERZEICHNIS']) ? true : false) ->schema([ Grid::make() ->columns(6) ->schema([ TextInput::make('konto_textblock_id')->hidden(), RichEditor::make('textblock') ->hiddenLabel() ->aboveLabel(fn ($record): string => $record?->tabellen_id != 0 ? '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') ->hidden(fn ($record) => in_array($record?->name, ['DECKBLATT']) ? true : false) ->schema([ Select::make('tabellen_id')->label('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') ->label('Index') ->alignRight() ->width('2rem') ->label('Index') ->getStateUsing(fn ($record): string => $record->ordnungszahl == '0' ? '' : number_format($record->ordnungszahl, 2)), IconColumn::make('neue_seite') ->tooltip('Start neue Seite') ->alignCenter() ->label('Start') ->color('primary') ->icon(fn (string $state): string => match ($state) { '1' => 'phosphor-file-plus', default => '' }), TextColumn::make('name') ->wrap() ->searchable() ->description(fn ($record): string => $record->textblock_kennung->name ?? ''), IconColumn::make('ueberschrift_anzeigen') ->label('Anzeigen') ->alignCenter() ->tooltip('Überschrift anzeigen') ->color(fn ($state): string => $state ? 'primary' : 'gray') ->icon(fn ($state): string => $state ? 'phosphor-article-ny-times' : ''), IconColumn::make('textblock') ->color('primary') ->alignCenter() ->icon('phosphor-article') ->tooltip(fn ($record): HtmlString => new HtmlString($record->textblock)), IconColumn::make('tabellen') ->label('Tabelle') ->color('primary') ->alignCenter() ->icon('phosphor-table') ->tooltip(fn ($record): HtmlString => new HtmlString($record->name)), TextColumn::make('seite') ->alignCenter() ->badge() ->color(fn ($record): string => $record->seitenzahl_anzeige ? 'primary' : 'gray') ->getStateUsing(function ($record) { if ($record->seitenzahl_anzeige) { return $record->seite == '0' ? 'auto' : $record->seite; } }), ]) ->defaultPaginationPageOption(5) ->persistFiltersInSession() ->deferFilters(false) ->filtersFormColumns(3) ->filters([ SelectFilter::make('part') ->selectablePlaceholder(false) ->default('standard') ->label('Gutachten Komponenten') ->options([ 'standard' => 'Gutachten Standard Texte', 'nutzwerte' => 'Nutzwerberechnung', 'paragraph' => 'Auszug Gutachten gem. §6', ]), ]) ->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(), ]), ]); } }