diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb
index 4bbec15..bcdc67c 100644
--- a/app/controllers/tournaments_controller.rb
+++ b/app/controllers/tournaments_controller.rb
@@ -1,10 +1,38 @@
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_filter :check_access_manage, only: [:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
+ 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: [: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_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
if params[:delegate]
@delegate = TournamentDelegate.find(params[:delegate])
diff --git a/app/models/school.rb b/app/models/school.rb
index 35eba7d..a29eabd 100644
--- a/app/models/school.rb
+++ b/app/models/school.rb
@@ -1,7 +1,7 @@
class School < ActiveRecord::Base
belongs_to :tournament, touch: true
has_many :wrestlers, dependent: :destroy
- has_many :deductedPoints, through: :wrestlers
+ has_many :deductedPoints, class_name: "Teampointadjust"
has_many :delegates, class_name: "SchoolDelegate"
validates :name, presence: true
@@ -33,9 +33,14 @@ class School < ActiveRecord::Base
def totalDeductedPoints
points = 0
- self.deductedPoints.each do |d|
+ deductedPoints.each do |d|
points = points + d.points
end
+ self.wrestlers.each do |w|
+ w.deductedPoints.each do |d|
+ points = points + d.points
+ end
+ end
points
end
end
diff --git a/app/models/teampointadjust.rb b/app/models/teampointadjust.rb
index ca2d708..c78f9d0 100644
--- a/app/models/teampointadjust.rb
+++ b/app/models/teampointadjust.rb
@@ -1,7 +1,28 @@
class Teampointadjust < ActiveRecord::Base
belongs_to :wrestler
+ belongs_to :school
- after_save do
- self.wrestler.lastFinishedMatch.advance_wrestlers
+ after_save do
+ 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
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index e2a983a..3469424 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -86,4 +86,19 @@ class Tournament < ActiveRecord::Base
m.save
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
diff --git a/app/views/layouts/_lsidebar.html.erb b/app/views/layouts/_lsidebar.html.erb
index 1b72ab6..ccfabe7 100644
--- a/app/views/layouts/_lsidebar.html.erb
+++ b/app/views/layouts/_lsidebar.html.erb
@@ -21,6 +21,7 @@
<%= link_to "Weigh In Page" , "/tournaments/#{@tournament.id}/weigh_in" %>
<%= link_to "All Matches" , "/tournaments/#{@tournament.id}/matches" %>
<%= link_to "Full Screen Bout Board" , "/tournaments/#{@tournament.id}/up_matches?print=true" %>
+
<%= link_to "Deduct Team Points" , "/tournaments/#{@tournament.id}/teampointadjust" %>
<% if can? :destroy, @tournament %>
<%= link_to "Tournament Delegation" , "/tournaments/#{@tournament.id}/delegate" %>
<% end %>
diff --git a/app/views/tournaments/teampointadjust.html.erb b/app/views/tournaments/teampointadjust.html.erb
new file mode 100644
index 0000000..3844354
--- /dev/null
+++ b/app/views/tournaments/teampointadjust.html.erb
@@ -0,0 +1,62 @@
+<%= link_to "Back to #{@tournament_name}", "/tournaments/#{@tournament_id}", :class=>"btn btn-default" %>
+
+
+
+
+
+
| Wrestler Deducted | +School Deducted | +Points To Deduct | +
|---|---|---|
| <%= f.collection_select :wrestler_id, @tournament.wrestlers, :id, :name, :include_blank => true %> | +<%= f.collection_select :school_id, @tournament.schools, :id, :name, :include_blank => true %> | +<%= f.number_field :points, :step => 'any' %> | +
Please leave either wrestler or school blank. Please do not choose both (the team will be double decuted the points)
+ <% if can? :manage, @tournament %> + <%= submit_tag "Deduct Points", :class=>"btn btn-success"%> + <% end %> + <% end %> +| Against | +Points Deducted | ++ |
|---|---|---|
| <% if point_adjustment.school_id != nil %> + <%= point_adjustment.school.name %> + <% elsif point_adjustment.wrestler_id != nil %> + <%= point_adjustment.wrestler.name %> + <% end %> + | +<%= point_adjustment.points %> | +<%= 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" %> | +