dragonflight/services/web-ui/public/containers.html

283 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<title>Containers — Dragonflight</title>
<link rel="stylesheet" href="/dist/app.css">
<style>
body { margin: 0; }
/* Page-only auto-refresh indicator (preserves original IDs + look-and-feel) */
.refresh-indicator {
display: inline-flex;
align-items: center;
gap: 6px;
font: 400 11px/1 var(--font);
color: var(--text-tertiary);
margin-right: 10px;
}
.refresh-dot {
width: 7px; height: 7px;
border-radius: 50%;
background: var(--signal-warn);
flex-shrink: 0;
}
.refresh-dot.live {
background: var(--signal-good);
animation: rd-pulse 2s ease-in-out infinite;
}
@keyframes rd-pulse { 0%,100%{opacity:.75;} 50%{opacity:1;} }
.container-name { font-weight: 500; color: var(--text-primary); }
.container-svc { font: 400 10px/1.2 var(--font-mono); color: var(--text-tertiary); margin-top: 2px; }
.container-image { font: 400 11px/1.2 var(--font-mono); color: var(--text-secondary); max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.container-ports { font: 400 10px/1.2 var(--font-mono); color: var(--text-secondary); }
.container-status-sub { font: 400 10px/1.2 var(--font); color: var(--text-tertiary); margin-top: 3px; }
.wd-list-row.container-row {
display: grid;
grid-template-columns: minmax(180px, 1.4fr) minmax(160px, 1.4fr) minmax(120px, 1fr) minmax(120px, 1fr) auto;
gap: 16px;
align-items: center;
}
.wd-list-row.container-row.header {
font: 600 10px/1 var(--font);
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--text-tertiary);
}
.empty-row {
padding: 48px 18px;
text-align: center;
color: var(--text-tertiary);
font-size: 13px;
}
</style>
</head>
<body>
<div class="wd-shell" style="display:flex;min-height:100vh;">
<nav class="wd-sidebar" aria-label="Main navigation">
<div class="wd-sidebar-header">
<img src="img/dragon-logo.png?v=1" alt="Dragonflight" style="width:18px;height:18px;">
<span class="wd-sidebar-brand">Dragonflight</span>
</div>
<div class="wd-sidebar-nav">
<a href="home.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M2 7l6-5 6 5v7a1 1 0 0 1-1 1h-3v-5H6v5H3a1 1 0 0 1-1-1z"/></svg>
Home
</a>
<a href="index.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="1" y="1" width="6" height="6" rx="1"/><rect x="9" y="1" width="6" height="6" rx="1"/><rect x="1" y="9" width="6" height="6" rx="1"/><rect x="9" y="9" width="6" height="6" rx="1"/></svg>
Library
</a>
<a href="projects.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M1 4a1 1 0 0 1 1-1h4l2 2h5a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1z"/></svg>
Projects
</a>
<a href="upload.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M8 11V3M5 6l3-3 3 3"/><path d="M2 13h12"/></svg>
Ingest
</a>
<a href="recorders.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="1" y="4" width="10" height="8" rx="1"/><path d="M11 7l4-2v6l-4-2"/></svg>
Recorders
</a>
<a href="capture.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="8" cy="8" r="3"/><circle cx="8" cy="8" r="6.5"/></svg>
Capture
</a>
<a href="jobs.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M2 4h12M2 8h8M2 12h5"/></svg>
Jobs
</a>
<a href="editor.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M2 13l1.5-3.5L11 2l3 3-7.5 7.5L3 14zM10 3l3 3"/></svg>
Editor
</a>
<div class="wd-sidebar-section">Admin</div>
<a href="users.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="6" cy="5" r="2.5"/><path d="M1 13c0-2.8 2.2-5 5-5s5 2.2 5 5"/><circle cx="12" cy="5" r="2"/><path d="M15 12c0-1.9-1.3-3.5-3-4"/></svg>
Users
</a>
<a href="tokens.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="6" cy="10" r="3.5"/><path d="M8.7 7.3L13 3M11.5 3.5l1.5 1.5M13.5 2.5l1 1"/></svg>
Tokens
</a>
<a href="containers.html" class="wd-nav-item is-active">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="1" y="5" width="14" height="4" rx="1"/><rect x="1" y="10" width="14" height="4" rx="1"/><path d="M4 7h1M4 12h1"/></svg>
Containers
</a>
<a href="cluster.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="8" cy="8" r="2"/><circle cx="2" cy="3" r="1.5"/><circle cx="14" cy="3" r="1.5"/><circle cx="2" cy="13" r="1.5"/><circle cx="14" cy="13" r="1.5"/><path d="M3.1 4.1L6.5 6.5M12.9 4.1L9.5 6.5M3.1 11.9L6.5 9.5M12.9 11.9L9.5 9.5"/></svg>
Cluster
</a>
<a href="settings.html" class="wd-nav-item">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="8" cy="8" r="2.5"/><path d="M8 1v1.5M8 13.5V15M1 8h1.5M13.5 8H15M2.9 2.9l1.1 1.1M12 12l1.1 1.1M2.9 13.1L4 12M12 4l1.1-1.1"/></svg>
Settings
</a>
</div>
<div class="wd-sidebar-footer">
<div class="wd-sidebar-user">
<div class="wd-sidebar-user-avatar" id="userAvatar">?</div>
<div class="wd-sidebar-user-info">
<div class="wd-sidebar-user-name" id="userName">&#8212;</div>
<div class="wd-sidebar-user-role" id="userRole"></div>
</div>
<button class="wd-btn wd-btn--ghost wd-btn--sm wd-btn--icon wd-sidebar-user-logout" id="logoutBtn" title="Sign out">
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" width="12" height="12"><path d="M10 8H3M6 5l-3 3 3 3"/><path d="M7 3h5a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1H7"/></svg>
</button>
</div>
</div>
</nav>
<div style="flex:1;display:flex;flex-direction:column;">
<header class="wd-topbar">
<div class="wd-topbar-left">
<nav class="wd-breadcrumb"><span class="wd-breadcrumb-crumb">Containers</span></nav>
</div>
<div class="wd-topbar-right">
<div class="refresh-indicator">
<span class="refresh-dot" id="refreshDot"></span>
<span id="refreshText">Loading&hellip;</span>
</div>
<button class="wd-btn wd-btn--ghost wd-btn--sm" id="refreshBtn">Refresh</button>
</div>
</header>
<main style="flex:1;padding:20px 20px 32px;overflow:auto;">
<div class="wd-list">
<div class="wd-list-row container-row header">
<span>Container</span>
<span>Image</span>
<span>State</span>
<span>Ports</span>
<span style="text-align:right">Actions</span>
</div>
<div id="containerBody">
<div class="empty-row">Loading&hellip;</div>
</div>
</div>
</main>
</div>
</div>
<div class="wd-toast-container" id="toastContainer" aria-live="polite"></div>
<script src="js/api.js?v=6"></script>
<script>
let containers = [];
async function loadContainers() {
try {
const r = await fetch('/api/v1/system/containers', { credentials: 'include' });
if (!r.ok) throw new Error('HTTP ' + r.status);
containers = await r.json();
renderContainers();
setDot('live', 'Live');
} catch (err) {
setDot('error', 'Error');
console.error('Container load failed:', err);
}
}
function renderContainers() {
const tbody = document.getElementById('containerBody');
if (!containers.length) {
tbody.innerHTML = '<div class="empty-row">No containers found for this compose project.</div>';
return;
}
const sorted = containers.slice().sort((a, b) => (a.service || a.name).localeCompare(b.service || b.name));
tbody.innerHTML = sorted.map(c => {
const state = (c.state || 'exited').toLowerCase();
const running = state === 'running';
const badgeMod = running ? 'wd-badge--good'
: state === 'restarting' ? 'wd-badge--warn'
: state === 'paused' ? 'wd-badge--warn'
: state === 'dead' ? 'wd-badge--bad'
: 'wd-badge--idle';
const svcLbl = c.service && c.service !== c.name
? `<div class="container-svc">${esc(c.service)}</div>` : '';
const actionBtn = running
? `<button class="wd-btn wd-btn--ghost wd-btn--sm" onclick="containerAction('${esc(c.id)}','stop',this)" title="Stop container">Stop</button>`
: `<button class="wd-btn wd-btn--ghost wd-btn--sm" onclick="containerAction('${esc(c.id)}','start',this)" title="Start container">Start</button>`;
return `
<div class="wd-list-row container-row">
<div class="wd-list-cell wd-list-cell--name">
<div class="container-name">${esc(c.name)}</div>
${svcLbl}
</div>
<div class="wd-list-cell wd-list-cell--meta"><div class="container-image" title="${esc(c.image)}">${esc(c.image)}</div></div>
<div class="wd-list-cell">
<span class="wd-badge ${badgeMod}">${esc(c.state)}</span>
<div class="container-status-sub">${esc(c.status)}</div>
</div>
<div class="wd-list-cell"><span class="container-ports">${c.ports ? esc(c.ports) : '&mdash;'}</span></div>
<div class="wd-list-cell wd-list-cell--actions" style="text-align:right">
<div style="display:flex;gap:4px;justify-content:flex-end;">
${actionBtn}
<button class="wd-btn wd-btn--ghost wd-btn--sm" onclick="containerAction('${esc(c.id)}','restart',this)" title="Restart container">Restart</button>
</div>
</div>
</div>`;
}).join('');
}
async function containerAction(id, action, btn) {
const origText = btn.textContent;
btn.disabled = true;
btn.textContent = '…';
try {
const r = await fetch(`/api/v1/system/containers/${id}/${action}`, {
method: 'POST',
credentials: 'include',
});
if (!r.ok) {
const j = await r.json().catch(() => ({}));
throw new Error(j.error || 'HTTP ' + r.status);
}
const label = action.charAt(0).toUpperCase() + action.slice(1);
toast(label + ' sent', id, 'success');
setTimeout(loadContainers, 2500);
} catch (err) {
toast('Action failed', err.message, 'error');
btn.disabled = false;
btn.textContent = origText;
}
}
function setDot(state, label) {
const dot = document.getElementById('refreshDot');
const txt = document.getElementById('refreshText');
dot.className = 'refresh-dot' + (state === 'live' ? ' live' : '');
txt.textContent = label;
}
function toast(title, msg, type) {
const el = document.createElement('div');
el.className = 'wd-toast wd-toast--' + (type || 'info');
el.innerHTML = '<div class="wd-toast-body"><div class="wd-toast-title">' + esc(title) + '</div>' +
(msg ? '<div class="wd-toast-msg">' + esc(msg) + '</div>' : '') + '</div>';
document.getElementById('toastContainer').appendChild(el);
setTimeout(() => el.remove(), 4000);
}
function esc(s) {
if (s == null) return '';
return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
}
document.addEventListener('DOMContentLoaded', () => {
loadContainers();
setInterval(loadContainers, 10000);
document.getElementById('refreshBtn').onclick = loadContainers;
});
</script>
<script src="js/auth-guard.js"></script>
</body>
</html>