Merge remote-tracking branch 'composer/feature/senior-officer' into staging

This commit is contained in:
Daeng Deni Mardaeni
2024-12-27 16:55:33 +07:00
4 changed files with 126 additions and 124 deletions

View File

@@ -384,37 +384,41 @@ class SurveyorController extends Controller
return $result; return $result;
} }
private function processFotoLantaiUnit(Request $request) public function replaceFotoLantaiUnit(Request $request)
{ {
$processedFotoLantaiUnit = []; // Pastikan foto lantai unit ada dalam request
if ($request->has('foto_lantai_unit')) {
// Ambil semua file foto lantai unit
$fotoLantaiUnit = $request->file('foto_lantai_unit', []); $fotoLantaiUnit = $request->file('foto_lantai_unit', []);
foreach ($fotoLantaiUnit as $lantaiKey => $files) { // Target lantai dan foto yang ingin diubah
$processedFiles = []; $lantaiKey = $request->input('lantai_key'); // Misal: 1
$indexToReplace = $request->input('index'); // Misal: 0
// Cek jika lantaiKey ada dan file yang akan diganti ada
if (isset($fotoLantaiUnit[$lantaiKey]) && isset($fotoLantaiUnit[$lantaiKey][$indexToReplace])) {
$file = $fotoLantaiUnit[$lantaiKey][$indexToReplace];
foreach ($files as $index => $file) {
// Pastikan file valid // Pastikan file valid
if ($file && $file->isValid()) { if ($file && $file->isValid()) {
// Generate unique filename // Generate filename baru untuk foto yang diganti
$filename = $this->generateUniqueFileName($file, "lantai_unit_{$lantaiKey}_{$index}"); $filename = $this->generateUniqueFileName($file, "lantai_unit_{$lantaiKey}_{$indexToReplace}");
$processedFiles[] = [ // Gantikan foto yang lama dengan yang baru
'path' => $this->uploadFile($file, $filename . '.' . $index), $processedFoto = [
'name' => "Foto Lantai {$lantaiKey} - " . ($index + 1), 'path' => $this->uploadFile($file, $filename . '.' . $file->getClientOriginalExtension()),
'name' => "Foto Lantai {$lantaiKey} - " . ($indexToReplace + 1),
]; ];
// Update foto lantai unit yang sudah diproses
$fotoLantaiUnit[$lantaiKey][$indexToReplace] = $processedFoto;
}
} }
} }
// Simpan file yang diproses dengan kunci lantai // Kembalikan data foto lantai unit yang sudah diperbarui
if (!empty($processedFiles)) { return response()->json(['foto_lantai_unit' => $fotoLantaiUnit]);
$processedFotoLantaiUnit[$lantaiKey] = $processedFiles;
}
} }
return $processedFotoLantaiUnit;
}
// Fungsi helper untuk generate nama file unik // Fungsi helper untuk generate nama file unik
private function generateUniqueFileName($file, $prefix = '') private function generateUniqueFileName($file, $prefix = '')

View File

@@ -397,6 +397,7 @@
ondrop="handleDrop(event)" ondragover="allowDrop(event)"> ondrop="handleDrop(event)" ondragover="allowDrop(event)">
<div class="preview-container grid grid-cols-2 md:grid-cols-4 gap-4"> <div class="preview-container grid grid-cols-2 md:grid-cols-4 gap-4">
@foreach ($lantaiFotos as $foto) @foreach ($lantaiFotos as $foto)
@if (is_array($foto) && isset($foto['path']) && isset($foto['name']))
<div class="preview-item relative"> <div class="preview-item relative">
<img src="{{ asset('storage/' . $foto['path']) }}" <img src="{{ asset('storage/' . $foto['path']) }}"
alt="{{ $foto['name'] }}" alt="{{ $foto['name'] }}"
@@ -407,15 +408,14 @@
<i class="ki-solid ki-cross"></i> <i class="ki-solid ki-cross"></i>
</button> </button>
</div> </div>
@else
<p>Invalid photo data.</p>
@endif
@endforeach @endforeach
</div> </div>
<input type="file" <input type="file" name="foto_lantai_unit[{{ $lantaiKey }}][]"
name="foto_lantai_unit[{{ $lantaiKey }}][]" class="file-input hidden" multiple accept="image/*"
class="file-input hidden" onchange="handleFileInput(this)" data-lantai="{{ $lantaiKey }}">
multiple
accept="image/*"
onchange="handleFileInput(this)"
data-lantai="{{ $lantaiKey }}">
<button type="button" class="btn btn-light btn-sm btnUploadFiles mt-2"> <button type="button" class="btn btn-light btn-sm btnUploadFiles mt-2">
<i class="ki-outline ki-upload"></i> Unggah Gambar <i class="ki-outline ki-upload"></i> Unggah Gambar
</button> </button>
@@ -426,8 +426,6 @@
</div> </div>
</div> </div>
@else @else
<div class="flex flex-wrap gap-4 w-full"> <div class="flex flex-wrap gap-4 w-full">
<div class="w-full"> <div class="w-full">
<div class="text-white py-4 flex items-center justify-between w-full"> <div class="text-white py-4 flex items-center justify-between w-full">
@@ -453,7 +451,8 @@
ondrop="handleDrop(event)" ondragover="allowDrop(event)"> ondrop="handleDrop(event)" ondragover="allowDrop(event)">
<div class="preview-container grid grid-cols-2 md:grid-cols-4 gap-4"></div> <div class="preview-container grid grid-cols-2 md:grid-cols-4 gap-4"></div>
<input type="file" name="foto_lantai_unit[1][]" class="file-input hidden" <input type="file" name="foto_lantai_unit[1][]" class="file-input hidden"
multiple accept="image/*" onchange="handleFileInput(this)" data-lantai="1"> multiple accept="image/*" onchange="handleFileInput(this)"
data-lantai="1">
<button type="button" class="btn btn-light btn-sm btnUploadFiles mt-2"> <button type="button" class="btn btn-light btn-sm btnUploadFiles mt-2">
<i class="ki-outline ki-upload"></i> Unggah Gambar <i class="ki-outline ki-upload"></i> Unggah Gambar
</button> </button>
@@ -602,8 +601,7 @@
@include('lpj::surveyor.js.utils') @include('lpj::surveyor.js.utils')
@push('scripts') @push('scripts')
<script> <script>
// console.log('@json($formFoto)');
console.log('@json($formFoto)');
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
const lantaiContainer = document.getElementById("lantaiContainer"); const lantaiContainer = document.getElementById("lantaiContainer");
@@ -783,7 +781,7 @@
} }
}); });
console.log(formData.value);
@@ -810,7 +808,7 @@
window.location.href = window.location.href =
'{{ route('surveyor.show', ['id' => $permohonan->id]) }}'; '{{ route('surveyor.show', ['id' => $permohonan->id]) }}';
} }
// console.log(response); console.log(response);
}); });
} else { } else {

View File

@@ -187,8 +187,8 @@
setupInputHandlers('inputContainerRute', 'btnRute', 'Foto Rute Menuju Lokasi', 'file-input', setupInputHandlers('inputContainerRute', 'btnRute', 'Foto Rute Menuju Lokasi', 'file-input',
'delete-btn'); 'delete-btn');
setupInputHandlers('inputContainerLantai', 'btnLantai', 'Foto Lantai', 'file-input', // setupInputHandlers('inputContainerLantai', 'btnLantai', 'Foto Lantai', 'file-input',
'delete-btn'); // 'delete-btn');
setupInputHandlers('inputContainerLingkungan', 'btnLingkungan', 'Lingkungan', 'file-input', setupInputHandlers('inputContainerLingkungan', 'btnLingkungan', 'Lingkungan', 'file-input',
'delete-btn'); 'delete-btn');