Commit awal: prototipe UI SIAKAD Untan
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Prototype\ResourceController;
|
||||
use App\Support\Prototype\Sample;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class KalenderController extends ResourceController
|
||||
{
|
||||
private const KATEGORI = [
|
||||
'Registrasi dan KRS' => 'Registrasi dan KRS', 'Perkuliahan' => 'Perkuliahan', 'Ujian' => 'Ujian',
|
||||
'Libur' => 'Libur', 'Penilaian' => 'Penilaian', 'Administrasi' => 'Administrasi',
|
||||
];
|
||||
|
||||
/** Kegiatan contoh diberi nomor urut sebagai pengenal. */
|
||||
protected function rows(): Collection
|
||||
{
|
||||
return Sample::kalender()->sortBy('mulai')->values()->map(fn (array $e, int $i): array => ['id' => $i + 1, ...$e]);
|
||||
}
|
||||
|
||||
protected function routeBase(): string
|
||||
{
|
||||
return 'admin.kalender';
|
||||
}
|
||||
|
||||
protected function names(): array
|
||||
{
|
||||
return ['singular' => 'Kegiatan', 'plural' => 'Kelola kalender akademik', 'description' => 'Atur kegiatan pada kalender akademik yang tampil bagi seluruh pengguna.'];
|
||||
}
|
||||
|
||||
protected function search(): array
|
||||
{
|
||||
return ['judul'];
|
||||
}
|
||||
|
||||
protected function filters(): array
|
||||
{
|
||||
return [['name' => 'kategori', 'label' => 'Kategori', 'options' => self::KATEGORI]];
|
||||
}
|
||||
|
||||
private function tanggal(?string $tanggal): string
|
||||
{
|
||||
return $tanggal ? Carbon::parse($tanggal)->locale('id')->isoFormat('D MMM YYYY') : '-';
|
||||
}
|
||||
|
||||
protected function columns(): array
|
||||
{
|
||||
return [
|
||||
['label' => 'Kegiatan', 'key' => 'judul'],
|
||||
['label' => 'Kategori', 'key' => 'kategori', 'badge' => fn (array $r): string => $r['tone']],
|
||||
['label' => 'Mulai', 'value' => fn (array $r): string => $this->tanggal($r['mulai'])],
|
||||
['label' => 'Selesai', 'value' => fn (array $r): string => $this->tanggal($r['selesai'])],
|
||||
];
|
||||
}
|
||||
|
||||
protected function fields(?array $row): array
|
||||
{
|
||||
return [
|
||||
['name' => 'judul', 'label' => 'Nama kegiatan', 'rules' => ['required', 'string', 'max:200'], 'span' => 'full'],
|
||||
['name' => 'kategori', 'label' => 'Kategori', 'type' => 'select', 'options' => self::KATEGORI, 'rules' => ['required', Rule::in(array_keys(self::KATEGORI))], 'span' => 'full'],
|
||||
['name' => 'mulai', 'label' => 'Tanggal mulai', 'type' => 'date', 'rules' => ['required', 'date']],
|
||||
['name' => 'selesai', 'label' => 'Tanggal selesai', 'type' => 'date', 'rules' => ['date', 'after_or_equal:mulai'], 'optional' => true, 'hint' => 'Kosongkan bila kegiatan satu hari.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user