From 1d2b80e1055ca198688a00aa8050b46d3f341e94 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Sat, 9 Nov 2019 00:42:17 +0100 Subject: [PATCH] WIP --- app/controllers/matches_controller.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 71abf28..e6be7e0 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -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']