From ac326c0a49851d6c914d1a026dd0b2b219b943cb Mon Sep 17 00:00:00 2001 From: majid Date: Thu, 6 Feb 2025 14:48:45 +0700 Subject: [PATCH] fix view foto jaminan --- app/Http/Controllers/PenilaiController.php | 4 +- .../penilai/components/foto-jaminan.blade.php | 275 +++++++------ .../components/foto-lampiran.blade.php | 377 +++++------------- resources/views/surveyor/components/data.json | 5 +- .../views/surveyor/components/foto.blade.php | 61 +-- 5 files changed, 276 insertions(+), 446 deletions(-) diff --git a/app/Http/Controllers/PenilaiController.php b/app/Http/Controllers/PenilaiController.php index fb8409d..bf8cbc9 100644 --- a/app/Http/Controllers/PenilaiController.php +++ b/app/Http/Controllers/PenilaiController.php @@ -52,7 +52,7 @@ class PenilaiController extends Controller $permohonanId = $request->query('permohonanId'); $documentId = $request->query('documentId'); $jaminanId = $request->query('jaminanId'); - + $basicData = $this->surveyorController->getCommonData(); $permohonan = $this->surveyorController->getPermohonanJaminanId($permohonanId, $documentId, $jaminanId); $inpeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first(); @@ -62,7 +62,7 @@ class PenilaiController extends Controller $forminspeksi = json_decode($inpeksi->data_form, true); } - return view('lpj::penilai.lampiran', compact('permohonan', 'formFoto', 'forminspeksi')); + return view('lpj::penilai.lampiran', compact('permohonan', 'formFoto', 'forminspeksi','basicData')); } public function create() diff --git a/resources/views/penilai/components/foto-jaminan.blade.php b/resources/views/penilai/components/foto-jaminan.blade.php index 1f29d95..c600d1b 100644 --- a/resources/views/penilai/components/foto-jaminan.blade.php +++ b/resources/views/penilai/components/foto-jaminan.blade.php @@ -1,142 +1,169 @@ -
- @php - $photoSections = [ - 'rute_menuju_lokasi' => [ - 'key' => 'rute_menuju_lokasi', - 'name_prefix' => '', - 'nested' => true, - ], - 'foto_rute_lainnya' => [ - 'key' => 'name_rute_lainnya', - 'name_prefix' => '', - 'nested' => false, - ], - 'foto_lingkungan' => [ - 'key' => 'foto_lingkungan', - 'name_prefix' => '', - 'nested' => true, - ], - 'single_photos' => [ - 'foto_basement' => 'Basement', - 'foto_gerbang' => 'Gerbang', - 'pendamping' => 'Pendamping', - ], - 'object_jaminan' => [ - 'key' => 'name_objek', - 'name_prefix' => '', - 'nested' => false, - ], - 'foto_lantai_unit' => [ - 'key' => 'name', - 'name_prefix' => 'Foto Lantai', - 'nested' => true, - ], - ]; + + +@isset($basicData['foto']) + @php + $photos = $formFoto['upload_foto'] ?? []; + if (!is_array($photos)) { + $photos = []; + } + $groupedPhotos = collect($photos)->groupBy('category'); + + $mainPhotos = $groupedPhotos->filter(fn($_, $key) => $key !== 'Lainnya'); + $otherPhotos = $groupedPhotos->get('Lainnya', collect()); @endphp - + @if ($groupedPhotos->isEmpty()) +

Tidak ada foto yang tersedia.

+ @else +
+ @foreach ($mainPhotos as $category => $photos) +

{{ $category }}

- @foreach ($photoSections as $sectionKey => $sectionConfig) - @if ($sectionKey === 'single_photos') -
- @foreach ($sectionConfig as $photoKey => $photoName) - @if (isset($formFoto[$photoKey]) && !empty($formFoto[$photoKey])) - @php - $imagePath = storage_path('app/public/' . $formFoto[$photoKey]); - $hasPhotos = true; - @endphp -
-

- {{ $photoName }} -

- @if ($statusLpj || file_exists($imagePath)) - {{ $photoName }} - @endif -
- @endif - @endforeach -
- @else - @php - $sectionData = $formFoto[$sectionKey] ?? null; - @endphp + @php + $groupedBySubcategory = $photos->groupBy('sub'); + @endphp - @if (!empty($sectionData)) - @if ($sectionConfig['nested']) - @if (isset($sectionData[$sectionConfig['key']][0])) -
- @foreach ($sectionData[$sectionConfig['key']][0] as $index => $item) + @if ($groupedBySubcategory->isEmpty()) +

Tidak ada subkategori yang tersedia.

+ @else + @foreach ($groupedBySubcategory as $subcategory => $subPhotos) +

+ {{ $subcategory ?: '' }} +

+ +
+ @foreach ($subPhotos as $index => $item) @php $imagePath = storage_path('app/public/' . $item['path']); - $hasPhotos = true; @endphp
-

- {{ $sectionConfig['name_prefix'] - ? $sectionConfig['name_prefix'] . ' ' . ($index + 1) - : $item['name'] ?? 'Foto ' . ($index + 1) }} -

+

{{ $item['name'] }}

@if ($statusLpj || file_exists($imagePath)) {{ $item['path'] }} + @else +

Foto tidak ditemukan.

@endif
- @endforeach + + @if (($index + 1) % 2 == 0 && !$loop->last)
+
@endif - @else -
- @foreach ($sectionData as $index => $item) - @php - $name = $item[$sectionConfig['key']] ?? ''; - $photoPath = - $sectionKey === 'object_jaminan' - ? $item['foto_objek'] ?? '' - : $item['foto_rute_lainnya'] ?? ''; - - $imagePath = storage_path('app/public/' . $photoPath); - @endphp - - @if (!empty($name) || !empty($photoPath)) - @php $hasPhotos = true; @endphp -
- @if (!empty($name)) -

- {{ $name }} -

- @endif - @if ($statusLpj || (file_exists($imagePath) && !empty($photoPath))) - {{ $name ?: 'Foto' }} - @endif -
- @endif - @endforeach -
- @endif - @endif - @endif + @endforeach +
+ @endforeach + @endif @endforeach - @if (!$hasPhotos) -
-

Tidak ada foto yang tersedia

-
- @endif + @if (!$otherPhotos->isEmpty()) +

Lainnya

+ + @php + $groupedBySubcategory = $otherPhotos->groupBy('sub'); + @endphp + + @if ($groupedBySubcategory->isEmpty()) +

Tidak ada subkategori yang tersedia.

+ @else + @foreach ($groupedBySubcategory as $subcategory => $subPhotos) +

+ {{ $subcategory ?: '' }} +

+ +
+ @foreach ($subPhotos as $index => $item) + @php + $imagePath = storage_path('app/public/' . $item['path']); + @endphp +
+

{{ $item['name'] }}

+ @if ($statusLpj || file_exists($imagePath)) + {{ $item['path'] }} + @else +

Foto tidak ditemukan.

+ @endif +
+ + @if (($index + 1) % 2 == 0 && !$loop->last) +
+
+ @endif + @endforeach +
+@endforeach +@endif +@endif
+@endif +@endisset diff --git a/resources/views/penilai/components/foto-lampiran.blade.php b/resources/views/penilai/components/foto-lampiran.blade.php index 039f613..f21b449 100644 --- a/resources/views/penilai/components/foto-lampiran.blade.php +++ b/resources/views/penilai/components/foto-lampiran.blade.php @@ -1,264 +1,89 @@ -@if (isset($formFoto['rute_menuju_lokasi']['rute_menuju_lokasi'])) -
-
-

- Rute Menuju Lokasi -

-
-
- @if (isset($formFoto['rute_menuju_lokasi']['rute_menuju_lokasi'])) - @foreach ($formFoto['rute_menuju_lokasi']['rute_menuju_lokasi'][0] as $index => $item) -
-
-

- {{ $item['name'] ?? 'Rute menuju lokasi - ' . ($index + 1) }} -

-
- Gambar {{ $index + 1 }} -
-
-
- @endforeach - @endif -
-
-@endif +@isset($basicData['foto']) + @php + $photos = $formFoto['upload_foto'] ?? []; + if (!is_array($photos)) { + $photos = []; + } + $groupedPhotos = collect($photos)->groupBy('category'); + @endphp -@if (isset($formFoto['foto_rute_lainnya'])) -
-
-

- Rute Lainnya -

-
-
- @if (isset($formFoto['foto_rute_lainnya'])) - @foreach ($formFoto['foto_rute_lainnya'] as $index => $item) -
-
-

- {{ $item['name_rute_lainnya'] ?? 'Rute Lainnya - ' . ($index + 1) }} -

-
- Gambar {{ $index + 1 }} -
-
-
- @endforeach - @endif -
-
-@endif - -@if (isset($formFoto['foto_gerbang'])) -
-
-

- Gerbang -

-
-
- - -
+ @if ($groupedPhotos->isEmpty()) +

Tidak ada foto yang tersedia.

+ @else + @foreach ($groupedPhotos as $category => $photos) +
+

{{ $category ?? 'Tanpa Kategori' }}

-

- Gerbang -

-
+ @php + $groupedBySubcategory = $photos->groupBy('sub'); + @endphp + @if ($groupedBySubcategory->isEmpty()) - - -
-
-
- -
-
-@endif - -@if (isset($formFoto['foto_lingkungan']['foto_lingkungan'])) -
-
-

- Lingkungan

-
-
- @if (isset($formFoto['foto_lingkungan']['foto_lingkungan'])) - @foreach ($formFoto['foto_lingkungan']['foto_lingkungan'][0] as $index => $item) -
-
-

- {{ $item['name'] ?? 'Lingkungan - ' . ($index + 1) }} -

-
- Gambar {{ $index + 1 }} -
-
-
- @endforeach - @endif -
-
-@endif - -@if (isset($formFoto['object_jaminan'])) -
-
-

- Object Jaminan -

-
-
- @if (isset($formFoto['object_jaminan'])) - @foreach ($formFoto['object_jaminan'] as $item) -
-
-

- {{ $item['name_objek'] ?? "" }} -

-
- -
-
-
- @endforeach - @endif -
-
-@endif - -@if (isset($formFoto['foto_lantai_unit'])) -
-
-

Lantai

-
-
- @if (isset($formFoto['foto_lantai_unit'])) - @foreach ($formFoto['foto_lantai_unit'] as $floorIndex => $floorPhotos) -
- @foreach ($floorPhotos as $index => $item) - @if (is_int($index) && isset($item['name'], $item['path']) && is_string($item['path'])) -
-
-

- {{ $item['name'] ?? 'Foto Lantai ' . ($floorIndex + 1) . ' - ' . ($index + 1) }} -

-
- Gambar {{ $floorIndex + 1 }}-{{ $index + 1 }} + @foreach ($photos as $index => $item) +
+
+

+ {{ $item['name'] ?? 'Foto - ' . ($index + 1) }} +

+
+ @if (isset($item['path'])) + Gambar {{ $index + 1 }} + @else +

Gambar tidak tersedia

+ @endif +
+

{{ $item['description'] ?? '-' }}

-
- @endif - @endforeach -
- @endforeach - - @endif -
-
-@endif - - - -@if (isset($formFoto['foto_basement'])) -
-
-

- Basement -

-
-
-
-
-

- Basemnt -

-
- - - - -
+ @endforeach + @else + + @foreach ($groupedBySubcategory as $subcategory => $subPhotos) +
+ +

+ @if ($subcategory) + {{ $subcategory }} + @endif +

+
+ @foreach ($subPhotos as $index => $item) +
+
+

+ {{ $item['name'] ?? 'Foto - ' . ($index + 1) }} +

+
+ @if (isset($item['path'])) + Gambar {{ $index + 1 }} + @else +

Gambar tidak tersedia

+ @endif +
+

{{ $item['description'] ?? '-' }}

+
+
+ @endforeach +
+
+ @endforeach + @endif
- -
-
-@endif - -@if (isset($formFoto['foto_lantai_lainnya'])) -
-
-

- Lantai Lainnya -

-
-
- @if (isset($formFoto['foto_lantai_lainnya'])) - @foreach ($formFoto['foto_lantai_lainnya'] as $index => $item) -
-
-

- {{ $item['name_lantai_lainnya'] ?? 'Lantai - ' . ($index + 1) }} -

-
- Gambar {{ $index + 1 }} -
-
-
- @endforeach - @endif -
-
-@endif - - - - -@if (isset($formFoto['pendamping'])) -
-
-

- Pendamping -

-
-
- - -
-
-

- Pendamping -

-
- - - - -
-
-
- -
-
-@endif + @endforeach + @endif +@endisset @php -$fotoTypes = ['foto_gistaru', 'foto_bhumi', 'foto_argis_region', 'foto_tempat']; -if (($key = array_search('foto_tempat', $fotoTypes)) !== false) { - unset($fotoTypes[$key]); - array_unshift($fotoTypes, 'foto_tempat'); -} -$adaFoto = false; + $fotoTypes = ['foto_gistaru', 'foto_bhumi', 'foto_argis_region', 'foto_tempat']; + if (($key = array_search('foto_tempat', $fotoTypes)) !== false) { + unset($fotoTypes[$key]); + array_unshift($fotoTypes, 'foto_tempat'); + } + $adaFoto = false; if (isset($forminspeksi)) { foreach ($fotoTypes as $type) { $imagePath = $forminspeksi[$type] ?? null; @@ -271,33 +96,33 @@ $adaFoto = false; @endphp @if ($adaFoto) -
-
-

- Peta -

-
-
+
+
+

+ Peta +

+
+
-
- @if (isset($forminspeksi)) - @forelse ($fotoTypes as $type) -
- @php - $imagePath = $forminspeksi[$type] ?? null; - @endphp +
+ @if (isset($forminspeksi)) + @forelse ($fotoTypes as $type) +
+ @php + $imagePath = $forminspeksi[$type] ?? null; + @endphp - @if ($imagePath && file_exists(storage_path('app/public/' . $imagePath))) - {{ $type }} - @endif -

{{ Str::title(str_replace('_', ' ', $type)) }}

-
- @empty -

Tidak ada tipe foto yang tersedia

- @endforelse - @endif + @if ($imagePath && file_exists(storage_path('app/public/' . $imagePath))) + {{ $type }} + @endif +

{{ Str::title(str_replace('_', ' ', $type)) }}

+
+ @empty +

Tidak ada tipe foto yang tersedia

+ @endforelse + @endif +
-
@endif diff --git a/resources/views/surveyor/components/data.json b/resources/views/surveyor/components/data.json index 188e0db..346465d 100644 --- a/resources/views/surveyor/components/data.json +++ b/resources/views/surveyor/components/data.json @@ -1,5 +1,5 @@ { - "rute_menuju_lokasi": [ + "upload_foto": [ { "name": "Tampak Depan Objek", "description": "terdapat jalan depan rumah", @@ -22,6 +22,5 @@ "updated_by": "Administrator", "updated_at": "2025-02-05 04:38:53" } - ], - "foto_lantai_unit": [] + ] } diff --git a/resources/views/surveyor/components/foto.blade.php b/resources/views/surveyor/components/foto.blade.php index f46aea2..120eb4c 100644 --- a/resources/views/surveyor/components/foto.blade.php +++ b/resources/views/surveyor/components/foto.blade.php @@ -322,25 +322,7 @@ showConfirmButton: false, timer: 1500 }); - var mockFile = { - name: file.name, - size: file.size || 12345, - originalPath: file.path - }; - - myDropzone.emit("addedfile", mockFile); - myDropzone.emit("thumbnail", mockFile, response.file.path); - myDropzone.emit("complete", mockFile); - addEditAndDeleteButtons(mockFile, { - path: response.file.path, - name: response.file.name, - description: response.file.description || '', - category: response.file.category || 'lainnya', - sub: response.file.sub || '', - param_name: paramName - }); - - + updatePhotoGallery(); } }, @@ -448,25 +430,25 @@ if (response.fotos && response.fotos.length) { response.fotos.forEach(function(foto) { // Cek jika foto sudah ada di Dropzone - if (!isFileInDropzone(foto.name)) { - var mockFile = { - name: foto.name, - size: foto.size || 12345, - originalPath: foto.path - }; - myDropzone.emit("addedfile", mockFile); - myDropzone.emit("thumbnail", mockFile, foto.path); - myDropzone.emit("complete", mockFile); - addEditAndDeleteButtons(mockFile, { - path: foto.path, - name: foto.name, - description: foto.description || '', - category: foto.category || 'lainnya', - sub: foto.sub || '', - param_name: 'upload_foto' - }); - } + var mockFile = { + name: foto.name, + size: foto.size || 12345, + originalPath: foto.path + }; + + myDropzone.emit("addedfile", mockFile); + myDropzone.emit("thumbnail", mockFile, foto.path); + myDropzone.emit("complete", mockFile); + addEditAndDeleteButtons(mockFile, { + path: foto.path, + name: foto.name, + description: foto.description || '', + category: foto.category || 'lainnya', + sub: foto.sub || '', + param_name: 'upload_foto' + }); + }); } else { console.log('Tidak ada foto yang ditemukan'); @@ -479,10 +461,7 @@ } - function isFileInDropzone(fileName) { - let files = myDropzone.files; - return files.some(file => file.name === fileName); - } + // Inisialisasi Dropzone untuk elemen awal dengan pengecekan function safeInitDropzone(selector, paramName) {