add list selection players et match, need to move it on the side and use a icone

This commit is contained in:
Theouche
2024-08-01 17:26:14 +02:00
parent 8ed7cf6419
commit fb9c54c8df
10 changed files with 273 additions and 126 deletions

View File

@@ -11,6 +11,9 @@ document.addEventListener('DOMContentLoaded', () => {
const loginForm = document.getElementById('login-form');
const registerForm = document.getElementById('register-form');
const formBlock = document.getElementById('block-form');
const viewSelector = document.getElementById('view-selector');
const playerList = document.getElementById('player-list');
const matchList = document.getElementById('match-list');
let socket;
@@ -241,4 +244,92 @@ document.addEventListener('DOMContentLoaded', () => {
player2Score.textContent = gameState.player2_score;
}
viewSelector.addEventListener('change', function() {
const selectedView = this.value;
// Masquer les deux listes par défaut
playerList.style.display = 'none';
matchList.style.display = 'none';
// Afficher la liste sélectionnée
if (selectedView === 'player-list') {
playerList.style.display = 'block';
fetchPlayers();
} else if (selectedView === 'match-list') {
matchList.style.display = 'block';
fetchMatches();
}
})
function fetchMatches() {
fetch('/api/match_list/')
.then(response => response.json())
.then(data => {
if (data.matches) {
displayMatches(data.matches);
}
})
.catch(error => console.error('Error fetching match data:', error));
}
function fetchPlayers(){
fetch('/api/player_list/')
.then(response => response.json())
.then(data => {
if (data.players) {
displayPlayers(data.players);
}
})
.catch(error => console.error('Error fetching match data:', error));
}
function displayMatches(matches) {
const matchListBody = document.querySelector('#match-list tbody');
matchListBody.innerHTML = '';
matches.forEach(match => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${match.id}</td>
<td>${match.player1__name}</td>
<td>${match.player2__name}</td>
<td>${match.score_player1}</td>
<td>${match.score_player2}</td>
<td>${match.winner__name}</td>
<td>${match.nbr_ball_touch_p1}</td>
<td>${match.nbr_ball_touch_p2}</td>
<td>${match.duration}</td>
<td>${match.date}</td>
<td>${match.is_tournoi}</td>
<td>${match.tournoi__name}</td>
`;
matchListBody.appendChild(row);
});
}
function displayPlayers(players) {
const playersListBody = document.querySelector('#player-list tbody');
playersListBody.innerHTML = '';
players.forEach(player => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${player.id}</td>
<td>${player.name}</td>
<td>${player.total_match}</td>
<td>${player.total_win}</td>
<td>${player.p_win}</td>
<td>${player.m_score_match}</td>
<td>${player.m_score_adv_match}</td>
<td>${player.best_score}</td>
<td>${player.m_nbr_ball_touch}</td>
<td>${player.total_duration}</td>
<td>${player.m_duration}</td>
<td>${player.num_participated_tournaments}</td>
<td>${player.num_won_tournaments}</td>
`;
playersListBody.appendChild(row);
});
}
});

View File

@@ -10,7 +10,6 @@
<div class="logo">
<img src="{% static 'logo-42-perpignan.png' %}" alt="Logo">
</div>
</head>
<body>
@@ -46,6 +45,14 @@
</div>
</div>
<div class="menu">
<select id="view-selector">
<option value="none">-- Select View --</option>
<option value="player-list">Players</option>
<option value="match-list">Matches</option>
</select>
</div>
<div id="game1" style="display: none;">
<div id="gameCode" class="game-code">Game Code : </div>
<div id="player1-name" class="name">Player 1</div>
@@ -58,6 +65,97 @@
<div id="ball"></div>
</div>
</div>
<div id="match-list" style="display: none;">
<h1>Matches List</h1>
<table border="1">
<thead>
<tr>
<th>ID</th>
<th>Player 1</th>
<th>Player 2</th>
<th>Score Player 1</th>
<th>Score Player 2</th>
<th>Winner</th>
<th>Ball Touches Player 1</th>
<th>Ball Touches Player 2</th>
<th>Duration</th>
<th>Date</th>
<th>Is Tournament</th>
<th>Tournament</th>
</tr>
</thead>
<tbody>
{% for match in matches %}
<tr>
<td>{{ match.id }}</td>
<td>{{ match.player1.name }}</td>
<td>{{ match.player2.name }}</td>
<td>{{ match.score_player1 }}</td>
<td>{{ match.score_player2 }}</td>
<td>{{ match.winner.name }}</td>
<td>{{ match.nbr_ball_touch_p1 }}</td>
<td>{{ match.nbr_ball_touch_p2 }}</td>
<td>{{ match.duration }}</td>
<td>{{ match.date }}</td>
<td>{{ match.is_tournoi }}</td>
<td>{{ match.tournoi.name }}</td>
</tr>
{% empty %}
<tr>
<td colspan="12">No matches found.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div id="player-list" style="display: none;">
<h1>Players List</h1>
<table border="1">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Total Matches</th>
<th>Total Wins</th>
<th>Win Percentage</th>
<th>Average Match Score</th>
<th>Average Opponent Score</th>
<th>Best Score</th>
<th>Average Ball Touches</th>
<th>Total Duration</th>
<th>Average Duration</th>
<th>Participated Tournaments</th>
<th>Won Tournaments</th>
</tr>
</thead>
<tbody>
{% for player in players %}
<tr>
<td>{{ player.id }}</td>
<td>{{ player.name }}</td>
<td>{{ player.total_match }}</td>
<td>{{ player.total_win }}</td>
<td>{{ player.p_win }}</td>
<td>{{ player.m_score_match }}</td>
<td>{{ player.m_score_adv_match }}</td>
<td>{{ player.best_score }}</td>
<td>{{ player.m_nbr_ball_touch }}</td>
<td>{{ player.total_duration }}</td>
<td>{{ player.m_duration }}</td>
<td>{{ player.num_participated_tournaments }}</td>
<td>{{ player.num_won_tournaments }}</td>
</tr>
{% empty %}
<tr>
<td colspan="13">No players found.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<script src="{% static 'game.js' %}"></script>
<script>
const starsContainer = document.getElementById('stars');
@@ -73,7 +171,8 @@
}
setInterval(createTrail, 100);
</script>
</body>
</html>
</html>

View File

@@ -250,4 +250,17 @@ button:hover {
position: relative;
z-index: 10;
max-width: 80%;
}
.menu {
margin-top: 20px;
text-align: center;
}
select#view-selector {
padding: 10px;
font-size: 16px;
border-radius: 5px;
border: 1px solid #ccc;
cursor: pointer;
}