From 010d9a5f6b49245cc21c92b6074c428951b0cb07 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 11 Mar 2025 12:32:18 -0400 Subject: [PATCH] Added all_results page to tournaments --- README.md | 4 +- app/controllers/tournaments_controller.rb | 12 ++- app/models/match.rb | 15 ++++ app/views/layouts/_tournament-navbar.html.erb | 1 + app/views/tournaments/all_results.html.erb | 8 ++ config/routes.rb | 1 + .../tournaments_controller_test.rb | 81 +++++++++++++++++++ 7 files changed, 118 insertions(+), 4 deletions(-) create mode 100644 app/views/tournaments/all_results.html.erb diff --git a/README.md b/README.md index 454c72e..cd2020b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,9 @@ If you want to run a full rails environment shell in docker run: `bash bin/rails From here, you can run the normal rails commands. Special rake tasks: -* `docker-compose -f deploy/docker-compose-test.yml exec -T app rails tournament:assign_random_wins` will complete all matches for tournament 204 from seed data. This task takes a while since it waits for the worker to complete tasks. In my testing, it takes about 3.5 hours to complete. +* `tournament:assign_random_wins` will complete all matches for tournament 204 from seed data. This task takes a while since it waits for the worker to complete tasks. In my testing, it takes about 3.5 hours to complete. + * `rake tournament:assign_random_wins` to run locally + * `docker-compose -f deploy/docker-compose-test.yml exec -T app rails tournament:assign_random_wins` to run on the dev server To deploy a a full local version of the app `bash deploy/deploy-test.sh` (this requires docker-compose to be installed). This deploys a full version of the app. App, delayed job, memcached, and mariadb. Now, you can open [http://localhost](http://localhost). Delayed jobs are turned off in dev and everything that is a delayed job in prod just runs in browser. diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 3e8f698..f0f01ae 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,10 +1,10 @@ class TournamentsController < ApplicationController - before_action :set_tournament, only: [:delete_school_keys, :generate_school_keys,:reset_bout_board,:calculate_team_scores,:bout_sheets,:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets] + before_action :set_tournament, only: [:all_results, :delete_school_keys, :generate_school_keys,:reset_bout_board,:calculate_team_scores,:bout_sheets,:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets] before_action :check_access_manage, only: [:delete_school_keys, :generate_school_keys,:reset_bout_board,:calculate_team_scores,:swap,:weigh_in_sheet,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches] before_action :check_access_destroy, only: [:destroy,:delegate,:remove_delegate] before_action :check_tournament_errors, only: [:generate_matches] - before_action :check_for_matches, only: [:up_matches,:bracket,:all_brackets] - before_action :check_access_read, only: [:up_matches,:bracket,:all_brackets] + before_action :check_for_matches, only: [:all_results,:up_matches,:bracket,:all_brackets] + before_action :check_access_read, only: [:all_results,:up_matches,:bracket,:all_brackets] def weigh_in_sheet @@ -175,6 +175,12 @@ class TournamentsController < ApplicationController end end + def all_results + @matches = @tournament.matches.includes(:schools,:wrestlers,:weight) + @round = nil + @bracket_position = nil + end + def generate_matches GenerateTournamentMatches.new(@tournament).generate end diff --git a/app/models/match.rb b/app/models/match.rb index 19540ef..732eca0 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -232,6 +232,21 @@ class Match < ApplicationRecord end end + def all_results_text + if self.finished != 1 + return "" + end + if self.winner_id == self.w1 + winning_wrestler = self.wrestler1 + losing_wrestler = self.wrestler2 + end + if self.winner_id == self.w2 + winning_wrestler = self.wrestler2 + losing_wrestler = self.wrestler1 + end + return "#{self.weight.max} lbs - #{winning_wrestler.name} (#{winning_wrestler.school.name}) #{self.win_type} #{losing_wrestler.name} (#{losing_wrestler.school.name}) #{self.score}" + end + def bracket_winner_name if winner_name != "" return "#{winner_name} (#{Wrestler.find(winner_id).school.abbreviation})" diff --git a/app/views/layouts/_tournament-navbar.html.erb b/app/views/layouts/_tournament-navbar.html.erb index 6c1abd6..42106a2 100644 --- a/app/views/layouts/_tournament-navbar.html.erb +++ b/app/views/layouts/_tournament-navbar.html.erb @@ -12,6 +12,7 @@