Files
Sdk_TV_app/templates/modern_player_analysis.html

1121 lines
36 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title data-i18n="players.player_analysis">👤 Player Analysis - Camera Dashboard</title>
<link rel="stylesheet" href="/static/css/base.css">
<link rel="stylesheet" href="/static/css/navbar.css">
<link rel="stylesheet" href="/static/css/buttons.css">
<link rel="stylesheet" href="/static/css/components.css">
<link rel="stylesheet" href="/static/css/responsive.css">
<script src="/static/js/chart.min.js"></script>
<script>
// Fallback: if Chart.js fails to load, create a simple notification
if (typeof Chart === 'undefined') {
console.warn('Chart.js failed to load - charts will be unavailable');
window.Chart = {
register: () => {},
Chart: function() {
return {
update: () => {},
destroy: () => {},
data: {},
options: {}
};
}
};
}
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background: #f5f5f5;
height: 100vh;
overflow: hidden;
color: #333;
}
/* Standardized Container */
.container {
max-width: 1400px;
margin: 0 auto;
padding: 20px;
}
/* White Scrollbar for main page */
body::-webkit-scrollbar {
width: 12px;
}
body::-webkit-scrollbar-track {
background: white;
}
body::-webkit-scrollbar-thumb {
background: #e0e0e0;
border-radius: 6px;
border: 2px solid white;
}
body::-webkit-scrollbar-thumb:hover {
background: #c0c0c0;
}
/* Section */
.section {
background: white;
border-radius: 12px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
border: 1px solid #e9ecef;
}
.section-title {
color: #333;
font-size: 1.4rem;
font-weight: bold;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 2px solid #f1f3f4;
display: flex;
align-items: center;
gap: 10px;
}
/* Tab Navigation */
.tab-navigation {
display: flex;
gap: 15px;
margin-bottom: 25px;
}
.tab-btn {
flex: 1;
background: #f8f9fa;
border: 2px solid #e9ecef;
padding: 14px 24px;
cursor: pointer;
font-size: 1.05rem;
font-weight: 600;
color: #666;
border-radius: 8px;
transition: all 0.3s ease;
min-height: 50px;
}
.tab-btn.active {
background: #28a745;
border-color: #1e7e34;
color: white;
box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}
.tab-btn:hover {
background: #28a745;
border-color: #1e7e34;
color: white;
box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
transform: translateY(-2px);
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
/* Tournament Leaders Section */
.tournament-leaders {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
gap: 30px;
margin-bottom: 30px;
}
.tournament-card {
border-radius: 20px;
padding: 35px;
box-shadow:
0 12px 40px rgba(0, 0, 0, 0.15),
0 6px 20px rgba(0, 0, 0, 0.1);
border: none;
position: relative;
overflow: hidden;
transition: box-shadow 0.3s ease;
width: 100%;
margin: 0;
}
.tournament-card:hover {
box-shadow:
0 15px 45px rgba(0, 0, 0, 0.15),
0 8px 25px rgba(0, 0, 0, 0.1);
}
/* Different color themes for each tournament type */
.tournament-card[data-type="20_targets"] {
background: linear-gradient(135deg, #ff6b6b 0%, #ff8e53 100%);
}
.tournament-card[data-type="40_targets"] {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.tournament-card[data-type="4_targets"] {
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}
.tournament-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 28px;
position: relative;
z-index: 3;
}
.tournament-name {
font-size: 1.6rem;
font-weight: 800;
color: white;
text-shadow:
0 2px 4px rgba(0, 0, 0, 0.3),
0 1px 2px rgba(0, 0, 0, 0.2);
position: relative;
display: flex;
align-items: center;
gap: 12px;
}
.tournament-card[data-type="20_targets"] .tournament-name::before {
content: '⚡';
font-size: 1.8rem;
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}
.tournament-card[data-type="40_targets"] .tournament-name::before {
content: '💪';
font-size: 1.8rem;
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}
.tournament-card[data-type="4_targets"] .tournament-name::before {
content: '🎯';
font-size: 1.8rem;
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}
.tournament-date {
background: rgba(255, 255, 255, 0.25);
backdrop-filter: blur(10px);
color: white;
padding: 8px 16px;
border-radius: 25px;
font-size: 0.75rem;
font-weight: 700;
box-shadow:
0 4px 15px rgba(0, 0, 0, 0.2),
inset 0 1px 0 rgba(255, 255, 255, 0.3);
text-transform: uppercase;
letter-spacing: 0.8px;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.leaders-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 25px;
position: relative;
z-index: 3;
}
.leader-category {
background: #ffffff;
border-radius: 16px;
padding: 28px;
text-align: center;
border: 2px solid #e9ecef;
transition: box-shadow 0.3s ease;
position: relative;
overflow: hidden;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
}
.leader-category:hover {
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.1);
}
.leader-category {
border-color: #e9ecef;
}
/* Dynamic colors based on tournament type */
.tournament-card[data-type="20_targets"] .leader-category::before {
background: linear-gradient(90deg, #ff6b6b 0%, #ff8e53 100%);
}
.tournament-card[data-type="40_targets"] .leader-category::before {
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
}
.tournament-card[data-type="4_targets"] .leader-category::before {
background: linear-gradient(90deg, #11998e 0%, #38ef7d 100%);
}
.leader-category::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4px;
border-radius: 16px 16px 0 0;
}
.category-title {
font-size: 0.8rem;
font-weight: 700;
color: #6c757d;
margin-bottom: 18px;
text-transform: uppercase;
letter-spacing: 1px;
position: relative;
}
.leader-info {
display: flex;
flex-direction: column;
gap: 10px;
}
.leader-name {
font-size: 1.1rem;
font-weight: 600;
color: #2c3e50;
margin-bottom: 8px;
line-height: 1.3;
}
.leader-score {
font-size: 1.8rem;
font-weight: 800;
padding: 12px 20px;
border-radius: 12px;
border: 2px solid;
position: relative;
}
/* Score colors based on tournament type */
.tournament-card[data-type="20_targets"] .leader-score {
border-color: #ff6b6b;
background: linear-gradient(135deg, #fff5f5 0%, #ffe8e8 100%);
color: #e53e3e;
}
.tournament-card[data-type="40_targets"] .leader-score {
border-color: #667eea;
background: linear-gradient(135deg, #f8f9ff 0%, #e8ebff 100%);
color: #667eea;
}
.tournament-card[data-type="4_targets"] .leader-score {
border-color: #11998e;
background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
color: #059669;
}
/* Yellow styling for 10s (Most 10s category) */
.leader-category:nth-child(2) .leader-score {
border-color: #fbbf24 !important;
background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%) !important;
color: #d97706 !important;
}
.leader-category:nth-child(2)::before {
background: linear-gradient(90deg, #fbbf24 0%, #f59e0b 100%) !important;
}
/* Stats Overview */
.stats-badges {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 15px;
margin-bottom: 20px;
}
.stat-badge {
background: white;
border-radius: 12px;
padding: 15px;
text-align: center;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
border: 1px solid #e9ecef;
transition: transform 0.3s ease;
}
.stat-badge:hover {
transform: translateY(-2px);
}
.stat-icon {
font-size: 1.5rem;
margin-bottom: 8px;
display: block;
}
.stat-number {
font-size: 1.5rem;
font-weight: bold;
color: #333;
margin-bottom: 5px;
}
.stat-label {
color: #666;
font-size: 0.75rem;
font-weight: 500;
}
/* ── PLAYERS SPLIT LAYOUT ── */
.players-layout {
display: flex;
gap: 8px;
height: calc(100vh - 50px);
padding: 8px 20px 20px 20px;
}
.players-left-panel {
width: 260px;
flex-shrink: 0;
display: flex;
flex-direction: column;
background: white;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
overflow: hidden;
border: 1px solid #e9ecef;
}
.players-panel-header {
display: flex; align-items: center; justify-content: space-between;
padding: 8px 12px;
background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
border-radius: 12px 12px 0 0;
flex-shrink: 0;
}
.players-panel-header-title {
font-size: 0.8rem; font-weight: 700; color: white; letter-spacing: 0.3px;
overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.players-panel-count {
font-size: 0.7rem; font-weight: 600;
background: rgba(255,255,255,0.25); color: white;
padding: 2px 7px; border-radius: 10px;
}
.players-sort-bar {
padding: 6px 8px;
border-bottom: 1px solid #e9ecef;
flex-shrink: 0;
background: #f8f9fa;
display: flex;
flex-direction: column;
gap: 5px;
}
.players-search {
width: 100%; border: 1px solid #dee2e6; border-radius: 6px;
padding: 5px 9px; font-size: 0.78rem; outline: none; background: white;
}
.players-search:focus { border-color: #28a745; }
.players-sort-btns {
display: flex; gap: 4px;
}
.psort-btn {
flex: 1;
padding: 2px 7px;
border: 2px solid #dee2e6; background: white; border-radius: 6px;
cursor: pointer; font-size: 0.6rem; font-weight: 600; color: #666;
transition: all 0.15s; white-space: nowrap; text-align: center;
}
.psort-btn.active { background: #28a745; border-color: #1e7e34; color: white; }
.psort-btn:hover:not(.active) { border-color: #28a745; color: #28a745; }
.player-tree-list {
flex: 1; overflow-y: auto; overflow-x: hidden;
}
.player-tree-list::-webkit-scrollbar { width: 5px; }
.player-tree-list::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
.player-tree-item {
display: flex; align-items: center;
padding: 8px 10px 8px 14px;
cursor: pointer; border-left: 4px solid transparent;
gap: 8px; transition: all 0.15s;
}
.player-tree-item:hover { background: #f0faf3; border-left-color: #7dcf95; }
.player-tree-item.active {
background: #28a745; border-left-color: #28a745;
font-weight: 700; color: white;
}
.player-tree-avatar {
width: 28px; height: 28px; border-radius: 50%;
background: #e9ecef; display: flex; align-items: center; justify-content: center;
font-size: 0.75rem; font-weight: 700; color: #666; flex-shrink: 0;
}
.player-tree-item.active .player-tree-avatar { background: rgba(255,255,255,0.25); color: white; }
.player-tree-info { flex: 1; min-width: 0; }
.player-tree-name { font-size: 0.82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-tree-meta { font-size: 0.65rem; color: #999; }
.player-tree-item.active .player-tree-meta { color: rgba(255,255,255,0.75); }
.player-tree-score {
font-size: 0.75rem; font-weight: 700; color: #28a745; flex-shrink: 0;
}
.player-tree-item.active .player-tree-score { color: rgba(255,255,255,0.9); }
.player-tree-rank {
font-size: 1.1rem; flex-shrink: 0; line-height: 1;
}
.player-tree-rank-num {
width: 24px; height: 24px; border-radius: 50%;
background: #cfe2ff; color: #084298;
display: flex; align-items: center; justify-content: center;
font-size: 0.6rem; font-weight: 700; flex-shrink: 0;
}
.player-tree-item.active .player-tree-rank-num {
background: rgba(255,255,255,0.3); color: white;
}
.players-right-panel {
flex: 1; overflow: hidden; min-width: 0;
display: flex; flex-direction: column;
}
#playerDetailEmbed { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#playerDetailEmbed iframe { flex: 1; min-height: 0; height: 100%; width: 100%; border: none; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.player-placeholder {
flex: 1; display: flex; flex-direction: column;
align-items: center; justify-content: center;
color: #ccc; gap: 10px;
background: white; border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
border: 1px solid #e9ecef;
}
.player-placeholder-icon { font-size: 2.5rem; }
.player-placeholder-text { font-size: 0.95rem; }
/* Compact Controls */
.controls {
display: flex;
gap: 15px;
margin-bottom: 20px;
flex-wrap: wrap;
align-items: center;
}
.search-box {
flex: 1;
min-width: 200px;
padding: 10px 15px;
border: 2px solid #e9ecef;
border-radius: 8px;
font-size: 0.9rem;
transition: all 0.3s ease;
background: white;
}
.search-box:focus {
outline: none;
border-color: #28a745;
box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}
.sort-select {
padding: 10px 15px;
border: 2px solid #e9ecef;
border-radius: 8px;
font-size: 0.9rem;
background: white;
cursor: pointer;
transition: all 0.3s ease;
min-width: 180px;
}
.sort-select:focus {
outline: none;
border-color: #28a745;
}
.filter-buttons {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.filter-btn {
background: white;
border: 2px solid #e9ecef;
padding: 8px 15px;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
font-size: 0.85rem;
font-weight: 600;
}
.filter-btn.active {
background: #28a745;
color: white;
border-color: #28a745;
}
.filter-btn:hover {
border-color: #28a745;
transform: translateY(-1px);
}
/* Compact Players Grid */
.players-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
gap: 20px;
}
.player-card {
background: white;
border-radius: 12px;
padding: 20px;
transition: all 0.3s ease;
cursor: pointer;
border: 1px solid #e9ecef;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
position: relative;
overflow: hidden;
}
.player-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4px;
background: linear-gradient(90deg, #28a745, #20c997);
transform: scaleX(0);
transition: transform 0.3s ease;
}
.player-card.current-player::before {
background: linear-gradient(90deg, #28a745, #20c997);
transform: scaleX(1);
}
.player-card.archived-player::before {
background: linear-gradient(90deg, #6c757d, #495057);
}
.player-card:hover {
transform: translateY(-3px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}
.player-card:hover::before {
transform: scaleX(1);
}
.player-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.player-name {
font-size: 1.2rem;
font-weight: bold;
color: #333;
}
.player-badge {
background: #28a745;
color: white;
padding: 4px 10px;
border-radius: 12px;
font-size: 0.75rem;
font-weight: 600;
}
.player-badge.archived {
background: #6c757d;
}
.player-stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.stat-item {
display: flex;
align-items: center;
gap: 6px;
font-size: 0.85rem;
}
.stat-item .icon {
font-size: 1rem;
}
.stat-item .value {
font-weight: 600;
color: #333;
}
.stat-item .label {
color: #666;
}
/* Compact Mini Charts */
.player-chart {
margin-top: 15px;
height: 80px;
position: relative;
}
.chart-canvas {
width: 100%;
height: 100%;
}
/* Loading State */
.loading {
text-align: center;
padding: 20px;
color: #666;
}
.loading-spinner {
width: 30px;
height: 30px;
border: 3px solid #f3f3f3;
border-top: 3px solid #28a745;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Empty State */
.empty-state {
text-align: center;
padding: 40px 20px;
color: #666;
}
.empty-state h3 {
font-size: 1.3rem;
margin-bottom: 8px;
color: #333;
}
.empty-icon {
font-size: 3rem;
margin-bottom: 15px;
opacity: 0.5;
}
/* Responsive Design */
@media (max-width: 768px) {
.navbar {
padding: 12px 20px;
flex-direction: column;
gap: 12px;
}
.navbar-controls {
flex-wrap: wrap;
justify-content: center;
}
.container {
padding: 15px;
height: auto;
}
.controls {
flex-direction: column;
align-items: stretch;
}
.search-box, .sort-select {
min-width: auto;
width: 100%;
}
.filter-buttons {
justify-content: center;
}
.players-grid {
grid-template-columns: 1fr;
}
.player-stats {
grid-template-columns: 1fr;
gap: 8px;
}
.stats-badges {
grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
}
.tournament-leaders {
grid-template-columns: 1fr;
gap: 20px;
}
.tournament-card {
padding: 25px;
margin: 0;
}
.tournament-name {
font-size: 1.3rem;
gap: 8px;
}
.tournament-header {
flex-direction: column;
align-items: center;
gap: 12px;
text-align: center;
}
.leaders-grid {
grid-template-columns: 1fr;
gap: 20px;
}
.leader-category {
padding: 24px;
}
.leader-score {
font-size: 1.6rem;
padding: 10px 16px;
}
.tab-navigation {
flex-direction: column;
gap: 10px;
}
.tab-btn {
padding: 12px 20px;
font-size: 0.95rem;
min-height: 45px;
}
}
</style>
<script src="/static/js/i18n.js"></script>
</head>
<body>
<!-- Navigation Bar -->
<div class="navbar">
<div class="navbar-title">👤 Analiza Igralcev</div>
<div class="navbar-controls">
<a href="/archive/player-analysis" class="nav-btn active">👤 <span data-i18n="players.player_analysis">Analiza Igralcev</span></a>
<a href="/archive" class="nav-btn">📚 <span data-i18n="navigation.archive">Archive</span></a>
<a href="/" class="nav-btn"></a>
</div>
</div>
<div class="players-layout">
<!-- LEFT: player tree -->
<div class="players-left-panel">
<div class="players-panel-header">
<div class="players-panel-header-title">👥 Igralci</div>
<div class="players-panel-count" id="playerTreeCount">0</div>
</div>
<div class="players-sort-bar">
<input type="text" class="players-search" id="searchBox" placeholder="🔍 Iskanje…" oninput="filterAndSortPlayers()">
<div class="players-sort-btns">
<button class="psort-btn active" data-sort="best_score" onclick="setSort('best_score')">🏆 Skupaj</button>
<button class="psort-btn" data-sort="total_tens" onclick="setSort('total_tens')">🎯 Desetke</button>
<button class="psort-btn" data-sort="best_single" onclick="setSort('best_single')">⭐ Enkrat</button>
</div>
</div>
<div class="player-tree-list" id="playerTreeList">
<div class="loading"><div class="loading-spinner"></div></div>
</div>
</div>
<!-- RIGHT: player detail -->
<div class="players-right-panel" id="playersRightPanel">
<div class="player-placeholder" id="playerPlaceholder">
<div class="player-placeholder-icon">👤</div>
<div class="player-placeholder-text">Izberi igralca iz seznama</div>
</div>
<div id="playerDetailEmbed" style="display:none"></div>
</div>
</div>
<script>
// Global data
let playersData = [];
let tournamentData = [];
let filteredPlayers = [];
let currentFilter = 'all';
let currentSort = 'best_score';
let playersWithStats = [];
// Initialize page
function initializePage() {
loadPlayerStats();
setupEventListeners();
}
// Format date for display
function formatDate(dateString) {
if (!dateString) return t('analysis.unknown_date');
try {
const date = new Date(dateString);
if (isNaN(date.getTime())) {
// Try to parse filename format YYYYMMDD_HHMMSS
if (dateString.length >= 8) {
const year = dateString.substring(0, 4);
const month = dateString.substring(4, 6);
const day = dateString.substring(6, 8);
const parsedDate = new Date(`${year}-${month}-${day}`);
if (!isNaN(parsedDate.getTime())) {
return parsedDate.toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric'
});
}
}
return t('analysis.unknown_date');
}
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric'
});
} catch (error) {
return 'Unknown Date';
}
}
// Load player statistics
async function loadPlayerStats() {
try {
const response = await fetch('/api/archive/players/with-stats');
const result = await response.json();
if (result.status === 'success') {
playersWithStats = result.players;
playersData = playersWithStats;
filteredPlayers = [...playersWithStats];
// Update total players count
document.getElementById('playerTreeCount').textContent = playersData.length;
filterAndSortPlayers();
} else {
console.error('Failed to load player stats:', result.message);
renderPlayersBasic();
}
} catch (error) {
console.error('Error loading player stats:', error);
renderPlayersBasic();
}
}
// Setup event listeners
function setupEventListeners() {
// search handled inline via oninput on the input element
}
function setSort(sort) {
currentSort = sort;
document.querySelectorAll('.psort-btn').forEach(b =>
b.classList.toggle('active', b.dataset.sort === sort));
filterAndSortPlayers();
}
// Filter and sort players
function filterAndSortPlayers() {
const searchTerm = document.getElementById('searchBox').value.toLowerCase();
// Sort full list and assign permanent ranks
const sorted = [...playersData].sort((a, b) => {
switch (currentSort) {
case 'best_score': return (b.stats?.best_tournament_score || 0) - (a.stats?.best_tournament_score || 0);
case 'total_tens': return (b.stats?.total_tens || 0) - (a.stats?.total_tens || 0);
case 'best_single': return (b.stats?.best_tournament_score || 0) - (a.stats?.best_tournament_score || 0);
default: return 0;
}
});
sorted.forEach((p, i) => { p._rank = i + 1; });
// Filter preserving original rank
filteredPlayers = sorted.filter(player => {
const matchesSearch = player.name.toLowerCase().includes(searchTerm);
const matchesFilter = currentFilter === 'all' ||
(currentFilter === 'current' && player.current_player) ||
(currentFilter === 'archived' && !player.current_player);
return matchesSearch && matchesFilter;
});
renderPlayers();
}
// Render players into the tree panel
let activePlayerId = null;
function renderPlayers() {
const treeList = document.getElementById('playerTreeList');
document.getElementById('playerTreeCount').textContent = filteredPlayers.length;
if (filteredPlayers.length === 0) {
treeList.innerHTML = `<div style="padding:24px;text-align:center;color:#bbb;font-size:0.82rem">Ni zadetkov</div>`;
return;
}
treeList.innerHTML = filteredPlayers.map((player) => {
const initials = player.name.split(' ').map(w => w[0]).join('').slice(0, 2).toUpperCase();
const active = player.id === activePlayerId ? ' active' : '';
let scoreVal, scoreMeta;
if (currentSort === 'total_tens') {
scoreVal = player.stats?.total_tens || 0;
scoreMeta = `${scoreVal} 🎯`;
} else {
scoreVal = player.stats?.best_tournament_score || 0;
scoreMeta = `${scoreVal} pts`;
}
const rank = player._rank || 0;
const rankHtml = rank === 1 ? `<div class="player-tree-rank">🥇</div>`
: rank === 2 ? `<div class="player-tree-rank">🥈</div>`
: rank === 3 ? `<div class="player-tree-rank">🥉</div>`
: `<div class="player-tree-rank-num">${rank}</div>`;
return `<div class="player-tree-item${active}" onclick="selectPlayer(${player.id})">
${rankHtml}
<div class="player-tree-info">
<div class="player-tree-name">${player.name}</div>
<div class="player-tree-meta">${player.stats?.total_tournaments || 0}T · ${scoreMeta}</div>
</div>
</div>`;
}).join('');
}
// Render players without stats (fallback)
function renderPlayersBasic() {
fetch('/api/players')
.then(response => response.json())
.then(data => {
const basicPlayers = data.players || [];
playersData = basicPlayers.map(p => ({ id: p.id, name: p.name, current_player: p.enabled, stats: {} }));
filteredPlayers = [...playersData];
document.getElementById('playerTreeCount').textContent = playersData.length;
renderPlayers();
})
.catch(() => {
document.getElementById('playerTreeList').innerHTML =
`<div style="padding:24px;text-align:center;color:#bbb;font-size:0.82rem">Napaka pri nalaganju</div>`;
});
}
// Create mini performance chart for player
function createMiniChart(player) {
const canvas = document.getElementById(`chart-${player.id}`);
if (!canvas || !player.stats?.performance_trend) return;
const ctx = canvas.getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: player.stats.performance_trend.map((_, i) => `T${i + 1}`),
datasets: [{
data: player.stats.performance_trend,
borderColor: player.current_player ? '#28a745' : '#6c757d',
backgroundColor: player.current_player ? 'rgba(40, 167, 69, 0.1)' : 'rgba(108, 117, 125, 0.1)',
borderWidth: 2,
fill: true,
tension: 0.4,
pointRadius: 2,
pointHoverRadius: 4
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
}
},
scales: {
x: {
display: false
},
y: {
display: false,
beginAtZero: true
}
},
elements: {
point: {
hoverBackgroundColor: player.current_player ? '#28a745' : '#6c757d'
}
},
interaction: {
intersect: false,
mode: 'index'
}
}
});
}
// Select player — load stats into right panel iframe
function selectPlayer(playerId) {
activePlayerId = playerId;
renderPlayers();
document.getElementById('playerPlaceholder').style.display = 'none';
const embed = document.getElementById('playerDetailEmbed');
embed.style.display = 'block';
embed.innerHTML = `<iframe src="/archive/player/${playerId}"></iframe>`;
}
// Navigate to player stats (kept for compatibility)
function viewPlayerStats(playerId) {
selectPlayer(playerId);
}
// Initialize page when DOM is loaded and translations are ready
document.addEventListener('DOMContentLoaded', function() {
window.addEventListener('i18nReady', function() {
initializePage();
}, { once: true });
});
</script>
</body>
</html>