mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2025-12-13 23:56:47 +00:00
🎉 Add venue management and enhance course events functionality
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\City;
|
||||
use App\Models\Course;
|
||||
use App\Models\CourseEvent;
|
||||
use App\Models\Venue;
|
||||
@@ -24,6 +25,11 @@ new class extends Component {
|
||||
#[Validate('required|url|max:255')]
|
||||
public ?string $link = null;
|
||||
|
||||
// New Venue Modal
|
||||
public string $newVenueName = '';
|
||||
public ?int $newVenueCityId = null;
|
||||
public string $newVenueStreet = '';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->country = request()->route('country');
|
||||
@@ -69,10 +75,33 @@ new class extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
public function createVenue(): void
|
||||
{
|
||||
$validated = $this->validate([
|
||||
'newVenueName' => ['required', 'string', 'max:255', 'unique:venues,name'],
|
||||
'newVenueCityId' => ['required', 'exists:cities,id'],
|
||||
'newVenueStreet' => ['required', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$venue = Venue::create([
|
||||
'name' => $validated['newVenueName'],
|
||||
'city_id' => $validated['newVenueCityId'],
|
||||
'street' => $validated['newVenueStreet'],
|
||||
'slug' => str($validated['newVenueName'])->slug(),
|
||||
'created_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
$this->venue_id = $venue->id;
|
||||
$this->reset(['newVenueName', 'newVenueCityId', 'newVenueStreet']);
|
||||
|
||||
\Flux\Flux::modal('add-venue')->close();
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
return [
|
||||
'venues' => Venue::query()->orderBy('name')->get(),
|
||||
'cities' => City::query()->orderBy('name')->get(),
|
||||
];
|
||||
}
|
||||
}; ?>
|
||||
@@ -105,7 +134,14 @@ new class extends Component {
|
||||
</div>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('Veranstaltungsort') }} <span class="text-red-500">*</span></flux:label>
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<flux:label>{{ __('Veranstaltungsort') }} <span class="text-red-500">*</span></flux:label>
|
||||
<flux:modal.trigger name="add-venue">
|
||||
<flux:button class="cursor-pointer" size="xs" variant="ghost" icon="plus">
|
||||
{{ __('Ort hinzufügen') }}
|
||||
</flux:button>
|
||||
</flux:modal.trigger>
|
||||
</div>
|
||||
<flux:select variant="listbox" searchable wire:model="venue_id"
|
||||
placeholder="{{ __('Veranstaltungsort auswählen') }}" required>
|
||||
<x-slot name="search">
|
||||
@@ -159,4 +195,51 @@ new class extends Component {
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Add Venue Modal -->
|
||||
<flux:modal name="add-venue" variant="flyout" wire:key="add-venue-modal">
|
||||
<form wire:submit="createVenue" class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">{{ __('Veranstaltungsort hinzufügen') }}</flux:heading>
|
||||
<flux:text class="mt-2">{{ __('Füge einen neuen Veranstaltungsort zur Datenbank hinzu.') }}</flux:text>
|
||||
</div>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('Name') }} <span class="text-red-500">*</span></flux:label>
|
||||
<flux:input wire:model="newVenueName" placeholder="{{ __('z.B. Bitcoin Zentrum München') }}" required/>
|
||||
<flux:error name="newVenueName"/>
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('Stadt') }} <span class="text-red-500">*</span></flux:label>
|
||||
<flux:select variant="listbox" searchable wire:model="newVenueCityId"
|
||||
placeholder="{{ __('Stadt auswählen') }}">
|
||||
<x-slot name="search">
|
||||
<flux:select.search class="px-4" placeholder="{{ __('Suche passende Stadt...') }}"/>
|
||||
</x-slot>
|
||||
@foreach($cities as $city)
|
||||
<flux:select.option value="{{ $city->id }}">{{ $city->name }} ({{ $city->country->name }})
|
||||
</flux:select.option>
|
||||
@endforeach
|
||||
</flux:select>
|
||||
<flux:error name="newVenueCityId"/>
|
||||
</flux:field>
|
||||
|
||||
<flux:field>
|
||||
<flux:label>{{ __('Straße') }} <span class="text-red-500">*</span></flux:label>
|
||||
<flux:input wire:model="newVenueStreet" placeholder="{{ __('z.B. Hauptstraße 1') }}" required/>
|
||||
<flux:error name="newVenueStreet"/>
|
||||
</flux:field>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<flux:spacer/>
|
||||
|
||||
<flux:modal.close>
|
||||
<flux:button class="cursor-pointer" type="button" variant="ghost">{{ __('Abbrechen') }}</flux:button>
|
||||
</flux:modal.close>
|
||||
|
||||
<flux:button class="cursor-pointer" type="submit" variant="primary">{{ __('Ort erstellen') }}</flux:button>
|
||||
</div>
|
||||
</form>
|
||||
</flux:modal>
|
||||
</div>
|
||||
|
||||
@@ -20,6 +20,7 @@ new class extends Component {
|
||||
'course' => $this->course->load('lecturer'),
|
||||
'events' => $this->course
|
||||
->courseEvents()
|
||||
->with(['venue.city'])
|
||||
->where('from', '>=', now())
|
||||
->orderBy('from', 'asc')
|
||||
->get(),
|
||||
@@ -133,8 +134,22 @@ new class extends Component {
|
||||
<flux:icon.map-pin class="inline w-4 h-4"/>
|
||||
{{ $event->venue->name }}
|
||||
</flux:text>
|
||||
@if($event->venue->street)
|
||||
<flux:text class="text-xs text-zinc-500 dark:text-zinc-500 ml-5">
|
||||
{{ $event->venue->street }}
|
||||
@if($event->venue->city)
|
||||
, {{ $event->venue->city->name }}
|
||||
@endif
|
||||
</flux:text>
|
||||
@endif
|
||||
@endif
|
||||
|
||||
<flux:text class="mt-2 text-sm text-zinc-600 dark:text-zinc-400">
|
||||
<div class="text-xs text-zinc-500 flex items-center gap-2">
|
||||
<span>{{ $event->registrations->count() }} {{ __('Anmeldungen') }}</span>
|
||||
</div>
|
||||
</flux:text>
|
||||
|
||||
<div class="mt-auto pt-4 flex gap-2">
|
||||
<flux:button
|
||||
target="_blank"
|
||||
|
||||
@@ -8,8 +8,6 @@ new class extends Component {
|
||||
use WithPagination;
|
||||
|
||||
public $country = 'de';
|
||||
public $sortBy = 'name';
|
||||
public $sortDirection = 'asc';
|
||||
public $search = '';
|
||||
|
||||
public function mount(): void
|
||||
@@ -17,31 +15,25 @@ new class extends Component {
|
||||
$this->country = request()->route('country');
|
||||
}
|
||||
|
||||
public function sort($column)
|
||||
{
|
||||
if ($this->sortBy === $column) {
|
||||
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc';
|
||||
} else {
|
||||
$this->sortBy = $column;
|
||||
$this->sortDirection = 'asc';
|
||||
}
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
return [
|
||||
'meetups' => Meetup::with(['city.country', 'createdBy'])
|
||||
->withExists([
|
||||
'meetupEvents as has_future_events' => fn($query) => $query->where('start', '>=', now())
|
||||
])
|
||||
->leftJoin('meetup_events', function ($join) {
|
||||
$join->on('meetups.id', '=', 'meetup_events.meetup_id')
|
||||
->where('meetup_events.start', '>=', now());
|
||||
})
|
||||
->selectRaw('meetups.*, MIN(meetup_events.start) as next_event_start')
|
||||
->groupBy('meetups.id')
|
||||
->whereHas('city.country', fn($query) => $query->where('countries.code', $this->country))
|
||||
->when($this->search, fn($query)
|
||||
=> $query->where('name', 'ilike', '%'.$this->search.'%'),
|
||||
)
|
||||
->when($this->sortBy === 'city',
|
||||
fn($query)
|
||||
=> $query
|
||||
->orderBy('cities.name', $this->sortDirection)
|
||||
->join('cities', 'meetups.city_id', '=', 'cities.id'),
|
||||
fn($query) => $query->orderBy($this->sortBy, $this->sortDirection),
|
||||
=> $query->where('meetups.name', 'ilike', '%'.$this->search.'%'),
|
||||
)
|
||||
->orderByDesc('has_future_events')
|
||||
->orderByRaw('next_event_start ASC NULLS LAST')
|
||||
->paginate(15),
|
||||
];
|
||||
}
|
||||
@@ -67,8 +59,7 @@ new class extends Component {
|
||||
|
||||
<flux:table :paginate="$meetups" class="mt-6">
|
||||
<flux:table.columns>
|
||||
<flux:table.column sortable :sorted="$sortBy === 'name'" :direction="$sortDirection"
|
||||
wire:click="sort('name')">{{ __('Name') }}
|
||||
<flux:table.column>{{ __('Name') }}
|
||||
</flux:table.column>
|
||||
<flux:table.column>{{ __('Nächster Termin') }}</flux:table.column>
|
||||
<flux:table.column>{{ __('Links') }}</flux:table.column>
|
||||
|
||||
Reference in New Issue
Block a user