Files
buryan-infra/ops/work/web/index.html
T

253 lines
15 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title>Комбайн</title>
<style>
:root{--bg:#0d1117;--panel:#161b22;--panel2:#1c232c;--line:#30363d;--txt:#e6edf3;--dim:#8b949e;--acc:#2f81f7;--ok:#3fb950;--bad:#f85149;--warn:#d29922;--purple:#a371f7}
*{box-sizing:border-box}
body{margin:0;font:14px/1.5 -apple-system,Segoe UI,Roboto,sans-serif;background:var(--bg);color:var(--txt)}
header{display:flex;align-items:center;gap:16px;padding:11px 20px;border-bottom:1px solid var(--line);background:var(--panel)}
header h1{font-size:15px;margin:0;font-weight:600}
.cs{font-size:12px;color:var(--dim)}.cs b{color:var(--txt)}
.mode{margin-left:auto;font-size:11.5px;color:var(--dim);border:1px solid var(--line);padding:4px 10px;border-radius:20px}
main{max-width:1620px;margin:0 auto;padding:18px}
.crumb{display:flex;align-items:center;gap:7px;margin-bottom:14px;font-size:12.5px;flex-wrap:wrap}
.crumb .c{padding:5px 12px;border:1px solid var(--line);border-radius:8px;background:var(--panel);color:var(--dim)}
.crumb .c.on{border-color:var(--acc);color:var(--txt);background:#132239}
.crumb .sep{color:var(--line)}
.dir{display:grid;grid-template-columns:repeat(3,1fr);gap:10px}
.dir .d{border:1px solid var(--line);border-radius:10px;padding:14px;background:var(--panel2);cursor:pointer}
.dir .d:hover{border-color:var(--acc)}
.dir .d.soon{opacity:.45;cursor:not-allowed}
.dir .d b{display:block;font-size:14px;margin-bottom:3px}
.dir .d span{font-size:11.5px;color:var(--dim)}
.vendors{display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:9px;margin-top:10px}
.vendors .d{border:1px solid var(--line);border-radius:10px;padding:12px;background:var(--panel2);cursor:pointer}
.vendors .d.soon{opacity:.45;cursor:not-allowed}
.card{background:var(--panel);border:1px solid var(--line);border-radius:11px;padding:14px}
.card h3{margin:0 0 10px;font-size:11.5px;text-transform:uppercase;letter-spacing:.6px;color:var(--dim);font-weight:600}
.lay{display:grid;grid-template-columns:300px 1fr 350px;gap:14px;align-items:start}
@media(max-width:1250px){.lay{grid-template-columns:1fr}}
label{display:block;font-size:11.5px;color:var(--dim);margin:8px 0 3px}
select,input{width:100%;background:#0d1117;border:1px solid var(--line);color:var(--txt);padding:7px 9px;border-radius:6px;font-size:12.5px}
input[type=range]{padding:0;accent-color:var(--acc)}
.btn{background:var(--acc);border:0;color:#fff;padding:9px 16px;border-radius:7px;font-size:13px;font-weight:600;cursor:pointer}
.btn.sm{padding:5px 10px;font-size:12px}
.btn.ghost{background:transparent;border:1px solid var(--line);color:var(--txt)}
.pos{margin-bottom:14px;border:1px solid var(--line);border-radius:9px;overflow:hidden}
.pos>h4{margin:0;padding:8px 12px;background:var(--panel2);font-size:12.5px;display:flex;justify-content:space-between;align-items:center;cursor:pointer}
.pos>h4 small{color:var(--dim);font-weight:400}
.pos>.body{padding:10px 12px}
.pitem{display:flex;align-items:center;gap:8px;padding:5px 0;border-bottom:1px solid #232b36}
.pitem:last-child{border-bottom:0}
.pitem .nm{flex:1;font-size:12.5px}
.pitem .sp{font-size:11px;color:var(--dim)}
table{width:100%;border-collapse:collapse;font-size:12.5px}
th,td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--line)}
th{color:var(--dim);font-weight:500;font-size:11px;text-transform:uppercase}
.tag{display:inline-block;background:#1f6feb22;color:#79c0ff;border:1px solid #1f6feb44;padding:1px 7px;border-radius:20px;font-size:10.5px;margin:1px 3px 1px 0}
.muted{color:var(--dim);font-size:11.5px}
.box{border-left:3px solid var(--warn);background:#2d2208;padding:8px 11px;border-radius:6px;margin:8px 0;font-size:12px}
.box.ok{border-color:var(--ok);background:#0d2417}
.box.bad{border-color:var(--bad);background:#2d1214}
.qty{display:inline-flex;align-items:center;gap:5px}
.qty button{width:23px;height:23px;border-radius:5px;border:1px solid var(--line);background:var(--panel2);color:var(--txt);cursor:pointer}
.qty button:disabled{opacity:.3}
svg{width:100%;height:460px;background:#0a0e13;border:1px solid var(--line);border-radius:10px}
.hidden{display:none}
.kv{display:grid;grid-template-columns:1fr auto;gap:3px 10px;font-size:12px}
.kv div:nth-child(odd){color:var(--dim)}
.legend{display:flex;gap:12px;flex-wrap:wrap;margin-top:8px;font-size:11px;color:var(--dim)}
.legend i{display:inline-block;width:18px;height:3px;margin-right:4px;vertical-align:middle}
</style>
</head>
<body>
<header>
<h1>Комбайн</h1>
<div class="cs">устройств <b id="s1">—</b></div>
<div class="cs">связей <b id="s2">—</b></div>
<div class="cs">хостов <b id="s3">—</b></div>
<div class="mode">сборка · без цен</div>
</header>
<main>
<div class="crumb" id="crumb"><div class="c on">ВКС</div></div>
<section id="pick">
<div class="card"><h3>Направление</h3><div class="dir" id="dirs"></div>
<div id="vendwrap" class="hidden"><h3 style="margin-top:14px">Вендор</h3><div class="vendors" id="vendors"></div></div>
</div>
</section>
<section id="work" class="hidden">
<div class="lay">
<!-- комната -->
<div class="card">
<h3>Комната</h3>
<label>Хост</label><select id="host" onchange="reload()"></select>
<div style="display:flex;gap:8px;margin-top:8px">
<div style="flex:1"><label style="margin:0">Ширина, м</label><input type="number" id="w" value="8" min="2" max="40" oninput="room()"></div>
<div style="flex:1"><label style="margin:0">Длина, м</label><input type="number" id="l" value="10" min="2" max="60" oninput="room()"></div>
</div>
<label>Мест</label>
<div style="display:flex;align-items:center;gap:8px"><input type="range" id="seats" min="2" max="30" value="10" oninput="room()"><b id="seatsv">10</b></div>
<div class="muted" id="roomout" style="margin-top:6px"></div>
<h3 style="margin-top:14px">Требования (фильтр)</h3>
<div id="reqs"></div>
</div>
<!-- позиции -->
<div class="card">
<h3>Позиции — что ставим и куда</h3>
<div id="positions"><p class="muted">выберите хост</p></div>
</div>
<!-- состав + ёмкость -->
<div>
<div class="card">
<h3>Состав решения</h3>
<div id="sel"><p class="muted">добавьте позиции</p></div>
</div>
<div class="card" style="margin-top:12px">
<h3>Проверка ёмкости</h3>
<div id="cap"><p class="muted">—</p></div>
</div>
<div style="display:flex;gap:8px;margin-top:12px">
<button class="btn sm" onclick="scheme()">Схема</button>
<button class="btn sm ghost" onclick="clearAll()">Очистить</button>
</div>
</div>
</div>
<div class="card hidden" id="schemecard" style="margin-top:14px">
<h3>Link View</h3><svg id="svg" viewBox="0 0 960 460"></svg>
<div class="legend"><span><i style="background:#2f81f7"></i>HDMI</span><span><i style="background:#3fb950"></i>USB</span><span><i style="background:#a371f7"></i>VCH</span><span><i style="background:#d29922"></i>LAN</span></div>
</div>
</section>
</main>
<script>
let DIRS=[],VENDS=[],HOSTS=[],POS=null,SEL={},NEED=new Set();
const $=s=>document.querySelector(s),J=async u=>(await fetch(u)).json();
const norm=s=>String(s).toLowerCase().replace(/[^a-z0-9]/g,'');
async function boot(){
const st=await J('/api/stats');
$('#s1').textContent=st.devices;$('#s2').textContent=st.edges;$('#s3').textContent=st.hosts;
DIRS=await J('/api/directions');VENDS=await J('/api/vendors');HOSTS=await J('/api/hosts');
$('#dirs').innerHTML=DIRS.map(d=>`<div class="d ${d.ready?'':'soon'}" ${d.ready?`onclick="dir('${d.id}')"`:''}>
<b>${d.name}</b><span>${d.note}</span></div>`).join('');
$('#host').innerHTML=HOSTS.map(h=>`<option value="${h.key}">${h.name}</option>`).join('');
const rq=await J('/api/requirements');
$('#reqs').innerHTML=rq.map(g=>`<div style="margin-bottom:8px"><div class="muted">${g.group}</div>
<div class="chips">${g.items.map(i=>`<span class="tag" style="cursor:pointer" data-n="${i}" onclick="tog(this,'${i}')">${i}</span>`).join('')}</div></div>`).join('');
room();
}
function dir(id){$('#vendwrap').classList.remove('hidden');
$('#vendors').innerHTML=VENDS.map(v=>`<div class="d ${v.ready?'':'soon'}" ${v.ready?`onclick="vend('${v.id}')"`:''}>
<b>${v.name}</b><span>${v.note}</span></div>`).join('');}
function vend(id){$('#pick').classList.add('hidden');$('#work').classList.remove('hidden');
$('#crumb').innerHTML='<div class="c">ВКС</div><span class="sep">›</span><div class="c">Yealink</div><span class="sep">›</span><div class="c on">конструктор</div>';
reload();}
function tog(el,n){const on=NEED.has(n);on?NEED.delete(n):NEED.add(n);
el.style.background=on?'':'#1f6feb33';el.style.color=on?'':'#79c0ff';reload();}
function room(){
const w=+$('#w').value,l=+$('#l').value,s=+$('#seats').value;
const area=w*l, need=Math.max(3,Math.min(12,Math.round(Math.sqrt(area)/1.4)));
$('#seatsv').textContent=s; window.NEEDM=need;
$('#roomout').innerHTML=`${area} м² · рекомендуемый захват <b>${need} м</b>`;
}
async function reload(){
const h=$('#host').value; if(!h)return;
const need=[...NEED].map(n=>'need='+encodeURIComponent(n)).join('&');
POS=await J(`/api/positions?host=${h}&${need}`);
if(POS.error){$('#positions').innerHTML=`<div class="box bad">${POS.error}</div>`;return}
renderPositions(); renderSel();
}
function renderPositions(){
$('#positions').innerHTML=POS.positions.map(p=>{
if(!p.items.length) return '';
return `<div class="pos"><h4>${p.name}<small>${p.hint} · ${p.items.length}</small></h4>
<div class="body">
<div style="display:flex;gap:6px;margin-bottom:8px">
<select id="p_${p.id}" style="flex:1">${p.items.map(i=>
`<option value="${i.model}">${i.model}${i.max_qty?' • до '+i.max_qty:''}${i.pickup_m?' • '+i.pickup_m+'м':''}${i.zoom?' • '+i.zoom+'×':''}</option>`).join('')}</select>
<button class="btn sm" onclick="add('${p.id}')">+</button>
</div>
${p.items.slice(0,6).map(i=>`<div class="pitem"><span class="nm">${i.model}</span><span class="sp">${i.max_qty?'до '+i.max_qty:''} ${i.pickup_m?i.pickup_m+'м':''} ${i.zoom?i.zoom+'×':''}</span></div>`).join('')}
${p.items.length>6?`<div class="muted">и ещё ${p.items.length-6}…</div>`:''}
</div></div>`;
}).join('') || '<div class="box">нет совместимых позиций под эти требования</div>';
}
function add(pid){
const p=POS.positions.find(x=>x.id===pid), model=$('#p_'+pid).value;
const it=p.items.find(i=>i.model===model); if(!it)return;
const cur=SEL[model]||{qty:0,limit:it.max_qty||99,role:p.name,cond:it.condition||''};
if(cur.qty<cur.limit) cur.qty++;
SEL[model]=cur; renderSel();
}
function setQ(m,d){const it=SEL[m];if(!it)return;it.qty+=d;
if(it.qty<=0)delete SEL[m]; else if(it.qty>it.limit)it.qty=it.limit; renderSel();}
function clearAll(){SEL={};renderSel();}
function renderSel(){
const ks=Object.keys(SEL);
if(!ks.length){$('#sel').innerHTML='<p class="muted">добавьте позиции</p>';$('#cap').innerHTML='<p class="muted">—</p>';return}
$('#sel').innerHTML=`<table><tr><th>Позиция</th><th>Кол</th><th></th></tr>
${ks.map(k=>`<tr><td><b>${k}</b><div class="muted">${SEL[k].role}</div></td>
<td><div class="qty"><button onclick="setQ('${k}',-1)">−</button><b>${SEL[k].qty}</b>
<button onclick="setQ('${k}',1)" ${SEL[k].qty>=SEL[k].limit?'disabled':''}>+</button></div></td>
<td><button class="btn sm ghost" onclick="setQ('${k}',-${SEL[k].qty})">✕</button></td></tr>`).join('')}</table>
<div class="muted" style="margin-top:6px">позиций ${ks.length} · единиц ${ks.reduce((a,k)=>a+SEL[k].qty,0)}</div>`;
capacity();
}
async function capacity(){
const h=$('#host').value, ks=Object.keys(SEL);
if(!ks.length)return;
const q=ks.map(k=>'item='+encodeURIComponent(k+':'+SEL[k].qty)).join('&');
const c=await J(`/api/capacity?host=${h}&${q}`);
if(c.error){$('#cap').innerHTML=`<div class="box bad">${c.error}</div>`;return}
const need=window.NEEDM||6;
const mics=ks.filter(k=>/микрофон|аудио/i.test(SEL[k].role));
let micNote='';
$('#cap').innerHTML=`<div class="kv">
<div>портов VCH</div><div><b>${c.vch_ports??'—'}</b></div>
<div>устройств на VCH</div><div><b>${c.vch_users}</b></div>
<div>потребление</div><div><b>${c.total_power_w} Вт</b></div>
</div>
${c.issues.length?`<div class="box bad">✗ ${c.issues.join('<br>✗ ')}</div>`:'<div class="box ok">✓ порты и лимиты в норме</div>'}
${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});
$('#schemecard').classList.remove('hidden');
}
const COLOR={HDMI:'#2f81f7',USB:'#3fb950',VCH:'#a371f7',LAN:'#d29922','—':'#8b949e'};
function draw(sc){
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;
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;
}
function esc(s){return String(s).replace(/[<>&]/g,c=>({'<':'&lt;','>':'&gt;','&':'&amp;'}[c]))}
boot();
</script>
</body>
</html>