Files
app-autotest/site/templates/index.html
T

200 lines
10 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<title>Autotest</title>
<link rel="icon" type="image/svg+xml" href="{{ url_for('static', filename='favicon.svg') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
<style>
.topbar { max-width:1200px; margin:0 auto; padding:10px 16px 0; display:flex; align-items:center; gap:12px; }
.layout { display:flex; gap:12px; max-width:1200px; margin:8px auto; padding:0 16px; }
.col-infra { width:280px; flex-shrink:0; }
.col-svc { width:240px; flex-shrink:0; }
.col-main { flex:1; min-width:0; }
.svc-item { cursor:pointer; padding:4px 8px; font-size:12px; border-radius:4px; }
.svc-item:hover, .svc-item.active { background:var(--brand-grey-light); }
.op-item { display:flex; align-items:center; gap:6px; padding:3px 8px; font-size:12px; }
.op-item.disabled { opacity:0.4; }
.btn-sm { height:24px; font-size:11px; padding:0 8px; }
.param-row { display:flex; align-items:center; gap:8px; margin-bottom:6px; }
.param-row label { width:160px; font-size:11px; text-align:right; flex-shrink:0; }
.param-row label.req { font-weight:600; }
.param-row label.req-nodfl { font-weight:600; color:var(--destructive); }
.param-row input,.param-row select { flex:1; height:28px; font-size:12px; border:1px solid var(--brand-gray); border-radius:4px; padding:0 6px; }
</style>
</head>
<body>
<div class="topbar">
<img src="{{ url_for('static', filename='logo.svg') }}" alt="Nubes" style="height:22px;" />
<span style="font-size:11px;color:var(--muted);">v{{ config.VERSION }}</span>
{% if token_info.email %}<span style="font-size:11px;color:var(--muted);">{{ token_info.email }} | {{ token_info.company }} | test</span>{% endif %}
<span style="flex:1;"></span>
<form method="post" style="display:flex;align-items:center;gap:6px;">
<input type="password" name="token" placeholder="env: {{ env_token_masked }}" value="{{ '' if not has_user_token else '••••••••' }}" style="height:28px;width:180px;font-size:12px;border:1px solid var(--brand-gray);border-radius:4px;padding:0 6px;" />
<button type="submit" name="action" value="save" class="btn" style="height:28px;font-size:12px;padding:0 8px;">OK</button>
{% if has_user_token %}<button type="submit" name="action" value="clear" class="btn btn-danger" style="height:28px;font-size:12px;padding:0 8px;">Выйти</button>{% endif %}
</form>
{% if error %}<span style="color:var(--destructive);font-size:12px;">{{ error }}</span>{% endif %}
</div>
<div class="layout">
<!-- Инфраструктура -->
<div class="col-infra">
{% if organization %}
<div class="card">
<div class="card-header">Организация</div>
<div class="card-body" style="padding:6px 10px;font-size:12px;">
{{ organization.displayName }}{% if client_id %} ({{ client_id }}){% endif %}<br>
<span class="badge badge-success" style="font-size:10px;">{{ organization.explainedStatus or "OK" }}</span>
</div>
</div>
{% endif %}
{% for svc_name, items in instance_groups.items() %}
<div class="card" style="margin-top:6px;">
<div class="card-header" style="font-size:12px;cursor:pointer;" onclick="this.nextElementSibling.style.display=this.nextElementSibling.style.display==='none'?'block':'none'">{{ svc_name }} ({{ items|length }})</div>
<div class="card-body" style="padding:0;max-height:150px;overflow-y:auto;">
<table>
{% for i in items %}
<tr><td style="font-size:11px;padding:2px 8px;">{{ i.displayName }}</td><td><span class="badge badge-success" style="font-size:9px;">{{ i.explainedStatus or '?' }}</span></td></tr>
{% endfor %}
</table>
</div>
</div>
{% endfor %}
</div>
<!-- Сервисы -->
<div class="col-svc">
<div class="card">
<div class="card-header" style="font-size:12px;">Сервисы</div>
<div class="card-body" style="padding:4px;max-height:70vh;overflow-y:auto;" id="svc-list">
<span style="color:var(--muted);font-size:11px;">Загрузка...</span>
</div>
</div>
</div>
<!-- Операции + Параметры + Результат -->
<div class="col-main">
<div class="card" id="ops-card" style="display:none;">
<div class="card-header" style="font-size:12px;" id="ops-title">Операции</div>
<div class="card-body" style="padding:4px;" id="ops-list"></div>
</div>
<div class="card" id="params-card" style="margin-top:8px;display:none;">
<div class="card-header" style="font-size:12px;">Параметры</div>
<div class="card-body" style="padding:8px;" id="params-form"></div>
<div style="padding:0 8px 8px;">
<button class="btn btn-primary btn-sm" onclick="runTest()" id="btn-test" style="display:none;">Запустить тест</button>
<span id="test-status" style="font-size:11px;margin-left:8px;"></span>
</div>
</div>
</div>
</div>
<script>
let selectedSvc=null, selectedOp=null, svcInstances=[];
// Load services
fetch('/api/services').then(r=>r.json()).then(data=>{
const el=document.getElementById('svc-list');
el.innerHTML=data.map(s=>`<div class="svc-item" data-svc-id="${s.svcId}" onclick="selectService(${s.svcId})">${s.svcId}. ${s.svc}${s.svcExtendedName?' — '+s.svcExtendedName:''}</div>`).join('');
});
async function selectService(svcId){
selectedSvc=svcId; selectedOp=null;
document.querySelectorAll('.svc-item').forEach(e=>e.classList.toggle('active',e.dataset.svcId==String(svcId)));
document.getElementById('params-card').style.display='none';
document.getElementById('btn-test').style.display='none';
const r=await fetch('/api/operations/'+svcId);
const d=await r.json();
svcInstances=d.instances||[];
const hasInstance=svcInstances.length>0;
const activeStatuses=svcInstances.map(i=>i.explainedStatus);
const opsCard=document.getElementById('ops-card');
opsCard.style.display='block';
document.getElementById('ops-title').textContent=d.svc+' — операции';
const opsList=document.getElementById('ops-list');
opsList.innerHTML=d.operations.map(o=>{
let disabled=!hasInstance && o.operation!=='create';
if(hasInstance && o.operation==='create') disabled=true;
if(o.operation==='reconcile') disabled=false;
const cls=disabled?'op-item disabled':'op-item';
const btn=disabled?'':'<button class="btn btn-primary btn-sm" onclick="selectOperation('+o.svcOperationId+',\''+o.operation+'\','+svcId+')">Тест</button>';
const hint=disabled?`<span style="font-size:10px;color:var(--muted);">${hasInstance?'уже есть':'нет инстанса'}</span>`:'';
const instUid=svcInstances.length>0?`<span style="font-size:10px;color:var(--muted);">${svcInstances[0].instanceUid.slice(0,8)}...</span>`:'';
return `<div class="${cls}">${btn} ${o.operation} ${hint} ${instUid}</div>`;
}).join('');
}
async function selectOperation(opId,opName,svcId){
selectedOp={opId,opName,svcId};
document.getElementById('params-card').style.display='block';
document.getElementById('btn-test').style.display='inline-flex';
const r=await fetch('/api/params/'+opId);
const params=await r.json();
const form=document.getElementById('params-form');
form.innerHTML=params.map(p=>{
const req=p.isRequired;
const hasDfl=p.defaultValue!==null&&p.defaultValue!==undefined&&p.defaultValue!=='';
const labelCls=req?(hasDfl?'req':'req-nodfl'):'';
const dfl=hasDfl?p.defaultValue:(req?'':'');
const vl=p.valueList;
let input;
if(vl&&Array.isArray(vl)){
input=`<select name="p_${p.svcOperationCfsParamId}">${vl.map(v=>`<option value="${v}" ${v==dfl?'selected':''}>${v}</option>`).join('')}</select>`;
}else if(p.dataType==='boolean'){
input=`<select name="p_${p.svcOperationCfsParamId}"><option value="true" ${dfl==='true'||dfl===true?'selected':''}>true</option><option value="false" ${dfl==='false'||dfl===false?'selected':''}>false</option></select>`;
}else{
input=`<input type="text" name="p_${p.svcOperationCfsParamId}" value="${dfl}" placeholder="${req&&!hasDfl?'обязательно':''}">`;
}
return `<div class="param-row"><label class="${labelCls}">${p.name}</label>${input}</div>`;
}).join('');
document.getElementById('test-status').textContent='';
}
async function runTest(){
if(!selectedOp) return;
const btn=document.getElementById('btn-test');
btn.disabled=true;
document.getElementById('test-status').textContent=' ⏳ выполняется...';
const params={};
document.querySelectorAll('#params-form [name^="p_"]').forEach(el=>{
params[el.name.replace('p_','')]=el.value;
});
let instUid='';
if(selectedOp.opName!=='create'&&svcInstances.length>0){
instUid=svcInstances[0].instanceUid;
}
try{
const r=await fetch('/api/test',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({
serviceId:selectedOp.svcId,
operation:selectedOp.opName,
svcOperationId:selectedOp.opId,
params,
instanceUid:instUid,
displayName:'autotest-'+selectedOp.svcId
})});
const d=await r.json();
const cls=d.status==='OK'?'badge badge-success':'badge';
document.getElementById('test-status').innerHTML=` <span class="${cls}">${d.status}</span> ${d.error||''} ${d.duration||''}s`;
if(d.status==='OK'&&selectedOp.opName==='create'){
// refresh services to update instance state
selectService(selectedOp.svcId);
}
}catch(e){
document.getElementById('test-status').textContent=' Ошибка: '+e.message;
}
btn.disabled=false;
}
</script>
</body>
</html>