miam les alertes qui marche bien miam miam

This commit is contained in:
Allan Cueff
2023-11-02 15:40:04 +01:00
parent f0e85b93d3
commit d39c6406bf
2 changed files with 13 additions and 26 deletions

View File

@@ -26,36 +26,27 @@ function deleteAlert(alertId){
alert.close()
}
function newGoalAlert(){
//CHANGE THIS PART WITH REAL VALUE WHEN LINKING TO DATABASE
let sportName = "Football"
let teamA = "FCFOUCHE"
let teamB = "A3 Grammes"
let scoreTeamA = 1
let scoreTeamB = 2
let goalTeamName = "FCFOUCHE"
let noGoalTeamName = "A3 Grammes"
let alertId = "testId"
function newGoalAlert(match, goalTeam){
let alertsContainer = document.querySelector('body #alertsContainer');
let alert = `
<div id="${alertId}" class="alert alert-success alert-dismissible fade show" role="alert">
<div id="${match.id}${match.point1}_${match.point2}" class="alert alert-success alert-dismissible fade show" role="alert">
<div class="d-flex align-items-center justify-content-between">
<h4 class="alert-heading d-inline-flex align-items-center"><span class="material-symbols-outlined">
scoreboard
</span>BUT !</h4>
<h4>${scoreTeamA} - ${scoreTeamB}</h4>
<h4>${match.point1} - ${match.point2}</h4>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<p>${goalTeamName} vient de marquer un but en ${sportName} face à ${noGoalTeamName} !</p>
<p>${goalTeam == "team1" ? match.expand.team1.name : match.expand.team2.name} vient de marquer un but en ${match.expand.sport.name} face à ${goalTeam == "team1" ? match.expand.team2.name : match.expand.team1.name} !</p>
<hr>
<div class="d-flex align-items-center justify-content-between">
<p class="mb-0 d-inline-flex align-items-center">${getSportIconHTML(sportName)}${sportName}</p>
<p class="mb-0">${teamA}</p>
<b><p class="mb-0">${scoreTeamA} - ${scoreTeamB}</p></b>
<p class="mb-0">${teamB}</p>
<p class="mb-0 d-inline-flex align-items-center">${getSportIconHTML(match.expand.sport.name)}${match.expand.sport.name}</p>
<p class="mb-0">${match.expand.team1.name}</p>
<b><p class="mb-0">${match.point1} - ${match.point2}</p></b>
<p class="mb-0">${match.expand.team2.name}</p>
</div>
</div>
`
alertsContainer.insertAdjacentHTML("beforeend", alert)
setTimeout(deleteAlert, 5000, alertId)
setTimeout(deleteAlert, 5000, `${match.id}${match.point1}_${match.point2}`)
}

View File

@@ -24,20 +24,16 @@ matchList.forEach(match => {
document.getElementById("cardHeader" + match.id).classList.add("text-warning-emphasis");
}
document.getElementById("pointT1" + match.id).innerHTML = e.record.point1;
matchList = await pb.collection('match').getFullList({
sort: '+heure_debut',
expand: 'team1,team2,sport',
});
match.point1 = e.record.point1
newGoalAlert(match, "team1")
}
if (e.record.point2 !== match.point2) {
if (!document.getElementById("cardHeader" + match.id).classList.contains("text-warning-emphasis")) {
document.getElementById("cardHeader" + match.id).classList.add("text-warning-emphasis");
}
document.getElementById("pointT2" + match.id).innerHTML = e.record.point2;
matchList = await pb.collection('match').getFullList({
sort: '+heure_debut',
expand: 'team1,team2,sport',
});
match.point2 = e.record.point2
newGoalAlert(match, "team2")
}
//Mise à jour du statut si le match est terminé
if (e.record.status === "finished") {