fix bracket

redesign-tournament-list
Razmig Sarkissian 8 months ago
parent fb7b882bb5
commit f29effa374
  1. 1
      tournaments/models/match.py
  2. 80
      tournaments/templates/tournaments/bracket_match_cell.html
  3. 15
      tournaments/templates/tournaments/tournament_bracket.html
  4. 6
      tournaments/views.py

@ -204,6 +204,7 @@ class Match(models.Model):
names = [f"Perdant {loser_bottom_match.computed_name()}", ''] names = [f"Perdant {loser_bottom_match.computed_name()}", '']
team = self.default_live_team(names) team = self.default_live_team(names)
teams.append(team) teams.append(team)
elif self.round and self.round.parent is None:
if previous_top_match: if previous_top_match:
names = [f"Gagnant {previous_top_match.computed_name()}", ''] names = [f"Gagnant {previous_top_match.computed_name()}", '']
team = self.default_live_team(names) team = self.default_live_team(names)

@ -0,0 +1,80 @@
{% load static %}
<div class="cell medium-12 large-3 my-block">
<div class="bubble">
<div class="flex-row">
<label class="matchtitle">{{ match.title }}</label>
{% if not match.ended %}
<label class="right-label minor-info bold">{{ match.court }}</label>
{% endif %}
</div>
<div>
{% for team in match.teams %}
<div class="match-result {% cycle 'bottom-border' '' %}">
<div class="player">
{% if team.id %}
<a href="{% url 'team-details' tournament.id team.id %}" class="player-link">
{% endif %}
{% if team.is_lucky_loser or team.walk_out == 1 %}
<div class="overlay-text">
{% if team.is_lucky_loser %}(LL){% elif team.walk_out == 1 %}(WO){% endif %}
</div>
{% endif %}
{% for name in team.names %}
<div class="semibold{% if team.walk_out == 1 %} strikethrough{% endif %}{% if team.is_winner %} winner{% endif %}">
{% if name|length > 0 %}
{{ name }}
{% else %}
&nbsp;
{% endif %}
</div>
{% endfor %}
{% if team.id %}
</a>
{% endif %}
</div>
{% if match.has_walk_out %}
<span class="score ws w60px">
{% if team.is_walk_out %}WO{% endif %}
</span>
{% elif match.should_show_scores %}
<div class="scores">
{% for score in team.scores %}
<span class="score ws {% if score.tiebreak %}w35px{% else %}w30px{% endif %}{% if team.is_winner %} winner{% endif %}">
{{ score.main }}
{% if score.tiebreak %}
<sup>{{ score.tiebreak }}</sup>
{% endif %}
</span>
{% endfor %}
</div>
{% elif not tournament.hide_weight and team.weight %}
<span class="score ws numbers">{{ team.weight }}</span>
{% endif %}
</div>
{% endfor %}
</div>
<div class="status-container {% if not match.ended and match.started %}running{% endif %}">
<div class="flex-row top-margin">
<label class="left-label minor-info bold">
{% if match.show_time_indication %}
{{ match.time_indication }}
{% endif %}
</label>
<label class="right-label minor-info">
{% if not match.ended %}
{{ match.format }}
{% endif %}
</label>
</div>
</div>
</div>
</div>

@ -19,7 +19,7 @@
data-match-index="{{ forloop.counter0 }}" data-match-index="{{ forloop.counter0 }}"
data-disabled="{{ match.disabled|lower }}" data-disabled="{{ match.disabled|lower }}"
class="match-template"> class="match-template">
{% include 'tournaments/match_cell.html' %} {% include 'tournaments/bracket_match_cell.html' %}
</div> </div>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
@ -58,6 +58,7 @@ function renderBracket() {
rounds.forEach((roundMatches, roundIndex) => { rounds.forEach((roundMatches, roundIndex) => {
const roundDiv = document.createElement('div'); const roundDiv = document.createElement('div');
roundDiv.className = 'butterfly-round'; roundDiv.className = 'butterfly-round';
roundDiv.style.setProperty('--match-width', `${360}px`);
matchPositions[roundIndex] = []; matchPositions[roundIndex] = [];
roundMatches.forEach((matchTemplate, matchIndex) => { roundMatches.forEach((matchTemplate, matchIndex) => {
@ -91,7 +92,11 @@ function renderBracket() {
top = matchPositions[roundIndex - 2][matchIndex]; top = matchPositions[roundIndex - 2][matchIndex];
nextMatchDistance = 0; nextMatchDistance = 0;
} else if (roundIndex == finalRoundIndex) { } else if (roundIndex == finalRoundIndex) {
top = matchPositions[roundIndex - 3][1 + matchIndex]; if (finalRoundIndex === 2) {
top = matchPositions[0][matchIndex];
} else {
top = matchPositions[0][1 + matchIndex];
}
nextMatchDistance = baseDistance; nextMatchDistance = baseDistance;
} else if (currentRoundMatches > previousRoundMatches) { } else if (currentRoundMatches > previousRoundMatches) {
// Bracket is reversed - matches are splitting instead of combining // Bracket is reversed - matches are splitting instead of combining
@ -116,6 +121,7 @@ function renderBracket() {
} }
if (roundIndex >= finalRoundIndex - 1) { if (roundIndex >= finalRoundIndex - 1) {
if (roundCount > 5) {
matchDiv.style.transform = `translateX(-50%)`; matchDiv.style.transform = `translateX(-50%)`;
if (roundIndex >= finalRoundIndex + 2) { if (roundIndex >= finalRoundIndex + 2) {
matchDiv.style.transform = `translateX(-100%)`; matchDiv.style.transform = `translateX(-100%)`;
@ -127,6 +133,7 @@ function renderBracket() {
if (roundIndex == finalRoundIndex + 1) { if (roundIndex == finalRoundIndex + 1) {
matchDiv.classList.add('outward'); matchDiv.classList.add('outward');
} }
}
} }
@ -146,7 +153,9 @@ function renderBracket() {
const matchDiv2 = document.createElement('div'); const matchDiv2 = document.createElement('div');
matchDiv2.className = 'butterfly-match'; matchDiv2.className = 'butterfly-match';
matchDiv2.style.position = 'absolute'; matchDiv2.style.position = 'absolute';
if (roundCount > 5) {
matchDiv2.style.transform = `translateX(-50%)`; matchDiv2.style.transform = `translateX(-50%)`;
}
matchDiv2.classList.add('inward'); matchDiv2.classList.add('inward');
matchDiv2.classList.add('semi-final'); matchDiv2.classList.add('semi-final');
matchDiv2.style.setProperty('--next-match-distance', `${baseDistance}px`); matchDiv2.style.setProperty('--next-match-distance', `${baseDistance}px`);
@ -191,7 +200,7 @@ function renderBracket() {
.butterfly-round { .butterfly-round {
position: relative; position: relative;
width: 25%; /* 300px for match + 20px on each side for lines */ width: var(--match-width); /* 300px for match + 20px on each side for lines */
flex-shrink: 0; /* Prevents rounds from shrinking */ flex-shrink: 0; /* Prevents rounds from shrinking */
} }

@ -965,7 +965,6 @@ def tournament_bracket(request, tournament_id):
parent=None, parent=None,
group_stage_loser_bracket=False group_stage_loser_bracket=False
).order_by('-index') ).order_by('-index')
main_rounds_reversed = tournament.round_set.filter( main_rounds_reversed = tournament.round_set.filter(
parent=None, parent=None,
group_stage_loser_bracket=False group_stage_loser_bracket=False
@ -989,8 +988,8 @@ def tournament_bracket(request, tournament_id):
matches = round.match_set.all() matches = round.match_set.all()
if matches: if matches:
midpoint = len(matches) // 2
if len(matches) > 1: if len(matches) > 1:
midpoint = int(len(matches) / 2)
first_half_matches = matches[:midpoint] first_half_matches = matches[:midpoint]
else: else:
first_half_matches = list(matches) # Convert QuerySet to a list first_half_matches = list(matches) # Convert QuerySet to a list
@ -1011,8 +1010,8 @@ def tournament_bracket(request, tournament_id):
for round in main_rounds_reversed: for round in main_rounds_reversed:
matches = round.match_set.all() matches = round.match_set.all()
if matches: if matches:
midpoint = len(matches) // 2
if len(matches) > 1: if len(matches) > 1:
midpoint = int(len(matches) / 2)
first_half_matches = matches[midpoint:] first_half_matches = matches[midpoint:]
match_group = tournament.create_match_group( match_group = tournament.create_match_group(
@ -1021,7 +1020,6 @@ def tournament_bracket(request, tournament_id):
) )
serializable_match_groups.append(match_group) serializable_match_groups.append(match_group)
context = { context = {
'tournament': tournament, 'tournament': tournament,
'match_groups': serializable_match_groups 'match_groups': serializable_match_groups

Loading…
Cancel
Save