[WORK] Link View: связи по разъёмам (HDMI/USB/USB-C/VCH/LAN/3.5mm), порты с источником (даташит/извлечено/роль), запрет UVC86 HDMI+MVC

This commit is contained in:
root committed 2026-11-06 16:02:51 +03:00
1 parent b433314eae
commit daffbe41dd
5 files changed
+582 -24

No files matched your search

+54 -24
View File
@@ -216,34 +216,64 @@ async function capacity(){
${c.notes.length?`<div class="muted" style="margin-top:6px">${c.notes.join('<br>')}</div>`:''}
${c.missing_power.length?`<div class="box">нет данных о питании: ${c.missing_power.join(', ')}</div>`:''}`;
}
function scheme(){
const hk=$('#host').value, name=HOSTS.find(h=>h.key===hk)?.name||hk;
const nodes=[{model:name,role:'Хост',qty:1,central:true,ins:['LAN'],outs:['HDMI','USB','VCH']}];
Object.keys(SEL).forEach(k=>nodes.push({model:k,role:SEL[k].role,qty:SEL[k].qty,ins:['LAN'],
outs:[/амер|исплей/i.test(SEL[k].role)?'HDMI':/ронштейн/i.test(SEL[k].role)?'—':'USB']}));
draw({nodes});
async function scheme(){
const hk=$('#host').value, host=HOSTS.find(h=>h.key===hk)?.name||hk;
const ks=Object.keys(SEL);
const q=ks.map(k=>'item='+encodeURIComponent(k)).join('&');
const lp=await J(`/api/links?host=${hk}&${q}`);
renderLinks(lp);
$('#schemecard').classList.remove('hidden');
drawLinks(lp, host);
}
const COLOR={HDMI:'#2f81f7',USB:'#3fb950',VCH:'#a371f7',LAN:'#d29922','—':'#8b949e'};
function draw(sc){
function renderLinks(lp){
const ok=lp.links.filter(l=>l.ok).length, bad=lp.links.filter(l=>!l.ok);
let html=`<div class="kv" style="margin-bottom:8px">
<div>порты хоста (вход)</div><div><b>${(lp.host_ports.in||[]).join(', ')||'—'}</b></div>
<div>порты хоста (выход)</div><div><b>${(lp.host_ports.out||[]).join(', ')||'—'}</b></div>
<div>источник портов</div><div><b>${lp.host_ports.source==='verified'?'даташит':lp.host_ports.source==='auto'?'извлечено':'по роли'}</b></div>
</div>
<div class="box ${ok===lp.links.length?'ok':''}">
связей собрано: <b>${ok}</b> из ${lp.links.length}
${bad.length?`<br>✗ ${bad.map(l=>l.device+': '+(l.reason||'нет пары')).join('<br>✗ ')}`:''}
</div>`;
$('#schemecard').querySelector('h3').innerHTML='Link View — связи по разъёмам';
let extra=document.getElementById('linkinfo');
if(!extra){extra=document.createElement('div');extra.id='linkinfo';$('#schemecard').appendChild(extra);}
extra.innerHTML=html;
}
const COLOR={HDMI:'#2f81f7',USB:'#3fb950','USB-C':'#3fb950',VCH:'#a371f7',LAN:'#d29922','3.5mm':'#8b949e',DP:'#a371f7',PHOENIX:'#8b949e','—':'#484f58'};
function drawLinks(lp, hostname){
const svg=$('#svg');svg.innerHTML='';
const c=sc.nodes.find(n=>n.central)||sc.nodes[0], others=sc.nodes.filter(n=>n!==c);
const W=960,H=460,cx=W/2,cy=H/2,bw=170,bh=80;
const cx=480,cy=230,bw=180,bh=90;
const good=lp.links.filter(l=>l.ok), bad=lp.links.filter(l=>!l.ok);
const all=lp.links;
let s='';
others.forEach((n,i)=>{const a=(2*Math.PI*i)/Math.max(others.length,1)-Math.PI/2;
const x=cx+320*Math.cos(a),y=cy+160*Math.sin(a);
s+=`<path d="M ${cx+bw/2} ${cy} C ${cx+110} ${cy}, ${x-130} ${y}, ${x-bw/2} ${y}" fill="none" stroke="${COLOR[(n.outs||['—'])[0]]||'#8b949e'}" stroke-width="2" opacity=".85"/>`;});
others.forEach((n,i)=>{const a=(2*Math.PI*i)/Math.max(others.length,1)-Math.PI/2;
const x=cx+320*Math.cos(a),y=cy+160*Math.sin(a);s+=box(n,x-bw/2,y-36,bw,72);});
s+=box(c,cx-bw/2,cy-bh/2,bw,bh,true);svg.innerHTML=s;
}
function box(n,x,y,w,h,central){
let s=`<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="10" fill="${central?'#132239':'#161b22'}" stroke="${central?'#2f81f7':'#30363d'}" stroke-width="${central?2:1.2}"/>`;
s+=`<text x="${x+11}" y="${y+19}" fill="#e6edf3" font-size="12" font-weight="600">${esc(n.model).slice(0,23)}</text>`;
s+=`<text x="${x+11}" y="${y+33}" fill="#8b949e" font-size="10">${esc(n.role)}${n.qty>1?' ×'+n.qty:''}</text>`;
let a=y+48;(n.ins||[]).forEach(p=>{s+=`<circle cx="${x}" cy="${a}" r="4" fill="${COLOR[p]||'#8b949e'}"/><text x="${x+9}" y="${a+3.5}" fill="#8b949e" font-size="9">in ${esc(p)}</text>`;a+=12;});
let b=y+48;(n.outs||[]).forEach(p=>{s+=`<circle cx="${x+w}" cy="${b}" r="4" fill="${COLOR[p]||'#8b949e'}"/><text x="${x+w-9}" y="${b+3.5}" fill="#8b949e" font-size="9" text-anchor="end">out ${esc(p)}</text>`;b+=12;});
return s;
// хост
s+=`<rect x="${cx-bw/2}" y="${cy-bh/2}" width="${bw}" height="${bh}" rx="10" fill="#132239" stroke="#2f81f7" stroke-width="2"/>`;
s+=`<text x="${cx-bw/2+12}" y="${cy-bh/2+20}" fill="#e6edf3" font-size="12.5" font-weight="600">${esc(hostname).slice(0,24)}</text>`;
s+=`<text x="${cx-bw/2+12}" y="${cy-bh/2+34}" fill="#8b949e" font-size="10">хост · ${lp.host_ports.source}</text>`;
// порты хоста
(lp.host_ports.in||[]).slice(0,4).forEach((p,i)=>{
const y=cy-bh/2+52+i*12;
s+=`<circle cx="${cx-bw/2}" cy="${y}" r="4" fill="${COLOR[p]||'#8b949e'}"/><text x="${cx-bw/2+9}" y="${y+3.5}" fill="#8b949e" font-size="9">in ${esc(p)}</text>`;
});
(lp.host_ports.out||[]).slice(0,4).forEach((p,i)=>{
const y=cy-bh/2+52+i*12;
s+=`<circle cx="${cx+bw/2}" cy="${y}" r="4" fill="${COLOR[p]||'#8b949e'}"/><text x="${cx+bw/2-9}" y="${y+3.5}" fill="#8b949e" font-size="9" text-anchor="end">out ${esc(p)}</text>`;
});
// аксессуары
all.forEach((l,i)=>{
const a=(2*Math.PI*i)/Math.max(all.length,1)-Math.PI/2;
const x=cx+300*Math.cos(a), y=cy+150*Math.sin(a);
const col=l.ok?(COLOR[l.from_port]||'#3fb950'):'#f85149';
const dash=l.ok?'':'stroke-dasharray="5 4"';
s+=`<path d="M ${cx} ${cy} L ${x} ${y}" stroke="${col}" stroke-width="2" ${dash} opacity=".8" fill="none"/>`;
s+=`<rect x="${x-78}" y="${y-26}" width="156" height="52" rx="9" fill="#161b22" stroke="${col}" stroke-width="1.3"/>`;
s+=`<text x="${x}" y="${y-7}" text-anchor="middle" fill="#e6edf3" font-size="11.5" font-weight="600">${esc(l.device).slice(0,22)}</text>`;
s+=`<text x="${x}" y="${y+8}" text-anchor="middle" fill="#8b949e" font-size="9.5">${l.ok?esc(l.from_port)+' → '+esc(l.to_port):'нет пары'}</text>`;
s+=`<text x="${x}" y="${y+19}" text-anchor="middle" fill="#8b949e" font-size="9">${l.source==='verified'?'даташит':l.source==='auto'?'извлечено':'по роли'}</text>`;
});
svg.innerHTML=s;
}
function esc(s){return String(s).replace(/[<>&]/g,c=>({'<':'&lt;','>':'&gt;','&':'&amp;'}[c]))}
boot();