diff --git a/app/Filament/Resources/Hunts/RelationManagers/StepsRelationManager.php b/app/Filament/Resources/Hunts/RelationManagers/StepsRelationManager.php index 14d212a..44bcf6d 100644 --- a/app/Filament/Resources/Hunts/RelationManagers/StepsRelationManager.php +++ b/app/Filament/Resources/Hunts/RelationManagers/StepsRelationManager.php @@ -2,11 +2,14 @@ namespace App\Filament\Resources\Hunts\RelationManagers; +use Dotswan\MapPicker\Fields\Map; use Filament\Actions\BulkActionGroup; use Filament\Actions\CreateAction; use Filament\Actions\DeleteAction; use Filament\Actions\DeleteBulkAction; use Filament\Actions\EditAction; +use Filament\Forms\Components\FileUpload; +use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Textarea; use Filament\Forms\Components\TextInput; use Filament\Resources\RelationManagers\RelationManager; @@ -20,6 +23,14 @@ class StepsRelationManager extends RelationManager public function form(Schema $schema): Schema { + $ownerRecord = $this->getOwnerRecord(); + $defaultLocation = ($ownerRecord->latitude !== null && $ownerRecord->longitude !== null) + ? [ + 'lat' => (float) $ownerRecord->latitude, + 'lng' => (float) $ownerRecord->longitude, + ] + : null; + return $schema ->components([ TextInput::make('step_number') @@ -31,14 +42,16 @@ class StepsRelationManager extends RelationManager Textarea::make('description'), Textarea::make('hint_text') ->label('Hint'), - TextInput::make('hint_media_url') - ->url() - ->label('Hint Media URL'), - TextInput::make('latitude') - ->numeric() + FileUpload::make('hint_media_url') + ->label('Hint image') + ->image() + ->disk('public') + ->directory('hunt-steps'), + Hidden::make('latitude') + ->default($defaultLocation['lat'] ?? null) ->required(), - TextInput::make('longitude') - ->numeric() + Hidden::make('longitude') + ->default($defaultLocation['lng'] ?? null) ->required(), TextInput::make('radius_m') ->numeric() @@ -47,6 +60,58 @@ class StepsRelationManager extends RelationManager TextInput::make('xp') ->numeric() ->default(10), + Map::make('location') + ->label('Location') + ->columnSpanFull() + ->default($defaultLocation) + ->defaultLocation( + latitude: $defaultLocation['lat'] ?? 40.4168, + longitude: $defaultLocation['lng'] ?? -3.7038, + ) + ->draggable(true) + ->clickable(true) + ->zoom(15) + ->minZoom(0) + ->maxZoom(28) + ->tilesUrl('https://tile.openstreetmap.org/{z}/{x}/{y}.png') + ->detectRetina(true) + ->showFullscreenControl(false) + ->showZoomControl(true) + ->showMyLocationButton(true) + ->boundaries(true, 49.5, -11, 61, 2) + ->rangeSelectField('radius_m') + ->extraStyles([ + 'border-radius: 10px', + ]) + ->afterStateUpdated(function ($set, ?array $state): void { + if ($state === null) { + return; + } + + $set('latitude', $state['lat']); + $set('longitude', $state['lng']); + }) + ->afterStateHydrated(function (?array $state, $record, $set) use ($defaultLocation): void { + if (($state['lat'] ?? null) !== null && ($state['lng'] ?? null) !== null) { + return; + } + + $latitude = $record?->latitude ?? ($defaultLocation['lat'] ?? null); + $longitude = $record?->longitude ?? ($defaultLocation['lng'] ?? null); + + if ($latitude === null || $longitude === null) { + return; + } + + $location = [ + 'lat' => (float) $latitude, + 'lng' => (float) $longitude, + ]; + + $set('location', $location); + $set('latitude', $location['lat']); + $set('longitude', $location['lng']); + }), ]); } @@ -56,6 +121,9 @@ class StepsRelationManager extends RelationManager ->recordTitleAttribute('title') ->columns([ Tables\Columns\TextColumn::make('step_number')->sortable(), + Tables\Columns\ImageColumn::make('hint_media_url') + ->label('Hint image') + ->disk('public'), Tables\Columns\TextColumn::make('title'), Tables\Columns\TextColumn::make('latitude'), Tables\Columns\TextColumn::make('longitude'), diff --git a/app/Notifications/HuntParticipantJoinedNotification.php b/app/Notifications/HuntParticipantJoinedNotification.php index 585773c..c05cce4 100644 --- a/app/Notifications/HuntParticipantJoinedNotification.php +++ b/app/Notifications/HuntParticipantJoinedNotification.php @@ -30,8 +30,11 @@ class HuntParticipantJoinedNotification extends Notification implements ShouldQu { return (new MailMessage) ->subject('Nouveau participant sur '.$this->hunt->title) - ->greeting('Bonjour '.$notifiable->username) - ->line($this->participant->username.' participe maintenant à votre chasse "'.$this->hunt->title.'".') - ->line('Vous pouvez suivre les participants depuis votre espace organisateur.'); + ->view('mail.hunts.joined-hunt', [ + 'notifiable' => $notifiable, + 'hunt' => $this->hunt, + 'participant' => $this->participant, + 'participantsCount' => $this->hunt->participants()->count(), + ]); } } diff --git a/resources/views/mail/hunts/joined-hunt.blade.php b/resources/views/mail/hunts/joined-hunt.blade.php new file mode 100644 index 0000000..a66801c --- /dev/null +++ b/resources/views/mail/hunts/joined-hunt.blade.php @@ -0,0 +1,70 @@ + + +
+ + +| + + | +