From afa9a26d93d0530e45460062f2dea6368a642fbd Mon Sep 17 00:00:00 2001 From: Malaber Date: Fri, 20 May 2022 00:17:15 +0200 Subject: [PATCH] Add documentation to upcoming matches filter --- app/controllers/matches_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index d898fbc..d5e06e5 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -10,11 +10,18 @@ class MatchesController < ApplicationController def index matches = if match_params['state'].nil? @tournament.matches + + # support for upcoming matches for beamer view elsif match_params['state'] == 'upcoming' + # for every group within the tournament find the match with the lowest position that is of state 'not_started' upcoming_matches = @tournament.stages.find_by(level: -1)&.groups&.map { |g| g.matches.select { |m| m.state == 'not_started' }.min_by(&:position) } + # if there are none, the group stage is over, so we have to look into the playoff stages if upcoming_matches.nil? next_level = 0 @tournament.stages.sort_by(&:level).reverse_each do |stage| + # matches in the playoffs are only generated after one of the parent matches are done, so the stages + # which are currently not running are empty, the first empty stage that is found is directly after + # the currently running one, so we subtract 1 and call it a day if stage.matches.nil? next_level = stage.level - 1 break