1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-24 17:04:43 +00:00

Added all_results page to tournaments

This commit is contained in:
2025-03-11 12:32:18 -04:00
parent 91e1939e69
commit 010d9a5f6b
7 changed files with 118 additions and 4 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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})"

View File

@@ -12,6 +12,7 @@
<ul class="dropdown-menu">
<li><strong>Results</strong></li>
<li><%= link_to "Team Scores" , "/tournaments/#{@tournament.id}/team_scores" %></li>
<li><%= link_to "All Match Results" , "/tournaments/#{@tournament.id}/all_results" %></li>
<li><strong>Brackets</strong></li>
<% @tournament.weights.sort_by{|weight| weight.max }.each do |weight| %>
<li><%= link_to "#{weight.max}" , "/tournaments/#{@tournament.id}/brackets/#{weight.id}" %></li>

View File

@@ -0,0 +1,8 @@
<% @matches.select{|m| m.finished == 1 && m.w1 && m.w2}.sort_by{|m| [ m.bout_number, m.bracket_position, m.weight.max ]}.each do |match| %>
<% if @round != match.round || @bracket_position != match.bracket_position %>
<p><strong><%= match.bracket_position %> Round: <%= match.round %></strong></p>
<% end %>
<p><%= match.all_results_text %></p>
<% @round = match.round %>
<% @bracket_position = match.bracket_position %>
<% end %>

View File

@@ -64,6 +64,7 @@ Wrestling::Application.routes.draw do
post "/tournaments/:id/swap" => "tournaments#swap", :as => :swap_wrestlers
get "/tournaments/:id/brackets" => "tournaments#show"
put "/tournaments/:id/calculate_team_scores", :to => "tournaments#calculate_team_scores"
get "/tournaments/:id/all_results" => "tournaments#all_results"
post "/wrestlers/update_pool" => "wrestlers#update_pool"

View File

@@ -471,6 +471,87 @@ class TournamentsControllerTest < ActionController::TestCase
end
# END UP MATCHES PAGE PERMISSIONS
# ALL_RESULTS PAGE PERMISSIONS WHEN TOURNAMENT IS NOT PUBLIC
test "logged in school delegate cannot get all_results page when tournament is not public" do
@tournament.is_public = false
@tournament.save
sign_in_school_delegate
get :all_results, params: { id: 1 }
redirect
end
test "logged in user cannot get all_results page when tournament is not public" do
@tournament.is_public = false
@tournament.save
sign_in_non_owner
get :all_results, params: { id: 1 }
redirect
end
test "logged in tournament delegate can get all_results page when tournament is not public" do
@tournament.is_public = false
@tournament.save
sign_in_delegate
get :all_results, params: { id: 1 }
success
end
test "logged in tournament owner can get all_results page when tournament is not public" do
@tournament.is_public = false
@tournament.save
sign_in_owner
get :all_results, params: { id: 1 }
success
end
test "non logged in user cannot get all_results page when tournament is not public" do
@tournament.is_public = false
@tournament.save
get :all_results, params: { id: 1 }
redirect
end
# ALL_RESULTS PAGE PERMISSIONS WHEN TOURNAMENT IS PUBLIC
test "logged in school delegate can get all_results page when tournament is public" do
@tournament.is_public = true
@tournament.save
sign_in_school_delegate
get :all_results, params: { id: 1 }
success
end
test "logged in user can get all_results page when tournament is public" do
@tournament.is_public = true
@tournament.save
sign_in_non_owner
get :all_results, params: { id: 1 }
success
end
test "logged in tournament delegate can get all_results page when tournament is public" do
@tournament.is_public = true
@tournament.save
sign_in_delegate
get :all_results, params: { id: 1 }
success
end
test "logged in tournament owner can get all_results page when tournament is public" do
@tournament.is_public = true
@tournament.save
sign_in_owner
get :all_results, params: { id: 1 }
success
end
test "non logged in user can get all_results page when tournament is public" do
@tournament.is_public = true
@tournament.save
get :all_results, params: { id: 1 }
success
end
# END ALL_RESULTS PAGE PERMISSIONS
#TESTS THAT NEED MATCHES PUT ABOVE THIS
test "redirect up_matches if no matches" do
sign_in_owner