254 lines
14 KiB
PHP
254 lines
14 KiB
PHP
@extends('layout.app')
|
|
|
|
@section('content')
|
|
<div class="page-header">
|
|
<ol class="breadcrumb">
|
|
<li class="breadcrumb-item">Home</li>
|
|
<li class="breadcrumb-item active">Data Pengguna</li>
|
|
</ol>
|
|
</div>
|
|
|
|
<div class="row gutters">
|
|
<div class="col-xl-12">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
|
|
{{-- Header Tabel & Dropdown Per Page --}}
|
|
<div class="mb-3 d-flex justify-content-between align-items-center">
|
|
<div class="d-flex align-items-center gap-3">
|
|
<h5 class="mb-0">Data Pengguna</h5>
|
|
|
|
{{-- Dropdown Pilihan Halaman --}}
|
|
<form action="{{ route('users.index') }}" method="GET" id="form-per-page" class="m-0">
|
|
<div class="d-flex align-items-center" style="gap: 8px;">
|
|
<label class="text-muted mb-0" style="font-size: 0.9rem; font-weight: normal; white-space: nowrap;">Tampil:</label>
|
|
<select name="per_page" class="form-control form-control-sm shadow-sm"
|
|
style="width: 75px; cursor: pointer; border-radius: 6px; border-color: #ced4da;"
|
|
onchange="document.getElementById('form-per-page').submit();">
|
|
<option value="10" {{ ($perPage ?? 10) == 10 ? 'selected' : '' }}>10</option>
|
|
<option value="25" {{ ($perPage ?? 10) == 25 ? 'selected' : '' }}>25</option>
|
|
<option value="50" {{ ($perPage ?? 10) == 50 ? 'selected' : '' }}>50</option>
|
|
<option value="100" {{ ($perPage ?? 10) == 100 ? 'selected' : '' }}>100</option>
|
|
</select>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<div>
|
|
<a href="{{ route('users.create') }}" class="btn btn-success">
|
|
<i class="icon-plus"></i> Tambah Pengguna
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
{{-- Tabel Data Pengguna --}}
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered table-striped text-center">
|
|
<thead>
|
|
<tr>
|
|
<th>No</th>
|
|
<th>Nama Lengkap</th>
|
|
<th>Username</th>
|
|
<th>Role</th>
|
|
<th>Status</th>
|
|
<th class="text-center">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@forelse($users as $user)
|
|
<tr>
|
|
<td>{{ $users->firstItem() + $loop->index }}</td>
|
|
<td class="text-left">{{ $user->nama_lengkap }}</td>
|
|
<td class="text-left">{{ $user->username }}</td>
|
|
<td>
|
|
<span class="badge {{ $user->role == 'admin' ? 'badge-primary' : 'badge-info' }}">
|
|
{{ ucfirst($user->role) }}
|
|
</span>
|
|
</td>
|
|
<td>
|
|
{{-- Badge Status --}}
|
|
@if($user->status === 'aktif')
|
|
<span class="badge badge-success"><i class="icon-check-circle"></i> Aktif</span>
|
|
@else
|
|
<span class="badge badge-secondary"><i class="icon-x-circle"></i> Nonaktif</span>
|
|
@endif
|
|
</td>
|
|
<td>
|
|
<div class="d-flex justify-content-center align-items-center" style="gap: 8px;">
|
|
|
|
{{-- Tombol Edit --}}
|
|
<a href="{{ route('users.edit', $user->id) }}"
|
|
class="btn btn-primary btn-sm m-0" title="Edit Data">
|
|
<i class="icon-edit"></i>
|
|
</a>
|
|
|
|
{{-- Tombol Toggle Status (HANYA MUNCUL JIKA BUKAN AKUN SENDIRI) --}}
|
|
@if (auth()->user()->role === 'admin' && auth()->id() !== $user->id)
|
|
<form action="{{ route('users.toggle_status', $user->id) }}" method="POST" id="status-form-{{ $user->id }}" class="m-0">
|
|
@csrf
|
|
@method('PATCH')
|
|
{{-- Jika Aktif, tombol berwarna abu-abu (untuk menonaktifkan). Jika Nonaktif, tombol hijau (untuk mengaktifkan) --}}
|
|
<button type="button"
|
|
class="btn {{ $user->status === 'aktif' ? 'btn-secondary' : 'btn-success' }} btn-sm btn-status m-0"
|
|
data-id="{{ $user->id }}"
|
|
data-action="{{ $user->status === 'aktif' ? 'menonaktifkan' : 'mengaktifkan' }}"
|
|
data-username="{{ $user->username }}"
|
|
title="{{ $user->status === 'aktif' ? 'Nonaktifkan Akun' : 'Aktifkan Akun' }}">
|
|
<i class="{{ $user->status === 'aktif' ? 'icon-power' : 'icon-check' }}"></i>
|
|
</button>
|
|
</form>
|
|
@endif
|
|
|
|
{{-- Tombol Reset Password --}}
|
|
@if (auth()->user()->role === 'admin')
|
|
<form action="{{ route('users.reset_password', $user->id) }}" method="POST" id="reset-form-{{ $user->id }}" class="m-0">
|
|
@csrf
|
|
<button type="button" class="btn btn-warning btn-sm btn-reset text-white m-0"
|
|
data-id="{{ $user->id }}" data-username="{{ $user->username }}" title="Reset Password Default">
|
|
<i class="icon-unlock"></i>
|
|
</button>
|
|
</form>
|
|
@endif
|
|
|
|
{{-- Tombol Hapus (HANYA MUNCUL JIKA BUKAN AKUN SENDIRI) --}}
|
|
@if (auth()->id() !== $user->id)
|
|
<form action="{{ route('users.destroy', $user->id) }}" method="POST" id="delete-form-{{ $user->id }}" class="m-0">
|
|
@csrf
|
|
@method('DELETE')
|
|
<button type="button" class="btn btn-danger btn-sm btn-delete m-0"
|
|
data-id="{{ $user->id }}" title="Hapus Data">
|
|
<i class="icon-trash"></i>
|
|
</button>
|
|
</form>
|
|
@endif
|
|
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="6" class="text-center">Data tidak ditemukan.</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
{{-- Menampilkan Tombol Next / Previous --}}
|
|
<div class="mt-4 d-flex justify-content-between align-items-center">
|
|
<div class="text-muted small">
|
|
Menampilkan {{ $users->firstItem() ?? 0 }} sampai {{ $users->lastItem() ?? 0 }} dari total
|
|
{{ $users->total() }} data
|
|
</div>
|
|
<div>
|
|
{{ $users->links('pagination::bootstrap-4') }}
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{{-- Script SweetAlert2 --}}
|
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
// Konfirmasi Status (Aktif/Nonaktif)
|
|
const statusButtons = document.querySelectorAll('.btn-status');
|
|
statusButtons.forEach(button => {
|
|
button.addEventListener('click', function() {
|
|
const userId = this.getAttribute('data-id');
|
|
const action = this.getAttribute('data-action');
|
|
const username = this.getAttribute('data-username');
|
|
|
|
Swal.fire({
|
|
title: 'Konfirmasi Akses',
|
|
text: `Apakah Anda yakin ingin ${action} akun ${username}?`,
|
|
icon: 'question',
|
|
showCancelButton: true,
|
|
confirmButtonColor: action === 'mengaktifkan' ? '#38d39f' : '#858796',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, Lanjutkan!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById(`status-form-${userId}`).submit();
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
// Konfirmasi Hapus SweetAlert
|
|
const deleteButtons = document.querySelectorAll('.btn-delete');
|
|
deleteButtons.forEach(button => {
|
|
button.addEventListener('click', function() {
|
|
const userId = this.getAttribute('data-id');
|
|
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: "Data ini akan dihapus permanen!",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#38d39f',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, Hapus!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById(`delete-form-${userId}`).submit();
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
// Konfirmasi Reset Password SweetAlert
|
|
const resetButtons = document.querySelectorAll('.btn-reset');
|
|
resetButtons.forEach(button => {
|
|
button.addEventListener('click', function() {
|
|
const userId = this.getAttribute('data-id');
|
|
const username = this.getAttribute('data-username');
|
|
|
|
Swal.fire({
|
|
title: 'Reset Password?',
|
|
html: `Password untuk pengguna <b>${username}</b> akan dikembalikan ke default: <b>123456</b>`,
|
|
icon: 'question',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#f39c12',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Ya, Reset!',
|
|
cancelButtonText: 'Batal'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
document.getElementById(`reset-form-${userId}`).submit();
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
// Toast Notifikasi Sukses
|
|
@if (session('success'))
|
|
Swal.fire({
|
|
icon: 'success',
|
|
title: 'Berhasil!',
|
|
text: "{!! session('success') !!}",
|
|
showConfirmButton: true,
|
|
confirmButtonColor: '#38d39f'
|
|
});
|
|
@endif
|
|
|
|
// Toast Notifikasi Error
|
|
@if (session('error'))
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Gagal!',
|
|
text: "{{ session('error') }}",
|
|
showConfirmButton: true,
|
|
confirmButtonColor: '#d33'
|
|
});
|
|
@endif
|
|
});
|
|
</script>
|
|
@endsection
|