botui/ui/suite/monitoring/services.html

766 lines
22 KiB
HTML
Raw Normal View History

2025-12-06 11:09:12 -03:00
<div class="services-container">
<!-- Services Header -->
<div class="services-header">
<div class="header-stats"
hx-get="/api/services/summary"
hx-trigger="load, every 10s"
hx-swap="innerHTML">
<div class="stat-item running">
<span class="stat-number">--</span>
<span class="stat-label">Running</span>
</div>
<div class="stat-item warning">
<span class="stat-number">--</span>
<span class="stat-label">Warning</span>
</div>
<div class="stat-item stopped">
<span class="stat-number">--</span>
<span class="stat-label">Stopped</span>
</div>
<div class="stat-item total">
<span class="stat-number">--</span>
<span class="stat-label">Total</span>
</div>
</div>
<div class="header-actions">
<div class="search-box">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
<input type="text"
id="service-search"
placeholder="Search services..."
onkeyup="filterServices(this.value)">
</div>
<select id="status-filter" onchange="filterByStatus(this.value)">
<option value="all">All Status</option>
<option value="running">Running</option>
<option value="warning">Warning</option>
<option value="stopped">Stopped</option>
</select>
<button class="action-btn" onclick="restartAllServices()" title="Restart All">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="23 4 23 10 17 10"></polyline>
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"></path>
</svg>
Restart All
</button>
</div>
</div>
<!-- Services Grid -->
<div class="services-grid" id="services-grid"
hx-get="/api/services/status"
hx-trigger="load, every 10s"
hx-swap="innerHTML">
<!-- Loading placeholder -->
<div class="service-card skeleton">
<div class="skeleton-line"></div>
<div class="skeleton-line short"></div>
</div>
<div class="service-card skeleton">
<div class="skeleton-line"></div>
<div class="skeleton-line short"></div>
</div>
<div class="service-card skeleton">
<div class="skeleton-line"></div>
<div class="skeleton-line short"></div>
</div>
<div class="service-card skeleton">
<div class="skeleton-line"></div>
<div class="skeleton-line short"></div>
</div>
</div>
<!-- Service Detail Panel (slides in from right) -->
<div class="service-detail-panel" id="service-detail-panel">
<div class="panel-header">
<h3 id="detail-service-name">Service Details</h3>
<button class="close-btn" onclick="closeServiceDetail()">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
</svg>
</button>
</div>
<div class="panel-content" id="service-detail-content">
<!-- Loaded via HTMX -->
</div>
</div>
</div>
<!-- Service Card Template (for reference - rendered by server) -->
<template id="service-card-template">
<div class="service-card" data-status="running" data-service="service-name">
<div class="card-header">
<div class="service-icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="2" y="2" width="20" height="8" rx="2" ry="2"></rect>
<rect x="2" y="14" width="20" height="8" rx="2" ry="2"></rect>
<line x1="6" y1="6" x2="6.01" y2="6"></line>
<line x1="6" y1="18" x2="6.01" y2="18"></line>
</svg>
</div>
<div class="status-badge running">
<span class="status-dot"></span>
<span class="status-text">Running</span>
</div>
</div>
<div class="card-body">
<h4 class="service-name">Service Name</h4>
<p class="service-description">Service description goes here</p>
<div class="service-meta">
<span class="meta-item">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"></circle>
<polyline points="12 6 12 12 16 14"></polyline>
</svg>
Uptime: 24d 5h
</span>
<span class="meta-item">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="4" y="4" width="16" height="16" rx="2"></rect>
<rect x="9" y="9" width="6" height="6"></rect>
</svg>
CPU: 12%
</span>
<span class="meta-item">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="2" y="6" width="20" height="12" rx="2"></rect>
</svg>
Mem: 256MB
</span>
</div>
</div>
<div class="card-actions">
<button class="card-btn" onclick="viewServiceDetails('service-id')" title="Details">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="16" x2="12" y2="12"></line>
<line x1="12" y1="8" x2="12.01" y2="8"></line>
</svg>
</button>
<button class="card-btn" onclick="restartService('service-id')" title="Restart">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="23 4 23 10 17 10"></polyline>
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"></path>
</svg>
</button>
<button class="card-btn" onclick="stopService('service-id')" title="Stop">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="6" y="4" width="4" height="16"></rect>
<rect x="14" y="4" width="4" height="16"></rect>
</svg>
</button>
<button class="card-btn" onclick="viewServiceLogs('service-id')" title="Logs">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
<polyline points="14 2 14 8 20 8"></polyline>
</svg>
</button>
</div>
</div>
</template>
<style>
.services-container {
position: relative;
}
/* Header */
.services-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 1.5rem;
flex-wrap: wrap;
gap: 1rem;
}
.header-stats {
display: flex;
gap: 1.5rem;
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
padding: 0.75rem 1.25rem;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 8px;
min-width: 80px;
}
.stat-item .stat-number {
font-size: 1.5rem;
font-weight: 700;
font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
}
.stat-item .stat-label {
font-size: 0.75rem;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
}
.stat-item.running .stat-number { color: var(--success); }
.stat-item.warning .stat-number { color: var(--warning); }
.stat-item.stopped .stat-number { color: var(--error); }
.stat-item.total .stat-number { color: var(--primary); }
.header-actions {
display: flex;
align-items: center;
gap: 0.75rem;
}
.search-box {
display: flex;
align-items: center;
gap: 0.5rem;
background: var(--surface);
border: 1px solid var(--border);
border-radius: 6px;
padding: 0.5rem 0.75rem;
}
.search-box svg {
color: var(--text-secondary);
flex-shrink: 0;
}
.search-box input {
background: transparent;
border: none;
color: var(--text);
font-size: 0.875rem;
width: 180px;
outline: none;
}
.search-box input::placeholder {
color: var(--text-secondary);
}
.header-actions select {
background: var(--surface);
border: 1px solid var(--border);
color: var(--text);
padding: 0.5rem 0.75rem;
border-radius: 6px;
font-size: 0.875rem;
cursor: pointer;
}
.header-actions select:focus {
outline: none;
border-color: var(--primary);
}
.action-btn {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.5rem 1rem;
background: var(--primary);
color: white;
border: none;
border-radius: 6px;
font-size: 0.875rem;
font-weight: 500;
cursor: pointer;
transition: background 0.2s ease;
}
.action-btn:hover {
background: var(--primary-hover);
}
/* Services Grid */
.services-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 1rem;
}
.service-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 12px;
overflow: hidden;
transition: all 0.2s ease;
}
.service-card:hover {
border-color: var(--primary);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.service-card.hidden {
display: none;
}
.service-card .card-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem;
background: var(--bg);
border-bottom: 1px solid var(--border);
}
.service-icon {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
background: var(--primary-light);
border-radius: 8px;
color: var(--primary);
}
.status-badge {
display: flex;
align-items: center;
gap: 0.375rem;
padding: 0.25rem 0.625rem;
border-radius: 20px;
font-size: 0.75rem;
font-weight: 500;
}
.status-badge.running {
background: rgba(34, 197, 94, 0.1);
color: var(--success);
}
.status-badge.warning {
background: rgba(245, 158, 11, 0.1);
color: var(--warning);
}
.status-badge.stopped {
background: rgba(239, 68, 68, 0.1);
color: var(--error);
}
.status-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
}
.status-badge.running .status-dot {
animation: pulse 2s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.card-body {
padding: 1rem;
}
.service-name {
font-size: 1rem;
font-weight: 600;
color: var(--text);
margin-bottom: 0.25rem;
}
.service-description {
font-size: 0.8125rem;
color: var(--text-secondary);
margin-bottom: 0.75rem;
line-height: 1.4;
}
.service-meta {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
}
.meta-item {
display: flex;
align-items: center;
gap: 0.25rem;
font-size: 0.75rem;
color: var(--text-secondary);
}
.meta-item svg {
color: var(--primary);
}
.card-actions {
display: flex;
border-top: 1px solid var(--border);
}
.card-btn {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 0.75rem;
background: transparent;
border: none;
color: var(--text-secondary);
cursor: pointer;
transition: all 0.2s ease;
}
.card-btn:hover {
background: var(--surface-hover);
color: var(--primary);
}
.card-btn:not(:last-child) {
border-right: 1px solid var(--border);
}
/* Skeleton Loading */
.service-card.skeleton {
pointer-events: none;
}
.service-card.skeleton .card-header,
.service-card.skeleton .card-body,
.service-card.skeleton .card-actions {
display: none;
}
.skeleton-line {
height: 16px;
background: linear-gradient(90deg, var(--border) 25%, var(--surface-hover) 50%, var(--border) 75%);
background-size: 200% 100%;
animation: shimmer 1.5s infinite;
border-radius: 4px;
margin: 1rem;
}
.skeleton-line.short {
width: 60%;
}
@keyframes shimmer {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
/* Detail Panel */
.service-detail-panel {
position: fixed;
top: 64px;
right: -450px;
width: 450px;
height: calc(100vh - 64px);
background: var(--surface);
border-left: 1px solid var(--border);
box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
z-index: 200;
transition: right 0.3s ease;
display: flex;
flex-direction: column;
}
.service-detail-panel.open {
right: 0;
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem 1.25rem;
border-bottom: 1px solid var(--border);
}
.panel-header h3 {
font-size: 1rem;
font-weight: 600;
color: var(--text);
}
.close-btn {
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
background: transparent;
border: none;
color: var(--text-secondary);
border-radius: 6px;
cursor: pointer;
transition: all 0.2s ease;
}
.close-btn:hover {
background: var(--surface-hover);
color: var(--text);
}
.panel-content {
flex: 1;
overflow-y: auto;
padding: 1.25rem;
}
/* Detail Content Sections */
.detail-section {
margin-bottom: 1.5rem;
}
.detail-section-title {
font-size: 0.75rem;
font-weight: 600;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 0.75rem;
}
.detail-row {
display: flex;
justify-content: space-between;
padding: 0.5rem 0;
border-bottom: 1px solid var(--border);
}
.detail-row:last-child {
border-bottom: none;
}
.detail-label {
color: var(--text-secondary);
font-size: 0.875rem;
}
.detail-value {
color: var(--text);
font-size: 0.875rem;
font-weight: 500;
font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
}
.detail-actions {
display: flex;
gap: 0.5rem;
margin-top: 1rem;
}
.detail-btn {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
padding: 0.625rem;
border-radius: 6px;
font-size: 0.875rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.detail-btn.primary {
background: var(--primary);
color: white;
border: none;
}
.detail-btn.primary:hover {
background: var(--primary-hover);
}
.detail-btn.secondary {
background: transparent;
color: var(--text);
border: 1px solid var(--border);
}
.detail-btn.secondary:hover {
background: var(--surface-hover);
border-color: var(--primary);
}
.detail-btn.danger {
background: transparent;
color: var(--error);
border: 1px solid var(--error);
}
.detail-btn.danger:hover {
background: rgba(239, 68, 68, 0.1);
}
/* Responsive */
@media (max-width: 768px) {
.services-header {
flex-direction: column;
align-items: stretch;
}
.header-stats {
justify-content: space-between;
}
.stat-item {
flex: 1;
min-width: auto;
padding: 0.5rem;
}
.stat-item .stat-number {
font-size: 1.25rem;
}
.header-actions {
flex-wrap: wrap;
}
.search-box {
flex: 1;
min-width: 150px;
}
.search-box input {
width: 100%;
}
.services-grid {
grid-template-columns: 1fr;
}
.service-detail-panel {
width: 100%;
right: -100%;
}
}
</style>
<script>
function filterServices(query) {
const cards = document.querySelectorAll('.service-card:not(.skeleton)');
const lowerQuery = query.toLowerCase();
cards.forEach(card => {
const name = card.dataset.service?.toLowerCase() || '';
const text = card.textContent.toLowerCase();
const matches = name.includes(lowerQuery) || text.includes(lowerQuery);
card.classList.toggle('hidden', !matches);
});
}
function filterByStatus(status) {
const cards = document.querySelectorAll('.service-card:not(.skeleton)');
cards.forEach(card => {
if (status === 'all') {
card.classList.remove('hidden');
} else {
const cardStatus = card.dataset.status;
card.classList.toggle('hidden', cardStatus !== status);
}
});
}
function viewServiceDetails(serviceId) {
const panel = document.getElementById('service-detail-panel');
const content = document.getElementById('service-detail-content');
// Load service details via HTMX
htmx.ajax('GET', `/api/services/${serviceId}/details`, {
target: content,
swap: 'innerHTML'
});
document.getElementById('detail-service-name').textContent = serviceId;
panel.classList.add('open');
}
function closeServiceDetail() {
document.getElementById('service-detail-panel').classList.remove('open');
}
function restartService(serviceId) {
if (confirm(`Are you sure you want to restart ${serviceId}?`)) {
htmx.ajax('POST', `/api/services/${serviceId}/restart`, {
swap: 'none'
}).then(() => {
htmx.trigger('#services-grid', 'refresh');
});
}
}
function stopService(serviceId) {
if (confirm(`Are you sure you want to stop ${serviceId}?`)) {
htmx.ajax('POST', `/api/services/${serviceId}/stop`, {
swap: 'none'
}).then(() => {
htmx.trigger('#services-grid', 'refresh');
});
}
}
function startService(serviceId) {
htmx.ajax('POST', `/api/services/${serviceId}/start`, {
swap: 'none'
}).then(() => {
htmx.trigger('#services-grid', 'refresh');
});
}
function viewServiceLogs(serviceId) {
// Navigate to logs with service filter
const logsLink = document.querySelector('.nav-item[href="#logs"]');
if (logsLink) {
logsLink.click();
setTimeout(() => {
const serviceFilter = document.getElementById('service-filter');
if (serviceFilter) {
serviceFilter.value = serviceId;
serviceFilter.dispatchEvent(new Event('change'));
}
}, 300);
}
}
function restartAllServices() {
if (confirm('Are you sure you want to restart all services? This may cause temporary downtime.')) {
htmx.ajax('POST', '/api/services/restart-all', {
swap: 'none'
}).then(() => {
htmx.trigger('#services-grid', 'refresh');
});
}
}
// Close panel on escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeServiceDetail();
}
});
// Close panel when clicking outside
document.addEventListener('click', function(e) {
const panel = document.getElementById('service-detail-panel');
if (panel.classList.contains('open') &&
!panel.contains(e.target) &&
!e.target.closest('.card-btn')) {
closeServiceDetail();
}
});
</script>