Files
Sdk_TV_app/templates/results_calculator.html
T
bl3kunja d0bbf7bdce quality update:
- calculator
- result screens
- some fixes
2026-02-08 15:19:13 +01:00

2026 lines
55 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title data-i18n="scoring.results_calculator">Results Calculator</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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">
<style>
/* ========== LAYOUT FOUNDATION ========== */
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
body {
display: flex;
flex-direction: column;
height: 100vh;
}
/* ========== NAVBAR (TOP) ========== */
.navbar {
flex-shrink: 0;
z-index: 100;
}
/* ========== CONTENT WRAPPER (MIDDLE - SCROLLABLE) ========== */
.content-wrapper {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
min-height: 0;
position: relative;
}
.container {
flex: 1;
overflow: hidden;
width: 100%;
display: flex;
flex-direction: column;
align-items: stretch;
padding: 0 0 70px 0;
box-sizing: border-box;
gap: 0;
min-height: 0;
}
.scrollable-content {
flex: 1;
overflow: hidden;
width: 100%;
display: flex;
flex-direction: column;
align-items: stretch;
padding: 5px 20px 20px 20px;
box-sizing: border-box;
gap: 0;
min-height: 0;
}
/* All direct children of scrollable-content */
.scrollable-content > *:not(.cards-wrapper) {
width: 100%;
max-width: none;
flex-shrink: 0;
padding: 0;
box-sizing: border-box;
}
.header-section {
display: none;
}
/* Dynamic header colors based on tournament type */
.header-section.tournament-4_targets {
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}
.header-section.tournament-20_targets {
background: linear-gradient(135deg, #ff6b6b 0%, #ff8e53 100%);
}
.header-section.tournament-40_targets {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.header-section.tournament-default {
background: linear-gradient(135deg, #ff6b6b 0%, #ff8e53 100%);
}
.header-section::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%, rgba(255, 255, 255, 0.05) 100%);
pointer-events: none;
}
.header-section * {
position: relative;
z-index: 2;
}
.header-logo {
height: 50px;
max-width: 140px;
object-fit: contain;
margin-bottom: 15px;
filter: brightness(1.2) contrast(1.1);
background-color: white;
padding: 8px;
border-radius: 6px;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.header-title {
font-size: 1.6rem;
font-weight: 700;
color: rgb(255, 255, 255);
margin-bottom: 8px;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.header-subtitle {
font-size: 1rem;
color: rgba(255, 255, 255, 0.95);
margin-bottom: 15px;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.progress-info {
display: none;
}
.progress-item {
text-align: center;
}
.progress-number {
font-size: 1.4rem;
font-weight: 700;
color: #ffffff;
display: block;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
.progress-label {
font-size: 0.75rem;
color: rgba(255, 255, 255, 0.9);
text-transform: uppercase;
letter-spacing: 0.5px;
font-weight: 500;
}
.global-actions {
display: none;
}
.global-btn {
padding: 12px 24px;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: bold;
cursor: pointer;
transition: all 0.2s ease;
}
.fill-all-btn {
background: #ff6b35;
color: white;
padding: 12px 28px;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
transition: all 0.2s ease;
}
.fill-all-btn:hover {
background: #e55a2b;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}
.save-all-btn {
background: #17a2b8;
color: white;
}
.save-all-btn:hover {
background: #138496;
transform: translateY(-1px);
box-shadow: 0 4px 8px rgba(23, 162, 184, 0.3);
}
.cards-wrapper {
background: white;
border-radius: 0;
border: 0;
box-shadow: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: row;
gap: 0;
width: 100%;
box-sizing: border-box;
flex: 1;
overflow: hidden;
min-height: 0;
}
.participants-list {
display: flex;
flex-direction: column;
gap: 8px;
width: 280px;
max-width: none;
box-sizing: border-box;
padding: 15px;
background: white;
border-right: 2px solid #e9ecef;
overflow-y: auto;
overflow-x: hidden;
flex-shrink: 0;
}
.participants-list::-webkit-scrollbar {
width: 8px;
}
.participants-list::-webkit-scrollbar-track {
background: transparent;
}
.participants-list::-webkit-scrollbar-thumb {
background: #d1d5db;
border-radius: 4px;
}
.participants-list::-webkit-scrollbar-thumb:hover {
background: #9ca3af;
}
/* Participant list item */
.participant-list-item {
padding: 10px 12px;
background: white;
border: 2px solid #9ca3af;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
flex-direction: row;
gap: 8px;
align-items: center;
justify-content: space-between;
}
.participant-list-item:hover {
background: #f9f9f9;
}
.participant-list-item.active {
background: #f0f0f0;
}
.participant-list-item.in-progress {
border-color: #ffc107;
}
.participant-list-item.active.in-progress {
background: #fff5e6;
}
.participant-list-item.completed {
border-color: #28a745;
}
.participant-list-item.active.completed {
background: #e8f5e8;
}
.participant-list-item-content {
display: flex;
flex-direction: row;
gap: 6px;
align-items: center;
width: 100%;
min-width: 0;
}
.participant-list-item-name {
font-size: 0.85rem;
font-weight: 700;
color: #000 !important;
flex: 1;
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.participant-list-item-score {
font-size: 0.7rem;
font-weight: 700;
color: #28a745 !important;
min-width: fit-content;
}
.participant-list-item-tens {
font-size: 0.7rem;
font-weight: 700;
color: #ffc107 !important;
min-width: fit-content;
}
/* Main card panel */
.main-card-panel {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 15px;
background: white;
min-height: 0;
gap: 0;
}
.main-card-panel-empty {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
color: #999;
font-size: 1.1rem;
}
.participant-card {
background: white;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
padding: 0;
width: 100%;
border: 2px solid #9ca3af;
transition: all 0.3s ease;
box-sizing: border-box;
display: none;
flex-direction: column;
overflow: hidden;
flex: 1;
min-height: 0;
}
/* Hide participant card items in list (shown individually) */
.participants-list .participant-card {
display: none;
}
/* Show only active card in main panel */
.main-card-panel .participant-card.active {
display: flex;
}
.participant-card.completed {
border-color: #28a745;
box-shadow: 0 4px 16px rgba(40, 167, 69, 0.15);
}
.participant-card.in-progress {
border-color: #ffc107;
box-shadow: 0 6px 24px rgba(255, 193, 7, 0.25);
}
/* Darker styling for selected/active card */
.main-card-panel .participant-card.active {
background: #f5f7fa;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.card-header-top {
background: white;
border-bottom: 1px solid #e9ecef;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 14px 16px;
flex-shrink: 0;
width: 100%;
gap: 12px;
transition: all 0.2s ease;
}
/* Hide collapse icon */
.collapse-icon {
display: none;
}
.header-info {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
text-align: left;
width: 100%;
gap: 20px;
flex: 1;
min-width: 0;
position: relative;
}
.header-info .player-name {
flex: 0 1 auto;
min-width: 0;
}
.header-info .player-stats {
position: absolute;
left: 50%;
transform: translateX(-50%);
flex: 0;
}
.header-actions {
display: flex;
gap: 8px;
width: auto;
justify-content: flex-end;
flex-shrink: 0;
}
.collapse-icon {
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
color: #666;
transition: transform 0.2s ease;
flex-shrink: 0;
}
.participant-card.collapsed .collapse-icon {
transform: rotate(-90deg);
}
.header-btn {
width: 40px;
height: 40px;
padding: 0;
border: none;
border-radius: 6px;
font-size: 1.1rem;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.header-btn.clear-btn {
background: #dc3545;
color: white;
}
.header-btn.clear-btn:hover {
background: #c82333;
transform: translateY(-1px);
box-shadow: 0 3px 8px rgba(220, 53, 69, 0.25);
}
.header-btn.zero-fill-btn {
background: #6c757d;
color: white;
}
.header-btn.zero-fill-btn:hover {
background: #5a6268;
transform: translateY(-1px);
box-shadow: 0 3px 8px rgba(108, 117, 125, 0.25);
}
.participant-card.completed .card-header-top {
background: #f0f8f5;
border-bottom-color: #28a745;
}
.participant-card.completed .card-header-top:hover {
background: #e8f5e8;
}
.participant-card.in-progress .card-header-top {
background: #fffbf0;
border-bottom-color: #ffc107;
}
.participant-card.in-progress .card-header-top:hover {
background: #fff8e6;
}
.participant-header {
background: linear-gradient(135deg, #f8f9fa 0%, #f0f1f3 100%);
border-bottom: 3px solid #e9ecef;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 12px 14px;
flex-shrink: 0;
text-align: center;
width: 100%;
}
.participant-card.completed .participant-header {
background: linear-gradient(135deg, #e8f5e8 0%, #c8e6c9 100%);
border-right-color: #28a745;
}
.participant-card.in-progress .participant-header {
background: linear-gradient(135deg, #fffbf0 0%, #fff8e6 100%);
border-right-color: #ffc107;
}
.participant-targets-wrapper {
display: flex;
flex-direction: column;
flex: 1;
overflow-y: auto;
overflow-x: hidden;
min-height: 0;
padding: 10px 12px;
padding-right: 4px;
gap: 8px;
transition: all 0.3s ease;
max-height: 100%;
}
.participant-card.collapsed .participant-targets-wrapper {
max-height: 0;
overflow: hidden;
padding: 0;
}
.participant-targets-wrapper::-webkit-scrollbar {
width: 12px;
}
.participant-targets-wrapper::-webkit-scrollbar-track {
background: transparent;
border-radius: 6px;
margin-right: 4px;
}
.participant-targets-wrapper::-webkit-scrollbar-thumb {
border-radius: 6px;
border: 2px solid white;
background-clip: padding-box;
}
/* Default neutral scrollbar */
.participant-card:not(.completed):not(.in-progress) .participant-targets-wrapper::-webkit-scrollbar-thumb {
background: #9ca3af;
}
.participant-card:not(.completed):not(.in-progress) .participant-targets-wrapper::-webkit-scrollbar-thumb:hover {
background: #6b7280;
background-clip: padding-box;
}
/* Scrollbar color for completed cards */
.participant-card.completed .participant-targets-wrapper::-webkit-scrollbar-thumb {
background: #28a745;
}
.participant-card.completed .participant-targets-wrapper::-webkit-scrollbar-thumb:hover {
background: #1f7e34;
background-clip: padding-box;
}
/* Scrollbar color for in-progress cards */
.participant-card.in-progress .participant-targets-wrapper::-webkit-scrollbar-thumb {
background: #ffc107;
}
.participant-card.in-progress .participant-targets-wrapper::-webkit-scrollbar-thumb:hover {
background: #e0a800;
background-clip: padding-box;
}
.player-info {
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
flex-shrink: 0;
}
.player-name {
font-size: 1.05rem;
font-weight: 700;
color: #2c3e50;
margin: 0;
letter-spacing: 0.3px;
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.player-stats {
display: flex;
align-items: center;
gap: 24px;
font-size: 0.85rem;
justify-content: center;
flex: 0 0 auto;
}
.total-score {
font-size: 1.2rem;
font-weight: 700;
color: #28a745 !important;
text-align: center;
}
.score-label {
color: #999;
font-size: 0.65rem;
text-transform: uppercase;
font-weight: 600;
letter-spacing: 0.5px;
}
.tens-count {
font-size: 1.2rem;
font-weight: 700;
color: #ffc107 !important;
text-align: center;
}
.tens-label {
color: #999;
font-size: 0.65rem;
text-transform: uppercase;
font-weight: 600;
letter-spacing: 0.5px;
}
.completion-badge {
padding: 4px 10px;
border-radius: 12px;
font-size: 0.7rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.5px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.badge-done {
background: #28a745;
color: white;
box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
}
.badge-pending {
background: #ffc107;
color: #856404;
box-shadow: 0 2px 8px rgba(255, 193, 7, 0.3);
}
.badge-in-progress {
background: #5a8fd1;
color: white;
box-shadow: 0 2px 8px rgba(90, 143, 209, 0.3);
}
.badge-not-started {
background: #9ca3af;
color: white;
box-shadow: 0 2px 6px rgba(156, 163, 175, 0.2);
}
.participant-info {
display: flex;
align-items: center;
gap: 15px;
}
.participant-name {
font-size: 1.4rem;
font-weight: bold;
color: #333;
}
.participant-id {
background: #28a745;
color: white;
padding: 6px 15px;
border-radius: 15px;
font-size: 0.9rem;
font-weight: bold;
}
.participant-status {
display: flex;
align-items: center;
gap: 15px;
}
.score-display {
text-align: right;
display: flex;
flex-direction: column;
gap: 5px;
}
.score-row {
display: flex;
align-items: center;
gap: 15px;
}
.total-score {
text-align: right;
}
.score-number {
font-size: 1.8rem;
font-weight: bold;
color: #28a745;
}
.score-label {
font-size: 0.8rem;
color: #666;
text-transform: uppercase;
}
.tens-count {
text-align: right;
}
.tens-number {
font-size: 1.4rem;
font-weight: bold;
color: #ffc107;
}
.tens-label {
font-size: 0.8rem;
color: #666;
text-transform: uppercase;
}
.completion-badge {
padding: 6px 15px;
border-radius: 15px;
font-size: 0.9rem;
font-weight: bold;
text-transform: uppercase;
}
.badge-completed {
background: #28a745;
color: white;
}
.badge-in-progress {
background: #ffc107;
color: #856404;
}
.badge-not-started {
background: #6c757d;
color: white;
}
.collapse-icon {
font-size: 1.2rem;
transition: transform 0.3s ease;
color: #666;
}
.participant-card.collapsed .collapse-icon {
transform: rotate(-90deg);
}
.participant-content {
max-height: 1000px;
overflow: hidden;
transition: max-height 0.3s ease;
}
.participant-card.collapsed .participant-content {
max-height: 0;
}
/* Target grid layout */
.targets-row {
display: grid;
gap: 6px;
width: 100%;
padding: 6px 0;
}
/* Grid layouts for different target counts */
.targets-row.targets-4 {
grid-template-columns: repeat(2, 1fr);
}
.targets-row.targets-20 {
grid-template-columns: repeat(5, 1fr);
}
.targets-row.targets-40 {
grid-template-columns: repeat(8, 1fr);
}
.targets-row .target-group {
display: flex;
flex-direction: column;
width: 100%;
}
.shot-input {
padding: 8px;
text-align: center;
border: 2px solid #ddd;
border-radius: 4px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
background-color: #ffffff;
}
.shot-input:focus {
outline: none;
border-color: #28a745;
box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.2);
}
.shot-input.valid {
border-color: #28a745;
background: #f0f8f5;
}
.shot-input.ten {
border-color: #ffc107;
background: #fff9e6;
font-weight: bold;
}
.shot-input.empty {
color: #999;
}
/* Responsive adjustments */
@media (max-width: 1200px) {
.targets-row {
padding: 8px;
gap: 5px;
}
.target-group {
min-width: 50px;
padding: 2px;
}
.shot-input {
width: 24px;
padding: 1px;
font-size: 0.55rem;
min-height: 16px;
}
.participant-header {
gap: 15px;
}
.player-name {
font-size: 1rem;
}
}
@media (max-width: 768px) {
.participant-header {
flex-wrap: wrap;
gap: 12px;
padding: 12px;
}
.targets-row {
width: 100%;
order: 3;
padding: 6px;
margin-top: 8px;
border-top: 1px solid #e9ecef;
}
.player-info {
min-width: auto;
}
.completion-badge {
margin-left: auto;
}
.player-name {
font-size: 0.9rem;
}
.target-group {
min-width: 45px;
padding: 2px;
}
.shot-input {
width: 22px;
padding: 1px;
font-size: 0.5rem;
min-height: 14px;
}
.target-number {
font-size: 0.5rem;
}
}
.target-group {
border: 1px solid #e9ecef;
border-radius: 4px;
background: #f8f9fa;
display: flex;
flex-direction: column;
gap: 4px;
padding: 0;
overflow: hidden;
transition: all 0.2s ease;
}
.target-group.completed {
border-color: #28a745;
background: #f0f8f5;
box-shadow: 0 2px 6px rgba(40, 167, 69, 0.1);
}
.target-number {
background: linear-gradient(135deg, #f0f1f3 0%, #e8eaed 100%);
border-bottom: 1px solid #e9ecef;
font-size: 0.65rem;
font-weight: 600;
color: #495057;
letter-spacing: 0;
padding: 3px 4px;
text-align: center;
flex-shrink: 0;
transition: all 0.2s ease;
}
.target-group.completed .target-number {
background: linear-gradient(135deg, #e8f5e8 0%, #c8e6c9 100%);
border-bottom-color: #28a745;
color: #28a745;
}
.shots-container {
display: flex;
flex-direction: column;
gap: 4px;
padding: 4px;
flex: 1;
}
.shots-container.shots-5 {
gap: 3px;
}
.shot-input {
width: 100%;
padding: 4px 2px;
border: 1px solid #ddd;
border-radius: 3px;
text-align: center;
font-size: 0.75rem;
font-weight: 700;
color: #333;
background-color: #ffffff;
min-height: 24px;
transition: all 0.2s ease;
}
.shots-container.shots-5 .shot-input {
min-height: 22px;
font-size: 0.7rem;
}
.shot-input:focus {
outline: none;
border-color: #28a745;
box-shadow: 0 0 0 1px rgba(40, 167, 69, 0.3);
}
.shot-input.valid {
border-color: #28a745;
background: #ffffff;
}
.shot-input.ten {
border-color: #ffc107;
background: #ffffff;
font-weight: 700;
color: #ffc107;
}
.participant-actions {
display: flex;
gap: 6px;
padding: 8px;
flex-shrink: 0;
align-items: center;
justify-content: center;
flex-direction: row;
border-top: 3px solid #e9ecef;
background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
width: 100%;
}
.action-btn {
width: 38px;
height: 38px;
padding: 0;
border: none;
border-radius: 6px;
font-size: 0.95rem;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.clear-btn {
background: #f8f9fa;
border: 2px solid #dc3545;
color: #dc3545;
}
.clear-btn:hover {
background: #dc3545;
color: white;
transform: translateY(-1px);
}
.zero-fill-btn {
background: #f8f9fa;
border: 2px solid #6c757d;
color: #6c757d;
}
.zero-fill-btn:hover {
background: #6c757d;
color: white;
transform: translateY(-1px);
}
.auto-fill-btn {
background: #ffc107;
color: #856404;
}
.auto-fill-btn:hover {
background: #e0a800;
}
/* Bottom Finish Card - Full Width */
.finish-section {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(135deg, #f8f9fa 0%, #f0f1f3 100%);
border-radius: 0;
border: none;
border-top: 3px solid #e9ecef;
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
padding: 0 20px;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
gap: 15px;
z-index: 999;
height: 70px;
min-height: 70px;
box-sizing: border-box;
flex-shrink: 0;
width: 100%;
}
.finish-title {
display: none;
}
.finish-description {
display: none;
}
.finish-btn {
background: #28a745;
border: none;
color: white;
padding: 12px 28px;
border-radius: 6px;
cursor: pointer;
font-size: 1rem;
font-weight: bold;
transition: all 0.2s ease;
white-space: nowrap;
}
.finish-btn:hover {
background: #1e7e34;
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}
.finish-btn:disabled {
background: #6c757d;
cursor: not-allowed;
transform: none;
box-shadow: none;
}
.warning-message {
background: #fff3cd;
border: 1px solid #ffeaa7;
color: #856404;
padding: 12px 15px;
border-radius: 6px;
margin: 15px 0;
}
.finish-section .warning-message {
margin: 0;
padding: 8px 12px;
font-size: 0.9rem;
}
/* Loading and saving indicators */
.saving {
opacity: 0.7;
pointer-events: none;
}
.saving::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 20px;
height: 20px;
margin: -10px 0 0 -10px;
border: 2px solid #f3f3f3;
border-top: 2px solid #28a745;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
<script src="/static/js/i18n.js"></script>
</head>
<body>
<div class="navbar">
<div class="navbar-title">🎯 <span data-i18n="scoring.results_calculator">Results Calculator</span></div>
<div class="navbar-controls">
<a href="/" class="nav-btn">📺 <span data-i18n="navigation.dashboard">Dashboard</span></a>
<a href="/tournament" class="nav-btn">🏆 <span data-i18n="navigation.tournament">Tournament</span></a>
<a href="/tournament/draft" class="nav-btn">📋 <span data-i18n="tournament.view_draft">Draft</span></a>
<a href="/results/calculator" class="nav-btn active">🎯 <span data-i18n="navigation.calculator">Results Calculator</span></a>
</div>
</div>
<div class="content-wrapper">
<div class="container">
<div class="scrollable-content">
<div class="header-section tournament-{{ results.tournament_type if results and results.tournament_type else 'default' }}">
<img src="/static/logo.png" alt="Logo" class="header-logo" onerror="this.style.display='none'" />
<div class="header-title">
{% if results and results.tournament_type == '4_targets' %}
🎯 <span data-i18n="scoring.tournament_scoring">Tournament Scoring</span>
{% elif results and results.tournament_type == '40_targets' %}
💪 <span data-i18n="scoring.tournament_scoring">Tournament Scoring</span>
{% else %}
<span data-i18n="scoring.tournament_scoring">Tournament Scoring</span>
{% endif %}
</div>
<div class="header-subtitle" id="tournamentSubtitle">
{% if results.tournament_type == '40_targets' %}
<span data-i18n="scoring.enter_scores_40_targets">Enter scores for each participant (40 targets, 2 shots each). Score 0 = miss.</span>
{% elif results.tournament_type == '4_targets' %}
<span data-i18n="scoring.enter_scores_4_targets">Enter scores for each participant (4 targets, 5 shots each). Score 0 = miss.</span>
{% else %}
<span data-i18n="scoring.enter_scores_20_targets">Enter scores for each participant (20 targets, 2 shots each). Score 0 = miss.</span>
{% endif %}
</div>
<div class="progress-info">
<div class="progress-item">
<div class="progress-number" id="completedCount">0</div>
<div class="progress-label" data-i18n="scoring.completed">Zaključeno</div>
</div>
<div class="progress-item">
<div class="progress-number" id="totalParticipants">{{ results.participants|length }}</div>
<div class="progress-label" data-i18n="scoring.total">Skupaj</div>
</div>
<div class="progress-item">
<div class="progress-number" id="totalShots">0</div>
<div class="progress-label" data-i18n="scoring.total_shots">Skupaj Strelov</div>
</div>
<div class="progress-item">
<div class="progress-number" id="totalTens">0</div>
<div class="progress-label" data-i18n="results.tens">Tens</div>
</div>
</div>
</div>
<div class="cards-wrapper">
<!-- Sidebar with participant list -->
<div class="participants-list" id="participantsList">
{% for player_id, participant in results.participants.items() %}
<div class="participant-list-item {{ 'completed' if participant.completed else '' }}" onclick="selectParticipant({{ player_id }})" id="list-item-{{ player_id }}" data-player-id="{{ player_id }}">
<div class="participant-list-item-content">
<span class="participant-list-item-name">{{ participant.name }}</span>
<span class="participant-list-item-score" id="list-score-{{ player_id }}">{{ participant.total_score }}</span>
<span class="participant-list-item-tens" id="list-tens-{{ player_id }}">0</span>
</div>
</div>
{% endfor %}
</div>
<!-- Main card panel on the right -->
<div class="main-card-panel" id="mainCardPanel">
<div class="main-card-panel-empty" id="emptyPanel">
👈 <span data-i18n="general.select">Select a participant</span>
</div>
{% for player_id, participant in results.participants.items() %}
<div class="participant-card {{ 'completed' if participant.completed else 'in-progress' }}" id="card-{{ player_id }}" data-player-id="{{ player_id }}">
<!-- Card Header on Top -->
<div class="card-header-top">
<div class="header-info">
<div class="player-name">{{ participant.name }}</div>
<div class="player-stats">
<div style="display: flex; flex-direction: column; align-items: center;">
<span class="total-score" id="total-{{ player_id }}">{{ participant.total_score }}</span>
<span class="score-label" data-i18n="scoring.points">pts</span>
</div>
<div style="display: flex; flex-direction: column; align-items: center;">
<span class="tens-count" id="tens-{{ player_id }}">0</span>
<span class="tens-label">10s</span>
</div>
</div>
</div>
<div class="header-actions" onclick="event.stopPropagation();">
<button class="header-btn clear-btn" onclick="clearParticipant({{ player_id }})" data-i18n-title="scoring.clear_all_scores">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="3 6 5 6 21 6"></polyline>
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
<line x1="10" y1="11" x2="10" y2="17"></line>
<line x1="14" y1="11" x2="14" y2="17"></line>
</svg>
</button>
<button class="header-btn zero-fill-btn" onclick="fillEmptyWithZeros({{ player_id }})" data-i18n-title="scoring.fill_empty_with_zero">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="10"></circle>
<line x1="12" y1="6" x2="12" y2="18"></line>
<line x1="6" y1="12" x2="18" y2="12"></line>
</svg>
</button>
</div>
</div>
<!-- All Targets (Middle - scrollable) -->
<div class="participant-targets-wrapper">
<div class="targets-row" id="targets-{{ player_id }}">
<!-- Targets will be populated by JavaScript -->
</div>
</div>
</div>
{% endfor %}
</div>
</div>
<div class="finish-section">
<button class="fill-all-btn" onclick="fillAllPlayersRandom()">
🎲 <span data-i18n="scoring.fill_all_players_random">Fill All Random</span>
</button>
<button class="finish-btn" id="finishBtn" onclick="finishTournament()" data-i18n="scoring.finish_tournament_button">🏁 Finish Tournament
</button>
</div>
</div>
</div>
<script>
let results = {{ results|tojson }};
let saveTimeout = {};
// Tournament configuration
const tournamentType = results.tournament_type || '20_targets';
let numTargets, shotsPerTarget;
// Set tournament parameters
if (tournamentType === '40_targets') {
numTargets = 40;
shotsPerTarget = 2;
} else if (tournamentType === '4_targets') {
numTargets = 4;
shotsPerTarget = 5;
} else {
numTargets = 20;
shotsPerTarget = 2;
}
// Calculate 10s count for a player
function calculateTensCount(playerId) {
const playerIdStr = playerId.toString();
const targets = results.participants[playerIdStr].targets;
let tensCount = 0;
for (let target in targets) {
const targetData = targets[target];
for (let i = 1; i <= shotsPerTarget; i++) {
const shotValue = targetData[`shot${i}`];
if (shotValue === 10) {
tensCount++;
}
}
}
return tensCount;
}
// Update participant's 10s display
function updateParticipantTens(playerId) {
const tensCount = calculateTensCount(playerId);
// Update main card display
const tensElement = document.getElementById(`tens-${playerId}`);
if (tensElement) {
tensElement.textContent = tensCount;
// Add visual feedback
tensElement.style.color = '#ffc107';
setTimeout(() => {
tensElement.style.color = '';
}, 300);
}
// Update sidebar 10s count
const sidebarTensElement = document.getElementById(`list-tens-${playerId}`);
if (sidebarTensElement) {
sidebarTensElement.textContent = tensCount;
}
}
// Update overall 10s count
function updateOverallTens() {
let totalTens = 0;
for (let playerId in results.participants) {
totalTens += calculateTensCount(parseInt(playerId));
}
document.getElementById('totalTens').textContent = totalTens;
}
// Debounce function for auto-saving
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
function generateTargetsHTML(playerId) {
const participant = results.participants[playerId.toString()];
let html = '';
for (let i = 1; i <= numTargets; i++) {
const targetData = participant.targets[i.toString()] || {};
html += `
<div class="target-group" id="target-group-${playerId}-${i}">
<div class="target-number">${i}</div>
<div class="shots-container shots-${shotsPerTarget}">
`;
for (let shot = 1; shot <= shotsPerTarget; shot++) {
const shotKey = `shot${shot}`;
const value = targetData[shotKey];
const displayValue = value !== null && value !== undefined ? value : '';
html += `
<input type="number"
class="shot-input ${value === 10 ? 'ten' : ''}"
id="shot${shot}-${playerId}-${i}"
data-player="${playerId}"
data-target="${i}"
data-shot="${shot}"
min="0"
max="10"
value="${displayValue}"
placeholder="Strel ${shot}"
oninput="updateScore(${playerId}, ${i}, ${shot}, this.value)">
`;
}
html += `
</div>
</div>
`;
}
return html;
}
function initializeTargetsForPlayer(playerId) {
const targetsContainer = document.getElementById(`targets-${playerId}`);
if (targetsContainer) {
targetsContainer.className = `targets-row targets-${numTargets}`;
targetsContainer.innerHTML = generateTargetsHTML(playerId);
}
}
function toggleParticipant(playerId) {
const card = document.getElementById(`card-${playerId}`);
card.classList.toggle('collapsed');
}
function selectParticipant(playerId) {
// Remove active class from all list items and cards
document.querySelectorAll('.participant-list-item').forEach(item => {
item.classList.remove('active');
});
document.querySelectorAll('.participant-card').forEach(card => {
card.classList.remove('active');
});
// Add active class to selected item and card
const listItem = document.getElementById(`list-item-${playerId}`);
const card = document.getElementById(`card-${playerId}`);
if (listItem) listItem.classList.add('active');
if (card) card.classList.add('active');
// Hide empty panel if shown
const emptyPanel = document.getElementById('emptyPanel');
if (emptyPanel) emptyPanel.style.display = 'none';
}
function updateScore(playerId, targetNum, shotNum, value) {
const playerIdStr = playerId.toString();
const targetStr = targetNum.toString();
// Parse input - allow empty string, treat as null/undefined for completion check
let numValue = null;
if (value !== '' && value !== null && value !== undefined) {
numValue = parseInt(value);
if (isNaN(numValue)) numValue = null;
else numValue = Math.max(0, Math.min(10, numValue)); // Clamp between 0-10
}
// Update the input field with clamped value
const input = document.getElementById(`shot${shotNum}-${playerId}-${targetNum}`);
if (input && numValue !== null && input.value !== numValue.toString()) {
input.value = numValue;
}
// Update local data
if (!results.participants[playerIdStr]) {
console.error('Player not found:', playerIdStr);
return;
}
if (!results.participants[playerIdStr].targets[targetStr]) {
// Initialize target with all shots as null
const target = {};
for (let i = 1; i <= shotsPerTarget; i++) {
target[`shot${i}`] = null;
}
results.participants[playerIdStr].targets[targetStr] = target;
}
results.participants[playerIdStr].targets[targetStr][`shot${shotNum}`] = numValue;
// Update target group styling
updateTargetGroupStyling(playerId, targetNum);
// Recalculate totals
updateParticipantTotal(playerId);
updateParticipantTens(playerId);
updateParticipantStatus(playerId);
updateOverallProgress();
updateOverallTens();
// Visual feedback for input - highlight 10s
if (input) {
input.classList.remove('valid', 'ten');
if (numValue !== null) {
if (numValue === 10) {
input.classList.add('ten');
} else {
input.classList.add('valid');
}
}
}
// Auto-save with debounce
clearTimeout(saveTimeout[playerId]);
saveTimeout[playerId] = setTimeout(() => {
saveParticipant(playerId, true);
}, 1000);
}
function updateTargetGroupStyling(playerId, targetNum) {
const playerIdStr = playerId.toString();
const targetStr = targetNum.toString();
const targetGroup = document.getElementById(`target-group-${playerId}-${targetNum}`);
if (targetGroup && results.participants[playerIdStr].targets[targetStr]) {
const targetData = results.participants[playerIdStr].targets[targetStr];
// Check if all shots are completed
let allCompleted = true;
for (let i = 1; i <= shotsPerTarget; i++) {
const shotValue = targetData[`shot${i}`];
if (shotValue === null || shotValue === undefined) {
allCompleted = false;
break;
}
}
if (allCompleted) {
targetGroup.classList.add('completed');
} else {
targetGroup.classList.remove('completed');
}
}
}
function updateParticipantTotal(playerId) {
const playerIdStr = playerId.toString();
const targets = results.participants[playerIdStr].targets;
let total = 0;
for (let target in targets) {
const targetData = targets[target];
for (let i = 1; i <= shotsPerTarget; i++) {
const shotValue = targetData[`shot${i}`];
total += (shotValue !== null && shotValue !== undefined ? shotValue : 0);
}
}
results.participants[playerIdStr].total_score = total;
// Update main card display
const totalElement = document.getElementById(`total-${playerId}`);
if (totalElement) {
totalElement.textContent = total;
// Add visual feedback
totalElement.style.color = '#28a745';
setTimeout(() => {
totalElement.style.color = '';
}, 300);
}
// Update sidebar score
const sidebarScoreElement = document.getElementById(`list-score-${playerId}`);
if (sidebarScoreElement) {
sidebarScoreElement.textContent = total;
}
}
function updateParticipantStatus(playerId) {
const playerIdStr = playerId.toString();
const targets = results.participants[playerIdStr].targets;
const card = document.getElementById(`card-${playerId}`);
let completedTargets = 0;
let totalShots = 0;
for (let target in targets) {
const targetData = targets[target];
let targetCompleted = true;
for (let i = 1; i <= shotsPerTarget; i++) {
const shotValue = targetData[`shot${i}`];
// Count shots that have been entered (including 0)
if (shotValue !== null && shotValue !== undefined) {
totalShots++;
} else {
targetCompleted = false;
}
}
if (targetCompleted) {
completedTargets++;
}
}
const isCompleted = completedTargets === numTargets;
const isInProgress = totalShots > 0 && !isCompleted;
results.participants[playerIdStr].completed = isCompleted;
// Update card styling based on status
if (card) {
card.classList.remove('completed', 'in-progress');
if (isCompleted) {
card.classList.add('completed');
} else if (isInProgress) {
card.classList.add('in-progress');
}
}
// Update sidebar styling based on status
const listItem = document.getElementById(`list-item-${playerId}`);
if (listItem) {
listItem.classList.remove('completed', 'in-progress');
if (isCompleted) {
listItem.classList.add('completed');
} else if (isInProgress) {
listItem.classList.add('in-progress');
}
}
}
function updateOverallProgress() {
let completedCount = 0;
let totalShots = 0;
for (let playerId in results.participants) {
const participant = results.participants[playerId];
if (participant.completed) {
completedCount++;
}
for (let target in participant.targets) {
const targetData = participant.targets[target];
for (let i = 1; i <= shotsPerTarget; i++) {
const shotValue = targetData[`shot${i}`];
if (shotValue !== null && shotValue !== undefined) totalShots++;
}
}
}
document.getElementById('completedCount').textContent = completedCount;
document.getElementById('totalShots').textContent = totalShots;
// Update finish button state
const finishBtn = document.getElementById('finishBtn');
const allCompleted = completedCount === Object.keys(results.participants).length;
if (finishBtn) {
finishBtn.disabled = !allCompleted;
}
}
async function saveParticipant(playerId, silent = false) {
try {
const playerIdStr = playerId.toString();
const participantData = results.participants[playerIdStr];
const response = await fetch(`/api/results/participant/${playerId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
targets: participantData.targets
})
});
if (!response.ok) {
throw new Error('Failed to save');
}
} catch (error) {
console.error('Error saving participant:', error);
if (!silent) {
alert('Failed to save participant data. Please try again.');
}
}
}
async function saveAllPlayers() {
const saveAllBtn = document.querySelector('.save-all-btn');
const originalText = saveAllBtn.textContent;
saveAllBtn.textContent = `💾 ${t('scoring.saving_all')}`;
saveAllBtn.disabled = true;
try {
const playerIds = Object.keys(results.participants);
for (const playerId of playerIds) {
await saveParticipant(parseInt(playerId), true);
}
// Show success feedback
saveAllBtn.textContent = `${t('scoring.all_saved')}`;
saveAllBtn.style.background = '#28a745';
setTimeout(() => {
saveAllBtn.textContent = originalText;
saveAllBtn.style.background = '';
saveAllBtn.disabled = false;
}, 2000);
} catch (error) {
console.error('Error saving all players:', error);
alert('Failed to save all player data. Please try again.');
saveAllBtn.textContent = originalText;
saveAllBtn.disabled = false;
}
}
function clearParticipant(playerId) {
if (!confirm('Are you sure you want to clear all scores for this participant?')) {
return;
}
const playerIdStr = playerId.toString();
// Clear all inputs
for (let i = 1; i <= numTargets; i++) {
for (let shot = 1; shot <= shotsPerTarget; shot++) {
const shotInput = document.getElementById(`shot${shot}-${playerId}-${i}`);
if (shotInput) {
shotInput.value = '';
shotInput.classList.remove('valid', 'ten');
}
}
// Update data
const target = {};
for (let shot = 1; shot <= shotsPerTarget; shot++) {
target[`shot${shot}`] = null;
}
results.participants[playerIdStr].targets[i.toString()] = target;
// Update target group styling
updateTargetGroupStyling(playerId, i);
}
updateParticipantTotal(playerId);
updateParticipantTens(playerId);
updateParticipantStatus(playerId);
updateOverallProgress();
updateOverallTens();
// Save changes
saveParticipant(playerId);
}
function fillEmptyWithZeros(playerId) {
const playerIdStr = playerId.toString();
let changedCount = 0;
// Fill all empty entries with 0
for (let i = 1; i <= numTargets; i++) {
const target = results.participants[playerIdStr].targets[i.toString()] || {};
for (let shot = 1; shot <= shotsPerTarget; shot++) {
const shotInput = document.getElementById(`shot${shot}-${playerId}-${i}`);
// Only fill if empty
if ((target[`shot${shot}`] === null || target[`shot${shot}`] === undefined) && shotInput && shotInput.value === '') {
shotInput.value = 0;
shotInput.classList.remove('ten');
shotInput.classList.add('valid');
changedCount++;
// Update data
if (!results.participants[playerIdStr].targets[i.toString()]) {
results.participants[playerIdStr].targets[i.toString()] = {};
}
results.participants[playerIdStr].targets[i.toString()][`shot${shot}`] = 0;
}
}
// Update target group styling
updateTargetGroupStyling(playerId, i);
}
if (changedCount > 0) {
updateParticipantTotal(playerId);
updateParticipantTens(playerId);
updateParticipantStatus(playerId);
updateOverallProgress();
updateOverallTens();
saveParticipant(playerId, true);
}
}
function autoFillDemo(playerId) {
if (!confirm('Fill with random demo scores? This will overwrite existing data.')) {
return;
}
fillPlayerRandom(playerId);
saveParticipant(playerId);
}
function fillPlayerRandom(playerId) {
const playerIdStr = playerId.toString();
let fillCount = 0;
// Fill with random scores (0-10) - all fields will be filled
for (let i = 1; i <= numTargets; i++) {
const target = {};
for (let shot = 1; shot <= shotsPerTarget; shot++) {
const randomScore = Math.floor(Math.random() * 11);
const inputId = `shot${shot}-${playerId}-${i}`;
const shotInput = document.getElementById(inputId);
if (shotInput) {
shotInput.value = randomScore;
shotInput.classList.remove('valid', 'ten');
if (randomScore === 10) {
shotInput.classList.add('ten');
} else {
shotInput.classList.add('valid');
}
fillCount++;
}
target[`shot${shot}`] = randomScore;
}
// Update data
results.participants[playerIdStr].targets[i.toString()] = target;
// Update target group styling
updateTargetGroupStyling(playerId, i);
}
console.log(`Player ${playerId}: filled ${fillCount} inputs`);
updateParticipantTotal(playerId);
updateParticipantTens(playerId);
updateParticipantStatus(playerId);
updateOverallProgress();
updateOverallTens();
}
async function fillAllPlayersRandom() {
if (!confirm('Fill ALL players with random demo scores? This will overwrite all existing data and enable tournament finish.')) {
return;
}
try {
// Fill all players with random data
const playerIds = Object.keys(results.participants);
for (const playerId of playerIds) {
fillPlayerRandom(parseInt(playerId));
}
// Save all players
for (const playerId of playerIds) {
await saveParticipant(parseInt(playerId), true);
}
} catch (error) {
console.error('Error filling all players:', error);
alert('Failed to fill all players: ' + error.message);
}
}
async function finishTournament() {
const allCompleted = Object.values(results.participants).every(p => p.completed);
if (!allCompleted) {
alert('Please complete scoring for all participants before finishing the tournament.');
return;
}
if (!confirm('Are you sure you want to finish the tournament? This will finalize all results and make them viewable.')) {
return;
}
const finishBtn = document.getElementById('finishBtn');
finishBtn.disabled = true;
const originalText = finishBtn.innerHTML;
const originalI18n = finishBtn.getAttribute('data-i18n');
finishBtn.removeAttribute('data-i18n');
finishBtn.innerHTML = '🔄 Finishing Tournament...';
try {
const response = await fetch('/api/results/finish', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
}
});
if (response.ok) {
const responseData = await response.json();
// Determine where to redirect based on tournament type and archive
let redirectUrl = '/results';
// Priority 1: If league finished, redirect to league archive
if (responseData.league_archived && responseData.league_archive_filename) {
redirectUrl = `/archive/league/${responseData.league_archive_filename}`;
}
// Priority 2: If standalone tournament, redirect to tournament archive
else if (responseData.archived && responseData.archive_filename) {
redirectUrl = `/archive/tournament/${responseData.archive_filename}`;
}
// Priority 3: If league tournament (not final), show league standings
else if (responseData.league && !responseData.league_finished) {
redirectUrl = '/results'; // This will show league standings with current tournament
}
// Always show results after tournament finishes
alert('Tournament finished successfully! Showing results...');
setTimeout(() => {
window.location.href = redirectUrl;
}, 1000);
} else {
const error = await response.json();
throw new Error(error.message || 'Failed to finish tournament');
}
} catch (error) {
console.error('Error finishing tournament:', error);
alert('Failed to finish tournament: ' + error.message);
finishBtn.disabled = false;
finishBtn.innerHTML = originalText;
if (originalI18n) {
finishBtn.setAttribute('data-i18n', originalI18n);
}
}
}
// Keyboard shortcuts
document.addEventListener('keydown', function(event) {
if (event.ctrlKey && event.key === 's') {
event.preventDefault();
saveAllPlayers();
}
});
// Initialize
document.addEventListener('DOMContentLoaded', function() {
// Initialize targets for all players
Object.keys(results.participants).forEach(playerId => {
initializeTargetsForPlayer(parseInt(playerId));
// Update initial states
for (let i = 1; i <= numTargets; i++) {
updateTargetGroupStyling(parseInt(playerId), i);
}
updateParticipantStatus(parseInt(playerId));
updateParticipantTens(parseInt(playerId));
});
updateOverallProgress();
updateOverallTens();
// Add input validation and navigation
document.addEventListener('input', function(e) {
if (e.target.classList.contains('shot-input')) {
if (e.target.value !== '') {
const value = parseInt(e.target.value);
const clampedValue = Math.max(0, Math.min(10, isNaN(value) ? 0 : value));
if (e.target.value !== clampedValue.toString()) {
e.target.value = clampedValue;
}
}
}
});
document.addEventListener('keydown', function(e) {
if (e.target.classList.contains('shot-input') && e.key === 'Enter') {
const inputs = Array.from(document.querySelectorAll('.shot-input'));
const currentIndex = inputs.indexOf(e.target);
const nextInput = inputs[currentIndex + 1];
if (nextInput) {
nextInput.focus();
nextInput.select();
}
}
});
});
</script>
</body>
</html>