[WORK] Матрица кликабельная: клик по хосту показывает совместимые аксессуары, клик по аксессуару — условия; быстрая проверка пары (M500 + VCM36-W -> несовместимо)
This commit is contained in:
1 parent
388b5c1603
commit
766dcbf1f9
2 files changed
+89
-5
No files matched your search
@@ -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":
|
||||
|
||||
+51
-5
@@ -128,7 +128,16 @@ svg{width:100%;height:480px;background:#0a0e13;border:1px solid var(--line);bord
|
||||
<label style="display:flex;gap:6px;align-items:center;margin:0;font-size:12px"><input type="checkbox" id="monly" onchange="renderMatrix()"> только с портами из даташита</label>
|
||||
<span class="muted" id="mstat"></span>
|
||||
</div>
|
||||
<div id="matrixbox" style="overflow:auto;max-height:68vh"></div>
|
||||
<div style="display:flex;gap:8px;margin-bottom:10px;flex-wrap:wrap;align-items:center">
|
||||
<span class="muted">проверить пару:</span>
|
||||
<select id="chk-host" style="max-width:220px"></select>
|
||||
<span class="muted">+</span>
|
||||
<input id="chk-dev" placeholder="модель, напр. VCM36-W" style="max-width:200px">
|
||||
<button class="btn sm" onclick="checkPair()">Проверить</button>
|
||||
<span id="chkres"></span>
|
||||
</div>
|
||||
<div id="mxdetail"></div>
|
||||
<div id="matrixbox" style="overflow:auto;max-height:62vh"></div>
|
||||
</div>
|
||||
<div class="card" style="margin-top:14px">
|
||||
<h3>Порты, комплектация, ограничения</h3>
|
||||
@@ -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='<span class="muted">укажите модель</span>'; return; }
|
||||
const r=await J(`/api/check?host=${encodeURIComponent(host)}&device=${encodeURIComponent(dev)}`);
|
||||
if(r.error){ $('#chkres').innerHTML=`<span style="color:#f85149">${r.error}</span>`; return; }
|
||||
const ok=r.supported&&r.usable;
|
||||
const col=ok?'#3fb950':(r.usable===false?'#d29922':'#f85149');
|
||||
$('#chkres').innerHTML=`<b style="color:${col}">${esc(r.verdict)}</b>
|
||||
${r.condition?`<span class="muted"> · ${esc(r.condition).slice(0,80)}</span>`:''}`;
|
||||
}
|
||||
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=`<div class="card" style="margin-bottom:12px;border-color:#2f81f7">
|
||||
<h3 style="color:#79c0ff">${esc(d.name)} — совместимые аксессуары (${accs.length})</h3>
|
||||
<div style="display:flex;flex-wrap:wrap;gap:6px;margin-bottom:8px">
|
||||
${accs.map(a=>`<span class="tag" style="cursor:pointer" onclick="checkOne('${key}','${esc(a.model).replace(/'/g,'')}')">${esc(a.model)}${a.max_qty?' до '+a.max_qty:''}</span>`).join('')}
|
||||
</div>
|
||||
<div class="muted">нажмите на аксессуар — покажу условия. несовместимых скрыто: ${blocked.length}</div>
|
||||
<div id="onecheck" style="margin-top:8px"></div>
|
||||
</div>`;
|
||||
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=`<div class="box ${ok?'ok':'bad'}">
|
||||
<b>${esc(r.host)} + ${esc(r.device)}</b> — ${esc(r.verdict)}<br>
|
||||
<span class="muted">${r.condition?esc(r.condition):'условий нет'} · источник: ${esc(r.source||'матрица')}</span></div>`;
|
||||
}
|
||||
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=>`<option>${esc(x)}</option>`).join('');
|
||||
}
|
||||
let html='<table style="font-size:11.5px"><tr><th>Хост</th><th>in</th><th>out</th>';
|
||||
accs.forEach(a=>{html+=`<th style="writing-mode:vertical-rl;transform:rotate(180deg);height:110px">${esc(a).slice(0,26)}</th>`});
|
||||
html+='</tr>';
|
||||
rows.forEach(r=>{
|
||||
html+=`<tr><td style="font-weight:600;white-space:nowrap">${esc(r.host)}</td>
|
||||
rows.forEach((r,ri)=>{
|
||||
html+=`<tr onclick="hostDetail('${r.host.toLowerCase().replace(/[^a-z0-9]/g,'')}')" style="cursor:pointer">
|
||||
<td style="font-weight:600;white-space:nowrap;color:#79c0ff">${esc(r.host)}</td>
|
||||
<td class="muted">${(r.ports.in||['—']).join(',')}</td>
|
||||
<td class="muted">${(r.ports.out||['—']).join(',')}</td>`;
|
||||
accs.forEach(a=>{
|
||||
const v=r.cells[a.toLowerCase().replace(/[^a-z0-9]/g,'')];
|
||||
html+=`<td style="text-align:center;color:${v?'#3fb950':'#30363d'}">${v?(v>1?v:'✓'):'·'}</td>`;
|
||||
html+=`<td style="text-align:center;color:${v?'#3fb950':'#30363d'}" ${v?`onclick="event.stopPropagation();checkOne('${r.host.toLowerCase().replace(/[^a-z0-9]/g,'')}','${esc(a).replace(/'/g,'')}')"`:''}>${v?(v>1?v:'✓'):'·'}</td>`;
|
||||
});
|
||||
html+='</tr>';
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user