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

302 lines
14 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:18px;padding:12px 22px;border-bottom:1px solid var(--line);background:var(--panel)}
header h1{font-size:16px;margin:0;font-weight:600}
.chipstat{font-size:12px;color:var(--dim)}
.chipstat b{color:var(--txt)}
.mode{margin-left:auto;font-size:12px;color:var(--dim);border:1px solid var(--line);padding:4px 10px;border-radius:20px}
main{max-width:1520px;margin:0 auto;padding:20px}
.steps{display:flex;gap:8px;margin-bottom:18px;flex-wrap:wrap}
.step{display:flex;align-items:center;gap:8px;padding:8px 14px;border:1px solid var(--line);border-radius:9px;background:var(--panel);font-size:13px;color:var(--dim);cursor:pointer}
.step.on{border-color:var(--acc);color:var(--txt);background:#132239}
.step i{width:20px;height:20px;border-radius:50%;background:var(--line);display:grid;place-items:center;font-size:11px;font-style:normal}
.step.on i{background:var(--acc);color:#fff}
.cols{display:grid;grid-template-columns:1fr 1fr;gap:16px}
.cols3{display:grid;grid-template-columns:340px 1fr;gap:16px}
.card{background:var(--panel);border:1px solid var(--line);border-radius:11px;padding:16px}
.card h3{margin:0 0 12px;font-size:12px;text-transform:uppercase;letter-spacing:.6px;color:var(--dim);font-weight:600}
.dir{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}
.dir .d{border:1px solid var(--line);border-radius:10px;padding:16px;cursor:pointer;background:var(--panel2);transition:.15s}
.dir .d:hover{border-color:var(--acc)}
.dir .d.on{border-color:var(--acc);background:#132239}
.dir .d.soon{opacity:.45;cursor:not-allowed}
.dir .d b{display:block;font-size:15px;margin-bottom:4px}
.dir .d span{font-size:12px;color:var(--dim)}
.chips{display:flex;flex-wrap:wrap;gap:7px;margin-top:6px}
.chip{border:1px solid var(--line);background:var(--panel2);color:var(--dim);padding:5px 12px;border-radius:20px;font-size:12.5px;cursor:pointer;user-select:none}
.chip:hover{border-color:var(--acc);color:var(--txt)}
.chip.on{background:#1f6feb22;border-color:var(--acc);color:#79c0ff}
.chip.on::before{content:"✓ ";font-weight:700}
.grp{margin-bottom:14px}
.grp h4{margin:0 0 6px;font-size:12px;color:var(--dim);font-weight:500}
label{display:block;font-size:12px;color:var(--dim);margin:10px 0 5px}
select,input[type=text],input[type=number]{width:100%;background:#0d1117;border:1px solid var(--line);color:var(--txt);padding:9px 11px;border-radius:7px;font-size:13.5px}
input[type=range]{width:100%;accent-color:var(--acc)}
.big{font-size:26px;font-weight:700;color:var(--txt)}
.btn{background:var(--acc);border:0;color:#fff;padding:11px 20px;border-radius:8px;font-size:14px;font-weight:600;cursor:pointer;width:100%;margin-top:14px}
.btn:hover{background:#388bfd}
.btn.ghost{background:transparent;border:1px solid var(--line);color:var(--txt)}
table{width:100%;border-collapse:collapse;font-size:13px}
th,td{text-align:left;padding:8px 10px;border-bottom:1px solid var(--line);vertical-align:top}
th{color:var(--dim);font-weight:500;font-size:11.5px;text-transform:uppercase;letter-spacing:.4px}
tr:hover td{background:#1c232c}
.tag{display:inline-block;background:#1f6feb22;color:#79c0ff;border:1px solid #1f6feb44;padding:2px 8px;border-radius:20px;font-size:11px;margin:2px 4px 2px 0}
.muted{color:var(--dim);font-size:12px}
.box{border-left:3px solid var(--warn);background:#2d2208;padding:10px 14px;border-radius:7px;margin:10px 0;font-size:13px}
.box.ok{border-color:var(--ok);background:#0d2417}
.box.bad{border-color:var(--bad);background:#2d1214}
svg{width:100%;height:560px;background:#0a0e13;border:1px solid var(--line);border-radius:11px}
.hidden{display:none}
.kv{display:grid;grid-template-columns:190px 1fr;gap:3px 14px;font-size:13px}
.kv div:nth-child(odd){color:var(--dim)}
.legend{display:flex;gap:16px;flex-wrap:wrap;margin-top:10px;font-size:12px;color:var(--dim)}
.legend i{display:inline-block;width:22px;height:3px;margin-right:6px;vertical-align:middle}
</style>
</head>
<body>
<header>
<h1>Комбайн</h1>
<div class="chipstat">устройств <b id="s1">—</b></div>
<div class="chipstat">связей <b id="s2">—</b></div>
<div class="chipstat">хостов <b id="s3">—</b></div>
<div class="chipstat">кронштейнов <b id="s4">—</b></div>
<div class="chipstat">атрибутов <b id="s5">—</b></div>
<div class="mode">сборка · без цен</div>
</header>
<main>
<div class="steps">
<div class="step on" data-s="1"><i>1</i> Направление</div>
<div class="step" data-s="2"><i>2</i> Сценарий</div>
<div class="step" data-s="3"><i>3</i> Требования</div>
<div class="step" data-s="4"><i>4</i> Результат</div>
</div>
<!-- 1 -->
<section id="s1v">
<div class="card">
<h3>Что проектируем</h3>
<div class="dir" id="dirs"></div>
</div>
</section>
<!-- 2 -->
<section id="s2v" class="hidden cols">
<div class="card">
<h3>Комната</h3>
<label>Посадка</label>
<div style="display:flex;align-items:center;gap:14px">
<input type="range" id="seats" min="2" max="30" value="10" oninput="seatsOut()">
<div class="big" id="seatsv">10</div><div class="muted">мест</div>
</div>
<div class="muted" id="roomcat" style="margin-top:6px"></div>
<label style="margin-top:16px">Хост (кодек / бар)</label>
<select id="host"></select>
<label style="margin-top:12px">Уже есть (якорь, необязательно)</label>
<select id="anchor"><option value="">— нет —</option></select>
<button class="btn" onclick="go(3)">Дальше →</button>
</div>
<div class="card">
<h3>Что даёт выбранный хост</h3>
<div id="hostinfo"><p class="muted">Выберите хост</p></div>
</div>
</section>
<!-- 3 -->
<section id="s3v" class="hidden cols3">
<div class="card">
<h3>Требования партнёра</h3>
<div id="reqs"></div>
<button class="btn" onclick="runBom()">Собрать решение →</button>
<button class="btn ghost" onclick="go(2)" style="margin-top:8px">← Назад</button>
</div>
<div class="card">
<h3>Выбрано</h3>
<div id="selinfo"><p class="muted">Требования не выбраны</p></div>
</div>
</section>
<!-- 4 -->
<section id="s4v" class="hidden">
<div class="cols">
<div class="card">
<h3>Состав решения</h3>
<div id="bom"></div>
</div>
<div class="card">
<h3>Link View — связи и порты</h3>
<div class="muted" style="margin-bottom:8px">входы слева, выходы справа · связи только между однотипными портами</div>
<svg id="svg" viewBox="0 0 980 560"></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>
<span><i style="background:#8b949e"></i>аудио/прочее</span>
</div>
</div>
</div>
<div style="margin-top:14px;display:flex;gap:10px">
<button class="btn ghost" style="width:auto" onclick="go(3)">← Изменить требования</button>
<button class="btn ghost" style="width:auto" onclick="go(2)">← Изменить комнату</button>
</div>
</section>
</main>
<script>
let HOSTS=[], CURS={dir:null,host:null,seats:10,need:new Set(),anchor:''};
const $=s=>document.querySelector(s);
const J=async u=>(await fetch(u)).json();
function go(n){
['1','2','3','4'].forEach(i=>{
$('#s'+i+'v').classList.toggle('hidden',i!==String(n));
document.querySelector(`.step[data-s="${i}"]`).classList.toggle('on',i===String(n));
});
if(n===2) renderHostInfo();
if(n===3) renderSelected();
}
async function boot(){
const s=await J('/api/stats');
$('#s1').textContent=s.devices; $('#s2').textContent=s.edges;
$('#s3').textContent=s.hosts; $('#s4').textContent=s.mounts; $('#s5').textContent=s.attrs;
const dirs=await J('/api/directions');
$('#dirs').innerHTML=dirs.map(d=>`
<div class="d ${d.ready?'':'soon'}" ${d.ready?`onclick="pickDir('${d.id}')"`:''}>
<b>${d.name}</b><span>${d.note}</span>
${d.ready?'':'<div class="muted" style="margin-top:8px">скоро</div>'}
</div>`).join('');
HOSTS=await J('/api/hosts');
$('#host').innerHTML=HOSTS.map(h=>`<option value="${h.key}">${h.name}</option>`).join('');
$('#anchor').innerHTML='<option value="">— нет —</option>'+
HOSTS.map(h=>`<option value="${h.key}">${h.name}</option>`).join('');
$('#host').onchange=renderHostInfo;
$('#anchor').onchange=e=>{CURS.anchor=e.target.value};
const reqs=await J('/api/requirements');
$('#reqs').innerHTML=reqs.map(g=>`
<div class="grp"><h4>${g.group}</h4><div class="chips">
${g.items.map(it=>`<div class="chip" onclick="toggleReq(this,'${it}')">${it}</div>`).join('')}
</div></div>`).join('');
seatsOut();
}
function pickDir(id){CURS.dir=id; go(2);}
function seatsOut(){
const v=+$('#seats').value; CURS.seats=v; $('#seatsv').textContent=v;
$('#roomcat').textContent = v<=6?'Small (2–6) — нужен захват 3 м'
: v<=12?'Medium (6–12) — 6 м' : v<=16?'Large (12–16) — 8 м':'Extra-large (16+) — 10 м';
}
function toggleReq(el,name){
el.classList.toggle('on');
CURS.need.has(name)?CURS.need.delete(name):CURS.need.add(name);
renderSelected();
}
function renderSelected(){
const items=[...CURS.need];
$('#selinfo').innerHTML = items.length
? items.map(x=>`<span class="tag">${x}</span>`).join('')
: '<p class="muted">Требования не выбраны</p>';
}
async function renderHostInfo(){
const k=$('#host').value; CURS.host=k;
if(!k) return;
const d=await J('/api/device?key='+k);
const attrs=Object.entries(d.attributes||{});
$('#hostinfo').innerHTML=`
<h2 style="margin:0 0 2px;font-size:17px">${d.name}</h2>
<div class="muted" style="margin-bottom:10px">роль: ${d.role} · аксессуаров: ${(d.accessories||[]).filter(a=>a.supported).length}</div>
<div>${(d.features||[]).slice(0,18).map(f=>`<span class="tag">${f}</span>`).join('')||'<span class="muted">нет данных о функциях</span>'}</div>
<h4 style="margin:14px 0 6px;font-size:12px;color:var(--dim)">КЛЮЧЕВЫЕ ЗНАЧЕНИЯ</h4>
<div class="kv">${attrs.slice(0,10).map(([a,b])=>`<div>${a.replace(/^(camera|audio|ports|network|physical)\./,'')}</div><div><b>${b}</b></div>`).join('')||'<div class="muted">нет</div>'}</div>
`;
}
async function runBom(){
const host=$('#host').value, seats=$('#seats').value;
const need=[...CURS.need], add=CURS.anchor?[CURS.anchor]:[];
const qs=need.map(n=>'need='+encodeURIComponent(n)).join('&')+
(add.length?'&add='+encodeURIComponent(add[0]):'');
const r=await J(`/api/bom?host=${host}&seats=${seats}&${qs}`);
if(r.error){$('#bom').innerHTML=`<div class="box bad">${r.error}</div>`;return}
$('#bom').innerHTML=`
<div style="margin-bottom:10px"><b style="font-size:16px">${r.host}</b>
<div class="muted">${r.seats} мест · требуется захват ${r.need_pickup} м</div></div>
<table><tr><th>Роль</th><th>Модель</th><th>Кол</th><th>Обоснование</th></tr>
${r.bom.map(b=>`<tr><td class="muted">${b.role}</td><td><b>${b.model}</b></td><td>${b.qty}</td><td class="muted">${b.why||''}</td></tr>`).join('')}
</table>
${r.warnings.length?`<div class="box">⚠ ${r.warnings.join('<br>⚠ ')}</div>`:''}
${r.cross.length?`<div class="box">зависимости: ${r.cross.join('; ')}</div>`:''}
${!r.warnings.length&&!r.cross.length?`<div class="box ok">✓ Конфигурация собрана без замечаний</div>`:''}
`;
drawLink(r.scheme);
go(4);
}
const COLOR={HDMI:'#2f81f7',USB:'#3fb950',VCH:'#a371f7',LAN:'#d29922'};
function drawLink(sc){
const svg=$('#svg'); svg.innerHTML='';
if(!sc||!sc.nodes.length) return;
const center=sc.nodes.find(n=>n.central)||sc.nodes[0];
const others=sc.nodes.filter(n=>n!==center);
const W=980,Hh=560, cx=W/2, cy=Hh/2;
let s='';
const bw=170, bh=Math.max(70,36+center.outs.length*13);
// линии
others.forEach((n,i)=>{
const a=(2*Math.PI*i)/Math.max(others.length,1)-Math.PI/2;
const x=cx+330*Math.cos(a), y=cy+190*Math.sin(a);
const t=(n.outs||['-'])[0];
const col=COLOR[t]||'#8b949e';
s+=`<path d="M ${cx+bw/2} ${cy} C ${cx+140} ${cy}, ${x-140} ${y}, ${x-bw/2} ${y}"
fill="none" stroke="${col}" stroke-width="2" opacity="0.85"/>`;
});
// остальные узлы
others.forEach((n,i)=>{
const a=(2*Math.PI*i)/Math.max(others.length,1)-Math.PI/2;
const x=cx+330*Math.cos(a), y=cy+190*Math.sin(a);
s+=nodeBox(n,x-bw/2,y-bh/2,bw,bh);
});
// центральный
s+=nodeBox(center,cx-bw/2,cy-bh/2,bw,bh,true);
svg.innerHTML=s;
}
function nodeBox(n,x,y,w,h,central=false){
const fill=central?'#132239':'#161b22', stroke=central?'#2f81f7':'#30363d';
let s=`<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="10" fill="${fill}" stroke="${stroke}" stroke-width="${central?2:1.2}"/>`;
s+=`<text x="${x+12}" y="${y+20}" fill="#e6edf3" font-size="12.5" font-weight="600">${esc(n.model).slice(0,24)}</text>`;
s+=`<text x="${x+12}" y="${y+34}" fill="#8b949e" font-size="10">${esc(n.role)}${n.qty>1?' ×'+n.qty:''}</text>`;
let yy=y+50;
(n.ins||[]).slice(0,3).forEach(p=>{
s+=`<circle cx="${x-1}" cy="${yy}" r="4" fill="${COLOR[p]||'#8b949e'}"/>`;
s+=`<text x="${x+10}" y="${yy+3.5}" fill="#8b949e" font-size="9.5">in ${esc(p)}</text>`;
yy+=13;
});
let yo=y+50;
(n.outs||[]).slice(0,3).forEach(p=>{
s+=`<circle cx="${x+w+1}" cy="${yo}" r="4" fill="${COLOR[p]||'#8b949e'}"/>`;
s+=`<text x="${x+w-10}" y="${yo+3.5}" fill="#8b949e" font-size="9.5" text-anchor="end">out ${esc(p)}</text>`;
yo+=13;
});
return s;
}
function esc(s){return String(s).replace(/[<>&]/g,c=>({'<':'&lt;','>':'&gt;','&':'&amp;'}[c]))}
document.querySelectorAll('.step').forEach(st=>st.onclick=()=>go(+st.dataset.s));
boot();
</script>
</body>
</html>