Add extra DB functions

This commit is contained in:
2025-10-04 16:47:40 +08:00
parent 131f17947c
commit 0c60a4b4d8
3 changed files with 489 additions and 19 deletions
+8
View File
@@ -144,6 +144,14 @@
</a>
</div>
</div>
<div class="col-md-4">
<div class="list-group card-custom">
<a href="/admin/motm/manage" class="list-group-item">
<h4 class="list-group-item-heading">MOTM Management</h4>
<p class="list-group-item-text">Reset MOTM/DotD counts for specific fixtures</p>
</a>
</div>
</div>
<div class="col-md-4">
<div class="list-group card-custom">
<a href="/admin/poty" class="list-group-item">
+272
View File
@@ -0,0 +1,272 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MOTM Management - HKFC Men's C Team</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.fixture-header {
background-color: #f8f9fa;
font-weight: bold;
}
.reset-section {
background-color: #fff3cd;
border: 1px solid #ffeaa7;
border-radius: 0.375rem;
padding: 1rem;
margin-bottom: 2rem;
}
.data-section {
background-color: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 0.375rem;
padding: 1rem;
margin-bottom: 2rem;
}
</style>
</head>
<body>
<div class="container mt-4">
<div class="row">
<div class="col-md-12">
<h1>MOTM/DotD Management</h1>
<p class="lead">Manage and reset Man of the Match and Dick of the Day counts</p>
<div class="mb-3">
<a href="/admin" class="btn btn-outline-primary">Back to Admin Dashboard</a>
<a href="/admin/motm" class="btn btn-outline-secondary">MOTM Admin</a>
</div>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ 'danger' if category == 'error' else 'success' }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
{% endfor %}
{% endif %}
{% endwith %}
<!-- Reset Controls -->
<div class="reset-section">
<h3>Reset Controls</h3>
<p class="text-muted">Use these controls to reset MOTM/DotD counts for specific fixtures or all data.</p>
<div class="row">
<div class="col-md-4">
<h5>Reset Specific Fixture</h5>
<form method="POST" onsubmit="return confirm('Are you sure you want to reset MOTM/DotD counts for this fixture?')">
<input type="hidden" name="action" value="reset_fixture">
<div class="mb-3">
<select name="fixture_date" class="form-select" required>
<option value="">Select fixture date...</option>
{% for date in fixture_dates %}
<option value="{{ date }}">{{ date }}</option>
{% endfor %}
</select>
</div>
<button type="submit" class="btn btn-warning">Reset Fixture</button>
</form>
</div>
<div class="col-md-4">
<h5>Reset All Totals</h5>
<p class="text-muted">Reset motmtotal, dotdtotal, assiststotal, goalstotal columns</p>
<form method="POST" onsubmit="return confirm('Are you sure you want to reset all MOTM/DotD totals? This will affect the Player of the Year calculations.')">
<input type="hidden" name="action" value="reset_totals">
<button type="submit" class="btn btn-danger">Reset All Totals</button>
</form>
</div>
<div class="col-md-4">
<h5>Reset Everything</h5>
<p class="text-muted">Reset all MOTM/DotD data including fixture-specific columns</p>
<form method="POST" onsubmit="return confirm('Are you sure you want to reset ALL MOTM/DotD data? This action cannot be undone.')">
<input type="hidden" name="action" value="reset_all">
<button type="submit" class="btn btn-danger">Reset Everything</button>
</form>
</div>
</div>
<div class="row mt-3">
<div class="col-md-4">
<h5>Sync Totals</h5>
<p class="text-muted">Update stored totals to match calculated values from fixture columns</p>
<form method="POST" onsubmit="return confirm('Sync stored totals with calculated values?')">
<input type="hidden" name="action" value="sync_totals">
<button type="submit" class="btn btn-info">Sync Totals</button>
</form>
</div>
</div>
</div>
<!-- Current Data Display -->
<div class="data-section">
<h3>Current MOTM/DotD Data</h3>
{% if motm_data %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="table-dark">
<tr>
<th>Player #</th>
<th>Player Name</th>
<th>MOTM Total</th>
<th>DotD Total</th>
<th>Goals Total</th>
<th>Assists Total</th>
{% for date in fixture_dates %}
<th class="fixture-header">MOTM {{ date }}</th>
<th class="fixture-header">DotD {{ date }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for player in motm_data %}
<tr>
<td>{{ player.playernumber }}</td>
<td>{{ player.playername }}</td>
<td>
<span class="badge bg-primary">{{ player.calculated_motmtotal or 0 }}</span>
{% if player.motmtotal != player.calculated_motmtotal %}
<small class="text-warning">(stored: {{ player.motmtotal or 0 }})</small>
{% endif %}
</td>
<td>
<span class="badge bg-secondary">{{ player.calculated_dotdtotal or 0 }}</span>
{% if player.dotdtotal != player.calculated_dotdtotal %}
<small class="text-warning">(stored: {{ player.dotdtotal or 0 }})</small>
{% endif %}
</td>
<td>
<span class="badge bg-success">{{ player.goalstotal or 0 }}</span>
</td>
<td>
<span class="badge bg-info">{{ player.assiststotal or 0 }}</span>
</td>
{% for date in fixture_dates %}
<td>
{% set motm_col = 'motm_' + date %}
{% set dotd_col = 'dotd_' + date %}
{% if player[motm_col] and player[motm_col] > 0 %}
<span class="badge bg-primary">{{ player[motm_col] }}</span>
<button type="button" class="btn btn-sm btn-outline-danger ms-1"
onclick="resetPlayerFixture({{ player.playernumber }}, '{{ date }}')"
title="Reset this player's counts for {{ date }}">
×
</button>
{% else %}
<span class="text-muted">0</span>
{% endif %}
</td>
<td>
{% if player[dotd_col] and player[dotd_col] > 0 %}
<span class="badge bg-secondary">{{ player[dotd_col] }}</span>
<button type="button" class="btn btn-sm btn-outline-danger ms-1"
onclick="resetPlayerFixture({{ player.playernumber }}, '{{ date }}')"
title="Reset this player's counts for {{ date }}">
×
</button>
{% else %}
<span class="text-muted">0</span>
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="alert alert-info">
<h5>No MOTM/DotD data found</h5>
<p>There is no data in the _hkfc_c_motm table. This might be because no votes have been cast yet.</p>
</div>
{% endif %}
</div>
<!-- Column Management -->
<div class="reset-section">
<h3>Column Management</h3>
<p class="text-muted">Drop unwanted columns from the _hkfc_c_motm table.</p>
<div class="row">
<div class="col-md-6">
<h5>Drop Specific Column</h5>
<form method="POST" onsubmit="return confirm('Are you sure you want to drop this column? This action cannot be undone!')">
<input type="hidden" name="action" value="drop_column">
<div class="mb-3">
<select name="column_name" class="form-select" required>
<option value="">Select column to drop...</option>
{% for date in fixture_dates %}
<option value="motm_{{ date }}">motm_{{ date }}</option>
<option value="dotd_{{ date }}">dotd_{{ date }}</option>
{% endfor %}
<option value="motm_none">motm_none</option>
<option value="dotd_none">dotd_none</option>
</select>
</div>
<button type="submit" class="btn btn-danger">Drop Column</button>
</form>
</div>
<div class="col-md-6">
<h5>Drop Fixture Columns</h5>
<form method="POST" onsubmit="return confirm('Are you sure you want to drop all columns for this fixture? This action cannot be undone!')">
<input type="hidden" name="action" value="drop_fixture_columns">
<div class="mb-3">
<select name="fixture_date" class="form-select" required>
<option value="">Select fixture date...</option>
{% for date in fixture_dates %}
<option value="{{ date }}">{{ date }}</option>
{% endfor %}
</select>
</div>
<button type="submit" class="btn btn-danger">Drop Fixture Columns</button>
</form>
</div>
</div>
</div>
<!-- Available Fixtures -->
<div class="data-section">
<h3>Available Fixtures</h3>
{% if fixture_dates %}
<p>The following fixture dates have MOTM/DotD columns in the database:</p>
<ul>
{% for date in fixture_dates %}
<li><code>{{ date }}</code> - Columns: <code>motm_{{ date }}</code>, <code>dotd_{{ date }}</code></li>
{% endfor %}
</ul>
{% else %}
<div class="alert alert-warning">
<h5>No fixture columns found</h5>
<p>No fixture-specific MOTM/DotD columns were found in the database.</p>
</div>
{% endif %}
</div>
</div>
</div>
</div>
<!-- Hidden form for individual player resets -->
<form id="playerResetForm" method="POST" style="display: none;">
<input type="hidden" name="action" value="reset_player_fixture">
<input type="hidden" name="player_number" id="playerNumber">
<input type="hidden" name="fixture_date" id="fixtureDate">
</form>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
function resetPlayerFixture(playerNumber, fixtureDate) {
if (confirm(`Are you sure you want to reset MOTM/DotD counts for player #${playerNumber} in fixture ${fixtureDate}?`)) {
document.getElementById('playerNumber').value = playerNumber;
document.getElementById('fixtureDate').value = fixtureDate;
document.getElementById('playerResetForm').submit();
}
}
</script>
</body>
</html>