fix: add pagination to draw list of played game in profile page

This commit is contained in:
kmitresse
2024-06-14 09:35:48 +02:00
parent 96fc8a2c11
commit 01c1793c48
10 changed files with 232 additions and 44 deletions
@@ -9,6 +9,7 @@
<layout:base title="${translator.translate('profile_title')}">
<jsp:attribute name="head">
<script defer type="module" src="${pageContext.request.contextPath}/static/js/form/profile.js"></script>
<script defer type="module" src="${pageContext.request.contextPath}/static/js/pagination/statistics-pagination.js"></script>
</jsp:attribute>
<jsp:body>
<component:hero>
@@ -1,11 +1,10 @@
<%@ tag import="uppa.project.database.pojo.Player" %>
<%@ tag import="uppa.project.web.translation.Translator" %>
<%@ tag import="java.util.Date" %>
<%@ tag import="java.text.SimpleDateFormat" %>
<%@tag description="component/statistics" pageEncoding="UTF-8" %>
<% Translator translator = (Translator) request.getSession().getAttribute("translator"); %>
<% int currentPage = request.getParameter("currentPage") == null ? 1 : Integer.parseInt(request.getParameter("currentPage")); %>
<jsp:useBean id="user" class="uppa.project.database.pojo.User" scope="session"/>
<input type="hidden" id="current-page" value="<%=currentPage%>"/>
<input type="hidden" id="nb-pages" value="<%=(int) Math.ceil((double) user.getNbPlayedGame() / 5)%>"/>
<h4 class="title is-4">${translator.translate("global_statistics")}</h4>
<div class="level">
<div class="level-item has-text-centered">
@@ -35,7 +34,7 @@
</div>
<h4 class="title is-4">${translator.translate("statistics_games_played")} </h4>
<table class="table is-fullwidth">
<table id="pagination-players" class="table is-fullwidth">
<thead>
<tr>
<th>${translator.translate("statistics_game_date")}</th>
@@ -44,31 +43,12 @@
<th></th>
</tr>
</thead>
<tbody>
<% for (int i = 0; i < user.getPlayedGames().size(); i++) {
Player player = user.getPlayedGames().get(i);
%>
<tr>
<% Date date = player.getGame().getCreatedAt();
String language = translator.getLanguage();
SimpleDateFormat sdfDay;
SimpleDateFormat sdfHour;
if (language.equals("EN")) {
sdfDay = new SimpleDateFormat("MM/dd/yyyy");
sdfHour = new SimpleDateFormat("HH:mm");
} else {
sdfDay = new SimpleDateFormat("dd/MM/yyyy");
sdfHour = new SimpleDateFormat("HH:mm");
}
String day = sdfDay.format(date);
String hour = sdfHour.format(date);
%>
<td><%=day%>, <%=hour%> </td>
<td><%= player.getScore() %></td>
<td><%= player.getGame().getWinner().getUser().getUsername() %></td>
<td><a href="${pageContext.request.contextPath}/game-statistics?id=<%= player.getGame().getId() %>">${translator.translate("statistics_game_show")}</a></td>
</tr>
<% } %>
</tbody>
<tbody></tbody>
</table>
<nav class="pagination is-rounded" role="navigation" aria-label="pagination">
<ul class="pagination-list">
<li><a class="pagination-previous">${translator.translate('pagination_previous')}</a></li>
<li><a class="pagination-link pagination-current" aria-label="Goto page 1"><%=currentPage%></a></li>
<li><a class="pagination-next">${translator.translate('pagination_next')}</a></li>
</ul>
</nav>
@@ -7,6 +7,7 @@
<form id="profile-form" action="${pageContext.request.contextPath}/profile" method="post">
<jsp:useBean id="user" class="uppa.project.database.pojo.User" scope="session"/>
<input id="user-id" type="hidden" name="user-id" value="${user.id}"/>
<div class="field">
<label class="label" for="username">${translator.translate('user_username')}</label>
<div class="control has-icons-left">
@@ -630,5 +630,13 @@
"game_statistics_win": {
"EN": "Win",
"FR": "Victoire"
},
"pagination_previous": {
"EN": "Previous",
"FR": "Précédent"
},
"pagination_next": {
"EN": "Next",
"FR": "Suivant"
}
}