alpinux-static/app/templates/stats.html
Alpinux 64989e83c8 feat: upload de fichiers dans l'app Flask CDN
Ajoute la route POST /upload (admin uniquement) et la zone de dépôt
dans browse.html — glisser-déposer ou sélection multiple, destination
= dossier courant du navigateur.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 20:35:29 +02:00

86 lines
2.7 KiB
HTML

{% extends "base.html" %}
{% block title %}Statistiques{% endblock %}
{% block content %}
{% if has_report %}
<div style="display:flex; justify-content:flex-end; margin-bottom:.6rem">
<a href="{{ url_for('stats_report') }}" target="_blank" class="btn btn-primary">
↗ Ouvrir dans un nouvel onglet
</a>
</div>
<div class="stats-frame-wrap">
<iframe src="{{ url_for('stats_report') }}" class="stats-frame" title="Rapport GoAccess"></iframe>
</div>
{% else %}
<section class="card">
<h2>Statistiques de trafic</h2>
<p id="gen-msg" style="color:var(--muted);margin-bottom:1rem">Aucun rapport disponible.</p>
<button id="gen-btn" class="btn btn-primary" onclick="startGeneration()">Générer et ouvrir</button>
</section>
<script>
(function () {
const GENERATE_URL = {{ url_for('stats_generate') | tojson }};
const STATUS_URL = {{ url_for('stats_status') | tojson }};
const REPORT_URL = {{ url_for('stats_report') | tojson }};
function setMsg(text) {
document.getElementById('gen-msg').textContent = text;
}
function setBtn(text, disabled) {
const b = document.getElementById('gen-btn');
b.textContent = text;
b.disabled = disabled;
}
function pollReady() {
const id = setInterval(async () => {
try {
const d = await fetch(STATUS_URL).then(r => r.json());
if (d.ready) {
clearInterval(id);
setMsg('Rapport prêt. Ouverture…');
window.open(REPORT_URL, '_blank');
location.reload();
} else if (!d.generating) {
clearInterval(id);
setMsg('La génération a échoué. Vérifier la configuration serveur (STATS_LOG_FILE).');
setBtn('Réessayer', false);
}
} catch (_) {}
}, 2000);
}
window.startGeneration = async function () {
setBtn('Génération en cours…', true);
setMsg('Lancement de la génération en arrière-plan…');
try {
const d = await fetch(GENERATE_URL, { method: 'POST' }).then(r => r.json());
if (d.status === 'error') {
setMsg('Erreur : ' + (d.message || 'configuration manquante'));
setBtn('Réessayer', false);
return;
}
setMsg('Génération en cours, veuillez patienter…');
pollReady();
} catch (_) {
setMsg('Erreur réseau.');
setBtn('Réessayer', false);
}
};
// Reprendre le polling si une génération est déjà en cours
fetch(STATUS_URL).then(r => r.json()).then(d => {
if (d.ready) { location.reload(); }
else if (d.generating) {
setBtn('Génération en cours…', true);
setMsg('Génération en cours, veuillez patienter…');
pollReady();
}
}).catch(() => {});
})();
</script>
{% endif %}
{% endblock %}