Refonte jauge : affichage des soutiens réguliers vers objectif 500
- Remplace le montant collecté par le nombre de soutiens réguliers actifs (plans Donorbox status=active + 98 soutiens historiques) avec objectif 500 - Proxy PHP : appel à /api/v1/plans pour compter les plans actifs toutes campagnes confondues, avec pagination et détail plans_detail dans la réponse - Jauge initialisée à 19.6% (98/500) en fallback si l'API est indisponible - Versions FR et EN mises à jour Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f0591a20ab
commit
97766e6bb7
5 changed files with 301 additions and 113 deletions
|
|
@ -2,17 +2,8 @@ const DONORBOX_CONFIG = {
|
|||
proxyUrl: '/api/donorbox-proxy.php',
|
||||
};
|
||||
|
||||
function formatCurrency(amount) {
|
||||
const rounded = Math.round(amount * 100) / 100;
|
||||
const hasDecimals = rounded % 1 !== 0;
|
||||
|
||||
const formatted = rounded.toLocaleString('fr-FR', {
|
||||
minimumFractionDigits: 0,
|
||||
maximumFractionDigits: hasDecimals ? 2 : 0,
|
||||
});
|
||||
|
||||
return formatted.replace(/[\s\u00A0\u202F]/g, '\u202F') + '\u202F€';
|
||||
}
|
||||
const RECURRING_DONORS_OFFSET = 98;
|
||||
const GOAL_SUPPORTERS = 500;
|
||||
|
||||
async function fetchDonorboxData() {
|
||||
try {
|
||||
|
|
@ -41,9 +32,9 @@ async function fetchDonorboxData() {
|
|||
}
|
||||
|
||||
function updateGaugeDisplay(campaignData) {
|
||||
const collected = campaignData.total_raised || 0;
|
||||
const goal = campaignData.goal_amt || 50000;
|
||||
const percentage = Math.min((collected / goal) * 100, 100);
|
||||
const recurringCount = campaignData.recurring_donors_count || 0;
|
||||
const totalSupport = recurringCount + RECURRING_DONORS_OFFSET;
|
||||
const percentage = Math.min((totalSupport / GOAL_SUPPORTERS) * 100, 100);
|
||||
|
||||
const gaugeElement = document.getElementById('gauge');
|
||||
if (gaugeElement) {
|
||||
|
|
@ -53,27 +44,16 @@ function updateGaugeDisplay(campaignData) {
|
|||
);
|
||||
}
|
||||
|
||||
const collectedElement = document.querySelector(
|
||||
const countElement = document.querySelector(
|
||||
'#gauge--infos__donateurs .value'
|
||||
);
|
||||
if (collectedElement) {
|
||||
collectedElement.textContent = formatCurrency(collected);
|
||||
}
|
||||
|
||||
const goalElement = document.querySelector('#gauge--infos__objectif .value');
|
||||
if (goalElement) {
|
||||
goalElement.textContent = formatCurrency(goal);
|
||||
}
|
||||
|
||||
const donorsCount = campaignData.donations_count || 0;
|
||||
const donorsElement = document.querySelector('#gauge--infos__donors .value');
|
||||
if (donorsElement) {
|
||||
donorsElement.textContent = donorsCount;
|
||||
if (countElement) {
|
||||
countElement.textContent = totalSupport;
|
||||
}
|
||||
|
||||
console.log('Gauge updated:', {
|
||||
collected: formatCurrency(collected),
|
||||
goal: formatCurrency(goal),
|
||||
recurringDonors: recurringCount,
|
||||
totalSupport,
|
||||
percentage: `${percentage.toFixed(1)}%`,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue