mueve selector de dispositivo al panel de admin

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
David Inostroza
2026-04-24 18:51:41 -04:00
parent d88547e310
commit 22ee2b58ad
2 changed files with 54 additions and 40 deletions
+53
View File
@@ -66,6 +66,18 @@
</div>
</div>
<!-- Selector de dispositivo -->
<div class="card">
<h2>Dispositivo de reproducción</h2>
<div class="device-row">
<select id="device-select" class="input" onchange="setDevice(this.value)" style="flex:1">
<option value="">Cargando dispositivos...</option>
</select>
<button class="btn-sm" onclick="loadDevices()">↻ Actualizar</button>
</div>
<div id="device-msg" style="font-size:.8rem;color:var(--text-muted);margin-top:.4rem"></div>
</div>
<!-- Resultados -->
<div class="card">
<div class="results-header">
@@ -121,7 +133,48 @@
</div>
<script>
async function loadDevices() {
const sel = document.getElementById('device-select');
const msg = document.getElementById('device-msg');
sel.innerHTML = '<option value="">Cargando...</option>';
msg.textContent = '';
try {
const res = await fetch('/player/devices');
const devices = await res.json();
if (!devices.length) {
sel.innerHTML = '<option value="">Sin dispositivos activos</option>';
return;
}
sel.innerHTML = devices.map(d =>
`<option value="${d.id}"${d.is_active ? ' selected' : ''}>${d.name} (${d.type})</option>`
).join('');
} catch (_) {
sel.innerHTML = '<option value="">Error al cargar dispositivos</option>';
}
}
async function setDevice(deviceId) {
if (!deviceId) return;
const msg = document.getElementById('device-msg');
try {
await fetch('/player/device', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ device_id: deviceId }),
});
msg.textContent = 'Dispositivo actualizado.';
setTimeout(() => msg.textContent = '', 2500);
} catch (_) {
msg.textContent = 'Error al cambiar dispositivo.';
}
}
loadDevices();
</script>
<style>
.device-row { display: flex; align-items: center; gap: .5rem; }
.voting-form { display: flex; flex-direction: column; gap: 1rem; }
.time-row { display: flex; align-items: flex-end; gap: 1rem; }
.time-field { display: flex; flex-direction: column; gap: .3rem; flex: 1; }