diff options
author | nfoy <nfoy@purdue.edu> | 2014-04-22 18:30:11 -0400 |
---|---|---|
committer | nfoy <nfoy@purdue.edu> | 2014-04-22 18:30:11 -0400 |
commit | e44115cf206804f7a22c5f98ba422d9c61ad81a7 (patch) | |
tree | e60532fbbc7639084ca218a196dc4b0e377ba4e7 | |
parent | f4373ec761491213a4c5690ef33832f35cbb5e32 (diff) | |
parent | c0ae56e4974a14433a58951c031d4b4c74f57935 (diff) |
Merge branch 'master' of https://github.com/LukeShu/leaguer
-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/tournaments_controller.rb | 25 | ||||
-rw-r--r-- | app/models/tournament_stage.rb | 4 | ||||
-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 | 5 | ||||
-rw-r--r-- | lib/scheduling/elimination.rb | 14 |
12 files changed, 42 insertions, 46 deletions
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/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 9fa6dcd..762f6a7 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 private 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 index 6d5826f..324fa48 100644 --- a/app/views/search/go.html.erb +++ b/app/views/search/go.html.erb @@ -1,10 +1,11 @@ <%# Show search results if a query was not nill %> <% if !@query.empty? %> - <h3> Showing results for: <span><%= @query %></span></h3> + <% if @tournaments.empty? and @players.empty? %> - <p> No results found for "<%= @query %>" </p> + <h3> No results found for "<%= @query %>" </h3> <% else %> + <h3> Showing results for: <span><%= @query %></span></h3> <% if @tournaments.length > 0 %> <h4> Tournaments </h4> <% end %> diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb index e718d54..5ce71ca 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 @@ -21,9 +23,9 @@ module Scheduling match_num = num_matches-1 team_num = 0 # for each grouping of min_players_per_team - self.tournament.players.each_slice(min_players_per_team) do |team_members| + 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 @@ -42,7 +44,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; @@ -71,7 +73,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 @@ -93,7 +95,7 @@ STRING color = matches[i].teams.first and matches[i].teams.first.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" @@ -113,7 +115,7 @@ STRING lastrh = rh lastrw = rw end - str += "</a>\n" + str += "</g></a>\n" end str += '</svg>' |