Init photobooth - borne photo evenementielle RPi4
Backend FastAPI complet : camera gphoto2, filtres/overlays Pillow, chroma key OpenCV, multi-shot/collage, GIF, impression CUPS, email SMTP, QR code. Frontend web vanilla (HTML/CSS/JS) pour Chromium kiosk. Menu admin cache (appui long coin ecran). Toutes les fonctionnalites activables/desactivables. Scripts install + systemd pour RPi4. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
161
frontend/js/admin.js
Normal file
161
frontend/js/admin.js
Normal file
@@ -0,0 +1,161 @@
|
||||
/* Module administration - Menu cache */
|
||||
|
||||
// Mapping toggle ID -> cle config
|
||||
const TOGGLES_MAP = {
|
||||
'tog-photo-simple': 'photo_simple',
|
||||
'tog-multi-shot': 'multi_shot',
|
||||
'tog-gif': 'gif',
|
||||
'tog-filtres': 'filtres',
|
||||
'tog-overlays': 'overlays',
|
||||
'tog-chroma-key': 'chroma_key',
|
||||
'tog-impression': 'impression',
|
||||
'tog-email': 'email',
|
||||
'tog-qr-code': 'qr_code',
|
||||
'tog-galerie': 'galerie',
|
||||
'tog-compteur': 'compteur',
|
||||
};
|
||||
|
||||
async function chargerAdmin() {
|
||||
config = await apiGet('/api/config');
|
||||
const fonc = config.fonctionnalites || {};
|
||||
const event = config.evenement || {};
|
||||
const cam = config.camera || {};
|
||||
const imp = config.impression || {};
|
||||
const email = config.email || {};
|
||||
const qr = config.qr_code || {};
|
||||
|
||||
// Toggles fonctionnalites
|
||||
for (const [id, cle] of Object.entries(TOGGLES_MAP)) {
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.checked = fonc[cle] !== false;
|
||||
}
|
||||
|
||||
// Evenement
|
||||
setValue('admin-nom-event', event.nom);
|
||||
setValue('admin-couleur-primaire', event.couleur_primaire || '#e91e63');
|
||||
setValue('admin-couleur-secondaire', event.couleur_secondaire || '#ffffff');
|
||||
|
||||
// Camera
|
||||
const statut = await apiGet('/api/camera/statut');
|
||||
document.getElementById('admin-camera-statut').textContent =
|
||||
statut.connectee ? 'Connectee' : 'Deconnectee';
|
||||
setValue('admin-car', cam.compte_a_rebours || 3);
|
||||
|
||||
// Impression
|
||||
const imprimantes = await apiGet('/api/imprimantes');
|
||||
const select = document.getElementById('admin-imprimante');
|
||||
select.innerHTML = '';
|
||||
for (const p of imprimantes) {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = p.nom;
|
||||
opt.textContent = `${p.nom} (${p.statut})`;
|
||||
select.appendChild(opt);
|
||||
}
|
||||
if (imp.imprimante) select.value = imp.imprimante;
|
||||
setValue('admin-copies', imp.copies || 1);
|
||||
|
||||
// Email
|
||||
setValue('admin-smtp-host', email.smtp_host);
|
||||
setValue('admin-smtp-port', email.smtp_port || 587);
|
||||
setValue('admin-smtp-user', email.smtp_user);
|
||||
setValue('admin-smtp-pass', email.smtp_password);
|
||||
setValue('admin-expediteur', email.expediteur);
|
||||
|
||||
// Galerie
|
||||
const compteur = await apiGet('/api/galerie/compteur');
|
||||
document.getElementById('admin-nb-photos').textContent = compteur.photos_prises || 0;
|
||||
document.getElementById('admin-nb-exports').textContent = compteur.exports || 0;
|
||||
setValue('admin-url-galerie', qr.url_galerie);
|
||||
|
||||
// Ecouter les changements de toggles
|
||||
setupToggleListeners();
|
||||
}
|
||||
|
||||
function setupToggleListeners() {
|
||||
for (const [id, cle] of Object.entries(TOGGLES_MAP)) {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) continue;
|
||||
// Retirer les anciens listeners en clonant
|
||||
const nouveau = el.cloneNode(true);
|
||||
el.parentNode.replaceChild(nouveau, el);
|
||||
nouveau.addEventListener('change', () => {
|
||||
apiPost('/api/config', { fonctionnalites: { [cle]: nouveau.checked } });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function sauvegarderEvenement() {
|
||||
await apiPost('/api/config', {
|
||||
evenement: {
|
||||
nom: getValue('admin-nom-event'),
|
||||
couleur_primaire: getValue('admin-couleur-primaire'),
|
||||
couleur_secondaire: getValue('admin-couleur-secondaire'),
|
||||
},
|
||||
camera: {
|
||||
compte_a_rebours: parseInt(getValue('admin-car')) || 3,
|
||||
},
|
||||
});
|
||||
afficherStatut('Evenement sauvegarde', 'succes');
|
||||
}
|
||||
|
||||
async function sauvegarderEmail() {
|
||||
await apiPost('/api/config', {
|
||||
email: {
|
||||
smtp_host: getValue('admin-smtp-host'),
|
||||
smtp_port: parseInt(getValue('admin-smtp-port')) || 587,
|
||||
smtp_user: getValue('admin-smtp-user'),
|
||||
smtp_password: getValue('admin-smtp-pass'),
|
||||
expediteur: getValue('admin-expediteur'),
|
||||
},
|
||||
});
|
||||
afficherStatut('Email sauvegarde', 'succes');
|
||||
}
|
||||
|
||||
async function sauvegarderGalerie() {
|
||||
await apiPost('/api/config', {
|
||||
qr_code: { url_galerie: getValue('admin-url-galerie') },
|
||||
impression: {
|
||||
imprimante: getValue('admin-imprimante'),
|
||||
copies: parseInt(getValue('admin-copies')) || 1,
|
||||
},
|
||||
});
|
||||
afficherStatut('Configuration sauvegardee', 'succes');
|
||||
}
|
||||
|
||||
async function reconnecterCamera() {
|
||||
const resultat = await apiPost('/api/camera/reconnecter');
|
||||
document.getElementById('admin-camera-statut').textContent =
|
||||
resultat.connectee ? 'Connectee' : 'Deconnectee';
|
||||
}
|
||||
|
||||
function confirmerViderGalerie() {
|
||||
if (confirm('Supprimer TOUTES les photos ? Cette action est irreversible.')) {
|
||||
apiPost('/api/galerie/vider').then(() => {
|
||||
afficherStatut('Galerie videe', 'succes');
|
||||
chargerAdmin();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function confirmerRedemarrage() {
|
||||
if (confirm('Redemarrer le systeme ?')) {
|
||||
apiPost('/api/systeme/redemarrer');
|
||||
}
|
||||
}
|
||||
|
||||
function confirmerExtinction() {
|
||||
if (confirm('Eteindre le systeme ?')) {
|
||||
apiPost('/api/systeme/eteindre');
|
||||
}
|
||||
}
|
||||
|
||||
// Utilitaires
|
||||
function setValue(id, val) {
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.value = val || '';
|
||||
}
|
||||
|
||||
function getValue(id) {
|
||||
const el = document.getElementById(id);
|
||||
return el ? el.value : '';
|
||||
}
|
||||
Reference in New Issue
Block a user