Pembaruan halaman Operator dan Mahasiswa
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
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\EmployeeDirectory;
|
||||
use App\Support\Legacy\EmployeeRecords;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -18,11 +21,14 @@ use Illuminate\Pagination\LengthAwarePaginator;
|
||||
*/
|
||||
class EmployeeListController extends Controller
|
||||
{
|
||||
use ServesLegacyList;
|
||||
|
||||
private const string SLUG = 'list_pegawai';
|
||||
|
||||
public function __construct(
|
||||
private readonly AcademicOverview $overview,
|
||||
private readonly EmployeeDirectory $directory,
|
||||
private readonly EmployeeRecords $records,
|
||||
) {}
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
@@ -35,7 +41,7 @@ class EmployeeListController 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 pegawai asli dari SIAKAD untuk program studi dan fakultas yang Anda kelola. Tombol aksi belum mengubah data.',
|
||||
'note' => 'Data pegawai asli dari SIAKAD untuk program studi dan fakultas yang Anda kelola. Ubah dan hapus langsung tersimpan di basis data; pegawai yang masih dirujuk jabatan, jadwal, bimbingan, skripsi, atau akun login tidak dapat dihapus.',
|
||||
'empty' => ['icon' => 'building-library', 'title' => 'Akun belum terhubung ke program studi', 'description' => 'Daftar pegawai tampil setelah akun Anda dipetakan ke program studi oleh Pusat Komputer.'],
|
||||
'url' => route('operator.pegawai.data'),
|
||||
'filters' => [
|
||||
@@ -55,9 +61,100 @@ class EmployeeListController extends Controller
|
||||
],
|
||||
'perPage' => EmployeeDirectory::PER_PAGE,
|
||||
'data' => $programs->isEmpty() ? null : $this->payload($this->search($request, $iduser, $programs->keys()->all())),
|
||||
'form' => $programs->isEmpty() ? null : $this->form(),
|
||||
'destroyUrl' => $programs->isEmpty() ? null : route('operator.list-pegawai.destroy'),
|
||||
'destroy' => ['title' => 'Hapus pegawai?', 'message' => 'Hanya pegawai yang tidak dirujuk jabatan, jadwal, bimbingan, skripsi, atau akun login yang dapat dihapus.'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
[$prodi, $faculties] = $this->scope($request);
|
||||
$input = $this->validated($request);
|
||||
|
||||
try {
|
||||
$this->records->update($prodi, $faculties, $id, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Data pegawai diperbarui.']);
|
||||
}
|
||||
|
||||
/** Hapus satu atau beberapa pegawai (POST {ids}). */
|
||||
public function destroy(Request $request): JsonResponse
|
||||
{
|
||||
[$prodi, $faculties] = $this->scope($request);
|
||||
$ids = $request->validate(['ids' => ['required', 'array', 'min:1', 'max:100'], 'ids.*' => ['integer']], [], ['ids' => 'pegawai'])['ids'];
|
||||
|
||||
try {
|
||||
$deleted = $this->records->delete($prodi, $faculties, $ids);
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => "{$deleted} pegawai dihapus."]);
|
||||
}
|
||||
|
||||
/** @return array{0: list<int>, 1: list<int>} prodi dan fakultas akun */
|
||||
private function scope(Request $request): array
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
$iduser = (int) $request->user()->getKey();
|
||||
$prodi = $this->overview->programs($iduser)->keys()->all();
|
||||
abort_if($prodi === [], 404);
|
||||
|
||||
return [$prodi, $this->directory->faculties($iduser)];
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function validated(Request $request): array
|
||||
{
|
||||
return $request->validate([
|
||||
'nip' => ['required', 'string', 'max:20'],
|
||||
'nama' => ['required', 'string', 'max:50'],
|
||||
'gelardepan' => ['nullable', 'string', 'max:20'],
|
||||
'gelarbelakang' => ['nullable', 'string', 'max:25'],
|
||||
'kelamin' => ['nullable', 'integer', 'in:1,2'],
|
||||
'nidn' => ['nullable', 'string', 'max:25'],
|
||||
'hp' => ['nullable', 'string', 'max:20'],
|
||||
'telepon' => ['nullable', 'string', 'max:15'],
|
||||
'email' => ['nullable', 'string', 'email', 'max:125'],
|
||||
'status' => ['nullable', 'integer'],
|
||||
'aktif' => ['required', 'integer', 'in:0,1'],
|
||||
], [], [
|
||||
'nip' => 'NIP', 'nama' => 'nama', 'gelardepan' => 'gelar depan', 'gelarbelakang' => 'gelar belakang', 'kelamin' => 'jenis kelamin',
|
||||
'nidn' => 'NIDN', 'hp' => 'no. HP', 'telepon' => 'no. telepon', 'email' => 'email', 'status' => 'status kepegawaian', 'aktif' => 'status aktif',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formulir ubah (modal); template SATU tidak punya tombol Tambah untuk Pegawai.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function form(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'pegawai',
|
||||
'storeUrl' => null,
|
||||
'updateUrl' => route('operator.list-pegawai.update', '__ID__'),
|
||||
'fields' => [
|
||||
['name' => 'nip', 'label' => 'NIP', 'type' => 'text', 'required' => true, 'max' => 20],
|
||||
['name' => 'nama', 'label' => 'Nama', 'type' => 'text', 'required' => true, 'max' => 50],
|
||||
['name' => 'gelardepan', 'label' => 'Gelar depan', 'type' => 'text', 'max' => 20],
|
||||
['name' => 'gelarbelakang', 'label' => 'Gelar belakang', 'type' => 'text', 'max' => 25],
|
||||
['name' => 'kelamin', 'label' => 'Jenis kelamin', 'type' => 'select', 'options' => EmployeeRecords::GENDER],
|
||||
['name' => 'nidn', 'label' => 'NIDN', 'type' => 'text', 'max' => 25],
|
||||
['name' => 'hp', 'label' => 'No. HP', 'type' => 'text', 'max' => 20],
|
||||
['name' => 'telepon', 'label' => 'No. telepon', 'type' => 'text', 'max' => 15],
|
||||
['name' => 'email', 'label' => 'Email', 'type' => 'text', 'max' => 125],
|
||||
['name' => 'status', 'label' => 'Status kepegawaian', 'type' => 'select', 'options' => $this->records->statusOptions()],
|
||||
['name' => 'aktif', 'label' => 'Status aktif', 'type' => 'select', 'options' => EmployeeRecords::ACTIVE, 'required' => true, 'default' => 1],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/** JSON untuk tabel (satuRemoteTable). Hanya akun DB lama yang memegang prodi. */
|
||||
public function data(Request $request): JsonResponse
|
||||
{
|
||||
@@ -98,6 +195,7 @@ class EmployeeListController extends Controller
|
||||
return [
|
||||
'rows' => collect($rows->items())->map(fn (array $p): array => [
|
||||
'id' => $p['id'],
|
||||
'form' => $p['form'],
|
||||
'nip' => $dash($p['nip']),
|
||||
'nama' => $p['nama'],
|
||||
'kelamin' => $dash($p['kelamin']),
|
||||
|
||||
Reference in New Issue
Block a user