Commit awal: prototipe UI SIAKAD Untan
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?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 MataKuliahController extends ResourceController
|
||||
{
|
||||
private const SIFAT = ['Wajib' => 'Wajib', 'Pilihan' => 'Pilihan'];
|
||||
|
||||
protected function rows(): Collection
|
||||
{
|
||||
return Sample::mataKuliah();
|
||||
}
|
||||
|
||||
protected function routeBase(): string
|
||||
{
|
||||
return 'admin.mata-kuliah';
|
||||
}
|
||||
|
||||
protected function names(): array
|
||||
{
|
||||
return ['singular' => 'Mata kuliah', 'plural' => 'Mata kuliah', 'description' => 'Katalog mata kuliah beserta SKS, semester, dan sifatnya.'];
|
||||
}
|
||||
|
||||
protected function keyName(): string
|
||||
{
|
||||
return 'kode';
|
||||
}
|
||||
|
||||
protected function search(): array
|
||||
{
|
||||
return ['kode', 'nama'];
|
||||
}
|
||||
|
||||
/** @return array<string, string> */
|
||||
private function prodiOptions(): array
|
||||
{
|
||||
return Sample::mataKuliah()->pluck('prodi')->unique()->sort()->mapWithKeys(fn (string $p): array => [$p => $p])->all();
|
||||
}
|
||||
|
||||
/** @return array<int, string> */
|
||||
private function semesterOptions(): array
|
||||
{
|
||||
return collect(range(1, 8))->mapWithKeys(fn (int $s): array => [$s => 'Semester '.$s])->all();
|
||||
}
|
||||
|
||||
protected function filters(): array
|
||||
{
|
||||
return [
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'options' => $this->prodiOptions()],
|
||||
['name' => 'semester', 'label' => 'Semester', 'options' => $this->semesterOptions()],
|
||||
['name' => 'sifat', 'label' => 'Sifat', 'options' => self::SIFAT],
|
||||
];
|
||||
}
|
||||
|
||||
protected function columns(): array
|
||||
{
|
||||
return [
|
||||
['label' => 'Kode', 'key' => 'kode'],
|
||||
['label' => 'Mata kuliah', 'key' => 'nama'],
|
||||
['label' => 'SKS', 'key' => 'sks', 'class' => 'num'],
|
||||
['label' => 'Semester', 'key' => 'semester', 'class' => 'num'],
|
||||
['label' => 'Sifat', 'key' => 'sifat', 'badge' => fn (array $r): string => $r['sifat'] === 'Wajib' ? 'accent' : 'gold'],
|
||||
['label' => 'Program studi', 'key' => 'prodi'],
|
||||
];
|
||||
}
|
||||
|
||||
protected function fields(?array $row): array
|
||||
{
|
||||
$prodi = $this->prodiOptions();
|
||||
|
||||
return [
|
||||
['name' => 'kode', 'label' => 'Kode mata kuliah', 'rules' => ['required', 'string', 'max:16']],
|
||||
['name' => 'nama', 'label' => 'Nama mata kuliah', 'rules' => ['required', 'string', 'max:150']],
|
||||
['name' => 'sks', 'label' => 'SKS', 'type' => 'number', 'rules' => ['required', 'integer', 'between:1,6'], 'attrs' => ['min' => 1, 'max' => 6]],
|
||||
['name' => 'semester', 'label' => 'Semester', 'type' => 'select', 'options' => $this->semesterOptions(), 'rules' => ['required', Rule::in(range(1, 8))]],
|
||||
['name' => 'sifat', 'label' => 'Sifat', 'type' => 'select', 'options' => self::SIFAT, 'rules' => ['required', Rule::in(array_keys(self::SIFAT))]],
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'type' => 'select', 'options' => $prodi, 'rules' => ['required', Rule::in(array_keys($prodi))]],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user