v2.1 - Small improvement
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/* Alfred V2 monitoring extension: no credentials, no write calls. */
|
||||
(() => {
|
||||
'use strict';
|
||||
const byId = id => document.getElementById(id);
|
||||
const text = (id, value) => { const el = byId(id); if (el) el.textContent = String(value ?? '—'); };
|
||||
const pill = (id, state) => {
|
||||
const el = byId(id); if (!el) return;
|
||||
const states = {ok:'Disponible', warning:'Attention', down:'Indisponible', unknown:'Non vérifié'};
|
||||
el.dataset.state = state || 'unknown';
|
||||
el.textContent = states[state] || 'Non vérifié';
|
||||
};
|
||||
const duration = seconds => {
|
||||
const n = Math.max(0, Math.floor(Number(seconds) || 0));
|
||||
if (n >= 3600) return `${Math.floor(n/3600)} h ${String(Math.floor((n%3600)/60)).padStart(2,'0')} min`;
|
||||
return `${Math.floor(n/60)} min ${String(n%60).padStart(2,'0')} s`;
|
||||
};
|
||||
window.alfredAdminV2Health = data => {
|
||||
if (document.body.dataset.page !== 'surveillance') return;
|
||||
const stt = data.stt || {}, whisper = stt.whisper || {}, timers = data.timers || {};
|
||||
text('v2SttActive', stt.active_engine === 'wyoming' ? 'Whisper distant' : 'Vosk local');
|
||||
text('v2SttDetail', stt.detail || 'État indisponible');
|
||||
pill('v2SttState', stt.state);
|
||||
text('v2WhisperAddress', stt.host && stt.port ? `${stt.host}:${stt.port}` : 'Non configuré');
|
||||
text('v2WhisperDetail', whisper.detail || 'Service non vérifié');
|
||||
pill('v2WhisperState', whisper.state);
|
||||
text('v2TimerCount', `${(timers.items || []).length} actif(s)`);
|
||||
pill('v2TimerState', timers.state);
|
||||
const list = byId('v2TimerList');
|
||||
if (list) {
|
||||
list.replaceChildren();
|
||||
const items = timers.items || [];
|
||||
if (!items.length) {
|
||||
const p=document.createElement('p');p.className='muted microtext';
|
||||
p.textContent=timers.detail || 'Aucun minuteur actif'; list.appendChild(p);
|
||||
}
|
||||
items.forEach(item => {
|
||||
const row=document.createElement('div'); row.className='admin-v2-timer-row';
|
||||
const name=document.createElement('strong'); name.textContent=item.label || 'Minuteur';
|
||||
const val=document.createElement('span');
|
||||
val.textContent=item.state === 'paused' ? 'En pause' :
|
||||
(item.remaining == null ? duration(item.elapsed || 0) + ' écoulées' : duration(item.remaining) + ' restantes');
|
||||
row.append(name,val); list.appendChild(row);
|
||||
});
|
||||
}
|
||||
const allowed = Boolean(data.maintenance?.web_restart_enabled);
|
||||
text('v2RestartLabel', allowed ? 'Autorisé' : 'Désactivé');
|
||||
pill('v2RestartState', allowed ? 'ok' : 'warning');
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user