✨ feat(ui): Perbaikan tampilan dan fungsionalitas halaman index untuk manajemen pengguna
- Memperbaiki fungsi export data pengguna dengan format yang lebih rapi - Update semua controller (Permissions, Positions, Roles, Users) untuk konsistensi response dan error handling - Tambahan fungsi `goPage(1)` pada event listener pencarian untuk langsung ke halaman pertama saat melakukan pencarian
This commit is contained in:
@@ -276,9 +276,7 @@
|
|||||||
// Apply search filter if provided
|
// Apply search filter if provided
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
$query->where('name', 'like', '%' . $search . '%');
|
||||||
$q->whereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%']);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply sorting if provided
|
// Apply sorting if provided
|
||||||
@@ -303,14 +301,11 @@
|
|||||||
// Get the filtered count of records
|
// Get the filtered count of records
|
||||||
$filteredRecords = $query->count();
|
$filteredRecords = $query->count();
|
||||||
|
|
||||||
|
|
||||||
// Get the data for the current page
|
// Get the data for the current page
|
||||||
$permissions = $query->get();
|
$data = $query->get();
|
||||||
|
|
||||||
|
$data = $data->map(function ($permission) {
|
||||||
$permissions = $permissions->map(function ($permission) {
|
|
||||||
$permission->roles = $permission->roles($permission);
|
$permission->roles = $permission->roles($permission);
|
||||||
|
|
||||||
return $permission;
|
return $permission;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -328,7 +323,7 @@
|
|||||||
'pageCount' => $pageCount,
|
'pageCount' => $pageCount,
|
||||||
'page' => $currentPage,
|
'page' => $currentPage,
|
||||||
'totalCount' => $totalRecords,
|
'totalCount' => $totalRecords,
|
||||||
'data' => $permissions,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -223,11 +223,7 @@
|
|||||||
// Apply search filter if provided
|
// Apply search filter if provided
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
$query->whereAny(['code', 'name', 'level'], 'like', '%' . $search . '%');
|
||||||
$q->whereRaw('LOWER(code) LIKE ?', ['%' . strtolower($search) . '%'])
|
|
||||||
->orWhereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%'])
|
|
||||||
->orWhereRaw('CAST(level AS TEXT) LIKE ?', ['%' . $search . '%']);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply sorting if provided
|
// Apply sorting if provided
|
||||||
@@ -253,7 +249,7 @@
|
|||||||
$filteredRecords = $query->count();
|
$filteredRecords = $query->count();
|
||||||
|
|
||||||
// Get the data for the current page
|
// Get the data for the current page
|
||||||
$positions = $query->get();
|
$data = $query->get();
|
||||||
|
|
||||||
// Calculate the page count
|
// Calculate the page count
|
||||||
$size = $request->get('size', 10); // Default to 10 if not set
|
$size = $request->get('size', 10); // Default to 10 if not set
|
||||||
@@ -270,7 +266,7 @@
|
|||||||
'pageCount' => $pageCount,
|
'pageCount' => $pageCount,
|
||||||
'page' => $currentPage,
|
'page' => $currentPage,
|
||||||
'totalCount' => $totalRecords,
|
'totalCount' => $totalRecords,
|
||||||
'data' => $positions,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -273,14 +273,17 @@
|
|||||||
// Retrieve data from the database
|
// Retrieve data from the database
|
||||||
$query = Role::query();
|
$query = Role::query();
|
||||||
|
|
||||||
|
if(!$this->user->hasRole('administrator')){
|
||||||
|
$query->where('name', '!=', 'administrator');
|
||||||
|
}
|
||||||
|
|
||||||
// Apply search filter if provided
|
// Apply search filter if provided
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
$query->where(function ($q) use ($search) {
|
||||||
$q->whereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%'])
|
$q->where('name', 'like', '%' . $search . '%')
|
||||||
->orWhereHas('position', function ($query) use ($search) {
|
->orWhereHas('position', function ($query) use ($search) {
|
||||||
$query->whereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%'])
|
$query->whereAny(['name', 'level'], 'like','%'.$search.'%');
|
||||||
->orWhereRaw('CAST(level AS TEXT) LIKE ?', ['%' . $search . '%']);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -290,19 +293,17 @@
|
|||||||
$order = $request->get('sortOrder');
|
$order = $request->get('sortOrder');
|
||||||
$column = $request->get('sortField');
|
$column = $request->get('sortField');
|
||||||
|
|
||||||
// Handle sorting for position-related columns
|
|
||||||
if ($column === 'position_name') {
|
if ($column === 'position_name') {
|
||||||
$query->leftJoin('positions', 'roles.position_id', '=', 'positions.id')
|
$query->leftJoin('positions', 'roles.position_id', '=', 'positions.id')
|
||||||
->orderByRaw('LOWER(positions.name) ' . $order)
|
->orderBy('positions.name', $order)
|
||||||
->select('roles.*'); // Select only from roles table to avoid column conflicts
|
->select('roles.*'); // Select only from roles table to avoid column conflicts
|
||||||
} else if ($column === 'level') {
|
} else if ($column === 'level') {
|
||||||
$query->leftJoin('positions', 'roles.position_id', '=', 'positions.id')
|
$query->leftJoin('positions', 'roles.position_id', '=', 'positions.id')
|
||||||
->orderBy('positions.level', $order)
|
->orderBy('positions.level', $order)
|
||||||
->select('roles.*'); // Select only from roles table to avoid column conflicts
|
->select('roles.*'); // Select only from roles table to avoid column conflicts
|
||||||
} else {
|
} else {
|
||||||
// Make sorting case-insensitive for string columns
|
|
||||||
if ($column === 'name') {
|
if ($column === 'name') {
|
||||||
$query->orderByRaw('LOWER(roles.name) ' . $order);
|
$query->orderBy('roles.name', $order);
|
||||||
} else {
|
} else {
|
||||||
$query->orderBy($column, $order);
|
$query->orderBy($column, $order);
|
||||||
}
|
}
|
||||||
@@ -328,7 +329,7 @@
|
|||||||
$filteredRecords = $countQuery->distinct()->count('roles.id');
|
$filteredRecords = $countQuery->distinct()->count('roles.id');
|
||||||
|
|
||||||
// Get the data for the current page
|
// Get the data for the current page
|
||||||
$roles = $query->with('position')->get();
|
$data = $query->with('position')->get();
|
||||||
|
|
||||||
// Calculate the page count - ensure we don't divide by zero
|
// Calculate the page count - ensure we don't divide by zero
|
||||||
$pageSize = $request->get('size', 10); // Default to 10 if not provided
|
$pageSize = $request->get('size', 10); // Default to 10 if not provided
|
||||||
@@ -345,7 +346,7 @@
|
|||||||
'pageCount' => $pageCount,
|
'pageCount' => $pageCount,
|
||||||
'page' => $currentPage,
|
'page' => $currentPage,
|
||||||
'totalCount' => $totalRecords,
|
'totalCount' => $totalRecords,
|
||||||
'data' => $roles,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,12 @@
|
|||||||
// Retrieve data from the database
|
// Retrieve data from the database
|
||||||
$query = User::query();
|
$query = User::query();
|
||||||
|
|
||||||
|
if(!$this->user->hasRole('administrator')){
|
||||||
|
$query->whereHas('roles', function($q){
|
||||||
|
$q->where('name', '!=', 'administrator');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Apply search filter if provided
|
// Apply search filter if provided
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
@@ -108,7 +114,7 @@
|
|||||||
$filteredRecords = $query->count();
|
$filteredRecords = $query->count();
|
||||||
|
|
||||||
// Get the data for the current page
|
// Get the data for the current page
|
||||||
$users = $query->with(['branch', 'roles'])->get();
|
$data = $query->with(['branch', 'roles'])->get();
|
||||||
|
|
||||||
// Calculate the page count
|
// Calculate the page count
|
||||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||||
@@ -124,7 +130,7 @@
|
|||||||
'pageCount' => $pageCount,
|
'pageCount' => $pageCount,
|
||||||
'page' => $currentPage,
|
'page' => $currentPage,
|
||||||
'totalCount' => $totalRecords,
|
'totalCount' => $totalRecords,
|
||||||
'data' => $users,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,6 +150,9 @@
|
|||||||
|
|
||||||
$user = User::find($id);
|
$user = User::find($id);
|
||||||
$roles = Role::all();
|
$roles = Role::all();
|
||||||
|
if(!$this->user->hasRole('administrator')){
|
||||||
|
$roles = $roles->where('name', '!=', 'administrator');
|
||||||
|
}
|
||||||
$branches = Branch::all();
|
$branches = Branch::all();
|
||||||
return view('usermanagement::users.create', compact('user', 'roles', 'branches'));
|
return view('usermanagement::users.create', compact('user', 'roles', 'branches'));
|
||||||
}
|
}
|
||||||
@@ -234,6 +243,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$roles = Role::all();
|
$roles = Role::all();
|
||||||
|
if(!$this->user->hasRole('administrator')){
|
||||||
|
$roles = $roles->where('name', '!=', 'administrator');
|
||||||
|
}
|
||||||
$branches = Branch::all();
|
$branches = Branch::all();
|
||||||
return view('usermanagement::users.create', compact('roles', 'branches'));
|
return view('usermanagement::users.create', compact('roles', 'branches'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,10 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="5" data-datatable-state-save="true" id="permissions-table" data-api-url="{{ route('users.permissions.datatables') }}">
|
<div class="min-w-full card card-grid" data-datatable="false" data-datatable-page-size="5"
|
||||||
<div class="card-header py-5 flex-wrap">
|
data-datatable-state-save="true" id="permissions-table"
|
||||||
|
data-api-url="{{ route('users.permissions.datatables') }}">
|
||||||
|
<div class="flex-wrap py-5 card-header">
|
||||||
<h3 class="card-title">
|
<h3 class="card-title">
|
||||||
List of Permissions
|
List of Permissions
|
||||||
</h3>
|
</h3>
|
||||||
@@ -21,14 +23,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
||||||
<div class="h-[24px] border border-r-gray-200"> </div>
|
<div class="h-[24px] border border-r-gray-200"> </div>
|
||||||
<a class="btn btn-sm btn-light" href="{{ route('users.permissions.export') }}"> Export to Excel </a>
|
<a class="btn btn-sm btn-light" href="{{ route('users.permissions.export') }}"> Export to Excel
|
||||||
<a class="btn btn-sm btn-primary" href="{{ route('users.permissions.create') }}"> Add Permission </a>
|
</a>
|
||||||
|
<a class="btn btn-sm btn-primary" href="{{ route('users.permissions.create') }}"> Add Permission
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="scrollable-x-auto">
|
<div class="scrollable-x-auto">
|
||||||
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
<table class="table text-sm font-medium text-gray-700 align-middle table-auto table-border"
|
||||||
|
data-datatable-table="true">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-14">
|
<th class="w-14">
|
||||||
@@ -47,12 +52,14 @@
|
|||||||
</thead>
|
</thead>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
<div
|
||||||
<div class="flex items-center gap-2">
|
class="flex-col gap-3 justify-center font-medium text-gray-600 card-footer md:justify-between md:flex-row text-2sm">
|
||||||
|
<div class="flex gap-2 items-center">
|
||||||
Show
|
Show
|
||||||
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per page
|
<select class="w-16 select select-sm" data-datatable-size="true" name="perpage"> </select> per
|
||||||
|
page
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex gap-4 items-center">
|
||||||
<span data-datatable-info="true"> </span>
|
<span data-datatable-info="true"> </span>
|
||||||
<div class="pagination" data-datatable-pagination="true">
|
<div class="pagination" data-datatable-pagination="true">
|
||||||
</div>
|
</div>
|
||||||
@@ -154,7 +161,7 @@
|
|||||||
searchInput.addEventListener('input', function() {
|
searchInput.addEventListener('input', function() {
|
||||||
const searchValue = this.value.trim();
|
const searchValue = this.value.trim();
|
||||||
dataTable.search(searchValue, true);
|
dataTable.search(searchValue, true);
|
||||||
|
dataTable.goPage(1);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="5" data-datatable-state-save="true" id="positions-table" data-api-url="{{ route('users.positions.datatables') }}">
|
<div class="min-w-full card card-grid" data-datatable="false" data-datatable-page-size="5"
|
||||||
<div class="card-header py-5 flex-wrap">
|
data-datatable-state-save="true" id="positions-table" data-api-url="{{ route('users.positions.datatables') }}">
|
||||||
|
<div class="flex-wrap py-5 card-header">
|
||||||
<h3 class="card-title">
|
<h3 class="card-title">
|
||||||
List of Positions
|
List of Positions
|
||||||
</h3>
|
</h3>
|
||||||
@@ -20,14 +21,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
<div class="flex flex-wrap gap-2.5 lg:gap-5">
|
||||||
<div class="h-[100%] border border-r-gray-200"> </div>
|
<div class="h-[100%] border border-r-gray-200"> </div>
|
||||||
<a class="btn btn-sm btn-light" id="export-btn" href="{{ route('users.positions.export') }}"> Export to Excel </a>
|
<a class="btn btn-sm btn-light" id="export-btn" href="{{ route('users.positions.export') }}">
|
||||||
<a class="btn btn-sm btn-primary" href="{{ route('users.positions.create') }}"> Add Position </a>
|
Export to Excel </a>
|
||||||
|
<a class="btn btn-sm btn-primary" href="{{ route('users.positions.create') }}"> Add Position
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="scrollable-x-auto">
|
<div class="scrollable-x-auto">
|
||||||
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
<table class="table text-sm font-medium text-gray-700 align-middle table-auto table-border"
|
||||||
|
data-datatable-table="true">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-14">
|
<th class="w-14">
|
||||||
@@ -50,12 +54,14 @@
|
|||||||
</thead>
|
</thead>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
<div
|
||||||
<div class="flex items-center gap-2">
|
class="flex-col gap-3 justify-center font-medium text-gray-600 card-footer md:justify-between md:flex-row text-2sm">
|
||||||
|
<div class="flex gap-2 items-center">
|
||||||
Show
|
Show
|
||||||
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per page
|
<select class="w-16 select select-sm" data-datatable-size="true" name="perpage"> </select> per
|
||||||
|
page
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex gap-4 items-center">
|
||||||
<span data-datatable-info="true"> </span>
|
<span data-datatable-info="true"> </span>
|
||||||
<div class="pagination" data-datatable-pagination="true">
|
<div class="pagination" data-datatable-pagination="true">
|
||||||
</div>
|
</div>
|
||||||
@@ -153,6 +159,7 @@
|
|||||||
searchInput.addEventListener('input', function() {
|
searchInput.addEventListener('input', function() {
|
||||||
const searchValue = this.value.trim();
|
const searchValue = this.value.trim();
|
||||||
dataTable.search(searchValue, true);
|
dataTable.search(searchValue, true);
|
||||||
|
dataTable.goPage(1);
|
||||||
|
|
||||||
// Update export URL with search parameter
|
// Update export URL with search parameter
|
||||||
if (searchValue) {
|
if (searchValue) {
|
||||||
|
|||||||
@@ -7,8 +7,9 @@
|
|||||||
@section('content')
|
@section('content')
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="5" data-datatable-state-save="true" id="roles-table" data-api-url="{{ route('users.roles.datatables') }}">
|
<div class="min-w-full card card-grid" data-datatable="false" data-datatable-page-size="5"
|
||||||
<div class="card-header py-5 flex-wrap">
|
data-datatable-state-save="true" id="roles-table" data-api-url="{{ route('users.roles.datatables') }}">
|
||||||
|
<div class="flex-wrap py-5 card-header">
|
||||||
<h3 class="card-title">
|
<h3 class="card-title">
|
||||||
List of Roles
|
List of Roles
|
||||||
</h3>
|
</h3>
|
||||||
@@ -28,7 +29,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="scrollable-x-auto">
|
<div class="scrollable-x-auto">
|
||||||
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
<table class="table text-sm font-medium text-gray-700 align-middle table-auto table-border"
|
||||||
|
data-datatable-table="true">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="w-14">
|
<th class="w-14">
|
||||||
@@ -51,12 +53,14 @@
|
|||||||
</thead>
|
</thead>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
<div
|
||||||
<div class="flex items-center gap-2">
|
class="flex-col gap-3 justify-center font-medium text-gray-600 card-footer md:justify-between md:flex-row text-2sm">
|
||||||
|
<div class="flex gap-2 items-center">
|
||||||
Show
|
Show
|
||||||
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per page
|
<select class="w-16 select select-sm" data-datatable-size="true" name="perpage"> </select> per
|
||||||
|
page
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex gap-4 items-center">
|
||||||
<span data-datatable-info="true"> </span>
|
<span data-datatable-info="true"> </span>
|
||||||
<div class="pagination" data-datatable-pagination="true">
|
<div class="pagination" data-datatable-pagination="true">
|
||||||
</div>
|
</div>
|
||||||
@@ -159,6 +163,7 @@
|
|||||||
searchInput.addEventListener('input', function() {
|
searchInput.addEventListener('input', function() {
|
||||||
const searchValue = this.value.trim();
|
const searchValue = this.value.trim();
|
||||||
dataTable.search(searchValue, true);
|
dataTable.search(searchValue, true);
|
||||||
|
dataTable.goPage(1);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|||||||
Reference in New Issue
Block a user