|
|
|
|
@ -4,6 +4,7 @@ const canManage = root?.dataset.canManage === '1';
|
|
|
|
|
const state = {
|
|
|
|
|
csrf: window.ADMIN_CSRF_TOKEN || '', agents: [], regions: [], summary: {},
|
|
|
|
|
selected: null, busy: false, expandedRegions: new Set(), regionsInitialized: false,
|
|
|
|
|
drawerOpener: null, drawerScroll: null,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function notice(message, error = false) {
|
|
|
|
|
@ -139,6 +140,8 @@ function renderAgent(agent) {
|
|
|
|
|
const button = text('button', 'cloud-admin-host cloud-admin-agent-row', '');
|
|
|
|
|
button.type = 'button';
|
|
|
|
|
button.dataset.hostId = String(agent.host_id);
|
|
|
|
|
button.setAttribute('aria-controls', 'agent-settings-drawer');
|
|
|
|
|
button.setAttribute('aria-haspopup', 'dialog');
|
|
|
|
|
button.setAttribute('aria-label', `配置 Agent ${agent.host_name || agent.agent_id}`);
|
|
|
|
|
if (String(agent.host_id) === String(state.selected)) button.setAttribute('aria-current', 'true');
|
|
|
|
|
const heading = text('span', 'cloud-admin-host-heading', '');
|
|
|
|
|
@ -149,7 +152,13 @@ function renderAgent(agent) {
|
|
|
|
|
const metrics = text('span', 'cloud-admin-host-metrics', '');
|
|
|
|
|
metrics.append(text('span', '', `版本 ${agent.last_agent_version || '--'}`), text('span', '', `最近测试 ${lastTestText(agent)}`));
|
|
|
|
|
button.append(heading, statuses, path, metrics);
|
|
|
|
|
button.addEventListener('click', () => { state.selected = String(agent.host_id); renderList(); fill(agent); });
|
|
|
|
|
button.addEventListener('click', () => {
|
|
|
|
|
state.selected = String(agent.host_id);
|
|
|
|
|
fill(agent);
|
|
|
|
|
renderList();
|
|
|
|
|
const opener = byId('agent-settings-list').querySelector(`[data-host-id="${agent.host_id}"]`);
|
|
|
|
|
openDrawer(opener);
|
|
|
|
|
});
|
|
|
|
|
return button;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -196,10 +205,62 @@ function renderHealth(agent) {
|
|
|
|
|
for (const [label, value] of rows) { health.append(text('dt', '', label), text('dd', '', value)); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderChecklist(agent) {
|
|
|
|
|
const checklist = byId('agent-settings-checklist');
|
|
|
|
|
checklist.replaceChildren();
|
|
|
|
|
const steps = [
|
|
|
|
|
['保存连接身份', agent.secret_configured === true],
|
|
|
|
|
['更新宿主机配置并重启 Agent', agent.ready === true],
|
|
|
|
|
['完成宿主机存储注册', agent.storage_configured === true],
|
|
|
|
|
['通过健康与必要能力测试', agent.ready === true],
|
|
|
|
|
];
|
|
|
|
|
const firstIncomplete = steps.findIndex(([, done]) => !done);
|
|
|
|
|
for (const [index, [label, done]] of steps.entries()) {
|
|
|
|
|
const item = text('li', 'cloud-agent-checklist-step', '');
|
|
|
|
|
if (done) item.classList.add('is-done');
|
|
|
|
|
else if (index === firstIncomplete) item.classList.add('is-current');
|
|
|
|
|
const mark = text('span', 'cloud-agent-checklist-mark', done ? '✓' : String(index + 1));
|
|
|
|
|
item.append(mark, text('span', '', label));
|
|
|
|
|
checklist.append(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function lockDrawerScroll() {
|
|
|
|
|
state.drawerScroll = { x: window.scrollX, y: window.scrollY };
|
|
|
|
|
document.body.style.setProperty('--admin-instance-scroll-top', `${-state.drawerScroll.y}px`);
|
|
|
|
|
document.documentElement.classList.add('admin-instance-detail-open');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function finishDrawerClose() {
|
|
|
|
|
document.documentElement.classList.remove('admin-instance-detail-open');
|
|
|
|
|
document.body.style.removeProperty('--admin-instance-scroll-top');
|
|
|
|
|
if (state.drawerScroll) window.scrollTo({ left: state.drawerScroll.x, top: state.drawerScroll.y, behavior: 'instant' });
|
|
|
|
|
state.drawerScroll = null;
|
|
|
|
|
if (state.drawerOpener?.isConnected) state.drawerOpener.focus({ preventScroll: true });
|
|
|
|
|
state.drawerOpener = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openDrawer(opener) {
|
|
|
|
|
const drawer = byId('agent-settings-drawer');
|
|
|
|
|
state.drawerOpener = opener || null;
|
|
|
|
|
if (drawer.open) return;
|
|
|
|
|
lockDrawerScroll();
|
|
|
|
|
window.VenixDrawerMotion.openDrawerWithMotion(drawer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function closeDrawer() {
|
|
|
|
|
const drawer = byId('agent-settings-drawer');
|
|
|
|
|
if (!drawer?.open) return;
|
|
|
|
|
void window.VenixDrawerMotion.closeDrawerWithMotion(drawer).then(closed => {
|
|
|
|
|
if (closed) finishDrawerClose();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fill(agent) {
|
|
|
|
|
byId('agent-settings-host-id').value = agent?.host_id || '';
|
|
|
|
|
byId('agent-settings-revision').value = String(agent?.revision || 0);
|
|
|
|
|
byId('agent-settings-title').textContent = agent ? `Agent 上行连接 · ${agent.host_name}` : '选择计算节点';
|
|
|
|
|
byId('agent-settings-panel-url').value = location.origin;
|
|
|
|
|
byId('agent-settings-agent-id').value = agent?.agent_id || agent?.host_id || '';
|
|
|
|
|
byId('agent-settings-secret').value = '';
|
|
|
|
|
byId('agent-settings-secret').placeholder = agent?.secret_configured ? '已配置,留空保留现有密钥' : '首次配置必须填写至少 32 位密钥';
|
|
|
|
|
@ -208,6 +269,7 @@ function fill(agent) {
|
|
|
|
|
byId('agent-settings-save').disabled = !canManage || !agent || state.busy;
|
|
|
|
|
byId('agent-settings-test').disabled = !canManage || !agent?.enabled || !agent?.secret_configured || state.busy;
|
|
|
|
|
renderHealth(agent || {});
|
|
|
|
|
renderChecklist(agent || {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function load() {
|
|
|
|
|
@ -273,6 +335,9 @@ async function testConnection() {
|
|
|
|
|
if (root) {
|
|
|
|
|
byId('agent-settings-form').addEventListener('submit', save);
|
|
|
|
|
byId('agent-settings-test').addEventListener('click', testConnection);
|
|
|
|
|
byId('agent-settings-close').addEventListener('click', closeDrawer);
|
|
|
|
|
byId('agent-settings-drawer').addEventListener('cancel', event => { event.preventDefault(); closeDrawer(); });
|
|
|
|
|
byId('agent-settings-drawer').addEventListener('click', event => { if (event.target === event.currentTarget) closeDrawer(); });
|
|
|
|
|
byId('agent-settings-search').addEventListener('input', renderList);
|
|
|
|
|
byId('agent-settings-region-filter').addEventListener('change', renderList);
|
|
|
|
|
byId('agent-settings-state-filter').addEventListener('change', renderList);
|
|
|
|
|
|