234 lines
15 KiB
PHP
234 lines
15 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.
|
|
filters: [['name', 'label', 'options' => [], 'value' => bawaan]] atau ['name', 'label', 'type' => 'check'].
|
|
Opsional: $viewUrl (aksi Lihat, "__ID__" diganti row.id), $destroyUrl + $destroy['title'|'message'] (Hapus sungguhan
|
|
lewat POST {ids}); $form = ['title', 'storeUrl', 'updateUrl' ("__ID__"), 'fields' => [['name', 'label', 'type' =>
|
|
text|number|date|select, 'options', 'required', 'max', 'min', 'hint', 'multiple', 'default']]] untuk Tambah/Ubah lewat
|
|
modal (baris data menyediakan row.form = nilai isian). Tanpa semuanya tombol aksi hanya notifikasi prototipe.
|
|
--}}
|
|
@php
|
|
$viewUrl ??= null;
|
|
$destroyUrl ??= null;
|
|
$form ??= null;
|
|
$destroy = ($destroy ?? []) + ['title' => 'Hapus data terpilih?', 'message' => 'Data yang dipilih akan dihapus.'];
|
|
$tools = [
|
|
'T' => ['Tambah', 'plus', 'primary', $form ? 'startInsert()' : "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' => collect($filters)->mapWithKeys(fn (array $f): array => [$f['name'] => ($f['type'] ?? 'select') === 'check' ? false : (string) ($f['value'] ?? '')])->all(),
|
|
'data' => $data,
|
|
'viewUrl' => $viewUrl,
|
|
'destroyUrl' => $destroyUrl,
|
|
'form' => $form ? ['storeUrl' => $form['storeUrl'], 'updateUrl' => $form['updateUrl'], 'fields' => array_map(fn (array $f): array => ['name' => $f['name'], 'default' => $f['default'] ?? (($f['multiple'] ?? false) ? [] : '')], $form['fields'])] : null,
|
|
'token' => csrf_token(),
|
|
];
|
|
@endphp
|
|
|
|
<div class="stack" x-data="satuRemoteTable(@js($config))">
|
|
@if ($filters)
|
|
<x-glass.panel padding="sm" as="section" aria-label="Filter data">
|
|
<div class="filter-bar">
|
|
@foreach ($filters as $filter)
|
|
@if (($filter['type'] ?? 'select') === 'check')
|
|
<x-form.checkbox
|
|
:name="'filter_'.$filter['name']"
|
|
:label="$filter['label']"
|
|
x-model="values.{{ $filter['name'] }}"
|
|
x-on:change="search()"
|
|
/>
|
|
@else
|
|
<x-form.select
|
|
:name="'filter_'.$filter['name']"
|
|
:label="$filter['label']"
|
|
:options="$filter['options']"
|
|
:value="$filter['value'] ?? null"
|
|
placeholder=""
|
|
x-model="values.{{ $filter['name'] }}"
|
|
x-on:change="search()"
|
|
/>
|
|
@endif
|
|
@endforeach
|
|
</div>
|
|
</x-glass.panel>
|
|
@endif
|
|
|
|
<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">
|
|
@if ($viewUrl)
|
|
<a class="btn btn--ghost btn--sm btn--icon" x-bind:href="link(row)" aria-label="Lihat"><x-heroicon-o-eye /></a>
|
|
@else
|
|
<x-ui.button variant="ghost" size="sm" icon="eye" :icon-only="true" aria-label="Lihat" x-on:click="demo('Lihat')" />
|
|
@endif
|
|
@if ($form)
|
|
<x-ui.button variant="ghost" size="sm" icon="pencil-square" :icon-only="true" aria-label="Ubah" x-on:click="startEdit(row)" />
|
|
@else
|
|
<x-ui.button variant="ghost" size="sm" icon="pencil-square" :icon-only="true" aria-label="Ubah" x-on:click="demo('Ubah')" />
|
|
@endif
|
|
@if ($destroyUrl)
|
|
<x-ui.button variant="ghost" size="sm" icon="trash" :icon-only="true" aria-label="Hapus" x-on:click="askRemove([row.id])" />
|
|
@else
|
|
<x-ui.button variant="ghost" size="sm" icon="trash" :icon-only="true" aria-label="Hapus" x-on:click="demo('Hapus')" />
|
|
@endif
|
|
</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>
|
|
|
|
@if ($form)
|
|
{{-- Modal formulir tambah/ubah: kolom menurut $form['fields'], nilai di formData --}}
|
|
<dialog x-ref="form" class="dialog dialog--wide" aria-labelledby="satu-form-judul" x-on:click="formBackdrop($event)" x-on:close="editing = null">
|
|
<form class="dialog__body" x-on:submit.prevent="save()" novalidate>
|
|
<div class="dialog__head">
|
|
<span class="dialog__icon" aria-hidden="true"><x-heroicon-o-pencil-square /></span>
|
|
<p id="satu-form-judul" class="dialog__title" x-text="editing === 'new' ? 'Tambah {{ $form['title'] }}' : 'Ubah {{ $form['title'] }}'"></p>
|
|
</div>
|
|
|
|
<div class="satu-form">
|
|
@foreach ($form['fields'] as $f)
|
|
@if (($f['type'] ?? 'text') === 'select')
|
|
<x-form.select
|
|
:name="'form_'.$f['name']"
|
|
:label="$f['label']"
|
|
:options="$f['options']"
|
|
:optional="! ($f['required'] ?? false)"
|
|
:hint="$f['hint'] ?? null"
|
|
placeholder=""
|
|
:required="$f['required'] ?? false"
|
|
:multiple="$f['multiple'] ?? false"
|
|
x-model="formData.{{ $f['name'] }}"
|
|
/>
|
|
@else
|
|
<x-form.field
|
|
:name="'form_'.$f['name']"
|
|
:label="$f['label']"
|
|
:type="$f['type'] ?? 'text'"
|
|
:optional="! ($f['required'] ?? false)"
|
|
:hint="$f['hint'] ?? null"
|
|
:placeholder="$f['placeholder'] ?? null"
|
|
:required="$f['required'] ?? false"
|
|
:maxlength="($f['type'] ?? 'text') === 'text' ? ($f['max'] ?? null) : null"
|
|
:min="($f['type'] ?? 'text') === 'number' ? ($f['min'] ?? null) : null"
|
|
:max="($f['type'] ?? 'text') === 'number' ? ($f['max'] ?? null) : null"
|
|
x-model="formData.{{ $f['name'] }}"
|
|
/>
|
|
@endif
|
|
@endforeach
|
|
</div>
|
|
|
|
<div class="dialog__actions">
|
|
<x-ui.button type="submit" variant="primary" icon="check" x-bind:disabled="loading">Simpan</x-ui.button>
|
|
<x-ui.button variant="secondary" x-on:click="closeForm()">Batal</x-ui.button>
|
|
</div>
|
|
</form>
|
|
</dialog>
|
|
@endif
|
|
|
|
@if ($destroyUrl)
|
|
<dialog x-ref="dialog" class="dialog dialog--danger" aria-labelledby="satu-hapus-judul" aria-describedby="satu-hapus-pesan" x-on:click="backdrop($event)" x-on:close="pending = []">
|
|
<div class="dialog__body">
|
|
<div class="dialog__head">
|
|
<span class="dialog__icon" aria-hidden="true"><x-heroicon-o-exclamation-triangle /></span>
|
|
<p id="satu-hapus-judul" class="dialog__title">{{ $destroy['title'] }}</p>
|
|
</div>
|
|
<p id="satu-hapus-pesan" class="dialog__message"><span x-text="pending.length"></span> baris dipilih. {{ $destroy['message'] }}</p>
|
|
<div class="dialog__actions">
|
|
<x-ui.button variant="danger" x-on:click="confirmRemove()" x-bind:disabled="loading">Ya, hapus</x-ui.button>
|
|
<x-ui.button variant="secondary" x-on:click="closeDialog()">Batal</x-ui.button>
|
|
</div>
|
|
</div>
|
|
</dialog>
|
|
@endif
|
|
</div>
|
|
@endif
|
|
</x-satu.frame>
|