Files
weval-l99/v117_hub_badges.py
2026-04-24 04:38:58 +02:00

91 lines
3.8 KiB
Python

#!/usr/bin/env python3
"""V117 - Add HTTP status badges to dashboard tiles + optional fetch with check"""
path = "/var/www/html/all-ia-hub.html"
with open(path, "r", encoding="utf-8") as f:
c = f.read()
if "V117-HTTP-BADGES" in c:
print("ALREADY")
exit(0)
# Enhance loadDashboards to include check=1 for status badges
old = """async function loadDashboards(){
try {
const r = await fetch('/api/dashboards-registry.php');
const d = await r.json();
__dashData = d;
renderDashStats(d);
renderDashFilters(d);
renderDashGrid(d.dashboards, 'all');
} catch(e){ console.error('[dashboards]',e); }
}"""
new = """async function loadDashboards(){
// V117-HTTP-BADGES: load with optional status check
try {
const r = await fetch('/api/dashboards-registry.php');
const d = await r.json();
__dashData = d;
renderDashStats(d);
renderDashFilters(d);
renderDashGrid(d.dashboards, 'all');
// async load status badges in background
loadDashboardsStatus();
} catch(e){ console.error('[dashboards]',e); }
}
async function loadDashboardsStatus(){
try {
const r = await fetch('/api/dashboards-registry.php?check=1');
const d = await r.json();
__dashData = d;
renderDashGrid(d.dashboards, document.querySelector('.dash-filter.on')?.getAttribute('data-cat') || 'all');
} catch(e){ console.error('[dashboards-status]',e); }
}"""
if old not in c:
print("loadDashboards anchor missing")
exit(1)
c = c.replace(old, new, 1)
# Enhance renderDashGrid to show status badge
old_render = """function renderDashGrid(items, cat){
const box = document.getElementById('dash-grid');
if (!box) return;
const filtered = cat === 'all' ? items : items.filter(x => x.category === cat);
box.innerHTML = filtered.map(e =>
'<a href=\"'+e.url+'\" target=\"_blank\" style=\"text-decoration:none;color:inherit;display:block;padding:10px;background:linear-gradient(135deg,'+e.color+'22,'+e.color+'11);border:1px solid '+e.color+'55;border-radius:6px\">' +
'<div style=\"font-size:18px;margin-bottom:4px\">'+e.icon+' <span style=\"font-size:9px;color:'+e.color+';text-transform:uppercase\">'+e.category+'</span></div>' +
'<div style=\"font-size:11px;font-weight:bold;line-height:1.3;margin-bottom:4px\">'+e.display+'</div>' +
'<div style=\"font-size:9px;color:var(--mu)\">'+e.name+' - '+e.size_kb+'KB</div>' +
'</a>'
).join('');
}"""
new_render = """function renderDashGrid(items, cat){
/* V117-HTTP-BADGES: status badge */
const box = document.getElementById('dash-grid');
if (!box) return;
const filtered = cat === 'all' ? items : items.filter(x => x.category === cat);
function statusBadge(s){
if(!s) return '';
if(s===200) return '<span style=\"color:#10b981;font-size:9px;margin-left:4px\">&#9679; 200</span>';
if(s===302) return '<span style=\"color:#f59e0b;font-size:9px;margin-left:4px\">&#9679; auth</span>';
return '<span style=\"color:#ef4444;font-size:9px;margin-left:4px\">&#9679; '+s+'</span>';
}
box.innerHTML = filtered.map(e =>
'<a href=\"'+e.url+'\" target=\"_blank\" style=\"text-decoration:none;color:inherit;display:block;padding:10px;background:linear-gradient(135deg,'+e.color+'22,'+e.color+'11);border:1px solid '+e.color+'55;border-radius:6px\">' +
'<div style=\"font-size:18px;margin-bottom:4px\">'+e.icon+' <span style=\"font-size:9px;color:'+e.color+';text-transform:uppercase\">'+e.category+'</span>'+statusBadge(e.http_status)+'</div>' +
'<div style=\"font-size:11px;font-weight:bold;line-height:1.3;margin-bottom:4px\">'+e.display+'</div>' +
'<div style=\"font-size:9px;color:var(--mu)\">'+e.name+' - '+e.size_kb+'KB</div>' +
'</a>'
).join('');
}"""
if old_render in c:
c = c.replace(old_render, new_render, 1)
with open(path, "w", encoding="utf-8") as f:
f.write(c)
print(f"PATCHED size={len(c)}")