From ce2a7b28bc37a40580575c1f5e9182393c670cb8 Mon Sep 17 00:00:00 2001 From: jcwimer Date: Tue, 30 Jun 2015 17:59:02 +0000 Subject: [PATCH] Created a weigh in page --- app/controllers/static_pages_controller.rb | 27 ++++++++ app/controllers/tournaments_controller.rb | 2 +- app/controllers/wrestlers_controller.rb | 2 +- app/views/static_pages/weigh_in.html.erb | 63 +++++++++++++++++++ app/views/tournaments/show.html.erb | 2 + config/routes.rb | 3 + ...0630170119_add_offical_weight_wrestlers.rb | 6 ++ db/schema.rb | 4 +- 8 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 app/views/static_pages/weigh_in.html.erb create mode 100644 db/migrate/20150630170119_add_offical_weight_wrestlers.rb diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 0db9b77..9da4c86 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -98,4 +98,31 @@ class StaticPagesController < ApplicationController end end end + + def weigh_in + if !user_signed_in? + redirect_to root_path + end + if params[:wrestler] + Wrestler.update(params[:wrestler].keys, params[:wrestler].values) + end + if params[:tournament] + @tournament = Tournament.find(params[:tournament]) + @tournament_id = @tournament.id + @tournament_name = @tournament.name + end + if @tournament + @weights = Weight.where(tournament_id: @tournament.id) + @weights = @weights.sort_by{|x|[x.max]} + end + if params[:weight] + @weight = Weight.find(params[:weight]) + @tournament_id = @weight.tournament_id + @tournament_name = Tournament.find(@tournament_id).name + end + if @weight + @wrestlers = @weight.wrestlers + + end + end end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 5830ad1..364e121 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -83,6 +83,6 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type) + params.require(:tournament).permit(:name, :address, :director, :director_email, :tournament_type, :weigh_in_ref) end end diff --git a/app/controllers/wrestlers_controller.rb b/app/controllers/wrestlers_controller.rb index 26188a2..be87ce9 100644 --- a/app/controllers/wrestlers_controller.rb +++ b/app/controllers/wrestlers_controller.rb @@ -102,6 +102,6 @@ class WrestlersController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def wrestler_params - params.require(:wrestler).permit(:name, :school_id, :weight_id, :seed, :original_seed, :season_win, :season_loss,:criteria,:extra) + params.require(:wrestler).permit(:name, :school_id, :weight_id, :seed, :original_seed, :season_win, :season_loss,:criteria,:extra,:offical_weight) end end diff --git a/app/views/static_pages/weigh_in.html.erb b/app/views/static_pages/weigh_in.html.erb new file mode 100644 index 0000000..0d89037 --- /dev/null +++ b/app/views/static_pages/weigh_in.html.erb @@ -0,0 +1,63 @@ +<%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %> +
+
+<% if @tournament %> + <% @weights.each do |weight| %> + <%= link_to "#{weight.max}" , "/static_pages/weigh_in?weight=#{weight.id}" %> +
+ <% end %> +
+ <% if user_signed_in? %> + <%= form_for(@tournament) do |f| %> +
+ <%= f.label :weigh_in_ref %>
+ <%= f.text_field :weigh_in_ref %> +
+
+ <%= f.submit 'Submit', :class=>"btn btn-success" %> + <% end %> + <% end %> +<% end %> + +<% if @weight %> + <%= link_to "Back to weigh in weights","/static_pages/weigh_in?tournament=#{@tournament_id}", :class=>"btn btn-default" %> +

+ + + + + + + + + + + + <%= form_tag @wrestlers_update_path do %> + <% @wrestlers.order("original_seed asc").each do |wrestler| %> + <% if wrestler.weight_id == @weight.id %> + + + + + + + + <% end %> + <% end %> + +
NameSchoolSeedWeight ClassOffical Weight
<%= wrestler.name %><%= School.find(wrestler.school_id).name %><%= wrestler.weight.max %><%= wrestler.original_seed %> + <% if user_signed_in? %> + <%= fields_for "wrestler[]", wrestler do |w| %> + <%= w.number_field :offical_weight, :step => 'any' %> + <% end %> + <% else %> + <%= wrestler.offical_weight %> + <% end %> +
+ <%= hidden_field_tag :tournament, @tournament_id %> + <% if user_signed_in? %> + <%= submit_tag "Save", :class=>"btn btn-success"%> + <% end %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb index e52f3e0..7b0a121 100644 --- a/app/views/tournaments/show.html.erb +++ b/app/views/tournaments/show.html.erb @@ -32,6 +32,8 @@
<% if user_signed_in? %> <%= link_to "Generate Pool Matches" , "/static_pages/generate_matches?tournament=#{@tournament.id}", data: { confirm: 'Are you sure? This will delete all current matches.' }, :class=>"btn btn-success" %> +

+<%= link_to "Weigh In Page" , "/static_pages/weigh_in?tournament=#{@tournament.id}", :class=>"btn btn-primary" %>

<% end %> diff --git a/config/routes.rb b/config/routes.rb index d5dacaf..596498a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -33,6 +33,9 @@ Wrestling::Application.routes.draw do get 'static_pages/noMatches' get 'static_pages/createCustomWeights' get 'static_pages/generate_matches' + get 'static_pages/weigh_in' + post 'static_pages/weigh_in' + # Example of regular route: # get 'products/:id' => 'catalog#view' diff --git a/db/migrate/20150630170119_add_offical_weight_wrestlers.rb b/db/migrate/20150630170119_add_offical_weight_wrestlers.rb new file mode 100644 index 0000000..781ac84 --- /dev/null +++ b/db/migrate/20150630170119_add_offical_weight_wrestlers.rb @@ -0,0 +1,6 @@ +class AddOfficalWeightWrestlers < ActiveRecord::Migration + def change + add_column :tournaments, :weigh_in_ref, :text + add_column :wrestlers, :offical_weight, :decimal + end +end diff --git a/db/schema.rb b/db/schema.rb index eaafe4d..92768cd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150619142023) do +ActiveRecord::Schema.define(version: 20150630170119) do create_table "matches", force: :cascade do |t| t.integer "w1" @@ -65,6 +65,7 @@ ActiveRecord::Schema.define(version: 20150619142023) do t.datetime "created_at" t.datetime "updated_at" t.text "tournament_type" + t.text "weigh_in_ref" end create_table "users", force: :cascade do |t| @@ -106,6 +107,7 @@ ActiveRecord::Schema.define(version: 20150619142023) do t.integer "season_loss" t.string "criteria" t.boolean "extra" + t.decimal "offical_weight" end add_index "wrestlers", ["weight_id"], name: "index_wrestlers_on_weight_id"