Integrasi Menu Laporan Operator
This commit is contained in:
@@ -42,6 +42,8 @@ trait ServesLegacyList
|
||||
|
||||
protected function query(Request $request): string
|
||||
{
|
||||
return mb_substr(trim((string) $request->string('q')), 0, 100);
|
||||
$q = $request->input('q');
|
||||
|
||||
return is_string($q) ? mb_substr(trim($q), 0, 100) : '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,20 @@ namespace App\Http\Controllers\Operator;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Operator\Concerns\ServesLegacyList;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Legacy\ReferenceData;
|
||||
use App\Support\Legacy\ReferenceWriter;
|
||||
use App\Support\Legacy\ReferenceWriters;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* Data Pelengkap (tabel referensi SATU) untuk akun DB lama: satu pengendali untuk semua slug yang punya sumber data
|
||||
* (ReferenceData::LISTS + data perguruan tinggi). Hanya baca; baris diambil lewat data() (JSON).
|
||||
* (ReferenceData::LISTS + data perguruan tinggi). Baris diambil lewat data() (JSON); tambah/ubah/hapus lewat penulis
|
||||
* (ReferenceWriters) untuk slug yang boleh ditulis, sisanya hanya baca.
|
||||
*/
|
||||
class DataPelengkapController extends Controller
|
||||
{
|
||||
@@ -35,17 +40,29 @@ class DataPelengkapController extends Controller
|
||||
|
||||
abort_unless(ReferenceData::isList($slug), 404);
|
||||
$definition = $this->reference->definition($slug);
|
||||
$writer = ReferenceWriters::for($slug);
|
||||
$abilities = $writer?->abilities($slug);
|
||||
$form = $writer && ($abilities['create'] || $abilities['update']) ? $writer->form($slug) : null;
|
||||
|
||||
return view('operator.satu.remote-list', [
|
||||
'page' => $page,
|
||||
'page' => $writer ? $this->withTools($page, $abilities) : $page,
|
||||
'crumbs' => $this->crumbs($slug, $page),
|
||||
'note' => $definition['note'].' Tombol aksi belum mengubah data.',
|
||||
'note' => $definition['note'].' '.$this->capabilityNote($abilities),
|
||||
'empty' => ['icon' => 'circle-stack', 'title' => 'Belum ada data', 'description' => 'Data tampil setelah tabel sumbernya terisi.'],
|
||||
'url' => route('operator.pelengkap.data', $slug),
|
||||
'filters' => $definition['filters'],
|
||||
'columns' => $definition['columns'],
|
||||
'perPage' => ReferenceData::PER_PAGE,
|
||||
'data' => $this->payload($this->reference->list($slug, [], ReferenceData::PER_PAGE[0])),
|
||||
'data' => $this->payload($this->decorate($writer, $slug, $this->reference->list($slug, [], ReferenceData::PER_PAGE[0]))),
|
||||
'strict' => true,
|
||||
'form' => $form ? [
|
||||
'title' => $form['title'],
|
||||
'storeUrl' => route('operator.pelengkap.store', $slug),
|
||||
'updateUrl' => route('operator.pelengkap.update', [$slug, '__ID__']),
|
||||
'fields' => $form['fields'],
|
||||
] : null,
|
||||
'destroyUrl' => ($abilities['delete'] ?? false) ? route('operator.pelengkap.destroy', $slug) : null,
|
||||
'destroy' => ['title' => 'Hapus data terpilih?', 'message' => 'Data yang masih dipakai tabel lain tidak akan dihapus.'],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -57,17 +74,124 @@ class DataPelengkapController extends Controller
|
||||
|
||||
$filter = ['q' => $this->query($request)];
|
||||
foreach ($this->reference->definition($slug)['filters'] as $f) {
|
||||
$value = (string) $request->string($f['name']);
|
||||
if ($value !== '' && isset($f['options'][$value])) {
|
||||
$value = $request->input($f['name']);
|
||||
if (is_string($value) && $value !== '' && isset($f['options'][$value])) {
|
||||
$filter[$f['name']] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json($this->payload($this->reference->list(
|
||||
return response()->json($this->payload($this->decorate(ReferenceWriters::for($slug), $slug, $this->reference->list(
|
||||
$slug,
|
||||
$filter,
|
||||
$this->perPage($request, ReferenceData::PER_PAGE),
|
||||
max(1, $request->integer('page', 1)),
|
||||
)));
|
||||
))));
|
||||
}
|
||||
|
||||
public function store(Request $request, string $slug): JsonResponse
|
||||
{
|
||||
$writer = $this->writer($request, $slug, 'create');
|
||||
$input = $this->input($request, $writer, $slug);
|
||||
|
||||
try {
|
||||
$id = $writer->create($slug, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Data ditambahkan.', 'id' => $id], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, string $slug, int $id): JsonResponse
|
||||
{
|
||||
$writer = $this->writer($request, $slug, 'update');
|
||||
$input = $this->input($request, $writer, $slug);
|
||||
|
||||
try {
|
||||
$writer->update($slug, $id, $input, (string) $request->user()->username, $request->ip());
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Data diperbarui.']);
|
||||
}
|
||||
|
||||
/** Hapus satu atau beberapa baris (POST {ids}); seluruhnya ditolak bila ada yang masih dipakai. */
|
||||
public function destroy(Request $request, string $slug): JsonResponse
|
||||
{
|
||||
$writer = $this->writer($request, $slug, 'delete');
|
||||
$ids = $request->validate(['ids' => ['required', 'array', 'min:1', 'max:100'], 'ids.*' => ['integer', 'distinct']], [], ['ids' => 'data'])['ids'];
|
||||
|
||||
try {
|
||||
$deleted = $writer->delete($slug, $ids);
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => "{$deleted} data dihapus."]);
|
||||
}
|
||||
|
||||
/** Penulis slug ini bila akun DB lama dan kemampuan yang diminta tersedia; selain itu 404. */
|
||||
private function writer(Request $request, string $slug, string $ability): ReferenceWriter
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
$writer = ReferenceWriters::for($slug) ?? abort(404);
|
||||
abort_unless($writer->abilities($slug)[$ability], 404);
|
||||
|
||||
return $writer;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function input(Request $request, ReferenceWriter $writer, string $slug): array
|
||||
{
|
||||
[$rules, $attributes] = $writer->rules($slug);
|
||||
|
||||
return $request->validate($rules, [], $attributes);
|
||||
}
|
||||
|
||||
/** Sisipkan nilai isian formulir (row.form) pada baris halaman bila slug bisa diubah. */
|
||||
private function decorate(?ReferenceWriter $writer, string $slug, LengthAwarePaginator $rows): LengthAwarePaginator
|
||||
{
|
||||
if ($writer === null || ! $writer->abilities($slug)['update']) {
|
||||
return $rows;
|
||||
}
|
||||
|
||||
$values = $writer->formValues($slug, $rows->getCollection()->pluck('id')->all());
|
||||
|
||||
return $rows->setCollection($rows->getCollection()->map(fn (array $row): array => isset($values[$row['id']]) ? $row + ['form' => $values[$row['id']]] : $row));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tombol halaman menurut kemampuan: Tambah bila boleh tambah, Hapus (dan kotak centang) bila boleh hapus, kolom
|
||||
* Aksi bila ada yang bisa dilakukan per baris. Tombol prototipe lain dibuang agar tidak ada tombol palsu.
|
||||
*
|
||||
* @param array<string, mixed> $page
|
||||
* @param array{create: bool, update: bool, delete: bool} $abilities
|
||||
*/
|
||||
private function withTools(array $page, array $abilities): array
|
||||
{
|
||||
$columns = array_values(array_filter($page['columns'], fn (string $c): bool => ! in_array($c, ['#', 'Aksi'], true)));
|
||||
if ($abilities['delete']) {
|
||||
array_unshift($columns, '#');
|
||||
}
|
||||
if ($abilities['update'] || $abilities['delete']) {
|
||||
$columns[] = 'Aksi';
|
||||
}
|
||||
|
||||
$flags = ($abilities['create'] ? 'T' : '').($abilities['delete'] ? 'H' : '').(str_contains($page['flags'], 'C') ? 'C' : '');
|
||||
|
||||
return ['columns' => $columns, 'flags' => $flags] + $page;
|
||||
}
|
||||
|
||||
/** @param array{create: bool, update: bool, delete: bool}|null $abilities */
|
||||
private function capabilityNote(?array $abilities): string
|
||||
{
|
||||
if ($abilities === null) {
|
||||
return 'Halaman ini hanya menampilkan data; pengelolaannya di halaman sumber (mis. Set Grup MK atau kurikulum).';
|
||||
}
|
||||
|
||||
$do = array_filter(['tambah' => $abilities['create'], 'ubah' => $abilities['update'], 'hapus' => $abilities['delete']]);
|
||||
|
||||
return ucfirst(implode(', ', array_keys($do))).' langsung tersimpan di basis data'.($abilities['delete'] ? '; data yang masih dipakai tabel lain tidak bisa dihapus.' : '.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operator;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\AcademicOverview;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Legacy\Reports\ReportContext;
|
||||
use App\Support\Legacy\Reports\ReportRegistry;
|
||||
use App\Support\Legacy\Reports\ReportSource;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
/**
|
||||
* Menu Laporan operator untuk akun DB lama: formulir parameter yang menjalankan laporan otomatis lewat JSON
|
||||
* (tabel berhalaman), unduh CSV, dan halaman cetak. Hanya baca. Sumber laporan (ReportSource) hanya mengenal
|
||||
* limit, jadi halaman N diambil dengan limit N × per halaman lalu dipotong (dibatasi CAP baris pertama).
|
||||
*/
|
||||
class LaporanController extends Controller
|
||||
{
|
||||
/** Pilihan jumlah baris per halaman; bawaan yang kedua. */
|
||||
public const array PER_PAGE = [10, 25, 50, 100];
|
||||
|
||||
/** Baris pertama yang bisa dilihat berhalaman; selebihnya lewat Unduh atau filter yang lebih sempit. */
|
||||
private const int CAP = 5000;
|
||||
|
||||
private const int PRINT = 2000;
|
||||
|
||||
private const int DOWNLOAD = 50000;
|
||||
|
||||
public function __construct(private readonly AcademicOverview $overview) {}
|
||||
|
||||
public function __invoke(Request $request, string $slug): View
|
||||
{
|
||||
[, , $page, $definition] = $this->prepare($request, $slug);
|
||||
[$values] = $this->parse($request, $definition['params'], $request->query() !== []);
|
||||
|
||||
return view('operator.satu.legacy-report', [
|
||||
'page' => $page,
|
||||
'crumbs' => ['Beranda' => route('operator.dashboard')] + array_fill_keys(Catalog::trail($slug), null) + [$page['title'] => null],
|
||||
'slug' => $slug,
|
||||
'definition' => $definition,
|
||||
'values' => $values,
|
||||
'config' => [
|
||||
'url' => route('operator.laporan.data', $slug),
|
||||
'downloadUrl' => route('operator.laporan.unduh', $slug),
|
||||
'printUrl' => route('operator.laporan.cetak', $slug),
|
||||
'params' => array_map(fn (array $p): array => ['name' => $p['name'], 'type' => $p['type'], 'required' => (bool) ($p['required'] ?? false), 'reload' => $p['name'] !== 'kop'], $definition['params']),
|
||||
'values' => $this->clientValues($definition['params'], $values),
|
||||
'perPage' => self::PER_PAGE,
|
||||
'per' => self::PER_PAGE[1],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/** JSON satu halaman hasil: kolom, baris halaman ini, keterangan, dan penomoran. */
|
||||
public function data(Request $request, string $slug): JsonResponse
|
||||
{
|
||||
[$source, $context, , $definition] = $this->prepare($request, $slug);
|
||||
[$values, $errors] = $this->parse($request, $definition['params'], true);
|
||||
if ($errors !== []) {
|
||||
return response()->json(['message' => implode(' ', $errors), 'errors' => $errors], 422);
|
||||
}
|
||||
|
||||
$per = in_array($request->integer('per'), self::PER_PAGE, true) ? $request->integer('per') : self::PER_PAGE[1];
|
||||
$maxPage = intdiv(self::CAP + $per - 1, $per);
|
||||
$page = min(max(1, $request->integer('page', 1)), $maxPage);
|
||||
|
||||
try {
|
||||
// +1 agar terlihat bila masih ada baris sesudah halaman ini saat sumber tidak mengisi total
|
||||
$result = $source->run($slug, $values, $context, $page * $per + 1);
|
||||
} catch (PortalException $e) {
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
$total = $result->total ?? count($result->rows);
|
||||
$lastPage = max(1, min($maxPage, intdiv($total + $per - 1, $per)));
|
||||
$page = min($page, $lastPage);
|
||||
|
||||
return response()->json([
|
||||
'columns' => $result->columns,
|
||||
'rows' => array_values(array_slice($result->rows, ($page - 1) * $per, $per)),
|
||||
'summary' => $result->summary,
|
||||
'note' => $result->note,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'last_page' => $lastPage,
|
||||
'per_page' => $per,
|
||||
'from' => ($page - 1) * $per + 1,
|
||||
'capped' => $total > self::CAP,
|
||||
'cap' => self::CAP,
|
||||
]);
|
||||
}
|
||||
|
||||
public function download(Request $request, string $slug): StreamedResponse|RedirectResponse
|
||||
{
|
||||
[$source, $context, , $definition] = $this->prepare($request, $slug);
|
||||
[$values, $errors] = $this->parse($request, $definition['params'], true);
|
||||
if ($errors !== []) {
|
||||
return redirect()->route('operator.halaman', [$slug] + $this->queryString($request));
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $source->run($slug, $values, $context, self::DOWNLOAD);
|
||||
} catch (PortalException $e) {
|
||||
return redirect()->route('operator.halaman', [$slug] + $this->queryString($request));
|
||||
}
|
||||
|
||||
return response()->streamDownload(function () use ($result): void {
|
||||
$out = fopen('php://output', 'w');
|
||||
fwrite($out, "\xEF\xBB\xBF"); // BOM agar Excel membaca UTF-8
|
||||
fputcsv($out, array_column($result->columns, 'label'), ',', '"', '\\');
|
||||
foreach ($result->rows as $row) {
|
||||
fputcsv($out, array_map(fn (array $c): mixed => $row[$c['key']] ?? '', $result->columns), ',', '"', '\\');
|
||||
}
|
||||
fclose($out);
|
||||
}, $slug.'-'.now()->format('Ymd-His').'.csv', ['Content-Type' => 'text/csv; charset=UTF-8']);
|
||||
}
|
||||
|
||||
public function print(Request $request, string $slug): View|RedirectResponse
|
||||
{
|
||||
[$source, $context, $page, $definition] = $this->prepare($request, $slug);
|
||||
[$values, $errors] = $this->parse($request, $definition['params'], true);
|
||||
if ($errors !== []) {
|
||||
return redirect()->route('operator.halaman', [$slug] + $this->queryString($request));
|
||||
}
|
||||
|
||||
try {
|
||||
$result = $source->run($slug, $values, $context, self::PRINT);
|
||||
} catch (PortalException $e) {
|
||||
return redirect()->route('operator.halaman', [$slug] + $this->queryString($request));
|
||||
}
|
||||
|
||||
return view('operator.laporan-cetak', [
|
||||
'title' => $page['title'],
|
||||
'result' => $result,
|
||||
'kop' => (bool) ($values['kop'] ?? true),
|
||||
'parameters' => $this->describe($definition['params'], $values),
|
||||
'operator' => $request->user()->username,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Penjaga akun dan definisi: akun DB lama dan slug terdaftar; kop (Gunakan KOP) ditambahkan di akhir parameter.
|
||||
*
|
||||
* @return array{0: ReportSource, 1: ReportContext, 2: array<string, mixed>, 3: array<string, mixed>}
|
||||
*/
|
||||
private function prepare(Request $request, string $slug): array
|
||||
{
|
||||
abort_unless($request->user() instanceof Account, 404);
|
||||
$source = ReportRegistry::sourceFor($slug) ?? abort(404);
|
||||
$page = Catalog::page($slug) ?? abort(404);
|
||||
|
||||
$programs = $this->overview->programs((int) $request->user()->getKey());
|
||||
$context = new ReportContext((int) $request->user()->getKey(), (string) $request->user()->username, $programs->keys()->all(), $programs->all());
|
||||
|
||||
$definition = $source->definition($slug, $context);
|
||||
$definition['params'][] = ['name' => 'kop', 'label' => 'Gunakan KOP', 'type' => 'check', 'default' => true];
|
||||
|
||||
return [$source, $context, $page, $definition];
|
||||
}
|
||||
|
||||
/**
|
||||
* Baca parameter dari query: pilihan dicocokkan ke opsi, teks dipangkas, angka dan tanggal diperiksa.
|
||||
* Kotak centang yang tidak dikirim berarti salah; sebelum ada query nilai awalnya dipakai.
|
||||
*
|
||||
* @param list<array<string, mixed>> $params
|
||||
* @return array{0: array<string, mixed>, 1: array<string, string>}
|
||||
*/
|
||||
private function parse(Request $request, array $params, bool $submitted): array
|
||||
{
|
||||
$values = [];
|
||||
$errors = [];
|
||||
|
||||
foreach ($params as $p) {
|
||||
$name = $p['name'];
|
||||
$label = $p['label'];
|
||||
$raw = $request->query($name);
|
||||
$raw = is_string($raw) ? trim($raw) : null;
|
||||
|
||||
if ($p['type'] === 'check') {
|
||||
$values[$name] = $submitted ? ($raw !== null && $raw !== '' && $raw !== '0') : (bool) ($p['default'] ?? false);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($raw === null || $raw === '') && ! $submitted && isset($p['default'])) {
|
||||
$raw = (string) $p['default'];
|
||||
}
|
||||
|
||||
if ($raw === null || $raw === '') {
|
||||
$values[$name] = null;
|
||||
if ($p['required'] ?? false) {
|
||||
$errors[$name] = "{$label} wajib diisi.";
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$values[$name] = match ($p['type']) {
|
||||
'select' => $this->matchOption($p['options'] ?? [], $raw),
|
||||
'number' => preg_match('/^-?\d{1,9}$/', $raw) ? (int) $raw : null,
|
||||
'date' => ($d = \DateTimeImmutable::createFromFormat('!Y-m-d', $raw)) && $d->format('Y-m-d') === $raw ? $raw : null,
|
||||
default => mb_substr($raw, 0, 100),
|
||||
};
|
||||
|
||||
if ($values[$name] === null) {
|
||||
$errors[$name] = "{$label} tidak valid.";
|
||||
}
|
||||
}
|
||||
|
||||
return [$values, $errors];
|
||||
}
|
||||
|
||||
/** @param array<int|string, string> $options */
|
||||
private function matchOption(array $options, string $raw): int|string|null
|
||||
{
|
||||
foreach ($options as $key => $label) {
|
||||
if ((string) $key === $raw) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nilai awal formulir untuk klien: teks/angka/pilihan sebagai string ('' bila kosong), kotak centang sebagai bool.
|
||||
*
|
||||
* @param list<array<string, mixed>> $params
|
||||
* @param array<string, mixed> $values
|
||||
* @return array<string, string|bool>
|
||||
*/
|
||||
private function clientValues(array $params, array $values): array
|
||||
{
|
||||
$out = [];
|
||||
foreach ($params as $p) {
|
||||
$value = $values[$p['name']] ?? null;
|
||||
$out[$p['name']] = $p['type'] === 'check' ? (bool) $value : ($value === null ? '' : (string) $value);
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ringkasan parameter yang terisi untuk halaman cetak: label => nilai tampil.
|
||||
*
|
||||
* @param list<array<string, mixed>> $params
|
||||
* @param array<string, mixed> $values
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function describe(array $params, array $values): array
|
||||
{
|
||||
$out = [];
|
||||
foreach ($params as $p) {
|
||||
$value = $values[$p['name']] ?? null;
|
||||
if ($p['type'] === 'check' || $value === null || $value === '') {
|
||||
continue;
|
||||
}
|
||||
$out[$p['label']] = $p['type'] === 'select' ? (string) ($p['options'][$value] ?? $value) : (string) $value;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/** Query laporan (string saja), untuk pengalihan kembali ke halaman. @return array<string, string> */
|
||||
private function queryString(Request $request): array
|
||||
{
|
||||
return collect($request->query())->filter(fn (mixed $v): bool => is_string($v))->all();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operator;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
/**
|
||||
* Halaman SATU yang belum punya sumber data di DB lama (sebagian Data Pelengkap: instansi, referensi perkuliahan,
|
||||
* biodata, pegawai, wilayah) untuk akun DB lama: bingkai yang sama, isinya keterangan menunggu data. Akun demo tetap prototipe.
|
||||
*/
|
||||
class PlaceholderPageController extends Controller
|
||||
{
|
||||
public const array SLUGS = [
|
||||
// Data Pelengkap > Perguruan Tinggi: instansi mitra, contact person, dan lokasi kampus tidak ada tabelnya
|
||||
'ms_perusahaan', 'list_cp', 'ms_kampus',
|
||||
// Data Pelengkap > Perkuliahan: referensi presensi/pertemuan, slot waktu, unsur nilai, sertifikat, dll. tidak ada tabelnya
|
||||
'ms_bidangilmu', 'ms_refnilai', 'ms_kelasperkuliahan', 'ms_slotwaktu', 'ms_statushadir', 'ms_jenispertemuan',
|
||||
'ms_kelompokperkuliahan', 'ms_jeniskegiatan', 'ms_jenissertifikat', 'ms_penyelenggarasertifikat',
|
||||
// Data Pelengkap > Biodata dan Mahasiswa: suku, jas almamater, jenis tinggal, transportasi, kebutuhan khusus tidak ada tabelnya
|
||||
'ms_suku', 'ms_almamater', 'ms_jenistinggal', 'ms_transport', 'ms_kebutuhankhusus',
|
||||
// Data Pelengkap > Pegawai dan Wilayah: predikat, honor, dan kecamatan tidak ada tabelnya
|
||||
// (Template Surat Keterangan Aktif ditampilkan sebagai templat tetap: view operator/satu/template-surat)
|
||||
'ms_predikatdosen', 'ms_honor', 'list_honortarif', 'ms_kecamatan',
|
||||
];
|
||||
|
||||
public function __invoke(string $slug): View
|
||||
{
|
||||
$page = Catalog::page($slug) ?? abort(404);
|
||||
|
||||
return view('operator.satu.placeholder', [
|
||||
'page' => $page,
|
||||
'crumbs' => ['Beranda' => route('operator.dashboard')] + array_fill_keys(Catalog::trail($slug), null) + [$page['title'] => null],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Operator;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\Reports\ReportRegistry;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use App\Support\Prototype\Satu\SatuSample;
|
||||
use Illuminate\Contracts\View\View;
|
||||
@@ -14,7 +15,6 @@ class SatuPageController extends Controller
|
||||
{
|
||||
/**
|
||||
* Halaman yang sudah memakai data asli untuk akun DB lama: slug => pengendali.
|
||||
* Slug tanpa sumber data (PlaceholderPageController::SLUGS) menampilkan keterangan menunggu data.
|
||||
*/
|
||||
private const array LEGACY_PAGES = [
|
||||
'list_mahasiswa' => StudentListController::class,
|
||||
@@ -51,8 +51,6 @@ class SatuPageController extends Controller
|
||||
'list_semesterpendek' => [SemesterPendekController::class, 'periode'],
|
||||
'list_mkpendek' => [SemesterPendekController::class, 'mataKuliah'],
|
||||
'list_pesertapendek' => [SemesterPendekController::class, 'peserta'],
|
||||
// Setting
|
||||
'list_periode' => PeriodeController::class,
|
||||
// Data Pelengkap: tabel referensi (ReferenceData::LISTS) dan data perguruan tinggi
|
||||
'data_universitas/detail' => DataPelengkapController::class,
|
||||
'list_fakultas' => DataPelengkapController::class, 'list_prodi' => DataPelengkapController::class, 'ms_bidangstudi' => DataPelengkapController::class,
|
||||
@@ -69,7 +67,11 @@ class SatuPageController extends Controller
|
||||
public function __invoke(Request $request, string $slug): View
|
||||
{
|
||||
if ($request->user() instanceof Account) {
|
||||
$controller = self::LEGACY_PAGES[$slug] ?? (in_array($slug, PlaceholderPageController::SLUGS, true) ? PlaceholderPageController::class : null);
|
||||
if (ReportRegistry::has($slug)) {
|
||||
return app(LaporanController::class)($request, $slug);
|
||||
}
|
||||
|
||||
$controller = self::LEGACY_PAGES[$slug] ?? null;
|
||||
|
||||
if ($controller !== null) {
|
||||
[$class, $method] = is_array($controller) ? $controller : [$controller, '__invoke'];
|
||||
|
||||
+24
-36
@@ -1,47 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operator;
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Operator\Concerns\ServesLegacyList;
|
||||
use App\Support\Legacy\AcademicOverview;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\AcademicPeriods;
|
||||
use App\Support\Legacy\PortalException;
|
||||
use App\Support\Prototype\Satu\Catalog;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Setting > Periode Akademik (slug list_periode) untuk akun DB lama: periode asli t_periodekuliah dengan tambah/ubah
|
||||
* lewat formulir dialog dan hapus berdialog. Aktif? = periode aktif prodi akun. Data dan simpan lewat JSON.
|
||||
* Periode Akademik (hanya Superuser, akun DB lama): periode asli t_periodekuliah dengan tambah/ubah lewat formulir
|
||||
* dialog dan hapus berdialog. Aktif? = periode yang aktif di setidaknya satu program studi. Data dan simpan lewat JSON.
|
||||
*/
|
||||
class PeriodeController extends Controller
|
||||
class PeriodeAkademikController extends Controller
|
||||
{
|
||||
use ServesLegacyList;
|
||||
|
||||
private const string SLUG = 'list_periode';
|
||||
|
||||
public function __construct(private readonly AcademicPeriods $periods, private readonly AcademicOverview $overview) {}
|
||||
public function __construct(private readonly AcademicPeriods $periods) {}
|
||||
|
||||
public function __invoke(Request $request): View
|
||||
{
|
||||
$page = Catalog::page(self::SLUG);
|
||||
$this->legacyOnly($request);
|
||||
|
||||
return view('operator.satu.periode', [
|
||||
'page' => $page,
|
||||
'crumbs' => $this->crumbs(self::SLUG, $page),
|
||||
'note' => 'Periode akademik asli dari SIAKAD; tambah, ubah, dan hapus langsung tersimpan di basis data. "Aktif?" adalah periode aktif program studi yang Anda kelola; tanggal UTS/UAS tidak tercatat di sumber data.',
|
||||
'rows' => $this->periods->all($this->prodi($request))->all(),
|
||||
return view('superuser.periode-akademik', [
|
||||
'page' => ['title' => 'Periode Akademik', 'subtitle' => 'Daftar Periode Akademik'],
|
||||
'crumbs' => ['Beranda' => route('superuser.dashboard'), 'Sistem' => null, 'Periode Akademik' => null],
|
||||
'note' => 'Periode akademik asli dari SIAKAD; tambah, ubah, dan hapus langsung tersimpan di basis data. "Aktif?" menandai periode yang sedang aktif di setidaknya satu program studi; tanggal UTS/UAS tidak tercatat di sumber data.',
|
||||
'rows' => $this->periods->all()->all(),
|
||||
'semesters' => AcademicPeriods::SEMESTERS,
|
||||
'kinds' => AcademicPeriods::KINDS,
|
||||
'urls' => [
|
||||
'data' => route('operator.periode.data'),
|
||||
'store' => route('operator.periode.store'),
|
||||
'update' => route('operator.periode.update', '__ID__'),
|
||||
'destroy' => route('operator.periode.destroy', '__ID__'),
|
||||
'data' => route('superuser.periode.data'),
|
||||
'store' => route('superuser.periode.store'),
|
||||
'update' => route('superuser.periode.update', '__ID__'),
|
||||
'destroy' => route('superuser.periode.destroy', '__ID__'),
|
||||
],
|
||||
'perPage' => [10, 25, 50, 100],
|
||||
'perPage' => [10, 25, 50],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -49,7 +43,7 @@ class PeriodeController extends Controller
|
||||
{
|
||||
$this->legacyOnly($request);
|
||||
|
||||
return response()->json(['rows' => $this->rows($request)]);
|
||||
return response()->json(['rows' => $this->periods->all()->all()]);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
@@ -63,7 +57,7 @@ class PeriodeController extends Controller
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Periode akademik ditambahkan.', 'id' => $id, 'rows' => $this->rows($request)], 201);
|
||||
return response()->json(['message' => 'Periode akademik ditambahkan.', 'id' => $id, 'rows' => $this->periods->all()->all()], 201);
|
||||
}
|
||||
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
@@ -77,7 +71,7 @@ class PeriodeController extends Controller
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Periode akademik diperbarui.', 'rows' => $this->rows($request)]);
|
||||
return response()->json(['message' => 'Periode akademik diperbarui.', 'rows' => $this->periods->all()->all()]);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, int $id): JsonResponse
|
||||
@@ -90,19 +84,13 @@ class PeriodeController extends Controller
|
||||
return response()->json(['message' => $e->getMessage()], 422);
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Periode akademik dihapus.', 'rows' => $this->rows($request)]);
|
||||
return response()->json(['message' => 'Periode akademik dihapus.', 'rows' => $this->periods->all()->all()]);
|
||||
}
|
||||
|
||||
/** @return list<array<string, mixed>> */
|
||||
private function rows(Request $request): array
|
||||
/** Hanya akun DB lama yang memegang data asli; akun demo mendapat 404. */
|
||||
private function legacyOnly(Request $request): void
|
||||
{
|
||||
return $this->periods->all($this->prodi($request))->all();
|
||||
}
|
||||
|
||||
/** @return list<int> */
|
||||
private function prodi(Request $request): array
|
||||
{
|
||||
return $this->overview->programs((int) $request->user()->getKey())->keys()->all();
|
||||
abort_unless($request->user() instanceof Account, 404);
|
||||
}
|
||||
|
||||
/** @return array{thakad: string, semester: int, perkuliahan: int, mulai: ?string, selesai: ?string} */
|
||||
Reference in New Issue
Block a user