summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile3
-rw-r--r--Gemfile.lock6
-rw-r--r--app/controllers/matches_controller.rb36
-rw-r--r--app/models/tournament.rb47
-rw-r--r--app/views/tournaments/_selected.html.erb23
-rw-r--r--db/seeds.rb5
6 files changed, 80 insertions, 40 deletions
diff --git a/Gemfile b/Gemfile
index bb38ab5..e486a62 100644
--- a/Gemfile
+++ b/Gemfile
@@ -13,6 +13,7 @@ gem 'httparty'
gem 'simple_captcha2', require: 'simple_captcha'
#gem 'rmagick'
+#gem 'byebug'
group :development, :test do
# Use sqlite3 as the database for Active Record
@@ -67,4 +68,4 @@ end
# Use debugger
# gem 'debugger', group: [:development, :test]
-#gem 'byebug' \ No newline at end of file
+#gem 'byebug'
diff --git a/Gemfile.lock b/Gemfile.lock
index fd03576..b894f81 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -31,6 +31,9 @@ GEM
bootstrap-sass (3.1.1.0)
sass (~> 3.2)
builder (3.1.4)
+ byebug (2.7.0)
+ columnize (~> 0.3)
+ debugger-linecache (~> 1.2)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
@@ -38,6 +41,8 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.7.0)
+ columnize (0.3.6)
+ debugger-linecache (1.2.0)
delayed_job (4.0.0)
activesupport (>= 3.0, < 4.1)
delayed_job_active_record (4.0.0)
@@ -130,6 +135,7 @@ PLATFORMS
DEPENDENCIES
bcrypt-ruby (= 3.1.2)
bootstrap-sass
+ byebug
coffee-rails (~> 4.0.0)
delayed_job_active_record
httparty
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index 8ef5e76..f196978 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -3,22 +3,26 @@ 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
+ # 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?
+ 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 +121,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
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 72c3ac8..fdcdba2 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 @@
</p>
<% end %>
- <% @settings = GameSetting.find_by(params[:game_id]) %>
- <% unless @settings %>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <% end %>
- <% @settings.each do |setting| %>
- <p>
- <%= f.label setting.name %><br>
- <% #eventually display by non-generic input method %>
- <%= f.select :setting options_from_collection_for_select([setting.description, ""].append setting.type_opt.split(',')) %>
- </p>
- <% end %>
-
- <%= f.submit %>
+ <%= f.submit %>
<% end %>
diff --git a/db/seeds.rb b/db/seeds.rb
index 6efc3e7..a6ddf11 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -16,6 +16,7 @@ Game.create(name: "Hearthstone", min_players_per_team: 1, max_players_per_team:
Game.find_by_name("League of Legends").settings.create(name: "Map", default: "Summoners Rift", type_opt: "Summoners Rift,Twisted Treeline,Crystal Scar,Haunted Abyss", description: "Select a map to play on.", stype: 5, display_order: 1)
Game.find_by_name("League of Legends").settings.create(name: "Pick Type", type_opt: "Blind Pick,Draft", description: "Select a pick type.", stype: 5, display_order: 2)
-#Game_setting.create(game_id: , type: , name: , default: , description: , type_opt: , display_order: , created_at: , updated_at: )
+Game.find_by_name("Chess").settings.create(name: "Time Control", description: "Enter a value for Time Control (ie. 5-5, 30, 6hr, or None)", stype: 1, display_order: 1)
+
+Game.find_by_name("Hearthstone").settings.create(name: "Deck Name", description: "Enter a name for your deck, be descriptive.", stype: 2, display_order: 1)
-#User.create(id: 1, name: "Andrew", email: "amurrel@example.com", user_name: "ImFromNASA", created_at: "2014-03-07 22:48:53", updated_at: "2014-03-07 22:48:53", password_digest: "$2a$10$W0FwPRDzdQp8arolCHGt5ezXqkOiTLNsXI5GKGtu9qr3...", remember_token: "1583722b02663e024533296171cad79f29037ebc", groups: 0)