diff --git a/app/controllers/weights_controller.rb b/app/controllers/weights_controller.rb
index 54bc317..02e17af 100644
--- a/app/controllers/weights_controller.rb
+++ b/app/controllers/weights_controller.rb
@@ -1,6 +1,6 @@
class WeightsController < ApplicationController
- before_action :set_weight, only: [:show, :edit, :update, :destroy]
- before_filter :check_access, only: [:new,:create,:update,:destroy,:edit]
+ before_action :set_weight, only: [:show, :edit, :update, :destroy,:re_gen]
+ before_filter :check_access, only: [:new,:create,:update,:destroy,:edit, :re_gen]
# GET /weights/1
@@ -69,6 +69,11 @@ class WeightsController < ApplicationController
format.json { head :no_content }
end
end
+
+ def re_gen
+ @tournament = @weight.tournament
+ GenerateTournamentMatches.new(@tournament).generateWeight(@weight)
+ end
private
# Use callbacks to share common setup or constraints between actions.
diff --git a/app/services/tournament_services/generate_tournament_matches.rb b/app/services/tournament_services/generate_tournament_matches.rb
index dcf3dd8..2deda40 100644
--- a/app/services/tournament_services/generate_tournament_matches.rb
+++ b/app/services/tournament_services/generate_tournament_matches.rb
@@ -2,6 +2,19 @@ class GenerateTournamentMatches
def initialize( tournament )
@tournament = tournament
end
+
+ def generateWeight(weight)
+ WipeTournamentMatches.new(@tournament).wipeWeightMatches(weight)
+ @tournament.curently_generating_matches = 1
+ @tournament.save
+ unAssignBouts
+ PoolToBracketMatchGeneration.new(@tournament).generatePoolToBracketMatchesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
+ postMatchCreationActions
+ PoolToBracketGenerateLoserNames.new(@tournament).assignLoserNamesWeight(weight) if @tournament.tournament_type == "Pool to bracket"
+ end
+ if Rails.env.production?
+ handle_asynchronously :generateWeight
+ end
def generate
standardStartingActions
@@ -57,7 +70,13 @@ class GenerateTournamentMatches
end
end
-
+ def unAssignBouts
+ bout_counts = Hash.new(0)
+ @tournament.matches.each do |m|
+ m.bout_number = nil
+ m.save!
+ end
+ end
diff --git a/app/services/tournament_services/pool_to_bracket_generate_loser_names.rb b/app/services/tournament_services/pool_to_bracket_generate_loser_names.rb
index d315c04..49b98fc 100644
--- a/app/services/tournament_services/pool_to_bracket_generate_loser_names.rb
+++ b/app/services/tournament_services/pool_to_bracket_generate_loser_names.rb
@@ -3,6 +3,18 @@ class PoolToBracketGenerateLoserNames
@tournament = tournament
end
+ def assignLoserNamesWeight(weight)
+ matches_by_weight = @tournament.matches.where(weight_id: weight.id)
+ if weight.pool_bracket_type == "twoPoolsToSemi"
+ twoPoolsToSemiLoser(matches_by_weight)
+ elsif weight.pool_bracket_type == "fourPoolsToQuarter"
+ fourPoolsToQuarterLoser(matches_by_weight)
+ elsif weight.pool_bracket_type == "fourPoolsToSemi"
+ fourPoolsToSemiLoser(matches_by_weight)
+ end
+ saveMatches(matches_by_weight)
+ end
+
def assignLoserNames
matches_by_weight = nil
@tournament.weights.each do |w|
diff --git a/app/services/tournament_services/pool_to_bracket_match_generation.rb b/app/services/tournament_services/pool_to_bracket_match_generation.rb
index 31e9388..a961895 100644
--- a/app/services/tournament_services/pool_to_bracket_match_generation.rb
+++ b/app/services/tournament_services/pool_to_bracket_match_generation.rb
@@ -3,7 +3,13 @@ class PoolToBracketMatchGeneration
@tournament = tournament
end
-
+ def generatePoolToBracketMatchesWeight(weight)
+ PoolGeneration.new(weight).generatePools()
+ last_match = @tournament.matches.where(weight: weight).order(round: :desc).limit(1).first
+ highest_round = last_match.round
+ PoolBracketGeneration.new(weight, highest_round).generateBracketMatches()
+ setOriginalSeedsToWrestleLastPoolRound(weight)
+ end
def generatePoolToBracketMatches
@tournament.weights.order(:max).each do |weight|
diff --git a/app/services/tournament_services/wipe_tournament_matches.rb b/app/services/tournament_services/wipe_tournament_matches.rb
index e77c0cb..1738a8c 100644
--- a/app/services/tournament_services/wipe_tournament_matches.rb
+++ b/app/services/tournament_services/wipe_tournament_matches.rb
@@ -9,6 +9,10 @@ class WipeTournamentMatches
resetSchoolScores
end
+ def wipeWeightMatches(weight)
+ weight.matches.destroy_all
+ end
+
def wipeMatches
@tournament.matches.destroy_all
end
diff --git a/app/views/weights/re_gen.html.erb b/app/views/weights/re_gen.html.erb
new file mode 100644
index 0000000..c1aaac8
--- /dev/null
+++ b/app/views/weights/re_gen.html.erb
@@ -0,0 +1,3 @@
+<%= link_to "Back to #{@weight.tournament.name}", "/tournaments/#{@weight.tournament.id}", :class=>"btn btn-default" %>
+
+<%= @weight.max %> lbs Matches are being generated. This can take anywhere from 1-5 minutes to finish. It is recommended to delete all delegated school permissions to prevent lineup changes after the tournament has started.
\ No newline at end of file
diff --git a/app/views/weights/show.html.erb b/app/views/weights/show.html.erb
index e65339c..c57c886 100644
--- a/app/views/weights/show.html.erb
+++ b/app/views/weights/show.html.erb
@@ -4,6 +4,9 @@
<%= link_to "Back to #{@tournament.name}", "/tournaments/#{@tournament.id}", :class=>"btn btn-default" %>
<% if can? :manage, @tournament %>
| <%= link_to "Edit #{@weight.max} Weight Class", edit_weight_path(@weight), :class=>"btn btn-primary" %>
+ | <%= form_for(@weight, url: regen_weight_path(@weight.id), :method => "post") do |f| %>
+ <%= submit_tag "Regenerate Weight Class Matches", :class=>"btn"%>
+ <% end %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 94cc729..8a0b0c2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -51,6 +51,7 @@ Wrestling::Application.routes.draw do
get 'tournaments/:id/error' => 'tournaments#error'
post "/tournaments/:id/swap" => "tournaments#swap", :as => :swap_wrestlers
+ post 'weights/:id/re_gen' => 'weights#re_gen', :as => :regen_weight
#API
get "/api/tournaments" => "api#tournaments"
diff --git a/db/schema.rb b/db/schema.rb
index e320d6e..f37635e 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: 20160126173424) do
+ActiveRecord::Schema.define(version: 20160112152946) do
create_table "delayed_jobs", force: :cascade do |t|
t.integer "priority", default: 0, null: false