diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 89f747f..0c6cba6 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,6 +1,6 @@ class MatchesController < ApplicationController - before_action :set_match, only: [:show, :edit, :update, :destroy] - before_action :check_access, only: [:edit,:update] + before_action :set_match, only: [:show, :edit, :update, :destroy, :stat] + before_action :check_access, only: [:edit,:update, :stat] # GET /matches/1 # GET /matches/1.json @@ -11,6 +11,16 @@ class MatchesController < ApplicationController # GET /matches/1/edit def edit + if params[:match] + @match = Match.where(:id => params[:match]).includes(:wrestlers).first + end + if @match + @wrestlers = @match.weight.wrestlers + end + session[:return_path] = "/tournaments/#{@match.tournament.id}/matches" + end + + def stat if params[:match] @match = Match.where(:id => params[:match]).includes(:wrestlers).first end diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb index ac9dbbc..e7a94d1 100644 --- a/app/views/matches/_form.html.erb +++ b/app/views/matches/_form.html.erb @@ -1,232 +1,15 @@ +

Change Wrestlers for Match <%= @match.bout_number %>

<%= form_for(@match) do |f| %> - <% if @match.errors.any? %> -
-

<%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:

- - -
- <% end %> -

Bout <%= @match.bout_number %>

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Name: <%= @w1.name %> -
School: <%= @w1.school.name %> -
Last Match: <%= if @w1.last_match != nil then time_ago_in_words(@w1.last_match.updated_at) else "N/A" end%>
Name: <%= @w2.name %> -
School: <%= @w2.school.name %> -
Last Match: <%= if @w2.last_match != nil then time_ago_in_words(@w2.last_match.updated_at) else "N/A" end%>
<%= @w1.name %> Stats:
<%= f.text_area :w1_stat, cols: "30", rows: "10" %>
<%= @w2.name %> Stats:
<%= f.text_area :w2_stat, cols: "30", rows: "10" %>
<%= @w1.name %> Scoring
- - - - - -
<%= @w2.name %> Scoring
- - - - - -
<%= @w1.name %> Choice
- - -
<%= @w2.name %> Choice
- - -
<%= @w1.name %> Warnings
-
<%= @w2.name %> Warnings
-
Match Options
-
-
-
-

Match Results

-
-
- <%= f.label "Win Type" %>
- <%= f.select(:win_type, Match::WIN_TYPES) %> -
-
-
- <%= f.label "Winner" %> Please choose the winner
- <%= f.collection_select :winner_id, @wrestlers, :id, :name %> -
-
-
- <%= f.label "Final Score" %> Also put pin time here if applicable. If default or forfeit, leave blank. Example: 7-2, 17-2, or 2:34
- <%= f.text_field :score %> -
-
- - <%= f.hidden_field :finished, :value => 1 %> - <%= f.hidden_field :round, :value => @match.round %> - -
- -
+
+ <%= f.label "Wrestler 1" %>
+ <%= f.collection_select :w1, @wrestlers, :id, :name %> +
+
vs
+
+ <%= f.label "Wrestler 2" %>
+ <%= f.collection_select :w2, @wrestlers, :id, :name %> +
+
<%= f.submit onclick: "return confirm('Is the name of the winner ' + document.getElementById('match_winner_id').options[document.getElementById('match_winner_id').selectedIndex].text + '?')", :class=>"btn btn-success" %> - -
-<% end %> - - +
+<% end %> \ No newline at end of file diff --git a/app/views/matches/_matchstats.html.erb b/app/views/matches/_matchstats.html.erb new file mode 100644 index 0000000..25e29f5 --- /dev/null +++ b/app/views/matches/_matchstats.html.erb @@ -0,0 +1,232 @@ +<%= form_for(@match) do |f| %> + <% if @match.errors.any? %> +
+

<%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:

+ + +
+ <% end %> +

Bout <%= @match.bout_number %>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name: <%= @w1.name %> +
School: <%= @w1.school.name %> +
Last Match: <%= if @w1.last_match != nil then time_ago_in_words(@w1.last_match.updated_at) else "N/A" end%>
Name: <%= @w2.name %> +
School: <%= @w2.school.name %> +
Last Match: <%= if @w2.last_match != nil then time_ago_in_words(@w2.last_match.updated_at) else "N/A" end%>
<%= @w1.name %> Stats:
<%= f.text_area :w1_stat, cols: "30", rows: "10" %>
<%= @w2.name %> Stats:
<%= f.text_area :w2_stat, cols: "30", rows: "10" %>
<%= @w1.name %> Scoring
+ + + + + +
<%= @w2.name %> Scoring
+ + + + + +
<%= @w1.name %> Choice
+ + +
<%= @w2.name %> Choice
+ + +
<%= @w1.name %> Warnings
+
<%= @w2.name %> Warnings
+
Match Options
+
+
+
+

Match Results

+
+
+ <%= f.label "Win Type" %>
+ <%= f.select(:win_type, Match::WIN_TYPES) %> +
+
+
+ <%= f.label "Winner" %> Please choose the winner
+ <%= f.collection_select :winner_id, @wrestlers, :id, :name %> +
+
+
+ <%= f.label "Final Score" %> Also put pin time here if applicable. If default or forfeit, leave blank. Example: 7-2, 17-2, or 2:34
+ <%= f.text_field :score %> +
+
+ + <%= f.hidden_field :finished, :value => 1 %> + <%= f.hidden_field :round, :value => @match.round %> + +
+ +
+ <%= f.submit onclick: "return confirm('Is the name of the winner ' + document.getElementById('match_winner_id').options[document.getElementById('match_winner_id').selectedIndex].text + '?')", :class=>"btn btn-success" %> + +
+<% end %> + + \ No newline at end of file diff --git a/app/views/matches/edit.html.erb b/app/views/matches/edit.html.erb index ac81e15..2d34363 100644 --- a/app/views/matches/edit.html.erb +++ b/app/views/matches/edit.html.erb @@ -1,2 +1 @@ -

<%= @w1.name %> VS. <%= @w2.name %>

<%= render 'form' %> diff --git a/app/views/matches/stat.html.erb b/app/views/matches/stat.html.erb new file mode 100644 index 0000000..126efae --- /dev/null +++ b/app/views/matches/stat.html.erb @@ -0,0 +1,2 @@ +

<%= @w1.name %> VS. <%= @w2.name %>

+<%= render 'matchstats' %> \ No newline at end of file diff --git a/app/views/mats/show.html.erb b/app/views/mats/show.html.erb index cb1a252..9667e41 100644 --- a/app/views/mats/show.html.erb +++ b/app/views/mats/show.html.erb @@ -2,7 +2,7 @@

Tournament: <%= @mat.tournament.name %>

<% if @match %> -<%= render 'matches/form' %> +<%= render 'matches/matchstats' %> <% else %>

No matches assigned to this mat.

<% end %> diff --git a/app/views/tournaments/matches.html.erb b/app/views/tournaments/matches.html.erb index c6c9910..01aa25e 100644 --- a/app/views/tournaments/matches.html.erb +++ b/app/views/tournaments/matches.html.erb @@ -27,7 +27,10 @@ <%= match.w1_bracket_name %> vs <%= match.w2_bracket_name %> <%= match.finished %> <%= link_to 'Show', match, :class=>"btn btn-default btn-sm" %> - <%= link_to 'Edit', edit_match_path(match), :class=>"btn btn-primary btn-sm" %> + <%= link_to 'Edit Wrestlers', edit_match_path(match), :class=>"btn btn-primary btn-sm" %> + <% if match.w1 and match.w2 %> + <%= link_to 'Stat Match', "/matches/#{match.id}/stat", :class=>"btn btn-primary btn-sm" %> + <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 253dc52..cdfcdb9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,6 +69,8 @@ Wrestling::Application.routes.draw do match "/delayed_job" => DelayedJobWeb, :anchor => false, :via => [:get, :post] + get "/matches/:id/stat" => "matches#stat", :as => :stat_match_path + # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/test/controllers/matches_controller_test.rb b/test/controllers/matches_controller_test.rb index 2c5c2d3..4428c79 100644 --- a/test/controllers/matches_controller_test.rb +++ b/test/controllers/matches_controller_test.rb @@ -21,6 +21,15 @@ class MatchesControllerTest < ActionController::TestCase def get_edit get :edit, params: { id: @match.id } end + + def post_update_from_match_stat + get :stat, params: { id: @match.id } + patch :update, params: { id: @match.id, match: {tournament_id: 1, mat_id: 1} } + end + + def get_stat + get :stat, params: { id: @match.id } + end def sign_in_owner sign_in users(:one) @@ -73,6 +82,17 @@ class MatchesControllerTest < ActionController::TestCase redirect end + test "logged school delegate should not get stat match page if not owner" do + sign_in_school_delegate + get_stat + redirect + end + + test "non logged in user should not get stat match page" do + get_stat + redirect + end + test "non logged in user should get post update match" do post_update assert_redirected_to '/static_pages/not_allowed' @@ -95,6 +115,12 @@ class MatchesControllerTest < ActionController::TestCase get_edit success end + + test "logged in tournament delegate should get stat match page" do + sign_in_tournament_delegate + get_stat + success + end test "logged in tournament delegate should post update match" do sign_in_tournament_delegate @@ -107,4 +133,10 @@ class MatchesControllerTest < ActionController::TestCase post_update_from_match_edit assert_redirected_to "/tournaments/#{@tournament.id}/matches" end + + test "should redirect to all matches when posting a match update from match stat" do + sign_in_owner + post_update_from_match_stat + assert_redirected_to "/tournaments/#{@tournament.id}/matches" + end end