diff --git a/app/Http/Controllers/Pg/SecurityGuardController.php b/app/Http/Controllers/Pg/SecurityGuardController.php index d9e2940..e3fa12e 100644 --- a/app/Http/Controllers/Pg/SecurityGuardController.php +++ b/app/Http/Controllers/Pg/SecurityGuardController.php @@ -54,10 +54,15 @@ class SecurityGuardController extends Controller */ public function index(Request $request): View { + $perPage = (int) $request->input('per_page', 20); + if (!in_array($perPage, [20, 50, 100])) { + $perPage = 20; + } + $guards = $this->getGuardsQuery($request) ->orderBy('team') ->orderBy('name') - ->paginate(20) + ->paginate($perPage) ->withQueryString(); $gates = Gate::where('is_active', true)->orderBy('name')->get(); diff --git a/resources/views/pg/guards_index.blade.php b/resources/views/pg/guards_index.blade.php index a022328..d02c523 100644 --- a/resources/views/pg/guards_index.blade.php +++ b/resources/views/pg/guards_index.blade.php @@ -62,7 +62,7 @@ -
+
@@ -76,7 +76,7 @@ class="w-full text-xs pl-10 pr-4 py-2.5 rounded-xl border border-slate-200 bg-white text-slate-800 placeholder-slate-400 focus:outline-none focus:border-[#1b5e20] focus:ring-2 focus:ring-[#1b5e20]/10 shadow-sm transition">
- +
@@ -89,11 +89,25 @@ + + + + + +
- @if(request()->anyFilled(['search', 'team', 'gate_id'])) + @if(request()->anyFilled(['search', 'team', 'gate_id', 'per_page'])) @@ -618,100 +632,23 @@ document.getElementById('editGuardModal').classList.add('hidden'); } - // Filter Pencarian Instan Real-time & Pesan Tidak Ditemukan + // Pencarian Server-side Otomatis (Global ke seluruh database, bukan hanya halaman 1) const searchInput = document.getElementById('guardSearchInput'); - const resetContainer = document.getElementById('guardResetContainer'); - const tableBody = document.getElementById('guardTableBody'); - const hasServerFilters = {{ request()->anyFilled(['search', 'team', 'gate_id']) ? 'true' : 'false' }}; + const guardFilterForm = document.getElementById('guardFilterForm'); + let searchDebounce = null; - function escapeHtml(str) { - const div = document.createElement('div'); - div.textContent = str; - return div.innerHTML; + // Fokuskan kursor di ujung teks input jika ada kata kunci pencarian aktif + if (searchInput && searchInput.value) { + searchInput.focus(); + const len = searchInput.value.length; + searchInput.setSelectionRange(len, len); } - searchInput?.addEventListener('input', function(e) { - const rawValue = e.target.value; - const query = rawValue.toLowerCase().trim(); - const rows = document.querySelectorAll('#guardTableBody tr.guard-row'); - let visibleCount = 0; - - rows.forEach(row => { - const text = row.textContent.toLowerCase(); - const match = text.includes(query); - row.style.display = match ? '' : 'none'; - if (match) visibleCount++; - }); - - const serverEmptyRow = document.getElementById('serverGuardEmptyRow'); - if (serverEmptyRow) { - serverEmptyRow.style.display = query.length > 0 ? 'none' : ''; - } - - // Hapus baris pesan kosong pencarian jika ada sebelumnya - const existingEmptyRow = document.getElementById('guardEmptySearchRow'); - if (existingEmptyRow) { - existingEmptyRow.remove(); - } - - // Tampilkan pesan jika tidak ada data yang cocok di tabel - if (visibleCount === 0 && query.length > 0) { - const emptyTr = document.createElement('tr'); - emptyTr.id = 'guardEmptySearchRow'; - emptyTr.innerHTML = ` - - -

- Data "${escapeHtml(rawValue)}" tidak ditemukan di tabel -

-

- Pastikan ejaan ID Satpam atau nama petugas yang dicari sudah benar. -

-
- -
- - `; - tableBody?.appendChild(emptyTr); - } - - // Tampilkan/sembunyikan tombol Reset Filter secara real-time saat mengetik - let resetBtn = document.getElementById('guardResetBtn'); - if (query.length > 0) { - if (!resetBtn && resetContainer) { - resetBtn = document.createElement('a'); - resetBtn.id = 'guardResetBtn'; - resetBtn.href = "{{ route('pg.guards.index') }}"; - resetBtn.className = "text-xs text-rose-600 hover:text-rose-700 font-semibold flex items-center justify-center sm:justify-start space-x-1.5 transition whitespace-nowrap py-1 sm:py-0 sm:ml-2"; - const resetIcon = document.createElement('i'); - resetIcon.className = "fa-solid fa-rotate-left text-[11px]"; - const resetText = document.createElement('span'); - resetText.textContent = "Reset Filter"; - resetBtn.appendChild(resetIcon); - resetBtn.appendChild(resetText); - resetContainer.appendChild(resetBtn); - } - } else if (!hasServerFilters && resetBtn) { - resetBtn.remove(); - } - }); - - // Reset filter click handler saat hanya input client-side tanpa server filter - resetContainer?.addEventListener('click', function(e) { - const btn = e.target.closest('#guardResetBtn'); - if (btn && !hasServerFilters) { - e.preventDefault(); - if (searchInput) { - searchInput.value = ''; - searchInput.dispatchEvent(new Event('input')); - searchInput.focus(); - } - } + searchInput?.addEventListener('input', function() { + clearTimeout(searchDebounce); + searchDebounce = setTimeout(function() { + guardFilterForm?.submit(); + }, 500); }); // Buka & Tutup Modal Panduan Halaman function openGuideModal() {