reproduce ganador en dispositivo seleccionado si lo permite
- play_winner acepta device_id del formulario y verifica que el dispositivo exista y no sea restringido antes de reproducir - corrige construcción del URI según spotify_type del ganador (antes siempre usaba spotify:playlist: independiente del tipo) - errores se muestran en la página admin en lugar de HTTPException cruda - template sincroniza device_id activo al campo oculto del formulario - dispositivos restringidos se marcan en el selector del admin Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,7 @@
|
||||
<div style="display:flex;gap:.5rem;align-items:center">
|
||||
{% if results and results[0].votes > 0 %}
|
||||
<form method="post" action="/admin/voting/play-winner">
|
||||
<input type="hidden" id="play-winner-device-id" name="device_id" value="">
|
||||
<button type="submit" class="btn-primary btn-sm">
|
||||
▶ Reproducir ganador
|
||||
</button>
|
||||
@@ -134,6 +135,11 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function _syncWinnerDevice(deviceId) {
|
||||
const input = document.getElementById('play-winner-device-id');
|
||||
if (input) input.value = deviceId || '';
|
||||
}
|
||||
|
||||
async function loadDevices() {
|
||||
const sel = document.getElementById('device-select');
|
||||
const msg = document.getElementById('device-msg');
|
||||
@@ -144,19 +150,24 @@ async function loadDevices() {
|
||||
const devices = await res.json();
|
||||
if (!devices.length) {
|
||||
sel.innerHTML = '<option value="">Sin dispositivos activos</option>';
|
||||
_syncWinnerDevice('');
|
||||
return;
|
||||
}
|
||||
sel.innerHTML = devices.map(d =>
|
||||
`<option value="${d.id}"${d.is_active ? ' selected' : ''}>${d.name} (${d.type})</option>`
|
||||
`<option value="${d.id}"${d.is_active ? ' selected' : ''}>${d.name} (${d.type})${d.is_restricted ? ' — sin control remoto' : ''}</option>`
|
||||
).join('');
|
||||
const active = devices.find(d => d.is_active);
|
||||
_syncWinnerDevice(active ? active.id : devices[0].id);
|
||||
} catch (_) {
|
||||
sel.innerHTML = '<option value="">Error al cargar dispositivos</option>';
|
||||
_syncWinnerDevice('');
|
||||
}
|
||||
}
|
||||
|
||||
async function setDevice(deviceId) {
|
||||
if (!deviceId) return;
|
||||
const msg = document.getElementById('device-msg');
|
||||
_syncWinnerDevice(deviceId);
|
||||
try {
|
||||
await fetch('/player/device', {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user