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;
}
private function processFotoLantaiUnit(Request $request)
public function replaceFotoLantaiUnit(Request $request)
{
$processedFotoLantaiUnit = [];
// Ambil semua file foto lantai unit
// Pastikan foto lantai unit ada dalam request
if ($request->has('foto_lantai_unit')) {
$fotoLantaiUnit = $request->file('foto_lantai_unit', []);
foreach ($fotoLantaiUnit as $lantaiKey => $files) {
$processedFiles = [];
// Target lantai dan foto yang ingin diubah
$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
if ($file && $file->isValid()) {
// Generate unique filename
$filename = $this->generateUniqueFileName($file, "lantai_unit_{$lantaiKey}_{$index}");
// Generate filename baru untuk foto yang diganti
$filename = $this->generateUniqueFileName($file, "lantai_unit_{$lantaiKey}_{$indexToReplace}");
$processedFiles[] = [
'path' => $this->uploadFile($file, $filename . '.' . $index),
'name' => "Foto Lantai {$lantaiKey} - " . ($index + 1),
// Gantikan foto yang lama dengan yang baru
$processedFoto = [
'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
if (!empty($processedFiles)) {
$processedFotoLantaiUnit[$lantaiKey] = $processedFiles;
}
// Kembalikan data foto lantai unit yang sudah diperbarui
return response()->json(['foto_lantai_unit' => $fotoLantaiUnit]);
}
return $processedFotoLantaiUnit;
}
// Fungsi helper untuk generate nama file unik
private function generateUniqueFileName($file, $prefix = '')

View File

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

View File

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