feat(admin): suivi des candidatures recues, suppression de code et compteur d utilisations
Cette révision appartient à :
1 Parent
3420ebee3d
révision
6dc0f6c296
4 fichiers modifiés
+313
-37
Aucun fichier ne correspond à votre recherche
+150
-37
@@ -113,13 +113,24 @@
|
||||
<!-- Historique des codes récents -->
|
||||
<div class="historique-codes">
|
||||
<div class="liste-codes-entete">
|
||||
<h4>Codes testeurs récents</h4>
|
||||
<h4>Codes testeurs émis <span class="compte" id="compte-codes">0</span></h4>
|
||||
<button type="button" id="btn-rafraichir-codes" class="btn-rafraichir" title="Actualiser">↻ Actualiser</button>
|
||||
</div>
|
||||
<div id="conteneur-tableau-codes" class="tableau-scroll">
|
||||
<p class="chargement">Chargement des codes en cours...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Candidatures reçues -->
|
||||
<div class="candidatures-bloc">
|
||||
<div class="liste-codes-entete">
|
||||
<h4>📬 Candidatures reçues via le formulaire <span class="compte" id="compte-candidatures">0</span></h4>
|
||||
<button type="button" id="btn-rafraichir-candidatures" class="btn-rafraichir" title="Actualiser">↻ Actualiser</button>
|
||||
</div>
|
||||
<div id="conteneur-tableau-candidatures" class="tableau-scroll">
|
||||
<p class="chargement">Chargement des candidatures...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -178,8 +189,13 @@
|
||||
const btnCopierMsg = document.getElementById('btn-copier-msg');
|
||||
const whatsappTexte = document.getElementById('texte-msg-whatsapp');
|
||||
|
||||
const conteneurTableau = document.getElementById('conteneur-tableau-codes');
|
||||
const btnRafraichir = document.getElementById('btn-rafraichir-codes');
|
||||
const conteneurTableauCodes = document.getElementById('conteneur-tableau-codes');
|
||||
const btnRafraichirCodes = document.getElementById('btn-rafraichir-codes');
|
||||
const compteCodesEl = document.getElementById('compte-codes');
|
||||
|
||||
const conteneurTableauCandidatures = document.getElementById('conteneur-tableau-candidatures');
|
||||
const btnRafraichirCandidatures = document.getElementById('btn-rafraichir-candidatures');
|
||||
const compteCandidaturesEl = document.getElementById('compte-candidatures');
|
||||
|
||||
let dernierCode = '';
|
||||
|
||||
@@ -189,38 +205,11 @@
|
||||
return d.toLocaleDateString('fr-FR', { day: '2-digit', month: '2-digit', year: 'numeric' });
|
||||
}
|
||||
|
||||
async function chargerCodes() {
|
||||
try {
|
||||
const res = await fetch('/_admin/api/codes/liste');
|
||||
if (!res.ok) {
|
||||
conteneurTableau.innerHTML = '<p class="chargement" style="color:#A0554B;">Impossible de charger les codes (' + res.status + ').</p>';
|
||||
return;
|
||||
}
|
||||
const data = await res.json();
|
||||
afficherTableau(data.codes || []);
|
||||
} catch (e) {
|
||||
conteneurTableau.innerHTML = '<p class="chargement">Impossible de contacter le serveur.</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function afficherTableau(codes) {
|
||||
if (!codes.length) {
|
||||
conteneurTableau.innerHTML = '<p class="chargement">Aucun code émis pour le moment.</p>';
|
||||
return;
|
||||
}
|
||||
let html = '<table class="table-codes"><thead><tr><th>ID</th><th>Testeur</th><th>Créé le</th><th>Expire</th><th>Usages</th><th>Statut</th></tr></thead><tbody>';
|
||||
for (const c of codes) {
|
||||
html += '<tr>' +
|
||||
'<td>#' + c.id + '</td>' +
|
||||
'<td><strong>' + escapeHtml(c.label) + '</strong></td>' +
|
||||
'<td>' + fmtDate(c.created_at) + '</td>' +
|
||||
'<td>' + (c.expires_at ? fmtDate(c.expires_at) : 'Illimité') + '</td>' +
|
||||
'<td>' + (c.uses || 0) + '</td>' +
|
||||
'<td><span class="badge-statut ' + (c.status === 'actif' ? 'actif' : (c.status === 'révoqué' ? 'revoque' : 'expire')) + '">' + escapeHtml(c.status) + '</span></td>' +
|
||||
'</tr>';
|
||||
}
|
||||
html += '</tbody></table>';
|
||||
conteneurTableau.innerHTML = html;
|
||||
function fmtDateHeure(ts) {
|
||||
if (!ts) return '-';
|
||||
const d = new Date(ts * 1000);
|
||||
return d.toLocaleDateString('fr-FR', { day: '2-digit', month: '2-digit', year: 'numeric' }) +
|
||||
' à ' + d.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
@@ -229,6 +218,127 @@
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
function escapeJs(str) {
|
||||
return (str || '').replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
||||
}
|
||||
|
||||
// --- Gestion des codes ---
|
||||
async function chargerCodes() {
|
||||
try {
|
||||
const res = await fetch('/_admin/api/codes/liste');
|
||||
if (!res.ok) {
|
||||
conteneurTableauCodes.innerHTML = '<p class="chargement" style="color:#A0554B;">Impossible de charger les codes (' + res.status + ').</p>';
|
||||
return;
|
||||
}
|
||||
const data = await res.json();
|
||||
afficherTableauCodes(data.codes || []);
|
||||
} catch (e) {
|
||||
conteneurTableauCodes.innerHTML = '<p class="chargement">Impossible de contacter le serveur.</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function afficherTableauCodes(codes) {
|
||||
if (compteCodesEl) compteCodesEl.textContent = codes.length;
|
||||
if (!codes.length) {
|
||||
conteneurTableauCodes.innerHTML = '<p class="chargement">Aucun code émis pour le moment.</p>';
|
||||
return;
|
||||
}
|
||||
let html = '<table class="table-codes"><thead><tr><th>ID</th><th>Testeur</th><th>Créé le</th><th>Expire</th><th>Utilisations</th><th>Statut</th><th>Action</th></tr></thead><tbody>';
|
||||
for (const c of codes) {
|
||||
const usesHtml = c.uses > 0
|
||||
? '<span class="badge-usages actif">' + c.uses + ' connexion' + (c.uses > 1 ? 's' : '') + '</span>' +
|
||||
(c.last_used_at ? '<span class="date-derniere">Dernière : ' + fmtDateHeure(c.last_used_at) + '</span>' : '')
|
||||
: '<span class="badge-usages">0 connexion</span>';
|
||||
|
||||
html += '<tr>' +
|
||||
'<td>#' + c.id + '</td>' +
|
||||
'<td><strong>' + escapeHtml(c.label) + '</strong></td>' +
|
||||
'<td>' + fmtDate(c.created_at) + '</td>' +
|
||||
'<td>' + (c.expires_at ? fmtDate(c.expires_at) : 'Illimité') + '</td>' +
|
||||
'<td>' + usesHtml + '</td>' +
|
||||
'<td><span class="badge-statut ' + (c.status === 'actif' ? 'actif' : (c.status === 'révoqué' ? 'revoque' : 'expire')) + '">' + escapeHtml(c.status) + '</span></td>' +
|
||||
'<td><button type="button" class="btn-action-suppr" onclick="window.jobrunnerBeta.supprimerCode(' + c.id + ', \'' + escapeJs(c.label) + '\')">Supprimer</button></td>' +
|
||||
'</tr>';
|
||||
}
|
||||
html += '</tbody></table>';
|
||||
conteneurTableauCodes.innerHTML = html;
|
||||
}
|
||||
|
||||
// --- Gestion des candidatures ---
|
||||
async function chargerCandidatures() {
|
||||
try {
|
||||
const res = await fetch('/_admin/api/candidatures/liste');
|
||||
if (!res.ok) {
|
||||
conteneurTableauCandidatures.innerHTML = '<p class="chargement" style="color:#A0554B;">Impossible de charger les candidatures (' + res.status + ').</p>';
|
||||
return;
|
||||
}
|
||||
const data = await res.json();
|
||||
afficherTableauCandidatures(data.candidatures || []);
|
||||
} catch (e) {
|
||||
conteneurTableauCandidatures.innerHTML = '<p class="chargement">Impossible de contacter le serveur.</p>';
|
||||
}
|
||||
}
|
||||
|
||||
function afficherTableauCandidatures(liste) {
|
||||
if (compteCandidaturesEl) compteCandidaturesEl.textContent = liste.length;
|
||||
if (!liste.length) {
|
||||
conteneurTableauCandidatures.innerHTML = '<p class="chargement">Aucune candidature reçue via le formulaire pour le moment.</p>';
|
||||
return;
|
||||
}
|
||||
let html = '<table class="table-codes"><thead><tr><th>Date</th><th>Candidat</th><th>Contact</th><th>Réseaux</th><th>Action</th></tr></thead><tbody>';
|
||||
for (const item of liste) {
|
||||
const ageBadge = item.mineur
|
||||
? '<span class="badge-age mineur">15-17 ans (mineur)</span>'
|
||||
: '<span class="badge-age">Majeur</span>';
|
||||
const parentHtml = (item.mineur && item.parent_nom)
|
||||
? '<span class="parent-info">Resp. légal : ' + escapeHtml(item.parent_nom) + ' (' + escapeHtml(item.parent_email || '') + ')</span>'
|
||||
: '';
|
||||
|
||||
html += '<tr>' +
|
||||
'<td>' + fmtDateHeure(item.ts) + '</td>' +
|
||||
'<td><strong>' + escapeHtml(item.prenom) + ' ' + escapeHtml(item.nom) + '</strong> ' + ageBadge + parentHtml + '</td>' +
|
||||
'<td><div class="contact-ligne">' +
|
||||
'<a href="mailto:' + escapeHtml(item.email) + '">' + escapeHtml(item.email) + '</a>' +
|
||||
'<a href="tel:' + escapeHtml(item.tel) + '">' + escapeHtml(item.tel) + '</a>' +
|
||||
'</div></td>' +
|
||||
'<td>' + (item.suivi_reseaux ? '<span style="color:#3E5A44;font-weight:700;">✓ Insta</span>' : '-') + '</td>' +
|
||||
'<td><button type="button" class="btn-remplir-code" onclick="window.jobrunnerBeta.preparerCodePour(\'' + escapeJs(item.prenom + ' ' + item.nom) + '\')">⚡ Créer code</button></td>' +
|
||||
'</tr>';
|
||||
}
|
||||
html += '</tbody></table>';
|
||||
conteneurTableauCandidatures.innerHTML = html;
|
||||
}
|
||||
|
||||
// --- Actions globales exposées ---
|
||||
window.jobrunnerBeta = {
|
||||
supprimerCode: async function(id, label) {
|
||||
if (!confirm('Supprimer définitivement le code de "' + label + '" ?\nSes sessions éventuelles seront immédiatement coupées.')) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const res = await fetch('/_admin/api/codes/supprimer', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id: id })
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (res.ok && data.ok) {
|
||||
chargerCodes();
|
||||
} else {
|
||||
alert(data.erreur || 'Erreur lors de la suppression.');
|
||||
}
|
||||
} catch (e) {
|
||||
alert('Erreur réseau lors de la suppression.');
|
||||
}
|
||||
},
|
||||
preparerCodePour: function(nomComplet) {
|
||||
inputLabel.value = nomComplet;
|
||||
inputLabel.focus();
|
||||
inputLabel.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
}
|
||||
};
|
||||
|
||||
// --- Formulaire de création ---
|
||||
form.addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
errBox.style.display = 'none';
|
||||
@@ -295,9 +405,12 @@
|
||||
});
|
||||
});
|
||||
|
||||
btnRafraichir.addEventListener('click', chargerCodes);
|
||||
btnRafraichirCodes.addEventListener('click', chargerCodes);
|
||||
btnRafraichirCandidatures.addEventListener('click', chargerCandidatures);
|
||||
|
||||
chargerCodes();
|
||||
chargerCandidatures();
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur