diff options
author | AndrewMurrell <amurrel@purdue.edu> | 2014-03-07 00:41:47 -0500 |
---|---|---|
committer | AndrewMurrell <amurrel@purdue.edu> | 2014-03-07 00:41:47 -0500 |
commit | fd213819fa004209fc466b19ee65d83b1f918068 (patch) | |
tree | ecfe47daa486da7d878207ac6a799b6fab79deab | |
parent | 5ca9bd493d0348d56a3a8ce56923a72230515fe0 (diff) | |
parent | 8fc6b48caccdb8fbfe04e41282444e0b916883b3 (diff) |
Merge branch 'master' of http://github.com/LukeShu/leaguer
-rw-r--r-- | app/controllers/matches_controller.rb | 4 | ||||
-rw-r--r-- | app/models/match.rb | 4 | ||||
-rw-r--r-- | app/views/matches/_form.html.erb | 4 | ||||
-rw-r--r-- | app/views/matches/index.html.erb | 2 | ||||
-rw-r--r-- | app/views/matches/index.json.jbuilder | 2 | ||||
-rw-r--r-- | app/views/matches/show.html.erb | 24 | ||||
-rw-r--r-- | app/views/matches/show.json.jbuilder | 2 | ||||
-rw-r--r-- | app/views/tournaments/_selected.html.erb | 2 | ||||
-rw-r--r-- | app/views/tournaments/index.html.erb | 2 | ||||
-rw-r--r-- | db/migrate/20140307052327_create_servers.rb (renamed from db/migrate/20140307045916_create_servers.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052331_create_matches.rb (renamed from db/migrate/20140307045922_create_matches.rb) | 1 | ||||
-rw-r--r-- | db/migrate/20140307052334_create_teams.rb (renamed from db/migrate/20140307045927_create_teams.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052338_create_alerts.rb (renamed from db/migrate/20140307045934_create_alerts.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052342_create_pms.rb (renamed from db/migrate/20140307045941_create_pms.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052346_create_tournaments.rb (renamed from db/migrate/20140307045948_create_tournaments.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052350_create_games.rb (renamed from db/migrate/20140307045954_create_games.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052354_create_users.rb (renamed from db/migrate/20140307050001_create_users.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052358_create_sessions.rb (renamed from db/migrate/20140307050008_create_sessions.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052402_create_server_settings.rb (renamed from db/migrate/20140307050016_create_server_settings.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052405_create_tournament_options.rb (renamed from db/migrate/20140307050023_create_tournament_options.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052409_create_game_options.rb (renamed from db/migrate/20140307050029_create_game_options.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052413_create_scores.rb (renamed from db/migrate/20140307050035_create_scores.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052417_create_tournament_players_join_table.rb (renamed from db/migrate/20140307050041_create_tournament_players_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052421_create_tournament_hosts_join_table.rb (renamed from db/migrate/20140307050046_create_tournament_hosts_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052424_create_team_user_join_table.rb (renamed from db/migrate/20140307050052_create_team_user_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052428_create_match_team_join_table.rb (renamed from db/migrate/20140307050059_create_match_team_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140307052443_add_hidden_attrs_to_user.rb (renamed from db/migrate/20140307050124_add_hidden_attrs_to_user.rb) | 0 | ||||
-rw-r--r-- | db/schema.rb | 4 | ||||
-rwxr-xr-x | generate.sh | 2 | ||||
-rw-r--r-- | test/controllers/matches_controller_test.rb | 4 | ||||
-rw-r--r-- | test/fixtures/matches.yml | 2 |
31 files changed, 48 insertions, 11 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 23d2700..986bb44 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,5 +1,5 @@ class MatchesController < ApplicationController - before_action :set_tournament, only: [:index] + before_action :set_tournament, only: [:index, :new, :create] before_action :set_match, only: [:show, :edit, :update, :destroy] # GET /matches # GET /matches.json @@ -72,6 +72,6 @@ class MatchesController < ApplicationController end # Never trust parameters from the scary internet, only allow the white list through. def match_params - params.require(:match).permit(:tournament_id, :name) + params.require(:match).permit(:tournament_id, :name, :winner_id) end end diff --git a/app/models/match.rb b/app/models/match.rb index 83d2e7b..7dacae5 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,4 +1,8 @@ class Match < ActiveRecord::Base belongs_to :tournament + has_and_belongs_to_many :teams + + belongs_to :winner + end diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb index 015aed0..67d30da 100644 --- a/app/views/matches/_form.html.erb +++ b/app/views/matches/_form.html.erb @@ -8,6 +8,10 @@ <%= f.label :name %><br> <%= f.text_field :name %> </div> + <div class="field"> + <%= f.label :winner_id %><br> + <%= f.text_field :winner_id %> + </div> <div class="actions"> <%= f.submit %> </div> diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index d635834..ff42ef1 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -5,6 +5,7 @@ <tr> <th>Tournament</th> <th>Name</th> + <th>Winner</th> <th></th> <th></th> <th></th> @@ -16,6 +17,7 @@ <tr> <td><%= match.tournament %></td> <td><%= match.name %></td> + <td><%= match.winner %></td> <td><%= link_to 'Show', tournament_match_path(@tournament, match) %></td> <td><%= link_to 'Edit', edit_tournament_match_path(@tournament, match) %></td> <td><%= link_to 'Destroy', tournament_match_path(@tournament, match), method: :delete, data: { confirm: 'Are you sure?' } %></td> diff --git a/app/views/matches/index.json.jbuilder b/app/views/matches/index.json.jbuilder index 08ae0ef..0b2bfcd 100644 --- a/app/views/matches/index.json.jbuilder +++ b/app/views/matches/index.json.jbuilder @@ -1,4 +1,4 @@ json.array!(@matches) do |match| - json.extract! match, :id, :tournament_id, :name + json.extract! match, :id, :tournament_id, :name, :winner_id json.url match_url(match, format: :json) end diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index e95cd07..f5a3686 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -1,6 +1,6 @@ <p> <strong>Tournament:</strong> - <%= @match.tournament %> + <%= @match.tournament.id %> </p> <p> @@ -8,5 +8,27 @@ <%= @match.name %> </p> +<% if @tournament.hosts.include?(current_user) %> + <%= form_for(@match, method: "put") do |f| %> + <ul> + <% @match.teams.each do |team| %> + <li><label><%= f.radio_button(:winner, team.id) %> + <%= team.users.collect{|u| u.user_name}.join(", ") %></label></li> + <% end %> + </ul> + <%= f.submit("Select winner") %> + <% end %> +<% end %> + <%= link_to 'Edit', edit_tournament_match_path(@tournament, @match) %> | <%= link_to 'Back', tournament_matches_path %> + +<% unless @match.winner.nil? %> + <p> + <strong>Winner:</strong> + <%= @match.winner.users.collect{|u| u.user_name}.join(", ") %> + </p> +<% end %> +<%= link_to 'Edit', edit_match_path(@match) %> | +<%= link_to 'Back', matches_path %> + diff --git a/app/views/matches/show.json.jbuilder b/app/views/matches/show.json.jbuilder index 128550f..fe14010 100644 --- a/app/views/matches/show.json.jbuilder +++ b/app/views/matches/show.json.jbuilder @@ -1 +1 @@ -json.extract! @match, :id, :tournament_id, :name, :created_at, :updated_at +json.extract! @match, :id, :tournament_id, :name, :winner_id, :created_at, :updated_at diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb index 925e127..9b1b7f8 100644 --- a/app/views/tournaments/_selected.html.erb +++ b/app/views/tournaments/_selected.html.erb @@ -4,7 +4,7 @@ <% @chosen = Game.find_by(params[:game]) %> <% @tournament.attributes.each do |name, value| %> - <% if (name == "id") or (name =~ /.*_at$/) or (name == "game_id") or (name == "statuss") %> + <% if (name == "id") or (name =~ /.*_at$/) or (name == "game_id") or (name == "status") %> <% next %> <% end %> <p> diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index 452d939..d4ef414 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -21,7 +21,7 @@ <tbody> <% @tournaments.each do |tournament| %> <tr> - <td><%= tournament.game %></td> + <td><%= tournament.id %></td> <td><%= tournament.status %></td> <td><%= tournament.min_players_per_team %></td> <td><%= tournament.max_players_per_team %></td> diff --git a/db/migrate/20140307045916_create_servers.rb b/db/migrate/20140307052327_create_servers.rb index f33241a..f33241a 100644 --- a/db/migrate/20140307045916_create_servers.rb +++ b/db/migrate/20140307052327_create_servers.rb diff --git a/db/migrate/20140307045922_create_matches.rb b/db/migrate/20140307052331_create_matches.rb index 325863d..67a5b7b 100644 --- a/db/migrate/20140307045922_create_matches.rb +++ b/db/migrate/20140307052331_create_matches.rb @@ -3,6 +3,7 @@ class CreateMatches < ActiveRecord::Migration create_table :matches do |t| t.references :tournament, index: true t.string :name + t.references :winner, index: true t.timestamps end diff --git a/db/migrate/20140307045927_create_teams.rb b/db/migrate/20140307052334_create_teams.rb index fdf9a68..fdf9a68 100644 --- a/db/migrate/20140307045927_create_teams.rb +++ b/db/migrate/20140307052334_create_teams.rb diff --git a/db/migrate/20140307045934_create_alerts.rb b/db/migrate/20140307052338_create_alerts.rb index 68a8e10..68a8e10 100644 --- a/db/migrate/20140307045934_create_alerts.rb +++ b/db/migrate/20140307052338_create_alerts.rb diff --git a/db/migrate/20140307045941_create_pms.rb b/db/migrate/20140307052342_create_pms.rb index 93bb5c6..93bb5c6 100644 --- a/db/migrate/20140307045941_create_pms.rb +++ b/db/migrate/20140307052342_create_pms.rb diff --git a/db/migrate/20140307045948_create_tournaments.rb b/db/migrate/20140307052346_create_tournaments.rb index 545e603..545e603 100644 --- a/db/migrate/20140307045948_create_tournaments.rb +++ b/db/migrate/20140307052346_create_tournaments.rb diff --git a/db/migrate/20140307045954_create_games.rb b/db/migrate/20140307052350_create_games.rb index 5e4f56f..5e4f56f 100644 --- a/db/migrate/20140307045954_create_games.rb +++ b/db/migrate/20140307052350_create_games.rb diff --git a/db/migrate/20140307050001_create_users.rb b/db/migrate/20140307052354_create_users.rb index 8032870..8032870 100644 --- a/db/migrate/20140307050001_create_users.rb +++ b/db/migrate/20140307052354_create_users.rb diff --git a/db/migrate/20140307050008_create_sessions.rb b/db/migrate/20140307052358_create_sessions.rb index fe25bf2..fe25bf2 100644 --- a/db/migrate/20140307050008_create_sessions.rb +++ b/db/migrate/20140307052358_create_sessions.rb diff --git a/db/migrate/20140307050016_create_server_settings.rb b/db/migrate/20140307052402_create_server_settings.rb index dfdd91b..dfdd91b 100644 --- a/db/migrate/20140307050016_create_server_settings.rb +++ b/db/migrate/20140307052402_create_server_settings.rb diff --git a/db/migrate/20140307050023_create_tournament_options.rb b/db/migrate/20140307052405_create_tournament_options.rb index 53b601c..53b601c 100644 --- a/db/migrate/20140307050023_create_tournament_options.rb +++ b/db/migrate/20140307052405_create_tournament_options.rb diff --git a/db/migrate/20140307050029_create_game_options.rb b/db/migrate/20140307052409_create_game_options.rb index 2f62ef7..2f62ef7 100644 --- a/db/migrate/20140307050029_create_game_options.rb +++ b/db/migrate/20140307052409_create_game_options.rb diff --git a/db/migrate/20140307050035_create_scores.rb b/db/migrate/20140307052413_create_scores.rb index 4ca0b0b..4ca0b0b 100644 --- a/db/migrate/20140307050035_create_scores.rb +++ b/db/migrate/20140307052413_create_scores.rb diff --git a/db/migrate/20140307050041_create_tournament_players_join_table.rb b/db/migrate/20140307052417_create_tournament_players_join_table.rb index be240e8..be240e8 100644 --- a/db/migrate/20140307050041_create_tournament_players_join_table.rb +++ b/db/migrate/20140307052417_create_tournament_players_join_table.rb diff --git a/db/migrate/20140307050046_create_tournament_hosts_join_table.rb b/db/migrate/20140307052421_create_tournament_hosts_join_table.rb index 7521d89..7521d89 100644 --- a/db/migrate/20140307050046_create_tournament_hosts_join_table.rb +++ b/db/migrate/20140307052421_create_tournament_hosts_join_table.rb diff --git a/db/migrate/20140307050052_create_team_user_join_table.rb b/db/migrate/20140307052424_create_team_user_join_table.rb index f3b57fc..f3b57fc 100644 --- a/db/migrate/20140307050052_create_team_user_join_table.rb +++ b/db/migrate/20140307052424_create_team_user_join_table.rb diff --git a/db/migrate/20140307050059_create_match_team_join_table.rb b/db/migrate/20140307052428_create_match_team_join_table.rb index c2ed1b7..c2ed1b7 100644 --- a/db/migrate/20140307050059_create_match_team_join_table.rb +++ b/db/migrate/20140307052428_create_match_team_join_table.rb diff --git a/db/migrate/20140307050124_add_hidden_attrs_to_user.rb b/db/migrate/20140307052443_add_hidden_attrs_to_user.rb index 2f1b0b2..2f1b0b2 100644 --- a/db/migrate/20140307050124_add_hidden_attrs_to_user.rb +++ b/db/migrate/20140307052443_add_hidden_attrs_to_user.rb diff --git a/db/schema.rb b/db/schema.rb index c9c0fa6..55f4046 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: 20140307050124) do +ActiveRecord::Schema.define(version: 20140307052443) do create_table "alerts", force: true do |t| t.integer "author_id" @@ -50,11 +50,13 @@ ActiveRecord::Schema.define(version: 20140307050124) do create_table "matches", force: true do |t| t.integer "tournament_id" t.string "name" + t.integer "winner_id" t.datetime "created_at" t.datetime "updated_at" end add_index "matches", ["tournament_id"], name: "index_matches_on_tournament_id" + add_index "matches", ["winner_id"], name: "index_matches_on_winner_id" create_table "matches_teams", id: false, force: true do |t| t.integer "match_id", null: false diff --git a/generate.sh b/generate.sh index 739c195..45a8ab6 100755 --- a/generate.sh +++ b/generate.sh @@ -18,7 +18,7 @@ git checkout clean-start -- app test config/routes.rb # The whole shebang, models, views, and controllers bundle exec rails generate scaffold server --force $NOTEST -bundle exec rails generate scaffold match tournament:references name:string --force $NOTEST +bundle exec rails generate scaffold match tournament:references name:string winner:references --force $NOTEST bundle exec rails generate scaffold team match:references $NOTEST bundle exec rails generate scaffold alert author:references message:text $NOTEST bundle exec rails generate scaffold pm author:references recipient:references message:text $NOTEST diff --git a/test/controllers/matches_controller_test.rb b/test/controllers/matches_controller_test.rb index 50675d8..51b7f37 100644 --- a/test/controllers/matches_controller_test.rb +++ b/test/controllers/matches_controller_test.rb @@ -18,7 +18,7 @@ class MatchesControllerTest < ActionController::TestCase test "should create match" do assert_difference('Match.count') do - post :create, match: { name: @match.name, tournament_id: @match.tournament_id } + post :create, match: { name: @match.name, tournament_id: @match.tournament_id, winner_id: @match.winner_id } end assert_redirected_to match_path(assigns(:match)) @@ -35,7 +35,7 @@ class MatchesControllerTest < ActionController::TestCase end test "should update match" do - patch :update, id: @match, match: { name: @match.name, tournament_id: @match.tournament_id } + patch :update, id: @match, match: { name: @match.name, tournament_id: @match.tournament_id, winner_id: @match.winner_id } assert_redirected_to match_path(assigns(:match)) end diff --git a/test/fixtures/matches.yml b/test/fixtures/matches.yml index 089fc65..956229c 100644 --- a/test/fixtures/matches.yml +++ b/test/fixtures/matches.yml @@ -3,7 +3,9 @@ one: tournament_id: name: MyString + winner_id: two: tournament_id: name: MyString + winner_id: |