summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorguntasgrewal <guntasgrewal@gmail.com>2014-04-26 20:35:55 -0400
committerguntasgrewal <guntasgrewal@gmail.com>2014-04-26 20:35:55 -0400
commit1d24cb050f198e9c8bec8dd014de203d889ab56a (patch)
tree9f10e7a5be75d7ffb4cb829d3738a144b5250b9b /app
parent2d0fe1a4197e70cb99f4285a8b32a645914d8beb (diff)
parentdfbbe46fdcca392b3dec703cf347d1b1d57ca94f (diff)
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'app')
-rw-r--r--app/controllers/brackets_controller.rb25
-rw-r--r--app/controllers/games_controller.rb2
-rw-r--r--app/controllers/matches_controller.rb55
-rw-r--r--app/controllers/tournaments_controller.rb2
-rw-r--r--app/models/bracket.rb7
-rw-r--r--app/models/tournament.rb1
-rw-r--r--app/models/user.rb4
-rw-r--r--app/views/brackets/index.html.erb7
-rw-r--r--app/views/brackets/new.html.erb4
-rw-r--r--app/views/brackets/show.html.erb14
-rw-r--r--app/views/common/_show_tournament.html.erb3
-rw-r--r--app/views/games/_form.html.erb4
-rw-r--r--app/views/games/index.html.erb2
-rw-r--r--app/views/games/index.json.jbuilder2
-rw-r--r--app/views/games/show.html.erb5
-rw-r--r--app/views/games/show.json.jbuilder2
-rw-r--r--app/views/matches/show.html.erb20
-rw-r--r--app/views/tournaments/_form.html.erb4
-rw-r--r--app/views/tournaments/index.json.jbuilder2
-rw-r--r--app/views/tournaments/show.json.jbuilder2
20 files changed, 86 insertions, 81 deletions
diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb
index fe43ca9..ed335d6 100644
--- a/app/controllers/brackets_controller.rb
+++ b/app/controllers/brackets_controller.rb
@@ -1,10 +1,11 @@
class BracketsController < ApplicationController
- before_action :set_bracket, only: [:show, :edit, :update, :destroy]
+ before_action :set_tournament, only: [:index, :create]
# GET /brackets
# GET /brackets.json
def index
- @brackets = Bracket.all
+ @tournament = Tournament.find(params[:tournament_id])
+ @brackets = @tournament.brackets
end
# GET /brackets/1
@@ -12,11 +13,6 @@ class BracketsController < ApplicationController
def show
end
- # GET /brackets/new
- def new
- @bracket = Bracket.new
- end
-
# GET /brackets/1/edit
def edit
end
@@ -24,12 +20,14 @@ class BracketsController < ApplicationController
# POST /brackets
# POST /brackets.json
def create
- @bracket = Bracket.new(bracket_params)
+ @bracket = @tournament.brackets.create(user: current_user)
+ @bracket.name = current_user.user_name + "'s Prediction for " + @tournament.name
+ @bracket.create_matches
respond_to do |format|
if @bracket.save
format.html { redirect_to @bracket, notice: 'Bracket was successfully created.' }
- format.json { render action: 'show', status: :created, location: @bracket }
+ format.json { render action: 'edit', status: :created, location: @bracket }
else
format.html { render action: 'new' }
format.json { render json: @bracket.errors, status: :unprocessable_entity }
@@ -64,11 +62,20 @@ class BracketsController < ApplicationController
private
# Use callbacks to share common setup or constraints between actions.
def set_bracket
+ @tournament = Tournament.find(params[:tournament_id])
@bracket = Bracket.find(params[:id])
end
+ def set_tournament
+ @tournament = Tournament.find(params[:tournament_id])
+ end
+
# Never trust parameters from the scary internet, only allow the white list through.
def bracket_params
params.require(:bracket).permit(:user_id, :tournament_id, :name)
end
+
+ def is_owner?(bracket)
+ bracket.user == current_user
+ end
end
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb
index aec5294..09119c8 100644
--- a/app/controllers/games_controller.rb
+++ b/app/controllers/games_controller.rb
@@ -67,6 +67,6 @@ class GamesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def game_params
- params.require(:game).permit(:parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method)
+ params.require(:game).permit(:parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method)
end
end
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index b1b283b..a2a1269 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -168,6 +168,10 @@ class MatchesController < ApplicationController
def update
case params[:update_action]
when "start"
+ #
+ # Redirect to the current match page for this tournament with the correct sampling view rendered
+ #
+
@match.status = 1
respond_to do |format|
if @match.save
@@ -179,39 +183,13 @@ class MatchesController < ApplicationController
end
end
when "finish"
+ #
+ # Get the winner and blowout status from the params given by the correct sampling view
+ #
- #make this use the statistics interface for scoring and ScoringAlgorithms
-
- @match.winner = @match.teams.find_by_id(params['winner'])
- @match.blowout = false
-
- @match.statistics['Score'] = @tournament.settings['ScoringMethod'].constantize.score(@match, @match.statistics)
-
-=begin
-
- # Individual scores
- #scores = params["scores"]
- #scores.each do |user_name, score|
- # Statistic.create(user: User.find_by_user_name(user_name), match: @match, name: "score", value: score.to_i)
- #end
-
- # Team scores (processing for manual)
- team_scores = {}
- @match.teams.each do |team|
- team_scores[team] = 0
- team.users.each do |user|
- team_scores[team] += scores[user.user_name].to_i
- end
+ unless @match.tournament_stage.tournament.sampling.sampling_done?
+ @match.tournament_stage.tournament.sampling.handle_user_interaction(@match, current_user, params)
end
- teams = team_scores.invert
- @match.winner = teams[teams.keys.sort.last]
-
- # Schedule next match
- #cur_match_num = @tournament.matches_ordered.invert[@match]
- #unless cur_match_num == 1
- # @match.winner.matches.push(@tournament.matches_ordered[cur_match_num/2])
- #end
-=end
# Skip peer evaluation if there aren't enough players per team
peer = false
@@ -222,7 +200,6 @@ class MatchesController < ApplicationController
end
@match.status = peer ? 2 : 3
-
respond_to do |format|
if @match.save
format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Peer evaluation started.' }
@@ -233,6 +210,12 @@ class MatchesController < ApplicationController
end
end
when "peer"
+ #
+ # Update user scores via scoring method
+ #
+
+ #update this to use scoring interface
+
order = params[:review_action]
base_score = 2
next_score = 3
@@ -262,10 +245,14 @@ class MatchesController < ApplicationController
end
end
when "reset"
- @match.status = 0
+ #
+ # Reset Match Status to 1 in case something needs to be replayed.
+ #
+
+ @match.status = 1
respond_to do |format|
if @match.save
- format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match Status Reset to 0' }
+ format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match Status Reset to 1' }
format.json { head :no_content }
else
format.html { redirect_to @tournament, notice: "You don't have permission to start this match." }
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb
index 6ba259e..60f8789 100644
--- a/app/controllers/tournaments_controller.rb
+++ b/app/controllers/tournaments_controller.rb
@@ -163,7 +163,7 @@ class TournamentsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def tournament_attribute_params
if params[:tournament]
- params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method)
+ params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method)
else
return {}
end
diff --git a/app/models/bracket.rb b/app/models/bracket.rb
index e8d9c5a..acd33ca 100644
--- a/app/models/bracket.rb
+++ b/app/models/bracket.rb
@@ -1,4 +1,11 @@
class Bracket < ActiveRecord::Base
belongs_to :user
belongs_to :tournament
+ has_many :bracket_matches
+
+ def create_matches
+ tournament.stages.first.matches.each do |m|
+ bracket_matches.create(match: m)
+ end
+ end
end
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 861be6c..7460a7d 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -1,6 +1,7 @@
class Tournament < ActiveRecord::Base
belongs_to :game
has_many :stages, class_name: "TournamentStage"
+ has_many :brackets
has_many :settings_raw, class_name: "TournamentSetting"
has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments"
has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments"
diff --git a/app/models/user.rb b/app/models/user.rb
index d87f988..b2c7862 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -74,6 +74,10 @@ class User < ActiveRecord::Base
:edit_permissions => (2**19),
:edit_server => (2**20),
+
+ :create_bracket => (2**21),
+ :edit_bracket => (2**22),
+ :delete_bracket => (2**23)
}
end
diff --git a/app/views/brackets/index.html.erb b/app/views/brackets/index.html.erb
index 2195d69..9effe37 100644
--- a/app/views/brackets/index.html.erb
+++ b/app/views/brackets/index.html.erb
@@ -8,7 +8,6 @@
<th>Name</th>
<th></th>
<th></th>
- <th></th>
</tr>
</thead>
@@ -18,9 +17,8 @@
<td><%= bracket.user %></td>
<td><%= bracket.tournament %></td>
<td><%= bracket.name %></td>
- <td><%= link_to 'Show', bracket %></td>
- <td><%= link_to 'Edit', edit_bracket_path(bracket) %></td>
- <td><%= link_to 'Destroy', bracket, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ <td><%= link_to 'Show', tournament_bracket_path(@tournament, bracket) %></td>
+ <td><%= link_to 'Edit', edit_tournament_bracket_path(@tournament, bracket) %></td>
</tr>
<% end %>
</tbody>
@@ -28,4 +26,3 @@
<br>
-<%= link_to 'New Bracket', new_bracket_path %>
diff --git a/app/views/brackets/new.html.erb b/app/views/brackets/new.html.erb
index c379c15..91d0033 100644
--- a/app/views/brackets/new.html.erb
+++ b/app/views/brackets/new.html.erb
@@ -1,5 +1,3 @@
<h1>New bracket</h1>
-<%= render 'form' %>
-
-<%= link_to 'Back', brackets_path %>
+<%= link_to 'Back', tournament_brackets_path %>
diff --git a/app/views/brackets/show.html.erb b/app/views/brackets/show.html.erb
index 9c7c14b..2e92bfb 100644
--- a/app/views/brackets/show.html.erb
+++ b/app/views/brackets/show.html.erb
@@ -1,13 +1,11 @@
-<p id="notice"><%= notice %></p>
-
<p>
<strong>User:</strong>
- <%= @bracket.user %>
+ <%= @bracket.user.user_name %>
</p>
<p>
<strong>Tournament:</strong>
- <%= @bracket.tournament %>
+ <%= @bracket.tournament.name %>
</p>
<p>
@@ -15,5 +13,9 @@
<%= @bracket.name %>
</p>
-<%= link_to 'Edit', edit_bracket_path(@bracket) %> |
-<%= link_to 'Back', brackets_path %>
+<% @bracket.bracket_matches.each do |m| %>
+ <p><b><%= m.match.id %></b></p>
+<% end %>
+
+
+<%= link_to 'Back', tournaments_path %>
diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb
index 0f60fad..b16a37b 100644
--- a/app/views/common/_show_tournament.html.erb
+++ b/app/views/common/_show_tournament.html.erb
@@ -29,6 +29,9 @@
<% else %>
<p style="margin-top:10px;"> You've signed up for this tournament! </p>
<% end %>
+ <%= form_tag(tournament_brackets_path(target), method: "post") do %>
+ <%= submit_tag("Make Bracket") %>
+ <% end %>
<% end %>
</div>
</div> \ No newline at end of file
diff --git a/app/views/games/_form.html.erb b/app/views/games/_form.html.erb
index 20cb214..b1db0b3 100644
--- a/app/views/games/_form.html.erb
+++ b/app/views/games/_form.html.erb
@@ -47,6 +47,10 @@
<%= f.label :sampling_method %><br>
<%= f.text_field :sampling_method %>
</div>
+ <div class="field">
+ <%= f.label :scoring_method %><br>
+ <%= f.text_field :scoring_method %>
+ </div>
<div class="actions">
<%= f.submit %>
</div>
diff --git a/app/views/games/index.html.erb b/app/views/games/index.html.erb
index bcd10dd..3045325 100644
--- a/app/views/games/index.html.erb
+++ b/app/views/games/index.html.erb
@@ -12,6 +12,7 @@
<th>Set rounds</th>
<th>Randomized teams</th>
<th>Sampling method</th>
+ <th>Scoring method</th>
<th></th>
<th></th>
<th></th>
@@ -30,6 +31,7 @@
<td><%= game.set_rounds %></td>
<td><%= game.randomized_teams %></td>
<td><%= game.sampling_method %></td>
+ <td><%= game.scoring_method %></td>
<td><%= link_to 'Show', game %></td>
<td><%= link_to 'Edit', edit_game_path(game) %></td>
<td><%= link_to 'Destroy', game, method: :delete, data: { confirm: 'Are you sure?' } %></td>
diff --git a/app/views/games/index.json.jbuilder b/app/views/games/index.json.jbuilder
index 6b20f60..7964f2c 100644
--- a/app/views/games/index.json.jbuilder
+++ b/app/views/games/index.json.jbuilder
@@ -1,4 +1,4 @@
json.array!(@games) do |game|
- json.extract! game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method
+ json.extract! game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method
json.url game_url(game, format: :json)
end
diff --git a/app/views/games/show.html.erb b/app/views/games/show.html.erb
index 1250cbd..1a18356 100644
--- a/app/views/games/show.html.erb
+++ b/app/views/games/show.html.erb
@@ -43,5 +43,10 @@
<%= @game.sampling_method %>
</p>
+<p>
+ <strong>Scoring method:</strong>
+ <%= @game.scoring_method %>
+</p>
+
<%= link_to 'Edit', edit_game_path(@game) %> |
<%= link_to 'Back', games_path %>
diff --git a/app/views/games/show.json.jbuilder b/app/views/games/show.json.jbuilder
index 087a156..c5fb4ed 100644
--- a/app/views/games/show.json.jbuilder
+++ b/app/views/games/show.json.jbuilder
@@ -1 +1 @@
-json.extract! @game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :created_at, :updated_at
+json.extract! @game, :id, :parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method, :created_at, :updated_at
diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb
index 7a82527..8344a7a 100644
--- a/app/views/matches/show.html.erb
+++ b/app/views/matches/show.html.erb
@@ -78,24 +78,8 @@ function score_peers() {
<!-- Started, waiting to finish -->
<!-- This will depend on the Sampling Method Eventually instead of always being Manual -->
- <% case @tournament.sampling_method %>
- <% when "Manual" %>
- <% if @tournament.hosts.include? current_user %>
- <input type="hidden" name="update_action" value="finish">
- <% @match.teams.each do |team| %>
- <%= tag :input, {"type" => "radio", "name" => "winner", "value" => "#{team.id}" } %>
- <%= "Team #{team.id} Won" %>
- <% end %>
- <%= submit_tag("Finish match") %>
- <%= @tournament.settings['ScoringMethod'] %>
- <% else %>
- <p>The match is running; the host has yet to post the scores of the match.</p>
- <% end %>
- <% when "Double Blind" %>
- <p>Double Blind isn't implemented yet.</p>
- <% when "RiotAPI" %>
- <p>Riot API is being called for Statistics. Results will appear shortly.</p>
- <% end %>
+ <%= raw @match.tournament_stage.tournament.sampling_method.camelcase.constantize.render_user_interaction(@match, current_user) %>
+
<% when 2 %>
<!-- Finished, waiting for peer reviews -->
<input type="hidden" name="update_action" value="peer">
diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb
index 9b9681c..7127d38 100644
--- a/app/views/tournaments/_form.html.erb
+++ b/app/views/tournaments/_form.html.erb
@@ -51,6 +51,10 @@
<%= f.label :sampling_method %><br>
<%= f.text_field :sampling_method %>
</div>
+ <div class="field">
+ <%= f.label :scoring_method %><br>
+ <%= f.text_field :scoring_method %>
+ </div>
<div class="actions">
<%= f.submit %>
</div>
diff --git a/app/views/tournaments/index.json.jbuilder b/app/views/tournaments/index.json.jbuilder
index 7118ecc..bd86e04 100644
--- a/app/views/tournaments/index.json.jbuilder
+++ b/app/views/tournaments/index.json.jbuilder
@@ -1,4 +1,4 @@
json.array!(@tournaments) do |tournament|
- json.extract! tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method
+ json.extract! tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method
json.url tournament_url(tournament, format: :json)
end
diff --git a/app/views/tournaments/show.json.jbuilder b/app/views/tournaments/show.json.jbuilder
index 4542e52..ff82412 100644
--- a/app/views/tournaments/show.json.jbuilder
+++ b/app/views/tournaments/show.json.jbuilder
@@ -1 +1 @@
-json.extract! @tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :created_at, :updated_at
+json.extract! @tournament, :id, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method, :created_at, :updated_at