summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/matches_controller.rb21
-rw-r--r--app/controllers/tournaments_controller.rb18
-rw-r--r--app/models/match.rb1
-rw-r--r--app/models/tournament.rb13
-rw-r--r--app/views/matches/_form.html.erb15
-rw-r--r--app/views/matches/index.html.erb10
-rw-r--r--app/views/matches/new.html.erb2
-rw-r--r--app/views/matches/show.html.erb4
-rw-r--r--app/views/tournaments/_selected.html.erb2
-rw-r--r--config/routes.rb12
10 files changed, 56 insertions, 42 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index 984be3f..23d2700 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -1,10 +1,10 @@
class MatchesController < ApplicationController
+ before_action :set_tournament, only: [:index]
before_action :set_match, only: [:show, :edit, :update, :destroy]
-
# GET /matches
# GET /matches.json
def index
- @matches = Match.all
+ @matches = @tournament.matches
end
# GET /matches/1
@@ -14,7 +14,7 @@ class MatchesController < ApplicationController
# GET /matches/new
def new
- @match = Match.new
+
end
# GET /matches/1/edit
@@ -24,11 +24,11 @@ class MatchesController < ApplicationController
# POST /matches
# POST /matches.json
def create
- @match = Match.new(match_params)
+ @match = @tournament.matches.build(match_params)
respond_to do |format|
if @match.save
- format.html { redirect_to @match, notice: 'Match was successfully created.' }
+ format.html { redirect_to tournament_matches_path, notice: 'Match was successfully created.' }
format.json { render action: 'show', status: :created, location: @match }
else
format.html { render action: 'new' }
@@ -54,19 +54,22 @@ class MatchesController < ApplicationController
# DELETE /matches/1
# DELETE /matches/1.json
def destroy
+
@match.destroy
respond_to do |format|
- format.html { redirect_to matches_url }
- format.json { head :no_content }
+ format.html { redirect_to tournament_matches_path }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_match
- @match = Match.find(params[:id])
+ @tournament = Tournament.find(params[:tournament_id])
+ @match = @tournament.matches.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 match_params
params.require(:match).permit(:tournament_id, :name)
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb
index 27765df..74a1f56 100644
--- a/app/controllers/tournaments_controller.rb
+++ b/app/controllers/tournaments_controller.rb
@@ -11,12 +11,16 @@ class TournamentsController < ApplicationController
# GET /tournaments/1
# GET /tournaments/1.json
def show
+ unless @tournament.status
+ redirect_to tournament_matches_page(@tournament)
+ end
end
# GET /tournaments/new
def new
@games = Game.all
@tournament = Tournament.new(game: Game.find_by_id(params[:game]))
+ @tournament.status = 1
end
# GET /tournaments/1/edit
@@ -42,8 +46,7 @@ class TournamentsController < ApplicationController
# PATCH/PUT /tournaments/1
# PATCH/PUT /tournaments/1.json
def update
- require 'pp'
- pp params
+
if params[:update_action].nil?
check_perms
respond_to do |format|
@@ -66,8 +69,15 @@ class TournamentsController < ApplicationController
format.html { render action: 'permission_denied', status: :forbidden }
format.json { render json: "Permission denied", status: :forbidden }
end
- #when "open"
- # TODO
+ when "open"
+ respond_to do |format|
+ if @tournament.setup
+ format.html { render action: 'show', notice: 'You have joined this tournament.' }
+ format.json { head :no_content }
+ end
+ format.html { render action: 'permission_denied', status: :forbidden }
+ format.json { render json: "Permission denied", status: :forbidden }
+ end
#when "close"
# TODO
else
diff --git a/app/models/match.rb b/app/models/match.rb
index 533435a..8acebf7 100644
--- a/app/models/match.rb
+++ b/app/models/match.rb
@@ -1,3 +1,4 @@
class Match < ActiveRecord::Base
belongs_to :tournament
+
end
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index aa22afa..44b22f5 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -18,4 +18,17 @@ class Tournament < ActiveRecord::Base
end
players<<user
end
+
+ def setup
+ num_teams = (self.users.count/self.players_per_team).floor
+ num_matches = num_teams - 1
+ for i in 0..num_matches
+ self.matches.create(name: "Match #{i}")
+ end
+ #self.players.each_slice(num_teams) do |team_players|
+ # Team.new(users: team_players)
+ #end
+ end
+
+
end
diff --git a/app/views/matches/_form.html.erb b/app/views/matches/_form.html.erb
index c5f1ba8..015aed0 100644
--- a/app/views/matches/_form.html.erb
+++ b/app/views/matches/_form.html.erb
@@ -1,16 +1,5 @@
-<%= form_for(@match) do |f| %>
- <% if @match.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@match.errors.count, "error") %> prohibited this match from being saved:</h2>
-
- <ul>
- <% @match.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
+<%= form_for([@tournament, @tournament.matches.build]) do |f| %>
+
<div class="field">
<%= f.label :tournament_id %><br>
<%= f.text_field :tournament_id %>
diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb
index 0742770..d635834 100644
--- a/app/views/matches/index.html.erb
+++ b/app/views/matches/index.html.erb
@@ -12,13 +12,13 @@
</thead>
<tbody>
- <% @matches.each do |match| %>
+ <% @tournament.matches.each do |match| %>
<tr>
<td><%= match.tournament %></td>
<td><%= match.name %></td>
- <td><%= link_to 'Show', match %></td>
- <td><%= link_to 'Edit', edit_match_path(match) %></td>
- <td><%= link_to 'Destroy', match, method: :delete, data: { confirm: 'Are you sure?' } %></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>
</tr>
<% end %>
</tbody>
@@ -26,4 +26,4 @@
<br>
-<%= link_to 'New Match', new_match_path %>
+<%= link_to 'New Match', new_tournament_match_path %>
diff --git a/app/views/matches/new.html.erb b/app/views/matches/new.html.erb
index bd4c78c..9ac669f 100644
--- a/app/views/matches/new.html.erb
+++ b/app/views/matches/new.html.erb
@@ -2,4 +2,4 @@
<%= render 'form' %>
-<%= link_to 'Back', matches_path %>
+
diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb
index 9c9cbb4..e95cd07 100644
--- a/app/views/matches/show.html.erb
+++ b/app/views/matches/show.html.erb
@@ -8,5 +8,5 @@
<%= @match.name %>
</p>
-<%= link_to 'Edit', edit_match_path(@match) %> |
-<%= link_to 'Back', matches_path %>
+<%= link_to 'Edit', edit_tournament_match_path(@tournament, @match) %> |
+<%= link_to 'Back', tournament_matches_path %>
diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb
index 9b1b7f8..925e127 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 == "status") %>
+ <% if (name == "id") or (name =~ /.*_at$/) or (name == "game_id") or (name == "statuss") %>
<% next %>
<% end %>
<p>
diff --git a/config/routes.rb b/config/routes.rb
index 178b7ad..5c5bece 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -7,19 +7,17 @@ Leaguer::Application.routes.draw do
resources :games
- resources :tournaments
-
resources :pms
resources :alerts
- resources :teams
-
- resources :matches
+ resource :server, only: [:show, :edit, :update]
- resources :tournaments
+ resources :teams
+ resources :tournaments do
+ resources :matches
+ end
- resource :server, only: [:show, :edit, :update]
root to: 'static#homepage'