combining league jsons
This commit is contained in:
+30
-1
@@ -22,6 +22,7 @@
|
|||||||
"enable_selected": "Enable Selected",
|
"enable_selected": "Enable Selected",
|
||||||
"disable_selected": "Disable Selected",
|
"disable_selected": "Disable Selected",
|
||||||
"print": "Print",
|
"print": "Print",
|
||||||
|
"export": "Export JSON",
|
||||||
"visible": "Visible",
|
"visible": "Visible",
|
||||||
"date": "Date",
|
"date": "Date",
|
||||||
"view": "View",
|
"view": "View",
|
||||||
@@ -140,6 +141,33 @@
|
|||||||
"highest_score": "Highest Score",
|
"highest_score": "Highest Score",
|
||||||
"average_final": "Average Final",
|
"average_final": "Average Final",
|
||||||
"5_tournament_league": "5 Tournament League - Best 4 Count",
|
"5_tournament_league": "5 Tournament League - Best 4 Count",
|
||||||
|
"combine_leagues": "Combine Leagues",
|
||||||
|
"combine_mode": "Combine Leagues",
|
||||||
|
"convert_mode": "Convert Tournaments to League",
|
||||||
|
"upload_league_files": "Upload League JSON Files",
|
||||||
|
"upload_tournament_files": "Upload Tournament JSON Files",
|
||||||
|
"combine_leagues_desc": "Upload multiple league JSON files to combine them into a single results table.",
|
||||||
|
"convert_tournaments_desc": "Upload 1-5 tournament JSON files to create a league. You can upload partial leagues as tournaments complete. Final scoring uses best 4 results when all 5 are uploaded.",
|
||||||
|
"click_browse": "Click to browse",
|
||||||
|
"drag_drop_files": "or drag and drop league JSON files here",
|
||||||
|
"supports_multiple": "Supports multiple file selection",
|
||||||
|
"clear_all": "Clear All",
|
||||||
|
"combine_preview": "Combine & Preview",
|
||||||
|
"convert_to_league": "Convert to League",
|
||||||
|
"valid_league": "Valid League",
|
||||||
|
"valid_tournament": "Valid Tournament",
|
||||||
|
"participants": "participants",
|
||||||
|
"tournaments": "tournaments",
|
||||||
|
"invalid_format": "Invalid file format",
|
||||||
|
"select_mode": "Select Mode",
|
||||||
|
"start_over": "Start Over",
|
||||||
|
"export_combined_results": "Export Combined Results",
|
||||||
|
"combined_league_info": "Combined League Information",
|
||||||
|
"uploaded_files": "Uploaded Files",
|
||||||
|
"remove": "Remove",
|
||||||
|
"type": "Type",
|
||||||
|
"failed_parse_json": "Failed to parse JSON",
|
||||||
|
"invalid_tournament_format": "Invalid tournament file format",
|
||||||
"joker_used_badge": "Joker Used",
|
"joker_used_badge": "Joker Used",
|
||||||
"search_players_placeholder": "Search players by name...",
|
"search_players_placeholder": "Search players by name...",
|
||||||
"no_players_found": "No players found matching your search criteria.",
|
"no_players_found": "No players found matching your search criteria.",
|
||||||
@@ -166,7 +194,8 @@
|
|||||||
"system": "System",
|
"system": "System",
|
||||||
"camera": "Camera",
|
"camera": "Camera",
|
||||||
"tournaments": "Tournaments",
|
"tournaments": "Tournaments",
|
||||||
"results.most_tens": "Most 10s"
|
"results.most_tens": "Most 10s",
|
||||||
|
"combine_leagues": "Combine Leagues"
|
||||||
},
|
},
|
||||||
"results": {
|
"results": {
|
||||||
"results": "Results",
|
"results": "Results",
|
||||||
|
|||||||
+28
-2
@@ -22,6 +22,7 @@
|
|||||||
"enable_selected": "Omogoči Izbrane",
|
"enable_selected": "Omogoči Izbrane",
|
||||||
"disable_selected": "Onemogoči Izbrane",
|
"disable_selected": "Onemogoči Izbrane",
|
||||||
"print": "Natisni",
|
"print": "Natisni",
|
||||||
|
"export": "Izvozi JSON",
|
||||||
"visible": "Vidni",
|
"visible": "Vidni",
|
||||||
"date": "Datum",
|
"date": "Datum",
|
||||||
"view": "Oglej",
|
"view": "Oglej",
|
||||||
@@ -171,8 +172,33 @@
|
|||||||
"system": "Sistem",
|
"system": "Sistem",
|
||||||
"camera": "Kamera",
|
"camera": "Kamera",
|
||||||
"tournaments": "Turnirji",
|
"tournaments": "Turnirji",
|
||||||
"results.most_tens": "Največ Desetk"
|
"results.most_tens": "Največ Desetk",
|
||||||
|
"combine_leagues": "Združi Lige",
|
||||||
|
"combine_mode": "Združi Lige",
|
||||||
|
"convert_mode": "Pretvori Turnirje v Ligo",
|
||||||
|
"upload_league_files": "Naloži Datoteke Lig",
|
||||||
|
"upload_tournament_files": "Naloži Datoteke Turnirjev",
|
||||||
|
"combine_leagues_desc": "Naloži več datotek lig JSON, da jih združiš v eno tabelo rezultatov.",
|
||||||
|
"convert_tournaments_desc": "Naloži 1-5 datotek turnirjev JSON za ustvarjanje lige. Lahko naložiš delne lige ko turnirji napredujejo. Končno točkovanje uporablja najboljše 4 rezultate, ko so vseh 5 naloženih.",
|
||||||
|
"click_browse": "Klikni za brskanje",
|
||||||
|
"drag_drop_files": "ali povleci in spusti datoteke JSON lig tukaj",
|
||||||
|
"supports_multiple": "Podpira izbiro več datotek",
|
||||||
|
"combine_preview": "Združi in Predoglej",
|
||||||
|
"convert_to_league": "Pretvori v Ligo",
|
||||||
|
"valid_league": "Veljavna Liga",
|
||||||
|
"valid_tournament": "Veljaven Turnir",
|
||||||
|
"participants": "udeleženci",
|
||||||
|
"invalid_format": "Neveljavna oblika datoteke",
|
||||||
|
"select_mode": "Izberi Način",
|
||||||
|
"start_over": "Začni Znova",
|
||||||
|
"export_combined_results": "Izvozi Združene Rezultate",
|
||||||
|
"combined_league_info": "Informacije o Združeni Ligi",
|
||||||
|
"uploaded_files": "Naložene Datoteke",
|
||||||
|
"remove": "Odstrani",
|
||||||
|
"type": "Tip",
|
||||||
|
"failed_parse_json": "Napaka pri branju JSON",
|
||||||
|
"invalid_tournament_format": "Neveljavna oblika datoteke turnirja"
|
||||||
|
|
||||||
},
|
},
|
||||||
"results": {
|
"results": {
|
||||||
"results": "Rezultati",
|
"results": "Rezultati",
|
||||||
|
|||||||
+8
-1
@@ -274,4 +274,11 @@ document.addEventListener('DOMContentLoaded', initI18n);
|
|||||||
// Export functions for global use
|
// Export functions for global use
|
||||||
window.t = t;
|
window.t = t;
|
||||||
window.changeLanguage = changeLanguage;
|
window.changeLanguage = changeLanguage;
|
||||||
window.createLanguageSelector = createLanguageSelector;
|
window.createLanguageSelector = createLanguageSelector;
|
||||||
|
|
||||||
|
// Export i18n object with useful functions
|
||||||
|
window.i18n = {
|
||||||
|
t: t,
|
||||||
|
updatePageTranslations: translatePage,
|
||||||
|
changeLanguage: changeLanguage
|
||||||
|
};
|
||||||
@@ -122,7 +122,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.round-row.current {
|
.round-row.current {
|
||||||
border-left: 4px solid #28a745;
|
border-left: 4px solid #007bff;
|
||||||
box-shadow: 0 4px 15px rgba(0, 123, 255, 0.25);
|
box-shadow: 0 4px 15px rgba(0, 123, 255, 0.25);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.current-badge {
|
.current-badge {
|
||||||
background: #28a745;
|
background: #007bff;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -683,21 +683,17 @@
|
|||||||
|
|
||||||
<div class="tournament-actions">
|
<div class="tournament-actions">
|
||||||
<a href="/tournament/draft" class="nav-link tournament-btn">📋 <span data-i18n="tournament.view_full_tournament_draft">Oglej si Celoten Žreb Turnirja</span></a>
|
<a href="/tournament/draft" class="nav-link tournament-btn">📋 <span data-i18n="tournament.view_full_tournament_draft">Oglej si Celoten Žreb Turnirja</span></a>
|
||||||
|
<a href="/results/calculator" class="nav-link tournament-btn">🎯 <span data-i18n="scoring.results_calculator">Calculator</span></a>
|
||||||
<a href="/tournament" class="nav-link tournament-btn" id="manageTournamentLink">⚙️ <span data-i18n="tournament.manage_tournament">Upravljaj Turnir</span></a>
|
<a href="/tournament" class="nav-link tournament-btn" id="manageTournamentLink">⚙️ <span data-i18n="tournament.manage_tournament">Upravljaj Turnir</span></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if settings.tournament_active %}
|
|
||||||
<div class="settings-group">
|
|
||||||
<a href="/results/calculator" class="nav-link tournament-btn">🎯 <span data-i18n="scoring.results_calculator">Calculator</span></a>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- Tournaments Section -->
|
<!-- Tournaments Section -->
|
||||||
<div class="settings-group">
|
<div class="settings-group">
|
||||||
<h4 data-i18n="league.tournaments">Turnirji</h4>
|
<h4 data-i18n="league.tournaments">Turnirji</h4>
|
||||||
<a href="/tournament" class="nav-link" id="tournamentModeLink">🏆 <span data-i18n="tournament.tournament_mode">Način Turnirja</span></a>
|
<a href="/tournament" class="nav-link" id="tournamentModeLink">🏆 <span data-i18n="tournament.tournament_mode">Način Turnirja</span></a>
|
||||||
|
<a href="/league/combine" class="nav-link">🔗 <span data-i18n="league.combine_leagues">Combine Leagues</span></a>
|
||||||
<a href="/archive/player-analysis" class="nav-link">👤 <span data-i18n="players.player_analysis">Analiza Igralcev</span></a>
|
<a href="/archive/player-analysis" class="nav-link">👤 <span data-i18n="players.player_analysis">Analiza Igralcev</span></a>
|
||||||
<a href="/archive" class="nav-link">📚 <span data-i18n="navigation.archive">Arhiv</span></a>
|
<a href="/archive" class="nav-link">📚 <span data-i18n="navigation.archive">Arhiv</span></a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,771 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="sl">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title data-i18n="league.combine_leagues">Combine Leagues</title>
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/base.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/navbar.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/buttons.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/components.css') }}">
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
background: #f5f5f5;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||||
|
min-height: 100vh;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar {
|
||||||
|
background: white;
|
||||||
|
border-bottom: 1px solid #e1e5e9;
|
||||||
|
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||||
|
padding: 15px 25px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-title {
|
||||||
|
font-size: 1.8rem;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-btn {
|
||||||
|
background: #f8f9fa;
|
||||||
|
border: 2px solid #e9ecef;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
color: #333;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-btn:hover {
|
||||||
|
background: #e9ecef;
|
||||||
|
border-color: #28a745;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
color: #28a745;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-section {
|
||||||
|
background: white;
|
||||||
|
padding: 30px;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-area {
|
||||||
|
border: 3px dashed #28a745;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 40px;
|
||||||
|
text-align: center;
|
||||||
|
background: #f8f9fa;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-area:hover {
|
||||||
|
background: #e9f7ed;
|
||||||
|
border-color: #1e7e34;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-area.drag-over {
|
||||||
|
background: #d4edda;
|
||||||
|
border-color: #28a745;
|
||||||
|
box-shadow: 0 4px 12px rgba(40, 167, 69, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-input {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-icon {
|
||||||
|
font-size: 48px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.uploaded-files {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-item {
|
||||||
|
background: #f8f9fa;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 5px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
border-left: 4px solid #28a745;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-item.error {
|
||||||
|
border-left-color: #dc3545;
|
||||||
|
background: #f8d7da;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-info {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-name {
|
||||||
|
font-weight: bold;
|
||||||
|
color: #2c3e50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.file-details {
|
||||||
|
font-size: 0.9em;
|
||||||
|
color: #6c757d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.remove-btn {
|
||||||
|
background: #dc3545;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 8px 15px;
|
||||||
|
border-radius: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.remove-btn:hover {
|
||||||
|
background: #c82333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-buttons {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
padding: 12px 24px;
|
||||||
|
border: 2px solid;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: bold;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
flex: 1;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background: #28a745;
|
||||||
|
color: white;
|
||||||
|
border-color: #1e7e34;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background: #1e7e34;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:disabled {
|
||||||
|
background: #6c757d;
|
||||||
|
border-color: #5a6268;
|
||||||
|
cursor: not-allowed;
|
||||||
|
opacity: 0.6;
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
background: #f8f9fa;
|
||||||
|
color: #333;
|
||||||
|
border-color: #e9ecef;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary:hover {
|
||||||
|
background: #e9ecef;
|
||||||
|
border-color: #dc3545;
|
||||||
|
color: #dc3545;
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-section {
|
||||||
|
background: white;
|
||||||
|
padding: 30px;
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-section.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-box {
|
||||||
|
background: #d4edda;
|
||||||
|
border-left: 4px solid #28a745;
|
||||||
|
padding: 15px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-box h3 {
|
||||||
|
margin: 0 0 10px 0;
|
||||||
|
color: #155724;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||||
|
gap: 15px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-card {
|
||||||
|
background: #f8f9fa;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 8px;
|
||||||
|
text-align: center;
|
||||||
|
border-left: 4px solid #28a745;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-value {
|
||||||
|
font-size: 32px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #28a745;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-label {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #6c757d;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-btn {
|
||||||
|
flex: 1;
|
||||||
|
padding: 12px 20px;
|
||||||
|
border: 2px solid #28a745;
|
||||||
|
background: white;
|
||||||
|
color: #28a745;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: bold;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-btn:hover {
|
||||||
|
background: #e9f7ed;
|
||||||
|
transform: translateY(-1px);
|
||||||
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-btn.active {
|
||||||
|
background: #28a745;
|
||||||
|
color: white;
|
||||||
|
border-color: #1e7e34;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="navbar">
|
||||||
|
<h1 class="navbar-title">🔗 <span data-i18n="league.combine_leagues">Combine Leagues</span></h1>
|
||||||
|
<a href="/" class="nav-btn">← <span data-i18n="navigation.dashboard">Dashboard</span></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="upload-section">
|
||||||
|
<div style="margin-bottom: 20px;">
|
||||||
|
<label style="display: block; margin-bottom: 10px; font-weight: bold; color: #2c3e50;">
|
||||||
|
<span data-i18n="league.select_mode">Select Mode</span>:
|
||||||
|
</label>
|
||||||
|
<div style="display: flex; gap: 10px;">
|
||||||
|
<button class="mode-btn active" id="combineMode" onclick="switchMode('combine')">
|
||||||
|
🔗 <span data-i18n="league.combine_mode">Combine Leagues</span>
|
||||||
|
</button>
|
||||||
|
<button class="mode-btn" id="convertMode" onclick="switchMode('convert')">
|
||||||
|
🔄 <span data-i18n="league.convert_mode">Convert Tournaments to League</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="combineSection">
|
||||||
|
<h2>📤 <span data-i18n="league.upload_league_files">Upload League JSON Files</span></h2>
|
||||||
|
<p style="color: #6c757d; margin-bottom: 20px;">
|
||||||
|
<span data-i18n="league.combine_leagues_desc">Upload multiple league JSON files to combine them into a single results table.</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="convertSection" style="display: none;">
|
||||||
|
<h2>📤 <span data-i18n="league.upload_tournament_files">Upload Tournament JSON Files</span></h2>
|
||||||
|
<p style="color: #6c757d; margin-bottom: 20px;">
|
||||||
|
<span data-i18n="league.convert_tournaments_desc">Upload 1-5 tournament JSON files to create a league. You can upload partial leagues as tournaments complete. Final scoring uses best 4 results when all 5 are uploaded.</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="upload-area" id="uploadArea">
|
||||||
|
<div class="upload-icon">📁</div>
|
||||||
|
<p><strong data-i18n="league.click_browse">Click to browse</strong> <span data-i18n="league.drag_drop_files">or drag and drop league JSON files here</span></p>
|
||||||
|
<p style="font-size: 0.9em; color: #6c757d;"><span data-i18n="league.supports_multiple">Supports multiple file selection</span></p>
|
||||||
|
<input type="file" id="fileInput" class="file-input" accept=".json" multiple>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="uploaded-files" id="uploadedFiles"></div>
|
||||||
|
|
||||||
|
<div class="action-buttons">
|
||||||
|
<button class="btn btn-secondary" id="clearBtn" disabled>
|
||||||
|
🗑️ <span data-i18n="scoring.clear_all">Clear All</span>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-primary" id="processBtn" disabled>
|
||||||
|
<span id="processBtnText">🔗 <span data-i18n="league.combine_preview">Combine & Preview</span></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="preview-section" id="previewSection">
|
||||||
|
<div class="info-box">
|
||||||
|
<h3>ℹ️ <span data-i18n="league.combined_league_info">Combined League Information</span></h3>
|
||||||
|
<div id="combinedInfo"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="stats-grid" id="statsGrid"></div>
|
||||||
|
|
||||||
|
<div id="resultsDisplay"></div>
|
||||||
|
|
||||||
|
<div class="action-buttons" style="margin-top: 20px;">
|
||||||
|
<button class="btn btn-secondary" onclick="window.location.reload()">
|
||||||
|
🔄 <span data-i18n="league.start_over">Start Over</span>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-primary" id="exportBtn">
|
||||||
|
💾 <span data-i18n="league.export_combined_results">Export Combined Results</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="/static/js/i18n.js"></script>
|
||||||
|
<script>
|
||||||
|
let uploadedLeagues = [];
|
||||||
|
let currentMode = 'combine'; // 'combine' or 'convert'
|
||||||
|
|
||||||
|
const uploadArea = document.getElementById('uploadArea');
|
||||||
|
const fileInput = document.getElementById('fileInput');
|
||||||
|
const uploadedFilesDiv = document.getElementById('uploadedFiles');
|
||||||
|
const clearBtn = document.getElementById('clearBtn');
|
||||||
|
const processBtn = document.getElementById('processBtn');
|
||||||
|
const processBtnText = document.getElementById('processBtnText');
|
||||||
|
const previewSection = document.getElementById('previewSection');
|
||||||
|
|
||||||
|
// Helper function to get translated text
|
||||||
|
function t(key) {
|
||||||
|
if (window.i18n && window.i18n.t) {
|
||||||
|
return window.i18n.t(key);
|
||||||
|
}
|
||||||
|
// Fallback if i18n not loaded yet
|
||||||
|
return key.split('.').pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
function switchMode(mode) {
|
||||||
|
currentMode = mode;
|
||||||
|
|
||||||
|
// Update button states
|
||||||
|
document.getElementById('combineMode').classList.toggle('active', mode === 'combine');
|
||||||
|
document.getElementById('convertMode').classList.toggle('active', mode === 'convert');
|
||||||
|
|
||||||
|
// Update sections
|
||||||
|
document.getElementById('combineSection').style.display = mode === 'combine' ? 'block' : 'none';
|
||||||
|
document.getElementById('convertSection').style.display = mode === 'convert' ? 'block' : 'none';
|
||||||
|
|
||||||
|
// Update button text with translations
|
||||||
|
processBtnText.innerHTML = mode === 'combine'
|
||||||
|
? '🔗 <span data-i18n="league.combine_preview">Combine & Preview</span>'
|
||||||
|
: '🔄 <span data-i18n="league.convert_to_league">Convert to League</span>';
|
||||||
|
// Re-apply translations after DOM change
|
||||||
|
if (window.i18n) window.i18n.updatePageTranslations();
|
||||||
|
|
||||||
|
// Clear uploaded files
|
||||||
|
uploadedLeagues = [];
|
||||||
|
updateFileList();
|
||||||
|
previewSection.classList.remove('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Click to upload
|
||||||
|
uploadArea.addEventListener('click', () => fileInput.click());
|
||||||
|
|
||||||
|
// Drag and drop
|
||||||
|
uploadArea.addEventListener('dragover', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
uploadArea.classList.add('drag-over');
|
||||||
|
});
|
||||||
|
|
||||||
|
uploadArea.addEventListener('dragleave', () => {
|
||||||
|
uploadArea.classList.remove('drag-over');
|
||||||
|
});
|
||||||
|
|
||||||
|
uploadArea.addEventListener('drop', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
uploadArea.classList.remove('drag-over');
|
||||||
|
handleFiles(e.dataTransfer.files);
|
||||||
|
});
|
||||||
|
|
||||||
|
// File input change
|
||||||
|
fileInput.addEventListener('change', (e) => {
|
||||||
|
handleFiles(e.target.files);
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleFiles(files) {
|
||||||
|
Array.from(files).forEach(file => {
|
||||||
|
if (file.type === 'application/json' || file.name.endsWith('.json')) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = (e) => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(e.target.result);
|
||||||
|
|
||||||
|
if (currentMode === 'combine') {
|
||||||
|
// Validate it's a league file (handles both archived and raw formats)
|
||||||
|
let leagueData = null;
|
||||||
|
if (data.league && data.league.participants) {
|
||||||
|
// Archived format (wrapped)
|
||||||
|
leagueData = data.league;
|
||||||
|
} else if (data.participants) {
|
||||||
|
// Raw league format (unwrapped)
|
||||||
|
leagueData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leagueData) {
|
||||||
|
uploadedLeagues.push({
|
||||||
|
filename: file.name,
|
||||||
|
data: data,
|
||||||
|
leagueData: leagueData, // Store the actual league data
|
||||||
|
valid: true,
|
||||||
|
type: 'league'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
uploadedLeagues.push({
|
||||||
|
filename: file.name,
|
||||||
|
error: 'Invalid league file format',
|
||||||
|
valid: false,
|
||||||
|
type: 'league'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Convert mode - validate it's a tournament file
|
||||||
|
if (data.tournament && data.results && data.results.participants) {
|
||||||
|
uploadedLeagues.push({
|
||||||
|
filename: file.name,
|
||||||
|
data: data,
|
||||||
|
valid: true,
|
||||||
|
type: 'tournament'
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
uploadedLeagues.push({
|
||||||
|
filename: file.name,
|
||||||
|
error: t('league.invalid_tournament_format'),
|
||||||
|
valid: false,
|
||||||
|
type: 'tournament'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFileList();
|
||||||
|
} catch (error) {
|
||||||
|
uploadedLeagues.push({
|
||||||
|
filename: file.name,
|
||||||
|
error: t('league.failed_parse_json'),
|
||||||
|
valid: false
|
||||||
|
});
|
||||||
|
updateFileList();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
reader.readAsText(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateFileList() {
|
||||||
|
uploadedFilesDiv.innerHTML = '';
|
||||||
|
|
||||||
|
if (uploadedLeagues.length > 0) {
|
||||||
|
const heading = document.createElement('h3');
|
||||||
|
heading.textContent = `📋 ${t('league.uploaded_files')} (${uploadedLeagues.length})`;
|
||||||
|
uploadedFilesDiv.appendChild(heading);
|
||||||
|
|
||||||
|
uploadedLeagues.forEach((league, index) => {
|
||||||
|
const fileItem = document.createElement('div');
|
||||||
|
fileItem.className = 'file-item' + (league.valid ? '' : ' error');
|
||||||
|
|
||||||
|
const fileInfo = document.createElement('div');
|
||||||
|
fileInfo.className = 'file-info';
|
||||||
|
|
||||||
|
const fileName = document.createElement('div');
|
||||||
|
fileName.className = 'file-name';
|
||||||
|
fileName.textContent = league.filename;
|
||||||
|
|
||||||
|
const fileDetails = document.createElement('div');
|
||||||
|
fileDetails.className = 'file-details';
|
||||||
|
|
||||||
|
if (league.valid) {
|
||||||
|
if (league.type === 'league') {
|
||||||
|
const participantCount = Object.keys(league.leagueData.participants).length;
|
||||||
|
const tournamentCount = league.leagueData.total_tournaments || 0;
|
||||||
|
fileDetails.textContent = `✓ ${t('league.valid_league')} | ${participantCount} ${t('league.participants')} | ${tournamentCount} ${t('league.tournaments')}`;
|
||||||
|
} else {
|
||||||
|
const participantCount = Object.keys(league.data.results.participants).length;
|
||||||
|
const tournamentType = league.data.results.tournament_type || '20_targets';
|
||||||
|
fileDetails.textContent = `✓ ${t('league.valid_tournament')} | ${participantCount} ${t('league.participants')} | ${t('league.type')}: ${tournamentType}`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fileDetails.textContent = `✗ ${league.error}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileInfo.appendChild(fileName);
|
||||||
|
fileInfo.appendChild(fileDetails);
|
||||||
|
|
||||||
|
const removeBtn = document.createElement('button');
|
||||||
|
removeBtn.className = 'remove-btn';
|
||||||
|
removeBtn.textContent = `✗ ${t('league.remove')}`;
|
||||||
|
removeBtn.onclick = () => removeFile(index);
|
||||||
|
|
||||||
|
fileItem.appendChild(fileInfo);
|
||||||
|
fileItem.appendChild(removeBtn);
|
||||||
|
uploadedFilesDiv.appendChild(fileItem);
|
||||||
|
});
|
||||||
|
|
||||||
|
clearBtn.disabled = false;
|
||||||
|
|
||||||
|
const validCount = uploadedLeagues.filter(l => l.valid).length;
|
||||||
|
if (currentMode === 'combine') {
|
||||||
|
processBtn.disabled = validCount < 1; // Allow preview with 1+ files
|
||||||
|
} else {
|
||||||
|
// Convert mode requires 1-5 tournament files
|
||||||
|
processBtn.disabled = validCount < 1 || validCount > 5;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
clearBtn.disabled = true;
|
||||||
|
processBtn.disabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeFile(index) {
|
||||||
|
uploadedLeagues.splice(index, 1);
|
||||||
|
updateFileList();
|
||||||
|
}
|
||||||
|
|
||||||
|
clearBtn.addEventListener('click', () => {
|
||||||
|
uploadedLeagues = [];
|
||||||
|
updateFileList();
|
||||||
|
previewSection.classList.remove('active');
|
||||||
|
});
|
||||||
|
|
||||||
|
processBtn.addEventListener('click', async () => {
|
||||||
|
const validFiles = uploadedLeagues.filter(l => l.valid);
|
||||||
|
|
||||||
|
if (currentMode === 'combine') {
|
||||||
|
if (validFiles.length < 1) {
|
||||||
|
alert('Please upload at least 1 valid league file');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send to backend for combination
|
||||||
|
const response = await fetch('/api/league/combine', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
leagues: validFiles.map(l => l.leagueData)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
// Store in session and redirect to preview
|
||||||
|
const previewResponse = await fetch('/league/set-preview', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
league: result.combined_league
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (previewResponse.ok) {
|
||||||
|
const previewResult = await previewResponse.json();
|
||||||
|
window.location.href = previewResult.redirect_url;
|
||||||
|
} else {
|
||||||
|
alert('Failed to preview league');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert('Failed to combine leagues');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Convert mode
|
||||||
|
if (validFiles.length < 1 || validFiles.length > 5) {
|
||||||
|
alert('Please upload 1-5 valid tournament files');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send to backend for conversion
|
||||||
|
const response = await fetch('/api/league/convert', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
tournaments: validFiles.map(l => l.data)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const result = await response.json();
|
||||||
|
|
||||||
|
// Store in session and redirect to preview
|
||||||
|
const previewResponse = await fetch('/league/set-preview', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
league: result.combined_league
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (previewResponse.ok) {
|
||||||
|
const previewResult = await previewResponse.json();
|
||||||
|
window.location.href = previewResult.redirect_url;
|
||||||
|
} else {
|
||||||
|
alert('Failed to preview league');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alert('Failed to convert tournaments to league');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function displayCombinedResults(result) {
|
||||||
|
// Display combined info
|
||||||
|
const sourceType = result.is_partial !== undefined ?
|
||||||
|
(result.is_partial ? 'tournament files (Partial League)' : 'tournament files (Complete League)') :
|
||||||
|
'league files';
|
||||||
|
|
||||||
|
document.getElementById('combinedInfo').innerHTML = `
|
||||||
|
<p><strong>Combined from:</strong> ${result.source_count} ${sourceType}</p>
|
||||||
|
<p><strong>Tournament Type:</strong> ${result.tournament_type}</p>
|
||||||
|
<p><strong>Total Participants:</strong> ${result.total_participants}</p>
|
||||||
|
${result.is_partial ? '<p style="color: #ff9800;"><strong>⚠️ Partial League:</strong> Upload more tournaments to complete the league (5 total needed)</p>' : ''}
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Display stats
|
||||||
|
const statsGrid = document.getElementById('statsGrid');
|
||||||
|
statsGrid.innerHTML = `
|
||||||
|
<div class="stat-card">
|
||||||
|
<div class="stat-value">${result.total_participants}</div>
|
||||||
|
<div class="stat-label">Total Players</div>
|
||||||
|
</div>
|
||||||
|
<div class="stat-card">
|
||||||
|
<div class="stat-value">${result.total_tournaments}</div>
|
||||||
|
<div class="stat-label">Total Tournaments</div>
|
||||||
|
</div>
|
||||||
|
<div class="stat-card">
|
||||||
|
<div class="stat-value">${result.highest_score}</div>
|
||||||
|
<div class="stat-label">Highest Score</div>
|
||||||
|
</div>
|
||||||
|
<div class="stat-card">
|
||||||
|
<div class="stat-value">${result.avg_score}</div>
|
||||||
|
<div class="stat-label">Average Score</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
// Store combined data for export
|
||||||
|
window.combinedLeagueData = result.combined_league;
|
||||||
|
|
||||||
|
// Redirect to results display with combined data
|
||||||
|
displayResultsTable(result.participants);
|
||||||
|
}
|
||||||
|
|
||||||
|
function displayResultsTable(participants) {
|
||||||
|
const resultsDisplay = document.getElementById('resultsDisplay');
|
||||||
|
|
||||||
|
let html = `
|
||||||
|
<h2>🏆 Combined Results</h2>
|
||||||
|
<table style="width: 100%; border-collapse: collapse; margin-top: 20px;">
|
||||||
|
<thead>
|
||||||
|
<tr style="background: #667eea; color: white;">
|
||||||
|
<th style="padding: 12px; text-align: left;">Rank</th>
|
||||||
|
<th style="padding: 12px; text-align: left;">Player</th>
|
||||||
|
<th style="padding: 12px; text-align: center;">Final Score</th>
|
||||||
|
<th style="padding: 12px; text-align: center;">Total Score</th>
|
||||||
|
<th style="padding: 12px; text-align: center;">Tournaments</th>
|
||||||
|
<th style="padding: 12px; text-align: center;">10s</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
`;
|
||||||
|
|
||||||
|
participants.forEach((p, i) => {
|
||||||
|
html += `
|
||||||
|
<tr style="border-bottom: 1px solid #dee2e6; ${i % 2 === 0 ? 'background: #f8f9fa;' : ''}">
|
||||||
|
<td style="padding: 12px; font-weight: bold;">${i + 1}</td>
|
||||||
|
<td style="padding: 12px;">${p.name}</td>
|
||||||
|
<td style="padding: 12px; text-align: center; font-weight: bold; color: #667eea;">${p.final_score}</td>
|
||||||
|
<td style="padding: 12px; text-align: center;">${p.total_score}</td>
|
||||||
|
<td style="padding: 12px; text-align: center;">${p.tournaments_participated}</td>
|
||||||
|
<td style="padding: 12px; text-align: center;">${p.total_tens}</td>
|
||||||
|
</tr>
|
||||||
|
`;
|
||||||
|
});
|
||||||
|
|
||||||
|
html += `
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
`;
|
||||||
|
|
||||||
|
resultsDisplay.innerHTML = html;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('exportBtn').addEventListener('click', () => {
|
||||||
|
if (window.combinedLeagueData) {
|
||||||
|
// Wrap in archive format to be compatible with results display
|
||||||
|
const archiveData = {
|
||||||
|
league: window.combinedLeagueData,
|
||||||
|
archived_at: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataStr = JSON.stringify(archiveData, null, 2);
|
||||||
|
const dataBlob = new Blob([dataStr], { type: 'application/json' });
|
||||||
|
const url = URL.createObjectURL(dataBlob);
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = `combined_league_${new Date().toISOString().slice(0, 10)}.json`;
|
||||||
|
link.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -787,6 +787,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="navbar-controls">
|
<div class="navbar-controls">
|
||||||
<a href="/" class="nav-btn">📺 <span data-i18n="navigation.dashboard">Dashboard</span></a>
|
<a href="/" class="nav-btn">📺 <span data-i18n="navigation.dashboard">Dashboard</span></a>
|
||||||
|
<button class="nav-btn" onclick="exportLeagueJSON()">💾 <span data-i18n="general.export">Export JSON</span></button>
|
||||||
<button class="nav-btn" onclick="window.print()">🖨️ <span data-i18n="general.print">Print</span></button>
|
<button class="nav-btn" onclick="window.print()">🖨️ <span data-i18n="general.print">Print</span></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1199,6 +1200,31 @@
|
|||||||
// Initialize when page loads
|
// Initialize when page loads
|
||||||
document.addEventListener('DOMContentLoaded', initializePage);
|
document.addEventListener('DOMContentLoaded', initializePage);
|
||||||
|
|
||||||
|
// Export league data as JSON
|
||||||
|
function exportLeagueJSON() {
|
||||||
|
const leagueData = {{ league | tojson | safe }};
|
||||||
|
|
||||||
|
// Wrap in archive format for compatibility
|
||||||
|
const archiveData = {
|
||||||
|
league: leagueData,
|
||||||
|
archived_at: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataStr = JSON.stringify(archiveData, null, 2);
|
||||||
|
const dataBlob = new Blob([dataStr], { type: 'application/json' });
|
||||||
|
const url = URL.createObjectURL(dataBlob);
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
|
||||||
|
// Generate filename with league info
|
||||||
|
const leagueId = leagueData.league_id || 'league';
|
||||||
|
const date = new Date().toISOString().slice(0, 10);
|
||||||
|
link.download = `${leagueId}_${date}.json`;
|
||||||
|
|
||||||
|
link.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
// Keyboard shortcuts
|
// Keyboard shortcuts
|
||||||
document.addEventListener('keydown', function(event) {
|
document.addEventListener('keydown', function(event) {
|
||||||
if (event.key === 'r' || event.key === 'R') {
|
if (event.key === 'r' || event.key === 'R') {
|
||||||
|
|||||||
@@ -657,6 +657,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="navbar-controls">
|
<div class="navbar-controls">
|
||||||
<a href="/" class="nav-btn">📺 <span data-i18n="navigation.dashboard">Dashboard</span></a>
|
<a href="/" class="nav-btn">📺 <span data-i18n="navigation.dashboard">Dashboard</span></a>
|
||||||
|
<button class="nav-btn" onclick="exportResultsJSON()">💾 <span data-i18n="general.export">Export JSON</span></button>
|
||||||
<button class="nav-btn" onclick="printResults()">🖨️ <span data-i18n="general.print">Print</span></button>
|
<button class="nav-btn" onclick="printResults()">🖨️ <span data-i18n="general.print">Print</span></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -962,6 +963,33 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Export results as JSON
|
||||||
|
function exportResultsJSON() {
|
||||||
|
const tournamentData = {{ tournament | tojson | safe }};
|
||||||
|
const resultsData = {{ results | tojson | safe }};
|
||||||
|
|
||||||
|
// Wrap in archive format for compatibility
|
||||||
|
const archiveData = {
|
||||||
|
tournament: tournamentData,
|
||||||
|
results: resultsData,
|
||||||
|
archived_at: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataStr = JSON.stringify(archiveData, null, 2);
|
||||||
|
const dataBlob = new Blob([dataStr], { type: 'application/json' });
|
||||||
|
const url = URL.createObjectURL(dataBlob);
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
|
||||||
|
// Generate filename with tournament info
|
||||||
|
const tournamentId = tournamentData.tournament_id || 'tournament';
|
||||||
|
const date = new Date().toISOString().slice(0, 10);
|
||||||
|
link.download = `${tournamentId}_${date}.json`;
|
||||||
|
|
||||||
|
link.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize when page loads
|
// Initialize when page loads
|
||||||
document.addEventListener('DOMContentLoaded', initializePage);
|
document.addEventListener('DOMContentLoaded', initializePage);
|
||||||
|
|
||||||
|
|||||||
@@ -1087,7 +1087,21 @@ def results_display():
|
|||||||
translations=get_translations(),
|
translations=get_translations(),
|
||||||
current_language=get_current_language())
|
current_language=get_current_language())
|
||||||
|
|
||||||
# Priority 1.5: Check if current results are from a finished league (even if league state was archived)
|
# Priority 1.5: Check if results contain league_data (from league preview/combiner)
|
||||||
|
elif results and results.get('league_data'):
|
||||||
|
league_data = results.get('league_data')
|
||||||
|
calculate_league_final_scores(league_data)
|
||||||
|
participants = get_league_final_rankings(league_data)
|
||||||
|
|
||||||
|
return render_template('league_scoreboard_display.html',
|
||||||
|
league=league_data,
|
||||||
|
participants=participants,
|
||||||
|
results=None,
|
||||||
|
preview_mode=True,
|
||||||
|
translations=get_translations(),
|
||||||
|
current_language=get_current_language())
|
||||||
|
|
||||||
|
# Priority 1.6: Check if current results are from a finished league (even if league state was archived)
|
||||||
elif results and results.get('league_tournament_number'):
|
elif results and results.get('league_tournament_number'):
|
||||||
# This is a league tournament result, but league state was archived
|
# This is a league tournament result, but league state was archived
|
||||||
# Try to find the archived league data
|
# Try to find the archived league data
|
||||||
@@ -1697,7 +1711,327 @@ def get_league():
|
|||||||
return jsonify(league_state)
|
return jsonify(league_state)
|
||||||
else:
|
else:
|
||||||
return jsonify({'status': 'error', 'message': 'No league found'}), 404
|
return jsonify({'status': 'error', 'message': 'No league found'}), 404
|
||||||
|
|
||||||
|
@app.route('/league/combine')
|
||||||
|
def league_combine_page():
|
||||||
|
"""Page for combining multiple league JSON files"""
|
||||||
|
if is_mobile_device():
|
||||||
|
return redirect('/mobile')
|
||||||
|
|
||||||
|
return render_template('league_combine.html',
|
||||||
|
translations=get_translations(),
|
||||||
|
current_language=get_current_language())
|
||||||
|
|
||||||
|
@app.route('/league/preview')
|
||||||
|
def league_preview():
|
||||||
|
"""Display league preview from session"""
|
||||||
|
# Get league data from session
|
||||||
|
league_data = session.get('preview_league')
|
||||||
|
|
||||||
|
if not league_data:
|
||||||
|
return redirect('/league/combine')
|
||||||
|
|
||||||
|
# Calculate scores and get rankings
|
||||||
|
calculate_league_final_scores(league_data)
|
||||||
|
participants = get_league_final_rankings(league_data)
|
||||||
|
|
||||||
|
return render_template('league_scoreboard_display.html',
|
||||||
|
league=league_data,
|
||||||
|
participants=participants,
|
||||||
|
results=None,
|
||||||
|
preview_mode=True,
|
||||||
|
translations=get_translations(),
|
||||||
|
current_language=get_current_language())
|
||||||
|
|
||||||
|
@app.route('/league/set-preview', methods=['POST'])
|
||||||
|
def set_league_preview():
|
||||||
|
"""Store league data in session for preview"""
|
||||||
|
try:
|
||||||
|
data = request.get_json()
|
||||||
|
combined_league = data.get('league')
|
||||||
|
|
||||||
|
if not combined_league:
|
||||||
|
return jsonify({'status': 'error', 'message': 'No league data provided'}), 400
|
||||||
|
|
||||||
|
# Store in session
|
||||||
|
session['preview_league'] = combined_league
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'status': 'success',
|
||||||
|
'redirect_url': '/league/preview'
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error setting league preview: {e}")
|
||||||
|
return jsonify({'status': 'error', 'message': str(e)}), 500
|
||||||
|
|
||||||
|
@app.route('/api/league/combine', methods=['POST'])
|
||||||
|
def combine_leagues():
|
||||||
|
"""API endpoint to combine multiple league files"""
|
||||||
|
try:
|
||||||
|
data = request.get_json()
|
||||||
|
leagues = data.get('leagues', [])
|
||||||
|
|
||||||
|
if len(leagues) < 1:
|
||||||
|
return jsonify({'status': 'error', 'message': 'Need at least 1 league'}), 400
|
||||||
|
|
||||||
|
# If only one league, just return it for preview
|
||||||
|
if len(leagues) == 1:
|
||||||
|
league = leagues[0]
|
||||||
|
calculate_league_final_scores(league)
|
||||||
|
participants = get_league_final_rankings(league)
|
||||||
|
|
||||||
|
highest_score = max((p['final_score'] for p in participants), default=0)
|
||||||
|
avg_score = sum(p['final_score'] for p in participants) / len(participants) if participants else 0
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'status': 'success',
|
||||||
|
'combined_league': league,
|
||||||
|
'participants': participants,
|
||||||
|
'source_count': 1,
|
||||||
|
'tournament_type': league.get('tournament_type', '20_targets'),
|
||||||
|
'total_participants': len(participants),
|
||||||
|
'total_tournaments': league.get('total_tournaments', 5),
|
||||||
|
'highest_score': highest_score,
|
||||||
|
'avg_score': round(avg_score, 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
# Get tournament type from first league
|
||||||
|
tournament_type = leagues[0].get('tournament_type', '20_targets')
|
||||||
|
|
||||||
|
# Create combined league structure
|
||||||
|
combined_league = {
|
||||||
|
'league_id': f'combined_{datetime.now().strftime("%Y%m%d_%H%M%S")}',
|
||||||
|
'created_at': datetime.now().isoformat(),
|
||||||
|
'tournament_type': tournament_type,
|
||||||
|
'total_tournaments': sum(len(league.get('completed_tournaments', [])) for league in leagues),
|
||||||
|
'current_tournament': 0,
|
||||||
|
'participants': {},
|
||||||
|
'completed_tournaments': [],
|
||||||
|
'league_finished': True,
|
||||||
|
'combined_from': len(leagues)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build name-to-player mapping for combining by name
|
||||||
|
name_to_combined_id = {} # Maps player name to their ID in combined league
|
||||||
|
next_player_id = 1
|
||||||
|
|
||||||
|
# Combine tournament results from all leagues
|
||||||
|
tournament_counter = 0
|
||||||
|
for league_idx, league in enumerate(leagues):
|
||||||
|
# Process each participant in this league
|
||||||
|
for player_id, league_participant in league.get('participants', {}).items():
|
||||||
|
player_name = league_participant.get('name', f'Player {player_id}')
|
||||||
|
|
||||||
|
# Check if we've seen this player name before
|
||||||
|
if player_name in name_to_combined_id:
|
||||||
|
# Use existing combined player
|
||||||
|
combined_id = name_to_combined_id[player_name]
|
||||||
|
else:
|
||||||
|
# Create new combined player
|
||||||
|
combined_id = str(next_player_id)
|
||||||
|
next_player_id += 1
|
||||||
|
name_to_combined_id[player_name] = combined_id
|
||||||
|
|
||||||
|
# Initialize new participant
|
||||||
|
combined_league['participants'][combined_id] = {
|
||||||
|
'name': player_name,
|
||||||
|
'joker_used': False,
|
||||||
|
'tournament_results': [],
|
||||||
|
'total_score': 0,
|
||||||
|
'final_score': 0,
|
||||||
|
'tournaments_participated': 0
|
||||||
|
}
|
||||||
|
|
||||||
|
combined_participant = combined_league['participants'][combined_id]
|
||||||
|
|
||||||
|
# Add all tournament results from this league
|
||||||
|
for result in league_participant.get('tournament_results', []):
|
||||||
|
combined_participant['tournament_results'].append({
|
||||||
|
'tournament': tournament_counter + result.get('tournament', 0),
|
||||||
|
'score': result.get('score', 0),
|
||||||
|
'tens_count': result.get('tens_count', 0),
|
||||||
|
'participated': result.get('participated', True),
|
||||||
|
'source_league': league_idx + 1
|
||||||
|
})
|
||||||
|
|
||||||
|
if result.get('participated', True):
|
||||||
|
combined_participant['tournaments_participated'] += 1
|
||||||
|
combined_participant['total_score'] += result.get('score', 0)
|
||||||
|
|
||||||
|
# Add completed tournaments
|
||||||
|
for completed in league.get('completed_tournaments', []):
|
||||||
|
combined_league['completed_tournaments'].append({
|
||||||
|
**completed,
|
||||||
|
'source_league': league_idx + 1
|
||||||
|
})
|
||||||
|
|
||||||
|
tournament_counter += len(league.get('completed_tournaments', []))
|
||||||
|
|
||||||
|
# Calculate final scores
|
||||||
|
calculate_league_final_scores(combined_league)
|
||||||
|
|
||||||
|
# Get rankings
|
||||||
|
participants = get_league_final_rankings(combined_league)
|
||||||
|
|
||||||
|
# Calculate stats
|
||||||
|
highest_score = max((p['final_score'] for p in participants), default=0)
|
||||||
|
avg_score = sum(p['final_score'] for p in participants) / len(participants) if participants else 0
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'status': 'success',
|
||||||
|
'combined_league': combined_league,
|
||||||
|
'participants': participants,
|
||||||
|
'source_count': len(leagues),
|
||||||
|
'tournament_type': tournament_type,
|
||||||
|
'total_participants': len(participants),
|
||||||
|
'total_tournaments': combined_league['total_tournaments'],
|
||||||
|
'highest_score': highest_score,
|
||||||
|
'avg_score': round(avg_score, 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error combining leagues: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
return jsonify({'status': 'error', 'message': str(e)}), 400
|
||||||
|
|
||||||
|
@app.route('/api/league/convert', methods=['POST'])
|
||||||
|
def convert_tournaments_to_league():
|
||||||
|
"""API endpoint to convert 1-5 tournament files into a league"""
|
||||||
|
try:
|
||||||
|
data = request.get_json()
|
||||||
|
tournaments = data.get('tournaments', [])
|
||||||
|
|
||||||
|
if len(tournaments) < 1 or len(tournaments) > 5:
|
||||||
|
return jsonify({'status': 'error', 'message': 'Need 1-5 tournament files'}), 400
|
||||||
|
|
||||||
|
# Sort tournaments by finished_at timestamp to maintain chronological order
|
||||||
|
tournaments.sort(key=lambda t: t.get('results', {}).get('finished_at', ''))
|
||||||
|
|
||||||
|
# Get tournament type from first tournament
|
||||||
|
tournament_type = tournaments[0].get('results', {}).get('tournament_type', '20_targets')
|
||||||
|
num_tournaments = len(tournaments)
|
||||||
|
|
||||||
|
# Collect all unique participants
|
||||||
|
all_player_ids = set()
|
||||||
|
for tournament in tournaments:
|
||||||
|
results = tournament.get('results', {})
|
||||||
|
all_player_ids.update(results.get('participants', {}).keys())
|
||||||
|
|
||||||
|
# Create league structure
|
||||||
|
created_league = {
|
||||||
|
'league_id': f'converted_{datetime.now().strftime("%Y%m%d_%H%M%S")}',
|
||||||
|
'created_at': datetime.now().isoformat(),
|
||||||
|
'tournament_type': tournament_type,
|
||||||
|
'total_tournaments': 5, # Always 5 for a full league
|
||||||
|
'current_tournament': num_tournaments, # How many completed so far
|
||||||
|
'participants': {},
|
||||||
|
'completed_tournaments': [],
|
||||||
|
'league_finished': num_tournaments >= 5, # Only finished if all 5 uploaded
|
||||||
|
'converted_from_tournaments': True,
|
||||||
|
'is_partial': num_tournaments < 5
|
||||||
|
}
|
||||||
|
|
||||||
|
# Initialize participants
|
||||||
|
for player_id in all_player_ids:
|
||||||
|
created_league['participants'][player_id] = {
|
||||||
|
'name': '',
|
||||||
|
'joker_used': False,
|
||||||
|
'tournament_results': [],
|
||||||
|
'total_score': 0,
|
||||||
|
'final_score': 0,
|
||||||
|
'tournaments_participated': 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process each tournament
|
||||||
|
for tournament_idx, tournament in enumerate(tournaments):
|
||||||
|
results = tournament.get('results', {})
|
||||||
|
tournament_results_data = results.get('participants', {})
|
||||||
|
|
||||||
|
# Add completed tournament metadata
|
||||||
|
created_league['completed_tournaments'].append({
|
||||||
|
'tournament_number': tournament_idx + 1,
|
||||||
|
'tournament_type': results.get('tournament_type', tournament_type),
|
||||||
|
'finished_at': results.get('finished_at', datetime.now().isoformat()),
|
||||||
|
'results_summary': {
|
||||||
|
'participants': len(tournament_results_data),
|
||||||
|
'tournament_id': tournament.get('tournament', {}).get('tournament_id', f'tournament_{tournament_idx + 1}')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
# Add results for each participant
|
||||||
|
for player_id in all_player_ids:
|
||||||
|
league_participant = created_league['participants'][player_id]
|
||||||
|
|
||||||
|
if player_id in tournament_results_data:
|
||||||
|
participant_data = tournament_results_data[player_id]
|
||||||
|
|
||||||
|
# Set name if not set
|
||||||
|
if not league_participant['name']:
|
||||||
|
league_participant['name'] = participant_data.get('name', f'Player {player_id}')
|
||||||
|
|
||||||
|
# Count tens
|
||||||
|
tens_count = 0
|
||||||
|
targets = participant_data.get('targets', {})
|
||||||
|
for target in targets.values():
|
||||||
|
for shot_key, shot_value in target.items():
|
||||||
|
if shot_key.startswith('shot') and shot_value == 10:
|
||||||
|
tens_count += 1
|
||||||
|
|
||||||
|
# Add tournament result
|
||||||
|
score = participant_data.get('total_score', 0)
|
||||||
|
league_participant['tournament_results'].append({
|
||||||
|
'tournament': tournament_idx + 1,
|
||||||
|
'score': score,
|
||||||
|
'tens_count': tens_count,
|
||||||
|
'participated': True
|
||||||
|
})
|
||||||
|
|
||||||
|
league_participant['tournaments_participated'] += 1
|
||||||
|
league_participant['total_score'] += score
|
||||||
|
else:
|
||||||
|
# Player didn't participate (used joker)
|
||||||
|
league_participant['tournament_results'].append({
|
||||||
|
'tournament': tournament_idx + 1,
|
||||||
|
'score': 0,
|
||||||
|
'tens_count': 0,
|
||||||
|
'participated': False,
|
||||||
|
'joker': True
|
||||||
|
})
|
||||||
|
|
||||||
|
if tournament_idx == 0:
|
||||||
|
# Set joker_used for players who didn't participate in first tournament
|
||||||
|
league_participant['joker_used'] = True
|
||||||
|
|
||||||
|
# Calculate final scores using league rules
|
||||||
|
calculate_league_final_scores(created_league)
|
||||||
|
|
||||||
|
# Get rankings
|
||||||
|
participants = get_league_final_rankings(created_league)
|
||||||
|
|
||||||
|
# Calculate stats
|
||||||
|
highest_score = max((p['final_score'] for p in participants), default=0)
|
||||||
|
avg_score = sum(p['final_score'] for p in participants) / len(participants) if participants else 0
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'status': 'success',
|
||||||
|
'combined_league': created_league,
|
||||||
|
'participants': participants,
|
||||||
|
'source_count': num_tournaments,
|
||||||
|
'tournament_type': tournament_type,
|
||||||
|
'total_participants': len(participants),
|
||||||
|
'total_tournaments': num_tournaments,
|
||||||
|
'is_partial': num_tournaments < 5,
|
||||||
|
'highest_score': highest_score,
|
||||||
|
'avg_score': round(avg_score, 2)
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error converting tournaments to league: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
return jsonify({'status': 'error', 'message': str(e)}), 400
|
||||||
|
|
||||||
# Add this route to your Flask app (around line 850, with the other mobile routes)
|
# Add this route to your Flask app (around line 850, with the other mobile routes)
|
||||||
|
|
||||||
@app.route('/mobile/remote')
|
@app.route('/mobile/remote')
|
||||||
|
|||||||
Reference in New Issue
Block a user