diff --git a/ops/work/web/app.py b/ops/work/web/app.py index a68ee91..8959240 100644 --- a/ops/work/web/app.py +++ b/ops/work/web/app.py @@ -334,6 +334,41 @@ class Data: return {"host": host, "host_ports": {"in": h_in, "out": h_out, "source": h_src}, "links": links} + # ── проверка одной пары: хост + устройство ── + def check_pair(self, host_key, accessory): + hk = norm(host_key) + ak = norm(accessory) + host = self.devices.get(hk, {}).get("name") + acc_name = self.devices.get(ak, {}).get("name") or accessory + if not host: + return {"error": "хост не найден"} + found = None + for e in self.edges.get(hk, []): + if norm(e["to"]) == ak: + found = e + break + if not found: + return {"host": host, "device": acc_name, "known": False, + "supported": False, "verdict": "нет в матрице для этого хоста", + "note": "устройство не описано как аксессуар этого хоста"} + supported = bool(found.get("supported")) + usable = found.get("usable", True) + if not usable: + verdict = "исключено: источники расходятся — требуется проверка у вендора" + elif supported: + q = found.get("max_qty") + verdict = "совместимо" + (" (до %s шт)" % q if q else "") + else: + verdict = "несовместимо" + cond = re.sub(r"^[\u221a\u2713\u2714\u00d7\u2717\u2718\u2022\s]+", "", + (found.get("condition") or "")).strip() # cond_clean + return {"host": host, "device": acc_name, "known": True, + "supported": supported, "usable": usable, + "max_qty": found.get("max_qty"), + "condition": cond, + "source": found.get("source") or "матрица", + "verdict": verdict} + # ── матрица: хосты × аксессуары + порты ── def matrix(self): hosts = [h for h in self.hosts()] @@ -673,6 +708,9 @@ class H(BaseHTTPRequestHandler): return self._out({"missing": D.extra.get("missing") or []}) if p == "/api/kits": return self._out(D.kits) + if p == "/api/check": + return self._out(D.check_pair(q.get("host", [""])[0], + q.get("device", [""])[0])) if p == "/api/matrix": return self._out(D.matrix()) if p == "/api/ports": diff --git a/ops/work/web/index.html b/ops/work/web/index.html index c0d26c5..6445b30 100644 --- a/ops/work/web/index.html +++ b/ops/work/web/index.html @@ -128,7 +128,16 @@ svg{width:100%;height:480px;background:#0a0e13;border:1px solid var(--line);bord -
+
+ проверить пару: + + + + + + +
+
+

Порты, комплектация, ограничения

@@ -291,6 +300,39 @@ function drawLinks(lp, hostname){ svg.innerHTML=s; } +async function checkPair(){ + const host=$('#chk-host').value, dev=$('#chk-dev').value.trim(); + if(!dev){ $('#chkres').innerHTML='укажите модель'; return; } + const r=await J(`/api/check?host=${encodeURIComponent(host)}&device=${encodeURIComponent(dev)}`); + if(r.error){ $('#chkres').innerHTML=`${r.error}`; return; } + const ok=r.supported&&r.usable; + const col=ok?'#3fb950':(r.usable===false?'#d29922':'#f85149'); + $('#chkres').innerHTML=`${esc(r.verdict)} + ${r.condition?` · ${esc(r.condition).slice(0,80)}`:''}`; +} +async function hostDetail(key){ + const d=await J('/api/device?key='+key); + const accs=(d.accessories||[]).filter(a=>a.supported&&a.usable!==false); + const blocked=(d.accessories||[]).filter(a=>!a.supported||a.usable===false); + const groups={}; + accs.forEach(a=>{ const r=(a.role||'прочее'); (groups[r]=groups[r]||[]).push(a); }); + $('#mxdetail').innerHTML=`
+

${esc(d.name)} — совместимые аксессуары (${accs.length})

+
+ ${accs.map(a=>`${esc(a.model)}${a.max_qty?' до '+a.max_qty:''}`).join('')} +
+
нажмите на аксессуар — покажу условия. несовместимых скрыто: ${blocked.length}
+
+
`; + window.scrollTo({top:0,behavior:'smooth'}); +} +async function checkOne(host,model){ + const r=await J(`/api/check?host=${encodeURIComponent(host)}&device=${encodeURIComponent(model)}`); + const ok=r.supported&&r.usable; + $('#onecheck').innerHTML=`
+ ${esc(r.host)} + ${esc(r.device)} — ${esc(r.verdict)}
+ ${r.condition?esc(r.condition):'условий нет'} · источник: ${esc(r.source||'матрица')}
`; +} async function loadMatrix(){ if(!MATRIX){ MATRIX=await J('/api/matrix'); PORTS=await J('/api/ports'); } renderMatrix(); renderPorts(); @@ -301,17 +343,21 @@ function renderMatrix(){ const accs=MATRIX.accessories.filter(a=>a.toLowerCase().includes(q)); let rows=MATRIX.rows.filter(r=>r.host.toLowerCase().includes(q)); if(only) rows=rows.filter(r=>r.ports.source==='verified'); - $('#mstat').textContent=`хостов ${rows.length} · аксессуаров ${accs.length}`; + $('#mstat').textContent=`хостов ${rows.length} · аксессуаров ${accs.length} · кликайте строку или ячейку`; + if($('#chk-host').options.length===0){ + $('#chk-host').innerHTML=MATRIX.hosts.map(x=>``).join(''); + } let html=''; accs.forEach(a=>{html+=``}); html+=''; - rows.forEach(r=>{ - html+=` + rows.forEach((r,ri)=>{ + html+=` + `; accs.forEach(a=>{ const v=r.cells[a.toLowerCase().replace(/[^a-z0-9]/g,'')]; - html+=``; + html+=``; }); html+=''; });
Хостinout${esc(a).slice(0,26)}
${esc(r.host)}
${esc(r.host)} ${(r.ports.in||['—']).join(',')} ${(r.ports.out||['—']).join(',')}${v?(v>1?v:'✓'):'·'}${v?(v>1?v:'✓'):'·'}