Skip to content

Commit

Permalink
fix : admin-access code fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ha-seungwon committed Aug 17, 2023
1 parent 3fe33f0 commit bd67caa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
68 changes: 38 additions & 30 deletions src/main/resources/static/js/admin-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const sortBySelection = document.getElementById('sortBy');
const dateFromSelection = document.getElementById('dateFrom');
const dateToSelection = document.getElementById('dateTo');

let pageSize = 10
let pageSize = 20
let currentPage = 1;
let users = []
let hiPage =1
Expand Down Expand Up @@ -53,13 +53,11 @@ pageSizeSelection.addEventListener("change", (event) => {
fetchAndDisplayUsers().then(() => {});
});

// Function to fetch and display products based on the current page and search query
async function fetchAndDisplayUsers() {
pageSize = pageSizeSelection.options[pageSizeSelection.selectedIndex].value;
currentPage = 1;
currentPage = 1; // Reset current page to 1 when fetching new data
users = await fetchUser();
await displayUsers()
await updatePagination()
await displayUsers();
await updatePagination();
}

async function fetchUser() {
Expand Down Expand Up @@ -91,12 +89,14 @@ async function fetchUser() {

// Function to display products in the table
async function displayUsers() {
hiPage += 100
tableBody.innerHTML = '';
for(let index = 0; index < users.length; index++) {
const user = users[index]
const startIndex = (currentPage - 1) * pageSize;
const endIndex = startIndex + pageSize;

for (let index = startIndex; index < endIndex && index < users.length; index++) {
const user = users[index];
const row = document.createElement('tr');
row.id = `user-${user.id}`
row.id = `user-${user.id}`;
row.innerHTML = `
<td>${user.dateTime}</td>
<td>${user.memberName}</td>
Expand All @@ -109,21 +109,27 @@ async function displayUsers() {

async function updatePagination() {
pagination.innerHTML = '';
if(currentPage > 10) {

const totalPages = Math.ceil(users.length / pageSize);
const maxVisiblePages = 10;

const startPage = Math.max(currentPage - Math.floor(maxVisiblePages / 2), 1);
const endPage = Math.min(startPage + maxVisiblePages - 1, totalPages);

if (currentPage > 1) {
const leftArrow = document.createElement('a');
leftArrow.href = '#';
leftArrow.textContent = '<<';
leftArrow.className = "pagination-link";
leftArrow.addEventListener('click', async () => {
currentPage = startPage - 1;
endPage = currentPage
startPage = startPage - pageCount
await updatePagination()
currentPage--;
await updatePagination();
await displayUsers();
});
pagination.appendChild(leftArrow);
}

for (let pageNumber = hiPage; pageNumber <= hiPage+10; pageNumber++) {
for (let pageNumber = startPage; pageNumber <= endPage; pageNumber++) {
const link = document.createElement('a');
link.href = '#';
link.textContent = pageNumber;
Expand All @@ -133,25 +139,27 @@ async function updatePagination() {
}
link.addEventListener('click', async () => {
currentPage = pageNumber;
await updatePagination()
await updatePagination();
await displayUsers();
});

pagination.appendChild(link);
}
const rightArrow = document.createElement('a');
rightArrow.href = '#';
rightArrow.textContent = '>>';
rightArrow.className = "pagination-link";
rightArrow.addEventListener('click', async () => {
currentPage = currentPage + 100;
hiPage = hiPage+10
startPage = currentPage
endPage = startPage + users.length / pageSize -1
await updatePagination()
});
pagination.appendChild(rightArrow);

if (currentPage < totalPages) {
const rightArrow = document.createElement('a');
rightArrow.href = '#';
rightArrow.textContent = '>>';
rightArrow.className = "pagination-link";
rightArrow.addEventListener('click', async () => {
currentPage++;
await updatePagination();
await displayUsers();
});
pagination.appendChild(rightArrow);
}
}


// Initial fetch and display of products
fetchAndDisplayUsers();
updatePagination()
2 changes: 1 addition & 1 deletion src/main/resources/static/js/admin-score.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const minScoreSelection = document.getElementById('minScore');
const maxScoreSelection = document.getElementById('maxScore');
const sortBySelection = document.getElementById('sortBy');

let pageSize = 10
let pageSize = 100
let pageCount = 5
let startPage = 1;
let currentPage = 1;
Expand Down

0 comments on commit bd67caa

Please sign in to comment.