Pembaruan halaman Operator dan Mahasiswa
This commit is contained in:
@@ -3,9 +3,13 @@
|
||||
namespace App\Http\Controllers\Operator;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Operator\Concerns\ServesLegacyList;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\AcademicOverview;
|
||||
use App\Support\Legacy\Curriculum;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Legacy\StudentDirectory;
|
||||
use App\Support\Legacy\StudentRecords;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -20,11 +24,15 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class StudentListController extends Controller
|
||||
{
|
||||
use ServesLegacyList;
|
||||
|
||||
private const string SLUG = 'list_mahasiswa';
|
||||
|
||||
public function __construct(
|
||||
private readonly AcademicOverview $overview,
|
||||
private readonly StudentDirectory $directory,
|
||||
private readonly StudentRecords $records,
|
||||
private readonly Curriculum $curriculum,
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
@@ -37,7 +45,7 @@ class StudentListController extends Controller
|
||||
return view('operator.satu.remote-list', [
|
||||
'page' => $page,
|
||||
'crumbs' => ['Beranda' => route('operator.dashboard')] + array_fill_keys(Catalog::trail(self::SLUG), null) + [$page['title'] => null],
|
||||
'note' => 'Data mahasiswa asli dari SIAKAD untuk program studi yang Anda kelola. Tombol tambah, ubah, dan hapus belum mengubah data.',
|
||||
'note' => 'Data mahasiswa asli dari SIAKAD untuk program studi yang Anda kelola. Tambah, ubah, dan hapus langsung tersimpan di basis data; mahasiswa yang sudah punya data akademik, keuangan, atau akun login tidak dapat dihapus, dan NIM tidak dapat diubah.',
|
||||
'empty' => ['icon' => 'building-library', 'title' => 'Akun belum terhubung ke program studi', 'description' => 'Daftar mahasiswa tampil setelah akun Anda dipetakan ke program studi oleh Pusat Komputer.'],
|
||||
'url' => route('operator.mahasiswa.data'),
|
||||
'filters' => [
|
||||
@@ -60,9 +68,121 @@ class StudentListController extends Controller
|
||||
],
|
||||
'perPage' => StudentDirectory::PER_PAGE,
|
||||
'data' => $options === null ? null : $this->payload($this->search($request, $programs, $options)),
|
||||
'form' => $options === null ? null : $this->form($programs->all()),
|
||||
'destroyUrl' => $options === null ? null : route('operator.list-mahasiswa.destroy'),
|
||||
'destroy' => ['title' => 'Hapus mahasiswa?', 'message' => 'Hanya mahasiswa tanpa data akademik, keuangan, dan akun login yang dapat dihapus.'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$input = $this->validated($request);
|
||||
|
||||
try {
|
||||
$id = $this->records->create($prodi, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Mahasiswa ditambahkan.', 'id' => $id], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$input = $this->validated($request);
|
||||
|
||||
try {
|
||||
$this->records->update($prodi, $id, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Data mahasiswa diperbarui.']);
|
||||
}
|
||||
|
||||
/** Hapus satu atau beberapa mahasiswa (POST {ids}). */
|
||||
public function destroy(Request $request): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$ids = $request->validate(['ids' => ['required', 'array', 'min:1', 'max:100'], 'ids.*' => ['integer']], [], ['ids' => 'mahasiswa'])['ids'];
|
||||
|
||||
try {
|
||||
$deleted = $this->records->delete($prodi, $ids);
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => "{$deleted} mahasiswa dihapus."]);
|
||||
}
|
||||
|
||||
/** @return list<int> */
|
||||
private function prodiOrFail(Request $request): array
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
$prodi = $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
||||
abort_if($prodi === [], 404);
|
||||
|
||||
return $prodi;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function validated(Request $request): array
|
||||
{
|
||||
return $request->validate([
|
||||
'nim' => ['required', 'string', 'max:15'],
|
||||
'nama' => ['required', 'string', 'max:50'],
|
||||
'prodi' => ['required', 'integer'],
|
||||
'kurikulum' => ['required', 'integer'],
|
||||
'angkatan' => ['required', 'integer'],
|
||||
'program' => ['required', 'integer'],
|
||||
'jalur' => ['nullable', 'integer'],
|
||||
'kelamin' => ['required', 'integer', 'in:1,2'],
|
||||
'tmplahir' => ['nullable', 'string', 'max:30'],
|
||||
'tgllahir' => ['nullable', 'date'],
|
||||
'hp' => ['nullable', 'string', 'max:35'],
|
||||
'email' => ['nullable', 'string', 'email', 'max:50'],
|
||||
'status' => ['required', 'integer', 'in:1,2,3,4,5'],
|
||||
], [], [
|
||||
'nim' => 'NIM', 'nama' => 'nama', 'prodi' => 'program studi', 'kurikulum' => 'kurikulum', 'angkatan' => 'angkatan',
|
||||
'program' => 'program kuliah', 'jalur' => 'jalur masuk', 'kelamin' => 'jenis kelamin', 'tmplahir' => 'tempat lahir',
|
||||
'tgllahir' => 'tanggal lahir', 'hp' => 'no. HP', 'email' => 'email', 'status' => 'status',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formulir tambah/ubah (modal); pilihan kurikulum memuat seluruh kurikulum prodi akun.
|
||||
*
|
||||
* @param array<int, string> $programs
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function form(array $programs): array
|
||||
{
|
||||
$options = $this->records->options();
|
||||
|
||||
return [
|
||||
'title' => 'mahasiswa',
|
||||
'storeUrl' => route('operator.list-mahasiswa.store'),
|
||||
'updateUrl' => route('operator.list-mahasiswa.update', '__ID__'),
|
||||
'fields' => [
|
||||
['name' => 'nim', 'label' => 'NIM', 'type' => 'text', 'required' => true, 'max' => 15, 'hint' => 'Tidak dapat diubah setelah disimpan.'],
|
||||
['name' => 'nama', 'label' => 'Nama', 'type' => 'text', 'required' => true, 'max' => 50],
|
||||
['name' => 'prodi', 'label' => 'Program studi', 'type' => 'select', 'options' => $programs, 'required' => true],
|
||||
['name' => 'kurikulum', 'label' => 'Kurikulum', 'type' => 'select', 'options' => $this->curriculum->curricula(array_keys($programs))->all(), 'required' => true, 'hint' => 'Pilih kurikulum milik program studi yang sama.'],
|
||||
['name' => 'angkatan', 'label' => 'Angkatan', 'type' => 'select', 'options' => $options['angkatan'], 'required' => true],
|
||||
['name' => 'program', 'label' => 'Program kuliah', 'type' => 'select', 'options' => $options['program'], 'required' => true],
|
||||
['name' => 'jalur', 'label' => 'Jalur masuk', 'type' => 'select', 'options' => $options['jalur']],
|
||||
['name' => 'kelamin', 'label' => 'Jenis kelamin', 'type' => 'select', 'options' => StudentRecords::GENDER, 'required' => true],
|
||||
['name' => 'tmplahir', 'label' => 'Tempat lahir', 'type' => 'text', 'max' => 30],
|
||||
['name' => 'tgllahir', 'label' => 'Tanggal lahir', 'type' => 'date'],
|
||||
['name' => 'hp', 'label' => 'No. HP', 'type' => 'text', 'max' => 35],
|
||||
['name' => 'email', 'label' => 'Email', 'type' => 'text', 'max' => 50],
|
||||
['name' => 'status', 'label' => 'Status', 'type' => 'select', 'options' => StudentRecords::STATUS, 'required' => true, 'default' => 1, 'hint' => 'Status Lulus ditetapkan lewat yudisium.'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/** JSON untuk tabel (satuRemoteTable). Hanya akun DB lama yang memegang prodi. */
|
||||
public function data(Request $request): JsonResponse
|
||||
{
|
||||
@@ -104,7 +224,8 @@ class StudentListController extends Controller
|
||||
{
|
||||
return [
|
||||
'rows' => collect($rows->items())->map(fn (array $m): array => [
|
||||
'id' => $m['nim'],
|
||||
'id' => $m['id'],
|
||||
'form' => $m['form'],
|
||||
'nim' => $m['nim'],
|
||||
'nama' => $m['nama'],
|
||||
'jenjang' => $m['jenjang'] ?? '–',
|
||||
|
||||
Reference in New Issue
Block a user