diff options
author | guntasgrewal <guntasgrewal@gmail.com> | 2014-04-22 19:13:01 -0400 |
---|---|---|
committer | guntasgrewal <guntasgrewal@gmail.com> | 2014-04-22 19:13:01 -0400 |
commit | 38c2ff9637018d88db7083c76c133da3a72f4c31 (patch) | |
tree | ae5c381e7fe9493abfe8fa6c700df64648246fe2 | |
parent | 3e86ffe1113a096541ea94567bffee79368fb863 (diff) | |
parent | 5c6d6dca48bf3d54f145e859e6d4c8b1befe1f09 (diff) |
Merge branch 'master' of https://github.com/LukeShu/leaguer
-rw-r--r-- | Gemfile | 3 | ||||
-rw-r--r-- | Gemfile.lock | 12 | ||||
-rw-r--r-- | app/assets/images/ChessBlackKnightIcon.png | bin | 0 -> 893 bytes | |||
-rw-r--r-- | app/assets/images/LOLG_icon_large.gif | bin | 0 -> 8207 bytes | |||
-rw-r--r-- | app/assets/stylesheets/application.css | 7 | ||||
-rw-r--r-- | app/assets/stylesheets/scaffolds.css.scss | 13 | ||||
-rw-r--r-- | app/assets/stylesheets/static.css.scss | 3 | ||||
-rw-r--r-- | app/controllers/matches_controller.rb | 11 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/tournaments_controller.rb | 25 | ||||
-rw-r--r-- | app/models/tournament_stage.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/views/common/_show_tournament.html.erb | 32 | ||||
-rw-r--r-- | app/views/layouts/application.html.erb | 12 | ||||
-rw-r--r-- | app/views/matches/index.html.erb | 2 | ||||
-rw-r--r-- | app/views/matches/show.html.erb | 4 | ||||
-rw-r--r-- | app/views/search/go.html.erb | 24 | ||||
-rw-r--r-- | app/views/tournaments/index.html.erb | 38 | ||||
-rw-r--r-- | config/initializers/mailboxer.rb | 17 | ||||
-rw-r--r-- | config/routes.rb | 6 | ||||
-rw-r--r-- | db/migrate/20140422172559_create_simple_captcha_data.rb (renamed from db/migrate/20140422155038_create_simple_captcha_data.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212555_create_mailboxer.mailboxer_engine.rb | 62 | ||||
-rw-r--r-- | db/migrate/20140422212556_add_notified_object.mailboxer_engine.rb | 18 | ||||
-rw-r--r-- | db/migrate/20140422212557_add_notification_code.mailboxer_engine.rb | 14 | ||||
-rw-r--r-- | db/migrate/20140422212558_add_attachments.mailboxer_engine.rb | 10 | ||||
-rw-r--r-- | db/migrate/20140422212559_rename_receipts_read.mailboxer_engine.rb | 10 | ||||
-rw-r--r-- | db/migrate/20140422212560_add_global_notification_support.mailboxer_engine.rb | 10 | ||||
-rw-r--r-- | db/migrate/20140422212602_create_delayed_jobs.rb (renamed from db/migrate/20140422195042_create_delayed_jobs.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212605_create_servers.rb (renamed from db/migrate/20140422195045_create_servers.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212609_create_matches.rb (renamed from db/migrate/20140422195049_create_matches.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212613_create_teams.rb (renamed from db/migrate/20140422195052_create_teams.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212616_create_alerts.rb (renamed from db/migrate/20140422195056_create_alerts.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212619_create_pms.rb (renamed from db/migrate/20140422195059_create_pms.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212623_create_tournaments.rb (renamed from db/migrate/20140422195103_create_tournaments.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212627_create_games.rb (renamed from db/migrate/20140422195107_create_games.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212630_create_users.rb (renamed from db/migrate/20140422195110_create_users.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212634_create_sessions.rb (renamed from db/migrate/20140422195114_create_sessions.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212637_create_brackets.rb (renamed from db/migrate/20140422195118_create_brackets.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212641_create_game_settings.rb (renamed from db/migrate/20140422195121_create_game_settings.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212644_create_tournament_settings.rb (renamed from db/migrate/20140422195125_create_tournament_settings.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212648_create_tournament_stages.rb (renamed from db/migrate/20140422195128_create_tournament_stages.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212651_create_statistics.rb (renamed from db/migrate/20140422195132_create_statistics.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212654_create_remote_usernames.rb (renamed from db/migrate/20140422195135_create_remote_usernames.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212657_create_bracket_matches.rb (renamed from db/migrate/20140422195139_create_bracket_matches.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212701_create_api_requests.rb (renamed from db/migrate/20140422195143_create_api_requests.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212704_create_tournament_players_join_table.rb (renamed from db/migrate/20140422195146_create_tournament_players_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212707_create_tournament_hosts_join_table.rb (renamed from db/migrate/20140422195150_create_tournament_hosts_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212711_create_team_user_join_table.rb (renamed from db/migrate/20140422195153_create_team_user_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212714_create_match_team_join_table.rb (renamed from db/migrate/20140422195157_create_match_team_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140422212727_add_hidden_attrs_to_user.rb (renamed from db/migrate/20140422195211_add_hidden_attrs_to_user.rb) | 0 | ||||
-rw-r--r-- | db/schema.rb | 42 | ||||
-rwxr-xr-x | generate.sh | 3 | ||||
-rw-r--r-- | lib/scheduling/elimination.rb | 16 | ||||
-rw-r--r-- | lib/scoring/fibonacci_peer_with_blowout.rb (renamed from lib/scoring/FibonacciPeerWithBlowout.rb) | 0 | ||||
-rw-r--r-- | lib/scoring/marginal_peer.rb (renamed from lib/scoring/MarginalPeer.rb) | 0 | ||||
-rw-r--r-- | lib/scoring/scoring_algorithm.rb (renamed from lib/scoring/ScoringAlgorithm.rb) | 0 | ||||
-rw-r--r-- | lib/scoring/winner_takes_all.rb (renamed from lib/scoring/WinnerTakesAll.rb) | 0 |
57 files changed, 330 insertions, 83 deletions
@@ -49,6 +49,9 @@ gem 'jbuilder', '~> 1.2' gem 'daemons' gem 'delayed_job_active_record' +# Mailboxer supports a messaging and alerting system. +gem 'mailboxer' + group :doc do # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', require: false diff --git a/Gemfile.lock b/Gemfile.lock index e7ccedb..145a7fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -30,6 +30,11 @@ GEM bootstrap-sass (3.1.1.1) sass (~> 3.2) builder (3.1.4) + carrierwave (0.10.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) + mime-types (>= 1.16) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -45,6 +50,8 @@ GEM delayed_job (>= 3.0, < 4.1) erubis (2.7.0) execjs (2.0.2) + foreigner (1.6.1) + activerecord (>= 3.0.0) hike (1.2.3) httparty (0.13.1) json (~> 1.8) @@ -61,6 +68,10 @@ GEM mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) + mailboxer (0.11.0) + carrierwave (>= 0.5.8) + foreigner (>= 0.9.1) + rails (> 3.0.0) mime-types (1.25.1) minitest (4.7.5) multi_json (1.9.2) @@ -135,6 +146,7 @@ DEPENDENCIES httparty jbuilder (~> 1.2) jquery-rails + mailboxer rails (= 4.0.2) sass-rails (~> 4.0.0) sdoc diff --git a/app/assets/images/ChessBlackKnightIcon.png b/app/assets/images/ChessBlackKnightIcon.png Binary files differnew file mode 100644 index 0000000..6bcffe6 --- /dev/null +++ b/app/assets/images/ChessBlackKnightIcon.png diff --git a/app/assets/images/LOLG_icon_large.gif b/app/assets/images/LOLG_icon_large.gif Binary files differnew file mode 100644 index 0000000..1f0fa43 --- /dev/null +++ b/app/assets/images/LOLG_icon_large.gif diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index ebb963c..677791c 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -22,10 +22,3 @@ padding: 0px 5px; } -footer { - clear: both; - margin: 0 auto; - margin-top: 10px; - color: white; - width: 90%; -}
\ No newline at end of file diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss index 509cb19..e8fe9c5 100644 --- a/app/assets/stylesheets/scaffolds.css.scss +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -19,7 +19,7 @@ body { height: 100%; } -h1, h2, h3, h4, h5, p{ +h1, h2, h3, h4, h5, p, li{ color: $orange; } @@ -96,20 +96,21 @@ div { .wrapper { width: 80%; - margin: 0 auto; margin-top: 10px; + min-height: 80%; + height: auto !important; + height: 99%; + margin: 0 auto; } button, input[type="submit"] { @extend .btn; } - - footer { clear: both; border-top: solid 1px $orange; - padding-top: 10px; text-align: center; - bottom: 0; + margin: 0 auto; + width: 90%; }
\ No newline at end of file diff --git a/app/assets/stylesheets/static.css.scss b/app/assets/stylesheets/static.css.scss index 14443f3..6732370 100644 --- a/app/assets/stylesheets/static.css.scss +++ b/app/assets/stylesheets/static.css.scss @@ -5,7 +5,8 @@ .jumbotron { background-color: #FFF; box-shadow: 1px 1px 20px black; - + width: 93%; + p { line-height: 1.5em; } diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 59f376a..b50aca5 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,6 +1,4 @@ class MatchesController < ApplicationController - before_action :set_tournament, only: [:index, :update] - require 'httparty' require 'json' require 'delayed_job' @@ -118,7 +116,7 @@ class MatchesController < ApplicationController # GET /tournaments/1/matches/1 # GET /tournaments/1/matches/1.json def show - if Tournament.find_by_id(@match.tournament_id).game_id == 1 + if @match.tournament_stage.tournament.game_id == 1 file_blue = "blue.yaml" file_purple = "purple.yaml" @blue2 = YAML.load_file(file_blue) @@ -235,11 +233,8 @@ class MatchesController < ApplicationController private # Use callbacks to share common setup or constraints between actions. def set_match - set_tournament - @match = @tournament.matches.find(params[:id]) - end - def set_tournament - @tournament = Tournament.find(params[:tournament_id]) + @match = Match.find(params[:id]) + @tournament = @match.tournament_stage.tournament end # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index ee61487..51aee9e 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,2 +1,15 @@ class SearchController < ApplicationController + + def go + @query = params[:query] + + if (@query.nil?) then + return + end + + @tournaments = Tournament.where("name LIKE '%#{@query}%'") + @players = User.where("name LIKE '%#{@query}%'") + + end + end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 4b0e1af..03dc5b8 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -95,17 +95,24 @@ class TournamentsController < ApplicationController end when "start" check_permission(:edit, @tournament) - @tournament.status = 1 - ok = - @tournament.save && - @tournament.tournament_stages.create(scheduling: "elimination") && - @tournament.tournament_stages.first.create_matches respond_to do |format| - if ok - format.html { redirect_to @tournament, notice: 'You have started this tournament.' } - format.json { head :no_content } + if @tournament.status == 0 + @tournament.status = 1 + success = true + ActiveRecord::Base.transaction do + success &= @tournament.save && + success &= @tournament.tournament_stages.create(scheduling: "elimination") + success &= @tournament.tournament_stages.first.create_matches + end + if success + format.html { redirect_to @tournament, notice: 'You have started this tournament.' } + format.json { head :no_content } + else + format.html { redirect_to @tournament, notice: "You don't have permission to start this tournament." } + format.json { render json: "Permission denied", status: :forbidden } + end else - format.html { redirect_to @tournament, notice: "You don't have permission to start this tournament." } + format.html { redirect_to @tournament, notice: "This tournament is not in a state that it can be started." } format.json { render json: "Permission denied", status: :forbidden } end end diff --git a/app/models/tournament_stage.rb b/app/models/tournament_stage.rb index a3ee7df..d5a5211 100644 --- a/app/models/tournament_stage.rb +++ b/app/models/tournament_stage.rb @@ -17,9 +17,9 @@ class TournamentStage < ActiveRecord::Base @scheduling.create_matches end - def to_svg + def to_svg(current_user) set_scheduling - return @scheduling.graph + return @scheduling.graph(current_user) end def pair diff --git a/app/models/user.rb b/app/models/user.rb index 57746b7..aacd7b1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,6 +10,8 @@ class User < ActiveRecord::Base apply_simple_captcha + acts_as_messageable + before_save { self.email = email.downcase } before_save { self.user_name = user_name } diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb new file mode 100644 index 0000000..89d8f53 --- /dev/null +++ b/app/views/common/_show_tournament.html.erb @@ -0,0 +1,32 @@ +<div class="row tournament-listing"> + <div class="col-md-2 col-sm-3 col-xs-6"><%= image_tag ('http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(target.hosts.first.email) + '?s=100&d=mm') %></div> + <div class="col-md-8 col-sm-7 col-xs-6"> + <%# "header" %> + <%= link_to(target) do %><h3><%= target.name %></h3><% end %> + <div class="row" style="margin-left:2%;"> + <div class="col-md-4 host"> + Hosted by: <%= target.hosts.first.name %> + </div> + <div class="col-md-4 things"> + <p> Players per team: <%= target.min_players_per_team %></p> + <p> Players signed up: <%= target.players.count %> </p> + </div> + <div class="col-md-4 things"> + <p> <%= (target.randomized_teams)? "Teams are Random" : "Teams are Chosen" %></p> + <p> Players signed up: <%= target.players.count %> </p> + </div> + </div> + </div> + <div class="col-md-2 col-sm-2 col-xs-2"> + <% if signed_in? %> + <% if !target.players.include?(current_user) %> + <%= form_tag(tournament_path(target), method: "put") do %> + <input type="hidden" name="update_action" value="join"> + <%= submit_tag("Join")%> + <% end %> + <% else %> + <p style="margin-top:10px;"> You've signed up for this tournament! </p> + <% end %> + <% end %> + </div> +</div>
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e6b5b25..fb5c1c5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,15 +13,20 @@ BetterDragSort.makeListSortable(document.getElementById("boxes")); }; </script> -<header><nav> +<header> + <nav> + <%# This is the logo %> <div class="navbar-brand"><%= link_to('Leaguer', root_path) %></div> + + <%# This is the search bar #%> <div> <%= form_tag("/search", method: "get", :class => "search") do %> <%= text_field_tag(:query, nil, :placeholder => "Search") %> - <%= submit_tag("Go") %> + <%= submit_tag("Go", :name=>nil) %> <% end %> </div> + <%# these are the log in buttons #%> <div id="log-buttons"> <% if signed_in? %> <%= link_to current_user.user_name, current_user, :class => "user" %> @@ -34,7 +39,8 @@ <%= link_to "Sign up", new_user_path, :class => "signup" %> <% end %> </div> -</nav></header> + </nav> +</header> <% if notice %><div id="notice"><p><%= notice %></p></div><% end %> diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb index 058477a..fda8582 100644 --- a/app/views/matches/index.html.erb +++ b/app/views/matches/index.html.erb @@ -37,5 +37,5 @@ <br> <% @tournament.stages_ordered.keys.sort.each do |stage_key| %> - <div class="graph"><%= raw @tournament.stages_ordered[stage_key].to_svg %></div> + <div class="graph"><%= raw @tournament.stages_ordered[stage_key].to_svg(current_user) %></div> <% end %> diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index e7fe791..a1d82a3 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -7,10 +7,6 @@ <%= @match.tournament_stage %> </p> -<p> - <strong>Name:</strong> - <%= @match.name %> -</p> <!-- Match Status 0 => Created, waiting to start Match Status 1 => Match is running, waiting to finish diff --git a/app/views/search/go.html.erb b/app/views/search/go.html.erb new file mode 100644 index 0000000..324fa48 --- /dev/null +++ b/app/views/search/go.html.erb @@ -0,0 +1,24 @@ + +<%# Show search results if a query was not nill %> +<% if !@query.empty? %> + + <% if @tournaments.empty? and @players.empty? %> + <h3> No results found for "<%= @query %>" </h3> + <% else %> + <h3> Showing results for: <span><%= @query %></span></h3> + <% if @tournaments.length > 0 %> + <h4> Tournaments </h4> + <% end %> + <% @tournaments.each do |t| %> + <%= render "common/show_tournament", :target => t %> + <% end %> + + <% if @players.length > 0 %> + <h4> Players </h4> + <% end %> + <% @players.each do |p| %> + <%= render "common/show_player", :target => p %> + <% end %> + + <% end %> +<% end %>
\ No newline at end of file diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index eef9577..06e1b25 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -2,48 +2,20 @@ <div id="tournament-list"> <% if @tournaments.length > 0 %> + <%# Each tournament has a div for its listing %> <% @tournaments.each do |t| %> - <div class="row tournament-listing"> - <div class="col-md-2 col-sm-3 col-xs-6"><%= image_tag 'http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(t.hosts.first.email) + '?s=100&d=mm' %></div> - <div class="col-md-8 col-sm-7 col-xs-6"> - <%# "header" %> - <%= link_to(t) do %><h3><%= t.name %></h3><% end %> - <div class="row" style="margin-left:2%;"> - <div class="col-md-4 host"> - Hosted by: <%= t.hosts.first.name %> - </div> - <div class="col-md-4 things"> - <p> Players per team: <%= t.min_players_per_team %></p> - <p> Players signed up: <%= t.players.count %> </p> - </div> - <div class="col-md-4 things"> - <p> <%= (t.randomized_teams)? "Teams are Random" : "Teams are Chosen" %></p> - <p> Players signed up: <%= t.players.count %> </p> - </div> - </div> - </div> - <div class="col-md-2 col-sm-2 col-xs-2"> - <% if signed_in? %> - <% if !t.players.include?(current_user) %> - <%= form_tag(tournament_path(t), method: "put") do %> - <input type="hidden" name="update_action" value="join"> - <%= submit_tag("Join") - %> - <% end %> - <% else %> - <p style="margin-top:10px;"> You've signed up for this tournament! </p> - <% end %> - <% end %> - </div> - </div> + <%= render "common/show_tournament", :target => t %> <% end %> + <% else %> + <p class="no-entries"> No tournaments going on right now... <% if current_user.can?(:create_tournament) %> Why not start your own? <% end %> </p> + <% end %> </div> diff --git a/config/initializers/mailboxer.rb b/config/initializers/mailboxer.rb new file mode 100644 index 0000000..2778a10 --- /dev/null +++ b/config/initializers/mailboxer.rb @@ -0,0 +1,17 @@ +Mailboxer.setup do |config| + + #Configures if you applications uses or no the email sending for Notifications and Messages + config.uses_emails = false + + #Configures the default from for the email sent for Messages and Notifications of Mailboxer + config.default_from = "no-reply@mailboxer.com" + + #Configures the methods needed by mailboxer + config.email_method = :mailboxer_email + config.name_method = :name + + #Configures if you use or not a search engine and wich one are you using + #Supported enignes: [:solr,:sphinx] + config.search_enabled = false + config.search_engine = :solr +end diff --git a/config/routes.rb b/config/routes.rb index f94bd2f..c1bbf52 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,8 +24,14 @@ Leaguer::Application.routes.draw do end root to: 'static#homepage' + get '/testsvg', to: 'static#test' + + get '/search', to: 'search#go' + end + + Leaguer::Application.routes.named_routes.module.module_eval do def match_path(match, options={}) tournament_match_path(match.tournament_stage.tournament, match, options) diff --git a/db/migrate/20140422155038_create_simple_captcha_data.rb b/db/migrate/20140422172559_create_simple_captcha_data.rb index 4573b20..4573b20 100644 --- a/db/migrate/20140422155038_create_simple_captcha_data.rb +++ b/db/migrate/20140422172559_create_simple_captcha_data.rb diff --git a/db/migrate/20140422212555_create_mailboxer.mailboxer_engine.rb b/db/migrate/20140422212555_create_mailboxer.mailboxer_engine.rb new file mode 100644 index 0000000..690cec2 --- /dev/null +++ b/db/migrate/20140422212555_create_mailboxer.mailboxer_engine.rb @@ -0,0 +1,62 @@ +# This migration comes from mailboxer_engine (originally 20110511145103) +class CreateMailboxer < ActiveRecord::Migration + def self.up + #Tables + #Conversations + create_table :conversations do |t| + t.column :subject, :string, :default => "" + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + #Receipts + create_table :receipts do |t| + t.references :receiver, :polymorphic => true + t.column :notification_id, :integer, :null => false + t.column :read, :boolean, :default => false + t.column :trashed, :boolean, :default => false + t.column :deleted, :boolean, :default => false + t.column :mailbox_type, :string, :limit => 25 + t.column :created_at, :datetime, :null => false + t.column :updated_at, :datetime, :null => false + end + #Notifications and Messages + create_table :notifications do |t| + t.column :type, :string + t.column :body, :text + t.column :subject, :string, :default => "" + t.references :sender, :polymorphic => true + t.references :object, :polymorphic => true + t.column :conversation_id, :integer + t.column :draft, :boolean, :default => false + t.column :updated_at, :datetime, :null => false + t.column :created_at, :datetime, :null => false + end + + + #Indexes + #Conversations + #Receipts + add_index "receipts","notification_id" + + #Messages + add_index "notifications","conversation_id" + + #Foreign keys + #Conversations + #Receipts + add_foreign_key "receipts", "notifications", :name => "receipts_on_notification_id" + #Messages + add_foreign_key "notifications", "conversations", :name => "notifications_on_conversation_id" + end + + def self.down + #Tables + remove_foreign_key "receipts", :name => "receipts_on_notification_id" + remove_foreign_key "notifications", :name => "notifications_on_conversation_id" + + #Indexes + drop_table :receipts + drop_table :conversations + drop_table :notifications + end +end diff --git a/db/migrate/20140422212556_add_notified_object.mailboxer_engine.rb b/db/migrate/20140422212556_add_notified_object.mailboxer_engine.rb new file mode 100644 index 0000000..7f41ac6 --- /dev/null +++ b/db/migrate/20140422212556_add_notified_object.mailboxer_engine.rb @@ -0,0 +1,18 @@ +# This migration comes from mailboxer_engine (originally 20110719110700) +class AddNotifiedObject < ActiveRecord::Migration + def self.up + change_table :notifications do |t| + t.references :notified_object, :polymorphic => true + t.remove :object_id + t.remove :object_type + end + end + + def self.down + change_table :notifications do |t| + t.remove :notified_object_id + t.remove :notified_object_type + t.references :object, :polymorphic => true + end + end +end diff --git a/db/migrate/20140422212557_add_notification_code.mailboxer_engine.rb b/db/migrate/20140422212557_add_notification_code.mailboxer_engine.rb new file mode 100644 index 0000000..04c12ef --- /dev/null +++ b/db/migrate/20140422212557_add_notification_code.mailboxer_engine.rb @@ -0,0 +1,14 @@ +# This migration comes from mailboxer_engine (originally 20110912163911) +class AddNotificationCode < ActiveRecord::Migration + def self.up + change_table :notifications do |t| + t.string :notification_code, :default => nil + end + end + + def self.down + change_table :notifications do |t| + t.remove :notification_code + end + end +end
\ No newline at end of file diff --git a/db/migrate/20140422212558_add_attachments.mailboxer_engine.rb b/db/migrate/20140422212558_add_attachments.mailboxer_engine.rb new file mode 100644 index 0000000..b8d6588 --- /dev/null +++ b/db/migrate/20140422212558_add_attachments.mailboxer_engine.rb @@ -0,0 +1,10 @@ +# This migration comes from mailboxer_engine (originally 20111204163911) +class AddAttachments < ActiveRecord::Migration + def self.up + add_column :notifications, :attachment, :string + end + + def self.down + remove_column :notifications, :attachment + end +end diff --git a/db/migrate/20140422212559_rename_receipts_read.mailboxer_engine.rb b/db/migrate/20140422212559_rename_receipts_read.mailboxer_engine.rb new file mode 100644 index 0000000..9ce904f --- /dev/null +++ b/db/migrate/20140422212559_rename_receipts_read.mailboxer_engine.rb @@ -0,0 +1,10 @@ +# This migration comes from mailboxer_engine (originally 20120813110712) +class RenameReceiptsRead < ActiveRecord::Migration + def up + rename_column :receipts, :read, :is_read + end + + def down + rename_column :receipts, :is_read, :read + end +end diff --git a/db/migrate/20140422212560_add_global_notification_support.mailboxer_engine.rb b/db/migrate/20140422212560_add_global_notification_support.mailboxer_engine.rb new file mode 100644 index 0000000..60f67ab --- /dev/null +++ b/db/migrate/20140422212560_add_global_notification_support.mailboxer_engine.rb @@ -0,0 +1,10 @@ +# This migration comes from mailboxer_engine (originally 20130305144212) +class AddGlobalNotificationSupport < ActiveRecord::Migration + + def change + change_table :notifications do |t| + t.boolean :global, default: false + t.datetime :expires + end + end +end diff --git a/db/migrate/20140422195042_create_delayed_jobs.rb b/db/migrate/20140422212602_create_delayed_jobs.rb index ec0dd93..ec0dd93 100644 --- a/db/migrate/20140422195042_create_delayed_jobs.rb +++ b/db/migrate/20140422212602_create_delayed_jobs.rb diff --git a/db/migrate/20140422195045_create_servers.rb b/db/migrate/20140422212605_create_servers.rb index fbe1b02..fbe1b02 100644 --- a/db/migrate/20140422195045_create_servers.rb +++ b/db/migrate/20140422212605_create_servers.rb diff --git a/db/migrate/20140422195049_create_matches.rb b/db/migrate/20140422212609_create_matches.rb index bac92d1..bac92d1 100644 --- a/db/migrate/20140422195049_create_matches.rb +++ b/db/migrate/20140422212609_create_matches.rb diff --git a/db/migrate/20140422195052_create_teams.rb b/db/migrate/20140422212613_create_teams.rb index dd8397d..dd8397d 100644 --- a/db/migrate/20140422195052_create_teams.rb +++ b/db/migrate/20140422212613_create_teams.rb diff --git a/db/migrate/20140422195056_create_alerts.rb b/db/migrate/20140422212616_create_alerts.rb index 68a8e10..68a8e10 100644 --- a/db/migrate/20140422195056_create_alerts.rb +++ b/db/migrate/20140422212616_create_alerts.rb diff --git a/db/migrate/20140422195059_create_pms.rb b/db/migrate/20140422212619_create_pms.rb index 93bb5c6..93bb5c6 100644 --- a/db/migrate/20140422195059_create_pms.rb +++ b/db/migrate/20140422212619_create_pms.rb diff --git a/db/migrate/20140422195103_create_tournaments.rb b/db/migrate/20140422212623_create_tournaments.rb index 716871f..716871f 100644 --- a/db/migrate/20140422195103_create_tournaments.rb +++ b/db/migrate/20140422212623_create_tournaments.rb diff --git a/db/migrate/20140422195107_create_games.rb b/db/migrate/20140422212627_create_games.rb index 46ed30d..46ed30d 100644 --- a/db/migrate/20140422195107_create_games.rb +++ b/db/migrate/20140422212627_create_games.rb diff --git a/db/migrate/20140422195110_create_users.rb b/db/migrate/20140422212630_create_users.rb index 8032870..8032870 100644 --- a/db/migrate/20140422195110_create_users.rb +++ b/db/migrate/20140422212630_create_users.rb diff --git a/db/migrate/20140422195114_create_sessions.rb b/db/migrate/20140422212634_create_sessions.rb index f667f1e..f667f1e 100644 --- a/db/migrate/20140422195114_create_sessions.rb +++ b/db/migrate/20140422212634_create_sessions.rb diff --git a/db/migrate/20140422195118_create_brackets.rb b/db/migrate/20140422212637_create_brackets.rb index 8813bf2..8813bf2 100644 --- a/db/migrate/20140422195118_create_brackets.rb +++ b/db/migrate/20140422212637_create_brackets.rb diff --git a/db/migrate/20140422195121_create_game_settings.rb b/db/migrate/20140422212641_create_game_settings.rb index 06fb72e..06fb72e 100644 --- a/db/migrate/20140422195121_create_game_settings.rb +++ b/db/migrate/20140422212641_create_game_settings.rb diff --git a/db/migrate/20140422195125_create_tournament_settings.rb b/db/migrate/20140422212644_create_tournament_settings.rb index e56697f..e56697f 100644 --- a/db/migrate/20140422195125_create_tournament_settings.rb +++ b/db/migrate/20140422212644_create_tournament_settings.rb diff --git a/db/migrate/20140422195128_create_tournament_stages.rb b/db/migrate/20140422212648_create_tournament_stages.rb index e3668cb..e3668cb 100644 --- a/db/migrate/20140422195128_create_tournament_stages.rb +++ b/db/migrate/20140422212648_create_tournament_stages.rb diff --git a/db/migrate/20140422195132_create_statistics.rb b/db/migrate/20140422212651_create_statistics.rb index cc2e97d..cc2e97d 100644 --- a/db/migrate/20140422195132_create_statistics.rb +++ b/db/migrate/20140422212651_create_statistics.rb diff --git a/db/migrate/20140422195135_create_remote_usernames.rb b/db/migrate/20140422212654_create_remote_usernames.rb index e265985..e265985 100644 --- a/db/migrate/20140422195135_create_remote_usernames.rb +++ b/db/migrate/20140422212654_create_remote_usernames.rb diff --git a/db/migrate/20140422195139_create_bracket_matches.rb b/db/migrate/20140422212657_create_bracket_matches.rb index 3323e31..3323e31 100644 --- a/db/migrate/20140422195139_create_bracket_matches.rb +++ b/db/migrate/20140422212657_create_bracket_matches.rb diff --git a/db/migrate/20140422195143_create_api_requests.rb b/db/migrate/20140422212701_create_api_requests.rb index 544c330..544c330 100644 --- a/db/migrate/20140422195143_create_api_requests.rb +++ b/db/migrate/20140422212701_create_api_requests.rb diff --git a/db/migrate/20140422195146_create_tournament_players_join_table.rb b/db/migrate/20140422212704_create_tournament_players_join_table.rb index be240e8..be240e8 100644 --- a/db/migrate/20140422195146_create_tournament_players_join_table.rb +++ b/db/migrate/20140422212704_create_tournament_players_join_table.rb diff --git a/db/migrate/20140422195150_create_tournament_hosts_join_table.rb b/db/migrate/20140422212707_create_tournament_hosts_join_table.rb index 7521d89..7521d89 100644 --- a/db/migrate/20140422195150_create_tournament_hosts_join_table.rb +++ b/db/migrate/20140422212707_create_tournament_hosts_join_table.rb diff --git a/db/migrate/20140422195153_create_team_user_join_table.rb b/db/migrate/20140422212711_create_team_user_join_table.rb index f3b57fc..f3b57fc 100644 --- a/db/migrate/20140422195153_create_team_user_join_table.rb +++ b/db/migrate/20140422212711_create_team_user_join_table.rb diff --git a/db/migrate/20140422195157_create_match_team_join_table.rb b/db/migrate/20140422212714_create_match_team_join_table.rb index c2ed1b7..c2ed1b7 100644 --- a/db/migrate/20140422195157_create_match_team_join_table.rb +++ b/db/migrate/20140422212714_create_match_team_join_table.rb diff --git a/db/migrate/20140422195211_add_hidden_attrs_to_user.rb b/db/migrate/20140422212727_add_hidden_attrs_to_user.rb index 9b5c505..9b5c505 100644 --- a/db/migrate/20140422195211_add_hidden_attrs_to_user.rb +++ b/db/migrate/20140422212727_add_hidden_attrs_to_user.rb diff --git a/db/schema.rb b/db/schema.rb index 3f39538..a160f22 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: 20140422195211) do +ActiveRecord::Schema.define(version: 20140422212727) do create_table "alerts", force: true do |t| t.integer "author_id" @@ -51,6 +51,12 @@ ActiveRecord::Schema.define(version: 20140422195211) do add_index "brackets", ["tournament_id"], name: "index_brackets_on_tournament_id" add_index "brackets", ["user_id"], name: "index_brackets_on_user_id" + create_table "conversations", force: true do |t| + t.string "subject", default: "" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "delayed_jobs", force: true do |t| t.integer "priority", default: 0, null: false t.integer "attempts", default: 0, null: false @@ -119,6 +125,26 @@ ActiveRecord::Schema.define(version: 20140422195211) do t.integer "team_id", null: false end + create_table "notifications", force: true do |t| + t.string "type" + t.text "body" + t.string "subject", default: "" + t.integer "sender_id" + t.string "sender_type" + t.integer "conversation_id" + t.boolean "draft", default: false + t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.integer "notified_object_id" + t.string "notified_object_type" + t.string "notification_code" + t.string "attachment" + t.boolean "global", default: false + t.datetime "expires" + end + + add_index "notifications", ["conversation_id"], name: "index_notifications_on_conversation_id" + create_table "players_tournaments", id: false, force: true do |t| t.integer "player_id", null: false t.integer "tournament_id", null: false @@ -135,6 +161,20 @@ ActiveRecord::Schema.define(version: 20140422195211) do add_index "pms", ["author_id"], name: "index_pms_on_author_id" add_index "pms", ["recipient_id"], name: "index_pms_on_recipient_id" + create_table "receipts", force: true do |t| + t.integer "receiver_id" + t.string "receiver_type" + t.integer "notification_id", null: false + t.boolean "is_read", default: false + t.boolean "trashed", default: false + t.boolean "deleted", default: false + t.string "mailbox_type", limit: 25 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "receipts", ["notification_id"], name: "index_receipts_on_notification_id" + create_table "remote_usernames", force: true do |t| t.integer "game_id" t.integer "user_id" diff --git a/generate.sh b/generate.sh index e965fde..b3e9343 100755 --- a/generate.sh +++ b/generate.sh @@ -16,6 +16,7 @@ git checkout clean-start -- app test config/routes.rb bundle install +bundle exec rails generate mailboxer:install bundle exec rails generate simple_captcha bundle exec rails generate delayed_job:active_record @@ -66,4 +67,4 @@ bundle exec rake db:seed find app -type f -name '*.rb' -exec bin/autoindent {} \; -git add app test config/routes.rb db/migrate db/schema.rb Gemfile.lock +git add app test config/routes.rb config/initializers db/migrate db/schema.rb Gemfile.lock diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb index e0f8d6a..1ac696d 100644 --- a/lib/scheduling/elimination.rb +++ b/lib/scheduling/elimination.rb @@ -1,5 +1,7 @@ + module Scheduling class Elimination + include Rails.application.routes.url_helpers def initialize(tournament_stage) @tournament_stage = tournament_stage @@ -28,7 +30,7 @@ module Scheduling # for each grouping of min_players_per_team self.tournament.players.each_slice(self.tournament.min_players_per_team) do |team_members| # if the match is full, move to the next match, otherwise move to the next team - if (team_num == min_teams_per_match) + if (team_num == self.tournament.min_teams_per_match) match_num -= 1 team_num = 0 else @@ -47,7 +49,7 @@ module Scheduling end end - def graph + def graph(current_user) matches = @tournament_stage.matches_ordered # depth of SVG tree depth = Math.log2(matches.count).floor+1; @@ -76,7 +78,7 @@ STRING rx = 50/(depth+1) + 100/(depth+1)*(depth-(Math.log2(i).floor+1)) ry = ( 100/(2**(Math.log2(i).floor)+1) + rh * 1.1 * (2**Math.log2(i).ceil-i)) - str += "\t<a id=\"svg-match-#{i}\" xlink:href=\"# {match_path(matches[i])}\">\n" + str += "\t<a id=\"svg-match-#{i}\" xlink:href=\"#{match_path(matches[i])}\"><g>\n" str += "\t\t<rect height=\"#{rh}%\" width=\"#{rw}%\" x=\"#{rx}%\" y=\"#{ry}%\" fill=\"url(#gradMatch)\" rx=\"5px\" stroke-width=\"2\"" case matches[i].status when 0 @@ -95,15 +97,15 @@ STRING end str += "/>\n" - color = matches[i].teams.first and matches[i].teams.first.users.include?(current_user) ? "#BCED91" : "white" + color = (matches[i].teams[0] and matches[i].teams[0].users.include?(current_user)) ? "#BCED91" : "white" str += "\t\t<rect width=\"#{rw-5}%\" height=\"#{rh/4}%\" x=\"#{rx + 2.5}%\" y=\"#{ry + rh/6}%\" fill=\"#{color}\" />\n" if matches[i].teams.first - str += '\t\t<text x="#{rx + rw/4}%" y="#{ry + rh/3}%" font-size="#{rh}">Team #{matches[i].teams.first.id}</text>\n' + str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + rh/3}%\" font-size=\"#{rh}\">Team #{matches[i].teams.first.id}</text>\n" end str += "\t\t<text x=\"#{rx + 1.3*rw/3}%\" y=\"#{ry + 5.2*rh/9}%\" font-size=\"#{rh}\"> VS </text>\n" - color = matches[i].teams[1] and matches[i].teams[1].users.include?(current_user) ? "#BCED91" : "white" + color = (matches[i].teams[1] and matches[i].teams[1].users.include?(current_user)) ? "#BCED91" : "white" str += "\t\t<rect width=\"#{rw-5}%\" height=\"#{rh/4}%\" x=\"#{rx + 2.5}%\" y=\"#{ry + 3*rh/5}%\" fill=\"#{color}\" />\n" if matches[i].teams[1] str += "\t\t<text x=\"#{rx + rw/4}%\" y=\"#{ry + 4*rh/5}%\" font-size=\"#{rh}\">Team #{matches[i].teams[1].id}</text>\n" @@ -118,7 +120,7 @@ STRING lastrh = rh lastrw = rw end - str += "</a>\n" + str += "</g></a>\n" end str += '</svg>' diff --git a/lib/scoring/FibonacciPeerWithBlowout.rb b/lib/scoring/fibonacci_peer_with_blowout.rb index 19ac9a7..19ac9a7 100644 --- a/lib/scoring/FibonacciPeerWithBlowout.rb +++ b/lib/scoring/fibonacci_peer_with_blowout.rb diff --git a/lib/scoring/MarginalPeer.rb b/lib/scoring/marginal_peer.rb index 0e1cfa8..0e1cfa8 100644 --- a/lib/scoring/MarginalPeer.rb +++ b/lib/scoring/marginal_peer.rb diff --git a/lib/scoring/ScoringAlgorithm.rb b/lib/scoring/scoring_algorithm.rb index f2afa6f..f2afa6f 100644 --- a/lib/scoring/ScoringAlgorithm.rb +++ b/lib/scoring/scoring_algorithm.rb diff --git a/lib/scoring/WinnerTakesAll.rb b/lib/scoring/winner_takes_all.rb index ad2471b..ad2471b 100644 --- a/lib/scoring/WinnerTakesAll.rb +++ b/lib/scoring/winner_takes_all.rb |