Files
Mo-Misinformation-Counter/public/admin.html
2026-01-10 23:49:26 +00:00

288 lines
8.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin - Global Counter</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<style>
.admin-grid {
display: grid;
grid-template-columns: 1fr;
gap: 2rem;
width: 100%;
max-width: 900px;
}
@media(min-width: 768px) {
.admin-grid {
grid-template-columns: 1fr 2fr;
}
}
.stat-card {
background: white;
padding: 2rem;
border-radius: 20px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.recent-activity {
background: white;
padding: 2rem;
border-radius: 20px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
max-height: 500px;
overflow-y: auto;
}
.activity-header {
font-size: 1.2rem;
font-weight: 700;
margin-bottom: 1rem;
color: var(--text-color);
}
.log-item {
display: flex;
align-items: flex-start;
gap: 1rem;
padding: 1rem 0;
border-bottom: 1px solid #f0f0f0;
animation: fadeIn 0.3s ease;
}
.log-item:last-child {
border-bottom: none;
}
.avatar {
width: 40px;
height: 40px;
border-radius: 50%;
background: #eee;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
color: #888;
font-size: 1.2rem;
}
.log-content {
flex: 1;
}
.log-name {
font-weight: 600;
font-size: 1rem;
}
.log-time {
font-size: 0.8rem;
color: #999;
margin-left: 0.5rem;
}
.log-quote {
font-size: 0.95rem;
color: #555;
margin-top: 0.2rem;
font-style: italic;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>
</head>
<body>
<div class="app-container" style="max-width: 1000px;">
<header>
<div class="logo">🔒 Admin Dashboard</div>
<a href="/" class="admin-link">Back to Counter</a>
</header>
<main class="admin-grid">
<!-- Stats -->
<div class="stat-card">
<h1 id="admin-count">...</h1>
<p class="label">Total Clicks</p>
</div>
<!-- Chart -->
<div class="chart-container"
style="background: white; padding: 1.5rem; border-radius: 20px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); grid-column: 1 / -1;">
<canvas id="activityChart"></canvas>
</div>
<!-- Logs -->
<div class="recent-activity" style="grid-column: 1 / -1;">
<div class="activity-header">Recent Activity</div>
<div id="logs-container">
<p style="text-align: center; color: #999;">Waiting for data...</p>
</div>
</div>
</main>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
const logsContainer = document.getElementById('logs-container');
const adminCount = document.getElementById('admin-count');
let chartInstance = null;
socket.on('connect', () => {
socket.emit('join_admin');
});
socket.on('update', (data) => {
adminCount.innerText = data.count;
});
socket.on('admin_data', (data) => {
renderLogs(data.logs);
renderChart(data.stats);
});
socket.on('new_log', (log) => {
prependLog(log);
// Optionally update chart in real-time or just let it refresh on reload/reconnect
// For simplicity, we won't real-time update the chart bars individually right now
});
function renderChart(stats) {
const ctx = document.getElementById('activityChart').getContext('2d');
// Process stats for Chart.js
// Fill in missing hours for the last 24h if you wanted to be fancy, but let's just show what we have
const labels = stats.map(s => {
const date = new Date(); // roughly based on server time but local rendering
// Actually server sends %H:00 string like "14:00"
return s.hour;
});
const dataPoints = stats.map(s => s.count);
if (chartInstance) {
chartInstance.destroy();
}
chartInstance = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Clicks per Hour',
data: dataPoints,
backgroundColor: 'rgba(255, 107, 107, 0.5)',
borderColor: 'rgba(255, 107, 107, 1)',
borderWidth: 1,
borderRadius: 4
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
ticks: {
precision: 0
}
}
},
plugins: {
legend: {
display: false
},
title: {
display: true,
text: 'Activity (Last 24 Hours)',
font: {
size: 16,
family: 'Outfit'
}
}
}
}
});
}
function renderLogs(logs) {
logsContainer.innerHTML = '';
logs.forEach(log => {
logsContainer.appendChild(createLogElement(log));
});
}
function prependLog(log) {
const firstChild = logsContainer.firstChild;
const logEl = createLogElement(log);
if (logsContainer.children.length === 0 || logsContainer.innerHTML.includes('Waiting')) {
logsContainer.innerHTML = '';
logsContainer.appendChild(logEl);
} else {
logsContainer.insertBefore(logEl, logsContainer.firstChild);
}
}
function createLogElement(log) {
const div = document.createElement('div');
div.className = 'log-item';
const initial = log.name ? log.name.charAt(0).toUpperCase() : '?';
const timeAgo = new Date(log.timestamp).toLocaleTimeString();
div.innerHTML = `
<div class="avatar" style="background-color: ${stringToColor(log.name)}20; color: ${stringToColor(log.name)}">${initial}</div>
<div class="log-content">
<div>
<span class="log-name">${escapeHtml(log.name)}</span>
<span class="log-time">${timeAgo}</span>
</div>
${log.quote ? `<div class="log-quote">"${escapeHtml(log.quote)}"</div>` : ''}
</div>
`;
return div;
}
function escapeHtml(text) {
if (!text) return "";
return text
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}
function stringToColor(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
const c = (hash & 0x00FFFFFF).toString(16).toUpperCase();
return '#' + "00000".substring(0, 6 - c.length) + c;
}
</script>
</body>
</html>