231 lines
11 KiB
HTML
231 lines
11 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); }
|
|
.inst-item { cursor:pointer; display:flex; align-items:center; gap:6px; padding:4px 8px; font-size:12px; border-radius:4px; }
|
|
.inst-item:hover, .inst-item.active { background:var(--brand-grey-light); }
|
|
.inst-ops { display:none; margin-left:16px; }
|
|
.inst-ops.open { display:block; }
|
|
.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;">
|
|
<div class="svc-item active" onclick="selectService(1)">1. Болванка</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Инстансы + Операции + Параметры -->
|
|
<div class="col-main">
|
|
<div class="card">
|
|
<div class="card-header" style="font-size:12px;">Инстансы</div>
|
|
<div class="card-body" style="padding:4px;" id="inst-list">
|
|
<span style="color:var(--muted);font-size:11px;">Загрузка...</span>
|
|
</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 svcInstances=[], selectedInst=null, selectedOp=null;
|
|
const SVC_ID=1;
|
|
|
|
// Загрузка при старте
|
|
selectService(SVC_ID);
|
|
|
|
async function selectService(svcId){
|
|
selectedInst=null; selectedOp=null;
|
|
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||[];
|
|
|
|
let html='';
|
|
svcInstances.forEach(i=>{
|
|
const sc=i.explainedStatus==='running'?'badge-success':'';
|
|
html+=`<div class="inst-item" onclick="toggleInstance('${i.instanceUid}')" data-iuid="${i.instanceUid}">
|
|
<span style="flex:1;">${i.displayName}</span>
|
|
<span class="badge ${sc}" style="font-size:9px;">${i.explainedStatus||'?'}</span>
|
|
</div>`;
|
|
html+=`<div class="inst-ops" id="ops-${i.instanceUid}"></div>`;
|
|
});
|
|
// Кнопка создать
|
|
html+=`<div class="inst-item" style="margin-top:8px;border-top:1px solid var(--brand-gray);padding-top:8px;" onclick="startCreate()">
|
|
<span style="flex:1;color:var(--brand-primary);">+ Создать новый инстанс</span>
|
|
</div>`;
|
|
document.getElementById('inst-list').innerHTML=html;
|
|
}
|
|
|
|
async function toggleInstance(iuid){
|
|
selectedInst=iuid;
|
|
document.querySelectorAll('[data-iuid]').forEach(e=>e.classList.toggle('active',e.dataset.iuid===iuid));
|
|
|
|
const opsEl=document.getElementById('ops-'+iuid);
|
|
if(opsEl.classList.contains('open')){
|
|
opsEl.classList.remove('open');
|
|
document.getElementById('params-card').style.display='none';
|
|
return;
|
|
}
|
|
// Закрыть все
|
|
document.querySelectorAll('.inst-ops').forEach(e=>e.classList.remove('open'));
|
|
|
|
const r=await fetch('/api/operations/'+SVC_ID);
|
|
const d=await r.json();
|
|
const ops=d.operations.filter(o=>o.operation!=='reconcile'&&o.operation!=='create');
|
|
opsEl.innerHTML=ops.map(o=>
|
|
`<div class="inst-item" style="margin-left:0;">
|
|
<span style="flex:1;">${o.operation}</span>
|
|
<button class="btn btn-primary btn-sm" onclick="startOperation(${o.svcOperationId},'${o.operation}')">Тест</button>
|
|
</div>`
|
|
).join('');
|
|
opsEl.classList.add('open');
|
|
}
|
|
|
|
function startCreate(){
|
|
selectedInst=null;
|
|
document.querySelectorAll('[data-iuid]').forEach(e=>e.classList.remove('active'));
|
|
document.querySelectorAll('.inst-ops').forEach(e=>e.classList.remove('open'));
|
|
loadParams(18,'create'); // svcOperationId for create = 18
|
|
}
|
|
|
|
function startOperation(opId,opName){
|
|
loadParams(opId,opName);
|
|
}
|
|
|
|
async function loadParams(opId,opName){
|
|
selectedOp={opId,opName,svcId:SVC_ID};
|
|
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=opName==='create'?('autotest-1-'+Date.now().toString(36)):'';
|
|
form.innerHTML=(opName==='create'?`<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;
|
|
});
|
|
|
|
try{
|
|
const r=await fetch('/api/test',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({
|
|
serviceId:SVC_ID,
|
|
operation:selectedOp.opName,
|
|
svcOperationId:selectedOp.opId,
|
|
params,
|
|
instanceUid:selectedInst||'',
|
|
displayName:document.getElementById('param-displayname')?.value||('autotest-1')
|
|
})});
|
|
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'){await selectService(SVC_ID);}
|
|
}catch(e){
|
|
document.getElementById('test-status').textContent=' Ошибка: '+e.message;
|
|
}
|
|
btn.disabled=false;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |