theouche merge

This commit is contained in:
CHIBOUB Chakib
2024-08-05 17:46:19 +02:00
8 changed files with 338 additions and 126 deletions

View File

@@ -1,4 +1,5 @@
document.addEventListener('DOMContentLoaded', () => {
console.log('DOMContentLoaded event fired');
const checkNicknameButton = document.getElementById('check-nickname');
const registerButton = document.getElementById('register');
const loginButton = document.getElementById('login');
@@ -11,6 +12,13 @@ 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 viewPlayersButton = document.getElementById('view-players');
//const viewMatchesButton = document.getElementById('view-matches');
const menuButton = document.querySelector('.burger-menu');
const playerList = document.getElementById('player-list');
const matchList = document.getElementById('match-list');
const dropdownMenu = document.getElementById('dropdown-menu');
let socket;
@@ -239,4 +247,145 @@ 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();
//}
//})
console.log('Here');
function toggleMenu() {
console.log('Menu toggled');
if (dropdownMenu.style.display === "block") {
dropdownMenu.style.display = "none";
} else {
dropdownMenu.style.display = "block";
}
}
function showTable(tableId) {
// Masquer tous les tableaux
if (playerList) {
playerList.style.display = 'none';
}
if (matchList) {
matchList.style.display = 'none';
}
// Afficher le tableau sélectionné
if (tableId === 'player-list') {
if (playerList) {
playerList.style.display = 'block';
}
fetchPlayers();
} else if (tableId === 'match-list') {
if (matchList) {
matchList.style.display = 'block';
}
fetchMatches();
}
// Masquer le menu après la sélection
if (dropdownMenu) {
dropdownMenu.style.display = 'none';
}
}
// Ajouter les gestionnaires d'événements
if (menuButton) {
menuButton.addEventListener('click', toggleMenu);
}
const links = document.querySelectorAll('#dropdown-menu a');
links.forEach(link => {
link.addEventListener('click', (event) => {
event.preventDefault(); // Empêche le comportement par défaut du lien
const tableId = link.getAttribute('data-table');
showTable(tableId);
});
});
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="navbar">
<button class="burger-menu">☰</button>
<div id="dropdown-menu" class="dropdown-content">
<a href="#" data-table="player-list">Players</a>
<a href="#" data-table="match-list">Matches</a>
</div>
</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" class="content-list" style="display: none;">
<h1>Matches</h1>
<table>
<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" class="content-list" style="display:none;">
<h1>Players</h1>
<table>
<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,9 @@
}
setInterval(createTrail, 100);
</script>
</body>
</html>
</html>

View File

@@ -1,5 +1,6 @@
/* General styles */
body,
html {
font-family: Arial, sans-serif;
color: #00ffff;
@@ -250,4 +251,41 @@ button:hover {
position: relative;
z-index: 10;
max-width: 80%;
}
}
.navbar {
position: absolute;
top: 0;
right: 0;
padding: 10px;
}
.burger-menu {
font-size: 24px;
background: none;
border: none;
color: white;
cursor: pointer;
}
.dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #f1f1f1;
}
.show {display: block;}