Commit awal: prototipe UI SIAKAD Untan
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Prototype\ResourceController;
|
||||
use App\Support\Prototype\Sample;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class MahasiswaController extends ResourceController
|
||||
{
|
||||
private const STATUS = ['Aktif' => 'Aktif', 'Cuti' => 'Cuti', 'Lulus' => 'Lulus', 'Drop out' => 'Drop out'];
|
||||
|
||||
protected function rows(): Collection
|
||||
{
|
||||
return Sample::mahasiswa();
|
||||
}
|
||||
|
||||
protected function routeBase(): string
|
||||
{
|
||||
return 'admin.mahasiswa';
|
||||
}
|
||||
|
||||
protected function names(): array
|
||||
{
|
||||
return ['singular' => 'Mahasiswa', 'plural' => 'Mahasiswa', 'description' => 'Data mahasiswa, status akademik, IPK, dan dosen pembimbing akademik.'];
|
||||
}
|
||||
|
||||
protected function keyName(): string
|
||||
{
|
||||
return 'nim';
|
||||
}
|
||||
|
||||
protected function search(): array
|
||||
{
|
||||
return ['nim', 'nama'];
|
||||
}
|
||||
|
||||
/** @return array<string, string> */
|
||||
private function prodiOptions(): array
|
||||
{
|
||||
return Sample::prodi()->pluck('nama', 'nama')->all();
|
||||
}
|
||||
|
||||
protected function filters(): array
|
||||
{
|
||||
return [
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'options' => $this->prodiOptions()],
|
||||
['name' => 'angkatan', 'label' => 'Angkatan', 'options' => Sample::mahasiswa()->pluck('angkatan')->unique()->sortDesc()->mapWithKeys(fn (int $a): array => [$a => (string) $a])->all()],
|
||||
['name' => 'status', 'label' => 'Status', 'options' => self::STATUS],
|
||||
];
|
||||
}
|
||||
|
||||
protected function columns(): array
|
||||
{
|
||||
return [
|
||||
['label' => 'NIM', 'key' => 'nim'],
|
||||
['label' => 'Nama', 'key' => 'nama'],
|
||||
['label' => 'Program studi', 'key' => 'prodi'],
|
||||
['label' => 'Angkatan', 'key' => 'angkatan', 'class' => 'num'],
|
||||
['label' => 'Status', 'key' => 'status', 'badge' => fn (array $r): string => match ($r['status']) {
|
||||
'Aktif' => 'success', 'Lulus' => 'accent', 'Cuti' => 'gold', default => 'danger',
|
||||
}],
|
||||
['label' => 'IPK', 'value' => fn (array $r): string => number_format($r['ipk'], 2, ',', '.'), 'class' => 'num'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function details(array $row): array
|
||||
{
|
||||
return [
|
||||
'NIM' => $row['nim'],
|
||||
'Nama' => $row['nama'],
|
||||
'Program studi' => $row['prodi'],
|
||||
'Angkatan' => $row['angkatan'],
|
||||
'Status' => $row['status'],
|
||||
'IPK' => number_format($row['ipk'], 2, ',', '.'),
|
||||
'SKS ditempuh' => $row['sks'],
|
||||
'Dosen pembimbing akademik' => $row['pa'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function fields(?array $row): array
|
||||
{
|
||||
$prodi = $this->prodiOptions();
|
||||
$dosen = Sample::dosen()->pluck('nama', 'nama')->all();
|
||||
|
||||
return [
|
||||
['name' => 'nim', 'label' => 'NIM', 'rules' => ['required', 'string', 'max:20'], 'section' => 'Identitas'],
|
||||
['name' => 'nama', 'label' => 'Nama lengkap', 'rules' => ['required', 'string', 'max:150'], 'section' => 'Identitas'],
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'type' => 'select', 'options' => $prodi, 'rules' => ['required', Rule::in(array_keys($prodi))], 'section' => 'Akademik'],
|
||||
['name' => 'angkatan', 'label' => 'Angkatan', 'type' => 'number', 'rules' => ['required', 'integer', 'between:2000,2100'], 'attrs' => ['min' => 2000, 'max' => 2100], 'section' => 'Akademik'],
|
||||
['name' => 'status', 'label' => 'Status', 'type' => 'select', 'options' => self::STATUS, 'rules' => ['required', Rule::in(array_keys(self::STATUS))], 'section' => 'Akademik'],
|
||||
['name' => 'pa', 'label' => 'Dosen pembimbing akademik', 'type' => 'select', 'options' => $dosen, 'rules' => ['required', Rule::in(array_keys($dosen))], 'section' => 'Akademik'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user