esp_proxmox: brilho dropdown niveis + relogio estilo/tema global e por-uid

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
deploy 2026-07-07 12:57:50 +01:00
parent 3204b1c905
commit aa78f601d5

View File

@ -32,6 +32,16 @@ function pmx_post(array $data): array {
$msg = ''; $msgOk = true;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// ações de frota (broadcast) — não precisam de uid válido
$action0 = $_POST['action'] ?? '';
if ($action0 === 'clock_style' || $action0 === 'clock_theme') {
$res = pmx_post($_POST);
$who = ($_POST['uid'] ?? '') === 'all' ? 'frota toda' : ($_POST['uid'] ?? '?');
if (!empty($res['ok'])) { $msg = "Relógio atualizado ($who)."; $msgOk = true; }
else { $msg = $res['error'] ?? 'Erro'; $msgOk = false; }
$qs = $msgOk ? '?ok='.urlencode($msg) : '?err='.urlencode($msg);
header("Location: /esp_proxmox.php$qs"); exit;
}
$uid = preg_replace('/[^0-9A-Fa-f]/', '', $_POST['uid'] ?? '');
if (!$uid) { $msg = 'UID invalido.'; $msgOk = false; }
else {
@ -94,6 +104,28 @@ ob_start();
<div class="alert <?= $msgOk ? 'alert-success' : 'alert-error' ?>"><?= $msgOk ? '✓' : '⚠' ?> <?= $msg ?></div>
<?php endif; ?>
<div style="display:flex;align-items:center;gap:8px;margin-bottom:16px;flex-wrap:wrap">
<span style="font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.06em;">Relógio:</span>
<?php foreach (['Hybrid','Analógico','Barras','Big'] as $s => $lbl): ?>
<form method="post" style="display:inline">
<input type="hidden" name="uid" value="all">
<input type="hidden" name="action" value="clock_style">
<input type="hidden" name="value" value="<?= $s ?>">
<button type="submit" class="btn btn-secondary btn-sm"><?= $lbl ?></button>
</form>
<?php endforeach; ?>
<span style="width:1px;height:18px;background:#30363d;margin:0 4px"></span>
<span style="font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.06em;">Tema:</span>
<?php foreach (['ambar'=>['Âmbar','#EF9F27'],'verde'=>['Verde','#3fb950'],'branco'=>['Branco','#d7dde4'],'noite'=>['Noite','#da3633']] as $tk => [$tlbl,$tcol]): ?>
<form method="post" style="display:inline">
<input type="hidden" name="uid" value="all">
<input type="hidden" name="action" value="clock_theme">
<input type="hidden" name="value" value="<?= $tk ?>">
<button type="submit" class="btn btn-secondary btn-sm" style="display:inline-flex;align-items:center;gap:6px"><span style="width:9px;height:9px;border-radius:50%;background:<?= $tcol ?>;display:inline-block"></span><?= $tlbl ?></button>
</form>
<?php endforeach; ?>
</div>
<?php if (!$devices): ?>
<div class="empty-state"><p>Sem dispositivos ou erro a ligar ao broker Proxmox.</p></div>
<?php else: ?>
@ -103,7 +135,7 @@ ob_start();
</div>
<div class="table-wrap">
<table>
<thead><tr><th>UID</th><th>Versão</th><th>Ultimo contacto</th><th>Online</th><th>Estado</th><th>Brilho</th><th>Ações</th><th>Broker</th></tr></thead>
<thead><tr><th>UID</th><th>Versão</th><th>Ultimo contacto</th><th>Online</th><th>Estado</th><th>Brilho</th><th>Relógio</th><th>Ações</th><th>Broker</th></tr></thead>
<tbody>
<?php foreach ($devices as $d):
$uid=$d['uid']; $blocked=(bool)$d['blocked']; $online=(bool)$d['online'];
@ -122,10 +154,34 @@ ob_start();
<td style="color:var(--muted);font-size:12px"><?= h($last) ?><br><span style="font-size:11px"><?= $ago ?></span></td>
<td><?php if($online):?><span class="badge" style="background:#0d2818;color:#3fb950">online</span><?php else:?><span class="badge" style="background:#1e2733;color:var(--muted)">offline</span><?php endif;?></td>
<td><?php if($blocked):?><span class="badge" style="background:#2d1a1a;color:#f85149">bloqueado</span><?php else:?><span class="badge" style="background:#0d2818;color:#3fb950">aprovado</span><?php endif;?></td>
<td><div style="display:flex;align-items:center;gap:6px">
<input type="range" min="0" max="255" value="<?= $bri ?>" id="bri_<?= h($uid) ?>" style="width:90px;accent-color:var(--accent)" oninput="setBri('<?= h($uid) ?>',this.value)" <?= $online?'':'disabled'?>>
<span id="brival_<?= h($uid) ?>" style="font-size:11px;color:var(--muted);min-width:24px"><?= $bri ?></span>
</div></td>
<td>
<?php $levels = [1,2,4,8,12,16,24,32,48,64,96,128,176,224,255];
if (!in_array($bri, $levels, true)) { $levels[] = $bri; sort($levels); } ?>
<select onchange="setBri('<?= h($uid) ?>', this.value)" <?= $online?'':'disabled'?>
style="background:#1e2733;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:3px 6px;font-size:12px;">
<?php foreach ($levels as $lv): ?>
<option value="<?= $lv ?>" <?= $lv === $bri ? 'selected' : '' ?>><?= $lv ?><?= $lv===1?' (mín)':($lv===255?' (máx)':'') ?></option>
<?php endforeach; ?>
</select>
</td>
<td style="white-space:nowrap">
<select onchange="clockCmd('<?= h($uid) ?>','clock_style',this.value);this.selectedIndex=0;" <?= $online?'':'disabled'?>
style="background:#1e2733;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:3px 4px;font-size:11px;">
<option value="" selected>Estilo…</option>
<option value="0">Hybrid</option>
<option value="1">Analógico</option>
<option value="2">Barras</option>
<option value="3">Big</option>
</select>
<select onchange="clockCmd('<?= h($uid) ?>','clock_theme',this.value);this.selectedIndex=0;" <?= $online?'':'disabled'?>
style="background:#1e2733;color:#c9d1d9;border:1px solid #30363d;border-radius:4px;padding:3px 4px;font-size:11px;">
<option value="" selected>Tema…</option>
<option value="ambar">Âmbar</option>
<option value="verde">Verde</option>
<option value="branco">Branco</option>
<option value="noite">Noite</option>
</select>
</td>
<td style="white-space:nowrap">
<?php if($blocked):?>
<button class="btn btn-secondary btn-sm" data-uid="<?= h($uid) ?>" data-act="approve">Aprovar</button>
@ -165,13 +221,15 @@ document.addEventListener('click',function(e){
act(b.dataset.uid,b.dataset.act,extra);
});
function setBri(uid,val){
document.getElementById('brival_'+uid).textContent=val;
clearTimeout(_bt[uid]);
_bt[uid]=setTimeout(()=>{
const fd=new FormData();
fd.append('action','brightness');fd.append('uid',uid);fd.append('value',val);
fetch('/esp_proxmox.php',{method:'POST',headers:{'X-Requested-With':'XMLHttpRequest'},body:fd});
},400);
const fd=new FormData();
fd.append('action','brightness');fd.append('uid',uid);fd.append('value',val);
fetch('/esp_proxmox.php',{method:'POST',headers:{'X-Requested-With':'XMLHttpRequest'},body:fd});
}
function clockCmd(uid,action,val){
if(val==='') return;
const fd=new FormData();
fd.append('action',action);fd.append('uid',uid);fd.append('value',val);
fetch('/esp_proxmox.php',{method:'POST',headers:{'X-Requested-With':'XMLHttpRequest'},body:fd}).catch(console.error);
}
</script>