striped() ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV), Header::make()->showSearchInput(), Footer::make() ->showPerPage(25) ->showRecordCount(), Detail::make() ->view('components.detail') ->showCollapseIcon() ->params([]), ]; } public function datasource(): Builder { return EinundzwanzigPleb::query() ->with([ 'profile', 'paymentEvents' => fn($query) => $query ->where('year', date('Y')) ->where('paid', true), ]) ->where('association_status', '>', 1) ->orWhereNotNull('application_for'); } public function fields(): PowerGridFields { return PowerGrid::fields() ->add('pubkey') ->add( 'avatar', fn($model, ) => '', ) ->add( 'for', fn($model, ) => $model->application_for ? '
' . AssociationStatus::from( $model->application_for, )->label() . '
' : '', ) ->add( 'payment', fn(EinundzwanzigPleb $model) => $model->paymentEvents->count() > 0 && $model->paymentEvents->first( )->paid ? $model->paymentEvents->first()->amount : 'keine Zahlung vorhanden', ) ->add( 'npub', fn(EinundzwanzigPleb $model) => 'Nostr Profile', ) ->add( 'association_status_formatted', fn(EinundzwanzigPleb $model) => $model->association_status->label(), ) ->add( 'name_lower', fn(EinundzwanzigPleb $model) => strtolower( e($model->profile?->name ?? $model->profile?->display_name ?? ''), ), ); } public function columns(): array { return [ Column::make('Avatar', 'avatar') ->visibleInExport(visible: false), Column::make('Npub', 'npub') ->visibleInExport(visible: false) ->sortable(), Column::make('Name', 'name_lower') ->sortable(), Column::make('Aktueller Status', 'association_status_formatted', 'association_status') ->visibleInExport(visible: true) ->sortable(), Column::make('Beitrag ' . date('Y'), 'payment') ->visibleInExport(visible: true), Column::make('Bewirbt sich für', 'for', 'application_for') ->visibleInExport(visible: false) ->sortable(), Column::action('Action') ->visibleInExport(visible: false), ]; } public function filters(): array { return []; } #[\Livewire\Attributes\On('edit')] public function edit($rowId): void { $pleb = EinundzwanzigPleb::query()->findOrFail($rowId); $for = $pleb->application_for; $text = $pleb->application_text; $pleb->association_status = AssociationStatus::from($for); $pleb->application_for = null; $pleb->archived_application_text = $text; $pleb->application_text = null; $pleb->save(); $this->fillData(); } public function actions(EinundzwanzigPleb $row): array { return [ Button::add('edit') ->slot('Approve') ->id() ->class( 'btn bg-white dark:bg-gray-800 border-gray-200 dark:border-gray-700/60 hover:border-gray-300 dark:hover:border-gray-600 text-green-500', ) ->dispatch('edit', ['rowId' => $row->id]), ]; } public function actionRules(EinundzwanzigPleb $row): array { return [ // Hide button edit for ID 1 Rule::button('edit') ->when(fn($row) => $row->application_for === null) ->hide(), ]; } }