Fix up voting and start adding club logos

This commit is contained in:
2025-10-03 00:13:09 +08:00
parent 7f0d171e21
commit 131f17947c
17 changed files with 516 additions and 37 deletions
+30 -1
View File
@@ -43,7 +43,7 @@
<div class="mb-3">
{{ form.logo_url.label(class="form-label") }}
{{ form.logo_url(class="form-control") }}
{{ form.logo_url(class="form-control", id="logoUrl", onchange="previewLogo()") }}
{% if form.logo_url.errors %}
<div class="text-danger">
{% for error in form.logo_url.errors %}
@@ -52,6 +52,15 @@
</div>
{% endif %}
<small class="form-text text-muted">Enter the full URL to the club's logo image</small>
<!-- Logo Preview -->
<div id="logoPreview" class="mt-2" style="display: none;">
<label class="form-label small">Preview:</label>
<div class="border rounded p-2 bg-light">
<img id="previewImage" src="" alt="Logo preview" style="max-height: 80px; max-width: 120px;" onerror="this.style.display='none'; document.getElementById('previewError').style.display='block';" onload="document.getElementById('previewError').style.display='none';">
<div id="previewError" class="text-muted small" style="display: none;">Unable to load image</div>
</div>
</div>
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
@@ -70,5 +79,25 @@
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
function previewLogo() {
const urlInput = document.getElementById('logoUrl');
const previewDiv = document.getElementById('logoPreview');
const previewImg = document.getElementById('previewImage');
if (urlInput.value.trim()) {
previewImg.src = urlInput.value;
previewDiv.style.display = 'block';
} else {
previewDiv.style.display = 'none';
}
}
// Preview logo on page load if URL is already filled
document.addEventListener('DOMContentLoaded', function() {
previewLogo();
});
</script>
</body>
</html>
+4 -4
View File
@@ -31,7 +31,7 @@
<div class="mb-3">
{{ form.club.label(class="form-label") }}
{{ form.club(class="form-control") }}
{{ form.club(class="form-select") }}
{% if form.club.errors %}
<div class="text-danger">
{% for error in form.club.errors %}
@@ -39,7 +39,7 @@
{% endfor %}
</div>
{% endif %}
<small class="form-text text-muted">Enter the club name (e.g., HKFC, KCC, USRC)</small>
<small class="form-text text-muted">Select the club from the list of available clubs</small>
</div>
<div class="mb-3">
@@ -70,7 +70,7 @@
<div class="mb-3">
{{ form.league.label(class="form-label") }}
{{ form.league(class="form-control") }}
{{ form.league(class="form-select") }}
{% if form.league.errors %}
<div class="text-danger">
{% for error in form.league.errors %}
@@ -78,7 +78,7 @@
{% endfor %}
</div>
{% endif %}
<small class="form-text text-muted">Enter the league/division (e.g., Premier Division, Division 1)</small>
<small class="form-text text-muted">Select the league/division from the list</small>
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
+15 -3
View File
@@ -77,6 +77,7 @@
<tr>
<th>ID</th>
<th>Club Name</th>
<th>Logo</th>
<th>Logo URL</th>
<th>Actions</th>
</tr>
@@ -87,9 +88,20 @@
<td>{{ club.id }}</td>
<td>{{ club.hockey_club }}</td>
<td>
<a href="{{ club.logo_url }}" target="_blank" class="text-decoration-none">
{{ club.logo_url }}
</a>
{% if club.logo_url %}
<img src="{{ club.logo_url }}" alt="{{ club.hockey_club }} logo" style="max-height: 40px; max-width: 60px;" onerror="this.style.display='none'">
{% else %}
<span class="text-muted">No logo</span>
{% endif %}
</td>
<td>
{% if club.logo_url %}
<a href="{{ club.logo_url }}" target="_blank" class="text-decoration-none small">
{{ club.logo_url[:50] }}{% if club.logo_url|length > 50 %}...{% endif %}
</a>
{% else %}
<span class="text-muted">No URL</span>
{% endif %}
</td>
<td>
<a href="/admin/clubs/edit/{{ club.id }}" class="btn btn-sm btn-outline-primary">Edit</a>
+174
View File
@@ -0,0 +1,174 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Select Clubs to Import - HKFC Men's C Team</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-4">
<div class="row justify-content-center">
<div class="col-md-10">
<div class="card">
<div class="card-header">
<h3>Select Clubs to Import</h3>
<p class="mb-0 text-muted">Choose which clubs you want to import from the Hong Kong Hockey Association</p>
</div>
<div class="card-body">
{% 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 %}
<div class="alert alert-info">
<h5>Club Selection</h5>
<p>Select the clubs you want to import. You can choose all clubs or select specific ones based on your needs.</p>
<p><strong>Note:</strong> Only new clubs will be imported. Existing clubs will be skipped to prevent duplicates.</p>
</div>
{% if clubs %}
<form method="POST" id="clubSelectionForm">
{{ form.hidden_tag() }}
<div class="mb-3">
<div class="d-flex gap-2 mb-3">
<button type="submit" name="select_all" class="btn btn-outline-primary btn-sm" formnovalidate>
Select All
</button>
<button type="submit" name="select_none" class="btn btn-outline-secondary btn-sm" formnovalidate>
Select None
</button>
<span class="text-muted align-self-center">
<span id="selectedCount">0</span> of {{ clubs|length }} clubs selected
</span>
</div>
</div>
<div class="row">
{% for club in clubs %}
<div class="col-md-6 col-lg-4 mb-3">
<div class="card h-100">
<div class="card-body">
<div class="form-check">
<input class="form-check-input club-checkbox"
type="checkbox"
name="selected_clubs"
value="{{ club.name }}"
id="club_{{ loop.index }}"
{% if club.name in selected_clubs %}checked{% endif %}>
<label class="form-check-label w-100" for="club_{{ loop.index }}">
<div class="d-flex justify-content-between align-items-start">
<div>
<h6 class="mb-1">{{ club.name }}</h6>
{% if club.abbreviation %}
<small class="text-muted">{{ club.abbreviation }}</small>
{% endif %}
</div>
<div class="text-end">
{% if club.teams %}
<small class="badge bg-info">{{ club.teams|length }} teams</small>
{% endif %}
</div>
</div>
{% if club.convenor %}
<div class="mt-2">
<small class="text-muted">
<i class="bi bi-person"></i> {{ club.convenor }}
</small>
</div>
{% endif %}
{% if club.email %}
<div>
<small class="text-muted">
<i class="bi bi-envelope"></i> {{ club.email }}
</small>
</div>
{% endif %}
</label>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end mt-4">
<button type="submit" name="cancel" class="btn btn-secondary me-md-2" formnovalidate>
Cancel
</button>
<button type="submit" name="import_selected" class="btn btn-primary" id="importButton" disabled>
Import Selected Clubs
</button>
</div>
</form>
{% else %}
<div class="alert alert-warning">
<h5>No clubs found</h5>
<p>Unable to fetch clubs from the Hong Kong Hockey Association website. This might be due to:</p>
<ul>
<li>Network connectivity issues</li>
<li>Website structure changes</li>
<li>Server maintenance</li>
</ul>
<p>Please try again later or contact the administrator.</p>
</div>
{% endif %}
</div>
</div>
<div class="mt-3">
<a href="/admin/import" class="btn btn-outline-secondary">Back to Data Import</a>
<a href="/admin" class="btn btn-outline-secondary">Back to Admin</a>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Update selected count and enable/disable import button
function updateSelection() {
const checkboxes = document.querySelectorAll('.club-checkbox');
const selectedCount = document.querySelectorAll('.club-checkbox:checked').length;
const importButton = document.getElementById('importButton');
const countSpan = document.getElementById('selectedCount');
countSpan.textContent = selectedCount;
importButton.disabled = selectedCount === 0;
}
// Add event listeners to checkboxes
document.addEventListener('DOMContentLoaded', function() {
const checkboxes = document.querySelectorAll('.club-checkbox');
checkboxes.forEach(checkbox => {
checkbox.addEventListener('change', updateSelection);
});
updateSelection(); // Initial update
});
// Handle select all/none buttons
document.getElementById('clubSelectionForm').addEventListener('submit', function(e) {
if (e.submitter.name === 'select_all') {
e.preventDefault();
document.querySelectorAll('.club-checkbox').forEach(checkbox => {
checkbox.checked = true;
});
updateSelection();
} else if (e.submitter.name === 'select_none') {
e.preventDefault();
document.querySelectorAll('.club-checkbox').forEach(checkbox => {
checkbox.checked = false;
});
updateSelection();
}
});
</script>
</body>
</html>
+8
View File
@@ -44,6 +44,14 @@
<small class="form-text text-muted d-block">
Import 30+ hockey clubs including HKFC, KCC, USRC, Valley, SSSC, Dragons, etc.
</small>
<div class="mt-2">
<a href="/admin/import/clubs/select" class="btn btn-outline-primary btn-sm">
Select Specific Clubs
</a>
<small class="text-muted d-block mt-1">
Choose which clubs to import instead of importing all
</small>
</div>
</div>
<div class="form-check mb-3">
+30 -1
View File
@@ -43,7 +43,7 @@
<div class="mb-3">
{{ form.logo_url.label(class="form-label") }}
{{ form.logo_url(class="form-control") }}
{{ form.logo_url(class="form-control", id="logoUrl", onchange="previewLogo()") }}
{% if form.logo_url.errors %}
<div class="text-danger">
{% for error in form.logo_url.errors %}
@@ -52,6 +52,15 @@
</div>
{% endif %}
<small class="form-text text-muted">Enter the full URL to the club's logo image</small>
<!-- Logo Preview -->
<div id="logoPreview" class="mt-2" style="display: none;">
<label class="form-label small">Preview:</label>
<div class="border rounded p-2 bg-light">
<img id="previewImage" src="" alt="Logo preview" style="max-height: 80px; max-width: 120px;" onerror="this.style.display='none'; document.getElementById('previewError').style.display='block';" onload="document.getElementById('previewError').style.display='none';">
<div id="previewError" class="text-muted small" style="display: none;">Unable to load image</div>
</div>
</div>
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
@@ -70,5 +79,25 @@
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script>
function previewLogo() {
const urlInput = document.getElementById('logoUrl');
const previewDiv = document.getElementById('logoPreview');
const previewImg = document.getElementById('previewImage');
if (urlInput.value.trim()) {
previewImg.src = urlInput.value;
previewDiv.style.display = 'block';
} else {
previewDiv.style.display = 'none';
}
}
// Preview logo on page load if URL is already filled
document.addEventListener('DOMContentLoaded', function() {
previewLogo();
});
</script>
</body>
</html>
+4 -4
View File
@@ -31,7 +31,7 @@
<div class="mb-3">
{{ form.club.label(class="form-label") }}
{{ form.club(class="form-control") }}
{{ form.club(class="form-select") }}
{% if form.club.errors %}
<div class="text-danger">
{% for error in form.club.errors %}
@@ -39,7 +39,7 @@
{% endfor %}
</div>
{% endif %}
<small class="form-text text-muted">Enter the club name (e.g., HKFC, KCC, USRC)</small>
<small class="form-text text-muted">Select the club from the list of available clubs</small>
</div>
<div class="mb-3">
@@ -70,7 +70,7 @@
<div class="mb-3">
{{ form.league.label(class="form-label") }}
{{ form.league(class="form-control") }}
{{ form.league(class="form-select") }}
{% if form.league.errors %}
<div class="text-danger">
{% for error in form.league.errors %}
@@ -78,7 +78,7 @@
{% endfor %}
</div>
{% endif %}
<small class="form-text text-muted">Enter the league/division (e.g., Premier Division, Division 1)</small>
<small class="form-text text-muted">Select the league/division from the list</small>
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end">
+6 -6
View File
@@ -30,10 +30,10 @@
<span class="input-group-addon" id="basic-addon1">Man of the Match</span>
<select class="form-control" name="motmVote" required>
{% for item in data %}
{% if item.playerNickname != "" %}
<option value={{ item.playerNumber }}>{{ item.playerNickname }}</option>
{% if item.playernickname != "" %}
<option value={{ item.playernumber }}>{{ item.playernickname }}</option>
{% else %}
<option value={{ item.playerNumber }}>{{ item.playerSurname }}, {{ item.playerForenames }}</option>
<option value={{ item.playernumber }}>{{ item.playersurname }}, {{ item.playerforenames }}</option>
{% endif %}
{% endfor %}
</select>
@@ -44,10 +44,10 @@
<span class="input-group-addon" id="basic-addon1">Dick of the Day</span>
<select class="form-control" name="dotdVote" required>
{% for item in data %}
{% if item.playerNickname != "" %}
<option value={{ item.playerNumber }}>{{ item.playerNickname }}</option>
{% if item.playernickname != "" %}
<option value={{ item.playernumber }}>{{ item.playernickname }}</option>
{% else %}
<option value={{ item.playerNumber }}>{{ item.playerSurname }}, {{ item.playerForenames }}</option>
<option value={{ item.playernumber }}>{{ item.playersurname }}, {{ item.playerforenames }}</option>
{% endif %}
{% endfor %}
</select>
+1 -1
View File
@@ -11,7 +11,7 @@
<body>
Smithers' army of Internet monkeys will now go about adding up the votes ...
<p>
<img src="https://storage.googleapis.com/hk-hockey-data/images/monkey-typing-simpsons.jpg"></img>
<img src="http://icarus.ipa.champion:9000/hockey-app/assets/simpsons-monkeys.jpg"></img>
</p>
<a class="btn btn-primary" href="/" role="button">Home</a>
<a class="btn btn-info" href="/motm/comments" role="button">Comments</a>