mirror of
https://github.com/AudebertAdrien/ft_transcendence.git
synced 2025-12-16 05:57:48 +01:00
Ca casse les couilles, tounroi veut pas s'afficher, I need chatgpt plus prenium extra !
This commit is contained in:
parent
0a0641db1f
commit
b1c865acae
2
makefile
2
makefile
@ -32,7 +32,7 @@ ps:
|
||||
db-shell:
|
||||
$(COMPOSE) exec db psql -U 42student players_db
|
||||
|
||||
re : destroy down up
|
||||
re: destroy down up
|
||||
|
||||
help:
|
||||
@echo "Usage:"
|
||||
|
||||
@ -4,9 +4,7 @@ from django.urls import path, include
|
||||
from . import views
|
||||
from .views import player_list, tournoi_list, match_list
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from .views import match_list_json
|
||||
from .views import player_list_json
|
||||
|
||||
from .views import match_list_json, player_list_json, tournoi_list_json
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
@ -20,4 +18,5 @@ urlpatterns = [
|
||||
path('tournois/', tournoi_list, name='tournoi_list'),
|
||||
path('api/match_list/', match_list_json, name='match_list_json'),
|
||||
path('api/player_list/', player_list_json, name='player_list_json'),
|
||||
path('api/tournoi_list/', tournoi_list_json, name='tournoi_list_json')
|
||||
]
|
||||
|
||||
@ -114,6 +114,20 @@ def player_list_json(request):
|
||||
# Renvoie les données en JSON
|
||||
return JsonResponse(data)
|
||||
|
||||
def tournoi_list_json(request):
|
||||
# Récupère tous les joueurs
|
||||
tournois = Tournoi.objects.all()
|
||||
|
||||
# Crée un dictionnaire avec les informations des joueurs
|
||||
data = {
|
||||
'tournois': list(tournois.values(
|
||||
'id', 'name', 'nbr_player', 'date', 'winner'
|
||||
))
|
||||
}
|
||||
|
||||
# Renvoie les données en JSON
|
||||
return JsonResponse(data)
|
||||
|
||||
|
||||
####################### THEOUCHE PART ############################
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const menuButton = document.querySelector('.burger-menu');
|
||||
const playerList = document.getElementById('player-list');
|
||||
const matchList = document.getElementById('match-list');
|
||||
const tournoiList = document.getElementById('tournoi-list');
|
||||
const dropdownMenu = document.getElementById('dropdown-menu');
|
||||
|
||||
const pongElements = document.getElementById('pong-elements');
|
||||
@ -283,26 +284,26 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
function showTable(tableId) {
|
||||
// Masquer tous les tableaux
|
||||
if (playerList) {
|
||||
playerList.style.display = 'none';
|
||||
}
|
||||
if (matchList) {
|
||||
matchList.style.display = 'none';
|
||||
}
|
||||
|
||||
printf('Entering showTable')
|
||||
console.log('Entering showTable', tableId);
|
||||
if (playerList) playerList.style.display = 'none';
|
||||
if (matchList) matchList.style.display = 'none';
|
||||
if (tournoiList) tournoiList.style.display = 'none';
|
||||
|
||||
// Afficher le tableau sélectionné
|
||||
if (tableId === 'player-list') {
|
||||
if (playerList) {
|
||||
playerList.style.display = 'block';
|
||||
}
|
||||
print('Showing player list');
|
||||
if (playerList) playerList.style.display = 'block';
|
||||
fetchPlayers();
|
||||
} else if (tableId === 'match-list') {
|
||||
if (matchList) {
|
||||
matchList.style.display = 'block';
|
||||
}
|
||||
print('Showing match list');
|
||||
if (matchList) matchList.style.display = 'block';
|
||||
fetchMatches();
|
||||
} else if (tableId === 'tournoi-list') {
|
||||
print('Showing tournoi list');
|
||||
if (tournoiList) tournoiList.style.display = 'block';
|
||||
fetchTournois();
|
||||
}
|
||||
|
||||
// Masquer le menu après la sélection
|
||||
if (dropdownMenu) {
|
||||
dropdownMenu.style.display = 'none';
|
||||
@ -345,6 +346,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
.catch(error => console.error('Error fetching match data:', error));
|
||||
}
|
||||
|
||||
function fetchTournois(){
|
||||
print('Fetching tournois...');
|
||||
fetch('/api/tournoi_list/')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
print('Tournois data:', data);
|
||||
if (data.tournois) {
|
||||
displayTournois(data.tournois);
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error fetching match data:', error));
|
||||
}
|
||||
|
||||
function displayMatches(matches) {
|
||||
const matchListBody = document.querySelector('#match-list tbody');
|
||||
matchListBody.innerHTML = '';
|
||||
@ -394,4 +408,26 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
}
|
||||
|
||||
function displayTournois(tournois) {
|
||||
print('Displaying tournois:');
|
||||
const tournoisListBody = document.querySelector('#tournoi-list tbody');
|
||||
tournoisListBody.innerHTML = '';
|
||||
|
||||
if (tournois.length === 0) {
|
||||
print('No tournois to display');
|
||||
}
|
||||
|
||||
tournois.forEach(tournoi => {
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
<td>${tournoi.id}</td>
|
||||
<td>${tournoi.name}</td>
|
||||
<td>${tournoi.nbr_player}</td>
|
||||
<td>${tournoi.date}</td>
|
||||
<td>${tournoi.winner.name}</td>
|
||||
`;
|
||||
tournoisListBody.appendChild(row);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@ -208,6 +208,8 @@
|
||||
<div id="dropdown-menu" class="dropdown-content">
|
||||
<a href="#" data-table="player-list">Players</a>
|
||||
<a href="#" data-table="match-list">Matches</a>
|
||||
<a href="#" data-table="tournoi-list">Tournois</a>
|
||||
<a href="#" data-table="blockchain-list">blockchain</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -268,7 +270,7 @@
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="player-list" class="content-list" style="display:none;">
|
||||
<div id="player-list" class="content-list" style="display: none;">
|
||||
<h1>Players</h1>
|
||||
<table>
|
||||
<thead>
|
||||
@ -314,6 +316,36 @@
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="tournoi-list" class="content-list" style="display: none;">
|
||||
<h1>Tournois</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Nbr_players</th>
|
||||
<th>Date</th>
|
||||
<th>Winner</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for tournoi in tournois %}
|
||||
<tr>
|
||||
<td>{{ tournoi.id }}</td>
|
||||
<td>{{ tournoi.name }}</td>
|
||||
<td>{{ tournoi.nbr_player }}</td>
|
||||
<td>{{ tournoi.date }}</td>
|
||||
<td>{{ tournoi.winner.name }}</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr>
|
||||
<td colspan="14">No tournois found.</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script src="{% static 'game.js' %}"></script>
|
||||
<script>
|
||||
const translations = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user