133 lines
7.9 KiB
PHP
133 lines
7.9 KiB
PHP
{{--
|
|
Halaman daftar SATU dengan data asli DB lama: markup sama dengan operator/satu/list (filter, bilah cari + tombol
|
|
menurut flags katalog, centang, kolom, aksi baris, satu-foot), tetapi baris diambil server lewat satuRemoteTable
|
|
(fetch JSON ke $url), sehingga alamat halaman tidak berubah. Halaman pertama ikut dirender sebagai data awal.
|
|
columns: [['key', 'label', 'num' => bool, 'badge' => bool]]; kolom badge memakai row.{key} dan nada row.tone.
|
|
Tombol aksi hanya notifikasi prototipe.
|
|
--}}
|
|
@php
|
|
$tools = [
|
|
'T' => ['Tambah', 'plus', 'primary', "demo('Tambah')"],
|
|
'H' => ['Hapus', 'trash', 'danger', 'remove()'],
|
|
'A' => ['Aksi', 'ellipsis-horizontal-circle', 'secondary', "demo('Aksi')"],
|
|
'C' => ['Cetak', 'printer', 'secondary', 'window.print()'],
|
|
];
|
|
$active = array_filter($tools, fn (string $key): bool => str_contains($page['flags'], $key), ARRAY_FILTER_USE_KEY);
|
|
$checkbox = in_array('#', $page['columns'], true);
|
|
$actions = in_array('Aksi', $page['columns'], true);
|
|
@endphp
|
|
|
|
<x-satu.frame :page="$page" :crumbs="$crumbs" :note="$note">
|
|
@if ($data === null)
|
|
<x-glass.panel padding="lg">
|
|
<x-ui.empty :icon="$empty['icon']" :title="$empty['title']" :description="$empty['description']" />
|
|
</x-glass.panel>
|
|
@else
|
|
@php
|
|
$config = [
|
|
'url' => $url,
|
|
'filters' => array_fill_keys(array_column($filters, 'name'), ''),
|
|
'data' => $data,
|
|
];
|
|
@endphp
|
|
|
|
<div class="stack" x-data="satuRemoteTable(@js($config))">
|
|
<x-glass.panel padding="sm" as="section" aria-label="Filter data">
|
|
<div class="filter-bar">
|
|
@foreach ($filters as $filter)
|
|
<x-form.select
|
|
:name="'filter_'.$filter['name']"
|
|
:label="$filter['label']"
|
|
:options="$filter['options']"
|
|
placeholder=""
|
|
x-model="values.{{ $filter['name'] }}"
|
|
x-on:change="search()"
|
|
/>
|
|
@endforeach
|
|
</div>
|
|
</x-glass.panel>
|
|
|
|
<x-glass.panel padding="none" as="section" :aria-label="'Daftar '.$page['title']">
|
|
<div class="satu-bar">
|
|
<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" class="field__input" style="--pad-start: 2.5rem" placeholder="Cari {{ Str::lower($page['title']) }}" autocomplete="off" x-model="q" x-on:input.debounce.400ms="search()">
|
|
</div>
|
|
</div>
|
|
|
|
<div class="satu-bar__tools">
|
|
@foreach ($active as [$label, $icon, $variant, $click])
|
|
<x-ui.button :variant="$variant" :icon="$icon" size="sm" x-on:click="{{ $click }}">{{ $label }}</x-ui.button>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
|
|
<x-ui.table :label="'Tabel '.Str::lower($page['title'])">
|
|
<table class="table satu-table" x-bind:aria-busy="loading">
|
|
<thead>
|
|
<tr>
|
|
@if ($checkbox)
|
|
<th scope="col" class="satu-check"><input type="checkbox" class="check__input" aria-label="Pilih semua baris di halaman ini" x-bind:checked="allPicked" x-on:change="toggleAll()"></th>
|
|
@endif
|
|
@foreach ($columns as $column)
|
|
<th scope="col" @class(['num' => $column['num'] ?? false])>{{ $column['label'] }}</th>
|
|
@endforeach
|
|
@if ($actions)
|
|
<th scope="col" class="table__actions"><span class="visually-hidden">Aksi</span></th>
|
|
@endif
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<template x-for="row in view" x-bind:key="row.id">
|
|
<tr>
|
|
@if ($checkbox)
|
|
<td class="satu-check"><input type="checkbox" class="check__input" aria-label="Pilih baris" x-model="picked" x-bind:value="row.id"></td>
|
|
@endif
|
|
@foreach ($columns as $column)
|
|
@if ($column['badge'] ?? false)
|
|
<td><span class="badge" x-bind:class="row.tone ? 'badge--' + row.tone : ''" x-text="row.{{ $column['key'] }}"></span></td>
|
|
@else
|
|
<td @class(['num' => $column['num'] ?? false, 'table__title' => $loop->first && ! $checkbox])><span x-text="row.{{ $column['key'] }}"></span></td>
|
|
@endif
|
|
@endforeach
|
|
@if ($actions)
|
|
<td class="table__actions">
|
|
<x-ui.button variant="ghost" size="sm" icon="eye" :icon-only="true" aria-label="Lihat" x-on:click="demo('Lihat')" />
|
|
<x-ui.button variant="ghost" size="sm" icon="pencil-square" :icon-only="true" aria-label="Ubah" x-on:click="demo('Ubah')" />
|
|
<x-ui.button variant="ghost" size="sm" icon="trash" :icon-only="true" aria-label="Hapus" x-on:click="demo('Hapus')" />
|
|
</td>
|
|
@endif
|
|
</tr>
|
|
</template>
|
|
</tbody>
|
|
</table>
|
|
<p class="satu-empty" x-show="view.length === 0" x-cloak>Tidak ada data yang cocok dengan pencarian atau filter.</p>
|
|
</x-ui.table>
|
|
|
|
<div class="satu-foot">
|
|
<p class="satu-foot__info" aria-live="polite">Halaman <span x-text="page.toLocaleString('id-ID')"></span> dari <span x-text="pages.toLocaleString('id-ID')"></span> (<span x-text="total.toLocaleString('id-ID')"></span> data)</p>
|
|
|
|
<label class="satu-foot__per">
|
|
<span class="visually-hidden">Jumlah data per halaman</span>
|
|
<select class="field__input field__select" data-no-clear x-model.number="per" x-on:change="search()">
|
|
@foreach ($perPage as $n)
|
|
<option value="{{ $n }}">{{ $n }} data</option>
|
|
@endforeach
|
|
</select>
|
|
</label>
|
|
|
|
<nav class="satu-pager" aria-label="Halaman data">
|
|
<button type="button" class="satu-pager__btn" aria-label="Halaman sebelumnya" x-bind:disabled="page === 1" x-on:click="go(page - 1)"><x-heroicon-m-chevron-left /></button>
|
|
<template x-for="n in window" x-bind:key="n">
|
|
<button type="button" class="satu-pager__btn" x-text="n" x-bind:aria-current="n === page ? 'page' : false" x-on:click="go(n)"></button>
|
|
</template>
|
|
<button type="button" class="satu-pager__btn" aria-label="Halaman berikutnya" x-bind:disabled="page === pages" x-on:click="go(page + 1)"><x-heroicon-m-chevron-right /></button>
|
|
</nav>
|
|
</div>
|
|
</x-glass.panel>
|
|
</div>
|
|
@endif
|
|
</x-satu.frame>
|