Commit awal: prototipe UI SIAKAD Untan
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operator;
|
||||
|
||||
use App\Http\Controllers\Prototype\ResourceController;
|
||||
use App\Support\Prototype\Sample;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
/** Data mahasiswa dan perubahan status akademik (aktif, cuti, lulus, drop out). */
|
||||
class MahasiswaController extends ResourceController
|
||||
{
|
||||
private const STATUS = ['Aktif', 'Cuti', 'Lulus', 'Drop out'];
|
||||
|
||||
protected function rows(): Collection
|
||||
{
|
||||
return Sample::mahasiswa();
|
||||
}
|
||||
|
||||
protected function routeBase(): string
|
||||
{
|
||||
return 'operator.mahasiswa';
|
||||
}
|
||||
|
||||
protected function keyName(): string
|
||||
{
|
||||
return 'nim';
|
||||
}
|
||||
|
||||
protected function names(): array
|
||||
{
|
||||
return [
|
||||
'singular' => 'Mahasiswa',
|
||||
'plural' => 'Mahasiswa',
|
||||
'description' => 'Data mahasiswa dan status akademiknya. Ubah status untuk mencatat cuti atau kembali aktif.',
|
||||
];
|
||||
}
|
||||
|
||||
protected function abilities(): array
|
||||
{
|
||||
return ['create' => true, 'show' => true, 'edit' => true, 'delete' => false];
|
||||
}
|
||||
|
||||
protected function search(): array
|
||||
{
|
||||
return ['nama', 'nim'];
|
||||
}
|
||||
|
||||
protected function filters(): array
|
||||
{
|
||||
$angkatan = Sample::mahasiswa()->pluck('angkatan')->unique()->sort()->mapWithKeys(fn (int $a): array => [(string) $a => (string) $a])->all();
|
||||
|
||||
return [
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'options' => $this->prodiOptions()],
|
||||
['name' => 'status', 'label' => 'Status', 'options' => array_combine(self::STATUS, self::STATUS)],
|
||||
['name' => 'angkatan', 'label' => 'Angkatan', 'options' => $angkatan],
|
||||
];
|
||||
}
|
||||
|
||||
protected function columns(): array
|
||||
{
|
||||
return [
|
||||
['label' => 'Nama', 'key' => 'nama'],
|
||||
['label' => 'NIM', 'key' => 'nim'],
|
||||
['label' => 'Program studi', 'key' => 'prodi'],
|
||||
['label' => 'Angkatan', 'key' => 'angkatan'],
|
||||
['label' => 'Status', 'key' => 'status', 'badge' => fn (array $r): string => self::tone($r['status'])],
|
||||
['label' => 'IPK', 'class' => 'num', 'value' => fn (array $r): string => number_format($r['ipk'], 2, ',', '.')],
|
||||
];
|
||||
}
|
||||
|
||||
protected function details(array $row): array
|
||||
{
|
||||
return [
|
||||
'Nama' => $row['nama'],
|
||||
'NIM' => $row['nim'],
|
||||
'Program studi' => $row['prodi'],
|
||||
'Angkatan' => $row['angkatan'],
|
||||
'Status akademik' => $row['status'],
|
||||
'IPK' => number_format($row['ipk'], 2, ',', '.'),
|
||||
'SKS ditempuh' => $row['sks'],
|
||||
'Dosen pembimbing akademik' => $row['pa'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function fields(?array $row): array
|
||||
{
|
||||
$dosen = Sample::dosen()->pluck('nama', 'nama')->all();
|
||||
|
||||
return [
|
||||
['name' => 'nim', 'label' => 'NIM', 'section' => 'Identitas', 'attrs' => ['maxlength' => 16], 'rules' => ['required', 'string', 'max:16']],
|
||||
['name' => 'nama', 'label' => 'Nama lengkap', 'section' => 'Identitas', 'rules' => ['required', 'string', 'max:120']],
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'type' => 'select', 'section' => 'Akademik', 'options' => $this->prodiOptions(), 'rules' => ['required', Rule::in(array_keys($this->prodiOptions()))]],
|
||||
['name' => 'angkatan', 'label' => 'Angkatan', 'type' => 'number', 'section' => 'Akademik', 'attrs' => ['min' => 2010, 'max' => 2026], 'rules' => ['required', 'integer', 'min:2010', 'max:2026']],
|
||||
['name' => 'status', 'label' => 'Status akademik', 'type' => 'select', 'section' => 'Akademik', 'options' => array_combine(self::STATUS, self::STATUS), 'hint' => 'Pilih Cuti untuk mahasiswa yang menjalani cuti akademik.', 'rules' => ['required', Rule::in(self::STATUS)]],
|
||||
['name' => 'pa', 'label' => 'Dosen pembimbing akademik', 'type' => 'select', 'section' => 'Akademik', 'options' => $dosen, 'rules' => ['required', Rule::in(array_keys($dosen))]],
|
||||
];
|
||||
}
|
||||
|
||||
private static function tone(string $status): string
|
||||
{
|
||||
return ['Aktif' => 'success', 'Cuti' => 'gold', 'Lulus' => 'accent', 'Drop out' => 'danger'][$status] ?? 'neutral';
|
||||
}
|
||||
|
||||
/** @return array<string, string> */
|
||||
private function prodiOptions(): array
|
||||
{
|
||||
return Sample::prodi()->pluck('nama', 'nama')->all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user