Commit awal: prototipe UI SIAKAD Untan
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Prototype\ResourceController;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class PenggunaController extends ResourceController
|
||||
{
|
||||
protected function rows(): Collection
|
||||
{
|
||||
return SuperuserData::pengguna();
|
||||
}
|
||||
|
||||
protected function routeBase(): string
|
||||
{
|
||||
return 'superuser.pengguna';
|
||||
}
|
||||
|
||||
protected function keyName(): string
|
||||
{
|
||||
return 'username';
|
||||
}
|
||||
|
||||
protected function names(): array
|
||||
{
|
||||
return [
|
||||
'singular' => 'Pengguna',
|
||||
'plural' => 'Pengguna',
|
||||
'description' => 'Kelola akun semua peran: tambah, ubah data, aktifkan atau nonaktifkan, dan atur ulang kata sandi.',
|
||||
];
|
||||
}
|
||||
|
||||
protected function search(): array
|
||||
{
|
||||
return ['nama', 'username', 'email'];
|
||||
}
|
||||
|
||||
protected function filters(): array
|
||||
{
|
||||
return [
|
||||
['name' => 'role', 'label' => 'Peran', 'options' => array_combine(SuperuserData::ROLES, SuperuserData::ROLES)],
|
||||
['name' => 'status', 'label' => 'Status', 'options' => ['Aktif' => 'Aktif', 'Nonaktif' => 'Nonaktif']],
|
||||
];
|
||||
}
|
||||
|
||||
protected function columns(): array
|
||||
{
|
||||
return [
|
||||
['label' => 'Nama', 'key' => 'nama'],
|
||||
['label' => 'Username', 'key' => 'username'],
|
||||
['label' => 'Peran', 'key' => 'role', 'badge' => fn (array $r): string => SuperuserData::ROLE_TONE[$r['role']] ?? 'neutral'],
|
||||
['label' => 'Email', 'key' => 'email'],
|
||||
['label' => 'Status', 'key' => 'status', 'badge' => fn (array $r): string => $r['aktif'] ? 'success' : 'danger'],
|
||||
['label' => 'Masuk terakhir', 'key' => 'terakhir'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function fields(?array $row): array
|
||||
{
|
||||
$editing = $row !== null;
|
||||
|
||||
return [
|
||||
['name' => 'nama', 'label' => 'Nama lengkap', 'section' => 'Identitas', 'span' => 'full', 'rules' => ['required', 'string', 'max:120']],
|
||||
['name' => 'username', 'label' => 'Username', 'section' => 'Identitas', 'hint' => 'Huruf, angka, titik, garis bawah, atau tanda hubung.', 'rules' => ['required', 'string', 'max:40', 'regex:/^[A-Za-z0-9._-]+$/']],
|
||||
['name' => 'email', 'label' => 'Email', 'type' => 'email', 'section' => 'Identitas', 'rules' => ['required', 'email', 'max:120']],
|
||||
['name' => 'role', 'label' => 'Peran', 'type' => 'select', 'section' => 'Akun', 'options' => array_combine(SuperuserData::ROLES, SuperuserData::ROLES), 'rules' => ['required', 'in:'.implode(',', SuperuserData::ROLES)]],
|
||||
['name' => 'password', 'label' => 'Kata sandi', 'type' => 'password', 'section' => 'Akun', 'optional' => $editing, 'hint' => $editing ? 'Kosongkan bila tidak diubah.' : 'Minimal 8 karakter, berisi huruf dan angka.', 'rules' => ['required', 'string', 'min:8']],
|
||||
['name' => 'aktif', 'label' => 'Akun aktif dan boleh masuk', 'type' => 'checkbox', 'section' => 'Akun', 'default' => true, 'span' => 'full'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function rowActions(array $row): array
|
||||
{
|
||||
return [['label' => 'Kata sandi', 'href' => route('superuser.pengguna.password', $row['username']), 'icon' => 'key']];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user