Merge branch 'ticket/TUR-9' into 'master'

TUR-9: Support upcoming match stage

See merge request turniere/turniere-backend!22
This commit is contained in:
Jonas Seydel 2022-05-22 16:46:28 +00:00
commit 48d3d3c174
2 changed files with 26 additions and 0 deletions

View File

@ -10,6 +10,23 @@ 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|
# the following if equates to true if it finds a stage where all matches are of state `in_progress`
if stage.matches.reject { |m| m.state == 'in_progress' }.nil?
next_level = stage.level - 1
break
end
end
@tournament.stages.find_by(level: next_level).matches
end
else
@tournament.matches.select do |m|
m.state == match_params['state']

View File

@ -6,3 +6,12 @@
tmp/restart.txt
tmp/caching-dev.txt
].each { |path| Spring.watch(path) }
Spring.after_fork do
if ENV['DEBUGGER_STORED_RUBYLIB']
ENV['DEBUGGER_STORED_RUBYLIB'].split(File::PATH_SEPARATOR).each do |path|
next unless path =~ /ruby-debug-ide/
load path + '/ruby-debug-ide/multiprocess/starter.rb'
end
end
end