card member page fixed
This commit is contained in:
parent
a0cbe8a239
commit
57167e64d7
|
@ -54,7 +54,8 @@ class CardMemberController extends Controller
|
|||
'lastName' => $member['lastname'] ?? '',
|
||||
'birthday' => $member['birthdate'] ?? '',
|
||||
'cardType' => $member['card_type'] ?? '',
|
||||
'status' => $member['is_validated'] ? 'Active' : 'Inactive',
|
||||
'status' => $member['status'] ? 'Active' : 'Inactive',
|
||||
'is_locked' => $member['is_locked'] ?? 0, // Add is_locked field
|
||||
];
|
||||
}, $json['data']);
|
||||
|
||||
|
@ -130,7 +131,8 @@ class CardMemberController extends Controller
|
|||
'lastName' => $member['lastname'] ?? '',
|
||||
'birthday' => $member['birthdate'] ?? '',
|
||||
'cardType' => $member['card_type'] ?? '',
|
||||
'status' => $member['is_validated'] ? 'Active' : 'Inactive',
|
||||
'status' => $member['status'] ? 'Active' : 'Inactive',
|
||||
'is_locked' => $member['is_locked'] ?? 0, // Add is_locked field
|
||||
];
|
||||
}, $json['data']);
|
||||
|
||||
|
@ -187,7 +189,8 @@ class CardMemberController extends Controller
|
|||
'lastName' => $json['data']['lastname'] ?? '',
|
||||
'birthday' => $json['data']['birthdate'] ?? '',
|
||||
'cardType' => $json['data']['card_type'] ?? '',
|
||||
'status' => $json['data']['is_validated'] ? 'Active' : 'Inactive',
|
||||
'status' => $json['data']['status'] ? 'Active' : 'Inactive',
|
||||
'is_locked' => $json['data']['is_locked'] ?? 0, // Add is_locked field
|
||||
];
|
||||
|
||||
// Determine the view based on the referring route
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
'currentPage' => 1,
|
||||
'lastPage' => 1,
|
||||
'total' => 0,
|
||||
'viewRoute' => '', // New prop for the view route
|
||||
])
|
||||
|
||||
<div class="card-header border-0 bg-transparent">
|
||||
|
@ -219,10 +220,11 @@
|
|||
currentPage: {{ $currentPage }},
|
||||
lastPage: {{ $lastPage }},
|
||||
total: {{ $total }},
|
||||
viewRoute: @json($viewRoute),
|
||||
};
|
||||
|
||||
const rowsPerPage = 5; // Fixed at 5 per page
|
||||
let currentPage = tableConfig.currentPage; // Initialize with server-side page
|
||||
const rowsPerPage = 5;
|
||||
let currentPage = tableConfig.currentPage;
|
||||
let filteredRows = [...tableConfig.data];
|
||||
let originalRows = [...tableConfig.data].map(row => ({ ...row }));
|
||||
let sortDirection = {};
|
||||
|
@ -232,12 +234,11 @@
|
|||
if (!tableBody) return;
|
||||
tableBody.innerHTML = '';
|
||||
|
||||
// Use the data passed from the server (already paginated to 5)
|
||||
const paginatedRows = filteredRows; // No client-side slicing needed
|
||||
const paginatedRows = filteredRows;
|
||||
|
||||
paginatedRows.forEach(row => {
|
||||
const tr = document.createElement('tr');
|
||||
tr.setAttribute('data-id', row.id); // Use lcard_uuid as id
|
||||
tr.setAttribute('data-id', row.id);
|
||||
tr.classList.add('clickable-row');
|
||||
let rowHtml = '';
|
||||
|
||||
|
@ -249,6 +250,8 @@
|
|||
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>`;
|
||||
});
|
||||
|
@ -257,9 +260,8 @@
|
|||
rowHtml += `<td class="text-center">`;
|
||||
tableConfig.actions.forEach(action => {
|
||||
if (action === 'view') {
|
||||
const route = tableConfig.pageTitle === 'Locked Account' ? 'locked-account.show' : 'card-member.show';
|
||||
rowHtml += `
|
||||
<a href="{{ route('') }}/${route}/${row.id}" class="btn btn-sm view-btn me-1" title="View">
|
||||
<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>`;
|
||||
}
|
||||
|
@ -280,7 +282,7 @@
|
|||
if (!pagination) return;
|
||||
pagination.innerHTML = '';
|
||||
|
||||
const routeName = tableConfig.pageTitle === 'Locked Account' ? 'locked-account.index' : 'card-member.index';
|
||||
const routeName = tableConfig.pageTitle === 'Locked Account' ? '{{ route("locked-account") }}' : '{{ route("card-member") }}';
|
||||
|
||||
const prevLi = document.createElement('li');
|
||||
prevLi.className = `page-item ${currentPage === 1 ? 'disabled' : ''}`;
|
||||
|
@ -288,7 +290,7 @@
|
|||
prevLi.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
if (currentPage > 1) {
|
||||
window.location.href = `{{ route('') }}/${routeName}?page=${currentPage - 1}&_search=${tableConfig.search || ''}`;
|
||||
window.location.href = `${routeName}?page=${currentPage - 1}&_search=${tableConfig.search || ''}`;
|
||||
}
|
||||
});
|
||||
pagination.appendChild(prevLi);
|
||||
|
@ -299,7 +301,7 @@
|
|||
li.innerHTML = `<a class="page-link" href="#">${i}</a>`;
|
||||
li.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
window.location.href = `{{ route('') }}/${routeName}?page=${i}&_search=${tableConfig.search || ''}`;
|
||||
window.location.href = `${routeName}?page=${i}&_search=${tableConfig.search || ''}`;
|
||||
});
|
||||
pagination.appendChild(li);
|
||||
}
|
||||
|
@ -310,7 +312,7 @@
|
|||
nextLi.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
if (currentPage < tableConfig.lastPage) {
|
||||
window.location.href = `{{ route('') }}/${routeName}?page=${currentPage + 1}&_search=${tableConfig.search || ''}`;
|
||||
window.location.href = `${routeName}?page=${currentPage + 1}&_search=${tableConfig.search || ''}`;
|
||||
}
|
||||
});
|
||||
pagination.appendChild(nextLi);
|
||||
|
@ -324,7 +326,6 @@
|
|||
}
|
||||
|
||||
function attachEventListeners() {
|
||||
// Search
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
if (searchInput) {
|
||||
searchInput.addEventListener('input', function() {
|
||||
|
@ -334,10 +335,9 @@
|
|||
value && value.toString().toLowerCase().includes(searchTerm)
|
||||
);
|
||||
});
|
||||
currentPage = 1; // Reset to first page on search
|
||||
currentPage = 1;
|
||||
renderTable();
|
||||
renderPagination();
|
||||
// Update URL with search parameter
|
||||
const url = new URL(window.location);
|
||||
if (searchTerm) {
|
||||
url.searchParams.set('_search', searchTerm);
|
||||
|
@ -348,7 +348,6 @@
|
|||
});
|
||||
}
|
||||
|
||||
// Sort
|
||||
document.querySelectorAll('.sortable').forEach(header => {
|
||||
header.addEventListener('click', function() {
|
||||
const columnIndex = parseInt(this.getAttribute('data-column')) - (tableConfig.showCheckboxes ? 1 : 0);
|
||||
|
@ -373,17 +372,20 @@
|
|||
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; // Reset to first page on sort
|
||||
currentPage = 1;
|
||||
renderTable();
|
||||
renderPagination();
|
||||
});
|
||||
});
|
||||
|
||||
// Clear Filters
|
||||
const clearFilters = document.getElementById('clearFilters');
|
||||
if (clearFilters) {
|
||||
clearFilters.addEventListener('click', function() {
|
||||
|
@ -397,22 +399,19 @@
|
|||
currentPage = 1;
|
||||
renderTable();
|
||||
renderPagination();
|
||||
// Clear search parameter from URL
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.delete('_search');
|
||||
window.history.pushState({}, '', url);
|
||||
});
|
||||
}
|
||||
|
||||
// Row click to view
|
||||
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');
|
||||
const route = tableConfig.pageTitle === 'Locked Account' ? 'locked-account.show' : 'card-member.show';
|
||||
window.location.href = `{{ route('') }}/${route}/${memberId}`;
|
||||
window.location.href = tableConfig.viewRoute.replace(':id', memberId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
<div class="mb-3">
|
||||
<strong>Status:</strong> {{ $member['status'] }}
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<strong>Lock Status:</strong> {{ $member['is_locked'] == 1 ? 'Locked' : 'Unlocked' }}
|
||||
</div>
|
||||
<a href="{{ route('card-member') }}" class="btn btn-secondary">Back</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
<div class="mb-3">
|
||||
<strong>Status:</strong> {{ $member['status'] }}
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<strong>Lock Status:</strong> {{ $member['is_locked'] == 1 ? 'Locked' : 'Unlocked' }}
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<a href="{{ route('locked-account') }}" class="btn btn-secondary">Back</a>
|
||||
<form action="{{ route('locked-account.activate', $member['id']) }}" method="POST">
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
@endif
|
||||
@include('components.table-component', [
|
||||
@include('components.card-member-component', [
|
||||
'pageTitle' => 'Card Member',
|
||||
'data' => $members,
|
||||
'columns' => [
|
||||
|
@ -25,7 +25,8 @@
|
|||
['name' => 'Last Name', 'key' => 'lastName', 'sortable' => true],
|
||||
['name' => 'Birthday', 'key' => 'birthday', 'sortable' => true],
|
||||
['name' => 'Card Type', 'key' => 'cardType', 'sortable' => true],
|
||||
['name' => 'Status', 'key' => 'status', 'sortable' => true]
|
||||
['name' => 'Status', 'key' => 'status', 'sortable' => true],
|
||||
['name' => 'Lock Status', 'key' => 'is_locked', 'sortable' => true], // New column
|
||||
],
|
||||
'actions' => ['view'],
|
||||
'showAddButton' => false,
|
||||
|
@ -36,6 +37,7 @@
|
|||
'currentPage' => $currentPage ?? 1,
|
||||
'lastPage' => $lastPage ?? 1,
|
||||
'total' => $total ?? 0,
|
||||
'viewRoute' => route('card-member.show', ':id'),
|
||||
])
|
||||
<div id="no-data-message" style="display: {{ empty($members) ? 'block' : 'none' }}; text-align: center; margin-top: 20px;">
|
||||
<p>No card members found.</p>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
@endif
|
||||
@include('components.table-component', [
|
||||
@include('components.card-member-component', [
|
||||
'pageTitle' => 'Locked Account',
|
||||
'data' => $members ?? [],
|
||||
'columns' => [
|
||||
|
@ -25,7 +25,8 @@
|
|||
['name' => 'Last Name', 'key' => 'lastName', 'sortable' => true],
|
||||
['name' => 'Birthday', 'key' => 'birthday', 'sortable' => true],
|
||||
['name' => 'Card Type', 'key' => 'cardType', 'sortable' => true],
|
||||
['name' => 'Status', 'key' => 'status', 'sortable' => true]
|
||||
['name' => 'Status', 'key' => 'status', 'sortable' => true],
|
||||
['name' => 'Lock Status', 'key' => 'is_locked', 'sortable' => true], // New column
|
||||
],
|
||||
'actions' => ['view'],
|
||||
'showAddButton' => false,
|
||||
|
@ -36,6 +37,7 @@
|
|||
'currentPage' => $currentPage ?? 1,
|
||||
'lastPage' => $lastPage ?? 1,
|
||||
'total' => $total ?? 0,
|
||||
'viewRoute' => route('locked-account.show', ':id'),
|
||||
])
|
||||
<div id="no-data-message" style="display: {{ empty($members ?? []) ? 'block' : 'none' }}; text-align: center; margin-top: 20px;">
|
||||
<p>No locked accounts found.</p>
|
||||
|
|
|
@ -162,11 +162,10 @@ Route::post('/notification', [NotificationController::class, 'store'])->name('no
|
|||
|
||||
//Member Management
|
||||
Route::get('/card-member', [CardMemberController::class, 'index'])->name('card-member');
|
||||
Route::get('/locked-account', [CardMemberController::class, 'lockedAccounts'])->name('locked-account');
|
||||
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-account/{uuid}', [CardMemberController::class, 'show'])->name('locked-account.show');
|
||||
Route::post('/locked-account/activate/{uuid}', [CardMemberController::class, 'activate'])->name('locked-account.activate');
|
||||
|
||||
//Promotion
|
||||
Route::get('/promotions', [PromotionController::class, 'index'])->name('promotions');
|
||||
Route::get('/promotions/create', [PromotionController::class, 'create'])->name('promotions.create');
|
||||
|
|
Loading…
Reference in New Issue