`
+ }
+ return card;
+}
+
//Affichage des matchs sur la page d'arbitrage
if (window.location.href.includes("arbitrage.html")) {
+ let alreadyPrintedSports = [];
+ let finishedMatch = [];
+ let container = document.getElementById('cardContainer');
//Affichage des matchs
+ sportList.filter(sport => sport.state === "started").forEach(sport => { // On met les tableaux en cours tout en haut
+ const cardTableauHTML = getTableCard(sport);
+ container.insertAdjacentHTML('beforeend', cardTableauHTML);
+ alreadyPrintedSports.push(sport.id);
+ })
matchList.forEach(record => {
- let container = document.getElementById('cardContainer');
+ if(!alreadyPrintedSports.includes(record.expand.sport.id) && !(record.expand.sport.state === "finished")){
+ //Si tableau pas encore affiché : on le met avant le premier match du tableau
+ const cardTableauHTML = getTableCard(record.expand.sport);
+ container.insertAdjacentHTML('beforeend', cardTableauHTML);
+ alreadyPrintedSports.push(sport.id);
+ }
const cardHTML = `
`;
- container.insertAdjacentHTML('beforeend', cardHTML);
+ if(record.status == "finished"){
+ finishedMatch.push({id: record.id, html: cardHTML});
+ } else {
+ container.insertAdjacentHTML('beforeend', cardHTML);
+ const button = document.getElementById(record.id);
+ button.addEventListener('click', () => {
+ window.location.href = `arbimatch.html?id=${record.id}`;
+ });
+ }
+ });
+ finishedMatch.forEach(record => {
+ container.insertAdjacentHTML('beforeend', record.html);
const button = document.getElementById(record.id);
button.addEventListener('click', () => {
window.location.href = `arbimatch.html?id=${record.id}`;
});
- });
+ })
}
+sportList.forEach(sport => {
+ //Gestion des appui sur bouton pour les tournois
+ if(sport.state === "started" && sport.following != ""){
+ console.log("Adding event on " + "#endTournoi"+sport.id);
+ document.querySelector("#endTournoi"+sport.id).addEventListener("submit", async e => {
+ e.preventDefault();
+ const sportData = {"state": "finished"};
+ try {
+ console.log("trying to finish sport with following tournament");
+ await pb.collection('sport').update(sport.id, sportData);
+ } catch (error) {
+ console.error('Erreur de fin du tournoi :', error);
+ }
+ let i = 0;
+ /*equipeList.filter(team => team.expand.sport.id === sport.id).slice(0,sport.qualified).forEach(async qualifiedTeam => {
+ const teamData = {"sport": sport.expand.following.id};
+ try {
+ await pb.collection('equipes').update(qualifiedTeam.id, teamData);
+ i++;
+ if(i === sport.qualified){
+ //window.location.href = "arbitrage.html"; //reload only after all request are terminated
+ }
+ } catch (error) {
+ console.error('Erreur de fin du tournoi :', error);
+ }
+ })*/
+ })
+ } else if(sport.state === "started"){
+ document.querySelector("#"+sport.id).addEventListener("click", async e => {
+ const data = {"state": "finished"};
+ try {
+ console.log("trying to finish sport as final phase");
+ await pb.collection('sport').update(sport.id, data);
+ //window.location.href = "arbitrage.html";
+ } catch (error) {
+ console.error('Erreur de fin du tournoi :', error);
+ }
+ })
+ } else if(sport.state === "waiting"){ // Si erreur ici : pas grave c'est qu'il n'y a aucun match de créé pour un tournoi en waiting donc la card de tournoi n'est pas créée
+ document.querySelector("#"+sport.id).addEventListener("click", async e => {
+ const data = {"state": "started"};
+ try {
+ console.log("trying to start sport");
+ await pb.collection('sport').update(sport.id, data);
+ //window.location.href = "arbitrage.html";
+ } catch (error) {
+ console.error('Erreur de fin du tournoi :', error);
+ }
+ })
+ }
+});
+
//Gestion des informations dans la modal
if (window.location.href.includes("arbitrage.html")) {
const modalHTML = `
@@ -263,8 +383,9 @@ if (window.location.href.includes("arbitrage.html")) {
//Elle s'appele index.html ou bien n'as pas d'autre juste /
if (window.location.href.includes("index.html") || window.location.href === "https://interpromo.appen.fr/") {
//Affichage des matchs
+ let finishedMatch = [];
+ let container = document.getElementById('cardContainer');
matchList.forEach(match => {
- let container = document.getElementById('cardContainer');
const cardHTML = `
`;
- container.innerHTML += cardHTML;
+ if(match.status == "finished"){
+ finishedMatch.push(cardHTML);
+ } else {
+ container.insertAdjacentHTML('beforeend', cardHTML);
+ }
+ });
+ finishedMatch.forEach(card => {
+ container.insertAdjacentHTML('beforeend', card);
});
}