[Superuser] Integrasi Pertama ke Database
This commit is contained in:
@@ -3,12 +3,50 @@
|
||||
namespace App\Http\Controllers\Superuser;
|
||||
|
||||
use App\Http\Controllers\Prototype\ResourceController;
|
||||
use App\Models\Legacy\Account;
|
||||
use App\Support\Legacy\LoginHistory;
|
||||
use App\Support\Prototype\SuperuserData;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/** Log aktivitas: hanya baca. */
|
||||
/**
|
||||
* Log aktivitas: hanya baca. Akun DB lama: riwayat masuk asli (t_historilogin), dicari dan disaring di server;
|
||||
* akun demo: contoh dari SuperuserData.
|
||||
*/
|
||||
class LogAktivitasController extends ResourceController
|
||||
{
|
||||
public function __construct(private readonly LoginHistory $history) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
if (! $this->legacy()) {
|
||||
return parent::index($request);
|
||||
}
|
||||
|
||||
$per = in_array($request->integer('per'), LoginHistory::PER_PAGE, true) ? $request->integer('per') : LoginHistory::PER_PAGE[0];
|
||||
$filter = $request->only(['q', 'dari', 'sampai']) + ['pengguna' => $request->filled('pengguna') ? $request->integer('pengguna') : null];
|
||||
|
||||
return view('crud.index', $this->share([
|
||||
'rows' => $this->history->search($filter, $per)->withQueryString(),
|
||||
'columns' => $this->columns(),
|
||||
'filters' => [
|
||||
['name' => 'dari', 'label' => 'Dari tanggal', 'type' => 'date'],
|
||||
['name' => 'sampai', 'label' => 'Sampai tanggal', 'type' => 'date'],
|
||||
// Saringan satu akun (dari detail Pengguna) tetap terbawa saat filter lain diubah.
|
||||
...($filter['pengguna'] === null ? [] : [['name' => 'pengguna', 'type' => 'hidden']]),
|
||||
],
|
||||
'searchable' => true,
|
||||
'searchPlaceholder' => 'Cari nama, NIP, atau NIM pemilik akun',
|
||||
'rowActions' => fn (array $row): array => [],
|
||||
]));
|
||||
}
|
||||
|
||||
private function legacy(): bool
|
||||
{
|
||||
return request()->user() instanceof Account;
|
||||
}
|
||||
|
||||
protected function rows(): Collection
|
||||
{
|
||||
return SuperuserData::aktivitas();
|
||||
@@ -24,7 +62,9 @@ class LogAktivitasController extends ResourceController
|
||||
return [
|
||||
'singular' => 'Aktivitas',
|
||||
'plural' => 'Log aktivitas',
|
||||
'description' => 'Jejak audit tindakan penting pengguna pada sistem, dari yang terbaru.',
|
||||
'description' => $this->legacy()
|
||||
? 'Riwayat masuk asli ke SIAKAD (waktu, komputer, alamat IP), dari yang terbaru. Sumber data hanya mencatat aktivitas masuk.'
|
||||
: 'Jejak audit tindakan penting pengguna pada sistem, dari yang terbaru.',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -55,6 +95,17 @@ class LogAktivitasController extends ResourceController
|
||||
|
||||
protected function columns(): array
|
||||
{
|
||||
if ($this->legacy()) {
|
||||
return [
|
||||
['label' => 'Waktu', 'key' => 'waktu'],
|
||||
['label' => 'Pengguna', 'key' => 'pengguna'],
|
||||
['label' => 'NIP/NIM', 'key' => 'username'],
|
||||
['label' => 'Aksi', 'key' => 'aksi', 'badge' => fn (array $r): string => 'success'],
|
||||
['label' => 'Komputer', 'key' => 'komputer'],
|
||||
['label' => 'Alamat IP', 'key' => 'ip'],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
['label' => 'Waktu', 'key' => 'waktu'],
|
||||
['label' => 'Pengguna', 'key' => 'pengguna'],
|
||||
|
||||
Reference in New Issue
Block a user