Commit awal: prototipe UI SIAKAD Untan
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enums\Role;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\Prototype\Sample;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): View
|
||||
{
|
||||
$role = Role::Admin;
|
||||
$user = $request->user()->loadMissing($role->profileRelation());
|
||||
$profile = $user->{$role->profileRelation()};
|
||||
|
||||
// Label => nilai; kolom kosong dilewati.
|
||||
$details = array_map(strval(...), array_filter([
|
||||
'Username' => $user->username,
|
||||
$role->identifierLabel() => $profile?->nip,
|
||||
'Jabatan' => $profile?->jabatan,
|
||||
'Unit kerja' => $profile?->unit_kerja,
|
||||
], fn (mixed $value): bool => $value !== null));
|
||||
|
||||
$fakultas = Sample::fakultas();
|
||||
$perStatus = Sample::mahasiswa()->countBy('status');
|
||||
$today = today()->toDateString();
|
||||
|
||||
return view('admin.dashboard', [
|
||||
'user' => $user,
|
||||
'details' => $details,
|
||||
'stats' => [
|
||||
'fakultas' => $fakultas->count(),
|
||||
'prodi' => Sample::prodi()->count(),
|
||||
'dosen' => Sample::dosen()->count(),
|
||||
'mahasiswa' => (int) $fakultas->sum('mahasiswa'),
|
||||
'mataKuliah' => Sample::mataKuliah()->count(),
|
||||
],
|
||||
'fakultasLabels' => $fakultas->pluck('kode')->all(),
|
||||
'fakultasData' => $fakultas->pluck('mahasiswa')->all(),
|
||||
'statusLabels' => $perStatus->keys()->all(),
|
||||
'statusData' => $perStatus->values()->all(),
|
||||
'tahun' => Sample::tahunAkademik()->firstWhere('aktif', true),
|
||||
'pengumuman' => Sample::pengumuman()->where('status', 'Terbit')->sortByDesc('tanggal')->take(3)->values(),
|
||||
'agenda' => Sample::kalender()->filter(fn (array $e): bool => ($e['selesai'] ?? $e['mulai']) >= $today)->sortBy('mulai')->take(4)->values(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user