227 lines
12 KiB
HTML
227 lines
12 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=[], selectedInst=null;
|
|
|
|
(async function(){
|
|
const el=document.getElementById('svc-list');
|
|
try{
|
|
const r=await fetch('/api/services');
|
|
const data=await r.json();
|
|
el.innerHTML=data.map(s=>`<div class="svc-item" data-svc-id="${s.svcId}" onclick="selectService(${s.svcId})">${s.svcId}. ${s.svc}</div>`).join('');
|
|
if(data.length>0) selectService(data[0].svcId);
|
|
}catch(e){el.innerHTML='<span style="color:var(--destructive);font-size:11px;">Ошибка загрузки</span>';}
|
|
})();
|
|
|
|
async function selectService(svcId){
|
|
selectedSvc=svcId; selectedOp=null; selectedInst=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||[];
|
|
|
|
document.getElementById('ops-card').style.display='block';
|
|
document.getElementById('ops-title').textContent=d.svc+' — операции';
|
|
|
|
let html='';
|
|
// Инстансы с именами и статусами
|
|
if(svcInstances.length>0){
|
|
html+='<div style="font-size:11px;font-weight:600;padding:4px 8px;color:var(--muted);">Инстансы</div>';
|
|
svcInstances.forEach(i=>{
|
|
const sc=i.explainedStatus==='running'?'badge-success':'';
|
|
html+=`<div class="op-item" style="cursor:pointer;" onclick="selectInstance('${i.instanceUid}')" data-iuid="${i.instanceUid}">
|
|
<span style="flex:1;font-size:12px;">${i.displayName}</span>
|
|
<span class="badge ${sc}" style="font-size:9px;">${i.explainedStatus||'?'}</span>
|
|
</div>`;
|
|
});
|
|
}
|
|
|
|
// Операции
|
|
html+='<div style="font-size:11px;font-weight:600;padding:4px 8px;color:var(--muted);margin-top:4px;">Операции</div>';
|
|
d.operations.filter(o=>o.operation!=='reconcile').forEach(o=>{
|
|
const isCreate=o.operation==='create';
|
|
const disabled=!isCreate&&!selectedInst;
|
|
const btn=disabled?'':`<button class="btn btn-primary btn-sm" onclick="selectOperation(${o.svcOperationId},'${o.operation}',${svcId})">Тест</button>`;
|
|
const hint=isCreate&&svcInstances.length>0?'<span style="font-size:10px;color:var(--muted);">уже есть</span>':
|
|
(!isCreate&&!selectedInst?'<span style="font-size:10px;color:var(--muted);">выберите инстанс</span>':'');
|
|
html+=`<div class="op-item${disabled?' disabled':''}" id="op-${o.operation}">${btn} ${o.operation} ${hint}</div>`;
|
|
});
|
|
document.getElementById('ops-list').innerHTML=html;
|
|
}
|
|
|
|
function selectInstance(iuid){
|
|
selectedInst=iuid;
|
|
document.querySelectorAll('[data-iuid]').forEach(e=>e.classList.toggle('active',e.dataset.iuid===iuid));
|
|
document.querySelectorAll('#ops-list .op-item').forEach(e=>{
|
|
if(e.id!=='op-create') e.classList.remove('disabled');
|
|
});
|
|
document.querySelectorAll('#op-create').forEach(e=>e.classList.add('disabled'));
|
|
}
|
|
|
|
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');
|
|
|
|
const displayName='autotest-'+svcId+'-'+Date.now().toString(36);
|
|
form.innerHTML='<div class="param-row"><label class="req">displayName</label><input type="text" id="param-displayname" value="'+displayName+'"></div>'
|
|
+ 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}" data-type="${p.dataType}">${vl.map(v=>`<option value="${v}" ${v==dfl?'selected':''}>${v}</option>`).join('')}</select>`;
|
|
}else if(p.dataType==='boolean'){
|
|
input=`<select name="p_${p.svcOperationCfsParamId}" data-type="boolean"><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=>{
|
|
let v=el.value;
|
|
const dt=el.dataset.type||'';
|
|
if(dt==='array'||dt.startsWith('array')) v=JSON.stringify([v]);
|
|
if(dt==='map'||dt==='map-fixed') v=v||'{}';
|
|
params[el.name.replace('p_','')]=v;
|
|
});
|
|
|
|
let instUid=selectedInst||'';
|
|
if(selectedOp.opName==='create') instUid='';
|
|
|
|
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:document.getElementById('param-displayname')?.value||('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> |