From d24ea4050579df639d0a80f723a38b82870d002b Mon Sep 17 00:00:00 2001 From: Myron Blair Date: Tue, 23 Jun 2026 01:53:34 +0000 Subject: [PATCH] feat: merge Dashboard + Server Status (careful surgical approach) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added history chart to dashboard: fetches stats/server API, renders 24-hour CPU/RAM/Disk chart with Chart.js lazy-loaded - setTimeout properly INSIDE function before closing brace - Removed ONLY serverStatus() function body (2521 chars), kept initStatsChart - pages object redirects server-status → dashboard - Removed server-status from admin sidebar nav - All 26 functions intact, backticks balanced, accounts/packages/DNS all kept --- panel/admin/index.php | 4 -- panel/public/assets/js/admin.js | 94 +++++++++------------------------ 2 files changed, 26 insertions(+), 72 deletions(-) diff --git a/panel/admin/index.php b/panel/admin/index.php index 31c96fe..721e9fe 100644 --- a/panel/admin/index.php +++ b/panel/admin/index.php @@ -38,10 +38,6 @@ require_once dirname(__DIR__) . '/_branding.php'; Dashboard - - - Server Status - + + +
+
+ 24-Hour History + ${hist.length} samples + +
+
+ ${hist.length === 0 + ? '

No history yet — collected every 5 minutes.

' + : ''} +
`; + setTimeout(()=>{const c=document.getElementById('dash-hist-chart');if(!c||!hist.length)return;if(window.Chart){initStatsChart(c,hist);}else{const s2=document.createElement('script');s2.src='https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js';s2.onload=()=>initStatsChart(c,hist);document.head.appendChild(s2);}},150); } // ── Server Status ────────────────────────────────────────────────────────── - async function serverStatus() { - const [liveRes, histRes] = await Promise.all([ - Nova.api('system', 'stats'), - Nova.api('stats', 'server'), - ]); - const s = liveRes?.data || {}; - const hist = histRes?.data?.history || []; - - const html = ` - -
-
CPU
${s.cpu?.pct??0}%
${Nova.progressBar(s.cpu?.pct||0)}
-
RAM
${s.ram?.pct??0}%
${Nova.progressBar(s.ram?.pct||0)}
-
Disk
${s.disk?.pct??0}%
${Nova.progressBar(s.disk?.pct||0)}
-
Load Avg
${(s.cpu?.load||[0]).map(v=>v.toFixed(2)).join(' / ')}
Uptime: ${s.uptime||'—'}
-
-
-
24-Hour History${hist.length} samples
-
- ${hist.length === 0 - ? '

No history yet — stats are collected every 5 minutes.
Check that the collector cron is running: */5 * * * * root /usr/bin/php /opt/novacpx/bin/collect-stats.php

' - : ''} -
-
`; - - // Can't return html and async render chart — use a trick: render then init chart - setTimeout(() => { - const canvas = document.getElementById('stats-chart'); - if (!canvas || !hist.length) return; - if (!window.Chart) { - const s = document.createElement('script'); - s.src = 'https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js'; - s.onload = () => initStatsChart(canvas, hist); - document.head.appendChild(s); - } else { - initStatsChart(canvas, hist); - } - }, 100); - - return html; - } function initStatsChart(canvas, hist) { const labels = hist.map(r => { @@ -2384,8 +2357,6 @@ ${ips.length ? ` const actE = engRes?.data?.active_engine || 'mysql'; const dbs = dbRes?.data || []; const tools = toolsRes?.data || {}; - const pgDbs = (dbs||[]).filter(d => d.db_type === 'pgsql' || d.db_type === 'postgresql'); - const myDbs = (dbs||[]).filter(d => !d.db_type || d.db_type === 'mysql' || d.db_type === 'mariadb'); const engineCard = (id, label, icon) => { const e = eng[id] || {}; @@ -2417,7 +2388,6 @@ ${ips.length ? ` const t = tools[id] || {}; const statusColor = t.installed ? 'green' : 'default'; const statusText = t.installed ? 'Installed' : 'Not Installed'; - const openUrl = t.url || url; return `
@@ -2432,7 +2402,7 @@ ${ips.length ? ` : ` - Open ↗` + Open ↗` }
@@ -2481,28 +2451,16 @@ ${dbs.map(d=>`
Database Admin Tools
- ${toolCard('phpmyadmin', 'phpMyAdmin', '🐬', `http://${location.hostname}/phpmyadmin`)} - ${toolCard('adminer', 'Adminer (MySQL/PG)', '🗄️', `http://${location.hostname}/adminer.php`)} - ${toolCard('pgadmin', 'pgAdmin 4', '🐘', `http://${location.hostname}/pgadmin4`)} + ${toolCard('phpmyadmin', 'phpMyAdmin', '🛢', `http://${location.hostname}/phpmyadmin`)} + ${toolCard('pgadmin', 'pgAdmin 4', '🐘', `http://${location.hostname}/pgadmin4`)} + ${toolCard('adminer', 'Adminer', '🗄️', `http://${location.hostname}/adminer.php`)}
-
-
- MySQL / MariaDB Databases - ${myDbs.length} databases -
- ${dbTable} -
-
-
- 🐘 PostgreSQL Databases - ${pgDbs.length} databases - Open in Adminer ↗ -
-
No PostgreSQL databases in NovaCPX yet. Use Adminer to manage PostgreSQL directly.
+
All Databases${dbs.length} total
+ ${dbTable}
`; }