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 3ab620e commit 54de34a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 167 deletions.
118 changes: 56 additions & 62 deletions src/main/resources/static/html/admin-access.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -8,69 +9,62 @@
</head>
</br>
<body>
<h1>Access users</h1>
<div id="table-container">
<div id="search-container">
<div id="userSearchForm">
<label for="userName">user name :</label>
<input type="text" id="userName" name="userName">
<br>
<label for="dateFrom">date from :</label>
<input type="number" id="dateFrom" name="dateFrom" step="5">
<br>
<label for="dateTo">date to :</label>
<input type="number" id="dateTo" name="dateTo" step="5">
<br>
<label for="sortBy">sort by :</label>
<select id="sortBy" name="sortBy">
<option value="accessTime,asc">ascending</option>
<option value="accessTime,desc">descending</option>
</select>
<br>
<label for="pageSize">page size:</label>
<select id="pageSize" name="pageSize">
<option value="10" selected>10</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option value="2000">2000</option>
<option value="5000">5000</option>
<option value="10000">10000</option>
</select>
<br>
<label for="pageSize">display option:</label>
<select id="displayOption" name="displayOption">
<option value="data" >data</option>
<option value="email"selected>email</option>
</select>
<br>
</div>
<h1>Access users</h1>
<div id="table-container">
<div id="search-container">
<div id="userSearchForm">
<label for="userName">user name :</label>
<input type="text" id="userName" name="userName">
<br>
<label for="dateFrom">date from :</label>
<input type="number" id="dateFrom" name="dateFrom" step="5">
<br>
<label for="dateTo">date to :</label>
<input type="number" id="dateTo" name="dateTo" step="5">
<br>
<label for="sortBy">sort by :</label>
<select id="sortBy" name="sortBy">
<option value="accessTime,asc">ascending</option>
<option value="accessTime,desc">descending</option>
</select>
<br>
<label for="pageSize">page size:</label>
<select id="pageSize" name="pageSize">
<option value="10" selected>10</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option value="2000">2000</option>
<option value="5000">5000</option>
<option value="10000">10000</option>
</select>
</div>
</div>

<table id="user-table">
<thead>
<tr>
<th>last login</th>
<th>name</th>
<th>email</th>
<th>encrypt password</th>
<th>block</th>
</tr>
</thead>
<tbody id="table-body">
<!-- User rows will be dynamically added here -->
</tbody>
</table>
<div id="pagination">
<!-- Pagination links will be dynamically generated here -->
</div>
</br>
</br>
<table id="user-table">
<thead>
<tr>
<th>last login</th>
<th>name</th>
<th>email</th>
<th>encrypt password</th>
<th>block</th>
</tr>
</thead>
<tbody id="table-body">
<!-- User rows will be dynamically added here -->
</tbody>
</table>
<div id="pagination">
<!-- Pagination links will be dynamically generated here -->
</div>
<script src="../js/admin-access.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</body>
</br>
</br>
</div>
<script src="../js/admin-access.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</body>
</html>
85 changes: 0 additions & 85 deletions src/main/resources/static/html/admin-data.html

This file was deleted.

24 changes: 4 additions & 20 deletions src/main/resources/static/js/admin-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,26 @@ sortBySelection.addEventListener("change", (event) => {
pageSizeSelection.addEventListener("change", (event) => {
fetchAndDisplayUsers().then(() => {});
});

async function fetchAndDisplayUsers() {
currentPage = 1; // Reset current page to 1 when fetching new data
pageSize = parseInt(pageSizeSelection.value); // Update pageSize based on selection
users = await fetchUser();
await displayUsers();
await updatePagination();
}


async function fetchUser() {
try {
const memberName = userNameInput.value.trim();
const dateFrom = dateFromSelection.value.trim();
const dateTo = dateToSelection.value.trim();
const sortBy = sortBySelection.options[sortBySelection.selectedIndex].value;
const pageSize = pageSizeSelection.options[pageSizeSelection.selectedIndex].value;

const fetchUrl = currentDomain + "/api/admin/users/access?"
let response = await fetch(fetchUrl + new URLSearchParams({
memberName: memberName,
size: pageSize,
size: pageSize, // Use the updated pageSize
dateFrom: dateFrom,
dateTo: dateTo,
sort: sortBy
Expand All @@ -92,23 +92,13 @@ async function displayUsers() {
tableBody.innerHTML = '';
const startIndex = (currentPage - 1) * pageSize;
const endIndex = startIndex + pageSize;
const displayOption = document.getElementById('displayOption').value;


for (let index = startIndex; index < endIndex && index < users.length; index++) {
const user = users[index];
const row = document.createElement('tr');
row.id = `user-${user.id}`;

let displayValue = "";
if (displayOption === "data") {
displayValue = user.dateTime;
} else if (displayOption === "email") {
displayValue = user.memberEmail;
}

row.innerHTML = `
<td>${displayValue}</td>
<td>${user.dateTime}</td>
<td>${user.memberName}</td>
<td>${user.memberEmail}</td>
<td>${user.memberEncryptedPassword}</td>
Expand All @@ -125,12 +115,6 @@ function navigateToPage(option) {
window.location.href = "./admin-access.html";
}
}
const displayOptionSelection = document.getElementById('displayOption');
displayOptionSelection.addEventListener('change', () => {
const selectedOption = displayOptionSelection.value;
navigateToPage(selectedOption);
});



async function updatePagination() {
Expand Down

0 comments on commit 54de34a

Please sign in to comment.