From 633c762b2ed9c151c69b0697bb3e443708e4299f Mon Sep 17 00:00:00 2001 From: jcwimer Date: Thu, 31 Dec 2015 20:07:14 +0000 Subject: [PATCH] Added all matches page and edit matches page --- app/controllers/matches_controller.rb | 4 +- app/controllers/tournaments_controller.rb | 13 +- app/views/layouts/_lsidebar.html.erb | 3 +- app/views/matches/_edit_form.html.erb | 36 ---- app/views/matches/_form.html.erb | 229 +++++++++++++++++++--- app/views/matches/edit.html.erb | 7 +- app/views/tournaments/matches.html.erb | 37 ++++ config/routes.rb | 1 + 8 files changed, 264 insertions(+), 66 deletions(-) delete mode 100644 app/views/matches/_edit_form.html.erb create mode 100644 app/views/tournaments/matches.html.erb diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 291ad7c..3186ad8 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -16,6 +16,8 @@ class MatchesController < ApplicationController if @match @w1 = @match.wrestler1 @w2 = @match.wrestler2 + @wrestlers = [@w1,@w2] + @tournament = @match.tournament end end @@ -43,7 +45,7 @@ class MatchesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def match_params - params.require(:match).permit(:w1, :w2, :g_stat, :r_stat, :winner_id, :win_type, :score, :finished) + params.require(:match).permit(:w1, :w2, :w1_stat, :w2_stat, :winner_id, :win_type, :score, :finished) end def check_access diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index b96e8b4..dcb9849 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -1,8 +1,17 @@ class TournamentsController < ApplicationController - before_action :set_tournament, only: [: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_filter :check_access, only: [:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:destroy,:generate_matches] + before_action :set_tournament, only: [: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_filter :check_access, only: [:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:destroy,:generate_matches,:matches] before_filter :check_for_matches, only: [:up_matches,:bracket,:all_brackets] + def matches + @matches = @tournament.matches.sort_by{|m| m.bout_number} + if @match + @w1 = @match.wrestler1 + @w2 = @match.wrestler2 + @wrestlers = [@w1,@w2] + end + end + def weigh_in_weight if params[:wrestler] Wrestler.update(params[:wrestler].keys, params[:wrestler].values) diff --git a/app/views/layouts/_lsidebar.html.erb b/app/views/layouts/_lsidebar.html.erb index 2e80917..7b2ef6b 100644 --- a/app/views/layouts/_lsidebar.html.erb +++ b/app/views/layouts/_lsidebar.html.erb @@ -6,7 +6,7 @@

Tournament Links

<% end %> - +

Bout <%= @match.bout_number %>

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<%= @w1.name %>
Last Match: <%= if @w1.lastMatch != nil then time_ago_in_words(@w1.lastMatch.updated_at) end%>
<%= @w2.name %>
Last Match: <%= if @w2.lastMatch != nil then time_ago_in_words(@w2.lastMatch.updated_at) 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 :w1_name %>
- <%= f.number_field :w1_name %> + <%= f.label "Win Type" %>
+ <%= f.select(:win_type, Match::WIN_TYPES) %>
+
- <%= f.label :w2_name %>
- <%= f.number_field :w2_name %> + <%= f.label "Winner" %> Please choose the winner
+ <%= f.collection_select :winner_id, @wrestlers, :id, :name %>
+
- <%= f.label :g_stat %>
- <%= f.text_area :g_stat %> -
-
- <%= f.label :r_stat %>
- <%= f.text_area :r_stat %> -
-
- <%= f.label :winner_id %>
- <%= f.number_field :winner_id %> -
-
- <%= f.label :win_type %>
- <%= f.text_field :win_type %> -
-
- <%= f.label :score %>
+ <%= 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 %> + <%= 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 %> + + diff --git a/app/views/matches/edit.html.erb b/app/views/matches/edit.html.erb index a64773b..4540c95 100644 --- a/app/views/matches/edit.html.erb +++ b/app/views/matches/edit.html.erb @@ -1,5 +1,6 @@ +<%= link_to "Back to #{@match.tournament.name} matches", "/tournaments/#{@match.tournament.id}/matches", :class=>"btn btn-default" %> +
+

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

-<%= render 'edit_form' %> - -<%= link_to 'Back', root_path %> +<%= render 'form' %> diff --git a/app/views/tournaments/matches.html.erb b/app/views/tournaments/matches.html.erb new file mode 100644 index 0000000..a2a01b1 --- /dev/null +++ b/app/views/tournaments/matches.html.erb @@ -0,0 +1,37 @@ + + +

All <%= @tournament.name %> matches

+
+
+<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %> + +
+
+ + + + + + + + + + + + <% @matches.each do |match| %> + + + + + + + <% end %> + +
Bout numberMatchupFinished?
<%= match.bout_number %><%= match.w1_name %> vs <%= match.w2_name %><%= match.finished %><%= link_to 'Show', match, :class=>"btn btn-default" %> + <%= link_to 'Edit', edit_match_path(match), :class=>"btn btn-primary" %> +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5ad9ab4..d98061e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,6 +39,7 @@ Wrestling::Application.routes.draw do get 'tournaments/:id/team_scores' => 'tournaments#team_scores' get 'tournaments/:id/up_matches' => 'tournaments#up_matches' get 'tournaments/:id/no_matches' => 'tournaments#no_matches' + get 'tournaments/:id/matches' => 'tournaments#matches' # Example of regular route: # get 'products/:id' => 'catalog#view'