From 1b47c2529497d5071e534b9ca0a4ac1bb1f30701 Mon Sep 17 00:00:00 2001 From: MGeurts <5404867+MGeurts@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:57:50 +0100 Subject: [PATCH] Optimized Datasheet Livewire component --- app/Livewire/People/Datasheet.php | 27 +++++++----- .../views/livewire/people/datasheet.blade.php | 42 ++++++++++--------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/app/Livewire/People/Datasheet.php b/app/Livewire/People/Datasheet.php index eafa26d04..d624f81a0 100644 --- a/app/Livewire/People/Datasheet.php +++ b/app/Livewire/People/Datasheet.php @@ -4,32 +4,37 @@ namespace App\Livewire\People; -use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; use Illuminate\View\View; use Livewire\Component; class Datasheet extends Component { - // ------------------------------------------------------------------------------ public $person; public array $images = []; - public Collection $files; + public array $files = []; - // ------------------------------------------------------------------------------ + /** + * Mount the component and load relevant data. + */ public function mount(): void { - $this->images = collect(File::glob(public_path() . '/storage/photos/' . $this->person->team_id . '/' . $this->person->id . '_*.webp')) - ->map(function ($p) { - return substr($p, strrpos($p, '/') + 1); - })->toArray(); - - $this->files = $this->person->getMedia('files'); + // Load image files for the person (webp format), returning only filenames with extensions + $this->images = collect(File::glob(storage_path("app/public/photos/{$this->person->team_id}/{$this->person->id}_*.webp"))) + ->map(fn ($path) => basename($path)) // Extract filename with extension + ->toArray(); + + // Load the media files associated with the person and extract only filenames (including extensions) + $this->files = $this->person->getMedia('files') + ->map(fn ($media) => basename($media->getPath())) // Extract filename with extension from media path + ->toArray(); } - // ------------------------------------------------------------------------------ + /** + * Render the Livewire view. + */ public function render(): View { return view('livewire.people.datasheet'); diff --git a/resources/views/livewire/people/datasheet.blade.php b/resources/views/livewire/people/datasheet.blade.php index 277fb8db5..d56c8f4d1 100644 --- a/resources/views/livewire/people/datasheet.blade.php +++ b/resources/views/livewire/people/datasheet.blade.php @@ -97,11 +97,11 @@ $cemetery = array_filter([$person->getMetadataValue('cemetery_location_name'), $person->getMetadataValue('cemetery_location_address')]); @endphp - @foreach($cemetery as $line) + @foreach ($cemetery as $line) {{ $line }} - @if(!$loop->last) -
+ @if (!$loop->last) +
@endif @endforeach @@ -154,7 +154,7 @@ {{ __('person.father') }} : @if ($person->father) - {{ $person->father->name }} + {{ $person->father->name }} {{ $person->father->birth_year }} @endif @@ -176,8 +176,10 @@ {{ __('person.parents') }} : @if ($person->parents) - {{ $person->parents->person_1->name }} {{ $person->parents->person_1->birth_year }}
- {{ $person->parents->person_2->name }} {{ $person->parents->person_2->birth_year }} + {{ $person->parents->person_1->name }} + {{ $person->parents->person_1->birth_year }}
+ {{ $person->parents->person_2->name }} + {{ $person->parents->person_2->birth_year }} @endif @@ -187,12 +189,12 @@ @if ($person->currentPartner()) {{ $person->currentPartner()->name }} - + {{ $person->currentPartner()->birth_year }} @endif - +   @@ -235,7 +237,7 @@ {{ $couple->date_end ? $couple->date_end->isoFormat('LL') : '??' }} @endif - + @endforeach @@ -258,11 +260,11 @@ {{ $child->name }} - {{ $child->birth_year }} + {{ $child->birth_year }} - + @endforeach - +   @@ -283,12 +285,12 @@ {{ $sibling->name }} - {{ $sibling->birth_year }} + {{ $sibling->birth_year }} {{ $sibling->type }} - + @endforeach - +   @@ -307,15 +309,15 @@   - {{ $file->file_name }} + {{ $file }} - + @endforeach - +   - + {{-- photos --}} @@ -332,7 +334,7 @@ @foreach ($images as $image)
{{ $person->name }} -
+ @endforeach