Initial commit

This commit is contained in:
Sundog Garage Studio
2026-03-17 16:17:53 +02:00
commit 411038582a
15 changed files with 1895 additions and 0 deletions
+645
View File
@@ -0,0 +1,645 @@
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
:root {
/* Colors inspired by the mock-up */
--bg-main: #fbfbf9;
--sys-card-bg: #f6f5ef;
--svc-online-bg: #ffffff;
--svc-offline-bg: #f6f5ef;
--text-main: #111827;
--text-muted: #6b7280;
--text-light: #9ca3af;
--red-main: #f05252;
--red-hover: #e02424;
--green: #10b981;
--green-bg: #ecfdf5;
--red: #ef4444;
--red-bg: #fef2f2;
--yellow: #f59e0b;
--border-color: #e5e7eb;
--border-card: #f3f4f6;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', system-ui, -apple-system, sans-serif;
background-color: var(--bg-main);
color: var(--text-main);
padding: 30px 40px;
min-height: 100vh;
}
.container {
max-width: 1400px;
margin: 0 auto;
}
/* ── HEADER ── */
header {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 24px;
border-bottom: 1px solid var(--border-color);
margin-bottom: 40px;
}
.header-left {
display: flex;
align-items: center;
gap: 16px;
}
.logo-dot {
width: 16px;
height: 16px;
background-color: #ff9fb2;
border-radius: 50%;
}
h1 {
font-size: 1.5rem;
font-weight: 600;
color: #8c8c8c;
}
.header-right {
display: flex;
align-items: center;
gap: 16px;
font-size: 0.9rem;
color: var(--text-muted);
}
.indicator-group {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 4px 12px;
border-radius: 99px;
font-weight: 500;
}
.ws-live {
color: var(--green);
border: 1px solid var(--green);
background: var(--green-bg);
}
.ws-offline {
color: var(--yellow);
border: 1px solid var(--yellow);
}
.ws-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background-color: currentColor;
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.4;
}
}
.refresh-btn {
background: transparent;
border: 1px solid var(--border-color);
color: var(--text-muted);
padding: 6px 14px;
border-radius: 8px;
cursor: pointer;
font-weight: 500;
transition: all 0.2s;
}
.refresh-btn:hover:not(:disabled) {
background: #f3f4f6;
color: var(--text-main);
}
/* ── SECTIONS ── */
.section {
margin-bottom: 48px;
}
.section-title {
font-size: 0.85rem;
font-weight: 700;
color: var(--text-muted);
letter-spacing: 0.08em;
margin-bottom: 20px;
}
/* ── SYSTEM STATUS ── */
.system-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 20px;
}
.stat-card {
background-color: var(--sys-card-bg);
padding: 24px;
border-radius: 16px;
border: 1px solid transparent;
}
.stat-label {
font-size: 0.95rem;
color: var(--text-main);
margin-bottom: 12px;
font-weight: 500;
}
.stat-value {
font-size: 2.2rem;
font-weight: 600;
color: var(--text-main);
margin-bottom: 16px;
}
.progress-bar {
width: 100%;
height: 4px;
background: #e5e5e5;
border-radius: 2px;
margin-bottom: 12px;
overflow: hidden;
}
.progress-fill {
height: 100%;
border-radius: 2px;
transition: width 0.5s ease;
}
.progress-fill {
background-color: var(--text-main);
}
.progress-fill.green {
background-color: var(--green);
}
.progress-fill.red {
background-color: var(--red);
}
.stat-detail {
font-size: 0.85rem;
color: var(--text-muted);
}
.stat-status {
font-size: 0.9rem;
font-weight: 500;
margin-top: 24px;
}
.status-ok {
color: #d97706;
}
/* Warning color from mockup for "Some services offline" */
.status-warn {
color: var(--yellow);
}
/* ── SERVICES ── */
.services-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
gap: 24px;
}
.service-card {
background-color: var(--svc-online-bg);
border-radius: 20px;
padding: 28px;
border: 1px solid var(--border-card);
display: flex;
flex-direction: column;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
}
.card-offline {
background-color: var(--svc-offline-bg);
border: 1px solid var(--border-color);
box-shadow: none;
}
.service-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.service-name {
display: flex;
align-items: center;
gap: 12px;
font-size: 1.4rem;
font-weight: 600;
color: var(--text-main);
}
.status-badge {
padding: 4px 12px;
border-radius: 99px;
font-size: 0.8rem;
font-weight: 500;
}
.status-online {
color: var(--green);
border: 1px solid var(--green);
background-color: var(--green-bg);
}
.status-offline {
color: var(--red);
border: 1px solid var(--red);
background-color: var(--red-bg);
}
.service-description {
color: var(--text-muted);
font-size: 0.95rem;
line-height: 1.5;
margin-bottom: 16px;
min-height: 44px;
/* Align cards if description differs slightly */
}
.service-url {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
font-size: 0.85rem;
color: var(--text-light);
margin-bottom: 24px;
letter-spacing: 0.05em;
}
.service-metrics {
background-color: var(--sys-card-bg);
border-radius: 12px;
padding: 16px 20px;
display: flex;
justify-content: space-between;
margin-bottom: 24px;
margin-top: auto;
/* push to bottom */
}
.metric {
display: flex;
flex-direction: column;
gap: 6px;
}
.metric-label {
font-size: 0.75rem;
color: var(--text-muted);
text-transform: uppercase;
font-weight: 600;
}
.metric-value {
font-size: 1.05rem;
font-weight: 700;
color: var(--text-main);
display: flex;
flex-direction: row;
align-items: baseline;
gap: 4px;
}
.metric-unit {
display: inline;
font-size: 0.8rem;
color: var(--text-muted);
}
.offline-message {
color: var(--text-muted);
font-size: 1.1rem;
text-align: center;
margin: 40px 0;
margin-top: auto;
}
/* ── ACTIONS ── */
.service-actions {
display: flex;
gap: 12px;
align-items: stretch;
}
.service-actions-center {
display: flex;
justify-content: center;
align-items: center;
}
.btn {
border-radius: 12px;
font-weight: 600;
font-size: 0.95rem;
cursor: pointer;
transition: all 0.2s;
text-align: center;
text-decoration: none;
display: inline-flex;
justify-content: center;
align-items: center;
padding: 12px 24px;
border: none;
}
.btn-primary {
background-color: var(--red-main);
color: #ffffff;
padding: 12px 32px;
/* Wider open button */
font-size: 1.1rem;
}
.btn-primary:hover {
background-color: var(--red-hover);
}
.btn-outline {
background-color: #ffffff;
border: 1px solid var(--border-color);
color: var(--text-main);
}
.btn-outline:hover {
background-color: #f9fafb;
border-color: #d1d5db;
}
.btn-icon {
background-color: #ffffff;
border: 1px solid var(--border-color);
color: var(--text-main);
width: 48px;
padding: 0;
font-size: 1.2rem;
}
.btn-icon:hover {
background-color: #f9fafb;
}
.btn-full {
padding: 14px 24px;
font-size: 1rem;
background-color: #ffffff;
border: 1px solid var(--border-color);
margin-bottom: 15px;
}
/* ── TOAST ── */
.toast {
position: fixed;
top: 24px;
right: 24px;
z-index: 1000;
padding: 16px 24px;
border-radius: 12px;
font-weight: 600;
font-size: 0.95rem;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}
.toast-success {
background-color: var(--green-bg);
color: var(--green);
border: 1px solid var(--green);
}
.toast-error {
background-color: var(--red-bg);
color: var(--red);
border: 1px solid var(--red);
}
/* ── DOCUMENTS ── */
.docs-list {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 16px;
}
.doc-item {
background-color: var(--svc-online-bg);
border: 1px solid var(--border-color);
border-radius: 12px;
padding: 16px 20px;
display: flex;
align-items: center;
gap: 14px;
cursor: pointer;
transition: all 0.2s;
}
.doc-item:hover {
border-color: #d1d5db;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
transform: translateY(-2px);
}
.doc-icon {
font-size: 1.5rem;
}
.doc-title {
font-weight: 600;
color: var(--text-main);
margin-bottom: 4px;
font-size: 0.95rem;
}
.doc-desc {
font-size: 0.8rem;
color: var(--text-muted);
}
/* ── MODAL ── */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(17, 24, 39, 0.4);
backdrop-filter: blur(4px);
z-index: 2000;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.modal-content {
background: #fff;
border-radius: 16px;
width: 100%;
max-width: 800px;
max-height: 90vh;
display: flex;
flex-direction: column;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 24px;
border-bottom: 1px solid var(--border-color);
}
.modal-header h3 {
font-size: 1.2rem;
color: var(--text-main);
font-weight: 600;
}
.modal-close {
background: transparent;
border: none;
font-size: 1.2rem;
color: var(--text-muted);
cursor: pointer;
}
.modal-close:hover {
color: var(--text-main);
}
.modal-body {
padding: 24px;
overflow-y: auto;
}
.doc-loading {
text-align: center;
padding: 40px;
color: var(--text-muted);
}
/* ── MARKDOWN BASIC STYLES ── */
.markdown-body {
font-family: inherit;
font-size: 0.95rem;
line-height: 1.6;
color: #333;
}
.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
margin-top: 1.5em;
margin-bottom: 1em;
font-weight: 600;
color: #111;
}
.markdown-body h1 {
font-size: 1.8em;
border-bottom: 1px solid #eee;
padding-bottom: 0.3em;
}
.markdown-body h2 {
font-size: 1.4em;
}
.markdown-body p,
.markdown-body ul,
.markdown-body ol {
margin-bottom: 1em;
}
.markdown-body code {
background: #f6f8fa;
padding: 0.2em 0.4em;
border-radius: 3px;
font-family: monospace;
}
.markdown-body pre {
background: #f6f8fa;
padding: 16px;
border-radius: 8px;
overflow-x: auto;
margin-bottom: 1em;
}
.markdown-body pre code {
background: transparent;
padding: 0;
}
.markdown-body blockquote {
border-left: 4px solid #dfe2e5;
padding: 0 1em;
color: #6a737d;
margin-left: 0;
}
.markdown-body table {
border-collapse: collapse;
width: 100%;
margin-bottom: 1em;
}
.markdown-body th,
.markdown-body td {
border: 1px solid #dfe2e5;
padding: 6px 13px;
}
footer {
text-align: center;
padding: 40px 0;
color: var(--text-light);
font-size: 0.85rem;
}
@media (max-width: 768px) {
.system-grid {
grid-template-columns: 1fr;
}
.services-grid {
grid-template-columns: 1fr;
}
header {
flex-direction: column;
gap: 20px;
align-items: flex-start;
}
}
+5
View File
File diff suppressed because one or more lines are too long
+193
View File
@@ -0,0 +1,193 @@
function dashboard() {
return {
services: [],
system: {
cpu: { percent: 0 },
memory: { percent: 0, used_gb: 0, total_gb: 0 },
disk: { percent: 0, used_gb: 0, total_gb: 0 },
containers: { running: 0, total: 0 },
uptime: { days: 0, seconds: 0 }
},
lastUpdate: 'Never',
loading: true,
wsConnected: false,
ws: null,
wsReconnectTimeout: null,
actionMessage: null,
actionError: false,
// ──────────────────── Documents ────────────────────
documents: [],
showDocModal: false,
docTitle: '',
docContent: '',
docLoading: false,
init() {
console.log('Initializing RedUnits Control Panel...');
this.fetchDocuments();
this.connectWebSocket();
},
// ──────────────────── WebSocket ────────────────────
connectWebSocket() {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${protocol}//${window.location.host}/ws`;
console.log(`Connecting to WebSocket: ${wsUrl}`);
this.ws = new WebSocket(wsUrl);
this.ws.onopen = () => {
console.log('WebSocket connected');
this.wsConnected = true;
if (this.wsReconnectTimeout) {
clearTimeout(this.wsReconnectTimeout);
this.wsReconnectTimeout = null;
}
};
this.ws.onmessage = (event) => {
try {
const data = JSON.parse(event.data);
if (data.type === 'update') {
this.services = data.services;
this.system = data.system;
this.loading = false;
this.updateLastUpdate();
}
} catch (e) {
console.error('Error parsing WS message:', e);
}
};
this.ws.onclose = () => {
console.warn('WebSocket disconnected. Reconnecting in 5s...');
this.wsConnected = false;
this.scheduleReconnect();
};
this.ws.onerror = (err) => {
console.error('WebSocket error:', err);
this.wsConnected = false;
this.ws.close();
};
},
scheduleReconnect() {
if (this.wsReconnectTimeout) return;
this.wsReconnectTimeout = setTimeout(() => {
this.wsReconnectTimeout = null;
this.connectWebSocket();
}, 5000);
},
// ──────────────────── Manual refresh (REST fallback) ────────────────────
async refresh() {
this.loading = true;
try {
const [svcRes, sysRes] = await Promise.all([
fetch('/api/services'),
fetch('/api/system')
]);
const svcData = await svcRes.json();
const sysData = await sysRes.json();
this.services = svcData.services;
this.system = sysData;
this.updateLastUpdate();
} catch (error) {
console.error('Error refreshing data:', error);
} finally {
this.loading = false;
}
},
// ──────────────────── Documents ────────────────────
async fetchDocuments() {
try {
const response = await fetch('/api/documents');
if (response.ok) {
const data = await response.json();
this.documents = data.documents;
}
} catch (error) {
console.error('Error fetching documents:', error);
}
},
async openDocument(doc) {
this.showDocModal = true;
this.docTitle = doc.title;
this.docContent = '';
this.docLoading = true;
try {
const res = await fetch(`/api/document/${doc.id}`);
const data = await res.json();
if (res.ok) {
this.docContent = marked.parse(data.content);
} else {
this.docContent = `<div style="color:var(--red)">Failed to load document: ${data.detail || 'Unknown error'}</div>`;
}
} catch (error) {
this.docContent = `<div style="color:var(--red)">Network error while loading document</div>`;
} finally {
this.docLoading = false;
}
},
closeDocument() {
this.showDocModal = false;
},
// ──────────────────── Container actions ────────────────────
async restartService(serviceId) {
if (!confirm(`Restart service "${serviceId}"?`)) return;
await this._serviceAction(serviceId, 'restart');
},
async stopService(serviceId) {
if (!confirm(`Stop service "${serviceId}"? It will go offline.`)) return;
await this._serviceAction(serviceId, 'stop');
},
async _serviceAction(serviceId, action) {
try {
const res = await fetch(`/api/services/${serviceId}/${action}`, { method: 'POST' });
const data = await res.json();
if (res.ok) {
this.showMessage(`${data.message}`, false);
} else {
this.showMessage(`${data.detail || data.message}`, true);
}
} catch (e) {
this.showMessage(`❌ Network error: ${e.message}`, true);
}
},
showMessage(msg, isError) {
this.actionMessage = msg;
this.actionError = isError;
setTimeout(() => { this.actionMessage = null; }, 4000);
},
// ──────────────────── Helpers ────────────────────
updateLastUpdate() {
this.lastUpdate = new Date().toLocaleTimeString('en-GB', { timeZone: 'Europe/Riga' });
},
allServicesOnline() {
if (this.services.length === 0) return false;
return this.services.every(s => s.status.online);
},
getProgressColor(percent) {
if (percent < 60) return 'green';
if (percent < 80) return 'yellow';
return 'red';
}
};
}
+69
View File
File diff suppressed because one or more lines are too long