fix bracket

shop
Razmig Sarkissian 8 months ago
parent 60dd2ca335
commit 95c83163a2
  1. 10
      tournaments/templates/tournaments/tournament_bracket.html
  2. 73
      tournaments/views.py

@ -37,6 +37,7 @@ function renderBracket() {
const matchTemplates = document.getElementById('match-templates').children;
const rounds = [];
const matchPositions = [];
const matchDisabled = []; // New array to track disabled matches
const doubleButterflyMode = {{ double_butterfly_mode|lower }};
const displayLoserFinal = {{ display_loser_final|lower }};
@ -121,12 +122,16 @@ function renderBracket() {
roundDiv.appendChild(matchesContainer);
matchPositions[roundIndex] = [];
matchDisabled[roundIndex] = []; // Initialize array for this round
roundMatches.forEach((matchTemplate, matchIndex) => {
const matchDiv = document.createElement('div');
matchDiv.className = 'butterfly-match';
matchDiv.style.position = 'absolute';
const isDisabled = matchTemplate.dataset.disabled === 'true';
matchDisabled[roundIndex][matchIndex] = isDisabled;
let isIncomingLineIsDisabled = isDisabled;
let top;
let left;
let right;
@ -194,6 +199,9 @@ function renderBracket() {
}
if (currentMatchesCount == previousMatchesCount) {
if (matchDisabled[roundIndex - 1][matchIndex] == true) {
isIncomingLineIsDisabled = true
}
top = matchPositions[roundIndex - 1][matchIndex];
} else {
const parentIndex1 = matchIndex * 2;
@ -266,7 +274,7 @@ function renderBracket() {
}
matchDiv.innerHTML = `
<div class="incoming-line ${isDisabled ? 'disabled' : ''}"></div>
<div class="incoming-line ${isIncomingLineIsDisabled ? 'disabled' : ''}"></div>
<div class="match-content ${isDisabled ? 'disabled' : ''}">${matchTemplate.innerHTML}</div>
`;

@ -1008,6 +1008,43 @@ def get_bracket(tournament, parent_round=None, double_butterfly_mode=False, disp
# Add first half of each round (from last to semi-finals)
for round in main_rounds:
matches = round.match_set.filter(disabled=False).order_by('index')
next_round = main_rounds.filter(index=round.index - 1).first()
if next_round:
next_round_matches = next_round.match_set.filter(disabled=False).order_by('index')
else:
next_round_matches = []
if len(matches) < len(next_round_matches):
all_matches = round.match_set.order_by('index')
filtered_matches = []
# Process matches in pairs
i = 0
while i < len(all_matches):
# Get the current match and its pair (if available)
current_match = all_matches[i]
pair_match = all_matches[i+1] if i+1 < len(all_matches) else None
# Only filter out the pair if both matches are disabled
if current_match.disabled and pair_match and pair_match.disabled:
# Skip one of the matches in the pair
filtered_matches.append(current_match)
pass
else:
# Keep the current match
if current_match.disabled == False:
filtered_matches.append(current_match)
# If there's a pair match, keep it too
if pair_match and pair_match.disabled == False:
filtered_matches.append(pair_match)
# Move to the next pair
i += 2
# Replace the matches list with our filtered list
matches = filtered_matches
if matches:
if len(matches) > 1 and double_butterfly_mode:
@ -1035,6 +1072,42 @@ def get_bracket(tournament, parent_round=None, double_butterfly_mode=False, disp
if double_butterfly_mode:
for round in main_rounds_reversed:
matches = round.match_set.filter(disabled=False).order_by('index')
next_round = main_rounds_reversed.filter(index=round.index - 1).first()
if next_round:
next_round_matches = next_round.match_set.filter(disabled=False).order_by('index')
else:
next_round_matches = []
if len(matches) < len(next_round_matches):
all_matches = round.match_set.order_by('index')
filtered_matches = []
# Process matches in pairs
i = 0
while i < len(all_matches):
# Get the current match and its pair (if available)
current_match = all_matches[i]
pair_match = all_matches[i+1] if i+1 < len(all_matches) else None
# Only filter out the pair if both matches are disabled
if current_match.disabled and pair_match and pair_match.disabled:
# Skip one of the matches in the pair
filtered_matches.append(current_match)
pass
else:
# Keep the current match
if current_match.disabled == False:
filtered_matches.append(current_match)
# If there's a pair match, keep it too
if pair_match and pair_match.disabled == False:
filtered_matches.append(pair_match)
# Move to the next pair
i += 2
# Replace the matches list with our filtered list
matches = filtered_matches
if matches:
if len(matches) > 1:
midpoint = int(len(matches) / 2)

Loading…
Cancel
Save