Pembaruan halaman Operator dan Mahasiswa
This commit is contained in:
@@ -7,13 +7,15 @@ use App\Http\Controllers\Operator\Concerns\ServesLegacyList;
|
||||
use App\Support\Legacy\AcademicOverview;
|
||||
use App\Support\Legacy\Administration;
|
||||
use App\Support\Legacy\Graduation;
|
||||
use App\Support\Legacy\GraduationWriter;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/** Perkuliahan > Data Tugas Akhir > Daftar Tugas Akhir (slug list_ta) untuk akun DB lama: t_skripsi prodi akun, hanya baca. */
|
||||
/** Perkuliahan > Data Tugas Akhir > Daftar Tugas Akhir (slug list_ta) untuk akun DB lama: t_skripsi prodi akun; tambah, ubah, hapus. */
|
||||
class TugasAkhirController extends Controller
|
||||
{
|
||||
use ServesLegacyList;
|
||||
@@ -24,6 +26,7 @@ class TugasAkhirController extends Controller
|
||||
private readonly AcademicOverview $overview,
|
||||
private readonly Graduation $graduation,
|
||||
private readonly Administration $admin,
|
||||
private readonly GraduationWriter $writer,
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
@@ -36,7 +39,7 @@ class TugasAkhirController extends Controller
|
||||
return view('operator.satu.remote-list', [
|
||||
'page' => $page,
|
||||
'crumbs' => $this->crumbs(self::SLUG, $page),
|
||||
'note' => 'Tugas akhir asli (t_skripsi) mahasiswa program studi yang Anda kelola: judul, pembimbing, penguji, tahap (lulus ujian bila tanggal lulus terisi), nilai dari mata kuliah tugas akhir. Tombol aksi belum mengubah data.',
|
||||
'note' => 'Tugas akhir asli (t_skripsi) mahasiswa program studi yang Anda kelola: judul, pembimbing, penguji, tahap (lulus ujian bila tanggal lulus terisi), nilai dari mata kuliah tugas akhir. Tambah, ubah, dan hapus langsung tersimpan di basis data (tugas akhir yang sudah lulus ujian tidak bisa dihapus).',
|
||||
'empty' => ['icon' => 'building-library', 'title' => 'Akun belum terhubung ke program studi', 'description' => 'Daftar tugas akhir tampil setelah akun Anda dipetakan ke program studi oleh Pusat Komputer.'],
|
||||
'url' => route('operator.tugas-akhir.data'),
|
||||
'filters' => [
|
||||
@@ -58,9 +61,103 @@ class TugasAkhirController extends Controller
|
||||
],
|
||||
'perPage' => Graduation::PER_PAGE,
|
||||
'data' => $prodi === [] ? null : $this->payload($this->search($request, $prodi)),
|
||||
'form' => $prodi === [] ? null : $this->form($prodi),
|
||||
'destroyUrl' => route('operator.tugas-akhir.destroy'),
|
||||
'destroy' => ['title' => 'Hapus tugas akhir terpilih?', 'message' => 'Tugas akhir yang sudah lulus ujian akan ditolak.'],
|
||||
]);
|
||||
}
|
||||
|
||||
/** @param list<int> $prodi */
|
||||
private function form(array $prodi): array
|
||||
{
|
||||
$lecturers = $this->graduation->lecturerOptions($prodi);
|
||||
|
||||
return [
|
||||
'title' => 'tugas akhir',
|
||||
'storeUrl' => route('operator.tugas-akhir.store'),
|
||||
'updateUrl' => route('operator.tugas-akhir.update', '__ID__'),
|
||||
'fields' => [
|
||||
['name' => 'nim', 'label' => 'NIM mahasiswa', 'type' => 'text', 'required' => true, 'max' => 30, 'hint' => 'Mahasiswa program studi Anda; tidak berubah saat Ubah.'],
|
||||
['name' => 'judul', 'label' => 'Judul tugas akhir', 'type' => 'text', 'required' => true, 'max' => 1000],
|
||||
['name' => 'pembimbing1', 'label' => 'Pembimbing 1', 'type' => 'select', 'options' => $lecturers],
|
||||
['name' => 'pembimbing2', 'label' => 'Pembimbing 2', 'type' => 'select', 'options' => $lecturers],
|
||||
['name' => 'penguji1', 'label' => 'Penguji 1', 'type' => 'select', 'options' => $lecturers],
|
||||
['name' => 'penguji2', 'label' => 'Penguji 2', 'type' => 'select', 'options' => $lecturers],
|
||||
['name' => 'mulai', 'label' => 'Tanggal mulai', 'type' => 'date'],
|
||||
['name' => 'lulus', 'label' => 'Tanggal lulus ujian', 'type' => 'date', 'hint' => 'Diisi bila ujian sudah lulus.'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$input = $this->validated($request, true);
|
||||
|
||||
try {
|
||||
$id = $this->writer->createThesis($prodi, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Tugas akhir ditambahkan.', 'id' => $id], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$input = $this->validated($request, false);
|
||||
|
||||
try {
|
||||
$this->writer->updateThesis($prodi, $id, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Tugas akhir diperbarui.']);
|
||||
}
|
||||
|
||||
/** Hapus satu atau beberapa tugas akhir (POST {ids}). */
|
||||
public function destroy(Request $request): JsonResponse
|
||||
{
|
||||
$prodi = $this->prodiOrFail($request);
|
||||
$ids = $request->validate(['ids' => ['required', 'array', 'min:1'], 'ids.*' => ['integer']], [], ['ids' => 'tugas akhir'])['ids'];
|
||||
|
||||
try {
|
||||
$deleted = $this->writer->deleteTheses($prodi, $ids);
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => "{$deleted} tugas akhir dihapus."]);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function validated(Request $request, bool $creating): array
|
||||
{
|
||||
return $request->validate([
|
||||
'nim' => [$creating ? 'required' : 'nullable', 'string', 'max:30'],
|
||||
'judul' => ['required', 'string', 'max:1000'],
|
||||
'pembimbing1' => ['nullable', 'integer'], 'pembimbing2' => ['nullable', 'integer'],
|
||||
'penguji1' => ['nullable', 'integer'], 'penguji2' => ['nullable', 'integer'],
|
||||
'mulai' => ['nullable', 'date_format:Y-m-d'],
|
||||
'lulus' => ['nullable', 'date_format:Y-m-d'],
|
||||
], [], [
|
||||
'nim' => 'NIM', 'judul' => 'judul tugas akhir', 'pembimbing1' => 'pembimbing 1', 'pembimbing2' => 'pembimbing 2',
|
||||
'penguji1' => 'penguji 1', 'penguji2' => 'penguji 2', 'mulai' => 'tanggal mulai', 'lulus' => 'tanggal lulus ujian',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @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;
|
||||
}
|
||||
|
||||
public function data(Request $request): JsonResponse
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
|
||||
Reference in New Issue
Block a user