2026-08-20 07:56:32 +00:00
|
|
|
// Tableau global JavaScript pour stocker les données
|
|
|
|
|
let indicesData = [];
|
|
|
|
|
|
|
|
|
|
function chargerDonnees() {
|
2026-08-20 08:29:28 +00:00
|
|
|
// Appel de l'API située dans le dossier php/
|
2026-08-20 07:56:32 +00:00
|
|
|
fetch("./php/api_indices.php")
|
|
|
|
|
.then((response) => response.json())
|
|
|
|
|
.then((result) => {
|
|
|
|
|
if (result.status === "success") {
|
2026-08-20 08:29:28 +00:00
|
|
|
// Stockage dans le tableau global JS
|
2026-08-20 07:56:32 +00:00
|
|
|
indicesData = result.data;
|
|
|
|
|
|
2026-08-20 08:29:28 +00:00
|
|
|
// Mise à jour de tous les affichages
|
2026-08-20 07:56:32 +00:00
|
|
|
afficherSyntheseCartes();
|
|
|
|
|
afficherTableauDetails();
|
|
|
|
|
alimenterBandeauxTicker();
|
|
|
|
|
|
|
|
|
|
// Mise à jour du statut
|
|
|
|
|
document.getElementById("statut").innerText =
|
|
|
|
|
`Dernière mise à jour : ${new Date().toLocaleTimeString()}`;
|
|
|
|
|
document.getElementById("counter").innerText =
|
|
|
|
|
`${indicesData.length} enregistrements`;
|
|
|
|
|
} else {
|
|
|
|
|
console.error("Erreur API :", result.message);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => console.error("Erreur réseau :", error));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function afficherSyntheseCartes() {
|
|
|
|
|
const container = document.getElementById("cards-container");
|
|
|
|
|
container.innerHTML = "";
|
|
|
|
|
|
2026-08-20 08:29:28 +00:00
|
|
|
// Trouver les indices uniques présents dans le tableau
|
2026-08-20 07:56:32 +00:00
|
|
|
const indicesUniques = [...new Set(indicesData.map((item) => item.indice))];
|
|
|
|
|
|
|
|
|
|
indicesUniques.forEach((nomIndice) => {
|
2026-08-20 08:29:28 +00:00
|
|
|
// Récupère le premier élément (le plus récent) pour cet indice
|
2026-08-20 07:56:32 +00:00
|
|
|
const dernier = indicesData.find((item) => item.indice === nomIndice);
|
|
|
|
|
if (!dernier) return;
|
|
|
|
|
|
|
|
|
|
const isPositive = parseFloat(dernier.variation_pct) >= 0;
|
|
|
|
|
const badgeColor = isPositive
|
|
|
|
|
? "bg-emerald-500/10 text-emerald-400 border-emerald-500/20"
|
|
|
|
|
: "bg-rose-500/10 text-rose-400 border-rose-500/20";
|
|
|
|
|
const sign = isPositive ? "+" : "";
|
|
|
|
|
|
|
|
|
|
container.innerHTML += `
|
|
|
|
|
<div class="bg-slate-800 p-6 rounded-2xl shadow-lg border border-slate-700 flex flex-col justify-between">
|
|
|
|
|
<div>
|
|
|
|
|
<div class="flex justify-between items-start">
|
|
|
|
|
<span class="text-xs font-semibold uppercase tracking-wider text-slate-400">${dernier.indice}</span>
|
|
|
|
|
<span class="text-xs px-2.5 py-1 rounded-full border ${badgeColor} font-semibold">
|
|
|
|
|
${sign}${parseFloat(dernier.variation_pct).toFixed(2)}%
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
<h3 class="text-xl font-bold text-white mt-2">${dernier.nom || dernier.indice}</h3>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="mt-6 flex items-baseline justify-between">
|
|
|
|
|
<span class="text-2xl font-extrabold text-white">${parseFloat(dernier.cours).toLocaleString("fr-FR")}</span>
|
|
|
|
|
<span class="text-xs text-slate-400">${dernier.date_cours}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function afficherTableauDetails() {
|
|
|
|
|
const tbody = document.getElementById("table-body");
|
|
|
|
|
tbody.innerHTML = "";
|
|
|
|
|
|
|
|
|
|
if (indicesData.length === 0) {
|
|
|
|
|
tbody.innerHTML = `<tr><td colspan="5" class="p-6 text-center text-slate-400">Aucune donnée disponible</td></tr>`;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
indicesData.forEach((row) => {
|
|
|
|
|
const isPositive = parseFloat(row.variation_pct) >= 0;
|
|
|
|
|
const textColor = isPositive ? "text-emerald-400" : "text-rose-400";
|
|
|
|
|
const sign = isPositive ? "+" : "";
|
|
|
|
|
|
|
|
|
|
tbody.innerHTML += `
|
|
|
|
|
<tr class="hover:bg-slate-700/30 transition-colors">
|
|
|
|
|
<td class="p-4 font-semibold text-white">${row.indice}</td>
|
|
|
|
|
<td class="p-4 text-slate-300">${row.nom || "-"}</td>
|
|
|
|
|
<td class="p-4 text-right font-mono text-white">${parseFloat(row.cours).toLocaleString("fr-FR")}</td>
|
|
|
|
|
<td class="p-4 text-right font-mono font-semibold ${textColor}">${sign}${parseFloat(row.variation_pct).toFixed(2)}%</td>
|
|
|
|
|
<td class="p-4 text-center text-xs text-slate-400">${row.date_cours}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
`;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function alimenterBandeauxTicker() {
|
|
|
|
|
const preparerDonneesTicker = (nomIndice) => {
|
|
|
|
|
let liste = indicesData.filter((item) => item.indice === nomIndice);
|
|
|
|
|
|
|
|
|
|
// Tri alphabétique
|
|
|
|
|
liste.sort((a, b) => {
|
|
|
|
|
let valA = (a.nom || a.indice).toLowerCase();
|
|
|
|
|
let valB = (b.nom || b.indice).toLowerCase();
|
|
|
|
|
return valA.localeCompare(valB);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return liste;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
remplirUnBandeau("ticker-cac40", preparerDonneesTicker("CAC40"));
|
|
|
|
|
remplirUnBandeau("ticker-ibex35", preparerDonneesTicker("IBEX35"));
|
|
|
|
|
remplirUnBandeau("ticker-dowjones", preparerDonneesTicker("DOWJONES"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function remplirUnBandeau(elementId, donneesTriees) {
|
|
|
|
|
const container = document.getElementById(elementId);
|
2026-08-20 08:29:28 +00:00
|
|
|
if (!container) {
|
|
|
|
|
console.error("Élément introuvable :", elementId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-08-20 07:56:32 +00:00
|
|
|
|
|
|
|
|
if (donneesTriees.length === 0) {
|
|
|
|
|
container.innerHTML = `<span class="px-4 text-slate-500">Aucune donnée disponible</span>`;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-20 08:29:28 +00:00
|
|
|
let blocs = "";
|
|
|
|
|
donneesTriees.forEach((item) => {
|
|
|
|
|
const isPositive = parseFloat(item.variation_pct) >= 0;
|
|
|
|
|
const colorClass = isPositive ? "text-emerald-400" : "text-rose-400";
|
|
|
|
|
const sign = isPositive ? "+" : "";
|
|
|
|
|
const nomAffichage = item.nom || item.indice;
|
|
|
|
|
const coursFormate = parseFloat(item.cours).toLocaleString("fr-FR");
|
|
|
|
|
const variationFormatee = parseFloat(item.variation_pct).toFixed(2);
|
|
|
|
|
|
|
|
|
|
blocs += `
|
|
|
|
|
<div class="inline-flex items-center px-6 space-x-3 border-r border-slate-800/80 whitespace-nowrap">
|
|
|
|
|
<span class="font-bold text-white">${nomAffichage}</span>
|
|
|
|
|
<span class="text-slate-300">${coursFormate}</span>
|
|
|
|
|
<span class="${colorClass} font-semibold">${sign}${variationFormatee}%</span>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Duplication du contenu pour la boucle infinie fluide
|
|
|
|
|
container.innerHTML = blocs + blocs;
|
|
|
|
|
|
|
|
|
|
// Vitesse uniforme et lente
|
|
|
|
|
const dureeParElement = 6;
|
|
|
|
|
const dureeTotale = Math.max(30, donneesTriees.length * dureeParElement);
|
2026-08-20 07:56:32 +00:00
|
|
|
|
2026-08-20 08:29:28 +00:00
|
|
|
container.style.animationDuration = `${dureeTotale}s`;
|
2026-08-20 07:56:32 +00:00
|
|
|
}
|
|
|
|
|
|
2026-08-20 08:29:28 +00:00
|
|
|
// Lancer le chargement des données au démarrage de la page
|
2026-08-20 07:56:32 +00:00
|
|
|
chargerDonnees();
|
|
|
|
|
|
|
|
|
|
// Rafraîchir automatiquement toutes les 60 secondes
|
|
|
|
|
setInterval(chargerDonnees, 60000);
|