From a6c8fb64352347fe3b579e3c48a700adc23dfec0 Mon Sep 17 00:00:00 2001 From: HolgerHatGarKeineNode Date: Tue, 20 Jan 2026 00:49:28 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Refactor=20project-support=20forms:?= =?UTF-8?q?=20add=20admin-only=20fields,=20improve=20Flux=20form=20compone?= =?UTF-8?q?nts,=20and=20enhance=20layout=20for=20consistency.=20?= =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Remove=20redundant=20NostrAuth=20method?= =?UTF-8?q?s=20and=20streamline=20authorization=20logic.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/ProjectProposal.php | 2 + .../views/components/project-card.blade.php | 6 +- .../association/election/admin.blade.php | 19 - .../association/election/index.blade.php | 22 -- .../association/election/show.blade.php | 22 -- .../association/members/admin.blade.php | 331 ++++++++++++++++-- .../livewire/association/profile.blade.php | 40 +-- .../project-support/form/create.blade.php | 97 +++-- .../project-support/form/edit.blade.php | 116 ++++-- .../project-support/index.blade.php | 15 - .../project-support/show.blade.php | 16 +- 11 files changed, 459 insertions(+), 227 deletions(-) diff --git a/app/Models/ProjectProposal.php b/app/Models/ProjectProposal.php index f21a9e0..4c11e95 100644 --- a/app/Models/ProjectProposal.php +++ b/app/Models/ProjectProposal.php @@ -35,6 +35,8 @@ class ProjectProposal extends Model implements HasMedia protected $casts = [ 'id' => 'integer', 'einundzwanzig_pleb_id' => 'integer', + 'accepted' => 'boolean', + 'sats_paid' => 'integer', ]; protected static function booted() {} diff --git a/resources/views/components/project-card.blade.php b/resources/views/components/project-card.blade.php index 6d47ff8..ad3807e 100644 --- a/resources/views/components/project-card.blade.php +++ b/resources/views/components/project-card.blade.php @@ -113,11 +113,7 @@
@if($project->sats_paid) -
- Wurde mit {{ number_format($project->sats_paid, 0, ',', '.') }} Sats - unterstützt -
+ Wurde mit {{ number_format($project->sats_paid, 0, ',', '.') }} Sats unterstützt @endif
diff --git a/resources/views/livewire/association/election/admin.blade.php b/resources/views/livewire/association/election/admin.blade.php index f04fa26..3d7c2c8 100644 --- a/resources/views/livewire/association/election/admin.blade.php +++ b/resources/views/livewire/association/election/admin.blade.php @@ -47,25 +47,6 @@ new class extends Component { $this->loadBoardVotes(); } - public function handleNostrLoggedOut(): void - { - $this->currentPubkey = null; - $this->currentPleb = null; - } - - public function handleNostrLoggedIn($pubkey): void - { - $this->currentPubkey = $pubkey; - $allowedPubkeys = [ - '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033', - '430169631f2f0682c60cebb4f902d68f0c71c498fd1711fd982f052cf1fd4279', - ]; - if (in_array($this->currentPubkey, $allowedPubkeys, true)) { - $this->isAllowed = true; - } - dd($this->isAllowed); - } - public function handleNewVote(): void { $this->loadEvents(); diff --git a/resources/views/livewire/association/election/index.blade.php b/resources/views/livewire/association/election/index.blade.php index 0894008..56a65f4 100644 --- a/resources/views/livewire/association/election/index.blade.php +++ b/resources/views/livewire/association/election/index.blade.php @@ -37,28 +37,6 @@ new class extends Component { } } - public function handleNostrLoggedOut(): void - { - $this->isAllowed = false; - $this->currentPubkey = null; - $this->currentPleb = null; - } - - public function handleNostrLoggedIn($pubkey): void - { - NostrAuth::login($pubkey); - $this->currentPubkey = $pubkey; - $this->currentPleb = \App\Models\EinundzwanzigPleb::query() - ->where('pubkey', $pubkey)->first(); - $logPubkeys = [ - '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033', - '430169631f2f0682c60cebb4f902d68f0c71c498fd1711fd982f052cf1fd4279', - ]; - if (in_array($this->currentPubkey, $logPubkeys, true)) { - $this->isAllowed = true; - } - } - public function saveElection($index): void { $election = $this->elections[$index]; diff --git a/resources/views/livewire/association/election/show.blade.php b/resources/views/livewire/association/election/show.blade.php index 423515e..f296b5d 100644 --- a/resources/views/livewire/association/election/show.blade.php +++ b/resources/views/livewire/association/election/show.blade.php @@ -210,28 +210,6 @@ new class extends Component { ->toArray(); } - public function handleNostrLoggedIn($pubkey): void - { - NostrAuth::login($pubkey); - $this->currentPubkey = $pubkey; - $this->currentPleb = EinundzwanzigPleb::query()->where('pubkey', $pubkey)->first(); - $logPubkeys = [ - '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033', - '430169631f2f0682c60cebb4f902d68f0c71c498fd1711fd982f052cf1fd4279', - ]; - if (in_array($this->currentPubkey, $logPubkeys, true)) { - $this->showLog = true; - $this->isAllowed = true; - } - } - - public function handleNostrLoggedOut(): void - { - $this->isAllowed = false; - $this->currentPubkey = null; - $this->currentPleb = null; - } - public function handleNewVote(): void { $this->loadEvents(); diff --git a/resources/views/livewire/association/members/admin.blade.php b/resources/views/livewire/association/members/admin.blade.php index 3e00b98..47fa04a 100644 --- a/resources/views/livewire/association/members/admin.blade.php +++ b/resources/views/livewire/association/members/admin.blade.php @@ -1,16 +1,41 @@ plebs = $this->loadPlebs(); + } + protected $listeners = [ 'nostrLoggedOut' => 'handleNostrLoggedOut', 'nostrLoggedIn' => 'handleNostrLoggedIn', @@ -34,43 +59,247 @@ new class extends Component { $this->isAllowed = true; } } + + $this->plebs = $this->loadPlebs(); } - public function handleNostrLoggedOut(): void + private function loadPlebs() { - $this->isAllowed = false; - $this->currentPubkey = null; + $query = EinundzwanzigPleb::query() + ->with([ + 'profile', + 'paymentEvents' => fn ($query) => $query + ->where('year', date('Y')) + ->where('paid', true), + ]); + + if ($this->search) { + $query->where(function ($query) { + $query->whereHas('profile', function ($query) { + $query->where('name', 'ilike', '%'.$this->search.'%'); + })->orWhere('npub', 'like', '%'.$this->search.'%'); + }); + } + + if ($this->showPaidOnly) { + $query->whereHas('paymentEvents', fn ($query) => $query + ->where('year', date('Y')) + ->where('paid', true) + ); + } + + return $query->tap(fn ($query) => $this->sortBy ? $query->orderBy($this->sortBy, $this->sortDirection) : $query) + ->get(); } - public function handleNostrLoggedIn($pubkey): void + public function sort(string $column): void { - NostrAuth::login($pubkey); - $this->currentPubkey = $pubkey; - $this->currentPleb = \App\Models\EinundzwanzigPleb::query() - ->where('pubkey', $pubkey)->first(); - $allowedPubkeys = [ - '0adf67475ccc5ca456fd3022e46f5d526eb0af6284bf85494c0dd7847f3e5033', - '430169631f2f0682c60cebb4f902d68f0c71c498fd1711fd982f052cf1fd4279', - '7acf30cf60b85c62b8f654556cc21e4016df8f5604b3b6892794f88bb80d7a1d', - 'f240be2b684f85cc81566f2081386af81d7427ea86250c8bde6b7a8500c761ba', - '19e358b8011f5f4fc653c565c6d4c2f33f32661f4f90982c9eedc292a8774ec3', - 'acbcec475a1a4f9481939ecfbd1c3d111f5b5a474a39ae039bbc720fdd305bec', - ]; - if (in_array($this->currentPubkey, $allowedPubkeys, true)) { - $this->isAllowed = true; + if ($this->sortBy === $column) { + $this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc'; + } else { + $this->sortBy = $column; + $this->sortDirection = 'asc'; + } + + $this->plebs = $this->loadPlebs(); + } + + public function togglePaidFilter(): void + { + $this->showPaidOnly = !$this->showPaidOnly; + $this->plebs = $this->loadPlebs(); + } + + public function openPaymentModal(int $plebId): void + { + $this->selectedPlebId = $plebId; + Flux::modal('payment-details')->show(); + } + + public function accept($rowId): void + { + $this->confirmAcceptId = $rowId; + Flux::modal('confirm-accept-pleb')->show(); + } + + public function delete($rowId): void + { + $this->confirmDeleteId = $rowId; + Flux::modal('confirm-delete-pleb')->show(); + } + + public function acceptPleb(): void + { + if ($this->confirmAcceptId) { + $pleb = EinundzwanzigPleb::query()->findOrFail($this->confirmAcceptId); + $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->confirmAcceptId = null; + Flux::modal('confirm-accept-pleb')->close(); } } + public function deletePleb(): void + { + if ($this->confirmDeleteId) { + $pleb = EinundzwanzigPleb::query()->findOrFail($this->confirmDeleteId); + $pleb->application_for = null; + $pleb->application_text = null; + $pleb->save(); + + $this->confirmDeleteId = null; + Flux::modal('confirm-delete-pleb')->close(); + } + } + + public function closePaymentModal(): void + { + $this->selectedPlebId = null; + Flux::modal('payment-details')->close(); + } + + #[Computed] + public function selectedPleb(): ?EinundzwanzigPleb + { + return EinundzwanzigPleb::with(['paymentEvents'])->find($this->selectedPlebId); + } }; ?>
@if($isAllowed) -
- +
+ + + {{ $showPaidOnly ? 'Alle anzeigen' : 'Nur Bezahlt' }} +
+ + + + Avatar + + Name + + + Aktueller Status + + Beitrag {{ date('Y') }} + Aktionen + + + + @foreach ($this->plebs as $pleb) + + + + + + +
+ + {{ $pleb->profile?->name ?: $pleb->profile?->display_name ?? '' }} + + + Nostr Profile + +
+
+ + + + {{ $pleb->association_status->label() }} + + + + + @if($pleb->paymentEvents->count() > 0 && $pleb->paymentEvents->first()->paid) + + + {{ number_format($pleb->paymentEvents->first()->amount, 0, ',', '.') }} + + + @else + keine Zahlung vorhanden + @endif + + + +
+ + + @if($pleb->application_for) + + @endif +
+
+
+ @endforeach +
+
@else -
+
Mitglieder können nicht bearbeitet werden

@@ -80,13 +309,68 @@ new class extends Component { @if(!NostrAuth::check()) Bitte melde dich zunächst mit Nostr an. @else - Dein Benutzer-Account ist nicht für diese Funktion autorisiert. Bitte kontaktiere den Vorstand, wenn du Zugriff benötigst. + Dein Benutzer-Account ist nicht für diese Funktion autorisiert. Bitte kontaktiere den Vorstand, + wenn du Zugriff benötigst. @endif

@endif + + + @if($this->selectedPleb) +
+
+ Zahlungsdetails + + {{ $this->selectedPleb->profile?->name ?: $this->selectedPleb->profile?->display_name ?? 'Unbekannt' }} + +
+ + @if($this->selectedPleb->application_text) + + {{ $this->selectedPleb->application_text }} + + @endif + +
+ Bisherige Zahlungen + + @if($this->selectedPleb->paymentEvents->count() > 0) + + + Satoshis + Jahr + Event-ID + + + + @foreach($this->selectedPleb->paymentEvents as $payment) + + {{ $payment->amount }} + {{ $payment->year }} + {{ $payment->event_id }} + + @endforeach + + + @else + + Keine Zahlungen gefunden + + @endif +
+ +
+ + Schließen +
+
+ @endif +
+ +
@@ -105,6 +389,7 @@ new class extends Component {
+
diff --git a/resources/views/livewire/association/profile.blade.php b/resources/views/livewire/association/profile.blade.php index e832be2..46ee296 100644 --- a/resources/views/livewire/association/profile.blade.php +++ b/resources/views/livewire/association/profile.blade.php @@ -73,44 +73,6 @@ new class extends Component { } } - public function handleNostrLoggedIn($pubkey): void - { - NostrAuth::login($pubkey); - - $this->currentPubkey = $pubkey; - $this->currentPleb = EinundzwanzigPleb::query() - ->with([ - 'paymentEvents' => fn($query) => $query->where('year', date('Y')), - ]) - ->where('pubkey', $pubkey)->first(); - $this->email = $this->currentPleb->email; - $this->no = $this->currentPleb->no_email; - $this->showEmail = !$this->no; - if ($this->currentPleb->association_status === AssociationStatus::ACTIVE) { - $this->amountToPay = config('app.env') === 'production' ? 21000 : 1; - } - if ($this->currentPleb->paymentEvents->count() < 1) { - $this->createPaymentEvent(); - $this->currentPleb->load('paymentEvents'); - } - $this->loadEvents(); - $this->listenForPayment(); - } - - public function handleNostrLoggedOut(): void - { - NostrAuth::logout(); - - $this->currentPubkey = null; - $this->currentPleb = null; - $this->yearsPaid = []; - $this->events = []; - $this->payments = []; - $this->qrCode = null; - $this->amountToPay = config('app.env') === 'production' ? 21000 : 1; - $this->currentYearIsPaid = false; - } - public function updatedNo(): void { $this->showEmail = !$this->no; @@ -562,7 +524,7 @@ new class extends Component { Pay {{ $amountToPay }} Sats @else - + Aktuelles Jahr bezahlt diff --git a/resources/views/livewire/association/project-support/form/create.blade.php b/resources/views/livewire/association/project-support/form/create.blade.php index 041b280..5a3e3b9 100644 --- a/resources/views/livewire/association/project-support/form/create.blade.php +++ b/resources/views/livewire/association/project-support/form/create.blade.php @@ -2,21 +2,28 @@ use App\Models\ProjectProposal; use App\Support\NostrAuth; -use Livewire\Component; use Livewire\Attributes\Layout; use Livewire\Attributes\Title; +use Livewire\Component; new #[Layout('layouts.app')] #[Title('Projektförderung anlegen')] -class extends Component { +class extends Component +{ public array $form = [ 'name' => '', 'description' => '', + 'support_in_sats' => '', + 'website' => '', + 'accepted' => false, + 'sats_paid' => 0, ]; public bool $isAllowed = false; + public bool $isAdmin = false; + public function mount(): void { if (NostrAuth::check()) { @@ -26,6 +33,10 @@ class extends Component { if ($currentPleb && $currentPleb->association_status->value > 1 && $currentPleb->paymentEvents()->where('year', date('Y'))->where('paid', true)->exists()) { $this->isAllowed = true; } + + if ($currentPleb && in_array($currentPleb->npub, config('einundzwanzig.config.current_board'), true)) { + $this->isAdmin = true; + } } } @@ -34,19 +45,24 @@ class extends Component { $this->validate([ 'form.name' => 'required|string|max:255', 'form.description' => 'required|string', + 'form.support_in_sats' => 'required|integer|min:0', + 'form.website' => 'required|url|max:255', ]); ProjectProposal::query()->create([ 'name' => $this->form['name'], 'description' => $this->form['description'], - 'support_in_sats' => 0, + 'support_in_sats' => (int) $this->form['support_in_sats'], + 'website' => $this->form['website'], + 'accepted' => $this->form['accepted'], + 'sats_paid' => $this->form['sats_paid'], 'einundzwanzig_pleb_id' => \App\Models\EinundzwanzigPleb::query()->where('pubkey', NostrAuth::pubkey())->first()->id, ]); $this->redirectRoute('association.projectSupport'); } }; - ?> +?>
@if($isAllowed)
@@ -59,47 +75,62 @@ class extends Component {
-
- -
-
-

- Formular -

-
-
+
+ +
+ + + Formular +
Name -
-
- Beschreibung - - + Website + + + + Unterstützung (Sats) + + + + + + + @if($isAdmin) + + Admin Felder +
+ + Akzeptiert + + + + Sats bezahlt + + +
+ @endif + + + Speichern +
- - Speichern - -
-
+ +
- -
-
-

- Information -

-

+ +

+ + Information +

Fülle das Formular aus, um eine neue Projektförderung anzulegen.

-
+
diff --git a/resources/views/livewire/association/project-support/form/edit.blade.php b/resources/views/livewire/association/project-support/form/edit.blade.php index 24a7119..0034bd3 100644 --- a/resources/views/livewire/association/project-support/form/edit.blade.php +++ b/resources/views/livewire/association/project-support/form/edit.blade.php @@ -9,16 +9,23 @@ use Livewire\Component; new #[Layout('layouts.app')] #[Title('Projektförderung bearbeiten')] -class extends Component { +class extends Component +{ public ProjectProposal $project; public array $form = [ 'name' => '', 'description' => '', + 'support_in_sats' => '', + 'website' => '', + 'accepted' => false, + 'sats_paid' => 0, ]; public bool $isAllowed = false; + public bool $isAdmin = false; + public function mount($projectProposal): void { $this->project = ProjectProposal::query()->where('slug', $projectProposal)->firstOrFail(); @@ -38,8 +45,16 @@ class extends Component { $this->form = [ 'name' => $this->project->name, 'description' => $this->project->description, + 'support_in_sats' => (string) $this->project->support_in_sats, + 'website' => $this->project->website ?? '', + 'accepted' => (bool) $this->project->accepted, + 'sats_paid' => $this->project->sats_paid, ]; } + + if ($currentPleb && in_array($currentPleb->npub, config('einundzwanzig.config.current_board'), true)) { + $this->isAdmin = true; + } } } @@ -48,11 +63,17 @@ class extends Component { $this->validate([ 'form.name' => 'required|string|max:255', 'form.description' => 'required|string', + 'form.support_in_sats' => 'required|integer|min:0', + 'form.website' => 'required|url|max:255', ]); $this->project->update([ 'name' => $this->form['name'], 'description' => $this->form['description'], + 'support_in_sats' => (int) $this->form['support_in_sats'], + 'website' => $this->form['website'], + 'accepted' => $this->isAdmin ? (bool) $this->form['accepted'] : $this->project->accepted, + 'sats_paid' => $this->isAdmin ? $this->form['sats_paid'] : $this->project->sats_paid, ]); $this->redirectRoute('association.projectSupport.item', $this->project); @@ -72,47 +93,70 @@ class extends Component {
-
- -
-
-

- Formular -

-
-
- - Name - - - -
-
- - Beschreibung - +
+ +
+ + + Formular +
+
+ + Name + + + +
+
+ + Website + + + +
+
+ + Unterstützung (Sats) + + + +
+
+ - +
+ + @if($isAdmin) + + Admin Felder +
+ + Akzeptiert + + + + Sats bezahlt + + +
+ @endif + + + Speichern +
- - Speichern - -
-
+ +
- -
-
-

- Information -

-

+ +

+ + Information +

Bearbeite die Projektförderung und speichere deine Änderungen.

-
+
diff --git a/resources/views/livewire/association/project-support/index.blade.php b/resources/views/livewire/association/project-support/index.blade.php index 8297e94..8f42584 100644 --- a/resources/views/livewire/association/project-support/index.blade.php +++ b/resources/views/livewire/association/project-support/index.blade.php @@ -64,21 +64,6 @@ new class extends Component { ->get(); } - public function handleNostrLoggedIn($pubkey): void - { - NostrAuth::login($pubkey); - $this->currentPubkey = $pubkey; - $this->currentPleb = EinundzwanzigPleb::query()->where('pubkey', $pubkey)->first(); - $this->isAllowed = true; - } - - public function handleNostrLoggedOut(): void - { - $this->isAllowed = false; - $this->currentPubkey = null; - $this->currentPleb = null; - } - public function confirmDeleteProject($id): void { $this->projectToDelete = ProjectProposal::query()->findOrFail($id); diff --git a/resources/views/livewire/association/project-support/show.blade.php b/resources/views/livewire/association/project-support/show.blade.php index 6f52500..f860639 100644 --- a/resources/views/livewire/association/project-support/show.blade.php +++ b/resources/views/livewire/association/project-support/show.blade.php @@ -21,7 +21,6 @@ new class extends Component { $this->projectProposal = \App\Models\ProjectProposal::query()->where('slug', $projectProposal)->firstOrFail(); if (NostrAuth::check()) { $this->currentPubkey = NostrAuth::pubkey(); - $this->handleNostrLoggedIn($this->currentPubkey); $this->isAllowed = true; } } @@ -45,17 +44,6 @@ new class extends Component { ->get(); } - public function handleNostrLoggedIn($pubkey): void - { - $this->currentPubkey = $pubkey; - $this->currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', $pubkey)->first(); - $this->isAllowed = true; - $this->ownVoteExists = Vote::query() - ->where('project_proposal_id', $this->projectProposal->id) - ->where('einundzwanzig_pleb_id', $this->currentPleb->id) - ->exists(); - } - public function handleApprove(): void { Vote::query()->updateOrCreate([ @@ -95,7 +83,9 @@ new class extends Component {

{{ $projectProposal->name }}

- {!! $projectProposal->description !!} + + {!! $projectProposal->description !!} +