mirror of
https://github.com/appen-isen/site-interpromo-2024.git
synced 2026-01-18 16:37:30 +01:00
Fix rollback
This commit is contained in:
@@ -77,7 +77,7 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const data = { "point1": currentStatus.point1 + 1 };
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = currentStatus.point1 + 1;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
point2Team1.addEventListener('click', async function (event) {
|
||||
@@ -85,7 +85,7 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const data = { "point1": currentStatus.point1 + 2 };
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = currentStatus.point1 + 2;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
point3Team1.addEventListener('click', async function (event) {
|
||||
@@ -93,7 +93,7 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const data = { "point1": currentStatus.point1 + 3 };
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = currentStatus.point1 + 3;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
point1Team2.addEventListener('click', async function (event) {
|
||||
@@ -101,7 +101,7 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const data = { "point2": currentStatus.point2 + 1 };
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint2.innerHTML = currentStatus.point2 + 1;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
point2Team2.addEventListener('click', async function (event) {
|
||||
@@ -109,7 +109,7 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const data = { "point2": currentStatus.point2 + 2 };
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint2.innerHTML = currentStatus.point2 + 2;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
point3Team2.addEventListener('click', async function (event) {
|
||||
@@ -117,7 +117,7 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const data = { "point2": currentStatus.point2 + 3 };
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint2.innerHTML = currentStatus.point2 + 3;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
// Ajout des champs de saisie pour les scores
|
||||
@@ -147,7 +147,7 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = manualScore1;
|
||||
textPoint2.innerHTML = manualScore2;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
} else if (currentStatus.expand.sport.name === "volleyball" || currentStatus.expand.sport.name === "badminton") {
|
||||
//Mise à jour de l'affichage des boutons
|
||||
@@ -157,18 +157,22 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
//Comptage des points
|
||||
buttonPoint1.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
const data = { "point1": currentStatus.point1 + 1 };
|
||||
const data = {"point1": currentStatus.point1 + 1};
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = currentStatus.point1 + 1;
|
||||
location.reload();
|
||||
console.log(currentStatus.point1)
|
||||
console.log(currentStatus);
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
buttonPoint2.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
const data = { "point2": currentStatus.point2 + 1 };
|
||||
const data = {"point2": currentStatus.point2 + 1};
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint2.innerHTML = currentStatus.point2 + 1;
|
||||
location.reload();
|
||||
console.log(currentStatus.point2)
|
||||
console.log(currentStatus);
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
//Ajoute un bouton pour le set sous le button pour finir le match
|
||||
@@ -197,35 +201,35 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const set1Team2 = document.getElementById("btnSet2");
|
||||
set1Team1.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
const data = { "set1": currentStatus.set1 + 1, "point1": 0, "point2": 0 };
|
||||
const data = {"set1": currentStatus.set1 + 1, "point1": 0, "point2": 0};
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = 0;
|
||||
textPoint2.innerHTML = 0;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
set1Team2.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
const data = { "set2": currentStatus.set2 + 1, "point1": 0, "point2": 0 };
|
||||
const data = {"set2": currentStatus.set2 + 1, "point1": 0, "point2": 0};
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = 0;
|
||||
textPoint2.innerHTML = 0;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
const point1Team1 = document.getElementById("btnPoint1");
|
||||
const point2Team1 = document.getElementById("btnPoint2");
|
||||
point1Team1.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
const data = { "point1": currentStatus.point1 + 1 };
|
||||
const data = {"point1": currentStatus.point1 + 1};
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = currentStatus.point1 + 1;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
point2Team1.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
const data = { "point2": currentStatus.point2 + 1 };
|
||||
const data = {"point2": currentStatus.point2 + 1};
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint2.innerHTML = currentStatus.point2 + 1;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
// Ajout des champs de saisie pour les scores
|
||||
@@ -267,7 +271,62 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = manualScore1;
|
||||
textPoint2.innerHTML = manualScore2;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
} else if (currentStatus.expand.sport.name === "handball") {
|
||||
// Mise à jour de l'affichage des boutons
|
||||
buttonPoint1.innerHTML = "1 point pour " + currentStatus.expand.team1.name;
|
||||
buttonPoint2.innerHTML = "1 point pour " + currentStatus.expand.team2.name;
|
||||
|
||||
// Comptage des points
|
||||
buttonPoint1.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
const data = {"point1": currentStatus.point1 + 1};
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = currentStatus.point1 + 1;
|
||||
console.log(currentStatus.point1)
|
||||
console.log(currentStatus);
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
buttonPoint2.addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
const data = {"point2": currentStatus.point2 + 1};
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint2.innerHTML = currentStatus.point2 + 1;
|
||||
console.log(currentStatus.point2)
|
||||
console.log(currentStatus);
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
// Ajout des champs de saisie pour les scores
|
||||
arbitrageDiv.innerHTML += `
|
||||
<div class="text-center">
|
||||
<label for="manualScore1">Score manuel pour ${currentStatus.expand.team1.name}:</label>
|
||||
<input type="number" id="manualScore1" value="${currentStatus.point1}" class="form-control">
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<label for="manualScore2">Score manuel pour ${currentStatus.expand.team2.name}:</label>
|
||||
<input type="number" id="manualScore2" value="${currentStatus.point2}" class="form-control">
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<button class="btn btn-primary" id="updateManualScore">Mettre à jour le score</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Gestion de la mise à jour manuelle des scores
|
||||
document.getElementById("updateManualScore").addEventListener('click', async function (event) {
|
||||
event.preventDefault();
|
||||
const manualScore1 = parseInt(document.getElementById("manualScore1").value, 10);
|
||||
const manualScore2 = parseInt(document.getElementById("manualScore2").value, 10);
|
||||
const data = {
|
||||
"point1": manualScore1,
|
||||
"point2": manualScore2
|
||||
};
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = manualScore1;
|
||||
textPoint2.innerHTML = manualScore2;
|
||||
//location.reload();
|
||||
});
|
||||
} else {
|
||||
//Mise à jour de l'affichage des boutons
|
||||
@@ -280,7 +339,9 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const data = { "point1": currentStatus.point1 + 1 };
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = currentStatus.point1 + 1;
|
||||
location.reload();
|
||||
console.log(currentStatus.point1)
|
||||
console.log(currentStatus);
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
buttonPoint2.addEventListener('click', async function (event) {
|
||||
@@ -288,7 +349,9 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const data = { "point2": currentStatus.point2 + 1 };
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint2.innerHTML = currentStatus.point2 + 1;
|
||||
location.reload();
|
||||
console.log(currentStatus.point2)
|
||||
console.log(currentStatus);
|
||||
//location.reload();
|
||||
});
|
||||
|
||||
// Ajout des champs de saisie pour les scores
|
||||
@@ -319,7 +382,7 @@ if (currentStatus.expand.sport.name === "basketball") {
|
||||
const record = await pb.collection('match').update(idMatch, data);
|
||||
textPoint1.innerHTML = manualScore1;
|
||||
textPoint2.innerHTML = manualScore2;
|
||||
location.reload();
|
||||
//location.reload();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -88,19 +88,6 @@ matchList.forEach(match => {
|
||||
if (e.record.set1 !== match.set1 || e.record.set2 !== match.set2) {
|
||||
newSetAlert(match);
|
||||
}
|
||||
const totalVotes = (e.record.voteFor1 || 0) + (e.record.voteFor2 || 0);
|
||||
const team1Percentage = totalVotes ? ((e.record.voteFor1 || 0) / totalVotes) * 100 : 50;
|
||||
const team2Percentage = totalVotes ? ((e.record.voteFor2 || 0) / totalVotes) * 100 : 50;
|
||||
|
||||
const progressTeam1 = document.getElementById(`progressTeam1${match.id}`);
|
||||
const progressTeam2 = document.getElementById(`progressTeam2${match.id}`);
|
||||
|
||||
if (progressTeam1 && progressTeam2) {
|
||||
progressTeam1.style.width = `${team1Percentage}%`;
|
||||
progressTeam1.setAttribute('aria-valuenow', team1Percentage);
|
||||
progressTeam2.style.width = `${team2Percentage}%`;
|
||||
progressTeam2.setAttribute('aria-valuenow', team2Percentage);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -331,17 +318,6 @@ if (window.location.href.includes("arbitrage.html")) {
|
||||
//Récupération des données du formulaire
|
||||
let equipe1 = document.getElementById('equipe1').value;
|
||||
let equipe2 = document.getElementById('equipe2').value;
|
||||
sportID = document.getElementById("sport").value;
|
||||
//Récupération de l'id de l'équipe
|
||||
if (!sportID.toLowerCase().includes("badminton")) {
|
||||
equipe1 = equipe1.substring(0, 6);
|
||||
equipe2 = equipe2.substring(0, 6);
|
||||
} else {
|
||||
equipe1 = equipe1.slice(0, -12);
|
||||
equipe2 = equipe2.slice(0, -12);
|
||||
}
|
||||
equipe1 = equipeList.find(equipe => equipe.name === equipe1);
|
||||
equipe2 = equipeList.find(equipe => equipe.name === equipe2);
|
||||
console.log("equipe 1 id = " + equipe1);
|
||||
console.log("equipe 2 id = " + equipe2);
|
||||
// Récupération de l'id du sport
|
||||
@@ -430,123 +406,39 @@ if (window.location.href.includes("index.html") || window.location.href === "htt
|
||||
let finishedMatch = [];
|
||||
let container = document.getElementById('cardContainer');
|
||||
matchList.forEach(match => {
|
||||
const isFinished = match.status === "finished"; // Define isFinished here
|
||||
const cardHTML = `
|
||||
<div class="card my-3" id="card${match.id}">
|
||||
<div class="card-header text-center bg-light-subtle ${match.status === "waiting" ? "text-primary-emphasis" : match.status === "in_progress" ? "text-warning-emphasis" : match.status === "finished" ? "text-success-emphasis" : "text-emphasis-light"}" id="cardHeader${match.id}">
|
||||
${match.status === "in_progress" || match.status === "finished" ? '' : new Date(match.heure_debut).toLocaleString()}
|
||||
${match.status === "in_progress" || match.status === "finished" ? `
|
||||
<div class="d-flex justify-content-evenly">
|
||||
<p id="pointT1${match.id}">${match.point1}</p>
|
||||
<p>-</p>
|
||||
<p id="pointT2${match.id}">${match.point2}</p>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
<div class="card-body bg-light-subtle text-emphasis-light">
|
||||
${match.team1 && match.team2 ? `<h5 class="card-title text-center">${match.expand.team1.name} VS ${match.expand.team2.name}</h5>` : ''}
|
||||
<p class="card-text text-center text-capitalize mb-0">${match.expand.sport.name}</p>
|
||||
${match.name !== "" ? `<p class="card-text text-center fw-semibold text-body-secondary">${match.name}</p>` : ''}
|
||||
</div>
|
||||
<div class="d-flex justify-content-between align-items-center bg-dark p-2">
|
||||
<button class="btn btn-primary" id="voteTeam1${match.id}" ${isFinished ? 'disabled' : ''}>Vote for Team 1</button>
|
||||
<div class="progress w-50 bg-dark">
|
||||
<div class="progress-bar bg-primary" id="progressTeam1${match.id}" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
<div class="progress-bar bg-danger" id="progressTeam2${match.id}" role="progressbar" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
<div class="card my-3" id="card${match.id}">
|
||||
<div class="card-header text-center bg-light-subtle ${match.status === "waiting" ? "text-primary-emphasis" : match.status === "in_progress" ? "text-warning-emphasis" : match.status === "finished" ? "text-success-emphasis" : "text-emphasis-light"}" id="cardHeader${match.id}">
|
||||
${match.status === "in_progress" || match.status === "finished" ? '' : new Date(match.heure_debut).toLocaleString()}
|
||||
${match.status === "in_progress" || match.status === "finished" ? `
|
||||
<div class="d-flex justify-content-evenly">
|
||||
<p id="pointT1${match.id}">${match.point1}</p>
|
||||
<p>-</p>
|
||||
<p id="pointT2${match.id}">${match.point2}</p>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
<div class="card-body bg-light-subtle text-emphasis-light">
|
||||
${match.team1 && match.team2 ? `<h5 class="card-title text-center">${match.expand.team1.name} VS ${match.expand.team2.name}</h5>` : ''}
|
||||
<p class="card-text text-center text-capitalize mb-0">${match.expand.sport.name}</p>
|
||||
${match.name !== "" ? `<p class="card-text text-center fw-semibold text-body-secondary">${match.name}</p>` : ''}
|
||||
</div>
|
||||
<div class="card-footer bg-light-subtle ${match.status === "waiting" ? "text-primary-emphasis" : match.status === "in_progress" ? "text-warning-emphasis" : match.status === "finished" ? "text-success-emphasis" : "text-emphasis-light"}" id="cardFooter${match.id}">
|
||||
${match.status === "waiting" ? "Match en attente" : match.status === "in_progress" ? "Match en cours" : match.status === "finished" ? "Match terminé" : "Erreur de statut"}
|
||||
</div>
|
||||
<button class="btn btn-danger" id="voteTeam2${match.id}" ${isFinished ? 'disabled' : ''}>Vote for Team 2</button>
|
||||
</div>
|
||||
<div class="card-footer bg-light-subtle ${match.status === "waiting" ? "text-primary-emphasis" : match.status === "in_progress" ? "text-warning-emphasis" : match.status === "finished" ? "text-success-emphasis" : "text-emphasis-light"}" id="cardFooter${match.id}">
|
||||
${match.status === "waiting" ? "Match en attente" : match.status === "in_progress" ? "Match en cours" : match.status === "finished" ? "Match terminé" : "Erreur de statut"}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
`;
|
||||
if(match.status == "finished"){
|
||||
finishedMatch.push(cardHTML);
|
||||
} else {
|
||||
container.insertAdjacentHTML('beforeend', cardHTML);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add event listeners for voting buttons
|
||||
matchList.forEach(record => {
|
||||
const voteTeam1Button = document.getElementById(`voteTeam1${record.id}`);
|
||||
const voteTeam2Button = document.getElementById(`voteTeam2${record.id}`);
|
||||
const progressTeam1 = document.getElementById(`progressTeam1${record.id}`);
|
||||
const progressTeam2 = document.getElementById(`progressTeam2${record.id}`);
|
||||
|
||||
if (voteTeam1Button) {
|
||||
voteTeam1Button.addEventListener('click', () => handleVote(record.id, 'team1', progressTeam1, progressTeam2));
|
||||
}
|
||||
if (voteTeam2Button) {
|
||||
voteTeam2Button.addEventListener('click', () => handleVote(record.id, 'team2', progressTeam1, progressTeam2));
|
||||
}
|
||||
});
|
||||
// Function to handle voting
|
||||
async function handleVote(matchId, team, progressTeam1, progressTeam2) {
|
||||
const match = await pb.collection('match').getOne(matchId);
|
||||
if (match.status === "finished") {
|
||||
alert('Pas le droit de voté pour un match déjà fini petit malin.');
|
||||
return;
|
||||
}
|
||||
|
||||
const cookieName = `votedForMatch${matchId}`;
|
||||
if (document.cookie.split(';').some((item) => item.trim().startsWith(`${cookieName}=`))) {
|
||||
alert('You have already voted for this match.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (team === 'team1') {
|
||||
match.voteFor1 = (match.voteFor1 || 0) + 1;
|
||||
} else {
|
||||
match.voteFor2 = (match.voteFor2 || 0) + 1;
|
||||
}
|
||||
|
||||
await pb.collection('match').update(matchId, match);
|
||||
document.cookie = `${cookieName}=true; path=/; max-age=31536000`;
|
||||
|
||||
const totalVotes = (match.voteFor1 || 0) + (match.voteFor2 || 0);
|
||||
const team1Percentage = ((match.voteFor1 || 0) / totalVotes) * 100;
|
||||
const team2Percentage = ((match.voteFor2 || 0) / totalVotes) * 100;
|
||||
|
||||
progressTeam1.style.width = `${team1Percentage}%`;
|
||||
progressTeam1.setAttribute('aria-valuenow', team1Percentage);
|
||||
progressTeam2.style.width = `${team2Percentage}%`;
|
||||
progressTeam2.setAttribute('aria-valuenow', team2Percentage);
|
||||
} catch (error) {
|
||||
console.error('Error updating vote:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Récupérer les votes depuis la base de données et mettre à jour les barres de progression
|
||||
async function updateVotesFromDB() {
|
||||
const matchList = await pb.collection('match').getFullList({
|
||||
sort: '+heure_debut',
|
||||
expand: 'team1,team2,sport',
|
||||
});
|
||||
|
||||
matchList.forEach(match => {
|
||||
const totalVotes = (match.voteFor1 || 0) + (match.voteFor2 || 0);
|
||||
const team1Percentage = totalVotes ? ((match.voteFor1 || 0) / totalVotes) * 100 : 50;
|
||||
const team2Percentage = totalVotes ? ((match.voteFor2 || 0) / totalVotes) * 100 : 50;
|
||||
|
||||
const progressTeam1 = document.getElementById(`progressTeam1${match.id}`);
|
||||
const progressTeam2 = document.getElementById(`progressTeam2${match.id}`);
|
||||
|
||||
if (progressTeam1 && progressTeam2) {
|
||||
progressTeam1.style.width = `${team1Percentage}%`;
|
||||
progressTeam1.setAttribute('aria-valuenow', team1Percentage);
|
||||
progressTeam2.style.width = `${team2Percentage}%`;
|
||||
progressTeam2.setAttribute('aria-valuenow', team2Percentage);
|
||||
}
|
||||
finishedMatch.forEach(card => {
|
||||
container.insertAdjacentHTML('beforeend', card);
|
||||
});
|
||||
}
|
||||
|
||||
// Appeler la fonction lors du chargement de la page
|
||||
updateVotesFromDB();
|
||||
|
||||
//Fonctionne dans match.js mais pas dans player.js PARCE QUE: NIQUE
|
||||
//Gestion de l'ajout d'un joueur
|
||||
if (window.location.href.includes("arbitrage.html")) {
|
||||
@@ -713,6 +605,7 @@ if (window.location.href.includes("arbitrage.html")) {
|
||||
"membres": teamPlayers,
|
||||
"capitaine": teamCaptain
|
||||
};
|
||||
console.log(data);
|
||||
await pb.collection('equipes').create(data);
|
||||
window.location.href = "arbitrage.html";
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user