diff --git a/app/controllers/mats_controller.rb b/app/controllers/mats_controller.rb index 9485d71..c245ad1 100644 --- a/app/controllers/mats_controller.rb +++ b/app/controllers/mats_controller.rb @@ -1,16 +1,35 @@ class MatsController < ApplicationController - before_action :set_mat, only: [:show, :edit, :update, :destroy] - before_action :check_access, only: [:new,:create,:update,:destroy,:edit,:show] + before_action :set_mat, only: [:show, :edit, :update, :destroy, :assign_next_match] + before_action :check_access, only: [:new,:create,:update,:destroy,:edit,:show, :assign_next_match] before_action :check_for_matches, only: [:show] # GET /mats/1 # GET /mats/1.json def show @match = @mat.unfinished_matches.first + @wrestlers = [] if @match - @w1 = @match.wrestler1 - @w2 = @match.wrestler2 - @wrestlers = [@w1,@w2] + if @match.w1 + @wrestler1_name = @match.wrestler1.name + @wrestler1_school_name = @match.wrestler1.school.name + @wrestler1_last_match = @match.wrestler1.last_match + @wrestlers.push(@match.wrestler1) + else + @wrestler1_name = "Not assigned" + @wrestler1_school_name = "N/A" + @wrestler1_last_match = nil + end + if @match.w2 + @wrestler2_name = @match.wrestler2.name + @wrestler2_school_name = @match.wrestler2.school.name + @wrestler2_last_match = @match.wrestler2.last_match + @wrestlers.push(@match.wrestler2) + else + @wrestler2_name = "Not assigned" + @wrestler2_school_name = "N/A" + @wrestler2_last_match = nil + end + @tournament = @match.tournament end session[:return_path] = request.original_fullpath end @@ -44,6 +63,20 @@ class MatsController < ApplicationController end end + # POST /mats/1/assign_next_match + def assign_next_match + @tournament = @mat.tournament_id + respond_to do |format| + if @mat.assign_next_match + format.html { redirect_to "/tournaments/#{@mat.tournament.id}", notice: "Next Match on Mat #{@mat.name} successfully completed." } + format.json { head :no_content } + else + format.html { redirect_to "/tournaments/#{@mat.tournament.id}", alert: "There was an error." } + format.json { head :no_content } + end + end + end + # PATCH/PUT /mats/1 # PATCH/PUT /mats/1.json def update diff --git a/app/models/mat.rb b/app/models/mat.rb index c23ec82..b557f43 100644 --- a/app/models/mat.rb +++ b/app/models/mat.rb @@ -22,10 +22,16 @@ class Mat < ActiveRecord::Base def assign_next_match t_matches = tournament.matches.select{|m| m.mat_id == nil && m.finished != 1 && m.bout_number != nil}.sort_by{|m| m.bout_number} - if t_matches.size > 0 + if t_matches.size > 0 and self.unfinished_matches.size < 4 match = t_matches.sort_by{|m| m.bout_number}.first match.mat_id = self.id - match.save + if match.save + return true + else + return false + end + else + return true end end diff --git a/app/views/mats/_match_edit_form.html.erb b/app/views/mats/_match_edit_form.html.erb deleted file mode 100644 index 66ac5df..0000000 --- a/app/views/mats/_match_edit_form.html.erb +++ /dev/null @@ -1,228 +0,0 @@ -<%= form_for(@match) do |f| %> - <% if @match.errors.any? %> -
| <%= @w1.name %> - <%= @w1.school.name %> Last Match: <%= if @w1.last_match != nil then time_ago_in_words(@w1.last_match.updated_at) end%> |
- <%= @w2.name %> - <%= @w2.school.name %> Last Match: <%= if @w2.last_match != nil then time_ago_in_words(@w2.last_match.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 |
-