[Operator] Perbaikan Laman Portal -> Konsultasi
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operator;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Operator\Concerns\ServesLegacyList;
|
||||
use App\Support\Legacy\AcademicOverview;
|
||||
use App\Support\Legacy\EmployeeBiodata;
|
||||
use App\Support\Legacy\EmployeeDirectory;
|
||||
use App\Support\Legacy\LegacyFormat;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Detail pegawai (aksi Lihat pada Portal > Pegawai) untuk akun DB lama: ringkasan, biodata lengkap per bagian (pribadi,
|
||||
* kontak, kepegawaian, pendidikan dan rekening, data dosen), dan penyimpanan per bagian lewat JSON. Hanya pegawai dalam
|
||||
* cakupan daftar (dosen home base prodi akun atau pemegang jabatan aktif di prodi/fakultas akun).
|
||||
*/
|
||||
class EmployeeDetailController extends Controller
|
||||
{
|
||||
use ServesLegacyList;
|
||||
|
||||
private const string SLUG = 'list_pegawai';
|
||||
|
||||
public function __construct(
|
||||
private readonly AcademicOverview $overview,
|
||||
private readonly EmployeeDirectory $directory,
|
||||
private readonly EmployeeBiodata $biodata,
|
||||
) {}
|
||||
|
||||
public function show(Request $request, int $id): View
|
||||
{
|
||||
[$prodi, $faculties] = $this->scope($request);
|
||||
$bio = $this->biodata->find($prodi, $faculties, $id) ?? abort(404);
|
||||
$page = Catalog::page(self::SLUG);
|
||||
$sections = $bio['sections'];
|
||||
$extra = $bio['extra'];
|
||||
|
||||
// Keterangan hanya dibaca di bagian Kepegawaian.
|
||||
$sections['kepegawaian']['readonly'] = [['name' => 'jenis', 'label' => 'Jenis pegawai'], ['name' => 'jabatan', 'label' => 'Jabatan aktif']];
|
||||
$sections['kepegawaian']['display'] += ['jenis' => $extra['jenis'] ?? '–', 'jabatan' => $extra['jabatan'] === [] ? '–' : implode('; ', $extra['jabatan'])];
|
||||
|
||||
$v = $sections['pribadi']['values'];
|
||||
|
||||
return view('operator.satu.pegawai-detail', [
|
||||
'page' => $page,
|
||||
'crumbs' => ['Beranda' => route('operator.dashboard')] + array_fill_keys(Catalog::trail(self::SLUG), null) + [$page['title'] => route('operator.halaman', self::SLUG), 'Detail' => null],
|
||||
'sections' => $sections,
|
||||
'extra' => $extra,
|
||||
'name' => LegacyFormat::pegawaiName($v['gelardepan'], $v['nama'], $v['gelarbelakang']),
|
||||
'back' => route('operator.halaman', self::SLUG),
|
||||
'saveUrl' => route('operator.list-pegawai.biodata', [$id, '__SECTION__']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id, string $section): JsonResponse
|
||||
{
|
||||
[$prodi, $faculties] = $this->scope($request);
|
||||
abort_unless(in_array($section, EmployeeBiodata::sectionKeys(), true) && $this->biodata->exists($prodi, $faculties, $id), 404);
|
||||
|
||||
try {
|
||||
$input = $this->biodata->validated($prodi, $faculties, $id, $section, $request->all());
|
||||
$result = $this->biodata->update($prodi, $faculties, $id, $section, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => $result['changed'] === 0 ? 'Tidak ada perubahan.' : 'Biodata diperbarui.',
|
||||
'values' => $result['section']['values'],
|
||||
'display' => $result['section']['display'],
|
||||
]);
|
||||
}
|
||||
|
||||
/** @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)];
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,8 @@ class EmployeeListController extends Controller
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
{
|
||||
$page = Catalog::page(self::SLUG);
|
||||
// Template SATU Pegawai tidak punya Tambah dan Hapus di bilah; keduanya dipasang di sini karena sudah bekerja.
|
||||
$page = ['flags' => 'TH'] + Catalog::page(self::SLUG);
|
||||
$iduser = (int) $request->user()->getKey();
|
||||
$programs = $this->overview->programs($iduser);
|
||||
[$labelAdvisor, $labelActive, $labelStatus] = $page['filters'];
|
||||
@@ -41,9 +42,13 @@ 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. Ubah dan hapus langsung tersimpan di basis data; pegawai yang masih dirujuk jabatan, jadwal, bimbingan, skripsi, atau akun login tidak dapat dihapus.',
|
||||
'note' => 'Data pegawai asli dari SIAKAD untuk program studi dan fakultas yang Anda kelola. Tambah dan hapus langsung tersimpan di basis data; pegawai baru ditambahkan sebagai dosen dengan home base program studi Anda, dan pegawai yang masih dirujuk jabatan, jadwal, bimbingan, skripsi, atau akun login tidak dapat dihapus. Pilih Lihat untuk biodata lengkap; perubahan data dilakukan di dalam halaman detail.',
|
||||
'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'),
|
||||
'viewUrl' => route('operator.list-pegawai.show', '__ID__'),
|
||||
// Hanya Tambah dan Hapus di bilah (tanpa Cetak) dan tanpa Ubah di baris: biodata diubah di halaman detail.
|
||||
'tools' => ['T', 'H'],
|
||||
'editable' => false,
|
||||
'filters' => [
|
||||
['name' => 'advisor', 'label' => $labelAdvisor, 'options' => EmployeeDirectory::ADVISOR_OPTIONS],
|
||||
['name' => 'active', 'label' => $labelActive, 'options' => EmployeeDirectory::ACTIVE_OPTIONS],
|
||||
@@ -61,24 +66,26 @@ 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(),
|
||||
'form' => $programs->isEmpty() ? null : $this->form($programs->all()),
|
||||
'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
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
[$prodi, $faculties] = $this->scope($request);
|
||||
$input = $this->validated($request);
|
||||
[$prodi] = $this->scope($request);
|
||||
// Home base diperiksa bersama isian lain agar semua galat tampil sekaligus.
|
||||
$input = $this->validated($request, creating: true);
|
||||
$homeBase = (int) $input['prodi'];
|
||||
|
||||
try {
|
||||
$this->records->update($prodi, $faculties, $id, $input, (string) $request->user()->username, $request->ip());
|
||||
$id = $this->records->create($prodi, $homeBase, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Data pegawai diperbarui.']);
|
||||
return response()->json(['message' => 'Pegawai ditambahkan.', 'id' => $id], 201);
|
||||
}
|
||||
|
||||
/** Hapus satu atau beberapa pegawai (POST {ids}). */
|
||||
@@ -108,9 +115,15 @@ class EmployeeListController extends Controller
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function validated(Request $request): array
|
||||
private function validated(Request $request, bool $creating = false): array
|
||||
{
|
||||
return $request->validate([
|
||||
return $request->validate($creating ? ['prodi' => ['required', 'integer']] + $this->rules() : $this->rules(), [], $this->attributes() + ['prodi' => 'home base']);
|
||||
}
|
||||
|
||||
/** @return array<string, list<string>> */
|
||||
private function rules(): array
|
||||
{
|
||||
return [
|
||||
'nip' => ['required', 'string', 'max:20'],
|
||||
'nama' => ['required', 'string', 'max:50'],
|
||||
'gelardepan' => ['nullable', 'string', 'max:20'],
|
||||
@@ -122,24 +135,32 @@ class EmployeeListController extends Controller
|
||||
'email' => ['nullable', 'string', 'email', 'max:125'],
|
||||
'status' => ['nullable', 'integer'],
|
||||
'aktif' => ['required', 'integer', 'in:0,1'],
|
||||
], [], [
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string, string> */
|
||||
private function attributes(): array
|
||||
{
|
||||
return [
|
||||
'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.
|
||||
* Formulir tambah (modal; tidak ada ubah di daftar). Biodata lengkap diubah di
|
||||
* halaman detail.
|
||||
*
|
||||
* @param array<int, string> $programs
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function form(): array
|
||||
private function form(array $programs): array
|
||||
{
|
||||
return [
|
||||
'title' => 'pegawai',
|
||||
'storeUrl' => null,
|
||||
'updateUrl' => route('operator.list-pegawai.update', '__ID__'),
|
||||
'storeUrl' => route('operator.list-pegawai.store'),
|
||||
'fields' => [
|
||||
['name' => 'prodi', 'label' => 'Home base (program studi)', 'type' => 'select', 'options' => $programs, 'required' => true, 'hint' => 'Pegawai baru ditambahkan sebagai dosen pada program studi ini.'],
|
||||
['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],
|
||||
@@ -195,7 +216,6 @@ 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