Spaces:
Sleeping
Sleeping
File size: 15,498 Bytes
a99d4dc 4a21e7e a99d4dc 85ff768 a99d4dc 03f1ed6 a99d4dc 999a034 a99d4dc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Users - Telegram Analytics</title>
<link rel="stylesheet" href="/static/css/style.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<button class="mobile-menu-btn" onclick="toggleMobileMenu()">☰</button>
<div class="sidebar-overlay" onclick="toggleMobileMenu()"></div>
<!-- Sidebar -->
<nav class="sidebar">
<div class="logo">
<span class="logo-icon">π</span>
<span class="logo-text">TG Analytics</span>
</div>
<ul class="nav-menu">
<li class="nav-item">
<a href="/" class="nav-link">
<span class="icon">π</span>
<span>Overview</span>
</a>
</li>
<li class="nav-item active">
<a href="/users" class="nav-link">
<span class="icon">π₯</span>
<span>Users</span>
</a>
</li>
<li class="nav-item">
<a href="/chat" class="nav-link">
<span class="icon">π¬</span>
<span>Chat</span>
</a>
</li>
<li class="nav-item">
<a href="/search" class="nav-link">
<span class="icon">π</span>
<span>Search</span>
</a>
</li>
<li class="nav-item">
<a href="/ai-search" class="nav-link">
<span class="icon">π€</span>
<span>AI Search</span>
</a>
</li>
<li class="nav-item">
<a href="/moderation" class="nav-link">
<span class="icon">π‘οΈ</span>
<span>Moderation</span>
</a>
</li>
<li class="nav-item">
<a href="/settings" class="nav-link">
<span class="icon">βοΈ</span>
<span>Settings</span>
</a>
</li>
<li class="nav-item">
<a href="/maintenance" class="nav-link">
<span class="icon">π</span>
<span>Maintenance</span>
</a>
</li>
</ul>
<div class="sidebar-footer">
<div class="export-buttons">
<button onclick="exportUsers()" class="btn btn-sm">π₯ Export Users</button>
</div>
</div>
</nav>
<!-- Main Content -->
<main class="main-content">
<!-- Header -->
<header class="header">
<h1>User Leaderboard</h1>
<div class="header-controls">
<select id="timeframe" class="select" onchange="loadUsers()">
<option value="today">Today</option>
<option value="yesterday">Yesterday</option>
<option value="week">This Week</option>
<option value="month" selected>This Month</option>
<option value="year">This Year</option>
<option value="2years">2 Years</option>
<option value="all">All Time</option>
</select>
<button onclick="loadUsers()" class="btn btn-primary">π Refresh</button>
</div>
</header>
<!-- User Stats Summary -->
<section class="stats-grid">
<div class="stat-card">
<div class="stat-icon">π₯</div>
<div class="stat-content">
<div class="stat-value" id="total-users">-</div>
<div class="stat-label">Total Members</div>
</div>
</div>
<div class="stat-card">
<div class="stat-icon">π¬</div>
<div class="stat-content">
<div class="stat-value" id="total-active">-</div>
<div class="stat-label">Active Users</div>
</div>
</div>
<div class="stat-card">
<div class="stat-icon">π</div>
<div class="stat-content">
<div class="stat-value" id="top-user">-</div>
<div class="stat-label">Top User</div>
</div>
</div>
<div class="stat-card">
<div class="stat-icon">π</div>
<div class="stat-content">
<div class="stat-value" id="avg-messages">-</div>
<div class="stat-label">Avg Messages/User</div>
</div>
</div>
</section>
<!-- Users Table -->
<section class="chart-card full-width">
<div class="chart-header">
<h3>All Users</h3>
<div style="display: flex; gap: 1rem; align-items: center;">
<input type="search" id="user-search" placeholder="Search users..."
style="width: 200px;" onkeyup="filterUsers()">
<span id="showing-count" style="color: var(--text-muted); font-size: 0.875rem;"></span>
</div>
</div>
<div style="overflow-x: auto;">
<table class="users-table">
<thead>
<tr>
<th style="width: 60px;">Rank</th>
<th>User</th>
<th style="width: 80px;">Role</th>
<th style="width: 120px;">Messages</th>
<th style="width: 100px;">Share</th>
<th style="width: 100px;">Links</th>
<th style="width: 100px;">Media</th>
<th style="width: 100px;">Active Days</th>
<th style="width: 100px;">Daily Avg</th>
</tr>
</thead>
<tbody id="users-table-body">
<tr>
<td colspan="8" class="loading">
<div class="spinner"></div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Pagination -->
<div class="pagination" id="pagination"></div>
</section>
</main>
<script src="/static/js/dashboard.js"></script>
<script>
// State
let allUsers = [];
let currentPage = 1;
const pageSize = 20;
// Initialize
document.addEventListener('DOMContentLoaded', () => {
loadUsers();
});
async function loadUsers() {
const timeframe = document.getElementById('timeframe').value;
const tbody = document.getElementById('users-table-body');
tbody.innerHTML = '<tr><td colspan="9" class="loading"><div class="spinner"></div></td></tr>';
try {
const response = await fetch(`/api/users?timeframe=${timeframe}&limit=500&include_inactive=1`);
const data = await response.json();
allUsers = data.users;
// Update summary stats
document.getElementById('total-users').textContent = formatNumber(data.total);
document.getElementById('total-active').textContent = formatNumber(data.total_active);
if (allUsers.length > 0) {
const activeUsers = allUsers.filter(u => u.messages > 0);
if (activeUsers.length > 0) {
document.getElementById('top-user').textContent = activeUsers[0].name;
const totalMessages = activeUsers.reduce((sum, u) => sum + u.messages, 0);
document.getElementById('avg-messages').textContent =
formatNumber(Math.round(totalMessages / activeUsers.length));
}
}
currentPage = 1;
renderUsers();
} catch (error) {
tbody.innerHTML = '<tr><td colspan="9" class="empty-state">Error loading users</td></tr>';
}
}
function filterUsers() {
currentPage = 1;
renderUsers();
}
function renderUsers() {
const search = document.getElementById('user-search').value.toLowerCase();
const filtered = allUsers.filter(u =>
u.name.toLowerCase().includes(search) ||
u.user_id.toLowerCase().includes(search)
);
const start = (currentPage - 1) * pageSize;
const end = start + pageSize;
const pageUsers = filtered.slice(start, end);
document.getElementById('showing-count').textContent =
`Showing ${start + 1}-${Math.min(end, filtered.length)} of ${filtered.length}`;
const tbody = document.getElementById('users-table-body');
if (pageUsers.length === 0) {
tbody.innerHTML = '<tr><td colspan="9" class="empty-state">No users found</td></tr>';
return;
}
tbody.innerHTML = pageUsers.map((user, i) => {
const rank = user.rank || '-';
const rankClass = rank === 1 ? 'gold' : rank === 2 ? 'silver' : rank === 3 ? 'bronze' : '';
const initial = user.name.charAt(0).toUpperCase();
const isInactive = user.messages === 0;
const rowStyle = isInactive ? 'opacity: 0.6;' : '';
let roleBadge = '';
if (user.role === 'creator') roleBadge = '<span style="background:#ffd700;color:#1a1a2e;padding:2px 6px;border-radius:4px;font-size:0.7rem;font-weight:600;">Creator</span>';
else if (user.role === 'admin') roleBadge = '<span style="background:#28a745;color:white;padding:2px 6px;border-radius:4px;font-size:0.7rem;font-weight:600;">Admin</span>';
else if (user.role === 'bot') roleBadge = '<span style="background:#6c757d;color:white;padding:2px 6px;border-radius:4px;font-size:0.7rem;font-weight:600;">Bot</span>';
const subtitle = user.username
? `@${escapeHtml(user.username)}`
: `ID: ${user.user_id}`;
return `
<tr onclick="window.location.href='/user/${user.user_id}'" style="cursor: pointer; ${rowStyle}">
<td><span class="list-rank ${rankClass}">${rank !== '-' ? '#' + rank : '-'}</span></td>
<td>
<div class="user-cell">
<div class="user-avatar">${initial}</div>
<div>
<div class="list-name">${escapeHtml(user.name)}</div>
<div class="list-subtitle">${subtitle}</div>
</div>
</div>
</td>
<td>${roleBadge}</td>
<td>
${isInactive ? '<span style="color: var(--text-muted);">-</span>' : `
<strong>${formatNumber(user.messages)}</strong>
<div class="progress-bar">
<div class="progress-fill" style="width: ${user.percentage}%"></div>
</div>`}
</td>
<td>${isInactive ? '-' : user.percentage + '%'}</td>
<td>${isInactive ? '-' : formatNumber(user.links)}</td>
<td>${isInactive ? '-' : formatNumber(user.media)}</td>
<td>${isInactive ? '-' : user.active_days}</td>
<td>${isInactive ? '-' : user.daily_average}</td>
</tr>
`;
}).join('');
// Render pagination
const totalPages = Math.ceil(filtered.length / pageSize);
renderPagination(totalPages);
}
function renderPagination(totalPages) {
const pagination = document.getElementById('pagination');
if (totalPages <= 1) {
pagination.innerHTML = '';
return;
}
let html = '';
// Previous button
html += `<button class="page-btn" onclick="goToPage(${currentPage - 1})"
${currentPage === 1 ? 'disabled' : ''}>«</button>`;
// Page numbers
const maxVisible = 5;
let startPage = Math.max(1, currentPage - Math.floor(maxVisible / 2));
let endPage = Math.min(totalPages, startPage + maxVisible - 1);
if (endPage - startPage < maxVisible - 1) {
startPage = Math.max(1, endPage - maxVisible + 1);
}
if (startPage > 1) {
html += `<button class="page-btn" onclick="goToPage(1)">1</button>`;
if (startPage > 2) html += `<span style="padding: 0 0.5rem;">...</span>`;
}
for (let i = startPage; i <= endPage; i++) {
html += `<button class="page-btn ${i === currentPage ? 'active' : ''}"
onclick="goToPage(${i})">${i}</button>`;
}
if (endPage < totalPages) {
if (endPage < totalPages - 1) html += `<span style="padding: 0 0.5rem;">...</span>`;
html += `<button class="page-btn" onclick="goToPage(${totalPages})">${totalPages}</button>`;
}
// Next button
html += `<button class="page-btn" onclick="goToPage(${currentPage + 1})"
${currentPage === totalPages ? 'disabled' : ''}>»</button>`;
pagination.innerHTML = html;
}
function goToPage(page) {
currentPage = page;
renderUsers();
window.scrollTo({ top: 0, behavior: 'smooth' });
}
function openUserProfile(userId) {
window.location.href = `/user/${userId}`;
}
// Export function
function exportUsers() {
const timeframe = document.getElementById('timeframe').value;
window.location.href = `/api/export/users?timeframe=${timeframe}`;
}
// Helper functions
function formatNumber(num) {
if (num >= 1000000) return (num / 1000000).toFixed(1) + 'M';
if (num >= 1000) return (num / 1000).toFixed(1) + 'K';
return num.toString();
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
</script>
</body>
</html>
|