locked-account data fetched
This commit is contained in:
parent
b5120e5b78
commit
2d920f245a
|
@ -0,0 +1,182 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
|
|
||||||
|
class LockedAccountController extends Controller
|
||||||
|
{
|
||||||
|
protected $apiBaseUrl = 'http://192.168.100.6:8081/api';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the main page with locked accounts.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return \Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Force a log to confirm the method is reached
|
||||||
|
Log::debug('Entering LockedAccountController index method', ['request' => $request->all()]);
|
||||||
|
|
||||||
|
$user = Session::get('user');
|
||||||
|
$accessToken = $user['access_token'] ?? null;
|
||||||
|
|
||||||
|
if (!$accessToken) {
|
||||||
|
Log::warning('No access token found, redirecting to login from locked-accounts');
|
||||||
|
return redirect()->route('login')->with('error', 'Please log in to view locked accounts.');
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug('Access token found', ['access_token' => $accessToken]);
|
||||||
|
|
||||||
|
// Prepare query parameters
|
||||||
|
$params = [
|
||||||
|
'page' => $request->input('page', 1),
|
||||||
|
'page_size' => $request->input('page_size', 5), // Match CardMemberController's default
|
||||||
|
'_search' => $request->input('_search', null),
|
||||||
|
'status' => $request->input('status', null),
|
||||||
|
'_locked' => 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
Log::debug('Making API call to fetch locked accounts', [
|
||||||
|
'url' => "{$this->apiBaseUrl}/cms/member",
|
||||||
|
'params' => $params,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = Http::withHeaders([
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
'Authorization' => 'Bearer ' . $accessToken,
|
||||||
|
])->get("{$this->apiBaseUrl}/cms/member", $params);
|
||||||
|
|
||||||
|
Log::debug('API response received', [
|
||||||
|
'status' => $response->status(),
|
||||||
|
'body' => $response->body(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($response->status() === 401 || $response->status() === 403) {
|
||||||
|
Log::warning('Unauthorized or Forbidden API response', ['response' => $response->json()]);
|
||||||
|
return redirect()->route('login')->with('error', 'Your session has expired. Please log in again.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = $response->json();
|
||||||
|
Log::info('Locked Accounts API Raw Response', ['response' => $json]);
|
||||||
|
|
||||||
|
if ($response->successful() && isset($json['data']) && is_array($json['data'])) {
|
||||||
|
$accounts = array_map(function ($account) {
|
||||||
|
Log::info('Processing locked account record', ['account' => $account]);
|
||||||
|
return [
|
||||||
|
'id' => $account['lcard_uuid'] ?? null,
|
||||||
|
'cardNumber' => $account['card_number'] ?? '',
|
||||||
|
'firstName' => $account['firstname'] ?? '',
|
||||||
|
'lastName' => $account['lastname'] ?? '',
|
||||||
|
'birthday' => $account['birthdate'] ?? '',
|
||||||
|
'cardType' => $account['card_type'] ?? '',
|
||||||
|
'status' => $account['status'] ? 'Active' : 'Inactive',
|
||||||
|
'is_locked' => $account['is_locked'] ?? 1, // Ensure locked status
|
||||||
|
];
|
||||||
|
}, $json['data']);
|
||||||
|
|
||||||
|
$total = $json['meta']['total'] ?? count($accounts);
|
||||||
|
$lastPage = $json['meta']['last_page'] ?? ceil($total / $params['page_size']);
|
||||||
|
} else {
|
||||||
|
Log::warning('No locked account data found or invalid API response', ['response' => $json]);
|
||||||
|
$accounts = [];
|
||||||
|
$total = 0;
|
||||||
|
$lastPage = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug('Rendering view with data', [
|
||||||
|
'accounts' => $accounts,
|
||||||
|
'currentPage' => $params['page'],
|
||||||
|
'lastPage' => $lastPage,
|
||||||
|
'total' => $total,
|
||||||
|
'params' => $params,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return view('pages.member management.locked-accounts', [
|
||||||
|
'members' => $accounts, // Match naming convention with CardMemberController
|
||||||
|
'currentPage' => $params['page'],
|
||||||
|
'lastPage' => $lastPage,
|
||||||
|
'total' => $total,
|
||||||
|
'search' => $params['_search'],
|
||||||
|
'params' => $params, // Include params for view compatibility
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Error in LockedAccountController index method', [
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
return view('pages.member management.locked-accounts', [
|
||||||
|
'members' => [],
|
||||||
|
'currentPage' => 1,
|
||||||
|
'lastPage' => 1,
|
||||||
|
'total' => 0,
|
||||||
|
'search' => $params['_search'] ?? null,
|
||||||
|
'params' => $params ?? [
|
||||||
|
'page' => 1,
|
||||||
|
'page_size' => 5,
|
||||||
|
'_search' => null,
|
||||||
|
'status' => null,
|
||||||
|
'_locked' => 1,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activate a locked account.
|
||||||
|
*
|
||||||
|
* @param string $uuid
|
||||||
|
* @return \Illuminate\Http\RedirectResponse
|
||||||
|
*/
|
||||||
|
public function activate($uuid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$user = Session::get('user');
|
||||||
|
$accessToken = $user['access_token'] ?? null;
|
||||||
|
|
||||||
|
if (!$accessToken) {
|
||||||
|
Log::warning('No access token found, redirecting to login from activate account');
|
||||||
|
return redirect()->route('login')->with('error', 'Please log in to activate an account.');
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug('Making API call to activate account', [
|
||||||
|
'url' => "{$this->apiBaseUrl}/cms/memberActivate/{$uuid}",
|
||||||
|
'uuid' => $uuid,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = Http::withHeaders([
|
||||||
|
'Accept' => 'application/json',
|
||||||
|
'Authorization' => 'Bearer ' . $accessToken,
|
||||||
|
])->post("{$this->apiBaseUrl}/cms/memberActivate/{$uuid}");
|
||||||
|
|
||||||
|
Log::debug('Activate API response received', [
|
||||||
|
'status' => $response->status(),
|
||||||
|
'body' => $response->body(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($response->successful()) {
|
||||||
|
return redirect()->route('locked-accounts')->with('success', 'Account activated successfully.');
|
||||||
|
} else {
|
||||||
|
Log::warning('Failed to activate account', ['uuid' => $uuid, 'response' => $response->json()]);
|
||||||
|
return redirect()->route('locked-accounts')->with('error', $response->json()['message'] ?? 'Failed to activate account. Please try again.');
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error('Error activating account', [
|
||||||
|
'uuid' => $uuid,
|
||||||
|
'message' => $e->getMessage(),
|
||||||
|
'trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
return redirect()->route('locked-accounts')->with('error', 'An error occurred while activating the account.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show()
|
||||||
|
{
|
||||||
|
return view('pages.locked-account-view');
|
||||||
|
}
|
||||||
|
}
|
|
@ -282,7 +282,7 @@
|
||||||
if (!pagination) return;
|
if (!pagination) return;
|
||||||
pagination.innerHTML = '';
|
pagination.innerHTML = '';
|
||||||
|
|
||||||
const routeName = tableConfig.pageTitle === 'Locked Account' ? '{{ route("locked-account") }}' : '{{ route("card-member") }}';
|
const routeName = tableConfig.pageTitle === 'Locked Account' ? '{{ route("locked-accounts") }}' : '{{ route("card-member") }}';
|
||||||
|
|
||||||
const prevLi = document.createElement('li');
|
const prevLi = document.createElement('li');
|
||||||
prevLi.className = `page-item ${currentPage === 1 ? 'disabled' : ''}`;
|
prevLi.className = `page-item ${currentPage === 1 ? 'disabled' : ''}`;
|
||||||
|
|
|
@ -0,0 +1,422 @@
|
||||||
|
@props([
|
||||||
|
'pageTitle' => '',
|
||||||
|
'data' => [],
|
||||||
|
'columns' => [],
|
||||||
|
'actions' => [],
|
||||||
|
'showAddButton' => false,
|
||||||
|
'addButtonUrl' => '#',
|
||||||
|
'showCheckboxes' => false,
|
||||||
|
'showBatchDelete' => false,
|
||||||
|
'showEditModal' => false,
|
||||||
|
'showViewModal' => false,
|
||||||
|
'currentPage' => 1,
|
||||||
|
'lastPage' => 1,
|
||||||
|
'total' => 0,
|
||||||
|
'viewRoute' => '', // New prop for the view route
|
||||||
|
])
|
||||||
|
|
||||||
|
<div class="card-header border-0 bg-transparent">
|
||||||
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
|
<h5 class="mb-0 fw-bold text-dark">{{ $pageTitle }}</h5>
|
||||||
|
@if ($showAddButton)
|
||||||
|
<a href="{{ $addButtonUrl }}" class="btn btn-primary btn-sm px-3">
|
||||||
|
<i class="fa-solid fa-plus me-1"></i> Add {{ $pageTitle }}
|
||||||
|
</a>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<!-- Search and Filters -->
|
||||||
|
<div class="row mb-3 align-items-center">
|
||||||
|
<div class="col-12 col-md-6 mb-2 mb-md-0">
|
||||||
|
<div class="input-group input-group-sm">
|
||||||
|
<span class="input-group-text bg-light border-end-0">
|
||||||
|
<i class="fa-solid fa-magnifying-glass text-muted"></i>
|
||||||
|
</span>
|
||||||
|
<input type="text" class="form-control border-start-0" placeholder="Search..." id="searchInput" data-search-param="_search">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6 d-flex justify-content-end">
|
||||||
|
<button class="btn btn-outline-secondary btn-sm" id="clearFilters">
|
||||||
|
<i class="fa-solid fa-filter-circle-xmark me-1"></i> Clear Filters
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Table -->
|
||||||
|
<div class="table-container">
|
||||||
|
<table class="table table-hover align-middle">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
@if ($showCheckboxes)
|
||||||
|
<th class="text-center" style="width: 40px;">
|
||||||
|
<input type="checkbox" id="selectAll">
|
||||||
|
</th>
|
||||||
|
@endif
|
||||||
|
@foreach ($columns as $index => $column)
|
||||||
|
<th class="{{ $column['sortable'] ? 'sortable' : '' }}" data-column="{{ $index + 1 }}">
|
||||||
|
{{ $column['name'] }}
|
||||||
|
@if ($column['sortable'])
|
||||||
|
<i class="fa-solid fa-sort"></i>
|
||||||
|
@endif
|
||||||
|
</th>
|
||||||
|
@endforeach
|
||||||
|
@if (!empty($actions))
|
||||||
|
<th class="text-center" style="width: 120px;">Action</th>
|
||||||
|
@endif
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="tableBody"></tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Batch Delete and Pagination -->
|
||||||
|
<div class="d-flex justify-content-between align-items-center mt-4">
|
||||||
|
@if ($showBatchDelete)
|
||||||
|
<div>
|
||||||
|
<button class="btn btn-danger btn-sm" id="deleteSelected" disabled>
|
||||||
|
<i class="fa-solid fa-trash-can me-1"></i> Delete Selected
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<nav aria-label="Page navigation">
|
||||||
|
<ul class="pagination pagination-sm" id="pagination"></ul>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.card,
|
||||||
|
.table,
|
||||||
|
.btn,
|
||||||
|
.form-control,
|
||||||
|
.input-group-text {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
.card-header h5 {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
.table thead th {
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
.form-label {
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
.card-header {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
.btn-primary {
|
||||||
|
background-color: #E74610;
|
||||||
|
border-color: #E74610;
|
||||||
|
}
|
||||||
|
.btn-primary:hover {
|
||||||
|
background-color: #E74610;
|
||||||
|
border-color: #E74610;
|
||||||
|
}
|
||||||
|
.sortable {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.sortable:hover {
|
||||||
|
background-color: #f1f3f5;
|
||||||
|
}
|
||||||
|
.table {
|
||||||
|
font-size: 0.85rem;
|
||||||
|
width: 100%;
|
||||||
|
table-layout: auto;
|
||||||
|
}
|
||||||
|
.table th,
|
||||||
|
.table td {
|
||||||
|
padding: 0.5rem;
|
||||||
|
vertical-align: middle;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.table th:first-child,
|
||||||
|
.table td:first-child {
|
||||||
|
width: 40px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.table th:last-child,
|
||||||
|
.table td:last-child {
|
||||||
|
width: 120px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.table td:nth-child(5),
|
||||||
|
.table th:nth-child(5) {
|
||||||
|
width: 100px;
|
||||||
|
}
|
||||||
|
.table td:nth-child(6),
|
||||||
|
.table th:nth-child(6) {
|
||||||
|
max-width: 200px;
|
||||||
|
}
|
||||||
|
.table td:nth-child(7),
|
||||||
|
.table th:nth-child(7) {
|
||||||
|
width: 120px;
|
||||||
|
}
|
||||||
|
.view-btn {
|
||||||
|
border-color: #6c757d;
|
||||||
|
color: #6c757d;
|
||||||
|
}
|
||||||
|
.view-btn:hover {
|
||||||
|
background-color: #6c757d;
|
||||||
|
border-color: #6c757d;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.table-hover tbody tr:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
@media (max-width: 576px) {
|
||||||
|
.table {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
.table thead th {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
.table th,
|
||||||
|
.table td {
|
||||||
|
padding: 0.3rem;
|
||||||
|
}
|
||||||
|
.btn-sm {
|
||||||
|
padding: 0.2rem 0.4rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
.input-group-sm>.form-control {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
.pagination-sm .page-link {
|
||||||
|
padding: 0.2rem 0.4rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
.table td:nth-child(6) {
|
||||||
|
max-width: 150px;
|
||||||
|
}
|
||||||
|
.form-control,
|
||||||
|
.form-select {
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const tableConfig = {
|
||||||
|
data: @json($data),
|
||||||
|
columns: @json($columns),
|
||||||
|
actions: @json($actions),
|
||||||
|
showCheckboxes: {{ json_encode($showCheckboxes) }},
|
||||||
|
showBatchDelete: {{ json_encode($showBatchDelete) }},
|
||||||
|
showEditModal: {{ json_encode($showEditModal) }},
|
||||||
|
showViewModal: {{ json_encode($showViewModal) }},
|
||||||
|
pageTitle: @json($pageTitle),
|
||||||
|
csrfToken: '{{ csrf_token() }}',
|
||||||
|
currentPage: {{ $currentPage }},
|
||||||
|
lastPage: {{ $lastPage }},
|
||||||
|
total: {{ $total }},
|
||||||
|
viewRoute: @json($viewRoute),
|
||||||
|
};
|
||||||
|
|
||||||
|
const rowsPerPage = 5;
|
||||||
|
let currentPage = tableConfig.currentPage;
|
||||||
|
let filteredRows = [...tableConfig.data];
|
||||||
|
let originalRows = [...tableConfig.data].map(row => ({ ...row }));
|
||||||
|
let sortDirection = {};
|
||||||
|
|
||||||
|
function renderTable() {
|
||||||
|
const tableBody = document.getElementById('tableBody');
|
||||||
|
if (!tableBody) return;
|
||||||
|
tableBody.innerHTML = '';
|
||||||
|
|
||||||
|
const paginatedRows = filteredRows;
|
||||||
|
|
||||||
|
paginatedRows.forEach(row => {
|
||||||
|
const tr = document.createElement('tr');
|
||||||
|
tr.setAttribute('data-id', row.id);
|
||||||
|
tr.classList.add('clickable-row');
|
||||||
|
let rowHtml = '';
|
||||||
|
|
||||||
|
if (tableConfig.showCheckboxes) {
|
||||||
|
rowHtml += `<td class="text-center"><input type="checkbox" class="rowCheckbox"></td>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
tableConfig.columns.forEach(col => {
|
||||||
|
let value = row[col.key] || '';
|
||||||
|
if (col.key === 'birthday') {
|
||||||
|
value = value ? new Date(value).toLocaleDateString() : 'N/A';
|
||||||
|
} else if (col.key === 'is_locked') {
|
||||||
|
value = value == 1 ? 'Locked' : 'Unlocked'; // Display Locked/Unlocked
|
||||||
|
}
|
||||||
|
rowHtml += `<td>${value}</td>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tableConfig.actions.length > 0) {
|
||||||
|
rowHtml += `<td class="text-center">`;
|
||||||
|
tableConfig.actions.forEach(action => {
|
||||||
|
if (action === 'view') {
|
||||||
|
rowHtml += `
|
||||||
|
<a href="${tableConfig.viewRoute.replace(':id', row.id)}" class="btn btn-sm view-btn me-1" title="View">
|
||||||
|
<i class="fa-solid fa-eye"></i>
|
||||||
|
</a>`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rowHtml += `</td>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr.innerHTML = rowHtml;
|
||||||
|
tableBody.appendChild(tr);
|
||||||
|
});
|
||||||
|
|
||||||
|
attachEventListeners();
|
||||||
|
updateNoDataMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderPagination() {
|
||||||
|
const pagination = document.getElementById('pagination');
|
||||||
|
if (!pagination) return;
|
||||||
|
pagination.innerHTML = '';
|
||||||
|
|
||||||
|
const routeName = tableConfig.pageTitle === 'Locked Account' ? '{{ route("locked-accounts") }}' : '{{ route("card-member") }}';
|
||||||
|
|
||||||
|
const prevLi = document.createElement('li');
|
||||||
|
prevLi.className = `page-item ${currentPage === 1 ? 'disabled' : ''}`;
|
||||||
|
prevLi.innerHTML = `<a class="page-link" href="#" aria-label="Previous"><span aria-hidden="true">«</span></a>`;
|
||||||
|
prevLi.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (currentPage > 1) {
|
||||||
|
window.location.href = `${routeName}?page=${currentPage - 1}&_search=${tableConfig.search || ''}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pagination.appendChild(prevLi);
|
||||||
|
|
||||||
|
for (let i = 1; i <= tableConfig.lastPage; i++) {
|
||||||
|
const li = document.createElement('li');
|
||||||
|
li.className = `page-item ${currentPage === i ? 'active' : ''}`;
|
||||||
|
li.innerHTML = `<a class="page-link" href="#">${i}</a>`;
|
||||||
|
li.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
window.location.href = `${routeName}?page=${i}&_search=${tableConfig.search || ''}`;
|
||||||
|
});
|
||||||
|
pagination.appendChild(li);
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextLi = document.createElement('li');
|
||||||
|
nextLi.className = `page-item ${currentPage === tableConfig.lastPage ? 'disabled' : ''}`;
|
||||||
|
nextLi.innerHTML = `<a class="page-link" href="#" aria-label="Next"><span aria-hidden="true">»</span></a>`;
|
||||||
|
nextLi.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (currentPage < tableConfig.lastPage) {
|
||||||
|
window.location.href = `${routeName}?page=${currentPage + 1}&_search=${tableConfig.search || ''}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
pagination.appendChild(nextLi);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateNoDataMessage() {
|
||||||
|
const noDataMessage = document.getElementById('no-data-message');
|
||||||
|
if (noDataMessage) {
|
||||||
|
noDataMessage.style.display = filteredRows.length === 0 ? 'block' : 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function attachEventListeners() {
|
||||||
|
const searchInput = document.getElementById('searchInput');
|
||||||
|
if (searchInput) {
|
||||||
|
searchInput.addEventListener('input', function() {
|
||||||
|
const searchTerm = this.value.toLowerCase();
|
||||||
|
filteredRows = tableConfig.data.filter(row => {
|
||||||
|
return Object.values(row).some(value =>
|
||||||
|
value && value.toString().toLowerCase().includes(searchTerm)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
currentPage = 1;
|
||||||
|
renderTable();
|
||||||
|
renderPagination();
|
||||||
|
const url = new URL(window.location);
|
||||||
|
if (searchTerm) {
|
||||||
|
url.searchParams.set('_search', searchTerm);
|
||||||
|
} else {
|
||||||
|
url.searchParams.delete('_search');
|
||||||
|
}
|
||||||
|
window.history.pushState({}, '', url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.sortable').forEach(header => {
|
||||||
|
header.addEventListener('click', function() {
|
||||||
|
const columnIndex = parseInt(this.getAttribute('data-column')) - (tableConfig.showCheckboxes ? 1 : 0);
|
||||||
|
const key = tableConfig.columns[columnIndex].key;
|
||||||
|
|
||||||
|
sortDirection[columnIndex] = !sortDirection[columnIndex] ? 'asc' : sortDirection[columnIndex] === 'asc' ? 'desc' : 'asc';
|
||||||
|
|
||||||
|
document.querySelectorAll('.sortable i').forEach(icon => {
|
||||||
|
icon.classList.remove('fa-sort-up', 'fa-sort-down');
|
||||||
|
icon.classList.add('fa-sort');
|
||||||
|
});
|
||||||
|
const icon = this.querySelector('i');
|
||||||
|
if (icon) {
|
||||||
|
icon.classList.remove('fa-sort');
|
||||||
|
icon.classList.add(sortDirection[columnIndex] === 'asc' ? 'fa-sort-up' : 'fa-sort-down');
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredRows.sort((a, b) => {
|
||||||
|
let aValue = (a[key] || '').toString().toLowerCase();
|
||||||
|
let bValue = (b[key] || '').toString().toLowerCase();
|
||||||
|
if (key === 'birthday') {
|
||||||
|
aValue = new Date(a[key] || '1970-01-01').getTime();
|
||||||
|
bValue = new Date(b[key] || '1970-01-01').getTime();
|
||||||
|
return sortDirection[columnIndex] === 'asc' ? aValue - bValue : bValue - aValue;
|
||||||
|
} else if (key === 'is_locked') {
|
||||||
|
aValue = a[key] == 1 ? 'Locked' : 'Unlocked';
|
||||||
|
bValue = b[key] == 1 ? 'Locked' : 'Unlocked';
|
||||||
|
return sortDirection[columnIndex] === 'asc' ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
|
||||||
|
}
|
||||||
|
return sortDirection[columnIndex] === 'asc' ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
currentPage = 1;
|
||||||
|
renderTable();
|
||||||
|
renderPagination();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const clearFilters = document.getElementById('clearFilters');
|
||||||
|
if (clearFilters) {
|
||||||
|
clearFilters.addEventListener('click', function() {
|
||||||
|
if (searchInput) searchInput.value = '';
|
||||||
|
document.querySelectorAll('.sortable i').forEach(icon => {
|
||||||
|
icon.classList.remove('fa-sort-up', 'fa-sort-down');
|
||||||
|
icon.classList.add('fa-sort');
|
||||||
|
});
|
||||||
|
sortDirection = {};
|
||||||
|
filteredRows = [...tableConfig.data];
|
||||||
|
currentPage = 1;
|
||||||
|
renderTable();
|
||||||
|
renderPagination();
|
||||||
|
const url = new URL(window.location);
|
||||||
|
url.searchParams.delete('_search');
|
||||||
|
window.history.pushState({}, '', url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelectorAll('.clickable-row').forEach(row => {
|
||||||
|
row.addEventListener('click', function(e) {
|
||||||
|
if (e.target.closest('.rowCheckbox, .edit-btn, .view-btn, .delete-btn')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const memberId = this.getAttribute('data-id');
|
||||||
|
window.location.href = tableConfig.viewRoute.replace(':id', memberId);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTable();
|
||||||
|
renderPagination();
|
||||||
|
</script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
|
@ -16,7 +16,7 @@
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@include('components.card-member-component', [
|
@include('components.locked-accounts-component', [
|
||||||
'pageTitle' => 'Locked Account',
|
'pageTitle' => 'Locked Account',
|
||||||
'data' => $members ?? [],
|
'data' => $members ?? [],
|
||||||
'columns' => [
|
'columns' => [
|
||||||
|
|
|
@ -13,6 +13,9 @@ use App\Http\Controllers\TermsAndPrivacyController;
|
||||||
use App\Http\Controllers\CardTypeController;
|
use App\Http\Controllers\CardTypeController;
|
||||||
use App\Http\Controllers\ReportsController;
|
use App\Http\Controllers\ReportsController;
|
||||||
use App\Http\Controllers\StationController;
|
use App\Http\Controllers\StationController;
|
||||||
|
use App\Http\Controllers\LockedAccountController;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return redirect()->route('login');
|
return redirect()->route('login');
|
||||||
|
@ -163,9 +166,10 @@ Route::post('/notification', [NotificationController::class, 'store'])->name('no
|
||||||
//Member Management
|
//Member Management
|
||||||
Route::get('/card-member', [CardMemberController::class, 'index'])->name('card-member');
|
Route::get('/card-member', [CardMemberController::class, 'index'])->name('card-member');
|
||||||
Route::get('/card-member/{uuid}', [CardMemberController::class, 'show'])->name('card-member.show');
|
Route::get('/card-member/{uuid}', [CardMemberController::class, 'show'])->name('card-member.show');
|
||||||
Route::get('/locked-account', [CardMemberController::class, 'lockedAccounts'])->name('locked-account');
|
Route::get('/locked-accounts', [LockedAccountController::class, 'index'])->name('locked-accounts');
|
||||||
Route::get('/locked-account/{uuid}', [CardMemberController::class, 'show'])->name('locked-account.show');
|
Route::post('/locked-accounts/activate/{uuid}', [LockedAccountController::class, 'activate'])->name('locked-accounts.activate');
|
||||||
Route::post('/locked-account/activate/{uuid}', [CardMemberController::class, 'activate'])->name('locked-account.activate');
|
Route::get('/locked-accounts/{uuid}', [LockedAccountController::class, 'show'])->name('locked-account.show');
|
||||||
|
|
||||||
//Promotion
|
//Promotion
|
||||||
Route::get('/promotions', [PromotionController::class, 'index'])->name('promotions');
|
Route::get('/promotions', [PromotionController::class, 'index'])->name('promotions');
|
||||||
Route::get('/promotions/create', [PromotionController::class, 'create'])->name('promotions.create');
|
Route::get('/promotions/create', [PromotionController::class, 'create'])->name('promotions.create');
|
||||||
|
|
Loading…
Reference in New Issue