Files
siakad/resources/views/crud/satu-index.blade.php
2026-11-12 12:22:06 +07:00

150 lines
8.2 KiB
PHP

{{--
Daftar berformat SATU dengan paginasi server (untuk data yang barisnya mahal dihitung): filter, cari, dan halaman lewat GET.
Opsional: $perOptions (pilihan data per halaman, bawaan 10/25), $searchPlaceholder, filter bertipe 'date' atau 'hidden'
(ikut terkirim tanpa ditampilkan) selain 'select'.
--}}
@php
$query = request()->query('q');
$query = is_string($query) ? $query : '';
$last = $rows->lastPage();
$current = $rows->currentPage();
$start = max(1, min($current - 2, $last - 4));
$window = range($start, $start + min(5, $last) - 1);
$per = $rows->perPage();
$perOptions ??= [10, 25];
$hiddenFilters = array_filter($filters, fn (array $f): bool => ($f['type'] ?? 'select') === 'hidden');
$visibleFilters = array_filter($filters, fn (array $f): bool => ($f['type'] ?? 'select') !== 'hidden');
@endphp
<x-layouts.app :title="$names['plural']">
<x-ui.page-header
:title="$names['plural']"
:description="$names['description'] ?? null"
/>
{{-- Kontrol memakai atribut form="satu-form" agar tabel (dengan tautan dan formulir aksi) tidak berada di dalam formulir pencarian. --}}
<div class="stack" x-data x-on:change="$refs.satuForm.requestSubmit()">
<form id="satu-form" x-ref="satuForm" method="GET" action="{{ url()->current() }}" role="search" aria-label="Pencarian dan filter">
@foreach ($hiddenFilters as $filter)
<input type="hidden" name="{{ $filter['name'] }}" value="{{ request($filter['name']) }}">
@endforeach
</form>
@if ($visibleFilters)
<x-glass.panel padding="sm" as="section" aria-label="Filter data">
<div class="filter-bar">
@foreach ($visibleFilters as $filter)
@if (($filter['type'] ?? 'select') === 'date')
<x-form.field
type="date"
:name="$filter['name']"
:label="$filter['label']"
:value="request($filter['name'])"
:id="'filter-'.$filter['name']"
form="satu-form"
/>
@else
<x-form.select
:name="$filter['name']"
:label="$filter['label']"
:options="$filter['options']"
:value="request($filter['name'])"
placeholder=""
:id="'filter-'.$filter['name']"
form="satu-form"
/>
@endif
@endforeach
</div>
</x-glass.panel>
@endif
<x-glass.panel padding="none" as="section" :aria-label="'Daftar '.Str::lower($names['plural'])">
<div class="satu-bar">
@if ($searchable)
<div class="satu-bar__search field">
<label class="visually-hidden" for="satu-q">Cari data</label>
<div class="field__control">
<span class="field__icon" aria-hidden="true"><x-heroicon-o-magnifying-glass /></span>
<input id="satu-q" type="search" name="q" form="satu-form" value="{{ $query }}" class="field__input" style="--pad-start: 2.5rem" placeholder="{{ $searchPlaceholder ?? 'Cari '.Str::lower($names['plural']) }}" autocomplete="off" enterkeyhint="search">
</div>
</div>
@endif
</div>
<x-ui.table :label="'Tabel '.Str::lower($names['plural'])">
<table class="table satu-table">
<thead>
<tr>
@foreach ($columns as $col)
<th scope="col" @class(['num' => ($col['class'] ?? null) === 'num'])>{{ $col['label'] }}</th>
@endforeach
<th scope="col" class="table__actions"><span class="visually-hidden">Aksi</span></th>
</tr>
</thead>
<tbody>
@foreach ($rows as $row)
@php $id = $keyOf($row); @endphp
<tr>
@foreach ($columns as $col)
@php
$val = isset($col['value']) ? $col['value']($row) : data_get($row, $col['key']);
$tone = isset($col['badge']) ? $col['badge']($row) : null;
@endphp
<td @class(['num' => ($col['class'] ?? null) === 'num', 'table__title' => $loop->first])>
@if ($tone !== null && $val !== null && $val !== '')
<x-ui.badge :tone="$tone">{{ $val }}</x-ui.badge>
@else
{{ $val === null || $val === '' ? '-' : $val }}
@endif
</td>
@endforeach
<td class="table__actions">
@foreach ($rowActions($row) as $action)
<x-ui.button variant="ghost" size="sm" :href="$action['href']" :icon="$action['icon'] ?? null">{{ $action['label'] }}</x-ui.button>
@endforeach
@if ($abilities['show'])
<x-ui.button variant="ghost" size="sm" :href="route($base.'.show', $id)" icon="eye" :icon-only="true" :aria-label="'Lihat '.Str::lower($names['singular'])" />
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
@if ($rows->isEmpty())
<p class="satu-empty">{{ request()->query() ? 'Tidak ada data yang cocok dengan pencarian atau filter.' : 'Belum ada data '.Str::lower($names['plural']).'.' }}</p>
@endif
</x-ui.table>
<div class="satu-foot">
<p class="satu-foot__info" aria-live="polite">Halaman {{ $current }} dari {{ $last }} ({{ $rows->total() }} data)</p>
<label class="satu-foot__per">
<span class="visually-hidden">Jumlah data per halaman</span>
<select name="per" form="satu-form" class="field__input field__select" data-no-clear>
@foreach ($perOptions as $n)
<option value="{{ $n }}" @selected($per === (int) $n)>{{ $n }} data</option>
@endforeach
</select>
</label>
<nav class="satu-pager" aria-label="Halaman data">
@if ($current > 1)
<a class="satu-pager__btn" href="{{ $rows->url($current - 1) }}" aria-label="Halaman sebelumnya"><x-heroicon-m-chevron-left /></a>
@else
<span class="satu-pager__btn" aria-hidden="true" style="opacity: 0.4"><x-heroicon-m-chevron-left /></span>
@endif
@foreach ($window as $n)
<a class="satu-pager__btn" href="{{ $rows->url($n) }}" @if ($n === $current) aria-current="page" @endif>{{ $n }}</a>
@endforeach
@if ($current < $last)
<a class="satu-pager__btn" href="{{ $rows->url($current + 1) }}" aria-label="Halaman berikutnya"><x-heroicon-m-chevron-right /></a>
@else
<span class="satu-pager__btn" aria-hidden="true" style="opacity: 0.4"><x-heroicon-m-chevron-right /></span>
@endif
</nav>
</div>
</x-glass.panel>
</div>
</x-layouts.app>