From 91fee659eadaf6bcc4d063fd5645950da1250896 Mon Sep 17 00:00:00 2001
From: AndrewMurrell
Date: Sun, 6 Apr 2014 22:20:24 -0400
Subject: A few bug fixes, and a bunch of code that almost works.
---
app/models/tournament.rb | 47 ++++++++++++++++++++++++++++++++
app/views/tournaments/_selected.html.erb | 23 ++--------------
2 files changed, 49 insertions(+), 21 deletions(-)
(limited to 'app')
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index e408cfe..0b55cb6 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -1,9 +1,56 @@
class Tournament < ActiveRecord::Base
belongs_to :game
has_many :matches
+ has_many :preferences_raw, class_name: "TournamentPreference"
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"
+ def preferences
+ @preferences ||= Preferences.new(self)
+ end
+ def preferences=(pref)
+ pref.each do |key, value|
+ value = false if valuedd == "0"
+ preferences[key] = value
+ end
+ end
+
+ class Preferences
+ def initialize(tournament)
+ @tournament = tournament
+ end
+
+ def [](preference)
+ p = @tournament.preferences_raw.find_by_name(preference)
+ if p.nil?
+ return nil
+ else
+ return p.value
+ end
+ end
+
+ def []=(preference, value)
+ p = @tournament.preferences_raw.find_by_name(preference)
+ if p.nil?
+ # TODO: create it
+ else
+ p.value = value
+ end
+ end
+
+ def keys
+ @tournament.preferences_raw.all.collect { |x| x.name }
+ end
+
+ def method_missing(name, *args)
+ if name.to_s.ends_with?('=')
+ self[name.to_s.sub(/=$/, '').to_sym] = args.first
+ else
+ return self[name.to_sym]
+ end
+ end
+ end
+
def open?
return true
end
diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb
index 3661077..b66acb0 100644
--- a/app/views/tournaments/_selected.html.erb
+++ b/app/views/tournaments/_selected.html.erb
@@ -2,7 +2,7 @@
<%= render "common/error_messages", :target => @tournament %>
<%= f.hidden_field(:game_id) %>
- <% @game = Game.find_by(params[:game]) %>
+ <% @game = Game.find(params[:game]) %>
<% @tournament.attributes.each do |name, value| %>
<% if (name == "id") or (name =~ /.*_at$/) or (name == "game_id") or (name == "status") or (name == "set_rounds") %>
<% next %>
@@ -17,24 +17,5 @@
<% end %>
- <% @settings = GameSetting.find_by(params[:game_id]) %>
- <% unless @settings %>
-
-
-
-
-
-
-
-
- <% end %>
- <% @settings.each do |setting| %>
-
- <%= f.label setting.name %>
- <% #eventually display by non-generic input method %>
- <%= f.select :setting options_from_collection_for_select([setting.description, ""].append setting.type_opt.split(',')) %>
-
- <% end %>
-
- <%= f.submit %>
+ <%= f.submit %>
<% end %>
--
cgit v1.2.3-2-g168b
From f91717ad1803cf547324e21899dd2e279852b43c Mon Sep 17 00:00:00 2001
From: Luke Shumaker
Date: Sun, 6 Apr 2014 22:26:05 -0400
Subject: indent the matches_controller
---
app/controllers/matches_controller.rb | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
(limited to 'app')
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index ee68e11..feeda02 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -3,22 +3,20 @@ class MatchesController < ApplicationController
# GET /matches
# GET /matches.json
- require 'httparty'
- require 'json'
- require 'delayed_job'
-
- def index
- @matches = @tournament.matches
- # width of SVG
- @width = 300 * (Math.log2(@matches.count).floor + 1);
- # height of SVG
- @height = 200 * 2**Math.log2(@matches.count).floor + 100;
- end
-
-
+ require 'httparty'
+ require 'json'
+ require 'delayed_job'
+
+ def index
+ @matches = @tournament.matches
+ # width of SVG
+ @width = 300 * (Math.log2(@matches.count).floor + 1);
+ # height of SVG
+ @height = 200 * 2**Math.log2(@matches.count).floor + 100;
+ end
- def get_riot_info
- if signed_in?
+ def get_riot_info
+ if signed_in?
#current user information
response = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{current_user.user_name}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38")
@@ -117,8 +115,8 @@ class MatchesController < ApplicationController
@purp = purple
@blue = blue
- end #end if
- end #end def
+ end #end if
+ end #end def
# GET /matches/1
# GET /matches/1.json
--
cgit v1.2.3-2-g168b
From 5798dd7da423895a5c8561800f7d78859e6ab000 Mon Sep 17 00:00:00 2001
From: Luke Shumaker
Date: Sun, 6 Apr 2014 22:26:28 -0400
Subject: MatchesController: define matches_url
---
app/controllers/matches_controller.rb | 6 ++++++
1 file changed, 6 insertions(+)
(limited to 'app')
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index feeda02..5c654dd 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -15,6 +15,12 @@ class MatchesController < ApplicationController
@height = 200 * 2**Math.log2(@matches.count).floor + 100;
end
+ # For compatability with the router assumptions made by ApplicationController#check_permission
+ def matches_url
+ set_tournament
+ tournament_matches_path(@tournament)
+ end
+
def get_riot_info
if signed_in?
--
cgit v1.2.3-2-g168b