mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-23 06:41:00 +00:00
Added pages for teampointsadjust and spearated wrestler and school deducted points
This commit is contained in:
@@ -1,10 +1,38 @@
|
|||||||
class TournamentsController < ApplicationController
|
class TournamentsController < ApplicationController
|
||||||
before_action :set_tournament, only: [: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: [: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_filter :check_access_manage, only: [:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
|
before_filter :check_access_manage, only: [:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
|
||||||
before_filter :check_access_destroy, only: [:destroy,:delegate,:remove_delegate]
|
before_filter :check_access_destroy, only: [:destroy,:delegate,:remove_delegate]
|
||||||
|
|
||||||
before_filter :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
|
before_filter :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
|
||||||
|
|
||||||
|
def remove_teampointadjust
|
||||||
|
if params[:teampointadjust]
|
||||||
|
@points = Teampointadjust.find(params[:teampointadjust])
|
||||||
|
@points.destroy
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to "/tournaments/#{@tournament.id}/teampointadjust", notice: 'Point adjustment removed successfully' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def teampointadjust
|
||||||
|
if params[:teampointadjust]
|
||||||
|
@points = Teampointadjust.new
|
||||||
|
@points.wrestler_id = params[:teampointadjust]["wrestler_id"]
|
||||||
|
@points.school_id = params[:teampointadjust]["school_id"]
|
||||||
|
@points.points = params[:teampointadjust]["points"]
|
||||||
|
respond_to do |format|
|
||||||
|
if @points.save
|
||||||
|
format.html { redirect_to "/tournaments/#{@tournament.id}/teampointadjust", notice: 'Point adjustment added successfully' }
|
||||||
|
else
|
||||||
|
format.html { redirect_to "/tournaments/#{@tournament.id}/teampointadjust", notice: 'There was an issue saving point adjustment please try again' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@point_adjustments = @tournament.pointAdjustments
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def remove_delegate
|
def remove_delegate
|
||||||
if params[:delegate]
|
if params[:delegate]
|
||||||
@delegate = TournamentDelegate.find(params[:delegate])
|
@delegate = TournamentDelegate.find(params[:delegate])
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class School < ActiveRecord::Base
|
class School < ActiveRecord::Base
|
||||||
belongs_to :tournament, touch: true
|
belongs_to :tournament, touch: true
|
||||||
has_many :wrestlers, dependent: :destroy
|
has_many :wrestlers, dependent: :destroy
|
||||||
has_many :deductedPoints, through: :wrestlers
|
has_many :deductedPoints, class_name: "Teampointadjust"
|
||||||
has_many :delegates, class_name: "SchoolDelegate"
|
has_many :delegates, class_name: "SchoolDelegate"
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
@@ -33,9 +33,14 @@ class School < ActiveRecord::Base
|
|||||||
|
|
||||||
def totalDeductedPoints
|
def totalDeductedPoints
|
||||||
points = 0
|
points = 0
|
||||||
self.deductedPoints.each do |d|
|
deductedPoints.each do |d|
|
||||||
points = points + d.points
|
points = points + d.points
|
||||||
end
|
end
|
||||||
|
self.wrestlers.each do |w|
|
||||||
|
w.deductedPoints.each do |d|
|
||||||
|
points = points + d.points
|
||||||
|
end
|
||||||
|
end
|
||||||
points
|
points
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,28 @@
|
|||||||
class Teampointadjust < ActiveRecord::Base
|
class Teampointadjust < ActiveRecord::Base
|
||||||
belongs_to :wrestler
|
belongs_to :wrestler
|
||||||
|
belongs_to :school
|
||||||
|
|
||||||
after_save do
|
after_save do
|
||||||
self.wrestler.lastFinishedMatch.advance_wrestlers
|
advance_wrestlers_and_calc_team_score
|
||||||
|
end
|
||||||
|
|
||||||
|
after_destroy do
|
||||||
|
advance_wrestlers_and_calc_team_score
|
||||||
|
end
|
||||||
|
|
||||||
|
def advance_wrestlers_and_calc_team_score
|
||||||
|
#Team score needs calculated
|
||||||
|
if self.wrestler_id != nil
|
||||||
|
#In case this affects pool order
|
||||||
|
if self.wrestler.lastFinishedMatch
|
||||||
|
self.wrestler.lastFinishedMatch.advance_wrestlers
|
||||||
|
end
|
||||||
|
self.wrestler.school.calcScore
|
||||||
|
elsif self.school_id != nil
|
||||||
|
self.school.calcScore
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if Rails.env.production?
|
||||||
|
handle_asynchronously :advance_wrestlers_and_calc_team_score
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -86,4 +86,19 @@ class Tournament < ActiveRecord::Base
|
|||||||
m.save
|
m.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pointAdjustments
|
||||||
|
point_adjustments = []
|
||||||
|
self.schools.each do |s|
|
||||||
|
s.deductedPoints.each do |d|
|
||||||
|
point_adjustments << d
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.wrestlers.each do |w|
|
||||||
|
w.deductedPoints.each do |d|
|
||||||
|
point_adjustments << d
|
||||||
|
end
|
||||||
|
end
|
||||||
|
point_adjustments
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
<br><%= link_to "Weigh In Page" , "/tournaments/#{@tournament.id}/weigh_in" %>
|
<br><%= link_to "Weigh In Page" , "/tournaments/#{@tournament.id}/weigh_in" %>
|
||||||
<br><%= link_to "All Matches" , "/tournaments/#{@tournament.id}/matches" %>
|
<br><%= link_to "All Matches" , "/tournaments/#{@tournament.id}/matches" %>
|
||||||
<br><%= link_to "Full Screen Bout Board" , "/tournaments/#{@tournament.id}/up_matches?print=true" %>
|
<br><%= link_to "Full Screen Bout Board" , "/tournaments/#{@tournament.id}/up_matches?print=true" %>
|
||||||
|
<br><%= link_to "Deduct Team Points" , "/tournaments/#{@tournament.id}/teampointadjust" %>
|
||||||
<% if can? :destroy, @tournament %>
|
<% if can? :destroy, @tournament %>
|
||||||
<br><%= link_to "Tournament Delegation" , "/tournaments/#{@tournament.id}/delegate" %>
|
<br><%= link_to "Tournament Delegation" , "/tournaments/#{@tournament.id}/delegate" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
62
app/views/tournaments/teampointadjust.html.erb
Normal file
62
app/views/tournaments/teampointadjust.html.erb
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h1>New Point Adjustment</h1>
|
||||||
|
</br>
|
||||||
|
</br>
|
||||||
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Wrestler Deducted</th>
|
||||||
|
<th>School Deducted</th>
|
||||||
|
<th>Points To Deduct</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
|
||||||
|
<%= form_for Teampointadjust.new, :url => url_for(:controller => 'tournaments', :action => 'teampointadjust', :method => "post") do |f| %>
|
||||||
|
<td><%= f.collection_select :wrestler_id, @tournament.wrestlers, :id, :name, :include_blank => true %></td>
|
||||||
|
<td><%= f.collection_select :school_id, @tournament.schools, :id, :name, :include_blank => true %></td>
|
||||||
|
<td><%= f.number_field :points, :step => 'any' %></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p>Please leave either wrestler or school blank. Please do not choose both (the team will be double decuted the points)</p>
|
||||||
|
<% if can? :manage, @tournament %>
|
||||||
|
<%= submit_tag "Deduct Points", :class=>"btn btn-success"%>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<br>
|
||||||
|
<% if @point_adjustments.size > 0 %>
|
||||||
|
<h1>Point Adjustments</h1>
|
||||||
|
</br>
|
||||||
|
</br>
|
||||||
|
<table class="table table-striped table-bordered table-condensed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Against</th>
|
||||||
|
<th>Points Deducted</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @point_adjustments.each do |point_adjustment| %>
|
||||||
|
<tr>
|
||||||
|
<td><% if point_adjustment.school_id != nil %>
|
||||||
|
<%= point_adjustment.school.name %>
|
||||||
|
<% elsif point_adjustment.wrestler_id != nil %>
|
||||||
|
<%= point_adjustment.wrestler.name %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td><%= point_adjustment.points %></td>
|
||||||
|
<td><%= link_to 'Remove Point Adjustment', "/tournaments/#{@tournament.id}/#{point_adjustment.id}/remove_teampointadjust", method: :delete, confirm: 'Are you sure?', :class=>"btn btn-danger btn-sm" %></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<% end %>
|
||||||
@@ -45,6 +45,9 @@ Wrestling::Application.routes.draw do
|
|||||||
get 'tournaments/:id/school_delegate' => 'tournaments#school_delegate', :as => :school_delegate
|
get 'tournaments/:id/school_delegate' => 'tournaments#school_delegate', :as => :school_delegate
|
||||||
post 'tournaments/:id/school_delegate' => 'tournaments#school_delegate', :as => :set_school_delegate
|
post 'tournaments/:id/school_delegate' => 'tournaments#school_delegate', :as => :set_school_delegate
|
||||||
delete 'tournaments/:id/:delegate/remove_school_delegate' => 'tournaments#remove_school_delegate', :as => :delete_school_delegate_path
|
delete 'tournaments/:id/:delegate/remove_school_delegate' => 'tournaments#remove_school_delegate', :as => :delete_school_delegate_path
|
||||||
|
get 'tournaments/:id/teampointadjust' => 'tournaments#teampointadjust'
|
||||||
|
post 'tournaments/:id/teampointadjust' => 'tournaments#teampointadjust'
|
||||||
|
delete 'tournaments/:id/:teampointadjust/remove_teampointadjust' => 'tournaments#remove_teampointadjust'
|
||||||
|
|
||||||
# Example of regular route:
|
# Example of regular route:
|
||||||
# get 'products/:id' => 'catalog#view'
|
# get 'products/:id' => 'catalog#view'
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddSchoolIdToTeampointsadjust < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :teampointadjusts, :school_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160106031418) do
|
ActiveRecord::Schema.define(version: 20160112152946) do
|
||||||
|
|
||||||
create_table "delayed_jobs", force: :cascade do |t|
|
create_table "delayed_jobs", force: :cascade do |t|
|
||||||
t.integer "priority", default: 0, null: false
|
t.integer "priority", default: 0, null: false
|
||||||
@@ -86,6 +86,7 @@ ActiveRecord::Schema.define(version: 20160106031418) do
|
|||||||
t.integer "wrestler_id"
|
t.integer "wrestler_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.integer "school_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "teampointadjusts", ["wrestler_id"], name: "index_teampointadjusts_on_wrestler_id"
|
add_index "teampointadjusts", ["wrestler_id"], name: "index_teampointadjusts_on_wrestler_id"
|
||||||
|
|||||||
Reference in New Issue
Block a user