fix: settings - add missing previewFlash/saveFlash/colorPickerToRgb/loadFlashConfig; fix previewBrightness to call API; fix printer refresh to update state badges
This commit is contained in:
@@ -807,20 +807,82 @@ async function loadBrightnessConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
function previewBrightness(val) {
|
||||
async function previewBrightness() {
|
||||
const val = parseInt(document.getElementById('brightness-slider').value);
|
||||
document.getElementById('brightness-val').textContent = val;
|
||||
try {
|
||||
await api('PUT', `/api/leds/brightness?value=${val}&save=false`);
|
||||
showToast(`👁 Aperçu luminosité : ${val}`, 'info');
|
||||
} catch(e) {
|
||||
showToast('Erreur aperçu : ' + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function saveBrightness() {
|
||||
const val = parseInt(document.getElementById('brightness-slider').value);
|
||||
try {
|
||||
await api('PUT', `/api/leds/brightness?value=${val}`);
|
||||
showToast(`✅ Luminosité réglée à ${val}`, 'success');
|
||||
showToast(`✅ Luminosité ${val} sauvegardée`, 'success');
|
||||
} catch(e) {
|
||||
showToast('Erreur : ' + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function previewFlash() {
|
||||
try {
|
||||
await api('POST', '/api/leds/effect?effect=capture');
|
||||
showToast('💡 Flash déclenché', 'info');
|
||||
} catch(e) {
|
||||
showToast('Erreur flash : ' + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function saveFlash() {
|
||||
const r = parseInt(document.getElementById('flash-r').value) || 255;
|
||||
const g = parseInt(document.getElementById('flash-g').value) || 200;
|
||||
const b = parseInt(document.getElementById('flash-b').value) || 80;
|
||||
const duration = parseFloat(document.getElementById('flash-duration').value) || 0.3;
|
||||
const flashes = parseInt(document.getElementById('flash-count').value) || 2;
|
||||
try {
|
||||
await api('PUT', `/api/leds/effect/capture?r=${r}&g=${g}&b=${b}&flash_duration=${duration}&flashes=${flashes}`);
|
||||
showToast('✅ Flash sauvegardé', 'success');
|
||||
} catch(e) {
|
||||
showToast('Erreur : ' + e.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function colorPickerToRgb(hex) {
|
||||
const r = parseInt(hex.slice(1,3), 16);
|
||||
const g = parseInt(hex.slice(3,5), 16);
|
||||
const b = parseInt(hex.slice(5,7), 16);
|
||||
document.getElementById('flash-r').value = r;
|
||||
document.getElementById('flash-g').value = g;
|
||||
document.getElementById('flash-b').value = b;
|
||||
document.getElementById('flash-preview').style.background = `rgb(${r},${g},${b})`;
|
||||
}
|
||||
|
||||
async function loadFlashConfig() {
|
||||
try {
|
||||
const effects = await api('GET', '/api/leds/effects');
|
||||
const cap = effects.capture;
|
||||
if (!cap) return;
|
||||
if (cap.color) {
|
||||
document.getElementById('flash-r').value = cap.color[0] ?? 255;
|
||||
document.getElementById('flash-g').value = cap.color[1] ?? 200;
|
||||
document.getElementById('flash-b').value = cap.color[2] ?? 80;
|
||||
document.getElementById('flash-preview').style.background =
|
||||
`rgb(${cap.color[0]},${cap.color[1]},${cap.color[2]})`;
|
||||
}
|
||||
if (cap.flash_duration !== undefined) {
|
||||
document.getElementById('flash-duration').value = cap.flash_duration;
|
||||
document.getElementById('flash-dur-val').textContent = cap.flash_duration.toFixed(2);
|
||||
}
|
||||
if (cap.flashes !== undefined) {
|
||||
document.getElementById('flash-count').value = cap.flashes;
|
||||
}
|
||||
} catch(e) { console.warn('loadFlashConfig:', e); }
|
||||
}
|
||||
|
||||
async function setAutoBrightness(enabled) {
|
||||
try {
|
||||
await api('PUT', `/api/leds/auto-brightness?enabled=${enabled}`);
|
||||
@@ -836,5 +898,6 @@ async function setAutoBrightness(enabled) {
|
||||
|
||||
// ── Init ──────────────────────────────────────────────────────────────────────
|
||||
loadBrightnessConfig();
|
||||
loadFlashConfig();
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user