This commit is contained in:
Daniel Schädler 2019-11-09 00:42:17 +01:00
parent 1598db7796
commit 1d2b80e105
1 changed files with 12 additions and 0 deletions

View File

@ -10,6 +10,18 @@ class MatchesController < ApplicationController
def index
matches = if match_params['state'].nil?
@tournament.matches
elsif match_params['state'] == 'upcoming'
upcoming_matches = @tournament.stages.find_by(level: -1)&.groups&.map { |g| g.matches.select { |m| m.state == 'not_started' }.min_by(&:position) }
if upcoming_matches.nil?
next_level = 0
@tournament.stages.sort_by(&:level).reverse_each do |stage|
if stage.matches.reject { |m| m.state == 'running' }.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']